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 ~ 2011, Tassilo Horn, all rights reserved.
11 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
12 ;; Copyright (C) 2009 ~ 2011, rubikitch, all rights reserved.
13 ;; Copyright (C) 2009 ~ 2011, 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-c-insert-latex-math'
127 ;; Preconfigured anything for latex math symbols completion.
128 ;; `anything-register'
129 ;; Preconfigured `anything' for Emacs registers.
130 ;; `anything-man-woman'
131 ;; Preconfigured `anything' for Man and Woman pages.
132 ;; `anything-org-keywords'
133 ;; Preconfigured `anything' for org keywords.
135 ;; Preconfigured `anything' for emms sources.
136 ;; `anything-eev-anchors'
137 ;; Preconfigured `anything' for eev anchors.
138 ;; `anything-bm-list'
139 ;; Preconfigured `anything' for visible bookmarks.
141 ;; Preconfigured `anything' for timers.
142 ;; `anything-list-emacs-process'
143 ;; Preconfigured `anything' for emacs process.
145 ;; Preconfigured Anything for Occur source.
146 ;; `anything-browse-code'
147 ;; Preconfigured anything to browse code.
148 ;; `anything-org-headlines'
149 ;; Preconfigured anything to show org headlines.
150 ;; `anything-kill-buffers'
151 ;; Preconfigured `anything' to kill buffer you selected.
153 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
154 ;; `anything-insert-buffer-name'
155 ;; Insert buffer name.
156 ;; `anything-insert-symbol'
157 ;; Insert current symbol.
158 ;; `anything-insert-selection'
159 ;; Insert current selection.
160 ;; `anything-show-buffer-only'
161 ;; [OBSOLETE] Only show sources about buffer.
162 ;; `anything-show-bbdb-only'
163 ;; [OBSOLETE] Only show sources about BBDB.
164 ;; `anything-show-locate-only'
165 ;; [OBSOLETE] Only show sources about Locate.
166 ;; `anything-show-info-only'
167 ;; [OBSOLETE] Only show sources about Info.
168 ;; `anything-show-imenu-only'
169 ;; [OBSOLETE] Only show sources about Imenu.
170 ;; `anything-show-files-only'
171 ;; [OBSOLETE] Only show sources about File.
172 ;; `anything-show-w3m-bookmarks-only'
173 ;; [OBSOLETE] Only show source about w3m bookmark.
174 ;; `anything-show-colors-only'
175 ;; [OBSOLETE] Only show source about color.
176 ;; `anything-show-kill-ring-only'
177 ;; [OBSOLETE] Only show source about kill ring.
178 ;; `anything-show-this-source-only'
179 ;; Only show this source.
180 ;; `anything-test-sources'
181 ;; List all anything sources for test.
182 ;; `anything-select-source'
184 ;; `anything-toggle-all-marks'
186 ;; `anything-find-files-down-one-level'
187 ;; Go down one level like unix command `cd ..'.
188 ;; `anything-find-files'
189 ;; Preconfigured `anything' for anything implementation of `find-file'.
190 ;; `anything-write-file'
191 ;; Preconfigured `anything' providing completion for `write-file'.
192 ;; `anything-insert-file'
193 ;; Preconfigured `anything' providing completion for `insert-file'.
194 ;; `anything-dired-rename-file'
195 ;; Preconfigured `anything' to rename files from dired.
196 ;; `anything-dired-copy-file'
197 ;; Preconfigured `anything' to copy files from dired.
198 ;; `anything-dired-symlink-file'
199 ;; Preconfigured `anything' to symlink files from dired.
200 ;; `anything-dired-hardlink-file'
201 ;; Preconfigured `anything' to hardlink files from dired.
202 ;; `anything-dired-bindings'
203 ;; Replace usual dired commands `C' and `R' by anything ones.
204 ;; `anything-do-grep'
205 ;; Preconfigured anything for grep.
206 ;; `anything-c-grep-precedent-file'
207 ;; Go to precedent file in `anything-do-grep'.
208 ;; `anything-c-grep-next-or-prec-file'
209 ;; Go to next or precedent candidate file in anything grep buffer.
210 ;; `anything-c-etags-select'
211 ;; Preconfigured anything for etags.
212 ;; `anything-filelist'
213 ;; Preconfigured `anything' to open files instantly.
214 ;; `anything-filelist+'
215 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
216 ;; `anything-c-describe-attributes'
217 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
219 ;; Preconfigured `anything' for Emacs commands.
220 ;; `anything-manage-advice'
221 ;; Preconfigured `anything' to disable/enable function advices.
222 ;; `anything-bookmark-ext'
223 ;; Preconfigured `anything' for bookmark-extensions sources.
224 ;; `anything-simple-call-tree'
225 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
226 ;; `anything-mark-ring'
227 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
228 ;; `anything-global-mark-ring'
229 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
230 ;; `anything-all-mark-rings'
231 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
232 ;; `anything-yaoddmuse-cache-pages'
233 ;; Fetch the list of files on emacswiki and create cache file.
234 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
235 ;; Preconfigured `anything' to edit or view EmacsWiki page.
236 ;; `anything-yaoddmuse-emacswiki-post-library'
237 ;; Preconfigured `anything' to post library to EmacsWiki.
238 ;; `anything-eval-expression'
239 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
240 ;; `anything-eval-expression-with-eldoc'
241 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
242 ;; `anything-surfraw'
243 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
244 ;; `anything-call-source'
245 ;; Preconfigured `anything' to call anything source.
246 ;; `anything-call-source-from-anything'
247 ;; Call anything source within `anything' session.
248 ;; `anything-execute-anything-command'
249 ;; Preconfigured `anything' to execute preconfigured `anything'.
250 ;; `anything-create-from-anything'
251 ;; Run `anything-create' from `anything' as a fallback.
253 ;; Preconfigured `anything' to do many create actions from STRING.
255 ;; Preconfigured `anything' for top command.
256 ;; `anything-select-xfont'
257 ;; Preconfigured `anything' to select Xfont.
258 ;; `anything-world-time'
259 ;; Preconfigured `anything' to show world time.
261 ;; Preconfigured `anything' : frontend of APT package manager.
262 ;; `anything-c-shell-command-if-needed'
264 ;; `anything-c-run-external-command'
265 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
266 ;; `anything-ratpoison-commands'
267 ;; Preconfigured `anything' to execute ratpoison commands.
268 ;; `anything-c-set-variable'
269 ;; Set value to VAR interactively.
270 ;; `anything-c-adaptive-save-history'
271 ;; Save history information to file given by `anything-c-adaptive-history-file'.
272 ;; `anything-c-toggle-match-plugin'
273 ;; Toggle anything-match-plugin.
275 ;; * User variables defined here:
276 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
277 ;; `anything-c-use-standard-keys'
278 ;; Default Value: nil
279 ;; `anything-c-adaptive-history-file'
280 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
281 ;; `anything-c-adaptive-history-length'
283 ;; `anything-c-google-suggest-url'
284 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
285 ;; `anything-c-google-suggest-search-url'
286 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
287 ;; `anything-google-suggest-use-curl-p'
288 ;; Default Value: nil
289 ;; `anything-c-yahoo-suggest-url'
290 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
291 ;; `anything-c-yahoo-suggest-search-url'
292 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
293 ;; `anything-c-boring-buffer-regexp'
294 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
295 ;; `anything-c-boring-file-regexp'
296 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
297 ;; `anything-kill-ring-threshold'
299 ;; `anything-su-or-sudo'
300 ;; Default Value: "su"
301 ;; `anything-for-files-prefered-list'
302 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
303 ;; `anything-create--actions-private'
304 ;; Default Value: nil
305 ;; `anything-allow-skipping-current-buffer'
307 ;; `anything-c-enable-eval-defun-hack'
309 ;; `anything-tramp-verbose'
311 ;; `anything-raise-command'
312 ;; Default Value: nil
313 ;; `anything-command-map-prefix-key'
314 ;; Default Value: "<f5> a"
315 ;; `anything-c-find-files-show-icons'
316 ;; Default Value: nil
317 ;; `anything-c-find-files-icons-directory'
318 ;; Default Value: "/usr/local/share/emacs/23.2.91/etc/images/tree-widget/default"
319 ;; `anything-c-browse-code-regexp-lisp'
320 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
321 ;; `anything-c-browse-code-regexp-python'
322 ;; Default Value: "\\<def\\>\\|\\<class\\>"
323 ;; `anything-c-browse-code-regexp-alist'
324 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
325 ;; `anything-c-external-programs-associations'
326 ;; Default Value: nil
327 ;; `anything-c-etags-tag-file-name'
328 ;; Default Value: "TAGS"
329 ;; `anything-c-etags-tag-file-search-limit'
331 ;; `anything-c-filelist-file-name'
332 ;; Default Value: nil
334 ;; * Anything sources defined here:
335 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
336 ;; `anything-c-source-regexp' (Regexp Builder)
337 ;; `anything-c-source-buffers' (Buffers)
338 ;; `anything-c-source-buffer-not-found' (Create buffer)
339 ;; `anything-c-source-buffers+' (Buffers)
340 ;; `anything-c-source-file-name-history' (File Name History)
341 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
342 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
343 ;; `anything-c-source-find-files' (Find Files (`C-.':Go to precedent level))
344 ;; `anything-c-source-write-file' (Write File (`C-.':Go to precedent level))
345 ;; `anything-c-source-insert-file' (Insert File (`C-.':Go to precedent level))
346 ;; `anything-c-source-copy-files' (Copy Files (`C-.':Go to precedent level))
347 ;; `anything-c-source-symlink-files' (Symlink Files (`C-.':Go to precedent level))
348 ;; `anything-c-source-hardlink-files' (Hardlink Files (`C-.':Go to precedent level))
349 ;; `anything-c-source-file-cache-initialized' ()
350 ;; `anything-c-source-file-cache' (File Cache)
351 ;; `anything-c-source-locate' (Locate)
352 ;; `anything-c-source-etags-select' (Etags)
353 ;; `anything-c-source-recentf' (Recentf)
354 ;; `anything-c-source-ffap-guesser' (File at point)
355 ;; `anything-c-source-ffap-line' (File/Lineno at point)
356 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
357 ;; `anything-c-source-filelist' (FileList)
358 ;; `anything-c-source-info-pages' (Info Pages)
359 ;; `anything-c-source-info-elisp' (Info index: elisp)
360 ;; `anything-c-source-info-cl' (Info index: cl)
361 ;; `anything-c-source-info-org' (Info index: org)
362 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
363 ;; `anything-c-source-info-zsh' (Info index: zsh)
364 ;; `anything-c-source-info-bash' (Info index: bash)
365 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
366 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
367 ;; `anything-c-source-info-find' (Info index: find)
368 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
369 ;; `anything-c-source-info-textutils' (Info index: textutils)
370 ;; `anything-c-source-info-libc' (Info index: libc)
371 ;; `anything-c-source-info-make' (Info index: make)
372 ;; `anything-c-source-info-automake' (Info index: automake)
373 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
374 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
375 ;; `anything-c-source-info-emacs' (Info index: emacs)
376 ;; `anything-c-source-info-elib' (Info index: elib)
377 ;; `anything-c-source-info-eieio' (Info index: eieio)
378 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
379 ;; `anything-c-source-info-guile' (Info index: guile)
380 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
381 ;; `anything-c-source-info-goops' (Info index: goops)
382 ;; `anything-c-source-info-screen' (Info index: screen)
383 ;; `anything-c-source-info-latex' (Info index: latex)
384 ;; `anything-c-source-info-gawk' (Info index: gawk)
385 ;; `anything-c-source-info-sed' (Info index: sed)
386 ;; `anything-c-source-info-m4' (Info index: m4)
387 ;; `anything-c-source-info-wget' (Info index: wget)
388 ;; `anything-c-source-info-binutils' (Info index: binutils)
389 ;; `anything-c-source-info-as' (Info index: as)
390 ;; `anything-c-source-info-bfd' (Info index: bfd)
391 ;; `anything-c-source-info-gprof' (Info index: gprof)
392 ;; `anything-c-source-info-ld' (Info index: ld)
393 ;; `anything-c-source-info-diff' (Info index: diff)
394 ;; `anything-c-source-info-flex' (Info index: flex)
395 ;; `anything-c-source-info-grep' (Info index: grep)
396 ;; `anything-c-source-info-gzip' (Info index: gzip)
397 ;; `anything-c-source-info-libtool' (Info index: libtool)
398 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
399 ;; `anything-c-source-info-info' (Info index: info)
400 ;; `anything-c-source-info-gdb' (Info index: gdb)
401 ;; `anything-c-source-info-stabs' (Info index: stabs)
402 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
403 ;; `anything-c-source-info-cvs' (Info index: cvs)
404 ;; `anything-c-source-info-bison' (Info index: bison)
405 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
406 ;; `anything-c-source-info-global' (Info index: global)
407 ;; `anything-c-source-man-pages' (Manual Pages)
408 ;; `anything-c-source-complex-command-history' (Complex Command History)
409 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
410 ;; `anything-c-source-emacs-commands' (Emacs Commands)
411 ;; `anything-c-source-lacarte' (Lacarte)
412 ;; `anything-c-source-emacs-functions' (Emacs Functions)
413 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
414 ;; `anything-c-source-advice' (Function Advice)
415 ;; `anything-c-source-emacs-variables' (Emacs Variables)
416 ;; `anything-c-source-bookmarks' (Bookmarks)
417 ;; `anything-c-source-bookmark-set' (Set Bookmark)
418 ;; `anything-c-source-bm' (Visible Bookmarks)
419 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
420 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
421 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
422 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
423 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
424 ;; `anything-c-source-bookmark-images' (Bookmark Images)
425 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
426 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
427 ;; `anything-c-source-bookmark-info' (Bookmark Info)
428 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
429 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
430 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
431 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
432 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
433 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
434 ;; `anything-c-source-imenu' (Imenu)
435 ;; `anything-c-source-ctags' (Exuberant ctags)
436 ;; `anything-c-source-semantic' (Semantic Tags)
437 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
438 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
439 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
440 ;; `anything-c-source-customize-face' (Customize Face)
441 ;; `anything-c-source-colors' (Colors)
442 ;; `anything-c-source-tracker-search' (Tracker Search)
443 ;; `anything-c-source-mac-spotlight' (mdfind)
444 ;; `anything-c-source-kill-ring' (Kill Ring)
445 ;; `anything-c-source-mark-ring' (mark-ring)
446 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
447 ;; `anything-c-source-register' (Registers)
448 ;; `anything-c-source-latex-math' (Latex Math Menu)
449 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
450 ;; `anything-c-source-rd-headline' (RD HeadLine)
451 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
452 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
453 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
454 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
455 ;; `anything-c-source-org-headline' (Org HeadLine)
456 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
457 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
458 ;; `anything-c-source-eev-anchor' (Anchors)
459 ;; `anything-c-source-org-keywords' (Org Keywords)
460 ;; `anything-c-source-picklist' (Picklist)
461 ;; `anything-c-source-bbdb' (BBDB)
462 ;; `anything-c-source-evaluation-result' (Evaluation Result)
463 ;; `anything-c-source-calculation-result' (Calculation Result)
464 ;; `anything-c-source-google-suggest' (Google Suggest)
465 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
466 ;; `anything-c-source-emms-streams' (Emms Streams)
467 ;; `anything-c-source-emms-dired' (Music Directory)
468 ;; `anything-c-source-emms-files' (Emms files)
469 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
470 ;; `anything-c-source-call-source' (Call anything source)
471 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
472 ;; `anything-c-source-occur' (Occur)
473 ;; `anything-c-source-browse-code' (Browse code)
474 ;; `anything-c-source-create' (Create)
475 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
476 ;; `anything-c-source-elscreen' (Elscreen)
477 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
478 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
479 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
480 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
481 ;; `anything-c-source-xfonts' (X Fonts)
482 ;; `anything-c-source-time-world' (Time World List)
483 ;; `anything-c-source-apt' (APT)
484 ;; `anything-c-source-gentoo' (Portage sources)
485 ;; `anything-c-source-use-flags' (Use Flags)
486 ;; `anything-c-source-emacs-process' (Emacs Process)
487 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
489 ;; *** END auto-documentation
494 ;; Change log of this file is found at
495 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
497 ;; Change log of this project is found at
498 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
503 ;; Tassilo Horn <tassilo@member.fsf.org>
504 ;; Vagn Johansen <gonz808@hotmail.com>
505 ;; Mathias Dahl <mathias.dahl@gmail.com>
506 ;; Bill Clementson <billclem@gmail.com>
507 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
508 ;; Drew Adams <drew.adams@oracle.com>
509 ;; Jason McBrayer <jmcbray@carcosa.net>
510 ;; Andy Stewart <lazycat.manatee@gmail.com>
511 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
512 ;; rubikitch <rubikitch@ruby-lang.org>
513 ;; Scott Vokes <vokes.s@gmail.com>
514 ;; Kenichirou Oyama <k1lowxb@gmail.com>
518 ;; Evaluate (autodoc-update-all) before commit. This function
519 ;; generates anything-c-source-* / functions / options list.
521 ;; Install also developer-tools/autodoc.el
522 ;; And eval it or run interactively.
524 ;; [EVAL IT] (autodoc-update-all)
526 ;; Please write details documentation about function, then others will
527 ;; read code more easier. -- Andy Stewart
533 ;; - Fix documentation, now many functions haven't documentations.
548 (let ((version "1.263"))
549 (when (and (string= "1." (substring version
0 2))
550 (string-match "1\.\\([0-9]+\\)" anything-version
)
551 (< (string-to-number (match-string 1 anything-version
))
552 (string-to-number (substring version
2))))
553 (error "Please update anything.el!!
555 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
557 or M-x install-elisp-from-emacswiki anything.el")))
560 (unless (fboundp 'window-system
)
561 (defun window-system (&optional arg
)
564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
565 (defgroup anything-config nil
566 "Predefined configurations for `anything.el'."
569 (defcustom anything-c-use-standard-keys nil
570 "Whether use standard keybindings. (no effect)
572 Key definitions in anything-config.el are removed because
573 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
574 minibuffer history, C-s for isearch, etc.
576 If you use `iswitchb' with `anything',
577 evaluate (anything-iswitchb-setup) . Then some bindings that
578 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
579 history, are removed from `anything-map'. "
581 :group
'anything-config
)
583 (defcustom anything-c-adaptive-history-file
"~/.emacs.d/anything-c-adaptive-history"
584 "Path of file where history information is stored."
586 :group
'anything-config
)
588 (defcustom anything-c-adaptive-history-length
50
589 "Maximum number of candidates stored for a source."
591 :group
'anything-config
)
593 (defcustom anything-c-google-suggest-url
594 "http://google.com/complete/search?output=toolbar&q="
595 "URL used for looking up Google suggestions."
597 :group
'anything-config
)
599 (defcustom anything-c-google-suggest-search-url
600 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
601 "URL used for Google searching."
603 :group
'anything-config
)
605 (defcustom anything-google-suggest-use-curl-p nil
606 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
607 Otherwise `url-retrieve-synchronously' is used."
609 :group
'anything-config
)
611 (defcustom anything-c-yahoo-suggest-url
612 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
613 "Url used for looking up Yahoo suggestions."
615 :group
'anything-config
)
617 (defcustom anything-c-yahoo-suggest-search-url
618 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
619 "Url used for Yahoo searching."
621 :group
'anything-config
)
623 (defcustom anything-c-boring-buffer-regexp
629 " *Echo Area" " *Minibuf"))
630 "The regexp that match boring buffers.
631 Buffer candidates matching this regular expression will be
632 filtered from the list of candidates if the
633 `anything-c-skip-boring-buffers' candidate transformer is used, or
634 they will be displayed with face `file-name-shadow' if
635 `anything-c-shadow-boring-buffers' is used."
637 :group
'anything-config
)
638 ;; (string-match anything-c-boring-buffer-regexp "buf")
639 ;; (string-match anything-c-boring-buffer-regexp " hidden")
640 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
642 (defcustom anything-c-boring-file-regexp
644 ;; Boring directories
645 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol
))
647 (and line-start
".#")
648 (and (or ".class" ".la" ".o" "~") eol
)))
649 "The regexp that match boring files.
650 File candidates matching this regular expression will be
651 filtered from the list of candidates if the
652 `anything-c-skip-boring-files' candidate transformer is used, or
653 they will be displayed with face `file-name-shadow' if
654 `anything-c-shadow-boring-files' is used."
656 :group
'anything-config
)
658 (defcustom anything-kill-ring-threshold
10
659 "*Minimum length to be listed by `anything-c-source-kill-ring'."
661 :group
'anything-config
)
663 (defcustom anything-su-or-sudo
"su"
664 "What command to use for root access."
666 :group
'anything-config
)
668 (defcustom anything-for-files-prefered-list
669 '(anything-c-source-ffap-line
670 anything-c-source-ffap-guesser
671 anything-c-source-buffers
+
672 anything-c-source-recentf
673 anything-c-source-bookmarks
674 anything-c-source-file-cache
675 anything-c-source-files-in-current-dir
+
676 anything-c-source-locate
)
677 "Your prefered sources to find files."
679 :group
'anything-config
)
681 (defcustom anything-create--actions-private nil
682 "User defined actions for `anything-create' / `anything-c-source-create'.
683 It is a list of (DISPLAY . FUNCTION) pairs like `action'
684 attribute of `anything-sources'.
686 It is prepended to predefined pairs."
688 :group
'anything-config
)
690 (defcustom anything-allow-skipping-current-buffer t
691 "Show current buffer or not in anything buffer"
693 :group
'anything-config
)
695 (defcustom anything-c-enable-eval-defun-hack t
696 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
697 This hack is invoked when pressing C-M-x in the form \
698 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
700 :group
'anything-config
)
702 (defcustom anything-tramp-verbose
0
703 "*Just like `tramp-verbose' but specific to anything.
704 When set to 0 don't show tramp messages in anything.
705 If you want to have the default tramp messages set it to 3."
707 :group
'anything-config
)
709 (defcustom anything-raise-command nil
710 "*A shell command to jump to a window running specific program.
711 Need external program wmctrl.
712 This will be use with `format', so use something like \"wmctrl -xa %s\"."
714 :group
'anything-config
)
716 (defun anything-set-anything-command-map-prefix-key (var key
)
717 (when (boundp 'anything-command-map-prefix-key
)
718 (global-unset-key (read-kbd-macro anything-command-map-prefix-key
)))
719 (setq anything-command-map-prefix-key key
)
720 (global-set-key (read-kbd-macro anything-command-map-prefix-key
)
721 'anything-command-map
))
723 (defcustom anything-command-map-prefix-key
"<f5> a"
724 "*The prefix key for all `anything-command-map' commands.
727 This default value is very likely to be changed,
728 because it is under discussion."
730 :set
'anything-set-anything-command-map-prefix-key
731 :group
'anything-config
)
733 (defcustom anything-c-find-files-show-icons nil
734 "*Whether show or hide icons in `anything-find-files'."
736 :group
'anything-config
)
738 (defcustom anything-c-find-files-icons-directory
740 (concat (car image-load-path
) "tree-widget/default"))
741 "*Default path where to find files and directory icons."
743 :group
'anything-config
)
745 (defcustom anything-c-browse-code-regexp-lisp
746 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
747 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
748 "*Regexp used to parse lisp buffer when browsing code."
750 :group
'anything-config
)
752 (defcustom anything-c-browse-code-regexp-python
753 "\\<def\\>\\|\\<class\\>"
754 "*Regexp used to parse python buffer when browsing code."
756 :group
'anything-config
)
758 (defcustom anything-c-browse-code-regexp-alist
759 `((lisp-interaction-mode .
,anything-c-browse-code-regexp-lisp
)
760 (emacs-lisp-mode .
,anything-c-browse-code-regexp-lisp
)
761 (lisp-mode .
,anything-c-browse-code-regexp-lisp
)
762 (python-mode .
,anything-c-browse-code-regexp-python
))
763 "*Alist to store regexps for browsing code corresponding \
764 to a specific `major-mode'."
766 :group
'anything-config
)
768 (defcustom anything-c-external-programs-associations nil
769 "*Alist to store externals programs associated with file extension.
770 This variable overhide setting in .mailcap file.
771 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
773 :group
'anything-config
)
775 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
776 ;; TODO: This should be integrated in anything.el instead of having
779 (defvar anything-current-prefix-arg nil
780 "Record `current-prefix-arg' when exiting minibuffer.
781 It will be cleared at start of next `anything' call when \
782 `anything-before-initialize-hook' is called.")
784 (defadvice anything-exit-minibuffer
(before anything-current-prefix-arg activate
)
785 (unless anything-current-prefix-arg
786 (setq anything-current-prefix-arg current-prefix-arg
)))
788 ;; using this hook instead of `anything-after-action-hook'
789 ;; allow to record the prefix args and keep their values
790 ;; when using `anything-comp-read'.
791 ;; i.e when quitting `anything-comp-read' prefix args are preserved
792 ;; for the following action.
793 (add-hook 'anything-before-initialize-hook
794 (lambda () (setq anything-current-prefix-arg nil
)))
797 (defun anything-configuration ()
798 "Customize `anything'."
800 (customize-group "anything-config"))
802 ;;; Anything-command-map
804 (defvar anything-command-map
)
805 (define-prefix-command 'anything-command-map
)
807 ;; rubikitch: Please change it freely because it is in discussion. I'll track from git.
808 (define-key anything-command-map
(kbd "<SPC>") 'anything-execute-anything-command
)
809 (define-key anything-command-map
(kbd "e") 'anything-c-etags-select
)
810 (define-key anything-command-map
(kbd "l") 'anything-locate
)
811 (define-key anything-command-map
(kbd "s") 'anything-surfraw
)
812 (define-key anything-command-map
(kbd "r") 'anything-regexp
)
813 (define-key anything-command-map
(kbd "w") 'anything-w3m-bookmarks
)
814 (define-key anything-command-map
(kbd "x") 'anything-firefox-bookmarks
)
815 (define-key anything-command-map
(kbd "#") 'anything-emms
)
816 (define-key anything-command-map
(kbd "m") 'anything-man-woman
)
817 (define-key anything-command-map
(kbd "t") 'anything-top
)
818 (define-key anything-command-map
(kbd "i") 'anything-imenu
)
819 (define-key anything-command-map
(kbd "p") 'anything-list-emacs-process
)
820 (define-key anything-command-map
(kbd "C-x r b") 'anything-c-pp-bookmarks
)
821 (define-key anything-command-map
(kbd "M-y") 'anything-show-kill-ring
)
822 (define-key anything-command-map
(kbd "C-c <SPC>") 'anything-all-mark-rings
)
823 (define-key anything-command-map
(kbd "C-x C-f") 'anything-find-files
)
824 (define-key anything-command-map
(kbd "f") 'anything-for-files
)
825 (define-key anything-command-map
(kbd "C-:") 'anything-eval-expression-with-eldoc
)
826 (define-key anything-command-map
(kbd "C-,") 'anything-calcul-expression
)
827 (define-key anything-command-map
(kbd "M-x") 'anything-M-x
)
828 (define-key anything-command-map
(kbd "C-x C-w") 'anything-write-file
)
829 (define-key anything-command-map
(kbd "C-x i") 'anything-insert-file
)
830 (define-key anything-command-map
(kbd "M-s o") 'anything-occur
)
831 (define-key anything-command-map
(kbd "M-g s") 'anything-do-grep
)
832 (define-key anything-command-map
(kbd "c") 'anything-colors
)
833 (define-key anything-command-map
(kbd "F") 'anything-select-xfont
)
834 (define-key anything-command-map
(kbd "C-c f") 'anything-recentf
)
835 (define-key anything-command-map
(kbd "C-c g") 'anything-google-suggest
)
836 (define-key anything-command-map
(kbd "h i") 'anything-info-at-point
)
837 (define-key anything-command-map
(kbd "h r") 'anything-info-emacs
)
838 (define-key anything-command-map
(kbd "C-x C-b") 'anything-buffers
+)
839 (define-key anything-command-map
(kbd "C-c C-b") 'anything-browse-code
)
840 (define-key anything-command-map
(kbd "C-x r i") 'anything-register
)
841 (define-key anything-command-map
(kbd "C-c C-x") 'anything-c-run-external-command
)
843 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
844 ;; minibuffer-local-filename-must-match-map.
845 (defvar minibuffer-local-filename-must-match-map
(make-sparse-keymap)) ;; Emacs 23.1.+
846 (defvar minibuffer-local-must-match-filename-map
(make-sparse-keymap)) ;; Older Emacsen
847 (dolist (map (list minibuffer-local-filename-completion-map
848 minibuffer-local-completion-map
849 minibuffer-local-must-match-filename-map
850 minibuffer-local-filename-must-match-map
852 minibuffer-local-isearch-map
853 minibuffer-local-must-match-map
854 minibuffer-local-ns-map
))
855 (define-key map
"\C-r" 'anything-minibuffer-history
))
858 (easy-menu-define nil global-map
861 ["All anything commands" anything-execute-anything-command t
]
862 ["Find any Files/Buffers" anything-for-files t
]
865 ["Find files" anything-find-files t
]
866 ["Recent Files" anything-recentf t
]
867 ["Locate" anything-locate t
]
868 ["Bookmarks" anything-c-pp-bookmarks t
])
870 ["Find buffers" anything-buffers
+ t
])
872 ["Emacs Commands" anything-M-x t
]
873 ["Externals Commands" anything-c-run-external-command t
])
875 ["Info at point" anything-info-at-point t
]
876 ["Emacs Manual index" anything-info-emacs t
])
878 ["Org keywords" anything-org-keywords t
]
879 ["Org headlines" anything-org-headlines t
])
881 ["Occur" anything-occur t
]
882 ["Grep" anything-do-grep t
]
883 ["Etags" anything-c-etags-select t
]
884 ["Browse Kill ring" anything-show-kill-ring t
]
885 ["Browse register" anything-register t
]
886 ["Browse code" anything-browse-code t
]
887 ["Mark Ring" anything-all-mark-rings t
]
888 ["Regexp handler" anything-regexp t
]
889 ["Colors & Faces" anything-colors t
]
890 ["Show xfonts" anything-select-xfont t
]
891 ["Imenu" anything-imenu t
]
892 ["Google Suggest" anything-google-suggest t
]
893 ["Eval expression" anything-eval-expression-with-eldoc t
]
894 ["Calcul expression" anything-calcul-expression t
]
895 ["Man pages" anything-man-woman t
]
896 ["Top externals process" anything-top t
]
897 ["Emacs internals process" anything-list-emacs-process t
])
899 ["Prefered Options" anything-configuration t
]))
903 ;; It is replaced by `anything-help'
904 (defun anything-c-describe-anything-bindings ()
905 "[OBSOLETE] Describe `anything' bindings."
907 (anything-run-after-quit
909 (with-current-buffer (get-buffer-create "*Anything Help*")
912 (substitute-command-keys
913 "The keys that are defined for `anything' are:
915 (pop-to-buffer "*Anything Help*")
916 (goto-char (point-min)))))
918 ;; Use `describe-mode' key in `global-map'
919 ;; (dolist (k (where-is-internal 'describe-mode global-map))
920 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
923 (defun anything-c-list-preconfigured-anything ()
926 for entry in
(cdr (assoc
927 (file-truename (locate-library "anything-config"))
929 if
(and (consp entry
)
930 (eq (car entry
) 'defun
)
931 (string-match "^Preconfigured.+$"
932 (setq doc
(or (documentation (setq sym
(cdr entry
)))
934 collect
(cons sym
(match-string 0 doc
))))
936 (defun anything-c-format-preconfigured-anything ()
937 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x
) (cdr x
)))
938 (anything-c-list-preconfigured-anything)))
940 (setq anything-help-message
944 "`anything' is QuickSilver-like candidate-selection framework.
946 Narrow the list by typing some pattern,
947 Multiple patterns are allowed by splitting by space.
948 Select with natural Emacs operations, choose with RET.
950 If you have any problems, press C-c C-x C-b!!
951 Feel free to send bug reports. I'll fix them.
952 The steps are described in the beginning of anything.el file.
954 == Basic Operations ==
955 C-p, Up: Previous Line
956 C-n, Down : Next Line
957 M-v, PageUp : Previous Page
958 C-v, PageDown : Next Page
959 Enter : Execute first (default) action / Select
962 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
963 M-PageDown, C-M-v : Next Page (other-window)
965 Tab, C-i : Show action list
966 Left : Previous Source
967 Right, C-o : Next Source
969 C-z : Persistent Action (Execute action with anything session kept)
970 C-c C-x C-b: Send a bug report
972 == Shortcuts For 2nd/3rd Action ==
973 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
974 \\[anything-select-3rd-action] : Execute 3rd Action
977 Visible marks store candidate. Some actions uses marked candidates.
979 \\[anything-toggle-visible-mark] : Toggle Visible Mark
980 \\[anything-prev-visible-mark] : Previous Mark
981 \\[anything-next-visible-mark] : Next Mark
983 == Miscellaneous Commands ==
984 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
985 \\[anything-quit-and-find-file] : Drop into `find-file'
986 \\[anything-delete-current-selection] : Delete Selected Item (visually)
987 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
988 \\[anything-yank-selection] : Yank Selected Item Into Pattern
989 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
990 \\[anything-force-update] : Recalculate And Redisplay Candidates
992 == Global Commands ==
993 \\<global-map>\\[anything-resume] revives last `anything' session.
994 It is very useful, so you should bind any key.
996 Single source is executed by \\[anything-call-source].
998 == Preconfigured `anything' ==
999 Preconfigured `anything' is commands that uses `anything' interface.
1000 You can use them without configuration.
1003 (apply 'concat
(anything-c-format-preconfigured-anything))
1007 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1009 (defun anything-mini ()
1010 "Preconfigured `anything' lightweight version (buffer -> recentf)."
1012 (anything-other-buffer '(anything-c-source-buffers+ anything-c-source-recentf
)
1015 (defun anything-for-files ()
1016 "Preconfigured `anything' for opening files.
1017 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
1019 (anything-other-buffer anything-for-files-prefered-list
"*anything for files*"))
1022 (defun anything-recentf ()
1023 "Preconfigured `anything' for `recentf'."
1025 (anything-other-buffer 'anything-c-source-recentf
"*anything recentf*"))
1028 (defun anything-info-at-point ()
1029 "Preconfigured `anything' for searching info at point."
1031 (anything '(anything-c-source-info-elisp
1032 anything-c-source-info-cl
1033 anything-c-source-info-pages
)
1034 (thing-at-point 'symbol
) nil nil nil
"*anything info*"))
1037 (defun anything-info-emacs ()
1038 "Preconfigured anything for Emacs manual index."
1040 (anything-other-buffer 'anything-c-source-info-emacs
"*info emacs*"))
1043 (defun anything-show-kill-ring ()
1044 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
1045 You may bind this command to M-y."
1047 (anything-other-buffer 'anything-c-source-kill-ring
"*anything kill-ring*"))
1050 (defun anything-minibuffer-history ()
1051 "Preconfigured `anything' for `minibuffer-history'."
1053 (let ((enable-recursive-minibuffers t
))
1054 (anything-other-buffer 'anything-c-source-minibuffer-history
1055 "*anything minibuffer-history*")))
1058 (defun anything-gentoo ()
1059 "Preconfigured `anything' for gentoo linux."
1061 (anything-other-buffer '(anything-c-source-gentoo
1062 anything-c-source-use-flags
)
1063 "*anything gentoo*"))
1066 (defun anything-imenu ()
1067 "Preconfigured `anything' for `imenu'."
1069 (anything 'anything-c-source-imenu nil nil nil nil
"*anything imenu*"))
1072 (defun anything-google-suggest ()
1073 "Preconfigured `anything' for google search with google suggest."
1075 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
1078 (defun anything-yahoo-suggest ()
1079 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
1081 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
1083 ;;; Converted from anything-show-*-only
1085 (defun anything-for-buffers ()
1086 "Preconfigured `anything' for buffer."
1088 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
1091 (defun anything-buffers+ ()
1092 "Enhanced preconfigured `anything' for buffer."
1094 (anything-other-buffer 'anything-c-source-buffers
+ "*anything buffers*"))
1097 (defun anything-bbdb ()
1098 "Preconfigured `anything' for BBDB.
1102 http://bbdb.sourceforge.net/"
1104 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
1107 (defun anything-locate ()
1108 "Preconfigured `anything' for Locate.
1109 Note you can add locate command after entering pattern.
1110 See man locate for more infos."
1112 (anything-other-buffer 'anything-c-source-locate
"*anything locate*"))
1115 (defun anything-w3m-bookmarks ()
1116 "Preconfigured `anything' for w3m bookmark.
1118 Needs w3m and emacs-w3m.
1120 http://w3m.sourceforge.net/
1121 http://emacs-w3m.namazu.org/"
1123 (anything-other-buffer 'anything-c-source-w3m-bookmarks
1124 "*anything w3m bookmarks*"))
1127 (defun anything-firefox-bookmarks ()
1128 "Preconfigured `anything' for firefox bookmark.
1129 You will have to enable html bookmarks in firefox:
1130 open about:config in firefox and double click on this line to enable value \
1133 user_pref(\"browser.bookmarks.autoExportHTML\", false);
1135 You should have now:
1137 user_pref(\"browser.bookmarks.autoExportHTML\", true);
1139 After closing firefox, you will be able to browse you bookmarks.
1142 (anything-other-buffer 'anything-c-source-firefox-bookmarks
1143 "*Anything Firefox*"))
1146 (defun anything-colors ()
1147 "Preconfigured `anything' for color."
1149 (anything-other-buffer
1150 '(anything-c-source-colors anything-c-source-customize-face
)
1151 "*anything colors*"))
1154 (defun anything-bookmarks ()
1155 "Preconfigured `anything' for bookmarks."
1157 (anything-other-buffer 'anything-c-source-bookmarks
"*anything bookmarks*"))
1160 (defun anything-c-pp-bookmarks ()
1161 "Preconfigured `anything' for bookmarks (pretty-printed)."
1163 (anything-other-buffer '(anything-c-source-bookmarks-local
1164 anything-c-source-bookmarks-su
1165 anything-c-source-bookmarks-ssh
)
1166 "*anything pp bookmarks*"))
1169 (defun anything-c-insert-latex-math ()
1170 "Preconfigured anything for latex math symbols completion."
1172 (anything-other-buffer 'anything-c-source-latex-math
"*anything latex*"))
1175 (defun anything-register ()
1176 "Preconfigured `anything' for Emacs registers."
1178 (anything-other-buffer 'anything-c-source-register
"*anything register*"))
1181 (defun anything-man-woman ()
1182 "Preconfigured `anything' for Man and Woman pages."
1184 (anything-other-buffer 'anything-c-source-man-pages
"*Anything man woman*"))
1187 (defun anything-org-keywords ()
1188 "Preconfigured `anything' for org keywords."
1190 (anything-other-buffer 'anything-c-source-org-keywords
"*org keywords*"))
1193 (defun anything-emms ()
1194 "Preconfigured `anything' for emms sources."
1196 (anything '(anything-c-source-emms-streams
1197 anything-c-source-emms-files
1198 anything-c-source-emms-dired
)
1203 (defun anything-eev-anchors ()
1204 "Preconfigured `anything' for eev anchors."
1206 (anything-other-buffer 'anything-c-source-eev-anchor
"*Anything eev anchors*"))
1209 (defun anything-bm-list ()
1210 "Preconfigured `anything' for visible bookmarks.
1214 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
1216 (let ((anything-outline-using t
))
1217 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*")))
1220 (defun anything-timers ()
1221 "Preconfigured `anything' for timers."
1223 (anything-other-buffer '(anything-c-source-absolute-time-timers
1224 anything-c-source-idle-time-timers
)
1225 "*anything timers*"))
1228 (defun anything-list-emacs-process ()
1229 "Preconfigured `anything' for emacs process."
1231 (anything-other-buffer 'anything-c-source-emacs-process
"*anything process*"))
1234 (defun anything-occur ()
1235 "Preconfigured Anything for Occur source."
1237 (let ((anything-compile-source-functions
1238 ;; rule out anything-match-plugin because the input is one regexp.
1239 (delq 'anything-compile-source--match-plugin
1240 (copy-sequence anything-compile-source-functions
))))
1241 (anything-other-buffer 'anything-c-source-occur
"*Anything Occur*")))
1244 (defun anything-browse-code ()
1245 "Preconfigured anything to browse code."
1247 (anything-other-buffer 'anything-c-source-browse-code
"*Browse code*"))
1250 (defun anything-org-headlines ()
1251 "Preconfigured anything to show org headlines."
1253 (anything-other-buffer 'anything-c-source-org-headline
"*org headlines*"))
1255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1258 (defun anything-kill-buffers ()
1259 "Preconfigured `anything' to kill buffer you selected."
1262 '(((name .
"Kill Buffers")
1263 (candidates . anything-c-buffer-list
)
1265 ("Kill Buffer" .
(lambda (candidate)
1266 (kill-buffer candidate
)
1267 (anything-kill-buffers)
1272 (defun anything-c-query-replace-regexp (candidate)
1273 (let ((regexp (funcall (anything-attr 'regexp
))))
1274 (apply 'query-replace-regexp
1275 (anything-c-query-replace-args regexp
))))
1277 (defun anything-c-kill-regexp-as-sexp (candidate)
1278 (anything-c-regexp-kill-new
1279 (prin1-to-string (funcall (anything-attr 'regexp
)))))
1281 (defun anything-c-kill-regexp (candidate)
1282 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp
))))
1284 (defun anything-c-query-replace-args (regexp)
1285 "create arguments of `query-replace-regexp' action in `anything-regexp'."
1286 (let ((region-only (anything-region-active-p)))
1289 (query-replace-read-to regexp
1290 (format "Query replace %s regexp %s"
1291 (if anything-current-prefix-arg
"word " "")
1292 (if region-only
"in region " ""))
1294 anything-current-prefix-arg
1295 (when region-only
(region-beginning))
1296 (when region-only
(region-end)))))
1298 (defvar anything-c-source-regexp
1299 '((name .
"Regexp Builder")
1301 (anything-candidate-buffer anything-current-buffer
)))
1302 (candidates-in-buffer)
1303 (get-line . anything-c-regexp-get-line
)
1304 (persistent-action . anything-c-regexp-persistent-action
)
1305 (persistent-help .
"Show this line")
1308 (requires-pattern .
2)
1309 (mode-line .
"Press TAB to select action.")
1311 ;; I use here `anything-input' because `anything-pattern' is lost when
1312 ;; using actions from action buffer (otherwise no e.g from RET, C-e or C-j).
1313 ;; It seem `anything-select-action' reset `anything-pattern' to empty too early.
1314 ;; Though the regexp attribute stay defined (tested with *-attr-defined).
1316 (regexp .
(lambda () anything-input
))
1317 (action .
(("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp
)
1318 ("Query Replace Regexp" . anything-c-query-replace-regexp
)
1319 ("Kill Regexp" . anything-c-kill-regexp
)))))
1321 (defun anything-c-regexp-get-line (s e
)
1325 (format "%5d: %s" (line-number-at-pos (1- s
)) (buffer-substring s e
))
1327 (loop for i from
0 to
(1- (/ (length (match-data)) 2))
1328 collect
(format "\n %s'%s'"
1329 (if (zerop i
) "Group 0: " (format "Group %d: " i
))
1332 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
1333 ;; It is implementation problem of candidates-in-buffer.
1337 (defun anything-goto-line (lineno)
1338 "Goto LINENO without modifying outline visibility if needed."
1339 (flet ((gotoline (numline)
1340 (goto-char (point-min)) (forward-line (1- numline
))))
1341 (if (or (eq major-mode
'org-mode
)
1346 (gotoline lineno
))))
1348 (defun anything-c-regexp-persistent-action (pt)
1350 (anything-persistent-highlight-point))
1352 (defun anything-c-regexp-kill-new (input)
1354 (message "Killed: %s" input
))
1356 (defun anything-region-active-p ()
1357 (and transient-mark-mode mark-active
(/= (mark) (point))))
1359 (defun* anything-current-buffer-narrowed-p
(&optional
1360 (buffer anything-current-buffer
))
1361 "Check if BUFFER is narrowed.
1362 Default is `anything-current-buffer'."
1363 (with-current-buffer buffer
1364 (let ((beg (point-min))
1366 (total (buffer-size)))
1367 (or (/= beg
1) (/= end
(1+ total
))))))
1370 (defun anything-regexp ()
1371 "Preconfigured anything to build regexps and run query-replace-regexp \
1375 (let ((anything-compile-source-functions
1376 ;; rule out anything-match-plugin because the input is one regexp.
1377 (delq 'anything-compile-source--match-plugin
1378 (copy-sequence anything-compile-source-functions
))))
1379 (when (and (anything-region-active-p)
1380 ;; Don't narrow to region if buffer is already narrowed.
1381 (not (anything-current-buffer-narrowed-p)))
1382 (narrow-to-region (region-beginning) (region-end)))
1384 anything-c-source-regexp
1385 :buffer
"*anything regexp*"
1386 :prompt
"Regexp: "))))
1389 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1391 (defun anything-insert-buffer-name ()
1392 "Insert buffer name."
1394 (anything-insert-string
1395 (with-current-buffer anything-current-buffer
1396 (if buffer-file-name
(file-name-nondirectory buffer-file-name
)
1399 (defun anything-insert-symbol ()
1400 "Insert current symbol."
1402 (anything-insert-string
1403 (with-current-buffer anything-current-buffer
1405 (buffer-substring (beginning-of-thing 'symbol
)
1406 (end-of-thing 'symbol
))))))
1408 (defun anything-insert-selection ()
1409 "Insert current selection."
1411 (anything-insert-string
1412 (with-current-buffer anything-current-buffer
1413 (anything-get-selection))))
1415 (defun anything-show-buffer-only ()
1416 "[OBSOLETE] Only show sources about buffer.
1417 Use `anything-for-buffers' instead."
1419 (anything-set-source-filter '("Buffers")))
1421 (defun anything-show-bbdb-only ()
1422 "[OBSOLETE] Only show sources about BBDB.
1423 Use `anything-bbdb' instead."
1425 (anything-set-source-filter '("BBDB")))
1427 (defun anything-show-locate-only ()
1428 "[OBSOLETE] Only show sources about Locate.
1429 Use `anything-locate' instead."
1431 (anything-set-source-filter '("Locate")))
1433 (defun anything-show-info-only ()
1434 "[OBSOLETE] Only show sources about Info.
1435 Use `anything-info-at-point' instead."
1437 (anything-set-source-filter '("Info Pages"
1439 "Info Common-Lisp")))
1441 (defun anything-show-imenu-only ()
1442 "[OBSOLETE] Only show sources about Imenu.
1443 Use `anything-imenu' instead."
1445 (anything-set-source-filter '("Imenu")))
1447 (defun anything-show-files-only ()
1448 "[OBSOLETE] Only show sources about File.
1449 Use `anything-for-files' instead."
1451 (anything-set-source-filter '("File Name History"
1452 "Files from Current Directory"
1455 (defun anything-show-w3m-bookmarks-only ()
1456 "[OBSOLETE] Only show source about w3m bookmark.
1457 Use `anything-w3m-bookmarks' instead."
1459 (anything-set-source-filter '("W3m Bookmarks")))
1461 (defun anything-show-colors-only ()
1462 "[OBSOLETE] Only show source about color.
1463 Use `anything-colors' instead."
1465 (anything-set-source-filter '("Colors"
1466 "Customize Faces")))
1468 (defun anything-show-kill-ring-only ()
1469 "[OBSOLETE] Only show source about kill ring.
1470 Use `anything-show-kill-ring' instead."
1472 (anything-set-source-filter '("Kill Ring")))
1474 (defun anything-show-this-source-only ()
1475 "Only show this source."
1477 (setq anything-candidate-number-limit
9999)
1478 (anything-set-source-filter
1479 (list (assoc-default 'name
(anything-get-current-source)))))
1481 (defun anything-test-sources ()
1482 "List all anything sources for test.
1483 The output is sexps which are evaluated by \\[eval-last-sexp]."
1485 (with-output-to-temp-buffer "*Anything Test Sources*"
1486 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s
)))
1487 (apropos-internal "^anything-c-source" #'boundp
))
1488 (pop-to-buffer standard-output
)))
1490 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1491 ;;; For compatibility
1492 (unless (fboundp 'region-active-p
)
1493 (defun region-active-p ()
1494 "Return t if Transient Mark mode is enabled and the mark is active.
1496 Most commands that act on the region if it is active and
1497 Transient Mark mode is enabled, and on the text near point
1498 otherwise, should use `use-region-p' instead. That function
1499 checks the value of `use-empty-active-region' as well."
1500 (and transient-mark-mode mark-active
)))
1502 (defun anything-nest (&rest same-as-anything
)
1503 "Nested `anything'. If you use `anything' within `anything', use it."
1504 (with-selected-window (anything-window)
1505 (let (anything-current-position
1506 anything-current-buffer
1507 (orig-anything-buffer anything-buffer
)
1511 anything-compiled-sources
1512 anything-buffer-chars-modified-tick
1513 (anything-samewindow t
)
1514 (enable-recursive-minibuffers t
))
1516 (apply #'anything same-as-anything
)
1517 (anything-initialize-overlays orig-anything-buffer
)
1518 (add-hook 'post-command-hook
'anything-check-minibuffer-input
)))))
1520 (defun anything-displaying-source-names ()
1521 "Display sources name."
1522 (with-current-buffer anything-buffer
1523 (goto-char (point-min))
1525 while
(setq pos
(next-single-property-change (point) 'anything-header
))
1527 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
1528 do
(forward-line 1))))
1530 (defun anything-select-source ()
1533 (let ((default (assoc-default 'name
(anything-get-current-source)))
1534 (source-names (anything-displaying-source-names))
1535 (all-source-names (mapcar (lambda (s) (assoc-default 'name s
))
1536 (anything-get-sources))))
1537 (setq anything-candidate-number-limit
9999)
1539 (let (anything-source-filter)
1540 (anything-nest '(((name .
"Anything Source")
1541 (candidates . source-names
)
1542 (action . identity
))
1543 ((name .
"Anything Source (ALL)")
1544 (candidates . all-source-names
)
1545 (action . identity
)))
1547 default
"*anything select source*"))
1548 (anything-set-source-filter (list it
))
1549 (anything-set-source-filter nil
))))
1551 (defun anything-insert-string (str)
1553 (delete-minibuffer-contents)
1556 (defun anything-c-match-on-file-name (candidate)
1557 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1558 (string-match anything-pattern
(file-name-nondirectory candidate
)))
1560 (defun anything-c-match-on-directory-name (candidate)
1561 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1562 (anything-aif (file-name-directory candidate
)
1563 (string-match anything-pattern it
)))
1565 (defun anything-c-string-match (candidate)
1566 "Return non-nil if `anything-pattern' match CANDIDATE.
1567 The match is done with `string-match'."
1568 (string-match anything-pattern candidate
))
1570 ;; `anything-c-compose' is no more needed, it is for compatibility.
1571 (defalias 'anything-c-compose
'anything-compose
)
1573 (defun anything-c-skip-entries (list regexp
)
1574 "Remove entries which matches REGEXP from LIST."
1575 (remove-if (lambda (x) (and (stringp x
) (string-match regexp x
)))
1578 (defun anything-c-shadow-entries (list regexp
)
1579 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1580 (mapcar (lambda (file)
1581 ;; Add shadow face property to boring files.
1582 (let ((face (if (facep 'file-name-shadow
)
1584 ;; fall back to default on XEmacs
1586 (if (string-match regexp file
)
1587 (setq file
(propertize file
'face face
))))
1591 (defsubst anything-c-stringify
(str-or-sym)
1592 "Get string of STR-OR-SYM."
1593 (if (stringp str-or-sym
)
1595 (symbol-name str-or-sym
)))
1597 (defsubst anything-c-symbolify
(str-or-sym)
1598 "Get symbol of STR-OR-SYM."
1599 (if (symbolp str-or-sym
)
1601 (intern str-or-sym
)))
1603 (defun anything-c-describe-function (func)
1604 "FUNC is symbol or string."
1605 (describe-function (anything-c-symbolify func
)))
1607 (defun anything-c-describe-variable (var)
1608 "VAR is symbol or string."
1609 (describe-variable (anything-c-symbolify var
)))
1611 (defun anything-c-find-function (func)
1612 "FUNC is symbol or string."
1613 (find-function (anything-c-symbolify func
)))
1615 (defun anything-c-find-variable (var)
1616 "VAR is symbol or string."
1617 (find-variable (anything-c-symbolify var
)))
1619 (defun anything-c-kill-new (string &optional replace yank-handler
)
1620 "STRING is symbol or string."
1621 (kill-new (anything-c-stringify string
) replace yank-handler
))
1623 ;;; Toggle all marks.
1625 (defun anything-mark-all ()
1626 "Mark all visible unmarked candidates in current source."
1627 (with-anything-window
1629 (goto-char (anything-get-previous-header-pos))
1630 (anything-next-line)
1631 (let* ((next-head (anything-get-next-header-pos))
1634 (goto-char next-head
)
1637 (maxpoint (or end
(point-max))))
1638 (while (< (point) maxpoint
)
1639 (let ((prefix (get-text-property (point-at-bol) 'display
)))
1640 (when (and (not (anything-this-visible-mark))
1641 (not (or (string= prefix
"[?]")
1642 (string= prefix
"[@]"))))
1643 ;; FIXME: This is a bug in `anything-make-visible-mark'
1644 ;; it should not assume that overlay is on line and
1645 ;; BTW not use `anything-get-selection' to get
1646 ;; the real value of candidate.
1647 ;; So for the moment just mark this line.
1648 (anything-mark-current-line)
1649 ;; Don't mark possibles directories ending with . or ..
1650 (unless (string-match "\\.$" (anything-get-selection))
1651 (anything-make-visible-mark))))
1652 (forward-line 1) (end-of-line))))
1653 (anything-mark-current-line)
1654 (message "%s candidates marked" (length anything-marked-candidates
))))
1656 (defun anything-unmark-all ()
1657 "Unmark all candidates in all sources of current anything session."
1658 (with-anything-window
1659 (let ((len (length anything-marked-candidates
)))
1661 (anything-clear-visible-mark))
1662 (setq anything-marked-candidates nil
)
1663 (anything-mark-current-line)
1664 (message "%s candidates unmarked" len
))))
1666 (defun anything-toggle-all-marks ()
1668 Mark all visible candidates of current source or unmark all candidates
1669 visible or invisible in all sources of current anything session"
1671 (let ((marked (anything-marked-candidates)))
1672 (if (> (length marked
) 1)
1673 (anything-unmark-all)
1674 (anything-mark-all))))
1676 (define-key anything-map
(kbd "M-m") 'anything-toggle-all-marks
)
1678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1679 (defadvice eval-defun
(after anything-source-hack activate
)
1680 "See `anything-c-enable-eval-defun-hack'."
1681 (when anything-c-enable-eval-defun-hack
1682 (let ((varsym (save-excursion
1683 (beginning-of-defun)
1685 (when (memq (read (current-buffer)) '(defvar setq
))
1686 (read (current-buffer))))))
1687 (when (string-match "^anything-c-source-" (symbol-name varsym
))
1688 (anything varsym
)))))
1689 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1691 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1692 (defconst anything-c-create-summary-index-regexp
1693 "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$")
1694 (defun anything-c-create-summary ()
1695 "Create `anything' summary."
1697 (goto-char (point-min))
1699 while
(re-search-forward anything-c-create-summary-index-regexp nil t
)
1701 (cond ((setq it
(match-string-no-properties 1))
1703 ((setq it
(match-string-no-properties 2))
1705 ,(assoc-default 'name
(symbol-value (intern it
)))))
1706 ((setq it
(match-string-no-properties 3))
1708 ,(assoc-default 'name
(symbol-value (intern it
)))))))))
1710 ;; (find-epp (anything-c-create-summary))
1712 (defun anything-c-insert-summary ()
1713 "Insert `anything' summary."
1715 (goto-char (point-min))
1716 (search-forward ";; Below are complete source list you can setup in")
1718 (delete-region (point)
1719 (progn (search-forward ";;; Change log:" nil t
)
1720 (forward-line -
1) (point)))
1723 for
(kind . value
) in
(anything-c-create-summary)
1725 do
(cond ((eq kind
'section
)
1727 (align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))
1728 (insert ";; " value
":\n")
1731 (insert ";; `" (car value
) "' (" (cdr value
) ")\n")))
1732 finally
(align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))))
1733 ;; (anything-c-insert-summary)
1735 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1737 (defun anything-c-buffer-list ()
1738 "Return the list of names of buffers with boring buffers filtered out.
1739 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1740 The first buffer in the list will be the last recently used
1741 buffer that is not the current buffer."
1742 (let ((buffers (mapcar 'buffer-name
(buffer-list))))
1743 (append (cdr buffers
) (list (car buffers
)))))
1745 (defvar anything-c-source-buffers
1746 '((name .
"Buffers")
1747 (candidates . anything-c-buffer-list
)
1749 ;; (anything 'anything-c-source-buffers)
1751 (defvar anything-c-source-buffer-not-found
1752 '((name .
"Create buffer")
1755 ;; (anything 'anything-c-source-buffer-not-found)
1758 (defface anything-dir-heading
'((t (:foreground
"Blue" :background
"Pink")))
1759 "*Face used for directory headings in dired buffers."
1762 (defface anything-file-name
1763 '((t (:foreground
"Blue")))
1764 "*Face used for file names (without suffixes) in dired buffers."
1767 (defface anything-dir-priv
1768 '((t (:foreground
"DarkRed" :background
"LightGray")))
1769 "*Face used for directory privilege indicator (d) in dired buffers."
1772 (defvar anything-c-buffers-face1
'anything-dir-priv
)
1773 (defvar anything-c-buffers-face2
'font-lock-type-face
)
1774 (defvar anything-c-buffers-face3
'italic
)
1775 (eval-when-compile (require 'dired
))
1776 (defun anything-c-highlight-buffers (buffers)
1778 (loop for i in buffers
1779 if
(rassoc (get-buffer i
) dired-buffers
)
1780 collect
(propertize i
1781 'face anything-c-buffers-face1
1782 'help-echo
(car (rassoc (get-buffer i
) dired-buffers
)))
1783 if
(buffer-file-name (get-buffer i
))
1784 collect
(propertize i
1785 'face anything-c-buffers-face2
1786 'help-echo
(buffer-file-name (get-buffer i
)))
1787 if
(and (not (rassoc (get-buffer i
) dired-buffers
))
1788 (not (buffer-file-name (get-buffer i
))))
1789 collect
(propertize i
1790 'face anything-c-buffers-face3
)))
1792 (defvar anything-c-source-buffers
+
1793 '((name .
"Buffers")
1794 (candidates . anything-c-buffer-list
)
1796 (candidate-transformer anything-c-skip-current-buffer
1797 anything-c-highlight-buffers
1798 anything-c-skip-boring-buffers
)
1799 (persistent-action . anything-c-buffers
+-persistent-action
)
1800 (persistent-help .
"Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1802 (defun anything-c-buffers+-persistent-action
(name)
1804 (with-current-buffer item
1805 (if (and (buffer-modified-p)
1806 (buffer-file-name (current-buffer)))
1810 (kill-buffer item
))))
1812 (switch-to-buffer item
)))
1813 (if current-prefix-arg
1816 (anything-delete-current-selection))
1819 ;; (anything 'anything-c-source-buffers+)
1823 ;;; File name history
1824 (defvar anything-c-source-file-name-history
1825 '((name .
"File Name History")
1826 (candidates . file-name-history
)
1827 (match anything-c-match-on-file-name
1828 anything-c-match-on-directory-name
)
1830 ;; (anything 'anything-c-source-file-name-history)
1832 ;;; Files in current dir
1833 (defvar anything-c-source-files-in-current-dir
1834 '((name .
"Files from Current Directory")
1835 (candidates .
(lambda ()
1836 (with-current-buffer anything-current-buffer
1837 (directory-files (anything-c-current-directory)))))
1838 ;; volatile is not needed, I think.
1840 ;; (anything 'anything-c-source-files-in-current-dir)
1842 (defvar anything-c-files-face1
'anything-dir-priv
)
1843 (defvar anything-c-files-face2
'anything-file-name
)
1844 (defun anything-c-highlight-files (files)
1845 (loop for i in files
1846 if
(file-directory-p i
)
1847 collect
(propertize (file-name-nondirectory i
)
1848 'face anything-c-files-face1
1849 'help-echo
(expand-file-name i
))
1851 collect
(propertize (file-name-nondirectory i
)
1852 'face anything-c-files-face2
1853 'help-echo
(expand-file-name i
))))
1856 (defvar anything-c-source-files-in-current-dir
+
1857 '((name .
"Files from Current Directory")
1858 (candidates .
(lambda ()
1859 (with-current-buffer anything-current-buffer
1860 (directory-files (anything-c-current-directory) t
))))
1861 (candidate-transformer anything-c-highlight-files
)
1862 ;; volatile is not needed, I think.
1865 ;; (anything 'anything-c-source-files-in-current-dir+)
1867 ;;; Anything replacement of file name completion for `find-file' and friends.
1869 (defvar anything-c-find-files-doc-header
(format " (`%s':Go to precedent level)"
1870 (if window-system
"C-." "C-l"))
1871 "*The doc that is inserted in the Name header of a find-files or dired source.")
1873 (defvar anything-c-source-find-files
1874 `((name .
,(concat "Find Files" anything-c-find-files-doc-header
))
1875 ;; It is needed for filenames with capital letters
1879 ;(require 'dired-aux)
1880 (setq ffap-newfile-prompt t
)
1881 ;; This is needed when connecting with emacsclient -t
1882 ;; on remote host that have an anything started on a window-system.
1883 ;; i.e when `C-.' is already loaded.
1884 (unless window-system
1885 (define-key anything-map
(kbd "C-l") 'anything-find-files-down-one-level
))))
1886 (candidates . anything-find-files-get-candidates
)
1887 (filtered-candidate-transformer anything-c-find-files-transformer
)
1888 (persistent-action . anything-find-files-persistent-action
)
1889 (persistent-help .
"Hit1 Expand Candidate, Hit2 or (C-u) Find file")
1891 (candidate-number-limit .
9999)
1892 (action-transformer . anything-find-files-action-transformer
)
1896 `(("Find File" . anything-c-find-file-or-marked
)
1897 ("Find file in Dired" . anything-c-point-file-in-dired
)
1898 ,(and (locate-library "elscreen")
1899 '("Find file in Elscreen" . anything-elscreen-find-file
))
1900 ("Complete at point"
1901 . anything-c-insert-file-name-completion-at-point
)
1902 ("Open file externally `C-u to choose'"
1903 . anything-c-open-file-externally
)
1904 ("Grep File(s) `C-u Recurse'"
1905 .
(lambda (candidate)
1906 (if anything-current-prefix-arg
1907 (anything-do-grep1 (anything-marked-candidates) 'recurse
)
1908 (anything-do-grep1 (anything-marked-candidates)))))
1909 ("Switch to Eshell" . anything-ff-switch-to-eshell
)
1910 ("Eshell command on file(s)" . anything-find-files-eshell-command-on-file
)
1911 ("Ediff File" . anything-find-files-ediff-files
)
1912 ("Ediff Merge File" . anything-find-files-ediff-merge-files
)
1913 ("Delete File(s)" . anything-delete-marked-files
)
1914 ("Copy file(s) `C-u to follow'" . anything-find-files-copy
)
1915 ("Rename file(s) `C-u to follow'" . anything-find-files-rename
)
1916 ("Symlink files(s) `C-u to follow'" . anything-find-files-symlink
)
1917 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink
)
1918 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink
)
1919 ("Find file other window" . find-file-other-window
)
1920 ("Find file other frame" . find-file-other-frame
)
1921 ("Find file as root" . anything-find-file-as-root
))))))
1922 ;; (anything 'anything-c-source-find-files)
1924 (defun anything-find-files-set-prompt-for-action (prompt files
)
1925 "Set prompt for action in `anything-find-files'."
1926 (let ((len (length files
)))
1928 (format "%s * %d Files to: " prompt len
)
1929 (format "%s %s to: " prompt
(car files
)))))
1931 (defun anything-find-files-do-action (action)
1932 "Generic function for creating action from `anything-c-source-find-files'.
1933 ACTION must be an action supported by `anything-dired-action'."
1934 (let* ((ifiles (anything-marked-candidates))
1935 (buf anything-current-buffer
)
1936 (prompt (anything-find-files-set-prompt-for-action
1937 (capitalize (symbol-name action
)) ifiles
))
1938 (parg anything-current-prefix-arg
)
1939 (dest (anything-c-read-file-name
1941 :initial-input
(car anything-ff-history
)
1942 :history
(anything-find-files-history :comp-read nil
)))
1943 (win-conf (current-window-configuration)))
1945 ;; Create temporarily a dired buffer to call dired functions.
1946 (with-current-buffer (dired anything-ff-default-directory
)
1947 (let ((dir-buf (current-buffer)))
1948 (anything-dired-action
1949 dest
:files ifiles
:action action
:follow parg
)
1950 ;; If we have started in a dired buffer, don't kill it.
1951 (unless (eq dir-buf
(get-buffer buf
))
1952 (kill-buffer dir-buf
))))
1953 (unless parg
(set-window-configuration win-conf
)))))
1955 (defun anything-find-files-copy (candidate)
1956 "Copy files from `anything-find-files'."
1957 (anything-find-files-do-action 'copy
))
1959 (defun anything-find-files-rename (candidate)
1960 "Rename files from `anything-find-files'."
1961 (anything-find-files-do-action 'rename
))
1963 (defun anything-find-files-symlink (candidate)
1964 "Symlink files from `anything-find-files'."
1965 (anything-find-files-do-action 'symlink
))
1967 (defun anything-find-files-relsymlink (candidate)
1968 "Relsymlink files from `anything-find-files'."
1969 (anything-find-files-do-action 'relsymlink
))
1971 (defun anything-find-files-hardlink (candidate)
1972 "Hardlink files from `anything-find-files'."
1973 (anything-find-files-do-action 'hardlink
))
1975 (defun anything-find-files-byte-compile (candidate)
1976 "Byte compile elisp files from `anything-find-files'."
1977 (let ((files (anything-marked-candidates))
1978 (parg anything-current-prefix-arg
))
1979 (loop for fname in files
1980 do
(byte-compile-file fname parg
))))
1982 (defun anything-find-files-load-files (candidate)
1983 "Load elisp files from `anything-find-files'."
1984 (let ((files (anything-marked-candidates)))
1985 (loop for fname in files
1988 (defun anything-find-files-ediff-files (candidate)
1989 "Default action to ediff files in `anything-find-files'."
1992 (anything-c-read-file-name
1993 (format "Ediff `%s' With File: " (file-name-nondirectory candidate
)))))
1995 (defun anything-find-files-ediff-merge-files (candidate)
1996 "Default action to ediff merge files in `anything-find-files'."
1999 (anything-c-read-file-name
2000 (format "Ediff Merge `%s' With File: "
2001 (file-name-nondirectory candidate
)))))
2003 (defvar eshell-command-aliases-list nil
)
2004 (declare-function eshell-read-aliases-list
"em-alias")
2005 (defun anything-find-files-eshell-command-on-file (candidate)
2006 "Run `eshell-command' on file CANDIDATE possibly with an eshell alias.
2008 If `eshell' or `eshell-command' have not been run once, `eshell-command-aliases-list'
2009 will not be loaded first time you use this."
2010 (when (or eshell-command-aliases-list
2011 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
2012 (and eshell-command-aliases-list
(eshell-read-aliases-list))
2013 (let ((cand-list (anything-marked-candidates))
2014 (default-directory anything-ff-default-directory
)
2015 (command (anything-comp-read
2017 (loop for
(a . c
) in eshell-command-aliases-list
2018 when
(string-match "\\$1$" (car c
))
2022 for com
= (concat command
" " (shell-quote-argument i
))
2023 do
(eshell-command com
)))))
2026 (declare-function eshell-send-input
"esh-mode" (&optional use-region queue-p no-newline
))
2027 (defun anything-ff-switch-to-eshell (candidate)
2028 "Switch to eshell and cd to `anything-ff-default-directory'."
2029 (flet ((cd-eshell ()
2030 (goto-char (point-max))
2032 (format "cd %s" (shell-quote-argument
2033 anything-ff-default-directory
)))
2034 (eshell-send-input)))
2035 (if (get-buffer "*eshell*")
2037 (switch-to-buffer "*eshell*")
2039 (call-interactively 'eshell
)
2042 (defun* anything-reduce-file-name
(fname level
&key unix-close expand
)
2043 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
2044 If LEVEL is positive reduce from end else from beginning.
2045 If UNIX-CLOSE is non--nil close filename with /.
2046 If EXPAND is non--nil expand-file-name."
2047 (let* ((exp-fname (expand-file-name fname
))
2048 (fname-list (split-string (if (or (string= fname
"~/") expand
)
2049 exp-fname fname
) "/" t
))
2050 (len (length fname-list
))
2051 (pop-list (if (< level
0)
2052 (subseq fname-list
(* level -
1))
2053 (subseq fname-list
0 (- len level
))))
2054 (result (mapconcat 'identity pop-list
"/"))
2055 (empty (string= result
"")))
2056 (when unix-close
(setq result
(concat result
"/")))
2057 (if (string-match "^~" result
)
2058 (if (string= result
"~/") "~/" result
)
2060 (if empty
"../" (concat "../" result
))
2061 (cond ((eq system-type
'windows-nt
)
2062 (if empty
"c:/" result
))
2065 (concat "/" result
)))))))
2067 (defun anything-file-completion-source-p ()
2068 "Test if current source is a dired or find-files source."
2069 (let ((ff-sources '("Find Files" "Copy Files"
2070 "Read File Name History"
2071 "Rename Files" "Symlink Files"
2072 "Hardlink Files" "Write File"
2073 "Insert File" "Read file name"))
2074 (cur-source (cdr (assoc 'name
(anything-get-current-source)))))
2075 (loop for i in ff-sources
2076 thereis
(string= cur-source
(concat i anything-c-find-files-doc-header
)))))
2078 (defun anything-find-files-down-one-level (arg)
2079 "Go down one level like unix command `cd ..'.
2080 If prefix numeric arg is given go ARG level down."
2082 (when (anything-file-completion-source-p)
2083 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
2084 :unix-close t
:expand t
)))
2085 (with-selected-window (minibuffer-window)
2086 (delete-minibuffer-contents)
2087 (insert new-pattern
)))))
2089 ;; `C-.' doesn't work in terms use `C-l' instead.
2091 (define-key anything-map
(kbd "C-.") 'anything-find-files-down-one-level
)
2092 (define-key anything-map
(kbd "C-l") 'anything-find-files-down-one-level
))
2094 (defun anything-c-point-file-in-dired (file)
2095 "Put point on filename FILE in dired buffer."
2096 (dired (file-name-directory file
))
2097 (dired-goto-file file
))
2099 (defun anything-create-tramp-name (fname)
2100 "Build filename for `anything-pattern' like /su:: or /sudo::."
2101 (apply #'tramp-make-tramp-file-name
2102 (loop with v
= (tramp-dissect-file-name fname
)
2103 for i across v collect i
)))
2105 (defun* anything-ff-set-pattern
(pattern)
2106 (let ((methods (mapcar 'car tramp-methods
))
2107 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
2108 cur-method tramp-name
)
2109 (cond ((string-match "^~" pattern
)
2110 (replace-match (getenv "HOME") nil t pattern
))
2111 ;; Match "/method:maybe_hostname:"
2112 ((and (string-match reg pattern
)
2113 (setq cur-method
(match-string 1 pattern
))
2114 (member cur-method methods
))
2115 (setq tramp-name
(anything-create-tramp-name (match-string 0 pattern
)))
2116 (replace-match tramp-name nil t pattern
))
2117 ;; Match "/hostname:"
2118 ((and (string-match tramp-file-name-regexp pattern
)
2119 (setq cur-method
(match-string 1 pattern
))
2120 (and cur-method
(not (member cur-method methods
))))
2121 (setq tramp-name
(anything-create-tramp-name (match-string 0 pattern
)))
2122 (replace-match tramp-name nil t pattern
))
2123 ;; Match "/method:" in this case don't try to connect.
2124 ((and (not (string-match reg pattern
))
2125 (string-match tramp-file-name-regexp pattern
)
2126 (member (match-string 1 pattern
) methods
))
2127 "Invalid tramp file name") ; Write in anything-buffer.
2128 ;; Return PATTERN unchanged.
2131 (defvar anything-ff-default-directory nil
)
2132 (defvar anything-ff-history nil
)
2133 (defvar anything-ff-history-max-length
30
2134 "*Number of elements shown in `anything-find-files' history.")
2135 (defun anything-find-files-get-candidates ()
2136 "Create candidate list for `anything-c-source-find-files'."
2137 (let* ((path (anything-ff-set-pattern anything-pattern
))
2138 (path-name-dir (file-name-directory path
))
2139 (tramp-verbose anything-tramp-verbose
)) ; No tramp message when 0.
2140 (set-text-properties 0 (length path
) nil path
)
2141 (if (member 'anything-compile-source--match-plugin
2142 anything-compile-source-functions
)
2143 (setq anything-pattern path
)
2144 (setq anything-pattern
(replace-regexp-in-string " " ".*" path
)))
2145 (setq anything-ff-default-directory
(if (string= anything-pattern
"")
2146 (if (eq system-type
'windows-nt
) "c:/" "/")
2147 (unless (string-match ffap-url-regexp path
)
2149 (cond ((or (string= path
"Invalid tramp file name")
2150 (file-regular-p path
)
2151 (and (not (file-exists-p path
)) (string-match "/$" path
))
2152 (and ffap-url-regexp
(string-match ffap-url-regexp path
)))
2154 ((string= anything-pattern
"") (directory-files "/" t
))
2155 ((file-directory-p path
) (directory-files path t
))
2159 (directory-files (file-name-directory path
) t
))))))
2161 (defun anything-ff-save-history ()
2162 "Store the last value of `anything-ff-default-directory' in `anything-ff-history'."
2163 (when anything-ff-default-directory
2164 (push anything-ff-default-directory anything-ff-history
)))
2165 (add-hook 'anything-cleanup-hook
'anything-ff-save-history
)
2167 (defface anything-dired-symlink-face
2168 '((t (:foreground
"DarkOrange")))
2169 "*Face used for symlinks in `anything-find-files'."
2172 (defface anything-ffiles-prefix-face
2173 '((t (:background
"yellow" :foreground
"black")))
2174 "*Face used to prefix new file or url paths in `anything-find-files'."
2177 (defun anything-c-prefix-filename (fname &optional image
)
2178 "Return fname FNAME prefixed with icon IMAGE."
2179 (let* ((img-name (and image
(expand-file-name
2180 image anything-c-find-files-icons-directory
)))
2181 (img (and image
(create-image img-name
)))
2182 (prefix-img (and image
(propertize " " 'display img
)))
2183 (prefix-new (propertize
2185 (propertize "[?]" 'face
'anything-ffiles-prefix-face
)))
2186 (prefix-url (propertize
2188 (propertize "[@]" 'face
'anything-ffiles-prefix-face
))))
2189 (cond ((or (file-exists-p fname
)
2190 (file-symlink-p fname
))
2191 (if image
(concat prefix-img fname
) fname
))
2192 ((string-match ffap-url-regexp fname
) (concat prefix-url
" " fname
))
2193 (t (concat prefix-new
" " fname
)))))
2195 (defun anything-c-find-files-transformer (files sources
)
2196 "Selector of transformer to use for `anything-c-source-find-files'."
2197 (if (and (window-system) anything-c-find-files-show-icons
)
2198 (anything-c-highlight-ffiles1 files sources
)
2199 (anything-c-highlight-ffiles files sources
)))
2201 (defun anything-c-highlight-ffiles (files sources
)
2202 "Candidate transformer for `anything-c-source-find-files' without icons."
2203 (loop for i in files
2204 collect
(cond ((file-symlink-p i
)
2206 (anything-c-prefix-filename
2207 (propertize i
'face
'anything-dired-symlink-face
2208 'help-echo
(file-truename i
)))
2210 ((file-directory-p i
)
2212 (anything-c-prefix-filename
2213 (propertize i
'face anything-c-files-face1
))
2217 (anything-c-prefix-filename
2218 (propertize i
'face anything-c-files-face2
))
2221 (defsubst anything-c-highlight-ffiles1
(files sources
)
2222 "Candidate transformer for `anything-c-source-find-files' that show icons."
2223 (loop for i in files
2224 for af
= (file-name-nondirectory i
)
2225 collect
(cond ( ;; Files.
2226 (eq nil
(car (file-attributes i
)))
2227 (cons (anything-c-prefix-filename
2228 (propertize i
'face anything-c-files-face2
)
2231 ( ;; Empty directories.
2232 (and (eq t
(car (file-attributes i
)))
2233 ;; Be sure to have permission to list content.
2237 i nil directory-files-no-dot-files-regexp t
))))
2238 (cons (anything-c-prefix-filename
2239 (propertize i
'face anything-c-files-face1
)
2242 ( ;; Open directories.
2243 (and (eq t
(car (file-attributes i
))) (get-buffer af
))
2244 (cons (anything-c-prefix-filename
2245 (propertize i
'face anything-c-files-face1
)
2248 (;; Closed directories.
2249 (eq t
(car (file-attributes i
)))
2250 (cons (anything-c-prefix-filename
2251 (propertize i
'face anything-c-files-face1
)
2254 ( ;; Open Symlinks directories.
2255 (and (stringp (car (file-attributes i
)))
2256 (file-directory-p i
) (get-buffer af
))
2257 (cons (anything-c-prefix-filename
2258 (propertize i
'face
'anything-dired-symlink-face
2259 'help-echo
(file-truename i
)) "open.xpm")
2261 ( ;; Closed Symlinks directories.
2262 (and (stringp (car (file-attributes i
))) (file-directory-p i
))
2263 (cons (anything-c-prefix-filename
2264 (propertize i
'face
'anything-dired-symlink-face
2265 'help-echo
(file-truename i
)) "close.xpm")
2267 ( ;; Files symlinks.
2268 (stringp (car (file-attributes i
)))
2269 (cons (anything-c-prefix-filename
2270 (propertize i
'face
'anything-dired-symlink-face
2271 'help-echo
(file-truename i
))
2275 (defun anything-find-files-action-transformer (actions candidate
)
2276 "Action transformer for `anything-c-source-find-files'."
2277 (cond ((with-current-buffer anything-current-buffer
(eq major-mode
'message-mode
))
2278 (append actions
'(("Gnus attach file(s)" . anything-ff-gnus-attach-files
))))
2279 ((string-match (image-file-name-regexp) candidate
)
2281 '(("Rotate image right" . anything-ff-rotate-image-right
)
2282 ("Rotate image left" . anything-ff-rotate-image-left
))))
2283 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
2284 (car it
) candidate
))
2285 (append actions
'(("Byte compile lisp file(s) `C-u to load'"
2286 . anything-find-files-byte-compile
)
2287 ("Load File(s)" . anything-find-files-load-files
))))
2288 ((and (string-match "\.html$" candidate
)
2289 (file-exists-p candidate
))
2290 (append actions
'(("Browse url file" . browse-url-of-file
))))
2293 (defun anything-ff-gnus-attach-files (candidate)
2294 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
2295 (let ((flist (anything-marked-candidates)))
2296 (gnus-dired-attach flist
)))
2298 (defun anything-ff-rotate-current-image1 (file &optional num-arg
)
2299 "Rotate current image at NUM-ARG degrees."
2300 (if (executable-find "mogrify")
2302 (shell-command (format "mogrify -rotate %s %s" (or num-arg
90) file
))
2303 (when (buffer-live-p image-dired-display-image-buffer
)
2304 (kill-buffer image-dired-display-image-buffer
))
2305 (image-dired-display-image file
)
2307 (display-buffer (get-buffer image-dired-display-image-buffer
)))
2308 (error "mogrify not found")))
2310 (defun anything-ff-rotate-image-left (candidate)
2311 "Rotate image file CANDIDATE left.
2312 This affect directly file CANDIDATE."
2313 (anything-ff-rotate-current-image1 candidate -
90))
2315 (defun anything-ff-rotate-image-right (candidate)
2316 "Rotate image file CANDIDATE right.
2317 This affect directly file CANDIDATE."
2318 (anything-ff-rotate-current-image1 candidate
))
2320 (defun anything-find-files-persistent-action (candidate)
2321 "Open subtree CANDIDATE without quitting anything.
2322 If CANDIDATE is not a directory expand CANDIDATE filename.
2323 If CANDIDATE is alone, open file CANDIDATE filename.
2325 First hit on C-z expand CANDIDATE second hit open file.
2326 If a prefix arg is given or `anything-follow-mode' is on open file."
2327 (let ((follow (buffer-local-value
2328 'anything-follow-mode
2329 (get-buffer-create anything-buffer
)))
2330 (new-pattern (anything-get-selection))
2331 (num-lines-buf (with-current-buffer anything-buffer
2332 (count-lines (point-min) (point-max)))))
2333 (flet ((insert-in-minibuffer (fname)
2334 (with-selected-window (minibuffer-window)
2336 (delete-minibuffer-contents)
2337 (set-text-properties 0 (length fname
) nil fname
)
2339 (cond (;; A symlink directory, expand it's truename.
2340 (and (file-directory-p candidate
) (file-symlink-p candidate
))
2341 (insert-in-minibuffer (file-name-as-directory
2343 (expand-file-name candidate
)))))
2344 ;; A directory, open it.
2345 ((file-directory-p candidate
)
2346 (insert-in-minibuffer (file-name-as-directory
2347 (expand-file-name candidate
))))
2348 ;; A symlink file, expand to it's true name. (first hit)
2349 ((file-symlink-p candidate
)
2350 (insert-in-minibuffer (file-truename candidate
)))
2351 ;; A regular file, expand it, (first hit)
2352 ((and (>= num-lines-buf
3) (not current-prefix-arg
) (not follow
))
2353 (insert-in-minibuffer new-pattern
))
2354 ;; An image file and it is the second hit on C-z,
2355 ;; show the file in `image-dired'.
2356 ((string-match (image-file-name-regexp) candidate
)
2357 (when (buffer-live-p image-dired-display-image-buffer
)
2358 (kill-buffer image-dired-display-image-buffer
))
2359 (image-dired-display-image candidate
)
2361 (display-buffer image-dired-display-image-buffer
))
2362 ;; Allow browsing archive on avfs fs.
2363 ;; Assume volume is already mounted with mountavfs.
2364 ((and anything-ff-avfs-directory
2366 (regexp-quote (expand-file-name anything-ff-avfs-directory
))
2367 (file-name-directory candidate
))
2368 (anything-ff-file-compressed-p candidate
))
2369 (insert-in-minibuffer (concat candidate
"#")))
2370 ;; On second hit we open file.
2371 (t (find-file candidate
))))))
2373 (defvar anything-ff-avfs-directory nil
2374 "*The default avfs directory, usually '.avfs'.
2375 When this is set you will be able to expand archive filenames with `C-z'
2376 inside an avfs directory mounted with mountavfs.
2377 See <http://sourceforge.net/projects/avf/>.")
2378 (defvar anything-ff-file-compressed-list
'("gz" "bz2" "zip" "7z")
2379 "*Minimal list of compressed files extension.")
2380 (defun anything-ff-file-compressed-p (candidate)
2381 "Whether CANDIDATE is a compressed file or not."
2382 (member (file-name-extension candidate
)
2383 anything-ff-file-compressed-list
))
2385 (defun anything-c-insert-file-name-completion-at-point (candidate)
2386 "Insert file name completion at point."
2387 (if buffer-read-only
2388 (error "Error: Buffer `%s' is read-only" (buffer-name))
2389 (let* ((end (point))
2390 (guess (thing-at-point 'filename
))
2391 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess
)
2392 (string-match "^[^\~]" guess
))))
2393 (set-text-properties 0 (length candidate
) nil candidate
)
2394 (if (and guess
(not (string= guess
"")) (string-match "^~\\|/.*" guess
))
2396 (search-backward guess
(- (point) (length guess
)))
2397 (delete-region (point) end
)
2399 (insert (expand-file-name candidate
))
2400 (insert (abbreviate-file-name candidate
))))
2401 (error "Aborting completion: No valid file name at point")))))
2403 (defun anything-find-files1 (fname)
2404 "Find FNAME with `anything' completion.
2405 Like `find-file' but with `anything' support.
2406 Use it for non--interactive calls of `anything-find-files'."
2407 (when (get-buffer anything-action-buffer
)
2408 (kill-buffer anything-action-buffer
))
2409 (let ((anything-mp-highlight-delay nil
))
2410 (anything :sources
'anything-c-source-find-files
2412 :prompt
"Find Files or Url: "
2413 :buffer
"*Anything Find Files*")))
2415 (defun* anything-find-files-history
(&key
(comp-read t
))
2416 "The `anything-find-files' history.
2417 Show the first `anything-ff-history-max-length' elements of `anything-ff-history'
2418 in an `anything-comp-read'."
2419 (let ((history (when anything-ff-history
2420 (loop with dup for i in anything-ff-history
2421 unless
(member i dup
) collect i into dup
2422 finally return dup
)))) ; Remove dups.
2424 (setq anything-ff-history
2425 (if (>= (length history
) anything-ff-history-max-length
)
2426 (subseq history
0 anything-ff-history-max-length
)
2430 "Switch to Directory: "
2432 :name
"Anything Find Files History"
2434 anything-ff-history
))))
2436 (defun anything-find-files-initial-input (&optional input
)
2437 "Return INPUT if present, otherwise try to guess it."
2438 (or (and input
(expand-file-name input
))
2439 (anything-find-files-input
2441 (thing-at-point 'filename
))))
2444 (defun anything-find-files ()
2445 "Preconfigured `anything' for anything implementation of `find-file'.
2446 Called with a prefix arg show history if some.
2447 Don't call it from programs, use `anything-find-files1' instead.
2448 This is the starting point for nearly all actions you can do on files."
2450 (let ((any-input (if (and current-prefix-arg anything-ff-history
)
2451 (anything-find-files-history)
2452 (anything-find-files-initial-input))))
2453 (anything-find-files1 any-input
)))
2455 (defun anything-c-current-directory ()
2456 "Return current-directory name at point.
2457 Useful in dired buffers when there is inserted subdirs."
2458 (if (eq major-mode
'dired-mode
)
2459 (dired-current-directory)
2462 (defun anything-find-files-input (fap tap
)
2463 "Default input of `anything-find-files'."
2464 (let* ((def-dir (anything-c-current-directory))
2465 (lib (anything-find-library-at-point))
2466 (file-p (and fap
(file-exists-p fap
)
2468 (file-name-directory (expand-file-name tap def-dir
)))))
2470 (file-p (expand-file-name tap def-dir
))
2472 (or input
(expand-file-name def-dir
))))
2474 (defun anything-find-library-at-point ()
2475 "Try to find library path at point.
2476 Find inside `require' and `declare-function' sexp."
2477 (require 'find-func
)
2478 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t
)))
2479 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t
)))
2480 (sexp (and beg-sexp end-sexp
2481 (buffer-substring-no-properties
2482 (1+ beg-sexp
) (1- end-sexp
)))))
2484 (cond ((and sexp
(string-match "require \'.+[^)]" sexp
))
2486 (replace-regexp-in-string
2488 ;; If require use third arg, ignore it,
2489 ;; always use library path found in `load-path'.
2490 (second (split-string (match-string 0 sexp
))))))
2491 ((and sexp
(string-match-p "^declare-function" sexp
))
2493 (replace-regexp-in-string
2495 (third (split-string sexp
)))))
2498 ;;; Anything completion for `write-file'.==> C-x C-w
2499 (defvar anything-c-source-write-file
2500 `((name .
,(concat "Write File" anything-c-find-files-doc-header
))
2501 ;; It is needed for filenames with capital letters
2503 (candidates . anything-find-files-get-candidates
)
2504 (filtered-candidate-transformer anything-c-find-files-transformer
)
2505 (persistent-action . anything-find-files-persistent-action
)
2506 (persistent-help .
"Expand Candidate")
2509 (("Write File" .
(lambda (candidate)
2510 (write-file candidate
'confirm
)))))))
2513 (defun anything-write-file ()
2514 "Preconfigured `anything' providing completion for `write-file'."
2516 (anything 'anything-c-source-write-file
2517 (expand-file-name default-directory
)
2518 "Write buffer to file: " nil nil
"*Anything write file*"))
2520 ;;; Anything completion for `insert-file'.==> C-x i
2521 (defvar anything-c-source-insert-file
2522 `((name .
,(concat "Insert File" anything-c-find-files-doc-header
))
2523 ;; It is needed for filenames with capital letters
2525 (candidates . anything-find-files-get-candidates
)
2526 (filtered-candidate-transformer anything-c-find-files-transformer
)
2527 (persistent-action . anything-find-files-persistent-action
)
2528 (persistent-help .
"Expand Candidate")
2531 (("Insert File" .
(lambda (candidate)
2532 (when (y-or-n-p (format "Really insert %s in %s "
2533 candidate anything-current-buffer
))
2534 (insert-file-contents candidate
))))))))
2537 (defun anything-insert-file ()
2538 "Preconfigured `anything' providing completion for `insert-file'."
2540 (anything 'anything-c-source-insert-file
2541 (expand-file-name default-directory
)
2542 "Insert file: " nil nil
"*Anything insert file*"))
2544 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
2545 (defvar anything-c-source-copy-files
2546 `((name .
,(concat "Copy Files" anything-c-find-files-doc-header
))
2547 ;; It is needed for filenames with capital letters
2549 (candidates . anything-find-files-get-candidates
)
2550 (filtered-candidate-transformer anything-c-find-files-transformer
)
2551 (persistent-action . anything-find-files-persistent-action
)
2552 (persistent-help .
"Expand Candidate")
2556 .
(lambda (candidate)
2557 (anything-dired-action candidate
:action
'copy
)))
2559 .
(lambda (candidate)
2560 (anything-dired-action candidate
:action
'copy
:follow t
)))))))
2563 (defvar anything-c-source-rename-files
2564 `((name .
,(concat "Rename Files" anything-c-find-files-doc-header
))
2565 ;; It is needed for filenames with capital letters
2567 (candidates . anything-find-files-get-candidates
)
2568 (filtered-candidate-transformer anything-c-find-files-transformer
)
2569 (persistent-action . anything-find-files-persistent-action
)
2570 (persistent-help .
"Expand Candidate")
2574 .
(lambda (candidate)
2575 (anything-dired-action candidate
:action
'rename
)))
2576 ("Rename and Follow"
2577 .
(lambda (candidate)
2578 (anything-dired-action candidate
:action
'rename
:follow t
)))))))
2580 (defvar anything-c-source-symlink-files
2581 `((name .
,(concat "Symlink Files" anything-c-find-files-doc-header
))
2582 ;; It is needed for filenames with capital letters
2584 (candidates . anything-find-files-get-candidates
)
2585 (filtered-candidate-transformer anything-c-find-files-transformer
)
2586 (persistent-action . anything-find-files-persistent-action
)
2587 (persistent-help .
"Expand Candidate")
2591 .
(lambda (candidate)
2592 (anything-dired-action candidate
:action
'symlink
)))
2594 .
(lambda (candidate)
2595 (anything-dired-action candidate
:action
'relsymlink
)))))))
2598 (defvar anything-c-source-hardlink-files
2599 `((name .
,(concat "Hardlink Files" anything-c-find-files-doc-header
))
2600 ;; It is needed for filenames with capital letters
2602 (candidates . anything-find-files-get-candidates
)
2603 (filtered-candidate-transformer anything-c-find-files-transformer
)
2604 (persistent-action . anything-find-files-persistent-action
)
2605 (persistent-help .
"Expand Candidate")
2609 .
(lambda (candidate)
2610 (anything-dired-action candidate
:action
'hardlink
)))))))
2613 (defun* anything-dired-action
(candidate &key action follow
(files (dired-get-marked-files)))
2614 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
2615 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
2616 (let ((fn (case action
2617 ('copy
'dired-copy-file
)
2618 ('rename
'dired-rename-file
)
2619 ('symlink
'make-symbolic-link
)
2620 ('relsymlink
'dired-make-relative-symlink
)
2621 ('hardlink
'dired-hardlink
)))
2622 (marker (case action
2623 ((copy rename
) dired-keep-marker-copy
)
2624 ('symlink dired-keep-marker-symlink
)
2625 ('relsymlink dired-keep-marker-relsymlink
)
2626 ('hardlink dired-keep-marker-hardlink
))))
2628 fn
(symbol-name action
) files
2629 ;; CANDIDATE is the destination.
2630 (if (file-directory-p candidate
)
2631 ;; When CANDIDATE is a directory, build file-name in this directory.
2632 ;; Else we use CANDIDATE.
2634 (expand-file-name (file-name-nondirectory from
) candidate
))
2635 #'(lambda (from) candidate
))
2638 (let* ((moved-flist (anything-get-dest-fnames-from-list files candidate
))
2639 (fname (car moved-flist
)))
2642 (setq anything-ff-cand-to-mark moved-flist
)
2643 (anything-find-files1 candidate
))
2644 (setq anything-ff-cand-to-mark nil
))))))
2647 (defvar anything-ff-cand-to-mark nil
)
2649 (defun anything-get-dest-fnames-from-list (flist dest-cand
)
2650 "Transform filenames of FLIST to abs of DEST-CAND."
2651 ;; At this point files have been renamed/copied at destination.
2653 with dest
= (expand-file-name dest-cand
)
2655 for basename-src
= (if (file-directory-p src
)
2657 (directory-file-name src
)
2658 (file-name-directory src
))
2659 (file-name-nondirectory src
))
2660 for fname
= (if (file-directory-p dest
)
2661 (concat (file-name-as-directory dest
)
2664 ;; Needed in case we rename a dir on itself. (e.g foo=>foo1)
2665 when
(file-exists-p fname
)
2666 collect fname into tmp-list
2667 finally return
(sort tmp-list
'string
<)))
2669 (defun anything-c-maybe-mark-candidates ()
2670 "Mark all candidates of list `anything-ff-cand-to-mark'."
2671 (when (and (string= (assoc-default 'name
(anything-get-current-source))
2672 (assoc-default 'name anything-c-source-find-files
))
2673 anything-ff-cand-to-mark
)
2674 (with-anything-window
2675 (while anything-ff-cand-to-mark
2676 (if (search-forward (car anything-ff-cand-to-mark
) (point-at-eol) t
)
2678 (call-interactively 'anything-toggle-visible-mark
)
2679 (setq anything-ff-cand-to-mark
(cdr anything-ff-cand-to-mark
)))
2680 (call-interactively 'anything-next-line
)))
2681 (unless (anything-this-visible-mark)
2682 (call-interactively 'anything-prev-visible-mark
)))))
2684 (add-hook 'anything-after-update-hook
#'anything-c-maybe-mark-candidates
)
2687 (defun* anything-dired-do-action-on-file
(&key action
)
2688 (let* ((files (dired-get-marked-files))
2689 (len (length files
))
2690 (fname (if (> len
1)
2691 (format "* %d Files" len
)
2693 (source (case action
2694 ('copy
'anything-c-source-copy-files
)
2695 ('rename
'anything-c-source-rename-files
)
2696 ('symlink
'anything-c-source-symlink-files
)
2697 ('hardlink
'anything-c-source-hardlink-files
)))
2698 (prompt-fm (case action
2699 ('copy
"Copy %s to: ")
2700 ('rename
"Rename %s to: ")
2701 ('symlink
"Symlink %s to: ")
2702 ('hardlink
"Hardlink %s to: ")))
2703 (buffer (case action
2704 ('copy
"*Anything Copy Files*")
2705 ('rename
"*Anything Rename Files*")
2706 ('symlink
"*Anything Symlink Files*")
2707 ('hardlink
"*Anything Hardlink Files*"))))
2709 (or (dired-dwim-target-directory)
2710 (expand-file-name (anything-c-current-directory)))
2711 (format prompt-fm fname
) nil nil buffer
)))
2715 (defun anything-dired-rename-file ()
2716 "Preconfigured `anything' to rename files from dired."
2718 (anything-dired-do-action-on-file :action
'rename
))
2721 (defun anything-dired-copy-file ()
2722 "Preconfigured `anything' to copy files from dired."
2724 (anything-dired-do-action-on-file :action
'copy
))
2727 (defun anything-dired-symlink-file ()
2728 "Preconfigured `anything' to symlink files from dired."
2730 (anything-dired-do-action-on-file :action
'symlink
))
2733 (defun anything-dired-hardlink-file ()
2734 "Preconfigured `anything' to hardlink files from dired."
2736 (anything-dired-do-action-on-file :action
'hardlink
))
2738 (defvar anything-dired-bindings nil
)
2740 (defun anything-dired-bindings (&optional arg
)
2741 "Replace usual dired commands `C' and `R' by anything ones.
2742 When call interactively toggle dired bindings and anything bindings.
2743 When call non--interactively with arg > 0, enable anything bindings.
2744 You can put (anything-dired-binding 1) in init file to enable anything bindings."
2746 (if (or (and arg
(> arg
0)) (not anything-dired-bindings
))
2747 ;; Replace dired bindings.
2749 (substitute-key-definition
2750 'dired-do-copy
'anything-dired-copy-file dired-mode-map
)
2751 (substitute-key-definition
2752 'dired-do-rename
'anything-dired-rename-file dired-mode-map
)
2753 (substitute-key-definition
2754 'dired-do-symlink
'anything-dired-symlink-file dired-mode-map
)
2755 (substitute-key-definition
2756 'dired-do-hardlink
'anything-dired-hardlink-file dired-mode-map
)
2757 (setq anything-dired-bindings t
))
2758 ;; Replace anything bindings.
2759 (substitute-key-definition
2760 'anything-dired-copy-file
'dired-do-copy dired-mode-map
)
2761 (substitute-key-definition
2762 'anything-dired-rename-file
'dired-do-rename dired-mode-map
)
2763 (substitute-key-definition
2764 'anything-dired-symlink-file
'dired-do-symlink dired-mode-map
)
2765 (substitute-key-definition
2766 'anything-dired-hardlink-file
'dired-do-hardlink dired-mode-map
)
2767 (setq anything-dired-bindings nil
)))
2769 (defun* anything-c-read-file-name
(prompt
2771 (initial-input (expand-file-name default-directory
))
2772 (buffer "*Anything Completions*")
2775 (marked-candidates nil
)
2776 (persistent-action 'anything-find-files-persistent-action
)
2777 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
2778 "Anything `read-file-name' emulation.
2779 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
2780 (when (get-buffer anything-action-buffer
)
2781 (kill-buffer anything-action-buffer
))
2782 (let ((anything-mp-highlight-delay nil
))
2783 (flet ((action-fn (candidate)
2784 (if marked-candidates
2785 (anything-marked-candidates)
2786 (identity candidate
))))
2789 `(((name .
,(concat "Read File Name History" anything-c-find-files-doc-header
))
2790 (candidates .
(lambda ()
2791 (anything-comp-read-get-candidates history
)))
2793 (persistent-action .
,persistent-action
)
2794 (persistent-help .
,persistent-help
)
2795 (action .
,'action-fn
))
2796 ((name .
,(concat "Read file name" anything-c-find-files-doc-header
))
2797 ;; It is needed for filenames with capital letters
2799 (candidates .
(lambda ()
2801 (loop with seq
= (anything-find-files-get-candidates)
2802 for fname in seq when
(funcall test fname
)
2804 (anything-find-files-get-candidates))))
2805 (filtered-candidate-transformer anything-c-find-files-transformer
)
2806 (persistent-action .
,persistent-action
)
2807 (persistent-help .
,persistent-help
)
2809 (action .
,'action-fn
)))
2810 :input initial-input
2817 (defvar anything-c-source-file-cache-initialized nil
)
2819 (defvar anything-c-file-cache-files nil
)
2821 (defvar anything-c-source-file-cache
2822 '((name .
"File Cache")
2825 (require 'filecache nil t
)
2826 (unless anything-c-source-file-cache-initialized
2827 (setq anything-c-file-cache-files
2828 (loop for item in file-cache-alist append
2829 (destructuring-bind (base &rest dirs
) item
2830 (loop for dir in dirs collect
2831 (concat dir base
)))))
2832 (defadvice file-cache-add-file
(after file-cache-list activate
)
2833 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
2834 (setq anything-c-source-file-cache-initialized t
))))
2835 (candidates . anything-c-file-cache-files
)
2836 (match anything-c-match-on-file-name
2837 anything-c-match-on-directory-name
)
2839 ;; (anything 'anything-c-source-file-cache)
2842 ;; NOTE for WINDOZE users:
2843 ;; You have to install Everything with his command line interface here:
2844 ;; http://www.voidtools.com/download.php
2846 (defvar anything-c-locate-command
2848 ('gnu
/linux
"locate -i -r %s")
2849 ('berkeley-unix
"locate -i %s")
2850 ('windows-nt
"es -i -r %s")
2852 "A list of arguments for locate program.
2853 The \"-r\" option must be the last option.")
2855 (defun anything-c-locate-init ()
2856 "Initialize async locate process for `anything-c-source-locate'."
2857 (setq mode-line-format
2858 '(" " mode-line-buffer-identification
" "
2859 (line-number-mode "%l") " "
2860 (:eval
(propertize "(Locate Process Running) "
2861 'face
'((:foreground
"red"))))))
2863 (start-process-shell-command "locate-process" nil
2864 (format anything-c-locate-command
2866 (set-process-sentinel (get-process "locate-process")
2867 #'(lambda (process event
)
2868 (when (string= event
"finished\n")
2869 (kill-local-variable 'mode-line-format
)
2870 (with-anything-window
2871 (anything-update-move-first-line)))))))
2873 (defvar anything-c-source-locate
2875 (candidates . anything-c-locate-init
)
2877 (requires-pattern .
3)
2879 "Find files matching the current input pattern with locate.")
2881 ;; (anything 'anything-c-source-locate)
2884 ;; NOTE: the -d option with skip avoid error on windows.
2885 ;; It have no effect on GNU/Linux.
2886 (defvar anything-c-grep-default-command
"grep -d skip -niH -e %s %s %s"
2887 "Default format command for `anything-do-grep'.
2888 If you want to enable recursion just add the -r option like this:
2889 \"grep -nirH -e %s %s %s\".
2890 NOTE: This option is accessible with a prefix arg
2891 from all anything grep commands without setting it here.")
2893 (defvar anything-c-grep-default-function
'anything-c-grep-init
)
2895 (defface anything-grep-match
2896 '((t (:inherit match
)))
2897 "Face used to highlight grep matches."
2900 (defface anything-grep-file
2901 '((t (:foreground
"BlueViolet" :underline t
)))
2902 "Face used to highlight grep results filenames."
2905 (defface anything-grep-lineno
2906 '((t (:foreground
"Darkorange1")))
2907 "Face used to highlight grep number lines."
2910 (defun anything-c-grep-prepare-candidates (candidates)
2911 "Prepare filenames and directories candidates for grep command line."
2912 ;; If one or more candidate is a directory, search in all files
2913 ;; of this candidate (e.g /home/user/directory/*).
2914 ;; If r option is enabled search also in subdidrectories.
2915 ;; We need here to expand wildcards to support crap windows filenames
2916 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
2917 (loop for i in candidates append
2918 (cond ((and (file-directory-p i
)
2919 (anything-c-grep-recurse-p))
2920 (list (expand-file-name i
)))
2921 ((file-directory-p i
)
2922 (file-expand-wildcards (concat (file-name-as-directory
2923 (expand-file-name i
))
2925 ((string-match "\*" i
) (file-expand-wildcards i t
))
2926 (t (list i
))) into of
2928 (mapconcat #'(lambda (x) (shell-quote-argument x
)) of
" ")))
2930 (defun anything-c-grep-recurse-p ()
2931 "Check if `anything-do-grep1' have switched to recursive."
2932 (let ((args (replace-regexp-in-string
2933 "grep" "" anything-c-grep-default-command
)))
2934 (string-match-p "r\\|recurse" args
)))
2936 (defun anything-c-grep-init (only-files &optional include
)
2937 "Start an asynchronous grep process in ONLY-FILES list."
2938 (let* ((fnargs (anything-c-grep-prepare-candidates
2939 (if (file-remote-p anything-ff-default-directory
)
2940 (mapcar #'(lambda (x) (file-remote-p x
'localname
)) only-files
)
2942 (ignored-files (mapconcat
2944 (concat "--exclude=" (shell-quote-argument x
)))
2945 grep-find-ignored-files
" "))
2946 (ignored-dirs (mapconcat ; Need grep version 2.5.4 of Gnuwin32 on windoze.
2948 (concat "--exclude-dir=" (shell-quote-argument x
)))
2949 grep-find-ignored-directories
" "))
2950 (exclude (if (anything-c-grep-recurse-p)
2951 (concat (or include ignored-files
) " " ignored-dirs
)
2953 (setq mode-line-format
2954 '(" " mode-line-buffer-identification
" "
2955 (line-number-mode "%l") " "
2956 (:eval
(propertize "(Grep Process Running) "
2957 'face
'((:foreground
"red"))))))
2959 (let ((default-directory anything-ff-default-directory
))
2960 (start-file-process-shell-command
2962 (format anything-c-grep-default-command
2963 (shell-quote-argument anything-pattern
)
2967 (set-process-sentinel
2968 (get-process "grep-process")
2969 #'(lambda (process event
)
2970 (when (string= event
"finished\n")
2971 (kill-local-variable 'mode-line-format
)
2972 (with-anything-window
2973 (anything-update-move-first-line))))))))
2975 (defun anything-c-grep-action (candidate &optional where mark
)
2976 "Define a default action for `anything-do-grep' on CANDIDATE.
2977 WHERE can be one of other-window, elscreen, other-frame."
2978 (let* ((split (anything-c-grep-split-line candidate
))
2979 (lineno (string-to-number (nth 1 split
)))
2980 (loc-fname (car split
))
2981 (tramp-method (file-remote-p anything-ff-default-directory
'method
))
2982 (tramp-host (file-remote-p anything-ff-default-directory
'host
))
2983 (tramp-prefix (concat "/" tramp-method
":" tramp-host
":"))
2984 (fname (if tramp-host
(concat tramp-prefix loc-fname
) loc-fname
)))
2986 (other-window (find-file-other-window fname
))
2987 (elscreen (anything-elscreen-find-file fname
))
2988 (other-frame (find-file-other-frame fname
))
2989 (t (find-file fname
)))
2990 (anything-goto-line lineno
)
2991 (set-marker (mark-marker) (point))
2993 (push-mark (point) 'nomsg
))))
2996 (defun anything-c-grep-persistent-action (candidate)
2997 "Persistent action for `anything-do-grep'.
2998 With a prefix arg record CANDIDATE in `mark-ring'."
2999 (if current-prefix-arg
3000 (anything-c-grep-action candidate nil
'mark
)
3001 (anything-c-grep-action candidate
))
3002 (anything-match-line-color-current-line))
3004 (defun anything-do-grep1 (only &optional recurse
)
3005 "Launch grep with a list of ONLY files.
3006 When RECURSE is given use -r option of grep and prompt user
3007 to set the --include arg of grep.
3008 If it's not empty use it instead of `grep-find-ignored-files'."
3009 (let* ((anything-compile-source-functions
3010 ;; rule out anything-match-plugin because the input is one regexp.
3011 (delq 'anything-compile-source--match-plugin
3012 (copy-sequence anything-compile-source-functions
)))
3013 (include-files (and recurse
(read-string "OnlyExt(*.[ext]): ")))
3014 (anything-c-grep-default-command (if recurse
"grep -nirH -e %s %s %s"
3015 anything-c-grep-default-command
))
3016 ;; Disable match-plugin and use here own highlighting.
3017 (anything-mp-highlight-delay nil
))
3020 (and (not (string= include-files
""))
3021 (mapconcat #'(lambda (x)
3022 (concat "--include=" (shell-quote-argument x
)))
3023 (split-string include-files
) " "))))
3024 ;; When called as action from an other source e.g *-find-files
3025 ;; we have to kill action buffer.
3026 (when (get-buffer anything-action-buffer
)
3027 (kill-buffer anything-action-buffer
))
3030 `(((name .
"Grep (M-up/down - next/prec file)")
3032 .
(lambda () (if include-files
3033 (funcall anything-c-grep-default-function only include-files
)
3034 (funcall anything-c-grep-default-function only
))))
3035 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
3036 (candidate-number-limit .
9999)
3039 `(("Find File" . anything-c-grep-action
)
3040 ("Find file other window"
3041 .
(lambda (candidate)
3042 (anything-c-grep-action candidate
'other-window
)))
3043 ,(and (locate-library "elscreen")
3044 '("Find file in Elscreen"
3045 .
(lambda (candidate)
3046 (anything-c-grep-action candidate
'elscreen
))))
3047 ("Find file other frame"
3048 .
(lambda (candidate)
3049 (anything-c-grep-action candidate
'other-frame
))))))
3050 (persistent-action .
(lambda (candidate)
3051 (anything-c-grep-persistent-action candidate
)))
3052 (persistent-help .
"Jump to line (`C-u' Record in mark ring)")
3053 (requires-pattern .
3)
3055 :buffer
"*anything grep*")))
3058 (defun anything-do-grep ()
3059 "Preconfigured anything for grep.
3060 Contrarily to Emacs `grep' no default directory is given, but
3061 the full path of candidates in ONLY.
3062 That allow to grep different files not only in `default-directory' but anywhere
3063 by marking them (C-<SPACE>). If one or more directory is selected
3064 grep will search in all files of these directories.
3065 You can use also wildcard in the base name of candidate.
3066 If a prefix arg is given use the -r option of grep."
3068 (let ((only (anything-c-read-file-name
3069 "Search in file(s): " :marked-candidates t
))
3070 (prefarg current-prefix-arg
))
3071 (anything-do-grep1 only prefarg
)))
3073 (defun anything-c-grep-split-line (line)
3074 "Split a grep output line."
3075 (let (beg fname lineno str
)
3076 ;; Don't print until grep line is valid.
3077 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line
)
3080 (goto-char (point-min))
3083 (re-search-forward ":" nil t
)
3084 (setq fname
(buffer-substring-no-properties beg
(1- (point))))
3086 (re-search-forward ":" nil t
)
3087 (setq lineno
(buffer-substring-no-properties beg
(1- (point))))
3088 (setq str
(buffer-substring-no-properties (point) (point-at-eol))))
3089 (list fname lineno str
))))
3091 (defun anything-c-grep-cand-transformer (candidates sources
)
3092 "Filtered candidate transformer function for `anything-do-grep'."
3093 (loop for i in candidates
3094 for split
= (and i
(anything-c-grep-split-line i
))
3095 for fname
= (car split
)
3096 for lineno
= (nth 1 split
)
3097 for str
= (nth 2 split
)
3098 when
(and fname lineno str
)
3100 (cons (concat (propertize (file-name-nondirectory fname
)
3101 'face
'anything-grep-file
3102 'help-echo fname
) ":"
3103 (propertize lineno
'face
'anything-grep-lineno
) ":"
3104 (anything-c-grep-highlight-match str
))
3107 (defun anything-c-grep-highlight-match (str)
3108 "Highlight in STR all occurences matching `anything-pattern'."
3112 (goto-char (point-min))
3113 (while (and (re-search-forward anything-pattern nil t
)
3114 (> (- (match-end 0) (match-beginning 0)) 0))
3115 (add-text-properties
3116 (match-beginning 0) (match-end 0)
3117 '(face anything-grep-match
)))
3121 ;; Go to next or precedent file (common to etags and grep).
3122 (defun anything-c-goto-next-or-prec-file (n)
3123 "Go to next or precedent candidate file in anything grep/etags buffers."
3124 (let ((cur-source (assoc-default 'name
(anything-get-current-source))))
3125 (with-anything-window
3126 (if (or (string= cur-source
"Grep (M-up/down - next/prec file)")
3127 (string-match "^Etags.*" cur-source
))
3128 (let* ((current-line-list (split-string
3131 (point-at-eol)) ":"))
3132 (current-fname (nth 0 current-line-list
))
3133 (fn-b-o-f (if (eq n
1) 'eobp
'bobp
)))
3135 (while (not (funcall fn-b-o-f
))
3136 (forward-line n
) ; Go forward or backward depending of n value.
3137 (unless (search-forward current-fname
(point-at-eol) t
)
3138 (anything-mark-current-line)
3139 (throw 'break nil
))))
3140 (cond ((and (eq n
1) (eobp))
3141 (re-search-backward ".")
3143 (anything-mark-current-line))
3144 ((and (< n
1) (bobp))
3146 (anything-mark-current-line))))
3148 (anything-next-line)
3149 (anything-previous-line))))))
3152 (defun anything-c-goto-precedent-file ()
3153 "Go to precedent file in anything grep/etags buffers."
3155 (anything-c-goto-next-or-prec-file -
1))
3158 (defun anything-c-goto-next-file ()
3159 "Go to precedent file in anything grep/etags buffers."
3161 (anything-c-goto-next-or-prec-file 1))
3163 ;; This keys affect etags and grep only.
3164 ;; in other sources they do nothing, just going next or precedent line.
3165 (define-key anything-map
(kbd "M-<down>") #'anything-c-goto-next-file
)
3166 (define-key anything-map
(kbd "M-<up>") #'anything-c-goto-precedent-file
)
3170 (when (locate-library "anything-etags.el")
3173 "You are using obsolete library `anything-etags.el' and should remove it."
3176 (defcustom anything-c-etags-tag-file-name
"TAGS"
3177 "Etags tag file name."
3179 :group
'anything-config
)
3181 (defcustom anything-c-etags-tag-file-search-limit
10
3182 "The limit level of directory to search tag file.
3183 Don't search tag file deeply if outside this value."
3185 :group
'anything-config
)
3187 (defvar anything-c-etags-tag-file-dir nil
3188 "Etags file directory.")
3189 (defvar anything-c-etags-mtime-alist nil
)
3190 (defvar anything-c-etags-cache
(make-hash-table :test
'equal
))
3192 (defun anything-c-etags-get-tag-file ()
3193 "Get Etags tag file."
3194 ;; Get tag file from `default-directory' or upper directory.
3195 (let ((current-dir (anything-c-etags-find-tag-file default-directory
)))
3196 ;; Return nil if not find tag file.
3198 (setq anything-c-etags-tag-file-dir current-dir
) ;set tag file directory
3199 (expand-file-name anything-c-etags-tag-file-name current-dir
))))
3201 (defun anything-c-etags-find-tag-file (current-dir)
3203 Try to find tag file in upper directory if haven't found in CURRENT-DIR."
3204 (flet ((file-exists?
(dir)
3205 (let ((tag-path (expand-file-name anything-c-etags-tag-file-name dir
)))
3206 (and (stringp tag-path
)
3207 (file-exists-p tag-path
)
3208 (file-readable-p tag-path
)))))
3209 (loop with count
= 0
3210 until
(file-exists? current-dir
)
3211 ;; Return nil if outside the value of
3212 ;; `anything-c-etags-tag-file-search-limit'.
3213 if
(= count anything-c-etags-tag-file-search-limit
)
3215 ;; Or search upper directories.
3218 (setq current-dir
(expand-file-name (concat current-dir
"../")))
3219 finally return current-dir
)))
3221 (defun anything-c-source-etags-header-name (x)
3223 (with-current-buffer anything-current-buffer
3224 (anything-c-etags-get-tag-file))))
3226 (defmacro anything-c-etags-create-buffer
(file)
3227 `(let* ((tag-fname ,file
)
3229 (split (with-current-buffer (find-file-noselect tag-fname
)
3231 (split-string (buffer-string) "\n" 'omit-nulls
)
3232 (setq max
(line-number-at-pos (point-max)))
3234 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max
)))
3238 for i in split for count from
0
3239 for elm
= (unless (string-match "^\x0c" i
)
3240 (anything-aif (string-match "\177" i
)
3243 do
(cond ((and elm
(string-match "^\\(.+\\),[0-9]+" elm
))
3244 (setq fname
(match-string 1 elm
)))
3245 (elm (setq cand
(concat fname
": " elm
)))
3246 (t (setq cand nil
)))
3248 (insert (concat cand
"\n"))
3249 (progress-reporter-update progress-reporter count
)))))
3251 (defun anything-c-etags-init ()
3252 (let ((tagfile (anything-c-etags-get-tag-file)))
3253 (with-current-buffer (anything-candidate-buffer 'global
)
3254 (anything-aif (gethash tagfile anything-c-etags-cache
)
3256 (anything-c-etags-create-buffer tagfile
)
3257 (puthash tagfile
(buffer-string) anything-c-etags-cache
)
3258 (anything-aif (assoc tagfile anything-c-etags-mtime-alist
)
3259 ;; If an entry exists modify it.
3260 (setcdr it
(anything-c-etags-mtime tagfile
))
3261 ;; No entry create a new one.
3262 (add-to-list 'anything-c-etags-mtime-alist
3263 (cons tagfile
(anything-c-etags-mtime tagfile
))))))))
3265 (defvar anything-c-source-etags-select
3267 (header-name . anything-c-source-etags-header-name
)
3268 (init . anything-c-etags-init
)
3269 (candidates-in-buffer)
3270 (action . anything-c-etags-default-action
)
3271 (persistent-action .
(lambda (candidate)
3272 (anything-c-etags-default-action candidate
)
3273 (anything-match-line-color-current-line)))))
3275 (defun anything-c-etags-default-action (candidate)
3276 (let* ((split (split-string candidate
": "))
3277 (fname (expand-file-name
3278 (car split
) anything-c-etags-tag-file-dir
))
3281 (goto-char (point-min))
3282 (search-forward elm nil t
)
3283 (goto-char (match-beginning 0))))
3285 (defun anything-c-etags-select (arg)
3286 "Preconfigured anything for etags.
3287 Called with one prefix arg use symbol at point as initial input.
3288 Called with two prefix arg reinitialize cache.
3289 If tag file have been modified reinitialize cache."
3291 (let ((tag (anything-c-etags-get-tag-file))
3292 (init (and arg
(equal current-prefix-arg
'(4))
3293 (thing-at-point 'symbol
)))
3294 (anything-quit-if-no-candidate t
)
3295 (anything-execute-action-at-once-if-one t
))
3296 (when (or (equal current-prefix-arg
'(16))
3297 (and anything-c-etags-mtime-alist
3298 (anything-c-etags-file-modified-p tag
)))
3299 (remhash tag anything-c-etags-cache
))
3300 (if (and tag
(file-exists-p tag
))
3301 (anything :sources
'anything-c-source-etags-select
3303 :buffer
"*anything etags*")
3304 (message "Error: No tag file found, please create one with etags shell command."))))
3306 (defun anything-c-etags-mtime (file)
3307 "Last modification time of FILE."
3308 (cadr (nth 5 (file-attributes file
))))
3310 (defun anything-c-etags-file-modified-p (file)
3311 "Check if tag FILE have been modified in this session.
3312 If FILE is nil return nil."
3313 (let ((last-modif (and file
3314 (assoc-default file anything-c-etags-mtime-alist
))))
3316 (/= last-modif
(anything-c-etags-mtime file
)))))
3319 (defvar anything-c-source-recentf
3320 '((name .
"Recentf")
3323 (or recentf-mode
(recentf-mode 1))
3324 ;; Big value empowers anything/recentf
3325 (when (and (numberp recentf-max-saved-items
)
3326 (<= recentf-max-saved-items
20))
3327 (setq recentf-max-saved-items
500))))
3328 (candidates . recentf-list
)
3329 (match anything-c-match-on-file-name
3330 anything-c-match-on-directory-name
)
3332 "See (info \"(emacs)File Conveniences\").
3333 if `recentf-max-saved-items' is too small, set it to 500.")
3334 ;; (anything 'anything-c-source-recentf)
3337 (eval-when-compile (require 'ffap
))
3338 (defvar anything-c-source-ffap-guesser
3339 '((name .
"File at point")
3340 (init .
(lambda () (require 'ffap
)))
3341 (candidates .
(lambda ()
3343 (with-current-buffer anything-current-buffer
3347 ;; (anything 'anything-c-source-ffap-guesser)
3349 ;;; ffap with line number
3350 (defun anything-c-ffap-file-line-at-point ()
3351 "Get (FILENAME . LINENO) at point."
3352 (anything-aif (let (ffap-alist) (ffap-file-at-point))
3355 (when (and (search-forward it nil t
)
3356 (looking-at ":\\([0-9]+\\)"))
3357 (cons it
(string-to-number (match-string 1)))))))
3359 (defvar anything-c-ffap-line-location nil
3360 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
3361 It is cleared after jumping line.")
3363 (defun anything-c-ffap-line-candidates ()
3364 (with-current-buffer anything-current-buffer
3365 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
3366 (when anything-c-ffap-line-location
3367 (destructuring-bind (file . line
) anything-c-ffap-line-location
3368 (list (cons (format "%s (line %d)" file line
) file
)))))
3370 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
3371 (defun anything-c-ffap-line-goto-line ()
3372 (when (car anything-c-ffap-line-location
)
3375 (with-selected-window
3377 (get-file-buffer (car anything-c-ffap-line-location
)))
3378 (anything-goto-line (cdr anything-c-ffap-line-location
)))))))
3379 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
3380 (add-hook 'anything-after-persistent-action-hook
'anything-c-ffap-line-goto-line
)
3382 (defvar anything-c-source-ffap-line
3383 '((name .
"File/Lineno at point")
3384 (init .
(lambda () (require 'ffap
)))
3385 (candidates . anything-c-ffap-line-candidates
)
3387 ;; (anything 'anything-c-source-ffap-line)
3389 ;;; list of files gleaned from every dired buffer
3390 (defun anything-c-files-in-all-dired-candidates ()
3394 (cond ((listp dir
) ;filelist
3396 ((equal "" (file-name-nondirectory dir
)) ;dir
3397 (directory-files dir t
))
3399 (file-expand-wildcards dir t
))))
3401 (mapcar (lambda (buf)
3403 (when (eq major-mode
'dired-mode
)
3404 (if (consp dired-directory
)
3405 (cdr dired-directory
) ;filelist
3406 dired-directory
))) ;dir or wildcard
3408 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
3410 (defvar anything-c-source-files-in-all-dired
3411 '((name .
"Files in all dired buffer.")
3412 (candidates . anything-c-files-in-all-dired-candidates
)
3414 ;; (anything 'anything-c-source-files-in-all-dired)
3416 (defcustom anything-c-filelist-file-name nil
3417 "*Filename of file list.
3418 Accept a list of string for multiple files.
3420 This file tend to be very large (> 100MB) and recommend to be in ramdisk for speed.
3421 File list is created by make-filelist.rb script.
3424 ruby make-filelist.rb > /tmp/all.filelist
3427 ;; Assume that /tmp is ramdisk or tmpfs
3428 (setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\")
3429 (setq anything-c-filelist-file-name \"/tmp/all.filelist\")
3432 :group
'anything-config
)
3433 (defvar anything-c-source-filelist
3434 '((name .
"FileList")
3435 (grep-candidates . anything-c-filelist-file-name
)
3436 (candidate-number-limit .
200)
3437 (requires-pattern .
4)
3441 (defun anything-filelist ()
3442 "Preconfigured `anything' to open files instantly."
3444 (anything-other-buffer 'anything-c-source-filelist
"*anything file list*"))
3447 (defun anything-filelist+ ()
3448 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
3450 This is a replacement for `anything-for-files'."
3452 (anything-other-buffer
3453 '(anything-c-source-ffap-line
3454 anything-c-source-ffap-guesser
3455 anything-c-source-buffers
+
3456 anything-c-source-recentf
3457 anything-c-source-bookmarks
3458 anything-c-source-file-cache
3459 anything-c-source-filelist
)
3460 "*anything file list*"))
3465 (defvar anything-c-info-pages nil
3466 "All info pages on system.
3467 Will be calculated the first time you invoke anything with this
3470 (defvar anything-c-source-info-pages
3471 `((name .
"Info Pages")
3474 (if anything-c-info-pages
3475 anything-c-info-pages
3476 (setq anything-c-info-pages
3477 (save-window-excursion
3480 (Info-find-node "dir" "top")
3481 (goto-char (point-min))
3482 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
3484 (while (re-search-forward info-topic-regexp nil t
)
3485 (add-to-list 'topics
(match-string-no-properties 1)))
3486 (goto-char (point-min))
3489 (action .
(("Show with Info" .
(lambda (node-str)
3490 (info (replace-regexp-in-string
3491 "^[^:]+: " "" node-str
))))))
3492 (requires-pattern .
2)))
3493 ;; (anything 'anything-c-source-info-pages)
3496 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
3497 (defun anything-c-describe-attributes (anything-attribute)
3498 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
3499 Same as `anything-describe-anything-attribute' but with anything completion."
3500 (interactive (list (intern
3502 "Describe anything attribute: "
3503 (mapcar 'symbol-name anything-additional-attributes
)
3506 #'(lambda (candidate)
3507 (with-output-to-temp-buffer "*Help*"
3508 (princ (get (intern candidate
) 'anything-attrdoc
))))))))
3509 (with-output-to-temp-buffer "*Help*"
3510 (princ (get anything-attribute
'anything-attrdoc
))))
3512 ;;; Use info-index plug-in. Note that `name' attribute is
3513 ;;; not needed but `anything-c-insert-summary' uses it.
3515 (defvar anything-c-source-info-elisp
3516 '((name .
"Info index: elisp")
3517 (info-index .
"elisp")))
3518 ;; (anything 'anything-c-source-info-elisp)
3521 (defvar anything-c-source-info-cl
3522 '((name .
"Info index: cl")
3523 (info-index .
"cl")))
3524 ;; (anything 'anything-c-source-info-cl)
3527 (defvar anything-c-source-info-org
3528 '((name .
"Info index: org")
3529 (info-index .
"org")))
3530 ;; (anything 'anything-c-source-info-org)
3532 ;; Info Index ratpoison
3533 (defvar anything-c-source-info-ratpoison
3534 '((name .
"Info index: ratpoison")
3535 (info-index .
"ratpoison")))
3536 ;; (anything 'anything-c-source-info-ratpoison)
3539 (defvar anything-c-source-info-zsh
3540 '((name .
"Info index: zsh")
3541 (info-index .
"zsh")))
3542 ;; (anything 'anything-c-source-info-zsh)
3545 (defvar anything-c-source-info-bash
3546 '((name .
"Info index: bash")
3547 (info-index .
"bash")))
3548 ;; (anything 'anything-c-source-info-bash)
3550 ;; Info Index coreutils
3551 (defvar anything-c-source-info-coreutils
3552 '((name .
"Info index: coreutils")
3553 (info-index .
"coreutils")))
3554 ;; (anything 'anything-c-source-info-coreutils)
3556 ;; Info Index fileutils
3557 (defvar anything-c-source-info-fileutils
3558 '((name .
"Info index: fileutils")
3559 (info-index .
"fileutils")))
3560 ;; (anything 'anything-c-source-info-fileutils)
3563 (defvar anything-c-source-info-find
3564 '((name .
"Info index: find")
3565 (info-index .
"find")))
3566 ;; (anything 'anything-c-source-info-find)
3568 ;; Info Index sh-utils
3569 (defvar anything-c-source-info-sh-utils
3570 '((name .
"Info index: sh-utils")
3571 (info-index .
"sh-utils")))
3572 ;; (anything 'anything-c-source-info-sh-utils)
3574 ;; Info Index textutils
3575 (defvar anything-c-source-info-textutils
3576 '((name .
"Info index: textutils")
3577 (info-index .
"textutils")))
3578 ;; (anything 'anything-c-source-info-textutils)
3581 (defvar anything-c-source-info-libc
3582 '((name .
"Info index: libc")
3583 (info-index .
"libc")))
3584 ;; (anything 'anything-c-source-info-libc)
3587 (defvar anything-c-source-info-make
3588 '((name .
"Info index: make")
3589 (info-index .
"make")))
3590 ;; (anything 'anything-c-source-info-make)
3592 ;; Info Index automake
3593 (defvar anything-c-source-info-automake
3594 '((name .
"Info index: automake")
3595 (info-index .
"automake")))
3596 ;; (anything 'anything-c-source-info-automake)
3598 ;; Info Index autoconf
3599 (defvar anything-c-source-info-autoconf
3600 '((name .
"Info index: autoconf")
3601 (info-index .
"autoconf")))
3602 ;; (anything 'anything-c-source-info-autoconf)
3604 ;; Info Index emacs-lisp-intro
3605 (defvar anything-c-source-info-emacs-lisp-intro
3606 '((name .
"Info index: emacs-lisp-intro")
3607 (info-index .
"emacs-lisp-intro")))
3608 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
3611 (defvar anything-c-source-info-emacs
3612 '((name .
"Info index: emacs")
3613 (info-index .
"emacs")))
3614 ;; (anything 'anything-c-source-info-emacs)
3617 (defvar anything-c-source-info-elib
3618 '((name .
"Info index: elib")
3619 (info-index .
"elib")))
3620 ;; (anything 'anything-c-source-info-elib)
3623 (defvar anything-c-source-info-eieio
3624 '((name .
"Info index: eieio")
3625 (info-index .
"eieio")))
3626 ;; (anything 'anything-c-source-info-eieio)
3628 ;; Info Index gauche-refe
3629 (defvar anything-c-source-info-gauche-refe
3630 '((name .
"Info index: gauche")
3631 (info-index .
"gauche-refe")))
3632 ;; (anything 'anything-c-source-info-gauche-refe)
3635 (defvar anything-c-source-info-guile
3636 '((name .
"Info index: guile")
3637 (info-index .
"guile")))
3638 ;; (anything 'anything-c-source-info-guile)
3640 ;; Info Index guile-tut
3641 (defvar anything-c-source-info-guile-tut
3642 '((name .
"Info index: guile-tut")
3643 (info-index .
"guile-tut")))
3644 ;; (anything 'anything-c-source-info-guile-tut)
3647 (defvar anything-c-source-info-goops
3648 '((name .
"Info index: goops")
3649 (info-index .
"goops")))
3650 ;; (anything 'anything-c-source-info-goops)
3652 ;; Info Index screen
3653 (defvar anything-c-source-info-screen
3654 '((name .
"Info index: screen")
3655 (info-index .
"screen")
3656 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
3657 ;; (anything 'anything-c-source-info-screen)
3660 (defvar anything-c-source-info-latex
3661 '((name .
"Info index: latex")
3662 (info-index .
"latex")))
3663 ;; (anything 'anything-c-source-info-latex)
3666 (defvar anything-c-source-info-gawk
3667 '((name .
"Info index: gawk")
3668 (info-index .
"gawk")))
3669 ;; (anything 'anything-c-source-info-gawk)
3672 (defvar anything-c-source-info-sed
3673 '((name .
"Info index: sed")
3674 (info-index .
"sed")))
3675 ;; (anything 'anything-c-source-info-sed)
3678 (defvar anything-c-source-info-m4
3679 '((name .
"Info index: m4")
3680 (info-index .
"m4")))
3681 ;; (anything 'anything-c-source-info-m4)
3684 (defvar anything-c-source-info-wget
3685 '((name .
"Info index: wget")
3686 (info-index .
"wget")))
3687 ;; (anything 'anything-c-source-info-wget)
3689 ;; Info Index binutils
3690 (defvar anything-c-source-info-binutils
3691 '((name .
"Info index: binutils")
3692 (info-index .
"binutils")))
3693 ;; (anything 'anything-c-source-info-binutils)
3696 (defvar anything-c-source-info-as
3697 '((name .
"Info index: as")
3698 (info-index .
"as")))
3699 ;; (anything 'anything-c-source-info-as)
3702 (defvar anything-c-source-info-bfd
3703 '((name .
"Info index: bfd")
3704 (info-index .
"bfd")))
3705 ;; (anything 'anything-c-source-info-bfd)
3708 (defvar anything-c-source-info-gprof
3709 '((name .
"Info index: gprof")
3710 (info-index .
"gprof")))
3711 ;; (anything 'anything-c-source-info-gprof)
3714 (defvar anything-c-source-info-ld
3715 '((name .
"Info index: ld")
3716 (info-index .
"ld")))
3717 ;; (anything 'anything-c-source-info-ld)
3720 (defvar anything-c-source-info-diff
3721 '((name .
"Info index: diff")
3722 (info-index .
"diff")))
3723 ;; (anything 'anything-c-source-info-diff)
3726 (defvar anything-c-source-info-flex
3727 '((name .
"Info index: flex")
3728 (info-index .
"flex")))
3729 ;; (anything 'anything-c-source-info-flex)
3732 (defvar anything-c-source-info-grep
3733 '((name .
"Info index: grep")
3734 (info-index .
"grep")))
3735 ;; (anything 'anything-c-source-info-grep)
3738 (defvar anything-c-source-info-gzip
3739 '((name .
"Info index: gzip")
3740 (info-index .
"gzip")))
3741 ;; (anything 'anything-c-source-info-gzip)
3743 ;; Info Index libtool
3744 (defvar anything-c-source-info-libtool
3745 '((name .
"Info index: libtool")
3746 (info-index .
"libtool")))
3747 ;; (anything 'anything-c-source-info-libtool)
3749 ;; Info Index texinfo
3750 (defvar anything-c-source-info-texinfo
3751 '((name .
"Info index: texinfo")
3752 (info-index .
"texinfo")))
3753 ;; (anything 'anything-c-source-info-texinfo)
3756 (defvar anything-c-source-info-info
3757 '((name .
"Info index: info")
3758 (info-index .
"info")))
3759 ;; (anything 'anything-c-source-info-info)
3762 (defvar anything-c-source-info-gdb
3763 '((name .
"Info index: gdb")
3764 (info-index .
"gdb")))
3765 ;; (anything 'anything-c-source-info-gdb)
3768 (defvar anything-c-source-info-stabs
3769 '((name .
"Info index: stabs")
3770 (info-index .
"stabs")))
3771 ;; (anything 'anything-c-source-info-stabs)
3773 ;; Info Index cvsbook
3774 (defvar anything-c-source-info-cvsbook
3775 '((name .
"Info index: cvsbook")
3776 (info-index .
"cvsbook")))
3777 ;; (anything 'anything-c-source-info-cvsbook)
3780 (defvar anything-c-source-info-cvs
3781 '((name .
"Info index: cvs")
3782 (info-index .
"cvs")))
3783 ;; (anything 'anything-c-source-info-cvs)
3786 (defvar anything-c-source-info-bison
3787 '((name .
"Info index: bison")
3788 (info-index .
"bison")))
3789 ;; (anything 'anything-c-source-info-bison)
3791 ;; Info Index id-utils
3792 (defvar anything-c-source-info-id-utils
3793 '((name .
"Info index: id-utils")
3794 (info-index .
"id-utils")))
3795 ;; (anything 'anything-c-source-info-id-utils)
3797 ;; Info Index global
3798 (defvar anything-c-source-info-global
3799 '((name .
"Info index: global")
3800 (info-index .
"global")))
3801 ;; (anything 'anything-c-source-info-global)
3805 (defvar anything-c-man-pages nil
3806 "All man pages on system.
3807 Will be calculated the first time you invoke anything with this
3810 (defun anything-c-man-default-action (candidate)
3811 "Default action for jumping to a woman or man page from anything."
3812 (let ((wfiles (woman-file-name-all-completions candidate
)))
3814 (if (> (length wfiles
) 1)
3815 (woman-find-file (anything-comp-read "ManFile: " wfiles
3817 ;; If woman is unable to format correctly
3820 (error (kill-buffer) ; Kill woman buffer.
3823 (defvar anything-c-source-man-pages
3824 `((name .
"Manual Pages")
3825 (candidates .
(lambda ()
3826 (if anything-c-man-pages
3827 anything-c-man-pages
3828 ;; XEmacs doesn't have a woman :)
3829 (setq anything-c-man-pages
3832 (woman-file-name "")
3833 (sort (mapcar 'car woman-topic-all-completions
)
3835 (action ("Show with Woman" . anything-c-man-default-action
))
3836 ;; Woman does not work OS X
3837 ;; http://xahlee.org/emacs/modernization_man_page.html
3838 (action-transformer .
(lambda (actions candidate
)
3839 (if (eq system-type
'darwin
)
3840 '(("Show with Man" . man
))
3842 (requires-pattern .
2)))
3843 ;; (anything 'anything-c-source-man-pages)
3846 ;;; Complex command history
3847 (defvar anything-c-source-complex-command-history
3848 '((name .
"Complex Command History")
3849 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
3851 ;; (anything 'anything-c-source-complex-command-history)
3854 (defvar anything-c-source-extended-command-history
3855 '((name .
"Emacs Commands History")
3856 (candidates . extended-command-history
)
3858 ;; (anything 'anything-c-source-extended-command-history)
3861 (defvar anything-c-source-emacs-commands
3862 '((name .
"Emacs Commands")
3863 (candidates .
(lambda ()
3865 (mapatoms (lambda (a)
3867 (push (symbol-name a
)
3869 (sort commands
'string-lessp
))))
3871 (requires-pattern .
2))
3872 "Source for completing and invoking Emacs commands.
3873 A command is a function with interactive spec that can
3874 be invoked with `M-x'.
3876 To get non-interactive functions listed, use
3877 `anything-c-source-emacs-functions'.")
3878 ;; (anything 'anything-c-source-emacs-commands)
3882 ;; Another replacement of `M-x' that act exactly like the
3883 ;; vanilla Emacs one, no problem of windows configuration, prefix args
3884 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
3885 ;; anything invocation.
3887 (defun anything-M-x ()
3888 "Preconfigured `anything' for Emacs commands.
3889 It is `anything' replacement of regular `M-x' `execute-extended-command'."
3891 (let* (in-help help-cand
3892 (command (anything-comp-read
3897 :name
"Emacs Commands"
3899 #'(lambda (candidate)
3900 (if (and in-help
(string= candidate help-cand
))
3901 (progn (kill-buffer "*Help*") (setq in-help nil
))
3902 (describe-function (intern candidate
))
3904 (setq help-cand candidate
))
3905 :persistent-help
"Describe this command"
3906 :history extended-command-history
3908 :fc-transformer
'anything-M-x-transformer
))
3909 (history (loop with hist
3910 for i in extended-command-history
3911 for com
= (intern i
)
3912 when
(and (fboundp com
) (not (member i hist
)))
3913 collect i into hist finally return hist
)))
3914 (unless current-prefix-arg
(setq current-prefix-arg anything-current-prefix-arg
))
3915 (call-interactively (intern command
))
3916 (setq extended-command-history
(cons command
(delete command history
)))))
3918 (defun* anything-M-x-get-major-mode-command-alist
(mode-map)
3919 "Return alist of MODE-MAP."
3920 (loop for key being the key-seqs of mode-map using
(key-bindings com
)
3921 for str-key
= (key-description key
)
3922 for ismenu
= (string-match "<menu-bar>" str-key
)
3923 unless ismenu collect
(cons str-key com
)))
3925 (defun anything-get-mode-map-from-mode (mode)
3926 "Guess the mode-map name according to MODE.
3927 Some modes don't use conventional mode-map name
3928 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
3929 Return nil if no mode-map found."
3931 ;; Start with a conventional mode-map name.
3932 with mode-map
= (intern-soft (format "%s-map" mode
))
3933 with mode-string
= (symbol-name mode
)
3934 with mode-name
= (replace-regexp-in-string "-mode" "" mode-string
)
3935 while
(not mode-map
)
3936 for count downfrom
(length mode-name
)
3937 ;; Return when no result after parsing entire string.
3938 when
(eq count
0) return nil
3939 for sub-name
= (substring mode-name
0 count
)
3940 do
(setq mode-map
(intern-soft (format "%s-map" (concat sub-name
"-mode"))))
3941 finally return mode-map
))
3943 (defun anything-M-x-current-mode-map-alist ()
3944 "Return mode-map alist of current `major-mode'."
3945 (let ((map (anything-get-mode-map-from-mode major-mode
)))
3946 (when (and map
(boundp map
))
3947 (anything-M-x-get-major-mode-command-alist (symbol-value map
)))))
3949 (defface anything-M-x-key-face
'((t (:foreground
"orange" :underline t
)))
3950 "*Face used in anything-M-x to show keybinding."
3953 (defun anything-M-x-transformer (candidates sources
)
3954 "filtered-candidate-transformer to show bindings in emacs commands.
3955 Show global bindings and local bindings according to current `major-mode'."
3957 with local-map
= (with-current-buffer anything-current-buffer
3958 (anything-M-x-current-mode-map-alist))
3960 for cand
= (symbol-name i
)
3961 for local-key
= (car (rassq i local-map
))
3962 for key
= (substitute-command-keys (format "\\[%s]" cand
))
3964 (cons (if (string-match "^M-x" key
)
3967 cand
" (" (propertize local-key
'face
'anything-M-x-key-face
)
3971 cand
" (" (propertize key
'face
'anything-M-x-key-face
) ")"))
3975 (defvar anything-c-source-lacarte
3976 '((name .
"Lacarte")
3977 (init .
(lambda () (require 'lacarte
)))
3978 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
3979 (candidate-number-limit .
9999)
3980 (action . anything-c-call-interactively
))
3983 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
3984 ;; (anything 'anything-c-source-lacarte)
3988 (defvar anything-c-source-emacs-functions
3989 '((name .
"Emacs Functions")
3990 (candidates .
(lambda ()
3992 (mapatoms (lambda (a)
3994 (push (symbol-name a
) commands
))))
3995 (sort commands
'string-lessp
))))
3997 (requires-pattern .
2))
3998 "Source for completing Emacs functions.")
3999 ;; (anything 'anything-c-source-emacs-functions)
4001 ;;; With abbrev expansion
4002 ;;; Similar to my exec-abbrev-cmd.el
4003 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
4004 (defvar anything-c-function-abbrev-regexp nil
4005 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
4006 Regexp built from the current `anything-pattern' interpreting it
4008 Only for internal use.")
4010 (defun anything-c-match-function-by-abbrev (candidate)
4011 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
4013 Abbreviations are made by taking the first character from each
4014 word in the function's name, e.g. \"bb\" is an abbrev for
4015 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
4016 (string-match anything-c-function-abbrev-regexp candidate
))
4018 (defvar anything-c-source-emacs-functions-with-abbrevs
4019 (append anything-c-source-emacs-functions
4020 '((match anything-c-match-function-by-abbrev
4021 anything-c-string-match
))
4024 (defadvice anything-update
4025 (before anything-c-update-function-abbrev-regexp activate
)
4026 (let ((char-list (append anything-pattern nil
))
4028 (dolist (c char-list
)
4029 (setq str
(concat str
(list c
) "[^-]*-")))
4030 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
4031 (setq anything-c-function-abbrev-regexp str
))))))))
4032 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
4034 (defvar anything-c-source-advice
4035 '((name .
"Function Advice")
4036 (candidates . anything-c-advice-candidates
)
4037 (action ("Toggle Enable/Disable" . anything-c-advice-toggle
))
4038 ;; (real-to-display . anything-c-advice-real-to-display)
4041 (persistent-action . anything-c-advice-persistent-action
)
4042 (persistent-help .
"Describe function / C-u C-z: Toggle advice")))
4043 ;; (anything 'anything-c-source-advice)
4044 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
4047 (defun anything-c-advice-candidates ()
4049 (loop for
(fname) in ad-advised-functions
4050 for function
= (intern fname
)
4052 (loop for class in ad-advice-classes append
4053 (loop for advice in
(ad-get-advice-info-field function class
)
4054 for enabled
= (ad-advice-enabled advice
)
4058 (if enabled
"Enabled " "Disabled")
4059 (propertize fname
'face
'font-lock-function-name-face
)
4060 (ad-make-single-advice-docstring advice class nil
))
4061 (list function class advice
))))))
4063 (defun anything-c-advice-persistent-action (func-class-advice)
4064 (if current-prefix-arg
4065 (anything-c-advice-toggle func-class-advice
)
4066 (describe-function (car func-class-advice
))))
4068 (defun anything-c-advice-toggle (func-class-advice)
4069 (destructuring-bind (function class advice
) func-class-advice
4070 (cond ((ad-advice-enabled advice
)
4071 (ad-advice-set-enabled advice nil
)
4072 (message "Disabled"))
4074 (ad-advice-set-enabled advice t
)
4075 (message "Enabled")))
4076 (ad-activate function
)
4077 (and anything-in-persistent-action
4078 (anything-c-advice-update-current-display-string))))
4080 (defun anything-c-advice-update-current-display-string ()
4081 (anything-edit-current-selection
4082 (let ((newword (cond ((looking-at "Disabled") "Enabled")
4083 ((looking-at "Enabled") "Disabled")))
4086 (delete-region (point) (progn (forward-word 1) (point)))
4087 (insert newword
)))))
4090 (defun anything-manage-advice ()
4091 "Preconfigured `anything' to disable/enable function advices."
4093 (anything-other-buffer 'anything-c-source-advice
"*anything advice*"))
4097 (defvar anything-c-source-emacs-variables
4098 '((name .
"Emacs Variables")
4099 (candidates .
(lambda ()
4100 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
4102 (requires-pattern .
2))
4103 "Source for completing Emacs variables.")
4104 ;; (anything 'anything-c-source-emacs-variables)
4108 (eval-when-compile (require 'bookmark
))
4109 (defvar anything-c-source-bookmarks
4110 '((name .
"Bookmarks")
4112 (require 'bookmark
)))
4113 (candidates . bookmark-all-names
)
4115 "See (info \"(emacs)Bookmarks\").")
4116 ;; (anything 'anything-c-source-bookmarks)
4119 (defvar anything-c-source-bookmark-set
4120 '((name .
"Set Bookmark")
4122 (action . bookmark-set
))
4123 "See (info \"(emacs)Bookmarks\").")
4124 ;; (anything 'anything-c-source-bookmark-set)
4126 ;;; Visible Bookmarks
4127 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
4130 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
4131 (defvar anything-c-source-bm
4132 '((name .
"Visible Bookmarks")
4133 (init . anything-c-bm-init
)
4134 (candidates-in-buffer)
4138 http://www.nongnu.org/bm/")
4140 (defun anything-c-bm-init ()
4141 "Init function for `anything-c-source-bm'."
4142 (when (require 'bm nil t
)
4144 (let ((bookmarks (bm-lists))
4145 (buf (anything-candidate-buffer 'global
)))
4146 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
4147 '< :key
'overlay-start
))
4148 (let ((start (overlay-start bm
))
4149 (end (overlay-end bm
))
4150 (annotation (or (overlay-get bm
'annotation
) "")))
4151 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
4152 (let ((str (format "%5d: [%s]: %s\n"
4153 (line-number-at-pos start
)
4155 (buffer-substring start
(1- end
)))))
4156 (with-current-buffer buf
(insert str
))))))))))
4158 ;;; Special bookmarks
4159 (defvar anything-c-source-bookmarks-ssh
4160 '((name .
"Bookmarks-ssh")
4162 (require 'bookmark
)))
4163 (candidates .
(lambda () (anything-c-collect-bookmarks :ssh t
)))
4165 "See (info \"(emacs)Bookmarks\").")
4166 ;; (anything 'anything-c-source-bookmarks-ssh)
4168 (defvar anything-c-source-bookmarks-su
4169 '((name .
"Bookmarks-root")
4171 (require 'bookmark
)))
4172 (candidates .
(lambda () (anything-c-collect-bookmarks :su t
)))
4173 (filtered-candidate-transformer anything-c-highlight-bookmark-su
)
4176 "See (info \"(emacs)Bookmarks\").")
4177 ;; (anything 'anything-c-source-bookmarks-su)
4179 (defvar anything-c-source-bookmarks-local
4180 '((name .
"Bookmarks-Local")
4182 (require 'bookmark
)))
4183 (candidates .
(lambda () (anything-c-collect-bookmarks :local t
)))
4184 (filtered-candidate-transformer
4185 anything-c-adaptive-sort
4186 anything-c-highlight-bookmark
)
4188 "See (info \"(emacs)Bookmarks\").")
4189 ;; (anything 'anything-c-source-bookmarks-local)
4191 (defun* anything-c-collect-bookmarks
(&key local su sudo ssh
)
4192 (let* ((lis-all (bookmark-all-names))
4193 (lis-loc (cond (local (loop for i in lis-all
4194 unless
(string-match "^(ssh)\\|^(su)" i
)
4196 (su (loop for i in lis-all
4197 when
(string-match "^(su)" i
)
4199 (sudo (loop for i in lis-all
4200 when
(string-match "^(sudo)" i
)
4202 (ssh (loop for i in lis-all
4203 when
(string-match "^(ssh)" i
)
4205 (sort lis-loc
'string-lessp
)))
4207 (defun anything-c-bookmark-root-logged-p ()
4209 (dolist (i (mapcar #'buffer-name
(buffer-list)))
4210 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
4211 (throw 'break t
)))))
4213 (defun anything-c-highlight-bookmark-su (files source
)
4214 (if (anything-c-bookmark-root-logged-p)
4215 (anything-c-highlight-bookmark files source
)
4216 (anything-c-highlight-not-logged files source
)))
4218 (defun anything-c-highlight-not-logged (files source
)
4219 (loop for i in files
4220 collect
(propertize i
'face anything-c-bookmarks-face3
)))
4222 (defun anything-c-highlight-bookmark (bookmarks source
)
4223 "Used as `candidate-transformer' to colorize bookmarks.
4224 Work both with standard Emacs bookmarks and bookmark-extensions.el."
4225 (loop for i in bookmarks
4226 for isfile
= (bookmark-get-filename i
)
4227 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
4228 (bmkext-get-buffer-name i
))
4229 for handlerp
= (and (fboundp 'bookmark-get-handler
)
4230 (bookmark-get-handler i
))
4231 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
4232 (bmkext-w3m-bookmark-p i
))
4233 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
4234 (bmkext-gnus-bookmark-p i
))
4235 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
4236 (bmkext-man-bookmark-p i
))
4237 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
4238 (bmkext-woman-bookmark-p i
))
4239 for handlerp
= (bookmark-get-handler i
)
4240 for isannotation
= (bookmark-get-annotation i
)
4241 for isabook
= (string= (bookmark-prop-get i
'type
) "addressbook")
4242 for isinfo
= (eq handlerp
'Info-bookmark-jump
)
4243 ;; Add a * if bookmark have annotation
4244 if
(and isannotation
(not (string-equal isannotation
"")))
4245 do
(setq i
(concat "*" i
))
4246 collect
(cond (;; info buffers
4248 (propertize i
'face
'anything-bmkext-info
'help-echo isfile
))
4251 (propertize i
'face
'anything-bmkext-w3m
'help-echo isfile
))
4254 (propertize i
'face
'anything-bmkext-gnus
'help-echo isfile
))
4257 (propertize i
'face
'anything-bmkext-man
'help-echo isfile
))
4260 (propertize i
'face
'((:foreground
"Tomato"))))
4262 (and isfile
(file-directory-p isfile
))
4263 (propertize i
'face anything-c-bookmarks-face1
'help-echo isfile
))
4266 (propertize i
'face
'anything-bmkext-file
'help-echo isfile
)))))
4269 ;;; Faces for bookmarks
4270 (defface anything-bmkext-info
4271 '((t (:foreground
"green")))
4272 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
4275 (defface anything-bmkext-w3m
4276 '((t (:foreground
"yellow")))
4277 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
4280 (defface anything-bmkext-gnus
4281 '((t (:foreground
"magenta")))
4282 "*Face used for Gnus bookmarks."
4285 (defface anything-bmkext-man
4286 '((t (:foreground
"Orange4")))
4287 "*Face used for Woman/man bookmarks."
4290 (defface anything-bmkext-no--file
4291 '((t (:foreground
"grey")))
4292 "*Face used for non--file bookmarks."
4295 (defface anything-bmkext-file
4296 '((t (:foreground
"Deepskyblue2")))
4297 "*Face used for non--file bookmarks."
4300 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
4301 "Face for su/sudo bookmarks."
4304 (defvar anything-c-bookmarks-face1
'anything-dir-heading
)
4305 (defvar anything-c-bookmarks-face2
'anything-file-name
)
4306 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
4309 ;;; Sources to filter bookmark-extensions bookmarks.
4310 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
4311 ;; If you want to enable google-maps in addressbook you will need
4312 ;; Julien Danjou google-maps-el package available here:
4313 ;; http://julien.danjou.info/google-maps-el.html
4315 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
4316 "Return a filtered `bookmark-alist' sorted alphabetically."
4318 with alist
= (if args
4319 (apply #'(lambda (x) (funcall fn x
)) args
)
4324 finally return
(sort sa
'string-lessp
)))
4327 (defvar anything-c-source-bmkext-addressbook
4328 '((name .
"Bookmark Addressbook")
4330 (require 'bookmark-extensions
)
4331 (bookmark-maybe-load-default-file)))
4332 (candidates . anything-c-bmkext-addressbook-setup-alist
)
4334 .
(lambda (candidate)
4335 (let ((bmk (anything-bookmark-get-bookmark-from-name
4337 (bookmark--jump-via bmk
'pop-to-buffer
))))
4338 (persistent-help .
"Show contact - Prefix with C-u to append")
4339 (filtered-candidate-transformer
4340 anything-c-adaptive-sort
4341 anything-c-highlight-bookmark
)
4342 (action .
(("Show person's data"
4343 .
(lambda (candidate)
4344 (let ((bmk (anything-bookmark-get-bookmark-from-name
4346 (current-prefix-arg anything-current-prefix-arg
))
4347 (bookmark-jump bmk
))))
4349 .
(lambda (candidate)
4350 (let ((bmk (anything-bookmark-get-bookmark-from-name
4352 (if anything-current-prefix-arg
4353 (addressbook-set-mail-buffer1 bmk
'append
)
4354 (addressbook-set-mail-buffer1 bmk
)))))
4356 .
(lambda (candidate)
4357 (let ((bmk (anything-bookmark-get-bookmark-from-name
4359 (addressbook-bookmark-edit
4360 (assoc bmk bookmark-alist
)))))
4361 ("Insert Email at point"
4362 .
(lambda (candidate)
4363 (let* ((bmk (anything-bookmark-get-bookmark-from-name
4365 (mlist (split-string
4367 'email
(assoc bmk bookmark-alist
))
4370 (if (> (length mlist
) 1)
4372 "Insert Mail Address: " mlist
:must-match t
)
4375 .
(lambda (candidate)
4376 (let ((bmk (anything-bookmark-get-bookmark-from-name
4378 (bookmark-show-annotation bmk
))))
4380 .
(lambda (candidate)
4381 (let ((bmk (anything-bookmark-get-bookmark-from-name
4383 (bookmark-edit-annotation bmk
))))
4385 .
(lambda (candidate)
4386 (let* ((bmk (anything-bookmark-get-bookmark-from-name
4388 (full-bmk (assoc bmk bookmark-alist
)))
4389 (addressbook-google-map full-bmk
))))))))
4392 (defun anything-c-bmkext-addressbook-setup-alist ()
4393 "Specialized filter function for bookmarks w3m."
4394 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only
))
4397 (defvar anything-c-source-bookmark-w3m
4398 '((name .
"Bookmark W3m")
4400 (require 'bookmark-extensions
)
4401 (bookmark-maybe-load-default-file)))
4402 (candidates . anything-c-bookmark-w3m-setup-alist
)
4403 (filtered-candidate-transformer
4404 anything-c-adaptive-sort
4405 anything-c-highlight-bookmark
)
4407 ;; (anything 'anything-c-source-bookmark-w3m)
4409 (defun anything-c-bookmark-w3m-setup-alist ()
4410 "Specialized filter function for bookmarks w3m."
4411 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
4414 (defvar anything-c-source-bookmark-images
4415 '((name .
"Bookmark Images")
4417 (require 'bookmark-extensions
)
4418 (bookmark-maybe-load-default-file)))
4419 (candidates . anything-c-bookmark-images-setup-alist
)
4420 (filtered-candidate-transformer
4421 anything-c-adaptive-sort
4422 anything-c-highlight-bookmark
)
4424 ;; (anything 'anything-c-source-bookmark-images)
4426 (defun anything-c-bookmark-images-setup-alist ()
4427 "Specialized filter function for images bookmarks."
4428 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only
))
4431 (defvar anything-c-source-bookmark-man
4432 '((name .
"Bookmark Woman&Man")
4434 (require 'bookmark-extensions
)
4435 (bookmark-maybe-load-default-file)))
4436 (candidates . anything-c-bookmark-man-setup-alist
)
4437 (filtered-candidate-transformer
4438 anything-c-adaptive-sort
4439 anything-c-highlight-bookmark
)
4441 ;; (anything 'anything-c-source-bookmark-man)
4443 (defun anything-c-bookmark-man-setup-alist ()
4444 "Specialized filter function for bookmarks w3m."
4445 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
4446 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
4449 (defvar anything-c-source-bookmark-gnus
4450 '((name .
"Bookmark Gnus")
4452 (require 'bookmark-extensions
)
4453 (bookmark-maybe-load-default-file)))
4454 (candidates . anything-c-bookmark-gnus-setup-alist
)
4455 (filtered-candidate-transformer
4456 anything-c-adaptive-sort
4457 anything-c-highlight-bookmark
)
4459 ;; (anything 'anything-c-source-bookmark-gnus)
4461 (defun anything-c-bookmark-gnus-setup-alist ()
4462 "Specialized filter function for bookmarks gnus."
4463 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
4466 (defvar anything-c-source-bookmark-info
4467 '((name .
"Bookmark Info")
4469 (require 'bookmark-extensions
)
4470 (bookmark-maybe-load-default-file)))
4471 (candidates . anything-c-bookmark-info-setup-alist
)
4472 (filtered-candidate-transformer
4473 anything-c-adaptive-sort
4474 anything-c-highlight-bookmark
)
4476 ;; (anything 'anything-c-source-bookmark-info)
4478 (defun anything-c-bookmark-info-setup-alist ()
4479 "Specialized filter function for bookmarks info."
4480 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
4482 ;; Local Files&directories
4483 (defvar anything-c-source-bookmark-files
&dirs
4484 '((name .
"Bookmark Files&Directories")
4486 (require 'bookmark-extensions
)
4487 (bookmark-maybe-load-default-file)))
4488 (candidates . anything-c-bookmark-local-files-setup-alist
)
4489 (filtered-candidate-transformer
4490 anything-c-adaptive-sort
4491 anything-c-highlight-bookmark
)
4493 ;; (anything 'anything-c-source-bookmark-files&dirs)
4495 (defun anything-c-bookmark-local-files-setup-alist ()
4496 "Specialized filter function for bookmarks locals files."
4497 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
4499 ;; Su Files&directories
4500 (defvar anything-c-source-bookmark-su-files
&dirs
4501 '((name .
"Bookmark Root-Files&Directories")
4503 (require 'bookmark-extensions
)
4504 (bookmark-maybe-load-default-file)))
4505 (candidates . anything-c-bookmark-su-files-setup-alist
)
4506 (filtered-candidate-transformer
4507 anything-c-adaptive-sort
4508 anything-c-highlight-bookmark-su
)
4510 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
4512 (defun anything-c-bookmark-su-files-setup-alist ()
4513 "Specialized filter function for bookmarks su/sudo files."
4515 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
4517 for isfile
= (bookmark-get-filename i
)
4518 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
4520 (string-match tramp-file-name-regexp isfile
)))
4521 for issu
= (and istramp
4522 (string-match bmkext-su-or-sudo-regexp isfile
))
4526 ;; Ssh Files&directories
4527 (defvar anything-c-source-bookmark-ssh-files
&dirs
4528 '((name .
"Bookmark Ssh-Files&Directories")
4530 (require 'bookmark-extensions
)
4531 (bookmark-maybe-load-default-file)))
4532 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
4533 (filtered-candidate-transformer . anything-c-adaptive-sort
)
4535 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
4537 (defun anything-c-bookmark-ssh-files-setup-alist ()
4538 "Specialized filter function for bookmarks ssh files."
4540 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
4542 for isfile
= (bookmark-get-filename i
)
4543 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
4545 (string-match tramp-file-name-regexp isfile
)))
4546 for isssh
= (and istramp
4547 (string-match "/ssh:" isfile
))
4552 ;; All bookmark-extensions sources.
4554 (defun anything-bookmark-ext ()
4555 "Preconfigured `anything' for bookmark-extensions sources.
4556 Needs bookmark-ext.el
4558 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
4562 '(anything-c-source-bookmark-files&dirs
4563 anything-c-source-bookmark-w3m
4564 anything-c-source-bmkext-addressbook
4565 anything-c-source-bookmark-gnus
4566 anything-c-source-bookmark-info
4567 anything-c-source-bookmark-man
4568 anything-c-source-bookmark-images
4569 anything-c-source-bookmark-su-files
&dirs
4570 anything-c-source-bookmark-ssh-files
&dirs
)
4571 :prompt
"SearchBookmark: "
4572 :buffer
"*anything bmkext*"))
4575 ;; Firefox bookmarks
4576 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
4577 ;; (only for firefox versions >=3)
4578 ;; To achieve that, open about:config in firefox and double click on this line to enable value
4580 ;; user_pref("browser.bookmarks.autoExportHTML", false);
4581 ;; You should have now:
4582 ;; user_pref("browser.bookmarks.autoExportHTML", true);
4584 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
4585 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
4587 (defun anything-get-firefox-user-init-dir ()
4588 "Guess the default Firefox user directory name."
4589 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
4591 (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
4592 (goto-char (point-min))
4594 (when (search-forward "Path=" nil t
)
4595 (buffer-substring-no-properties (point) (point-at-eol)))
4597 (file-name-as-directory (concat moz-dir moz-user-dir
))))
4599 (defun anything-guess-firefox-bookmark-file ()
4600 "Return the path of the Firefox bookmarks file."
4601 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
4603 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
4604 "Parse html bookmark FILE and return an alist with (title . url) as elements."
4605 (let (bookmarks-alist url title
)
4607 (insert-file-contents file
)
4608 (goto-char (point-min))
4609 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
4611 (when (re-search-forward url-regexp nil t
)
4612 (setq url
(match-string 0)))
4613 (when (re-search-forward bmk-regexp nil t
)
4614 (setq title
(match-string 1)))
4615 (push (cons title url
) bookmarks-alist
)
4617 (nreverse bookmarks-alist
)))
4619 (defvar anything-c-firefox-bookmarks-alist nil
)
4620 (defvar anything-c-source-firefox-bookmarks
4621 '((name .
"Firefox Bookmarks")
4623 (setq anything-c-firefox-bookmarks-alist
4624 (anything-html-bookmarks-to-alist
4625 (anything-guess-firefox-bookmark-file)
4626 anything-firefox-bookmark-url-regexp
4627 anything-firefox-bookmarks-regexp
))))
4628 (candidates .
(lambda ()
4629 (mapcar #'car anything-c-firefox-bookmarks-alist
)))
4630 (filtered-candidate-transformer
4631 anything-c-adaptive-sort
4632 anything-c-highlight-firefox-bookmarks
)
4633 (action .
(("Browse Url Firefox"
4634 .
(lambda (candidate)
4636 (anything-c-firefox-bookmarks-get-value candidate
))))
4638 .
(lambda (candidate)
4640 (anything-c-firefox-bookmarks-get-value candidate
))))
4643 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
4645 ;; (anything 'anything-c-source-firefox-bookmarks)
4647 (defun anything-c-firefox-bookmarks-get-value (elm)
4648 (assoc-default elm anything-c-firefox-bookmarks-alist
))
4650 (defun anything-c-highlight-firefox-bookmarks (bookmarks source
)
4651 (loop for i in bookmarks
4653 i
'face
'((:foreground
"YellowGreen"))
4654 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
4658 ;; Some users have the emacs-w3m library in load-path
4659 ;; without having the w3m executable :-;
4660 ;; So check if w3m program is present before trying to load
4663 (when (executable-find "w3m")
4664 (require 'w3m-bookmark nil t
)))
4665 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html")
4668 (defface anything-w3m-bookmarks-face
'((t (:foreground
"cyan1" :underline t
)))
4669 "Face for w3m bookmarks" :group
'anything
)
4671 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
4672 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
4673 (defvar anything-c-w3m-bookmarks-alist nil
)
4674 (defvar anything-c-source-w3m-bookmarks
4675 '((name .
"W3m Bookmarks")
4677 (setq anything-c-w3m-bookmarks-alist
4678 (anything-html-bookmarks-to-alist
4680 anything-w3m-bookmark-url-regexp
4681 anything-w3m-bookmarks-regexp
))))
4682 (candidates .
(lambda ()
4683 (mapcar #'car anything-c-w3m-bookmarks-alist
)))
4684 (filtered-candidate-transformer
4685 anything-c-adaptive-sort
4686 anything-c-highlight-w3m-bookmarks
)
4687 (action .
(("Browse Url"
4688 .
(lambda (candidate)
4689 (anything-c-w3m-browse-bookmark candidate
)))
4692 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
4693 ("Browse Url Firefox"
4694 .
(lambda (candidate)
4695 (anything-c-w3m-browse-bookmark candidate t
)))
4697 .
(lambda (candidate)
4698 (anything-c-w3m-delete-bookmark candidate
)))
4700 .
(lambda (candidate)
4701 (anything-c-w3m-rename-bookmark candidate
)))))
4702 (persistent-action .
(lambda (candidate)
4703 (if current-prefix-arg
4704 (anything-c-w3m-browse-bookmark candidate t
)
4705 (anything-c-w3m-browse-bookmark candidate nil t
))))
4706 (persistent-help .
"Open URL with emacs-w3m in new tab / \
4707 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
4708 "Needs w3m and emacs-w3m.
4710 http://w3m.sourceforge.net/
4711 http://emacs-w3m.namazu.org/")
4713 ;; (anything 'anything-c-source-w3m-bookmarks)
4715 (defun anything-c-w3m-bookmarks-get-value (elm)
4716 (replace-regexp-in-string
4717 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist
))))
4719 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
4720 (let* ((fn (if use-firefox
'browse-url-firefox
'w3m-browse-url
))
4721 (arg (and (eq fn
'w3m-browse-url
) new-tab
)))
4722 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
4724 (defun anything-c-highlight-w3m-bookmarks (bookmarks source
)
4725 (loop for i in bookmarks
4727 i
'face
'anything-w3m-bookmarks-face
4728 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
4731 (defun anything-c-w3m-delete-bookmark (elm)
4733 (find-file-literally w3m-bookmark-file
)
4734 (goto-char (point-min))
4735 (when (re-search-forward elm nil t
)
4737 (delete-region (point)
4738 (line-end-position))
4739 (delete-blank-lines))
4740 (save-buffer (current-buffer))
4741 (kill-buffer (current-buffer))))
4743 (defun anything-c-w3m-rename-bookmark (elm)
4744 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
4745 (new-title (read-string "NewTitle: " old-title
)))
4747 (find-file-literally w3m-bookmark-file
)
4748 (goto-char (point-min))
4749 (when (re-search-forward (concat elm
"<") nil t
)
4750 (goto-char (1- (point)))
4751 (delete-char (- (length old-title
)))
4753 (save-buffer (current-buffer))
4754 (kill-buffer (current-buffer)))))
4757 ;;; Elisp library scan
4758 (defvar anything-c-source-elisp-library-scan
4759 '((name .
"Elisp libraries (Scan)")
4760 (init .
(anything-c-elisp-library-scan-init))
4761 (candidates-in-buffer)
4762 (action ("Find library"
4763 .
(lambda (candidate) (find-file (find-library-name candidate
))))
4764 ("Find library other window"
4765 .
(lambda (candidate)
4766 (find-file-other-window (find-library-name candidate
))))
4768 .
(lambda (candidate) (load-library candidate
))))))
4769 ;; (anything 'anything-c-source-elisp-library-scan)
4771 (defun anything-c-elisp-library-scan-init ()
4772 "Init anything buffer status."
4773 (let ((anything-buffer (anything-candidate-buffer 'global
))
4774 (library-list (anything-c-elisp-library-scan-list)))
4775 (with-current-buffer anything-buffer
4776 (dolist (library library-list
)
4777 (insert (format "%s\n" library
))))))
4779 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
4780 "Do completion for file names passed to `locate-file'.
4781 DIRS is directory to search path.
4782 STRING is string to match."
4783 ;; Use `load-path' as path when ignore `dirs'.
4784 (or dirs
(setq dirs load-path
))
4785 ;; Init with blank when ignore `string'.
4786 (or string
(setq string
""))
4787 ;; Get library list.
4788 (let ((string-dir (file-name-directory string
))
4789 ;; File regexp that suffix match `load-file-rep-suffixes'.
4790 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
4795 (setq dir default-directory
))
4797 (setq dir
(expand-file-name string-dir dir
)))
4798 (when (file-directory-p dir
)
4799 (dolist (file (file-name-all-completions
4800 (file-name-nondirectory string
) dir
))
4801 ;; Suffixes match `load-file-rep-suffixes'.
4802 (setq name
(if string-dir
(concat string-dir file
) file
))
4803 (if (string-match match-regexp name
)
4804 (add-to-list 'names name
)))))
4809 (defvar anything-c-imenu-delimiter
" / ")
4811 (defvar anything-c-imenu-index-filter nil
)
4812 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
4814 (defvar anything-c-cached-imenu-alist nil
)
4815 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
4817 (defvar anything-c-cached-imenu-candidates nil
)
4818 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
4820 (defvar anything-c-cached-imenu-tick nil
)
4821 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
4823 (eval-when-compile (require 'imenu
))
4824 (setq imenu-auto-rescan t
)
4826 (defun anything-imenu-create-candidates (entry)
4827 "Create candidates with ENTRY."
4828 (if (listp (cdr entry
))
4831 (if (consp (cdr sub
))
4834 (concat (car entry
) anything-c-imenu-delimiter subentry
))
4835 (anything-imenu-create-candidates sub
))
4836 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
4840 (defvar anything-c-source-imenu
4842 (init .
(lambda () (require 'imenu
)))
4843 (candidates . anything-c-imenu-candidates
)
4844 (persistent-action .
(lambda (elm)
4845 (anything-c-imenu-default-action elm
)
4846 (unless (fboundp 'semantic-imenu-tag-overlay
)
4847 (anything-match-line-color-current-line))))
4848 (persistent-help .
"Show this entry")
4849 (action . anything-c-imenu-default-action
))
4850 "See (info \"(emacs)Imenu\")")
4852 ;; (anything 'anything-c-source-imenu)
4854 (defun anything-c-imenu-candidates ()
4855 (with-current-buffer anything-current-buffer
4856 (let ((tick (buffer-modified-tick)))
4857 (if (eq anything-c-cached-imenu-tick tick
)
4858 anything-c-cached-imenu-candidates
4859 (setq imenu--index-alist nil
)
4860 (setq anything-c-cached-imenu-tick tick
4861 anything-c-cached-imenu-candidates
4864 'anything-imenu-create-candidates
4865 (setq anything-c-cached-imenu-alist
4866 (let ((index (imenu--make-index-alist)))
4867 (if anything-c-imenu-index-filter
4868 (funcall anything-c-imenu-index-filter index
)
4870 (setq anything-c-cached-imenu-candidates
4871 (mapcar #'(lambda (x)
4875 anything-c-cached-imenu-candidates
))))))
4877 (setq imenu-default-goto-function
'imenu-default-goto-function
)
4878 (defun anything-c-imenu-default-action (elm)
4879 "The default action for `anything-c-source-imenu'."
4880 (let ((path (split-string elm anything-c-imenu-delimiter
))
4881 (alist anything-c-cached-imenu-alist
))
4882 (if (> (length path
) 1)
4884 (setq alist
(assoc (car path
) alist
))
4885 (setq elm
(cadr path
))
4886 (imenu (assoc elm alist
)))
4887 (imenu (assoc elm alist
)))))
4890 (defvar anything-c-ctags-modes
4891 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
4892 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
4893 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
4895 (defun anything-c-source-ctags-init ()
4896 (when (and buffer-file-name
4897 (memq major-mode anything-c-ctags-modes
)
4898 (anything-current-buffer-is-modified))
4899 (with-current-buffer (anything-candidate-buffer 'local
)
4900 (call-process-shell-command
4901 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
4902 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
4903 anything-buffer-file-name
)
4904 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
4905 nil
(current-buffer))
4906 (goto-char (point-min))
4908 (delete-region (point-min) (point))
4909 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
4910 for lineno-start
= (point)
4911 for lineno
= (buffer-substring
4913 (1- (search-forward "," (point-at-eol) t
)))
4916 (insert (format "%5s:" lineno
))
4917 (search-forward "\177" (point-at-eol) t
)
4918 (delete-region (1- (point)) (point-at-eol))
4919 (forward-line 1)))))
4921 (defvar anything-c-source-ctags
4922 '((name .
"Exuberant ctags")
4923 (init . anything-c-source-ctags-init
)
4924 (candidates-in-buffer)
4927 "Needs Exuberant Ctags.
4929 http://ctags.sourceforge.net/")
4930 ;; (anything 'anything-c-source-ctags)
4933 (eval-when-compile (require 'semantic nil t
))
4934 (declare-function semantic-format-tag-summarize
"ext:format.el" (tag &optional parent color
) t
)
4935 (declare-function semantic-tag-components
"ext:tag.el" (tag) t
)
4936 (declare-function semantic-go-to-tag
"ext:tag-file.el" (tag) t
)
4937 (declare-function semantic-tag-type
"ext:tag-file.el" (tag) t
)
4938 (declare-function semantic-tag-class
"ext:tag-file.el" (tag) t
)
4939 (defvar anything-semantic-candidates nil
)
4941 (defun anything-semantic-construct-candidates (tags depth
)
4942 (when (require 'semantic nil t
)
4948 (let ((type (semantic-tag-type tag
))
4949 (class (semantic-tag-class tag
)))
4950 (if (or (and (stringp type
)
4951 (or (string= type
"class")
4952 (string= type
"namespace")))
4953 (eq class
'function
)
4954 (eq class
'variable
))
4955 (cons (cons (concat (make-string (* depth
2) ?\s
)
4956 (semantic-format-tag-summarize tag nil t
))
4958 (anything-semantic-construct-candidates
4959 (semantic-tag-components tag
) (1+ depth
)))))))
4962 (defun anything-semantic-default-action (candidate)
4963 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
4964 (semantic-go-to-tag tag
)))
4966 (defvar anything-c-source-semantic
4967 '((name .
"Semantic Tags")
4969 (setq anything-semantic-candidates
4970 (ignore-errors (anything-semantic-construct-candidates
4971 (semantic-fetch-tags) 0)))))
4972 (candidates .
(lambda ()
4973 (if anything-semantic-candidates
4974 (mapcar 'car anything-semantic-candidates
))))
4975 (persistent-action .
(lambda (elm)
4976 (anything-semantic-default-action elm
)
4977 (anything-match-line-color-current-line)))
4978 (persistent-help .
"Show this entry")
4979 (action . anything-semantic-default-action
)
4980 "Needs semantic in CEDET.
4982 http://cedet.sourceforge.net/semantic.shtml
4983 http://cedet.sourceforge.net/"))
4985 ;; (anything 'anything-c-source-semantic)
4987 ;;; Function is called by
4989 (defun anything-simple-call-tree ()
4990 "Preconfigured `anything' for simple-call-tree. List function relationships.
4992 Needs simple-call-tree.el.
4993 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
4995 (anything-other-buffer
4996 '(anything-c-source-simple-call-tree-functions-callers
4997 anything-c-source-simple-call-tree-callers-functions
)
4998 "*anything simple-call-tree*"))
5000 (defvar anything-c-source-simple-call-tree-functions-callers
5001 '((name .
"Function is called by")
5002 (init . anything-c-simple-call-tree-functions-callers-init
)
5004 (candidates . anything-c-simple-call-tree-candidates
)
5005 (persistent-action . anything-c-simple-call-tree-persistent-action
)
5006 (persistent-help .
"Show function definitions by rotation")
5007 (action ("Find definition selected by persistent-action" .
5008 anything-c-simple-call-tree-find-definition
)))
5009 "Needs simple-call-tree.el.
5010 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
5012 (defvar anything-c-simple-call-tree-tick nil
)
5013 (make-variable-buffer-local 'anything-c-simple-call-tree-tick
)
5014 (defun anything-c-simple-call-tree-analyze-maybe ()
5015 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick
)
5016 (simple-call-tree-analyze)
5017 (setq anything-c-simple-call-tree-tick
(buffer-chars-modified-tick))))
5019 (defun anything-c-simple-call-tree-init-base (function message
)
5020 (require 'simple-call-tree
)
5022 (when (anything-current-buffer-is-modified)
5023 (anything-c-simple-call-tree-analyze-maybe)
5024 (let ((list (funcall function simple-call-tree-alist
)))
5025 (with-current-buffer (anything-candidate-buffer 'local
)
5026 (dolist (entry list
)
5027 (let ((funcs (concat " " (mapconcat #'identity
(cdr entry
) "\n "))))
5028 (insert (car entry
) message
5029 (if (string= funcs
" ")
5034 (defun anything-c-simple-call-tree-functions-callers-init ()
5035 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
5038 (defun anything-c-simple-call-tree-candidates ()
5039 (with-current-buffer (anything-candidate-buffer)
5040 (split-string (buffer-string) "\n\n")))
5042 (defvar anything-c-simple-call-tree-related-functions nil
)
5043 (defvar anything-c-simple-call-tree-function-index
0)
5044 (defun anything-c-simple-call-tree-persistent-action (candidate)
5045 (unless (eq last-command
'anything-execute-persistent-action
)
5046 (setq anything-c-simple-call-tree-related-functions
5047 (delete "no functions."
5049 (replace-regexp-in-string " \\| is called by\\| calls "
5052 (setq anything-c-simple-call-tree-function-index -
1))
5053 (incf anything-c-simple-call-tree-function-index
)
5054 (anything-c-simple-call-tree-find-definition candidate
))
5056 (defun anything-c-simple-call-tree-find-definition (candidate)
5059 (nth (mod anything-c-simple-call-tree-function-index
5060 (length anything-c-simple-call-tree-related-functions
))
5061 anything-c-simple-call-tree-related-functions
))))
5063 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
5066 (defvar anything-c-source-simple-call-tree-callers-functions
5067 '((name .
"Function calls")
5068 (init . anything-c-simple-call-tree-callers-functions-init
)
5070 (candidates . anything-c-simple-call-tree-candidates
)
5071 (persistent-action . anything-c-simple-call-tree-persistent-action
)
5072 (persistent-help .
"Show function definitions by rotation")
5073 (action ("Find definition selected by persistent-action" .
5074 anything-c-simple-call-tree-find-definition
)))
5075 "Needs simple-call-tree.el.
5076 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
5078 (defun anything-c-simple-call-tree-callers-functions-init ()
5079 (anything-c-simple-call-tree-init-base 'identity
" calls \n"))
5081 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
5083 ;;; Commands/Options with doc
5084 (defvar anything-c-auto-document-data nil
)
5085 (make-variable-buffer-local 'anything-c-auto-document-data
)
5086 (defvar anything-c-source-commands-and-options-in-file
5087 '((name .
"Commands/Options in file")
5089 .
(lambda (x) (format "Commands/Options in %s"
5090 (buffer-local-value 'buffer-file-name
5091 anything-current-buffer
))))
5092 (candidates . anything-command-and-options-candidates
)
5095 "List Commands and Options with doc. It needs auto-document.el .
5097 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
5099 (eval-when-compile (require 'auto-document nil t
))
5100 (defun anything-command-and-options-candidates ()
5101 (with-current-buffer anything-current-buffer
5102 (when (and (require 'auto-document nil t
)
5103 (eq major-mode
'emacs-lisp-mode
)
5104 (or (anything-current-buffer-is-modified)
5105 (not anything-c-auto-document-data
)))
5106 (or imenu--index-alist
(imenu--make-index-alist t
))
5107 (setq anything-c-auto-document-data
5108 (destructuring-bind (commands options
)
5109 (adoc-construct anything-current-buffer
)
5111 (loop for
(command . doc
) in commands
5112 for cmdname
= (symbol-name command
)
5115 (format "Command: %s\n %s"
5116 (propertize cmdname
'face font-lock-function-name-face
)
5117 (adoc-first-line doc
))
5118 (assoc cmdname imenu--index-alist
)))
5119 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
5120 for
(option doc default
) in options
5121 for optname
= (symbol-name option
)
5124 (format "Option: %s\n %s\n default = %s"
5125 (propertize optname
'face font-lock-variable-name-face
)
5126 (adoc-first-line doc
)
5127 (adoc-prin1-to-string default
))
5130 anything-c-auto-document-data
))
5132 ;; (anything 'anything-c-source-commands-and-options-in-file)
5134 ;;;; <Color and Face>
5136 (defvar anything-c-source-customize-face
5137 '((name .
"Customize Face")
5139 (unless (anything-candidate-buffer)
5140 (save-window-excursion (list-faces-display))
5141 (anything-candidate-buffer (get-buffer "*Faces*")))))
5142 (candidates-in-buffer)
5143 (get-line . buffer-substring
)
5144 (action .
(lambda (line)
5145 (customize-face (intern (car (split-string line
))))))
5146 (requires-pattern .
3))
5147 "See (info \"(emacs)Faces\")")
5148 ;; (anything 'anything-c-source-customize-face)
5151 (defvar anything-c-source-colors
5153 (init .
(lambda () (unless (anything-candidate-buffer)
5154 (save-window-excursion (list-colors-display))
5155 (anything-candidate-buffer (get-buffer "*Colors*")))))
5156 (candidates-in-buffer)
5157 (get-line . buffer-substring
)
5159 ("Copy Name" .
(lambda (candidate)
5160 (kill-new (anything-c-colors-get-name candidate
))))
5161 ("Copy RGB" .
(lambda (candidate)
5162 (kill-new (anything-c-colors-get-rgb candidate
))))
5163 ("Insert Name" .
(lambda (candidate)
5164 (with-current-buffer anything-current-buffer
5165 (insert (anything-c-colors-get-name candidate
)))))
5166 ("Insert RGB" .
(lambda (candidate)
5167 (with-current-buffer anything-current-buffer
5168 (insert (anything-c-colors-get-rgb candidate
))))))))
5169 ;; (anything 'anything-c-source-colors)
5171 (defun anything-c-colors-get-name (candidate)
5173 (replace-regexp-in-string
5176 (insert (capitalize candidate
))
5177 (goto-char (point-min))
5178 (search-forward-regexp "\\s-\\{2,\\}")
5179 (delete-region (point) (point-max))
5182 (defun anything-c-colors-get-rgb (candidate)
5184 (replace-regexp-in-string
5187 (insert (capitalize candidate
))
5188 (goto-char (point-max))
5189 (search-backward-regexp "\\s-\\{2,\\}")
5190 (delete-region (point) (point-min))
5193 ;;;; <Search Engine>
5194 ;;; Tracker desktop search
5195 (defvar anything-c-source-tracker-search
5196 '((name .
"Tracker Search")
5197 (candidates .
(lambda ()
5198 (start-process "tracker-search-process" nil
5202 (requires-pattern .
3)
5204 "Source for retrieving files matching the current input pattern
5205 with the tracker desktop search.")
5206 ;; (anything 'anything-c-source-tracker-search)
5208 ;;; Spotlight (MacOS X desktop search)
5209 (defvar anything-c-source-mac-spotlight
5212 .
(lambda () (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
5214 (requires-pattern .
3)
5216 "Source for retrieving files via Spotlight's command line
5218 ;; (anything 'anything-c-source-mac-spotlight)
5223 (defvar anything-c-source-kill-ring
5224 '((name .
"Kill Ring")
5225 (init .
(lambda () (anything-attrset 'last-command last-command
)))
5226 (candidates . anything-c-kill-ring-candidates
)
5227 (action . anything-c-kill-ring-action
)
5231 "Source for browse and insert contents of kill-ring.")
5233 (defun anything-c-kill-ring-candidates ()
5234 (loop for kill in kill-ring
5235 unless
(or (< (length kill
) anything-kill-ring-threshold
)
5236 (string-match "^[\\s\\t]+$" kill
))
5239 (defun anything-c-kill-ring-action (str)
5240 "Insert STR in `kill-ring' and set STR to the head.
5241 If this action is executed just after `yank',
5242 replace with STR as yanked string."
5243 (setq kill-ring
(delete str kill-ring
))
5244 (if (not (eq (anything-attr 'last-command
) 'yank
))
5245 (insert-for-yank str
)
5247 (let ((inhibit-read-only t
)
5248 (before (< (point) (mark t
))))
5250 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
5251 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
5252 (setq yank-undo-function nil
)
5253 (set-marker (mark-marker) (point) (current-buffer))
5254 (insert-for-yank str
)
5255 ;; Set the window start back where it was in the yank command,
5257 (set-window-start (selected-window) yank-window-start t
)
5259 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
5260 ;; It is cleaner to avoid activation, even though the command
5261 ;; loop would deactivate the mark because we inserted text.
5262 (goto-char (prog1 (mark t
)
5263 (set-marker (mark-marker) (point) (current-buffer)))))))
5266 ;; (anything 'anything-c-source-kill-ring)
5269 ;; DO NOT include these sources in `anything-sources' use
5270 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
5271 ;; `anything-all-mark-rings' instead.
5273 (defun anything-c-source-mark-ring-candidates ()
5274 (flet ((get-marks (pos)
5278 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
5279 (when (string= "" line
)
5280 (setq line
"<EMPTY LINE>"))
5281 (format "%7d: %s" (line-number-at-pos) line
)))))
5282 (with-current-buffer anything-current-buffer
5284 with marks
= (cons (mark-marker) mark-ring
)
5287 for m
= (get-marks i
)
5288 unless
(member m recip
)
5289 collect m into recip
5290 finally return recip
))))
5292 (defvar anything-mark-ring-cache nil
)
5293 (defvar anything-c-source-mark-ring
5294 '((name .
"mark-ring")
5296 (setq anything-mark-ring-cache
5297 (ignore-errors (anything-c-source-mark-ring-candidates)))))
5298 (candidates .
(lambda ()
5299 (anything-aif anything-mark-ring-cache
5301 (action .
(("Goto line"
5302 .
(lambda (candidate)
5303 (anything-goto-line (string-to-number candidate
))))))
5304 (persistent-action .
(lambda (candidate)
5305 (anything-goto-line (string-to-number candidate
))
5306 (anything-match-line-color-current-line)))
5307 (persistent-help .
"Show this line")))
5309 ;; (anything 'anything-c-source-mark-ring)
5312 (defun anything-mark-ring ()
5313 "Preconfigured `anything' for `anything-c-source-mark-ring'."
5315 (anything 'anything-c-source-mark-ring
))
5317 ;;; Global-mark-ring
5318 (defvar anything-c-source-global-mark-ring
5319 '((name .
"global-mark-ring")
5320 (candidates . anything-c-source-global-mark-ring-candidates
)
5321 (action .
(("Goto line"
5322 .
(lambda (candidate)
5323 (let ((items (split-string candidate
":")))
5324 (switch-to-buffer (second items
))
5325 (anything-goto-line (string-to-number (car items
))))))))
5326 (persistent-action .
(lambda (candidate)
5327 (let ((items (split-string candidate
":")))
5328 (switch-to-buffer (second items
))
5329 (anything-goto-line (string-to-number (car items
)))
5330 (anything-match-line-color-current-line))))
5331 (persistent-help .
"Show this line")))
5333 (defun anything-c-source-global-mark-ring-candidates ()
5335 (with-current-buffer (marker-buffer m
)
5339 (if (string= "" line
)
5340 (setq line
"<EMPTY LINE>")
5341 (setq line
(car (split-string (thing-at-point 'line
)
5343 (format "%7d:%s: %s"
5344 (line-number-at-pos) (marker-buffer m
) line
)))))
5346 with marks
= global-mark-ring
5349 for gm
= (unless (or (string-match
5350 "^ " (format "%s" (marker-buffer i
)))
5351 (null (marker-buffer i
)))
5353 when
(and gm
(not (member gm recip
)))
5354 collect gm into recip
5355 finally return recip
)))
5357 ;; (anything 'anything-c-source-global-mark-ring)
5360 (defun anything-global-mark-ring ()
5361 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
5363 (anything 'anything-c-source-global-mark-ring
))
5366 (defun anything-all-mark-rings ()
5367 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
5368 `anything-c-source-mark-ring'."
5370 (anything '(anything-c-source-mark-ring
5371 anything-c-source-global-mark-ring
)))
5374 ;;; Insert from register
5375 (defvar anything-c-source-register
5376 '((name .
"Registers")
5377 (candidates . anything-c-register-candidates
)
5378 (action-transformer . anything-c-register-action-transformer
)
5381 "See (info \"(emacs)Registers\")")
5383 (defun anything-c-register-candidates ()
5384 "Collecting register contents and appropriate commands."
5385 (loop for
(char . val
) in register-alist
5386 for key
= (single-key-description char
)
5387 for string-actions
=
5390 (list (int-to-string val
)
5392 'increment-register
))
5394 (let ((buf (marker-buffer val
)))
5396 (list "a marker in no buffer")
5398 "a buffer position:"
5401 (int-to-string (marker-position val
)))
5403 'insert-register
))))
5404 ((and (consp val
) (window-configuration-p (car val
)))
5405 (list "window configuration."
5407 ((and (consp val
) (frame-configuration-p (car val
)))
5408 (list "frame configuration."
5410 ((and (consp val
) (eq (car val
) 'file
))
5411 (list (concat "file:"
5412 (prin1-to-string (cdr val
))
5415 ((and (consp val
) (eq (car val
) 'file-query
))
5416 (list (concat "file:a file-query reference: file "
5419 (int-to-string (car (cdr (cdr val
))))
5423 (let ((lines (format "%4d" (length val
))))
5424 (list (format "%s: %s\n" lines
5425 (truncate-string-to-width
5426 (mapconcat 'identity
(list (car val
))
5427 ;; (mapconcat (lambda (y) y) val
5428 "^J") (- (window-width) 15)))
5431 (list ;; without properties
5432 (substring-no-properties val
)
5435 'prepend-to-register
))
5438 collect
(cons (format "register %3s: %s" key
(car string-actions
))
5439 (cons char
(cdr string-actions
)))))
5441 (defun anything-c-register-action-transformer (actions register-and-functions
)
5442 "Decide actions by the contents of register."
5443 (loop with func-actions
=
5446 (lambda (c) (insert-register (car c
))))
5448 "Jump to Register" .
5449 (lambda (c) (jump-to-register (car c
))))
5451 "Append Region to Register" .
5452 (lambda (c) (append-to-register
5453 (car c
) (region-beginning) (region-end))))
5454 (prepend-to-register
5455 "Prepend Region to Register" .
5456 (lambda (c) (prepend-to-register
5457 (car c
) (region-beginning) (region-end))))
5459 "Increment Prefix Arg to Register" .
5460 (lambda (c) (increment-register
5461 anything-current-prefix-arg
(car c
)))))
5462 for func in
(cdr register-and-functions
)
5463 for cell
= (assq func func-actions
)
5465 collect
(cdr cell
)))
5467 ;; (anything 'anything-c-source-register)
5469 ;;; Latex completion
5470 (defun anything-c-latex-math-candidates ()
5471 "Collect candidates for latex math completion."
5472 (loop for i in
(cddr LaTeX-math-menu
)
5473 for elm
= (loop for s in i when
(vectorp s
)
5474 collect
(cons (aref s
0) (aref s
1)))
5477 (defvar anything-c-source-latex-math
5478 '((name .
"Latex Math Menu")
5480 (with-current-buffer anything-current-buffer
5481 (LaTeX-math-mode 1))))
5482 (candidate-number-limit .
9999)
5483 (candidates . anything-c-latex-math-candidates
)
5484 (action .
(lambda (candidate)
5485 (call-interactively candidate
)))))
5487 ;;;; <Headline Extraction>
5488 (defvar anything-c-source-fixme
5489 '((name .
"TODO/FIXME/DRY comments")
5490 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
5493 "Show TODO/FIXME/DRY comments in current file.")
5494 ;; (anything 'anything-c-source-fixme)
5496 (defvar anything-c-source-rd-headline
5497 '((name .
"RD HeadLine")
5498 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
5499 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
5505 http://en.wikipedia.org/wiki/Ruby_Document_format")
5506 ;; (anything 'anything-c-source-rd-headline)
5508 (defvar anything-c-source-oddmuse-headline
5509 '((name .
"Oddmuse HeadLine")
5510 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
5511 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
5512 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
5515 "Show Oddmuse headlines, such as EmacsWiki.")
5516 ;; (anything 'anything-c-source-oddmuse-headline)
5518 (defvar anything-c-source-emacs-source-defun
5519 '((name .
"Emacs Source DEFUN")
5520 (headline .
"DEFUN\\|DEFVAR")
5521 (condition .
(string-match "/emacs2[0-9].+/src/.+c$"
5522 (or buffer-file-name
""))))
5523 "Show DEFUN/DEFVAR in Emacs C source file.")
5524 ;; (anything 'anything-c-source-emacs-source-defun)
5526 (defvar anything-c-source-emacs-lisp-expectations
5527 '((name .
"Emacs Lisp Expectations")
5528 (headline .
"(desc[ ]\\|(expectations")
5529 (condition .
(eq major-mode
'emacs-lisp-mode
)))
5530 "Show descriptions (desc) in Emacs Lisp Expectations.
5532 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
5533 ;; (anything 'anything-c-source-emacs-lisp-expectations)
5535 (defvar anything-c-source-emacs-lisp-toplevels
5536 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
5537 (headline .
"^(\\|(@\\*\\|^;;;;")
5538 (get-line . buffer-substring
)
5539 (condition .
(eq major-mode
'emacs-lisp-mode
))
5541 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
5542 linkd.el is optional because linkd stars are extracted by regexp.
5543 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
5544 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
5546 (defvar anything-c-source-org-headline
5547 '((name .
"Org HeadLine")
5549 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5550 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5551 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5552 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5553 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5554 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5555 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5556 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
5557 (condition .
(eq major-mode
'org-mode
))
5560 (persistent-action .
(lambda (elm)
5561 (anything-c-action-line-goto elm
)
5564 .
(lambda (actions candidate
)
5565 '(("Go to Line" . anything-c-action-line-goto
)
5566 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline
)))))
5567 "Show Org headlines.
5568 org-mode is very very much extended text-mode/outline-mode.
5570 See (find-library \"org.el\")
5571 See http://orgmode.org for the latest version.")
5573 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
5576 (anything-goto-line (car lineno-and-content
))
5577 (and (looking-at org-complex-heading-regexp
)
5578 (org-make-link-string (concat "*" (match-string 4)))))))
5580 ;; (anything 'anything-c-source-org-headline)
5582 ;;; Anything yaoddmuse
5583 ;; Be sure to have yaoddmuse.el installed
5584 ;; install-elisp may be required if you want to install elisp file from here.
5585 (defvar anything-yaoddmuse-use-cache-file nil
)
5586 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
5587 (defvar anything-c-yaoddmuse-ew-cache nil
)
5588 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
5589 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
5590 (candidates .
(lambda ()
5591 (if anything-yaoddmuse-use-cache-file
5593 (unless anything-c-yaoddmuse-ew-cache
5594 (load anything-c-yaoddmuse-cache-file
)
5595 (setq anything-c-yaoddmuse-ew-cache
5596 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
5597 anything-c-yaoddmuse-ew-cache
)
5598 (yaoddmuse-update-pagename t
)
5599 (gethash "EmacsWiki" yaoddmuse-pages-hash
))))
5600 (action .
(("Edit page" .
(lambda (candidate)
5601 (yaoddmuse-edit "EmacsWiki" candidate
)))
5602 ("Browse page" .
(lambda (candidate)
5603 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
5604 ("Browse page other window" .
(lambda (candidate)
5606 (split-window-vertically))
5607 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
5608 ("Browse diff" .
(lambda (candidate)
5609 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
5610 ("Copy URL" .
(lambda (candidate)
5611 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
5612 (message "Have copy page %s's URL to yank." candidate
)))
5613 ("Create page" .
(lambda (candidate)
5614 (yaoddmuse-edit "EmacsWiki" anything-input
)))
5615 ("Update cache" .
(lambda (candidate)
5616 (if anything-yaoddmuse-use-cache-file
5618 (anything-yaoddmuse-cache-pages t
)
5619 (setq anything-c-yaoddmuse-ew-cache
5620 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
5621 (yaoddmuse-update-pagename))))))
5622 (action-transformer anything-c-yaoddmuse-action-transformer
))
5623 "Needs yaoddmuse.el.
5625 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5627 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
5629 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
5630 '((name .
"Yaoddmuse Post library (EmacsWiki)")
5631 (init .
(anything-yaoddmuse-init))
5632 (candidates-in-buffer)
5633 (action .
(("Post library and Browse" .
(lambda (candidate)
5634 (yaoddmuse-post-file (find-library-name candidate
)
5636 (file-name-nondirectory (find-library-name candidate
))
5638 ("Post library" .
(lambda (candidate)
5639 (yaoddmuse-post-file (find-library-name candidate
)
5641 (file-name-nondirectory (find-library-name candidate
))))))))
5642 "Needs yaoddmuse.el.
5644 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5646 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
5648 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
5649 "Allow the use of `install-elisp' only on elisp files."
5650 (if (string-match "\.el$" candidate
)
5651 (append actions
'(("Install Elisp" .
(lambda (elm)
5652 (install-elisp-from-emacswiki elm
)))))
5656 (defun anything-yaoddmuse-cache-pages (&optional load
)
5657 "Fetch the list of files on emacswiki and create cache file.
5658 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
5660 (yaoddmuse-update-pagename)
5662 (find-file anything-c-yaoddmuse-cache-file
)
5664 (insert "(puthash \"EmacsWiki\" '(")
5665 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
5667 (insert (concat "(\"" (car i
) "\") ")))
5668 (insert ") yaoddmuse-pages-hash)\n")
5670 (kill-buffer (current-buffer))
5671 (when (or current-prefix-arg
5673 (load anything-c-yaoddmuse-cache-file
))))
5676 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
5677 "Preconfigured `anything' to edit or view EmacsWiki page.
5681 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5683 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
5686 (defun anything-yaoddmuse-emacswiki-post-library ()
5687 "Preconfigured `anything' to post library to EmacsWiki.
5691 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5693 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library
))
5695 (defun anything-yaoddmuse-init ()
5696 "Init anything buffer status."
5697 (let ((anything-buffer (anything-candidate-buffer 'global
))
5698 (library-list (yaoddmuse-get-library-list)))
5699 (with-current-buffer anything-buffer
5700 ;; Insert library name.
5701 (dolist (library library-list
)
5702 (insert (format "%s\n" library
)))
5704 (sort-lines nil
(point-min) (point-max)))))
5707 (defvar anything-c-source-eev-anchor
5708 '((name .
"Anchors")
5712 (with-current-buffer anything-current-buffer
5713 (loop initially
(goto-char (point-min))
5714 while
(re-search-forward (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
5715 for anchor
= (match-string-no-properties 1)
5716 collect
(cons (format "%5d:%s"
5717 (line-number-at-pos (match-beginning 0))
5718 (format ee-anchor-format anchor
)) anchor
))))))
5719 (persistent-action .
(lambda (item)
5721 (anything-match-line-color-current-line)))
5722 (persistent-help .
"Show this entry")
5723 (action .
(("Goto link" . ee-to
)))))
5724 ;; (anything 'anything-c-source-eev-anchor)
5728 (defvar anything-c-source-org-keywords
5729 '((name .
"Org Keywords")
5730 (init . anything-c-org-keywords-init
)
5731 (candidates . anything-c-org-keywords-candidates
)
5732 (action . anything-c-org-keywords-insert
)
5733 (persistent-action . anything-c-org-keywords-show-help
)
5734 (persistent-help .
"Show an example and info page to describe this keyword.")
5737 ;; (anything 'anything-c-source-org-keywords)
5738 (defvar anything-c-org-keywords-info-location
5739 '(("#+TITLE:" .
"(org)Export options")
5740 ("#+AUTHOR:" .
"(org)Export options")
5741 ("#+DATE:" .
"(org)Export options")
5742 ("#+EMAIL:" .
"(org)Export options")
5743 ("#+DESCRIPTION:" .
"(org)Export options")
5744 ("#+KEYWORDS:" .
"(org)Export options")
5745 ("#+LANGUAGE:" .
"(org)Export options")
5746 ("#+TEXT:" .
"(org)Export options")
5747 ("#+TEXT:" .
"(org)Export options")
5748 ("#+OPTIONS:" .
"(org)Export options")
5749 ("#+BIND:" .
"(org)Export options")
5750 ("#+LINK_UP:" .
"(org)Export options")
5751 ("#+LINK_HOME:" .
"(org)Export options")
5752 ("#+LATEX_HEADER:" .
"(org)Export options")
5753 ("#+EXPORT_SELECT_TAGS:" .
"(org)Export options")
5754 ("#+EXPORT_EXCLUDE_TAGS:" .
"(org)Export options")
5755 ("#+INFOJS_OPT" .
"(org)Javascript support")
5756 ("#+BEGIN_HTML" .
"(org)Quoting HTML tags")
5757 ("#+BEGIN_LaTeX" .
"(org)Quoting LaTeX code")
5758 ("#+ORGTBL" .
"(org)Radio tables")
5759 ("#+HTML:" .
"(org)Quoting HTML tags")
5760 ("#+LaTeX:" .
"(org)Quoting LaTeX code")
5761 ("#+BEGIN:" .
"(org)Dynamic blocks") ;clocktable columnview
5762 ("#+BEGIN_EXAMPLE" .
"(org)Literal examples")
5763 ("#+BEGIN_QUOTE" .
"(org)Paragraphs")
5764 ("#+BEGIN_VERSE" .
"(org)Paragraphs")
5765 ("#+BEGIN_SRC" .
"(org)Literal examples")
5766 ("#+CAPTION" .
"(org)Tables in HTML export")
5767 ("#+LABEL" .
"(org)Tables in LaTeX export")
5768 ("#+ATTR_HTML" .
"(org)Links")
5769 ("#+ATTR_LaTeX" .
"(org)Images in LaTeX export")))
5771 (defun anything-c-org-keywords-init ()
5772 (unless (anything-attr 'keywords-examples
)
5774 (anything-attrset 'keywords-examples
5778 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x
)
5779 (cons (match-string 2 x
) (match-string 1 x
)))
5780 (org-split-string (org-get-current-options) "\n"))
5781 (mapcar 'list org-additional-option-like-keywords
)))
5782 (anything-attrset 'keywords
(mapcar 'car
(anything-attr 'keywords-examples
)))))
5784 (defun anything-c-org-keywords-candidates ()
5785 (and (eq (buffer-local-value 'major-mode anything-current-buffer
) 'org-mode
)
5786 (anything-attr 'keywords
)))
5788 (defun anything-c-org-keywords-insert (keyword)
5789 (cond ((string-match "BEGIN" keyword
)
5790 (insert "#+" keyword
" ")
5792 (insert "\n#+" (replace-regexp-in-string "BEGIN" "END" keyword
) "\n")))
5794 (insert "#+" keyword
" "))))
5796 (defun anything-c-org-keywords-show-help (keyword)
5797 (info (or (assoc-default (concat "#+" keyword
) anything-c-org-keywords-info-location
)
5798 "(org)In-buffer settings"))
5799 (search-forward (concat "#+" keyword
) nil t
)
5800 (anything-persistent-highlight-point)
5801 (message "%s" (or (cdr (assoc keyword
(anything-attr 'keywords-examples
))) "")))
5805 (defvar anything-c-source-picklist
5806 '((name .
"Picklist")
5807 (candidates .
(lambda () (mapcar 'car picklist-list
)))
5809 ;; (anything 'anything-c-source-picklist)
5812 (defvar bbdb-records
)
5813 (defvar bbdb-buffer-name
)
5814 (declare-function bbdb
"ext:bbdb-com")
5815 (declare-function bbdb-current-record
"ext:bbdb-com")
5816 (declare-function bbdb-redisplay-one-record
"ext:bbdb-com")
5817 (declare-function bbdb-record-net
"ext:bbdb-com" (string) t
)
5818 (declare-function bbdb-current-record
"ext:bbdb-com")
5819 (declare-function bbdb-dwim-net-address
"ext:bbdb-com")
5820 (declare-function bbdb-records
"ext:bbdb-com"
5821 (&optional dont-check-disk already-in-db-buffer
))
5823 (defun anything-c-bbdb-candidates ()
5824 "Return a list of all names in the bbdb database. The format
5825 is \"Firstname Lastname\"."
5826 (mapcar (lambda (bbdb-record)
5827 (replace-regexp-in-string
5829 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
5832 (defun anything-c-bbdb-create-contact (actions candidate
)
5833 "Action transformer that returns only an entry to add the
5834 current `anything-pattern' as new contact. All other actions are
5836 (if (string= candidate
"*Add to contacts*")
5837 '(("Add to contacts" .
(lambda (actions)
5838 (bbdb-create-internal
5839 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
5840 (read-from-minibuffer "Company: ")
5841 (read-from-minibuffer "Email: ")
5844 (read-from-minibuffer "Note: ")))))
5847 (defun anything-c-bbdb-get-record (candidate)
5848 "Return record that match CANDIDATE."
5849 (bbdb candidate nil
)
5850 (set-buffer "*BBDB*")
5851 (bbdb-current-record))
5853 (defvar anything-c-bbdb-name nil
5854 "Only for internal use.")
5856 (defvar anything-c-source-bbdb
5858 (candidates . anything-c-bbdb-candidates
)
5859 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
5860 ("View person's data" . anything-c-bbdb-view-person-action
))
5861 (filtered-candidate-transformer .
(lambda (candidates source
)
5862 (setq anything-c-bbdb-name anything-pattern
)
5863 (if (not candidates
)
5864 (list "*Add to contacts*")
5866 (action-transformer .
(lambda (actions candidate
)
5867 (anything-c-bbdb-create-contact actions candidate
))))
5870 http://bbdb.sourceforge.net/")
5871 ;; (anything 'anything-c-source-bbdb)
5873 (defun anything-c-bbdb-view-person-action (candidate)
5874 "View BBDB data of single CANDIDATE or marked candidates."
5875 (anything-aif (anything-marked-candidates)
5876 (let ((bbdb-append-records (length it
)))
5878 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
5879 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
5881 (defun anything-c-bbdb-collect-mail-addresses ()
5882 "Return a list of all mail addresses of records in bbdb buffer."
5883 (with-current-buffer bbdb-buffer-name
5884 (loop for i in bbdb-records
5885 if
(bbdb-record-net (car i
))
5886 collect
(bbdb-dwim-net-address (car i
)))))
5888 (defun anything-c-bbdb-compose-mail (candidate)
5889 "Compose a mail with all records of bbdb buffer."
5890 (anything-c-bbdb-view-person-action candidate
)
5891 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
5892 (address-str (mapconcat 'identity address-list
",\n ")))
5893 (compose-mail address-str
)))
5895 ;;; Evaluation Result
5896 (defvar anything-c-source-evaluation-result
5897 '((name .
"Evaluation Result")
5900 (filtered-candidate-transformer .
(lambda (candidates source
)
5903 (with-current-buffer anything-current-buffer
5905 (eval (read anything-pattern
))))
5907 (action ("Copy result to kill-ring" .
(lambda (candidate)
5908 (with-current-buffer anything-buffer
5909 (let ((end (save-excursion
5910 (goto-char (point-max))
5911 (search-backward "\n")
5913 (kill-region (point) end
))))))))
5914 ;; (anything 'anything-c-source-evaluation-result)
5917 (defun anything-eval-expression (arg)
5918 "Preconfigured anything for `anything-c-source-evaluation-result'."
5920 (anything 'anything-c-source-evaluation-result
(when arg
(thing-at-point 'sexp
))
5921 nil nil nil
"*anything eval*"))
5924 (defun anything-eval-expression-with-eldoc ()
5925 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
5928 (let ((timer (run-with-idle-timer eldoc-idle-delay
5929 'repeat
'anything-eldoc-show-in-eval
)))
5931 (call-interactively 'anything-eval-expression
)
5932 (cancel-timer timer
)))
5933 (call-interactively 'anything-eval-expression
)))
5935 (defun anything-eldoc-show-in-eval ()
5936 "Return eldoc in a tooltip for current minibuffer input."
5937 (let* ((str-all (minibuffer-completion-contents))
5941 (goto-char (point-max))
5942 (unless (looking-back ")\\|\"") (forward-char -
1))
5943 (eldoc-current-symbol))))
5944 (doc (or (eldoc-get-var-docstring sym
)
5945 (eldoc-get-fnsym-args-string
5946 (car (eldoc-fnsym-in-current-sexp))))))
5947 (when doc
(tooltip-show doc
))))
5949 ;;; Calculation Result
5950 (defvar anything-c-source-calculation-result
5951 '((name .
"Calculation Result")
5953 (filtered-candidate-transformer .
(lambda (candidates source
)
5956 (calc-eval anything-pattern
)
5958 (action ("Copy result to kill-ring" . kill-new
))))
5959 ;; (anything 'anything-c-source-calculation-result)
5961 ;;; Google Suggestions
5962 (defvar anything-gg-sug-lgh-flag
0)
5963 (defun anything-c-google-suggest-fetch (input)
5964 "Fetch suggestions for INPUT from XML buffer.
5965 Return an alist with elements like (data . number_results)."
5966 (let ((request (concat anything-c-google-suggest-url
5967 (url-hexify-string input
))))
5970 with result-alist
= (xml-get-children
5971 (car (xml-parse-region (point-min) (point-max)))
5972 'CompleteSuggestion
)
5973 for i in result-alist
5974 for data
= (cdr (caadr (assoc 'suggestion i
)))
5975 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
5976 for ldata
= (length data
)
5978 (when (> ldata anything-gg-sug-lgh-flag
)
5979 (setq anything-gg-sug-lgh-flag ldata
))
5980 collect
(cons data nqueries
) into cont
5981 finally return cont
)))
5982 (if anything-google-suggest-use-curl-p
5984 (call-process "curl" nil t nil request
)
5986 (with-current-buffer
5987 (url-retrieve-synchronously request
)
5991 (defun anything-c-google-suggest-set-candidates ()
5992 "Set candidates with result and number of google results found."
5993 (let ((suggestions (anything-c-google-suggest-fetch anything-input
)))
5994 (setq suggestions
(loop for i in suggestions
5995 for interval
= (- anything-gg-sug-lgh-flag
(length (car i
)))
5996 for elm
= (concat (car i
)
5997 (make-string (+ 2 interval
) ?
)
5998 "(" (cdr i
) " results)")
5999 collect
(cons elm
(car i
))))
6000 (if (some (lambda (data) (equal (cdr data
) anything-input
)) suggestions
)
6002 ;; if there is no suggestion exactly matching the input then
6003 ;; prepend a Search on Google item to the list
6006 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
6007 anything-input
))))))
6010 (defun anything-c-google-suggest-action (candidate)
6011 "Default action to jump to a google suggested candidate."
6012 (anything-c-browse-url (concat anything-c-google-suggest-search-url
6013 (url-hexify-string candidate
))))
6016 (defvar anything-c-source-google-suggest
6017 '((name .
"Google Suggest")
6018 (candidates . anything-c-google-suggest-set-candidates
)
6019 (action .
(("Google Search" . anything-c-google-suggest-action
)))
6021 (requires-pattern .
3)
6024 ;; (anything 'anything-c-source-google-suggest)
6026 ;;; Yahoo suggestions
6028 (defun anything-c-yahoo-suggest-fetch (input)
6029 "Fetch Yahoo suggestions for INPUT from XML buffer.
6030 Return an alist with elements like (data . number_results)."
6031 (let ((request (concat anything-c-yahoo-suggest-url
6032 (url-hexify-string input
))))
6035 with result-alist
= (xml-get-children
6036 (car (xml-parse-region (point-min) (point-max)))
6038 for i in result-alist
6039 collect
(caddr i
))))
6040 (with-current-buffer
6041 (url-retrieve-synchronously request
)
6044 (defun anything-c-yahoo-suggest-set-candidates ()
6045 "Set candidates with Yahoo results found."
6046 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
6050 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
6051 anything-input
))))))
6053 (defun anything-c-yahoo-suggest-action (candidate)
6054 "Default action to jump to a Yahoo suggested candidate."
6055 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
6056 (url-hexify-string candidate
))))
6058 (defvar anything-c-source-yahoo-suggest
6059 '((name .
"Yahoo Suggest")
6060 (candidates . anything-c-yahoo-suggest-set-candidates
)
6061 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
6063 (requires-pattern .
3)
6066 ;; (anything 'anything-c-source-yahoo-suggest)
6069 ;;; Need external program surfraw.
6070 ;;; http://surfraw.alioth.debian.org/
6072 (require 'browse-url
)
6073 (defvar w3m-command nil
)
6074 (defvar anything-c-home-url
"http://www.google.fr"
6075 "*Default url to use as home url.")
6077 (defvar browse-url-chromium-program
"chromium-bin")
6078 (defvar anything-browse-url-default-browser-alist
6079 `((,w3m-command . w3m-browse-url
)
6080 (,browse-url-firefox-program . browse-url-firefox
)
6081 (,browse-url-chromium-program . browse-url-chromium
)
6082 (,browse-url-kde-program . browse-url-kde
)
6083 (,browse-url-gnome-moz-program . browse-url-gnome-moz
)
6084 (,browse-url-mozilla-program . browse-url-mozilla
)
6085 (,browse-url-galeon-program . browse-url-galeon
)
6086 (,browse-url-netscape-program . browse-url-netscape
)
6087 (,browse-url-mosaic-program . browse-url-mosaic
)
6088 (,browse-url-xterm-program . browse-url-text-xterm
))
6089 "*Alist of (executable . function) to try to find a suitable url browser.")
6091 (defun* anything-c-generic-browser
(url name
&rest args
)
6092 (let ((proc (concat name
" " url
)))
6093 (message "Starting %s..." name
)
6094 (apply 'start-process proc nil name
6095 (append args
(list url
)))
6096 (set-process-sentinel
6098 #'(lambda (process event
)
6099 (when (string= event
"finished\n")
6100 (message "%s process %s" process event
))))))
6102 (defun browse-url-chromium (url)
6103 (interactive "sURL: ")
6104 (anything-c-generic-browser
6105 url browse-url-chromium-program
6106 "--enable-plugins"))
6108 (defun anything-browse-url-default-browser (url &rest args
)
6109 "Find a suitable browser and ask it to load URL."
6110 (let ((default-browser (loop
6111 for i in anything-browse-url-default-browser-alist
6112 thereis
(and (car i
) (executable-find (car i
))))))
6114 (apply default-browser url args
)
6115 (error "No usable browser found"))))
6117 (defun* anything-c-browse-url
(&optional
(url anything-c-home-url
))
6118 "Default command to browse URL."
6119 (if browse-url-browser-function
6120 (funcall browse-url-browser-function url
)
6121 (anything-browse-url-default-browser url
)))
6123 (defun anything-c-build-elvi-list ()
6124 "Return list of all engines and descriptions handled by surfraw."
6127 (call-process "surfraw" nil t nil
6129 (split-string (buffer-string) "\n"))))
6131 (defvar anything-surfraw-default-browser-function nil
6132 "*The browse url function you prefer to use with surfraw.
6133 When nil, fallback to `browse-url-browser-function'.")
6134 (defvar anything-surfraw-engines-history nil
)
6136 (defun anything-surfraw (pattern engine
)
6137 "Preconfigured `anything' to search PATTERN with search ENGINE."
6138 (interactive (list (read-string "SearchFor: ")
6141 (anything-c-build-elvi-list)
6143 :name
"Surfraw Search Engines"
6144 :history anything-surfraw-engines-history
)))
6145 (let* ((engine-nodesc (car (split-string engine
)))
6146 (url (with-temp-buffer
6147 (apply 'call-process
"surfraw" nil t nil
6148 (list engine-nodesc
"-p" pattern
))
6149 (replace-regexp-in-string
6150 "\n" "" (buffer-string))))
6151 (browse-url-browser-function (or anything-surfraw-default-browser-function
6152 browse-url-browser-function
)))
6153 (if (string= engine-nodesc
"W")
6154 (anything-c-browse-url)
6155 (anything-c-browse-url url
)
6156 (setq anything-surfraw-engines-history
6157 (cons engine
(delete engine anything-surfraw-engines-history
))))))
6161 (defun anything-emms-stream-edit-bookmark (elm)
6162 "Change the information of current emms-stream bookmark from anything."
6163 (let* ((cur-buf anything-current-buffer
)
6164 (bookmark (assoc elm emms-stream-list
))
6165 (name (read-from-minibuffer "Description: "
6167 (url (read-from-minibuffer "URL: "
6169 (fd (read-from-minibuffer "Feed Descriptor: "
6170 (int-to-string (nth 2 bookmark
))))
6171 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
6172 (format "%s" (car (last bookmark
))))))
6175 (when (re-search-forward (concat "^" name
) nil t
)
6177 (emms-stream-delete-bookmark)
6178 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
6179 (emms-stream-save-bookmarks-file)
6181 (switch-to-buffer cur-buf
)))))
6183 (defun anything-emms-stream-delete-bookmark (elm)
6184 "Delete an emms-stream bookmark from anything."
6185 (let* ((cur-buf anything-current-buffer
)
6186 (bookmark (assoc elm emms-stream-list
))
6187 (name (nth 0 bookmark
)))
6190 (when (re-search-forward (concat "^" name
) nil t
)
6192 (emms-stream-delete-bookmark)
6193 (emms-stream-save-bookmarks-file)
6195 (switch-to-buffer cur-buf
)))))
6197 (defvar anything-c-source-emms-streams
6198 '((name .
"Emms Streams")
6200 (emms-stream-init)))
6201 (candidates .
(lambda ()
6202 (mapcar 'car emms-stream-list
)))
6203 (action .
(("Play" .
(lambda (elm)
6204 (let* ((stream (assoc elm emms-stream-list
))
6205 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
6206 (url (second stream
)))
6208 ("Delete" . anything-emms-stream-delete-bookmark
)
6209 ("Edit" . anything-emms-stream-edit-bookmark
)))
6210 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
6211 ;; (anything 'anything-c-source-emms-streams)
6213 ;; Don't forget to set `emms-source-file-default-directory'
6214 (defvar anything-c-source-emms-dired
6215 '((name .
"Music Directory")
6216 (candidates .
(lambda ()
6217 (cddr (directory-files emms-source-file-default-directory
))))
6219 (("Play Directory" .
(lambda (item)
6220 (emms-play-directory
6223 emms-source-file-default-directory
))))
6224 ("Open dired in file's directory" .
(lambda (item)
6225 (anything-c-open-dired
6228 emms-source-file-default-directory
))))))
6229 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
6230 ;; (anything 'anything-c-source-emms-dired)
6232 (defface anything-emms-playlist
6233 '((t (:foreground
"Springgreen4" :underline t
)))
6234 "*Face used for tracks in current emms playlist."
6237 (defun anything-c-emms-files-modifier (candidates source
)
6238 (let ((current-playlist (with-current-emms-playlist
6240 with cur-list
= (emms-playlist-tracks-in-region
6241 (point-min) (point-max))
6243 collect
(assoc-default 'name i
)))))
6244 (loop for i in candidates
6245 if
(member (cdr i
) current-playlist
)
6246 collect
(cons (propertize (car i
)
6247 'face
'anything-emms-playlist
)
6249 else collect i into lis
6250 finally return lis
)))
6252 (defun anything-c-emms-play-current-playlist ()
6253 "Play current playlist."
6254 (with-current-emms-playlist
6255 (emms-playlist-first)
6256 (emms-playlist-mode-play-smart)))
6258 (defvar anything-c-source-emms-files
6259 '((name .
"Emms files")
6260 (candidates .
(lambda ()
6261 (loop for v being the hash-values in emms-cache-db
6262 for name
= (assoc-default 'name v
)
6263 for artist
= (or (assoc-default 'info-artist v
) "unknown")
6264 for genre
= (or (assoc-default 'info-genre v
) "unknown")
6265 for tracknum
= (or (assoc-default 'info-tracknumber v
) "unknown")
6266 for song
= (or (assoc-default 'info-title v
) "unknown")
6267 for info
= (concat artist
" - " genre
" - " tracknum
": " song
)
6268 unless
(string-match "^http:" name
) collect
(cons info name
))))
6269 (filtered-candidate-transformer . anything-c-emms-files-modifier
)
6270 (action .
(("Play file" . emms-play-file
)
6271 ("Add to Playlist and play (C-u clear current)"
6272 .
(lambda (candidate)
6273 (when anything-current-prefix-arg
6274 (emms-playlist-current-clear))
6276 (mapc 'emms-add-playlist-file
(anything-marked-candidates))
6277 (unless emms-player-playing-p
6278 (anything-c-emms-play-current-playlist))))))))
6280 ;; (anything 'anything-c-source-emms-files)
6282 ;;; Jabber Contacts (jabber.el)
6283 (defun anything-c-jabber-online-contacts ()
6284 "List online Jabber contacts."
6287 (dolist (item (jabber-concat-rosters) jids
)
6288 (when (get item
'connected
)
6289 (push (if (get item
'name
)
6290 (cons (get item
'name
) item
)
6291 (cons (symbol-name item
) item
)) jids
))))))
6293 (defvar anything-c-source-jabber-contacts
6294 '((name .
"Jabber Contacts")
6295 (init .
(lambda () (require 'jabber
)))
6296 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
6297 (action .
(lambda (x)
6299 (jabber-read-account)
6301 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
6302 ;; (anything 'anything-c-source-jabber-contacts)
6306 (defvar anything-source-select-buffer
"*anything source select*")
6307 (defvar anything-c-source-call-source
6308 `((name .
"Call anything source")
6309 (candidate-number-limit)
6310 (candidates .
(lambda ()
6311 (loop for vname in
(all-completions "anything-c-source-" obarray
)
6312 for var
= (intern vname
)
6313 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
6314 if name collect
(cons (format "%s `%s'"
6315 name
(propertize vname
'face
'font-lock-variable-name-face
))
6317 (action .
(("Invoke anything with selected source" .
6319 (setq anything-candidate-number-limit
9999)
6320 (anything candidate nil nil nil nil
6321 anything-source-select-buffer
)))
6322 ("Describe variable" . describe-variable
)
6323 ("Find variable" . find-variable
)))
6324 (persistent-action . describe-variable
)
6325 (persistent-help .
"Show description of this source")))
6326 ;; (anything 'anything-c-source-call-source)
6329 (defun anything-call-source ()
6330 "Preconfigured `anything' to call anything source."
6332 (anything 'anything-c-source-call-source nil nil nil nil
6333 anything-source-select-buffer
))
6335 (defun anything-call-source-from-anything ()
6336 "Call anything source within `anything' session."
6338 (setq anything-input-idle-delay
0)
6339 (anything-set-sources '(anything-c-source-call-source)))
6341 ;;; Execute Preconfigured anything.
6342 (defvar anything-c-source-anything-commands
6343 '((name .
"Preconfigured Anything")
6344 (candidates . anything-c-anything-commands-candidates
)
6346 (candidate-number-limit)))
6347 ;; (anything 'anything-c-source-anything-commands)
6349 (defun anything-c-anything-commands-candidates ()
6350 (loop for
(cmd . desc
) in
(anything-c-list-preconfigured-anything)
6351 collect
(cons (if (where-is-internal cmd nil t
)
6352 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc
))
6353 (substitute-command-keys (format "\\[%s] : %s" cmd desc
)))
6357 (defun anything-execute-anything-command ()
6358 "Preconfigured `anything' to execute preconfigured `anything'."
6360 (anything-other-buffer 'anything-c-source-anything-commands
6361 "*anything commands*"))
6364 (defun anything-c-occur-init ()
6365 (anything-candidate-buffer anything-current-buffer
))
6367 (defun anything-c-occur-get-line (s e
)
6368 (format "%7d:%s" (line-number-at-pos (1- s
)) (buffer-substring s e
)))
6370 (defvar anything-c-source-occur
6372 (init . anything-c-occur-init
)
6373 (candidates-in-buffer)
6375 (get-line . anything-c-occur-get-line
)
6378 (requires-pattern .
1)
6381 ;; (anything 'anything-c-source-occur)
6383 ;;; Anything browse code.
6384 (defun anything-c-browse-code-get-line (beg end
)
6385 "Select line if it match the regexp corresponding to current `major-mode'.
6386 Line is parsed for BEG position to END position."
6387 (let ((str-line (buffer-substring beg end
))
6388 (regexp (assoc-default major-mode
6389 anything-c-browse-code-regexp-alist
))
6390 (num-line (if (string= anything-pattern
"") beg
(1- beg
))))
6391 (when (and regexp
(string-match regexp str-line
))
6392 (format "%4d:%s" (line-number-at-pos num-line
) str-line
))))
6395 (defvar anything-c-source-browse-code
6396 '((name .
"Browse code")
6398 (anything-candidate-buffer anything-current-buffer
)
6399 (with-current-buffer anything-current-buffer
6400 (jit-lock-fontify-now))))
6401 (candidate-number-limit .
9999)
6402 (candidates-in-buffer)
6403 (get-line . anything-c-browse-code-get-line
)
6407 ;; Do many actions for input
6408 (defvar anything-c-source-create
6412 (action-transformer . anything-create--actions
))
6413 "Do many create actions from `anything-pattern'.
6414 See also `anything-create--actions'.")
6415 ;; (anything 'anything-c-source-create)
6417 (defun anything-create-from-anything ()
6418 "Run `anything-create' from `anything' as a fallback."
6420 (anything-run-after-quit 'anything-create nil anything-pattern
))
6423 (defun anything-create (&optional string initial-input
)
6424 "Preconfigured `anything' to do many create actions from STRING.
6425 See also `anything-create--actions'."
6427 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
6428 (anything '(((name .
"Anything Create")
6429 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
6430 (candidates . anything-create--actions
)
6431 (candidate-number-limit)
6432 (action .
(lambda (func) (funcall func string
)))))))
6434 (defun anything-create--actions (&rest ignored
)
6435 "Default actions for `anything-create' / `anything-c-source-create'."
6437 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
6438 (append anything-create--actions-private
6439 '(("find-file" . find-file
)
6440 ("find-file other window" . find-file-other-window
)
6441 ("New buffer" . switch-to-buffer
)
6442 ("New buffer other window" . switch-to-buffer-other-window
)
6443 ("Bookmark Set" . bookmark-set
)
6445 (lambda (x) (set-register (read-char "Register: ") x
)))
6446 ("Insert Linkd star" . linkd-insert-star
)
6447 ("Insert Linkd Tag" . linkd-insert-tag
)
6448 ("Insert Linkd Link" . linkd-insert-link
)
6449 ("Insert Linkd Lisp" . linkd-insert-lisp
)
6450 ("Insert Linkd Wiki" . linkd-insert-wiki
)
6451 ("Google Search" . google
)))))
6453 ;; Minibuffer History
6454 (defvar anything-c-source-minibuffer-history
6455 '((name .
"Minibuffer History")
6456 (header-name .
(lambda (name) (format "%s (%s)" name minibuffer-history-variable
)))
6457 (candidates .
(lambda () (let ((history (symbol-value minibuffer-history-variable
)))
6458 (if (consp (car history
))
6459 (mapcar 'prin1-to-string history
)
6463 ;; (anything 'anything-c-source-minibuffer-history)
6466 (defvar anything-c-source-elscreen
6467 '((name .
"Elscreen")
6468 (candidates .
(lambda ()
6469 (if (cdr (elscreen-get-screen-to-name-alist))
6471 (loop for sname in
(elscreen-get-screen-to-name-alist)
6472 append
(list (format "[%d] %s" (car sname
) (cdr sname
))) into lst
6473 finally
(return lst
))
6474 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
6475 (action .
(("Change Screen".
6477 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
6480 (dolist (i (anything-marked-candidates))
6481 (elscreen-goto (- (aref i
1) (aref "0" 0)))
6485 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
6486 (elscreen-kill-others)))))))
6487 ;; (anything 'anything-c-source-elscreen)
6492 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
6493 "Top command (batch mode). %s is replaced with `frame-width'.")
6494 (defvar anything-c-source-top
6495 '((name .
"Top (Press C-c C-u to refresh)")
6496 (init . anything-c-top-init
)
6497 (candidates-in-buffer)
6498 (display-to-real . anything-c-top-display-to-real
)
6499 (update . anything-c-top-update
)
6500 (persistent-action . anything-c-top-sh-persistent-action
)
6501 (persistent-help .
"SIGTERM")
6503 ("kill (TERM)" .
(lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid
))))
6504 ("kill (KILL)" .
(lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid
))))
6505 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
6506 ;; (anything 'anything-c-source-top)
6508 (defun anything-c-top-sh (cmd)
6509 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
6511 (defun anything-c-top-sh-persistent-action (pid)
6512 (delete-other-windows)
6513 (anything-c-top-sh (format "kill -TERM %s" pid
))
6514 (anything-force-update))
6516 (defun anything-c-top-init ()
6517 (with-current-buffer (anything-candidate-buffer 'global
)
6518 (call-process-shell-command
6519 (format anything-c-top-command
6520 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
6521 nil
(current-buffer))))
6523 (defun anything-c-top-display-to-real (line)
6524 (car (split-string line
)))
6526 (defun anything-c-top-update ()
6527 (let ((anything-source-name (assoc-default 'name anything-c-source-top
))) ;UGLY HACK
6528 (anything-c-top-init)))
6531 (defun anything-top ()
6532 "Preconfigured `anything' for top command."
6534 (let ((anything-samewindow t
)
6535 (anything-enable-shortcuts)
6536 (anything-display-function 'anything-default-display-buffer
)
6537 (anything-candidate-number-limit 9999))
6538 (save-window-excursion
6539 (delete-other-windows)
6540 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
6543 (defvar anything-c-source-absolute-time-timers
6544 '((name .
"Absolute Time Timers")
6545 (candidates . timer-list
)
6547 ;; (anything 'anything-c-source-absolute-time-timers)
6549 (defvar anything-c-source-idle-time-timers
6550 '((name .
"Idle Time Timers")
6551 (candidates . timer-idle-list
)
6553 ;; (anything 'anything-c-source-idle-time-timers)
6555 (defun anything-c-timer-real-to-display (timer)
6556 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay
)
6557 (append timer nil
) ;use `append' to convert vector->list
6558 (format "%s repeat=%5S %s(%s)"
6559 (let ((time (list t1 t2 t3
)))
6561 (format-time-string "idle-for=%5s" time
)
6562 (format-time-string "%m/%d %T" time
)))
6565 (mapconcat 'prin1-to-string args
" "))))
6567 ;;; X RandR resolution change
6568 ;;; FIXME I do not care multi-display.
6569 (defvar anything-c-xrandr-output
"VGA")
6570 (defvar anything-c-xrandr-screen
"0")
6571 (defvar anything-c-source-xrandr-change-resolution
6572 '((name .
"Change Resolution")
6576 (call-process "xrandr" nil
(current-buffer) nil
6577 "--screen" anything-c-xrandr-screen
"-q")
6579 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
6580 collect
(match-string 1)))))
6582 ("Change Resolution" .
(lambda (mode)
6583 (call-process "xrandr" nil nil nil
6584 "--screen" anything-c-xrandr-screen
6585 "--output" anything-c-xrandr-output
6587 ;; (anything 'anything-c-source-xrandr-change-resolution)
6590 (defun anything-c-persistent-xfont-action (elm)
6591 "Show current font temporarily"
6592 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
6595 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
6596 (set-frame-font current-font
))))
6598 (defvar anything-c-xfonts-cache nil
)
6599 (defvar anything-c-source-xfonts
6600 '((name .
"X Fonts")
6602 (unless anything-c-xfonts-cache
6603 (setq anything-c-xfonts-cache
6604 (x-list-fonts "*")))))
6605 (candidates . anything-c-xfonts-cache
)
6606 (action .
(("Copy to kill ring" .
(lambda (elm)
6608 ("Set Font" .
(lambda (elm)
6610 (set-frame-font elm
'keep-size
)
6611 (message "New font have been copied to kill ring")))))
6612 (persistent-action . anything-c-persistent-xfont-action
)
6613 (persistent-help .
"Switch to this font temporarily")))
6616 (defun anything-select-xfont ()
6617 "Preconfigured `anything' to select Xfont."
6619 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
6621 ;; (anything 'anything-c-source-xfonts)
6625 (defvar anything-c-source-time-world
6626 '((name .
"Time World List")
6628 (let ((anything-buffer (anything-candidate-buffer 'global
)))
6629 (with-current-buffer anything-buffer
6630 (display-time-world-display display-time-world-list
)))))
6631 (candidates-in-buffer)))
6634 (defun anything-world-time ()
6635 "Preconfigured `anything' to show world time."
6637 (anything-other-buffer 'anything-c-source-time-world
"*anything world time*"))
6639 ;;; Source for Debian/Ubuntu users
6640 (defvar anything-c-source-apt
6642 (init . anything-c-apt-init
)
6643 (candidates-in-buffer)
6644 (candidate-transformer anything-c-apt-candidate-transformer
)
6645 (display-to-real . anything-c-apt-display-to-real
)
6646 (candidate-number-limit .
9999)
6648 ("Show package description" . anything-c-apt-cache-show
)
6649 ("Install package" . anything-c-apt-install
)
6650 ("Remove package" . anything-c-apt-uninstall
)
6651 ("Purge package" . anything-c-apt-purge
))
6652 (persistent-action . anything-c-apt-persistent-action
)
6653 (persistent-help .
"Show - C-u Refresh")))
6654 ;; (anything 'anything-c-source-apt)
6656 (defvar anything-c-apt-query
"emacs")
6657 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
6658 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
6659 (defvar anything-c-apt-installed-packages nil
)
6661 (defface anything-apt-installed
6662 '((t (:foreground
"green")))
6663 "*Face used for apt installed candidates."
6666 (defun anything-c-apt-refresh ()
6667 "Refresh installed candidates list."
6668 (setq anything-c-apt-installed-packages nil
)
6669 (anything-force-update))
6671 (defun anything-c-apt-persistent-action (candidate)
6672 "Persistent action for APT source."
6673 (if current-prefix-arg
6674 (anything-c-apt-refresh)
6675 (anything-c-apt-cache-show candidate
)))
6678 (defun anything-apt (query)
6679 "Preconfigured `anything' : frontend of APT package manager."
6680 (interactive "sAPT search: ")
6681 (let ((anything-c-apt-query query
))
6682 (anything 'anything-c-source-apt
)))
6684 (defun anything-c-apt-candidate-transformer (candidates)
6685 "Show installed candidates in a different color."
6688 for cand in candidates
6689 for name
= (anything-c-apt-display-to-real cand
)
6690 if
(member name anything-c-apt-installed-packages
)
6691 collect
(propertize cand
'face
'anything-apt-installed
) into all
6692 else collect cand into all finally return all
))
6694 (defun anything-c-apt-init ()
6695 "Initialize list of debian packages."
6696 (unless anything-c-apt-installed-packages
6697 (message "Updating installed candidate list...")
6698 (setq anything-c-apt-installed-packages
6700 (call-process-shell-command "dpkg --get-selections"
6701 nil
(current-buffer))
6702 (loop for i in
(split-string (buffer-string) "\n" t
)
6703 collect
(car (split-string i
))))))
6704 (with-current-buffer
6705 (anything-candidate-buffer
6706 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query
)))
6708 (call-process-shell-command
6709 (format anything-c-apt-search-command anything-c-apt-query
)
6710 nil
(current-buffer)))
6711 (message "Updating installed candidate list...done"))
6713 (defun anything-c-apt-display-to-real (line)
6714 "Return only name of a debian package.
6715 LINE is displayed like:
6716 package name - description."
6717 (car (split-string line
" - ")))
6720 (defun anything-c-shell-command-if-needed (command)
6721 (interactive "sShell command: ")
6722 (if (get-buffer command
) ; if the buffer already exists
6723 (switch-to-buffer command
) ; then just switch to it
6724 (switch-to-buffer command
) ; otherwise create it
6725 (insert (shell-command-to-string command
))))
6727 (defun anything-c-apt-cache-show (package)
6728 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package
)))
6730 (defun anything-c-apt-install (package)
6731 (anything-c-apt-install1 package
:action
'install
))
6733 (defun anything-c-apt-uninstall (package)
6734 (anything-c-apt-install1 package
:action
'uninstall
))
6736 (defun anything-c-apt-purge (package)
6737 (anything-c-apt-install1 package
:action
'purge
))
6739 (defun* anything-c-apt-install1
(candidate &key action
)
6740 (ansi-term (getenv "SHELL") "anything apt")
6742 (let ((command (case action
6743 ('install
"sudo apt-get install '%s'")
6744 ('uninstall
"sudo apt-get remove '%s'")
6745 ('purge
"sudo apt-get purge '%s'")
6746 (t (error "Unknow action"))))
6748 (goto-char (point-max))
6749 (insert (format command candidate
))
6751 (if (y-or-n-p (format "%s package" (symbol-name action
)))
6753 (setq anything-c-external-commands-list nil
)
6754 (setq anything-c-apt-installed-packages nil
)
6755 (term-char-mode) (term-send-input))
6756 (delete-region beg end
) (term-send-eof) (kill-buffer))))
6758 ;; (anything-c-apt-install "jed")
6760 ;;; Sources for gentoo users
6761 (defvar anything-c-gentoo-use-flags nil
)
6762 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
6763 (defvar anything-c-cache-gentoo nil
)
6764 (defvar anything-c-cache-world nil
)
6765 (defvar anything-c-source-gentoo
6766 '((name .
"Portage sources")
6768 (get-buffer-create anything-c-gentoo-buffer
)
6769 (unless anything-c-cache-gentoo
6770 (anything-c-gentoo-setup-cache))
6771 (unless anything-c-cache-world
6772 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
6773 (anything-c-gentoo-init-list)))
6774 (candidates-in-buffer)
6776 (candidate-transformer anything-c-highlight-world
)
6777 (action .
(("Show package" .
(lambda (elm)
6778 (anything-c-gentoo-eshell-action elm
"eix")))
6779 ("Show history" .
(lambda (elm)
6780 (if (member elm anything-c-cache-world
)
6781 (anything-c-gentoo-eshell-action elm
"genlop -qe")
6782 (message "No infos on packages not yet installed"))))
6783 ("Copy in kill-ring" . kill-new
)
6784 ("insert at point" . insert
)
6785 ("Browse HomePage" .
(lambda (elm)
6786 (let ((urls (anything-c-gentoo-get-url elm
)))
6787 (browse-url (anything-comp-read "Url: " urls
:must-match t
)))))
6788 ("Show extra infos" .
(lambda (elm)
6789 (if (member elm anything-c-cache-world
)
6790 (anything-c-gentoo-eshell-action elm
"genlop -qi")
6791 (message "No infos on packages not yet installed"))))
6792 ("Show use flags" .
(lambda (elm)
6793 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
6794 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
6795 (font-lock-mode 1)))
6796 ("Run emerge pretend" .
(lambda (elm)
6797 (anything-c-gentoo-eshell-action elm
"emerge -p")))
6798 ("Emerge" .
(lambda (elm)
6799 (anything-gentoo-install elm
:action
'install
)))
6800 ("Unmerge" .
(lambda (elm)
6801 (anything-gentoo-install elm
:action
'uninstall
)))
6802 ("Show dependencies" .
(lambda (elm)
6803 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
6804 ("Show related files" .
(lambda (elm)
6805 (anything-c-gentoo-default-action elm
"equery" "files")))
6806 ("Refresh" .
(lambda (elm)
6807 (anything-c-gentoo-setup-cache)
6808 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
6810 ;; (anything 'anything-c-source-gentoo)
6812 (defun* anything-gentoo-install
(candidate &key action
)
6813 (setq anything-c-external-commands-list nil
)
6814 (ansi-term (getenv "SHELL") "Gentoo emerge")
6816 (let ((command (case action
6817 ('install
"sudo emerge -av ")
6818 ('uninstall
"sudo emerge -avC ")
6819 (t (error "Unknow action"))))
6820 (elms (mapconcat 'identity
(anything-marked-candidates) " "))
6822 (goto-char (point-max))
6823 (insert (concat command elms
))
6825 (term-char-mode) (term-send-input)))
6827 (defun anything-c-gentoo-default-action (elm command
&rest args
)
6828 "Gentoo default action that use `anything-c-gentoo-buffer'."
6829 (if (member elm anything-c-cache-world
)
6831 (switch-to-buffer anything-c-gentoo-buffer
)
6833 (let ((com-list (append args
(list elm
))))
6834 (apply #'call-process command nil t nil
6836 (message "No infos on packages not yet installed")))
6838 (defvar anything-c-source-use-flags
6839 '((name .
"Use Flags")
6841 (unless anything-c-gentoo-use-flags
6842 (anything-c-gentoo-setup-use-flags-cache))
6843 (anything-c-gentoo-get-use)))
6844 (candidates-in-buffer)
6846 (candidate-transformer anything-c-highlight-local-use
)
6847 (action .
(("Description"
6849 (switch-to-buffer anything-c-gentoo-buffer
)
6851 (apply #'call-process
"euse" nil t nil
6854 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
6855 (font-lock-mode 1)))
6858 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -E")))
6861 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -D")))
6864 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -P")))
6865 ("Show which dep use this flag"
6867 (switch-to-buffer anything-c-gentoo-buffer
)
6869 (apply #'call-process
"equery" nil t nil
6875 ;; (anything 'anything-c-source-use-flags)
6877 (defun anything-c-gentoo-init-list ()
6878 "Initialize buffer with all packages in Portage."
6879 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
6880 (buf (anything-candidate-buffer 'portage-buf
)))
6881 (with-current-buffer buf
6882 (dolist (i anything-c-cache-gentoo
)
6883 (insert (concat i
"\n"))))))
6885 (defun anything-c-gentoo-setup-cache ()
6886 "Set up `anything-c-cache-gentoo'"
6887 (setq anything-c-cache-gentoo
6888 (split-string (with-temp-buffer
6889 (call-process "eix" nil t nil
6893 (defun anything-c-gentoo-eshell-action (elm command
)
6894 (when (get-buffer "*EShell Command Output*")
6895 (kill-buffer "*EShell Command Output*"))
6896 (message "Wait searching...")
6897 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
6898 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
6900 (save-window-excursion
6901 (pop-to-buffer "*scratch*")
6902 (eshell-command (format "%s %s" command elm
)))
6903 (pop-to-buffer "*EShell Command Output*"))
6904 (eshell-command (format "%s %s" command elm
)))))
6906 (defun anything-c-gentoo-get-use ()
6907 "Initialize buffer with all use flags."
6908 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
6909 (buf (anything-candidate-buffer 'use-buf
)))
6910 (with-current-buffer buf
6911 (dolist (i anything-c-gentoo-use-flags
)
6912 (insert (concat i
"\n"))))))
6915 (defun anything-c-gentoo-setup-use-flags-cache ()
6916 "Setup `anything-c-gentoo-use-flags'"
6917 (setq anything-c-gentoo-use-flags
6918 (split-string (with-temp-buffer
6919 (call-process "eix" nil t nil
6920 "--print-all-useflags")
6923 (defun anything-c-gentoo-get-url (elm)
6924 "Return a list of urls from eix output."
6926 with url-list
= (split-string
6928 (call-process "eix" nil t nil
6929 elm
"--format" "<homepage>\n")
6933 when
(and (string-match "^http://.*" i
)
6934 (not (member i all
)))
6936 finally return all
))
6938 (defun anything-c-gentoo-get-world ()
6939 "Return list of all installed package on your system."
6940 (split-string (with-temp-buffer
6941 (call-process "qlist" nil t nil
6945 (defun anything-c-gentoo-get-local-use ()
6946 (split-string (with-temp-buffer
6947 (call-process "portageq" nil t nil
6952 (defface anything-gentoo-match-face
'((t (:foreground
"red")))
6953 "Face for anything-gentoo installed packages."
6954 :group
'traverse-faces
)
6956 (defun anything-c-highlight-world (eix)
6957 "Highlight all installed package."
6959 if
(member i anything-c-cache-world
)
6960 collect
(propertize i
'face
'anything-gentoo-match-face
)
6964 (defun anything-c-highlight-local-use (use-flags)
6965 (let ((local-uses (anything-c-gentoo-get-local-use)))
6966 (loop for i in use-flags
6967 if
(member i local-uses
)
6968 collect
(propertize i
'face
'anything-gentoo-match-face
)
6972 (defvar anything-c-source-emacs-process
6973 '((name .
"Emacs Process")
6974 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
6975 (persistent-action .
(lambda (elm)
6976 (delete-process (get-process elm
))
6977 (anything-delete-current-selection)))
6978 (persistent-help .
"Kill Process")
6979 (action ("Kill Process" .
(lambda (elm)
6980 (delete-process (get-process elm
)))))))
6982 ;; (anything 'anything-c-source-emacs-process)
6984 ;; Run Externals commands within Emacs
6985 (defmacro* anything-comp-hash-get-items
(hash-table &key test
)
6986 "Get the list of all keys/values of hash-table."
6987 `(let ((li-items ()))
6988 (maphash #'(lambda (x y
)
6990 (when (funcall ,test y
)
6991 (push (list x y
) li-items
))
6992 (push (list x y
) li-items
)))
6996 (defun anything-comp-read-get-candidates (collection &optional test sort-fn
)
6997 "Convert COLLECTION to list removing elements that don't match TEST.
6998 SORT-FN is a predicate to sort COLLECTION.
6999 If collection is an `obarray', a TEST is needed. See `obarray'."
7001 (cond ((and (listp collection
) test
)
7002 (loop for i in collection when
(funcall test i
) collect i
))
7003 ((and (eq collection obarray
) test
)
7004 (loop for s being the symbols of collection
7005 when
(funcall test s
) collect s
))
7006 ((and (vectorp collection
) test
)
7007 (loop for i across collection when
(funcall test i
) collect i
))
7008 ((vectorp collection
)
7009 (loop for i across collection collect i
))
7010 ((and (hash-table-p collection
) test
)
7011 (anything-comp-hash-get-items collection
:test test
))
7012 ((hash-table-p collection
)
7013 (anything-comp-hash-get-items collection
))
7015 (if sort-fn
(sort cands sort-fn
) cands
)))
7017 (defun anything-cr-default-transformer (candidates source
)
7018 "Default filter candidate function for `anything-comp-read'.
7019 Do nothing, just return candidate list unmodified."
7022 (defun* anything-comp-read
(prompt collection
7026 (buffer "*Anything Completions*")
7028 (requires-pattern 0)
7030 (persistent-action nil
)
7031 (persistent-help "DoNothing")
7032 (name "Anything Completions")
7034 (fc-transformer 'anything-cr-default-transformer
)
7035 (marked-candidates nil
))
7036 "Anything `completing-read' emulation.
7037 PROMPT is the prompt name to use.
7038 COLLECTION can be a list, vector, obarray or hash-table.
7041 TEST: A predicate called with one arg i.e candidate.
7042 INITIAL-INPUT: Same as initial-input arg in `anything'.
7043 BUFFER: Name of anything-buffer.
7044 MUST-MATCH: Candidate selected must be one of COLLECTION.
7045 REQUIRES-PATTERN: Same as anything attribute, default is 0.
7046 HISTORY: A list containing specific history, default is nil.
7047 When it is non--nil, all elements of HISTORY are displayed in
7048 anything-buffer before COLLECTION.
7049 PERSISTENT-ACTION: A function called with one arg i.e candidate.
7050 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
7051 NAME: The name related to this local source.
7052 SORT: A predicate to give to `sort' e.g `string-lessp'.
7053 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
7054 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
7056 Any prefix args passed during `anything-comp-read' invocation will be recorded
7057 in `anything-current-prefix-arg', otherwise if prefix args where given before
7058 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
7059 That's mean you can pass prefix arg before or after calling
7060 a command that use `anything-comp-read'."
7061 (when (get-buffer anything-action-buffer
)
7062 (kill-buffer anything-action-buffer
))
7063 (flet ((action-fn (candidate)
7064 (if marked-candidates
7065 (anything-marked-candidates)
7066 (identity candidate
))))
7069 `(((name .
,(format "%s History" name
))
7070 (candidates .
(lambda ()
7071 (anything-comp-read-get-candidates history
)))
7073 (persistent-action .
,persistent-action
)
7074 (persistent-help .
,persistent-help
)
7075 (action .
,'action-fn
))
7079 (let ((cands (anything-comp-read-get-candidates
7080 collection test sort
)))
7081 (if (or must-match
(string= anything-pattern
""))
7082 cands
(append (list anything-pattern
) cands
)))))
7083 (filtered-candidate-transformer ,fc-transformer
)
7084 (requires-pattern .
,requires-pattern
)
7085 (persistent-action .
,persistent-action
)
7086 (persistent-help .
,persistent-help
)
7088 (action .
,'action-fn
)))
7089 :input initial-input
7095 (defun anything-c-get-pid-from-process-name (process-name)
7096 "Get pid from running process PROCESS-NAME."
7097 (loop with process-list
= (list-system-processes)
7098 for pid in process-list
7099 for process
= (assoc-default 'comm
(process-attributes pid
))
7100 when
(and process
(string-match process-name process
))
7104 (defun anything-run-or-raise (exe &optional file
)
7105 "Generic command that run asynchronously EXE.
7106 If EXE is already running just jump to his window if `anything-raise-command'
7108 When FILE argument is provided run EXE with FILE.
7109 In this case EXE must be provided as \"EXE %s\"."
7110 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string "'%s'" "" exe
))))
7111 (proc (if file
(concat real-com
" " file
) real-com
)))
7112 (if (get-process proc
)
7113 (if anything-raise-command
7114 (shell-command (format anything-raise-command real-com
))
7115 (error "Error: %s is already running" real-com
))
7116 (when (member real-com anything-c-external-commands-list
)
7117 (message "Starting %s..." real-com
)
7119 (start-process-shell-command proc nil
(format exe file
))
7120 (start-process-shell-command proc nil real-com
))
7121 (set-process-sentinel
7123 #'(lambda (process event
)
7124 (when (and (string= event
"finished\n")
7125 anything-raise-command
7126 (not (anything-c-get-pid-from-process-name real-com
)))
7127 (shell-command (format anything-raise-command
"emacs")))
7128 (message "%s process...Finished." process
))))
7129 (setq anything-c-external-commands-list
7130 (cons real-com
(delete real-com anything-c-external-commands-list
))))))
7133 (defvar anything-external-command-history nil
)
7135 (defun anything-c-run-external-command (program)
7136 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
7137 If program is already running exit with error.
7138 You can set your own list of commands with
7139 `anything-c-external-commands-list'."
7143 (anything-c-external-commands-list-1 'sort
)
7145 :name
"External Commands"
7146 :history anything-external-command-history
)))
7147 (anything-run-or-raise program
)
7148 (setq anything-external-command-history
7149 (cons program
(delete program
7150 (loop for i in anything-external-command-history
7151 when
(executable-find i
) collect i
)))))
7153 (defsubst* anything-c-position
(item seq
&key
(test 'eq
))
7154 "A simple and faster replacement of CL `position'."
7155 (loop for i in seq for index from
0
7156 when
(funcall test i item
) return index
))
7158 (defvar anything-c-source-ratpoison-commands
7159 '((name .
"Ratpoison Commands")
7160 (init . anything-c-ratpoison-commands-init
)
7161 (candidates-in-buffer)
7162 (action ("Execute the command" . anything-c-ratpoison-commands-execute
))
7163 (display-to-real . anything-c-ratpoison-commands-display-to-real
)
7164 (candidate-number-limit)))
7165 ;; (anything 'anything-c-source-ratpoison-commands)
7167 (defun anything-c-ratpoison-commands-init ()
7168 (unless (anything-candidate-buffer)
7169 (with-current-buffer (anything-candidate-buffer 'global
)
7170 ;; with ratpoison prefix key
7172 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help"))
7173 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
7174 (replace-match "<ratpoison> \\1: \\2"))
7175 (goto-char (point-max))
7178 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help top"))
7179 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
7180 (replace-match "\\1: \\2")))))
7182 (defun anything-c-ratpoison-commands-display-to-real (display)
7183 (and (string-match ": " display
)
7184 (substring display
(match-end 0))))
7186 (defun anything-c-ratpoison-commands-execute (candidate)
7187 (call-process "ratpoison" nil nil nil
"-ic" candidate
))
7190 (defun anything-ratpoison-commands ()
7191 "Preconfigured `anything' to execute ratpoison commands."
7193 (anything-other-buffer 'anything-c-source-ratpoison-commands
7194 "*anything ratpoison commands*"))
7196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7198 (defvar anything-c-external-commands-list nil
7199 "A list of all external commands the user can execute. If this
7200 variable is not set by the user, it will be calculated
7203 (defun anything-c-external-commands-list-1 (&optional sort
)
7204 "Returns a list of all external commands the user can execute.
7205 If `anything-c-external-commands-list' is non-nil it will
7206 return its contents. Else it calculates all external commands
7207 and sets `anything-c-external-commands-list'."
7208 (if anything-c-external-commands-list
7209 anything-c-external-commands-list
7210 (setq anything-c-external-commands-list
7212 with paths
= (split-string (getenv "PATH") path-separator
)
7213 with completions
= ()
7215 when
(and (file-exists-p dir
) (file-accessible-directory-p dir
))
7216 for lsdir
= (loop for i in
(directory-files dir t
)
7217 for bn
= (file-name-nondirectory i
)
7218 when
(and (not (member bn completions
))
7219 (not (file-directory-p i
))
7220 (file-executable-p i
))
7222 append lsdir into completions
7223 finally return
(if sort
(sort completions
'string-lessp
) completions
)))))
7226 (defun anything-c-file-buffers (filename)
7227 "Returns a list of buffer names corresponding to FILENAME."
7228 (let ((name (expand-file-name filename
))
7230 (dolist (buf (buffer-list) buf-list
)
7231 (let ((bfn (buffer-file-name buf
)))
7232 (when (and bfn
(string= name bfn
))
7233 (push (buffer-name buf
) buf-list
))))))
7235 (defun anything-c-delete-file (file)
7236 "Delete the given file after querying the user.
7237 Ask to kill buffers associated with that file, too."
7238 (let ((buffers (anything-c-file-buffers file
)))
7239 (dired-delete-file file
'dired-recursive-deletes
)
7241 (dolist (buf buffers
)
7242 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
7243 (kill-buffer buf
))))))
7245 (defun anything-get-mailcap-for-file (filename)
7246 "Get the command to use for FILENAME from mailcap files.
7247 The command is like <command %s> and is meant to use with `format'."
7248 (mailcap-parse-mailcaps)
7249 (let* ((ext (file-name-extension filename
))
7250 (mime (when ext
(mailcap-extension-to-mime ext
))))
7251 (when mime
(mailcap-mime-info mime
))))
7253 (defun anything-get-default-program-for-file (filename)
7254 "Try to find a default program to open FILENAME.
7255 Try first in `anything-c-external-programs-associations' and then in mailcap file
7256 if nothing found return nil."
7257 (let* ((ext (file-name-extension filename
))
7258 (def-prog (assoc-default ext anything-c-external-programs-associations
)))
7259 (if (and def-prog
(not (string= def-prog
"")))
7260 (concat def-prog
" %s")
7261 (anything-get-mailcap-for-file filename
))))
7263 (defun anything-c-open-file-externally (file)
7264 "Open FILE with an external program.
7265 Try to guess which program to use with `anything-get-default-program-for-file'.
7266 If not found or a prefix arg is given query the user which tool to use."
7267 (let* ((fname (expand-file-name file
))
7268 (collection (anything-c-external-commands-list-1 'sort
))
7269 (def-prog (anything-get-default-program-for-file fname
))
7271 ;; No prefix arg, default program exists.
7272 (unless (or anything-current-prefix-arg
(not def-prog
))
7273 (replace-regexp-in-string " %s\\| '%s'" "" def-prog
))
7274 ;; Prefix arg or no default program.
7276 "Program: " collection
7278 :name
"Open file Externally"
7279 :history anything-external-command-history
)))
7280 (program (concat real-prog-name
" '%s'")))
7281 (unless (or def-prog
; Association exists, no need to record it.
7282 (not (file-exists-p fname
))) ; Don't record non--filenames.
7286 "Do you want to make %s the default program for this kind of files? "
7288 (push (cons (file-name-extension fname
)
7290 "Program(Add args maybe and confirm): " real-prog-name
))
7291 anything-c-external-programs-associations
)
7292 (customize-save-variable 'anything-c-external-programs-associations
7293 anything-c-external-programs-associations
)))
7294 (anything-run-or-raise program file
)
7295 (setq anything-external-command-history
7296 (cons real-prog-name
7297 (delete real-prog-name
7298 (loop for i in anything-external-command-history
7299 when
(executable-find i
) collect i
))))))
7303 (defun w32-shell-execute-open-file (file)
7304 (interactive "fOpen file:")
7306 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
7308 (replace-regexp-in-string ; strip cygdrive paths
7309 "/cygdrive/\\(.\\)" "\\1:"
7310 file nil nil
) nil t
))))
7312 (defun anything-c-open-file-with-default-tool (file)
7313 "Open FILE with the default tool on this platform."
7314 (if (eq system-type
'windows-nt
)
7315 (w32-shell-execute-open-file file
)
7316 (start-process "anything-c-open-file-with-default-tool"
7318 (cond ((eq system-type
'gnu
/linux
)
7320 ((or (eq system-type
'darwin
) ;; Mac OS X
7321 (eq system-type
'macos
)) ;; Mac OS 9
7325 (defun anything-c-open-dired (file)
7326 "Opens a dired buffer in FILE's directory. If FILE is a
7327 directory, open this directory."
7328 (if (file-directory-p file
)
7330 (dired (file-name-directory file
))
7331 (dired-goto-file file
)))
7333 (defun anything-c-display-to-real-line (candidate)
7334 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
7335 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
7336 (error "Line number not found")))
7338 (defun anything-c-action-line-goto (lineno-and-content)
7339 (apply #'anything-goto-file-line
(anything-interpret-value (anything-attr 'target-file
))
7340 (append lineno-and-content
7341 (list (if (and (anything-attr-defined 'target-file
)
7342 (not anything-in-persistent-action
))
7343 'find-file-other-window
7346 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
7347 (apply #'anything-goto-file-line
7348 (if (stringp file-line-content
)
7349 ;; Case: filtered-candidate-transformer is skipped
7350 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content
))
7351 file-line-content
)))
7354 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
7355 (delq nil
(mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates
)))
7357 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
7358 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
)
7359 (let ((filename (match-string 1 candidate
))
7360 (lineno (match-string 2 candidate
))
7361 (content (match-string 3 candidate
)))
7362 (cons (format "%s:%s\n %s"
7363 (propertize filename
'face compilation-info-face
)
7364 (propertize lineno
'face compilation-line-face
)
7366 (list (expand-file-name
7368 (or (anything-interpret-value (anything-attr 'default-directory
))
7369 (and (anything-candidate-buffer)
7371 'default-directory
(anything-candidate-buffer)))))
7372 (string-to-number lineno
) content
)))))
7374 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
7375 (anything-aif (anything-attr 'before-jump-hook
)
7377 (when file
(funcall find-file-function file
))
7378 (if (anything-attr-defined 'adjust
)
7379 (anything-c-goto-line-with-adjustment lineno content
)
7380 (anything-goto-line lineno
))
7381 (unless (anything-attr-defined 'recenter
)
7382 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
7383 (anything-aif (anything-attr 'after-jump-hook
)
7385 (when anything-in-persistent-action
7386 (anything-match-line-color-current-line)))
7388 (defun anything-find-file-as-root (candidate)
7389 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
7391 (defun anything-find-many-files (ignore)
7392 (mapc 'find-file
(anything-marked-candidates)))
7394 ;; borrowed from etags.el
7395 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
7396 (defun anything-c-goto-line-with-adjustment (line line-content
)
7399 ;; This constant is 1/2 the initial search window.
7400 ;; There is no sense in making it too small,
7401 ;; since just going around the loop once probably
7402 ;; costs about as much as searching 2000 chars.
7405 pat
(concat (if (eq selective-display t
)
7406 "\\(^\\|\^m\\) *" "^ *") ;allow indent
7407 (regexp-quote line-content
)))
7408 ;; If no char pos was given, try the given line number.
7409 (setq startpos
(progn (anything-goto-line line
) (point)))
7410 (or startpos
(setq startpos
(point-min)))
7411 ;; First see if the tag is right at the specified location.
7412 (goto-char startpos
)
7413 (setq found
(looking-at pat
))
7414 (while (and (not found
)
7416 (goto-char (- startpos offset
))
7419 (re-search-forward pat
(+ startpos offset
) t
)
7420 offset
(* 3 offset
))) ; expand search window
7422 (re-search-forward pat nil t
)
7423 (error "not found")))
7424 ;; Position point at the right place
7425 ;; if the search string matched an extra Ctrl-m at the beginning.
7426 (and (eq selective-display t
)
7429 (beginning-of-line))
7431 (anything-document-attribute 'default-directory
"type . file-line"
7432 "`default-directory' to interpret file.")
7433 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
7434 "Function to call before jumping to the target location.")
7435 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
7436 "Function to call after jumping to the target location.")
7437 (anything-document-attribute 'adjust
"type . file-line"
7438 "Search around line matching line contents.")
7439 (anything-document-attribute 'recenter
"type . file-line / line"
7440 "`recenter' after jumping.")
7441 (anything-document-attribute 'target-file
"type . line"
7442 "Goto line of target-file.")
7445 (defun anything-c-call-interactively (cmd-or-name)
7446 "Execute CMD-OR-NAME as Emacs command.
7447 It is added to `extended-command-history'.
7448 `anything-current-prefix-arg' is used as the command's prefix argument."
7449 (setq extended-command-history
7450 (cons (anything-c-stringify cmd-or-name
)
7451 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
7452 (let ((current-prefix-arg anything-current-prefix-arg
)
7453 (cmd (anything-c-symbolify cmd-or-name
)))
7454 (if (stringp (symbol-function cmd
))
7455 (execute-kbd-macro (symbol-function cmd
))
7456 (setq this-command cmd
)
7457 (call-interactively cmd
))))
7460 (defun anything-c-set-variable (var)
7461 "Set value to VAR interactively."
7463 (let ((sym (anything-c-symbolify var
)))
7464 (set sym
(eval-minibuffer (format "Set %s: " var
)
7465 (prin1-to-string (symbol-value sym
))))))
7467 ;; (anything-c-set-variable 'hh)
7469 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7470 (defvar anything-match-line-overlay-face nil
)
7471 (defvar anything-match-line-overlay nil
)
7473 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
7474 "Highlight and underline current position"
7475 (let ((args (list (or start
(line-beginning-position))
7476 (or end
(1+ (line-end-position)))
7478 (if (not anything-match-line-overlay
)
7479 (setq anything-match-line-overlay
(apply 'make-overlay args
))
7480 (apply 'move-overlay anything-match-line-overlay args
)))
7481 (overlay-put anything-match-line-overlay
7482 'face
(or face anything-match-line-overlay-face
))
7487 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
7489 (defface anything-overlay-line-face
'((t (:background
"IndianRed4" :underline t
)))
7490 "Face for source header in the anything buffer." :group
'anything
)
7492 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
7494 (defun anything-match-line-cleanup ()
7495 (when anything-match-line-overlay
7496 (delete-overlay anything-match-line-overlay
)
7497 (setq anything-match-line-overlay nil
)))
7499 (defun anything-match-line-update ()
7500 (when anything-match-line-overlay
7501 (delete-overlay anything-match-line-overlay
)
7502 (anything-match-line-color-current-line)))
7504 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
7505 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
7507 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7509 (defun anything-c-transform-file-load-el (actions candidate
)
7510 "Add action to load the file CANDIDATE if it is an emacs lisp
7511 file. Else return ACTIONS unmodified."
7512 (if (member (file-name-extension candidate
) '("el" "elc"))
7513 (append actions
'(("Load Emacs Lisp File" . load-file
)))
7516 (defun anything-c-transform-file-browse-url (actions candidate
)
7517 "Add an action to browse the file CANDIDATE if it in a html
7518 file or URL. Else return ACTIONS unmodified."
7519 (let ((browse-action '("Browse with Browser" . browse-url
)))
7520 (cond ((string-match "^http\\|^ftp" candidate
)
7521 (cons browse-action actions
))
7522 ((string-match "\\.html?$" candidate
)
7523 (append actions
(list browse-action
)))
7527 (defun anything-c-transform-function-call-interactively (actions candidate
)
7528 "Add an action to call the function CANDIDATE interactively if
7529 it is a command. Else return ACTIONS unmodified."
7530 (if (commandp (intern-soft candidate
))
7531 (append actions
'(("Call Interactively"
7533 anything-c-call-interactively
)))
7537 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
7538 "If CANDIDATE's `car' is a command, then add an action to
7539 evaluate it and put it onto the `command-history'."
7540 (if (commandp (car (read candidate
)))
7541 ;; Make it first entry
7542 (cons '("Eval and put onto command-history" .
7544 (let ((sym (read sexp
)))
7546 (setq command-history
7547 (cons sym command-history
)))))
7551 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7553 (defun anything-c-skip-boring-buffers (buffers)
7554 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
7556 (defun anything-c-skip-current-buffer (buffers)
7557 (if anything-allow-skipping-current-buffer
7558 (remove (buffer-name anything-current-buffer
) buffers
)
7561 (defun anything-c-shadow-boring-buffers (buffers)
7562 "Buffers matching `anything-c-boring-buffer-regexp' will be
7563 displayed with the `file-name-shadow' face if available."
7564 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
7567 (defun anything-c-shadow-boring-files (files)
7568 "Files matching `anything-c-boring-file-regexp' will be
7569 displayed with the `file-name-shadow' face if available."
7570 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
7572 (defun anything-c-skip-boring-files (files)
7573 "Files matching `anything-c-boring-file-regexp' will be skipped."
7574 (anything-c-skip-entries files anything-c-boring-file-regexp
))
7575 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
7577 (defun anything-c-skip-current-file (files)
7578 "Current file will be skipped."
7579 (remove (buffer-file-name anything-current-buffer
) files
))
7581 (defun anything-c-w32-pathname-transformer (args)
7582 "Change undesirable features of windows pathnames to ones more acceptable to
7583 other candidate transformers."
7584 (if (eq system-type
'windows-nt
)
7586 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
7588 (replace-regexp-in-string "\\\\" "/" y
)) args
))
7591 (defun anything-c-shorten-home-path (files)
7592 "Replaces /home/user with ~."
7593 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
7595 (mapcar (lambda (file)
7596 (if (and (stringp file
) (string-match home file
))
7597 (cons (replace-match "~" nil nil file
) file
)
7602 (defun anything-c-mark-interactive-functions (functions)
7603 "Mark interactive functions (commands) with (i) after the function name."
7605 (loop for function in functions
7606 do
(push (cons (concat function
7607 (when (commandp (intern-soft function
)) " (i)"))
7610 finally
(return (nreverse list
)))))
7612 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7613 (defvar anything-c-adaptive-done nil
7614 "nil if history information is not yet stored for the current
7617 (defvar anything-c-adaptive-history nil
7618 "Contains the stored history information.
7619 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
7621 (defadvice anything-initialize
(before anything-c-adaptive-initialize activate
)
7622 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
7623 when anything is started."
7624 (setq anything-c-adaptive-done nil
))
7626 (defadvice anything-exit-minibuffer
(before anything-c-adaptive-exit-minibuffer activate
)
7627 "Advise `anything-exit-minibuffer' to store history information
7628 when a candidate is selected with RET."
7629 (anything-c-adaptive-store-selection))
7631 (defadvice anything-select-action
(before anything-c-adaptive-select-action activate
)
7632 "Advise `anything-select-action' to store history information
7633 when the user goes to the action list with TAB."
7634 (anything-c-adaptive-store-selection))
7636 (defun anything-c-source-use-adaptative-p (&optional source-name
)
7637 "Return current source only if it use adaptative history, nil otherwise."
7638 (let* ((source (or source-name
(anything-get-current-source)))
7639 (adapt-source (or (assoc-default 'filtered-candidate-transformer
7640 (assoc (assoc-default 'type source
)
7641 anything-type-attributes
))
7642 (assoc-default 'candidate-transformer
7643 (assoc (assoc-default 'type source
)
7644 anything-type-attributes
))
7645 (assoc-default 'filtered-candidate-transformer source
)
7646 (assoc-default 'candidate-transformer source
))))
7647 (if (listp adapt-source
)
7648 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
7649 (when (eq adapt-source
'anything-c-adaptive-sort
) source
))))
7651 (defun anything-c-adaptive-store-selection ()
7652 "Store history information for the selected candidate."
7653 (unless anything-c-adaptive-done
7654 (setq anything-c-adaptive-done t
)
7655 (let ((source (anything-c-source-use-adaptative-p)))
7657 (let* ((source-name (or (assoc-default 'type source
)
7658 (assoc-default 'name source
)))
7659 (source-info (or (assoc source-name anything-c-adaptive-history
)
7661 (push (list source-name
) anything-c-adaptive-history
)
7662 (car anything-c-adaptive-history
))))
7663 (selection (anything-get-selection))
7664 (selection-info (progn
7667 (let ((found (assoc selection
(cdr source-info
))))
7672 ;; move entry to the beginning of the
7673 ;; list, so that it doesn't get
7674 ;; trimmed when the history is
7677 (delete found
(cdr source-info
)))
7680 (cadr source-info
)))
7681 (pattern-info (progn
7682 (setcdr selection-info
7684 (let ((found (assoc anything-pattern
(cdr selection-info
))))
7687 (cons anything-pattern
0)
7689 ;; move entry to the beginning of the
7690 ;; list, so if two patterns used the
7691 ;; same number of times then the one
7692 ;; used last appears first in the list
7693 (setcdr selection-info
7694 (delete found
(cdr selection-info
)))
7696 (cdr selection-info
)))
7697 (cadr selection-info
))))
7699 ;; increase usage count
7700 (setcdr pattern-info
(1+ (cdr pattern-info
)))
7702 ;; truncate history if needed
7703 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
7704 (setcdr selection-info
7705 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
7707 (if (file-readable-p anything-c-adaptive-history-file
)
7708 (load-file anything-c-adaptive-history-file
))
7709 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
7711 (defun anything-c-adaptive-save-history ()
7712 "Save history information to file given by `anything-c-adaptive-history-file'."
7716 ";; -*- mode: emacs-lisp -*-\n"
7717 ";; History entries used for anything adaptive display.\n")
7718 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
7721 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
7722 (unless (interactive-p) 'quiet
))))
7724 (defun anything-c-adaptive-sort (candidates source
)
7725 "Sort the CANDIDATES for SOURCE by usage frequency.
7726 This is a filtered candidate transformer you can use for the
7727 attribute `filtered-candidate-transformer' of a source in
7728 `anything-sources' or a type in `anything-type-attributes'."
7729 (let* ((source-name (or (assoc-default 'type source
)
7730 (assoc-default 'name source
)))
7731 (source-info (assoc source-name anything-c-adaptive-history
)))
7732 (if (not source-info
)
7733 ;; if there is no information stored for this source then do nothing
7737 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
7739 (mapcar (lambda (candidate-info)
7741 (dolist (pattern-info (cdr candidate-info
))
7742 (if (not (equal (car pattern-info
)
7744 (incf count
(cdr pattern-info
))
7746 ;; if current pattern is equal to the previously
7747 ;; used one then this candidate has priority
7748 ;; (that's why its count is boosted by 10000) and
7749 ;; it only has to compete with other candidates
7750 ;; which were also selected with the same pattern
7751 (setq count
(+ 10000 (cdr pattern-info
)))
7753 (cons (car candidate-info
) count
)))
7757 ;; sort the list in descending order, so candidates with highest
7758 ;; priorty come first
7759 (setq usage
(sort usage
(lambda (first second
)
7760 (> (cdr first
) (cdr second
)))))
7762 ;; put those candidates first which have the highest usage count
7763 (dolist (info usage
)
7764 (when (member* (car info
) candidates
7765 :test
'anything-c-adaptive-compare
)
7766 (push (car info
) sorted
)
7767 (setq candidates
(remove* (car info
) candidates
7768 :test
'anything-c-adaptive-compare
))))
7770 ;; and append the rest
7771 (append (reverse sorted
) candidates nil
)))))
7773 (defun anything-c-adaptive-compare (x y
)
7774 "Compare candidates X and Y taking into account that the
7775 candidate can be in (DISPLAY . REAL) format."
7776 (equal (if (listp x
)
7783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7784 (defvar anything-outline-goto-near-line-flag t
)
7785 (defvar anything-outline-using nil
)
7786 (defun anything-after-update-hook--outline ()
7787 (if (and (eq anything-outline-using t
)
7788 (eq anything-outline-goto-near-line-flag t
))
7789 (anything-outline-goto-near-line)))
7790 (add-hook 'anything-after-update-hook
'anything-after-update-hook--outline
)
7792 (defun anything-outline-goto-near-line ()
7793 (with-anything-window
7794 ;; TODO need consideration whether to update position by every input.
7795 (when t
; (equal anything-pattern "")
7796 (anything-goto-line 2)
7797 (let ((lineno (with-current-buffer anything-current-buffer
7798 (line-number-at-pos (car anything-current-position
)))))
7800 (while (<= (progn (skip-chars-forward " ")
7801 (or (number-at-point) lineno
))
7806 (return-from exit
))))
7808 (and (bobp) (forward-line 1))
7809 (and (anything-pos-header-line-p) (forward-line -
2))
7810 (anything-mark-current-line)))))
7812 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7813 ;; Plug-in: info-index
7814 (defun* anything-c-info-init
(&optional
(file (anything-attr 'info-file
)))
7816 (unless (anything-candidate-buffer)
7817 (save-window-excursion
7820 (tobuf (anything-candidate-buffer 'global
))
7821 (infobuf (current-buffer))
7823 (dolist (node (or (anything-attr 'index-nodes
) (Info-index-nodes)))
7824 (Info-goto-node node
)
7825 (goto-char (point-min))
7826 (while (search-forward "\n* " nil t
)
7827 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t
)
7828 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result
)
7829 (setq s
(point-at-bol)
7831 (with-current-buffer tobuf
7832 (insert-buffer-substring infobuf s e
)
7833 (insert "\n"))))))))))
7835 (defun anything-c-info-goto (node-line)
7836 (Info-goto-node (car node-line
))
7837 (anything-goto-line (cdr node-line
)))
7839 (defun anything-c-info-display-to-real (line)
7841 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line
)
7842 (cons (format "(%s)%s" (anything-attr 'info-file
) (match-string 2 line
))
7843 (string-to-number (or (match-string 3 line
) "1")))))
7845 (defun anything-c-make-info-source (file)
7846 `((name .
,(concat "Info Index: " file
))
7848 (init . anything-c-info-init
)
7849 (display-to-real . anything-c-info-display-to-real
)
7850 (get-line . buffer-substring
)
7851 (candidates-in-buffer)
7852 (action ("Goto node" . anything-c-info-goto
))))
7854 (defun anything-compile-source--info-index (source)
7855 (anything-aif (anything-interpret-value (assoc-default 'info-index source
))
7856 (anything-c-make-info-source it
)
7858 (add-to-list 'anything-compile-source-functions
'anything-compile-source--info-index
)
7860 (anything-document-attribute 'info-index
"info-index plugin"
7861 "Create a source of info index very easily.
7863 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
7865 (anything-document-attribute 'index-nodes
"info-index plugin (optional)"
7866 "Index nodes of info file.
7868 If it is omitted, `Info-index-nodes' is used to collect index nodes.
7869 Some info files are missing index specification.
7871 ex. See `anything-c-source-info-screen'.")
7873 ;; Plug-in: candidates-file
7874 (defun anything-compile-source--candidates-file (source)
7875 (if (assoc-default 'candidates-file source
)
7876 `((init anything-p-candidats-file-init
7877 ,@(let ((orig-init (assoc-default 'init source
)))
7878 (cond ((null orig-init
) nil
)
7879 ((functionp orig-init
) (list orig-init
))
7881 (candidates-in-buffer)
7884 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
7886 (defun anything-p-candidats-file-init ()
7887 (destructuring-bind (file &optional updating
)
7888 (anything-mklist (anything-attr 'candidates-file
))
7889 (setq file
(anything-interpret-value file
))
7890 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
7892 (buffer-disable-undo)
7894 (auto-revert-mode 1)))))
7896 (anything-document-attribute 'candidates-file
"candidates-file plugin"
7897 "Use a file as the candidates buffer.
7899 1st argument is a filename, string or function name or variable name.
7900 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
7902 ;; Plug-in: headline
7903 (defun anything-compile-source--anything-headline (source)
7904 (if (assoc-default 'headline source
)
7905 (append '((init . anything-headline-init
)
7906 (get-line . buffer-substring
)
7909 '((candidates-in-buffer)
7910 (persistent-help .
"Show this line")))
7912 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
7914 (defun anything-headline-init ()
7915 (when (and (anything-current-buffer-is-modified)
7916 (with-current-buffer anything-current-buffer
7917 (eval (or (anything-attr 'condition
) t
))))
7918 (anything-headline-make-candidate-buffer
7919 (anything-interpret-value (anything-attr 'headline
))
7920 (anything-interpret-value (anything-attr 'subexp
)))))
7922 (anything-document-attribute 'headline
"Headline plug-in"
7923 "Regexp string for anything-headline to scan.")
7924 (anything-document-attribute 'condition
"Headline plug-in"
7925 "A sexp representing the condition to use anything-headline.")
7926 (anything-document-attribute 'subexp
"Headline plug-in"
7927 "Display (match-string-no-properties subexp).")
7930 (defun anything-headline-get-candidates (regexp subexp
)
7931 (with-current-buffer anything-current-buffer
7933 (goto-char (point-min))
7934 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
7935 (let (hierarchy curhead
)
7937 (if (numberp subexp
)
7938 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
7939 (cons (buffer-substring (point-at-bol) (point-at-eol))
7941 (hierarchies (headlines)
7942 (1+ (loop for
(_ . hierarchy
) in headlines
7943 maximize hierarchy
)))
7945 (loop for i from
0 to hierarchy
7946 collecting
(aref curhead i
)))
7947 (arrange (headlines)
7948 (unless (null headlines
) ; FIX headlines empty bug!
7949 (loop with curhead
= (make-vector (hierarchies headlines
) "")
7950 for
((str . pt
) . hierarchy
) in headlines
7951 do
(aset curhead hierarchy str
)
7954 (format "H%d:%s" (1+ hierarchy
)
7955 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / "))
7960 (loop for re in regexp
7961 for hierarchy from
0
7962 do
(goto-char (point-min))
7965 while
(re-search-forward re nil t
)
7966 collect
(cons (matched) hierarchy
)))
7967 (lambda (a b
) (> (cdar b
) (cdar a
)))))
7968 (loop while
(re-search-forward regexp nil t
)
7969 collect
(matched))))))))
7972 (defun anything-headline-make-candidate-buffer (regexp subexp
)
7973 (with-current-buffer (anything-candidate-buffer 'local
)
7974 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
7977 (with-current-buffer anything-current-buffer
7978 (line-number-at-pos pos
))
7981 (defun anything-headline-goto-position (pos recenter
)
7984 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
7986 (defun anything-revert-buffer (candidate)
7987 (with-current-buffer candidate
7988 (when (buffer-modified-p)
7989 (revert-buffer t t
))))
7991 (defun anything-revert-marked-buffers (ignore)
7992 (mapc 'anything-revert-buffer
(anything-marked-candidates)))
7994 (defun anything-kill-marked-buffers (ignore)
7995 (mapc 'kill-buffer
(anything-marked-candidates)))
7997 ;; Plug-in: persistent-help
7998 (defun anything-compile-source--persistent-help (source)
7999 (append source
'((header-line . anything-persistent-help-string
))))
8000 (add-to-list 'anything-compile-source-functions
'anything-compile-source--persistent-help
)
8002 (defun anything-persistent-help-string ()
8003 (substitute-command-keys
8004 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
8005 (or (anything-interpret-value (anything-attr 'persistent-help
))
8006 (anything-aif (or (assoc-default 'persistent-action
8007 (anything-get-current-source))
8008 (assoc-default 'action
8009 (anything-get-current-source)))
8010 (cond ((symbolp it
) (symbol-name it
))
8011 ((listp it
) (or (ignore-errors (caar it
)) ""))))
8013 " (keeping session)")))
8015 (anything-document-attribute 'persistent-help
"persistent-help plug-in"
8016 "A string to explain persistent-action of this source.
8017 It also accepts a function or a variable name.")
8019 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
8021 ;; Plug-in: Type customize
8022 (defun anything-c-uniq-list (lst)
8023 "Like `remove-duplicates' in CL.
8024 But cut deeper duplicates and test by `equal'. "
8025 (reverse (remove-duplicates (reverse lst
) :test
'equal
)))
8026 (defvar anything-additional-type-attributes nil
)
8027 (defun anything-c-arrange-type-attribute (type spec
)
8028 "Override type attributes by `define-anything-type-attribute'.
8030 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
8032 Example: Set `play-sound-file' as default action
8033 (anything-c-arrange-type-attribute 'file
8034 '((action (\"Play sound\" . play-sound-file)
8035 REST ;; Rest of actions (find-file, find-file-other-window, ...)
8038 (add-to-list 'anything-additional-type-attributes
8040 (loop with typeattr
= (assoc-default type anything-type-attributes
)
8041 for
(attr . value
) in spec
8044 (anything-c-uniq-list
8045 (loop for v in value
8047 append
(assoc-default attr typeattr
)
8051 collect
(cons attr value
)))))
8052 (put 'anything-c-arrange-type-attribute
'lisp-indent-function
1)
8054 (defun anything-compile-source--type-customize (source)
8055 (anything-aif (assoc-default (assoc-default 'type source
) anything-additional-type-attributes
)
8058 (add-to-list 'anything-compile-source-functions
'anything-compile-source--type-customize t
)
8060 ;; Plug-in: default-action
8061 (defun anything-compile-source--default-action (source)
8062 (anything-aif (assoc-default 'default-action source
)
8063 (append `((action ,it
,@(remove it
(assoc-default 'action source
))))
8066 (add-to-list 'anything-compile-source-functions
'anything-compile-source--default-action t
)
8067 (anything-document-attribute 'default-action
"default-action plug-in"
8070 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8072 (defun anything-c-find-file-or-marked (candidate)
8073 "Open file CANDIDATE or open anything marked files in background."
8074 (let ((marked (anything-marked-candidates)))
8075 (if (> (length marked
) 1)
8076 ;; Open all marked files in background.
8077 (mapc 'find-file-noselect marked
)
8078 (if (and (not (file-exists-p candidate
))
8079 (and ffap-url-regexp
8080 (not (string-match ffap-url-regexp candidate
)))
8081 (string-match "/$" candidate
))
8082 ;; A a non--existing filename ending with /
8083 ;; Create a directory and jump to it.
8084 (when (y-or-n-p (format "Create directory `%s'? " candidate
))
8085 (make-directory candidate
'parent
)
8086 (anything-find-files1 candidate
))
8087 ;; A non--existing filename NOT ending with / or
8088 ;; an existing filename, create or jump to it.
8089 (find-file-at-point (car marked
))))))
8091 (defun anything-delete-marked-files (ignore)
8092 (let* ((files (anything-marked-candidates))
8093 (len (length files
)))
8095 (format "Delete *%s File(s):\n%s"
8097 (mapconcat (lambda (f) (format "- %s\n" f
)) files
""))))
8098 (message "(No deletions performed)")
8100 (set-text-properties 0 (length i
) nil i
)
8101 (anything-c-delete-file i
))
8102 (message "%s File(s) deleted" len
))))
8104 (defun anything-ediff-marked-buffers (candidate &optional merge
)
8105 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
8106 With optional arg `merge' call `ediff-merge-buffers'."
8107 (let ((lg-lst (length (anything-marked-candidates)))
8111 (error "Error:You have to mark at least 1 buffer"))
8113 (setq buf1 anything-current-buffer
8114 buf2
(first (anything-marked-candidates))))
8116 (setq buf1
(first (anything-marked-candidates))
8117 buf2
(second (anything-marked-candidates))))
8119 (error "Error:To much buffers marked!")))
8121 (ediff-merge-buffers buf1 buf2
)
8122 (ediff-buffers buf1 buf2
))))
8124 (defun anything-bookmark-get-bookmark-from-name (bmk)
8125 "Return bookmark name even if it is a bookmark with annotation.
8126 e.g prepended with *.
8127 Return nil if bmk is not a valid bookmark."
8128 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
8129 (if (assoc bookmark bookmark-alist
)
8131 (when (assoc bmk bookmark-alist
)
8134 (defun anything-delete-marked-bookmarks (ignore)
8135 "Delete this bookmark or all marked bookmarks."
8136 (dolist (i (anything-marked-candidates))
8137 (bookmark-delete (anything-bookmark-get-bookmark-from-name i
)
8140 (defun anything-require-or-error (feature function
)
8141 (or (require feature nil t
)
8142 (error "Need %s to use `%s'." feature function
)))
8144 (defun anything-find-buffer-on-elscreen (candidate)
8145 "Open buffer in new screen, if marked buffers open all in elscreens."
8146 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
8147 (anything-aif (anything-marked-candidates)
8149 (let ((target-screen (elscreen-find-screen-by-buffer
8150 (get-buffer i
) 'create
)))
8151 (elscreen-goto target-screen
)))
8152 (let ((target-screen (elscreen-find-screen-by-buffer
8153 (get-buffer candidate
) 'create
)))
8154 (elscreen-goto target-screen
))))
8156 (defun anything-elscreen-find-file (file)
8157 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
8158 (elscreen-find-file file
))
8160 ;; Toggle anything-match-plugin
8161 (defvar anything-mp-initial-highlight-delay nil
)
8162 (defun anything-c-toggle-match-plugin ()
8163 "Toggle anything-match-plugin."
8165 (let ((anything-match-plugin-enabled
8166 (member 'anything-compile-source--match-plugin
8167 anything-compile-source-functions
)))
8168 (flet ((disable-match-plugin ()
8169 (setq anything-compile-source-functions
8170 (delq 'anything-compile-source--match-plugin
8171 anything-compile-source-functions
))
8172 (setq anything-mp-initial-highlight-delay
8173 anything-mp-highlight-delay
)
8174 (setq anything-mp-highlight-delay nil
))
8175 (enable-match-plugin ()
8176 (require 'anything-match-plugin
)
8177 (unless anything-mp-initial-highlight-delay
8178 (setq anything-mp-initial-highlight-delay
8179 anything-mp-highlight-delay
))
8180 (setq anything-compile-source-functions
8181 (cons 'anything-compile-source--match-plugin
8182 anything-compile-source-functions
))
8183 (unless anything-mp-highlight-delay
8184 (setq anything-mp-highlight-delay
8185 anything-mp-initial-highlight-delay
))))
8186 (if anything-match-plugin-enabled
8187 (when (y-or-n-p "Really disable match-plugin? ")
8188 (disable-match-plugin)
8189 (message "Anything-match-plugin disabled"))
8190 (when (y-or-n-p "Really enable match-plugin? ")
8191 (enable-match-plugin)
8192 (message "Anything-match-plugin enabled"))))))
8195 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8197 ;;;; Type Attributes
8198 (define-anything-type-attribute 'buffer
8201 '(("Switch to buffer other window" . switch-to-buffer-other-window
)
8202 ("Switch to buffer" . switch-to-buffer
))
8203 '(("Switch to buffer" . switch-to-buffer
)
8204 ("Switch to buffer other window" . switch-to-buffer-other-window
)
8205 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)))
8206 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
8207 ("View buffer" . view-buffer
)
8208 ("Display buffer" . display-buffer
)
8209 ("Revert buffer" . anything-revert-buffer
)
8210 ("Revert Marked buffers" . anything-revert-marked-buffers
)
8211 ("Insert buffer" . insert-buffer
)
8212 ("Kill buffer" . kill-buffer
)
8213 ("Kill Marked buffers" . anything-kill-marked-buffers
)
8214 ("Diff with file" . diff-buffer-with-file
)
8215 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
8216 ("Ediff Merge marked buffers" .
(lambda (candidate)
8217 (anything-ediff-marked-buffers candidate t
))))
8218 (persistent-help .
"Show this buffer")
8219 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers
))
8220 "Buffer or buffer name.")
8222 (define-anything-type-attribute 'file
8225 '(("Find file other window" . find-file-other-window
)
8226 ("Find file(s)" . anything-find-many-files
)
8227 ("Find file as root" . anything-find-file-as-root
))
8228 '(("Find file" . anything-find-many-files
)
8229 ("Find file as root" . anything-find-file-as-root
)
8230 ("Find file other window" . find-file-other-window
)
8231 ("Find file other frame" . find-file-other-frame
)))
8232 ("Open dired in file's directory" . anything-c-open-dired
)
8233 ("Grep File(s) `C-u recurse'"
8234 .
(lambda (candidate)
8235 (if anything-current-prefix-arg
8236 (anything-do-grep1 (anything-marked-candidates) 'recurse
)
8237 (anything-do-grep1 (anything-marked-candidates)))))
8238 ("View file" . view-file
)
8239 ("Insert file" . insert-file
)
8240 ("Delete file(s)" . anything-delete-marked-files
)
8241 ("Open file externally (C-u to choose)" . anything-c-open-file-externally
)
8242 ("Open file with default tool" . anything-c-open-file-with-default-tool
)
8243 ("Find file in hex dump" . hexl-find-file
))
8244 (persistent-help .
"Show this file")
8245 (action-transformer anything-c-transform-file-load-el
8246 anything-c-transform-file-browse-url
)
8247 (candidate-transformer anything-c-w32-pathname-transformer
8248 anything-c-skip-current-file
8249 anything-c-skip-boring-files
8250 anything-c-shorten-home-path
))
8253 (let ((actions '(("Describe command" . describe-function
)
8254 ("Add command to kill ring" . anything-c-kill-new
)
8255 ("Go to command's definition" . find-function
)
8256 ("Debug on entry" . debug-on-entry
)
8257 ("Cancel debug on entry" . cancel-debug-on-entry
)
8258 ("Trace function" . trace-function
)
8259 ("Trace function (background)" . trace-function-background
)
8260 ("Untrace function" . untrace-function
))))
8261 (define-anything-type-attribute 'command
8262 `((action ("Call interactively" . anything-c-call-interactively
)
8264 ;; Sort commands according to their usage count.
8265 (filtered-candidate-transformer . anything-c-adaptive-sort
)
8266 (coerce . anything-c-symbolify
)
8267 (persistent-action . describe-function
))
8268 "Command. (string or symbol)")
8270 (define-anything-type-attribute 'function
8271 `((action .
,actions
)
8272 (action-transformer anything-c-transform-function-call-interactively
)
8273 (candidate-transformer anything-c-mark-interactive-functions
)
8274 (coerce . anything-c-symbolify
))
8275 "Function. (string or symbol)"))
8277 (define-anything-type-attribute 'variable
8278 '((action ("Describe variable" . describe-variable
)
8279 ("Add variable to kill ring" . anything-c-kill-new
)
8280 ("Go to variable's definition" . find-variable
)
8281 ("Set variable" . anything-c-set-variable
))
8282 (coerce . anything-c-symbolify
))
8285 (define-anything-type-attribute 'sexp
8286 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
8287 ("Add s-expression to kill ring" . kill-new
))
8288 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
8289 "String representing S-Expressions.")
8291 (define-anything-type-attribute 'bookmark
8292 `((coerce . anything-bookmark-get-bookmark-from-name
)
8294 ("Jump to bookmark" .
(lambda (bookmark)
8295 (let ((current-prefix-arg anything-current-prefix-arg
))
8296 (bookmark-jump bookmark
))
8298 ("Jump to BM other window" .
(lambda (bookmark)
8299 (bookmark-jump-other-window bookmark
)
8301 ("Bookmark edit annotation" . bookmark-edit-annotation
)
8302 ("Bookmark show annotation" . bookmark-show-annotation
)
8303 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
8304 ,@(when (fboundp 'bmkext-edit-bookmark
)
8305 '(("Edit Bookmark" . bmkext-edit-bookmark
)))
8306 ("Rename bookmark" . bookmark-rename
)
8307 ("Relocate bookmark" . bookmark-relocate
)))
8310 (define-anything-type-attribute 'line
8311 '((display-to-real . anything-c-display-to-real-line
)
8312 (action ("Go to Line" . anything-c-action-line-goto
)))
8313 "LINENO:CONTENT string, eg. \" 16:foo\".
8315 Optional `target-file' attribute is a name of target file.
8317 Optional `before-jump-hook' attribute is a function with no
8318 arguments which is called before jumping to position.
8320 Optional `after-jump-hook' attribute is a function with no
8321 arguments which is called after jumping to position.
8323 If `adjust' attribute is specified, searches the line whose
8324 content is CONTENT near the LINENO.
8326 If `recenter' attribute is specified, the line is displayed at
8327 the center of window, otherwise at the top of window.
8330 (define-anything-type-attribute 'file-line
8331 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
8333 (action ("Go to" . anything-c-action-file-line-goto
)))
8334 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
8336 Optional `default-directory' attribute is a default-directory
8337 FILENAME is interpreted.
8339 Optional `before-jump-hook' attribute is a function with no
8340 arguments which is called before jumping to position.
8342 Optional `after-jump-hook' attribute is a function with no
8343 arguments which is called after jumping to position.
8345 If `adjust' attribute is specified, searches the line whose
8346 content is CONTENT near the LINENO.
8348 If `recenter' attribute is specified, the line is displayed at
8349 the center of window, otherwise at the top of window.
8352 (define-anything-type-attribute 'timer
8353 '((real-to-display . anything-c-timer-real-to-display
)
8354 (action ("Cancel Timer" . cancel-timer
)
8355 ("Describe Function" .
(lambda (tm) (describe-function (timer--function tm
))))
8356 ("Find Function" .
(lambda (tm) (find-function (timer--function tm
)))))
8357 (persistent-action .
(lambda (tm) (describe-function (timer--function tm
))))
8358 (persistent-help .
"Describe Function"))
8361 ;;;; Default `anything-sources'
8362 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
8363 ;; tend to invoke M-x anything directly. So I offer default setting.
8364 (setq anything-sources
8365 '(anything-c-source-buffers+
8366 anything-c-source-recentf
8367 anything-c-source-files-in-current-dir
+))
8370 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
8371 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
8373 (when (fboundp 'expectations
)
8375 (desc "candidates-file plug-in")
8376 (expect '(anything-p-candidats-file-init)
8377 (assoc-default 'init
8378 (car (anything-compile-sources
8380 (candidates-file .
"test.txt")))
8381 '(anything-compile-source--candidates-file)))))
8382 (expect '(anything-p-candidats-file-init
8384 (assoc-default 'init
8385 (car (anything-compile-sources
8387 (candidates-file .
"test.txt")
8388 (init .
(lambda () 1))))
8389 '(anything-compile-source--candidates-file)))))
8390 (expect '(anything-p-candidats-file-init
8392 (assoc-default 'init
8393 (car (anything-compile-sources
8395 (candidates-file .
"test.txt")
8396 (init (lambda () 1))))
8397 '(anything-compile-source--candidates-file)))))
8399 ;; (desc "anything-c-source-buffers")
8400 ;; (expect '(("Buffers" ("foo" "curbuf")))
8401 ;; (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
8402 ;; (let ((anything-c-boring-buffer-regexp
8407 ;; " *Echo Area" " *Minibuf"))))
8408 ;; (flet ((buffer-name (&optional x) x))
8409 ;; (anything-test-candidates 'anything-c-source-buffers))))
8410 (desc "anything-c-stringify")
8412 (anything-c-stringify "str1"))
8414 (anything-c-stringify 'str2
))
8415 (desc "anything-c-symbolify")
8417 (anything-c-symbolify "sym1"))
8419 (anything-c-symbolify 'sym2
))
8420 (desc "plug-in:default-action")
8421 (expect '(((action ("default" . default
) ("original" . original
))
8422 (default-action .
("default" . default
))
8423 (action ("original" . original
))))
8424 (anything-compile-sources
8425 '(((default-action .
("default" . default
))
8426 (action ("original" . original
))))
8427 '(anything-compile-source--default-action)))
8428 (expect '(((action ("a1" . a1
) ("a2" . a2
))
8429 (default-action .
("a1" . a1
))
8430 (action ("a1" . a1
) ("a2" . a2
))))
8431 (anything-compile-sources
8432 '(((default-action .
("a1" . a1
))
8433 (action ("a1" . a1
) ("a2" . a2
))))
8434 '(anything-compile-source--default-action)))
8435 (expect '(((action ("a2" . a2
) ("a1" . a1
))
8436 (default-action .
("a2" . a2
))
8437 (action ("a1" . a1
) ("a2" . a2
))))
8438 (anything-compile-sources
8439 '(((default-action .
("a2" . a2
))
8440 (action ("a1" . a1
) ("a2" . a2
))))
8441 '(anything-compile-source--default-action))))))
8443 (provide 'anything-config
)
8445 ;;; Local Variables:
8446 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
8449 ;; How to save (DO NOT REMOVE!!)
8450 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
8451 ;;; anything-config.el ends here
8453 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
8454 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
8455 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
8456 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
8457 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
8458 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
8459 ;;; LocalWords: dotimes Thierry online vname
8460 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
8461 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
8462 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
8463 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
8464 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
8465 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
8466 ;;; LocalWords: startpos noselect dont desc