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 (dolist (i image-load-path
)
741 (if (file-directory-p (expand-file-name "tree-widget/default" (eval i
)))
742 (return (expand-file-name "tree-widget/default" (eval i
))))))
743 "*Default path where to find files and directory icons."
745 :group
'anything-config
)
747 (defcustom anything-c-browse-code-regexp-lisp
748 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
749 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
750 "*Regexp used to parse lisp buffer when browsing code."
752 :group
'anything-config
)
754 (defcustom anything-c-browse-code-regexp-python
755 "\\<def\\>\\|\\<class\\>"
756 "*Regexp used to parse python buffer when browsing code."
758 :group
'anything-config
)
760 (defcustom anything-c-browse-code-regexp-alist
761 `((lisp-interaction-mode .
,anything-c-browse-code-regexp-lisp
)
762 (emacs-lisp-mode .
,anything-c-browse-code-regexp-lisp
)
763 (lisp-mode .
,anything-c-browse-code-regexp-lisp
)
764 (python-mode .
,anything-c-browse-code-regexp-python
))
765 "*Alist to store regexps for browsing code corresponding \
766 to a specific `major-mode'."
768 :group
'anything-config
)
770 (defcustom anything-c-external-programs-associations nil
771 "*Alist to store externals programs associated with file extension.
772 This variable overhide setting in .mailcap file.
773 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
775 :group
'anything-config
)
777 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
778 ;; TODO: This should be integrated in anything.el instead of having
781 (defvar anything-current-prefix-arg nil
782 "Record `current-prefix-arg' when exiting minibuffer.
783 It will be cleared at start of next `anything' call when \
784 `anything-before-initialize-hook' is called.")
786 (defadvice anything-exit-minibuffer
(before anything-current-prefix-arg activate
)
787 (unless anything-current-prefix-arg
788 (setq anything-current-prefix-arg current-prefix-arg
)))
790 ;; using this hook instead of `anything-after-action-hook'
791 ;; allow to record the prefix args and keep their values
792 ;; when using `anything-comp-read'.
793 ;; i.e when quitting `anything-comp-read' prefix args are preserved
794 ;; for the following action.
795 (add-hook 'anything-before-initialize-hook
796 (lambda () (setq anything-current-prefix-arg nil
)))
799 (defun anything-configuration ()
800 "Customize `anything'."
802 (customize-group "anything-config"))
804 ;;; Anything-command-map
806 (defvar anything-command-map
)
807 (define-prefix-command 'anything-command-map
)
809 ;; rubikitch: Please change it freely because it is in discussion. I'll track from git.
810 (define-key anything-command-map
(kbd "<SPC>") 'anything-execute-anything-command
)
811 (define-key anything-command-map
(kbd "e") 'anything-c-etags-select
)
812 (define-key anything-command-map
(kbd "l") 'anything-locate
)
813 (define-key anything-command-map
(kbd "s") 'anything-surfraw
)
814 (define-key anything-command-map
(kbd "r") 'anything-regexp
)
815 (define-key anything-command-map
(kbd "w") 'anything-w3m-bookmarks
)
816 (define-key anything-command-map
(kbd "x") 'anything-firefox-bookmarks
)
817 (define-key anything-command-map
(kbd "#") 'anything-emms
)
818 (define-key anything-command-map
(kbd "m") 'anything-man-woman
)
819 (define-key anything-command-map
(kbd "t") 'anything-top
)
820 (define-key anything-command-map
(kbd "i") 'anything-imenu
)
821 (define-key anything-command-map
(kbd "p") 'anything-list-emacs-process
)
822 (define-key anything-command-map
(kbd "C-x r b") 'anything-c-pp-bookmarks
)
823 (define-key anything-command-map
(kbd "M-y") 'anything-show-kill-ring
)
824 (define-key anything-command-map
(kbd "C-c <SPC>") 'anything-all-mark-rings
)
825 (define-key anything-command-map
(kbd "C-x C-f") 'anything-find-files
)
826 (define-key anything-command-map
(kbd "f") 'anything-for-files
)
827 (define-key anything-command-map
(kbd "C-:") 'anything-eval-expression-with-eldoc
)
828 (define-key anything-command-map
(kbd "C-,") 'anything-calcul-expression
)
829 (define-key anything-command-map
(kbd "M-x") 'anything-M-x
)
830 (define-key anything-command-map
(kbd "C-x C-w") 'anything-write-file
)
831 (define-key anything-command-map
(kbd "C-x i") 'anything-insert-file
)
832 (define-key anything-command-map
(kbd "M-s o") 'anything-occur
)
833 (define-key anything-command-map
(kbd "M-g s") 'anything-do-grep
)
834 (define-key anything-command-map
(kbd "c") 'anything-colors
)
835 (define-key anything-command-map
(kbd "F") 'anything-select-xfont
)
836 (define-key anything-command-map
(kbd "C-c f") 'anything-recentf
)
837 (define-key anything-command-map
(kbd "C-c g") 'anything-google-suggest
)
838 (define-key anything-command-map
(kbd "h i") 'anything-info-at-point
)
839 (define-key anything-command-map
(kbd "h r") 'anything-info-emacs
)
840 (define-key anything-command-map
(kbd "C-x C-b") 'anything-buffers
+)
841 (define-key anything-command-map
(kbd "C-c C-b") 'anything-browse-code
)
842 (define-key anything-command-map
(kbd "C-x r i") 'anything-register
)
843 (define-key anything-command-map
(kbd "C-c C-x") 'anything-c-run-external-command
)
845 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
846 ;; minibuffer-local-filename-must-match-map.
847 (defvar minibuffer-local-filename-must-match-map
(make-sparse-keymap)) ;; Emacs 23.1.+
848 (defvar minibuffer-local-must-match-filename-map
(make-sparse-keymap)) ;; Older Emacsen
849 (dolist (map (list minibuffer-local-filename-completion-map
850 minibuffer-local-completion-map
851 minibuffer-local-must-match-filename-map
852 minibuffer-local-filename-must-match-map
854 minibuffer-local-isearch-map
855 minibuffer-local-must-match-map
856 minibuffer-local-ns-map
))
857 (define-key map
"\C-r" 'anything-minibuffer-history
))
860 (easy-menu-define nil global-map
863 ["All anything commands" anything-execute-anything-command t
]
864 ["Find any Files/Buffers" anything-for-files t
]
867 ["Find files" anything-find-files t
]
868 ["Recent Files" anything-recentf t
]
869 ["Locate" anything-locate t
]
870 ["Bookmarks" anything-c-pp-bookmarks t
])
872 ["Find buffers" anything-buffers
+ t
])
874 ["Emacs Commands" anything-M-x t
]
875 ["Externals Commands" anything-c-run-external-command t
])
877 ["Info at point" anything-info-at-point t
]
878 ["Emacs Manual index" anything-info-emacs t
])
880 ["Org keywords" anything-org-keywords t
]
881 ["Org headlines" anything-org-headlines t
])
883 ["Occur" anything-occur t
]
884 ["Grep" anything-do-grep t
]
885 ["Etags" anything-c-etags-select t
]
886 ["Browse Kill ring" anything-show-kill-ring t
]
887 ["Browse register" anything-register t
]
888 ["Browse code" anything-browse-code t
]
889 ["Mark Ring" anything-all-mark-rings t
]
890 ["Regexp handler" anything-regexp t
]
891 ["Colors & Faces" anything-colors t
]
892 ["Show xfonts" anything-select-xfont t
]
893 ["Imenu" anything-imenu t
]
894 ["Google Suggest" anything-google-suggest t
]
895 ["Eval expression" anything-eval-expression-with-eldoc t
]
896 ["Calcul expression" anything-calcul-expression t
]
897 ["Man pages" anything-man-woman t
]
898 ["Top externals process" anything-top t
]
899 ["Emacs internals process" anything-list-emacs-process t
])
901 ["Prefered Options" anything-configuration t
]))
905 ;; It is replaced by `anything-help'
906 (defun anything-c-describe-anything-bindings ()
907 "[OBSOLETE] Describe `anything' bindings."
909 (anything-run-after-quit
911 (with-current-buffer (get-buffer-create "*Anything Help*")
914 (substitute-command-keys
915 "The keys that are defined for `anything' are:
917 (pop-to-buffer "*Anything Help*")
918 (goto-char (point-min)))))
920 ;; Use `describe-mode' key in `global-map'
921 ;; (dolist (k (where-is-internal 'describe-mode global-map))
922 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
925 (defun anything-c-list-preconfigured-anything ()
928 for entry in
(cdr (assoc
929 (file-truename (locate-library "anything-config"))
931 if
(and (consp entry
)
932 (eq (car entry
) 'defun
)
933 (string-match "^Preconfigured.+$"
934 (setq doc
(or (documentation (setq sym
(cdr entry
)))
936 collect
(cons sym
(match-string 0 doc
))))
938 (defun anything-c-format-preconfigured-anything ()
939 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x
) (cdr x
)))
940 (anything-c-list-preconfigured-anything)))
942 (setq anything-help-message
946 "`anything' is QuickSilver-like candidate-selection framework.
948 Narrow the list by typing some pattern,
949 Multiple patterns are allowed by splitting by space.
950 Select with natural Emacs operations, choose with RET.
952 If you have any problems, press C-c C-x C-b!!
953 Feel free to send bug reports. I'll fix them.
954 The steps are described in the beginning of anything.el file.
956 == Basic Operations ==
957 C-p, Up: Previous Line
958 C-n, Down : Next Line
959 M-v, PageUp : Previous Page
960 C-v, PageDown : Next Page
961 Enter : Execute first (default) action / Select
964 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
965 M-PageDown, C-M-v : Next Page (other-window)
967 Tab, C-i : Show action list
968 Left : Previous Source
969 Right, C-o : Next Source
971 C-z : Persistent Action (Execute action with anything session kept)
972 C-c C-x C-b: Send a bug report
974 == Shortcuts For 2nd/3rd Action ==
975 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
976 \\[anything-select-3rd-action] : Execute 3rd Action
979 Visible marks store candidate. Some actions uses marked candidates.
981 \\[anything-toggle-visible-mark] : Toggle Visible Mark
982 \\[anything-prev-visible-mark] : Previous Mark
983 \\[anything-next-visible-mark] : Next Mark
985 == Miscellaneous Commands ==
986 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
987 \\[anything-quit-and-find-file] : Drop into `find-file'
988 \\[anything-delete-current-selection] : Delete Selected Item (visually)
989 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
990 \\[anything-yank-selection] : Yank Selected Item Into Pattern
991 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
992 \\[anything-force-update] : Recalculate And Redisplay Candidates
994 == Global Commands ==
995 \\<global-map>\\[anything-resume] revives last `anything' session.
996 It is very useful, so you should bind any key.
998 Single source is executed by \\[anything-call-source].
1000 == Preconfigured `anything' ==
1001 Preconfigured `anything' is commands that uses `anything' interface.
1002 You can use them without configuration.
1005 (apply 'concat
(anything-c-format-preconfigured-anything))
1009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1011 (defun anything-mini ()
1012 "Preconfigured `anything' lightweight version (buffer -> recentf)."
1014 (anything-other-buffer '(anything-c-source-buffers+ anything-c-source-recentf
)
1017 (defun anything-for-files ()
1018 "Preconfigured `anything' for opening files.
1019 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
1021 (anything-other-buffer anything-for-files-prefered-list
"*anything for files*"))
1024 (defun anything-recentf ()
1025 "Preconfigured `anything' for `recentf'."
1027 (anything-other-buffer 'anything-c-source-recentf
"*anything recentf*"))
1030 (defun anything-info-at-point ()
1031 "Preconfigured `anything' for searching info at point."
1033 (anything '(anything-c-source-info-elisp
1034 anything-c-source-info-cl
1035 anything-c-source-info-pages
)
1036 (thing-at-point 'symbol
) nil nil nil
"*anything info*"))
1039 (defun anything-info-emacs ()
1040 "Preconfigured anything for Emacs manual index."
1042 (anything-other-buffer 'anything-c-source-info-emacs
"*info emacs*"))
1045 (defun anything-show-kill-ring ()
1046 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
1047 You may bind this command to M-y."
1049 (anything-other-buffer 'anything-c-source-kill-ring
"*anything kill-ring*"))
1052 (defun anything-minibuffer-history ()
1053 "Preconfigured `anything' for `minibuffer-history'."
1055 (let ((enable-recursive-minibuffers t
))
1056 (anything-other-buffer 'anything-c-source-minibuffer-history
1057 "*anything minibuffer-history*")))
1060 (defun anything-gentoo ()
1061 "Preconfigured `anything' for gentoo linux."
1063 (anything-other-buffer '(anything-c-source-gentoo
1064 anything-c-source-use-flags
)
1065 "*anything gentoo*"))
1068 (defun anything-imenu ()
1069 "Preconfigured `anything' for `imenu'."
1071 (anything 'anything-c-source-imenu nil nil nil nil
"*anything imenu*"))
1074 (defun anything-google-suggest ()
1075 "Preconfigured `anything' for google search with google suggest."
1077 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
1080 (defun anything-yahoo-suggest ()
1081 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
1083 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
1085 ;;; Converted from anything-show-*-only
1087 (defun anything-for-buffers ()
1088 "Preconfigured `anything' for buffer."
1090 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
1093 (defun anything-buffers+ ()
1094 "Enhanced preconfigured `anything' for buffer."
1096 (anything-other-buffer 'anything-c-source-buffers
+ "*anything buffers*"))
1099 (defun anything-bbdb ()
1100 "Preconfigured `anything' for BBDB.
1104 http://bbdb.sourceforge.net/"
1106 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
1109 (defun anything-locate ()
1110 "Preconfigured `anything' for Locate.
1111 Note you can add locate command after entering pattern.
1112 See man locate for more infos."
1114 (anything-other-buffer 'anything-c-source-locate
"*anything locate*"))
1117 (defun anything-w3m-bookmarks ()
1118 "Preconfigured `anything' for w3m bookmark.
1120 Needs w3m and emacs-w3m.
1122 http://w3m.sourceforge.net/
1123 http://emacs-w3m.namazu.org/"
1125 (anything-other-buffer 'anything-c-source-w3m-bookmarks
1126 "*anything w3m bookmarks*"))
1129 (defun anything-firefox-bookmarks ()
1130 "Preconfigured `anything' for firefox bookmark.
1131 You will have to enable html bookmarks in firefox:
1132 open about:config in firefox and double click on this line to enable value \
1135 user_pref(\"browser.bookmarks.autoExportHTML\", false);
1137 You should have now:
1139 user_pref(\"browser.bookmarks.autoExportHTML\", true);
1141 After closing firefox, you will be able to browse you bookmarks.
1144 (anything-other-buffer 'anything-c-source-firefox-bookmarks
1145 "*Anything Firefox*"))
1148 (defun anything-colors ()
1149 "Preconfigured `anything' for color."
1151 (anything-other-buffer
1152 '(anything-c-source-colors anything-c-source-customize-face
)
1153 "*anything colors*"))
1156 (defun anything-bookmarks ()
1157 "Preconfigured `anything' for bookmarks."
1159 (anything-other-buffer 'anything-c-source-bookmarks
"*anything bookmarks*"))
1162 (defun anything-c-pp-bookmarks ()
1163 "Preconfigured `anything' for bookmarks (pretty-printed)."
1165 (anything-other-buffer '(anything-c-source-bookmarks-local
1166 anything-c-source-bookmarks-su
1167 anything-c-source-bookmarks-ssh
)
1168 "*anything pp bookmarks*"))
1171 (defun anything-c-insert-latex-math ()
1172 "Preconfigured anything for latex math symbols completion."
1174 (anything-other-buffer 'anything-c-source-latex-math
"*anything latex*"))
1177 (defun anything-register ()
1178 "Preconfigured `anything' for Emacs registers."
1180 (anything-other-buffer 'anything-c-source-register
"*anything register*"))
1183 (defun anything-man-woman ()
1184 "Preconfigured `anything' for Man and Woman pages."
1186 (anything-other-buffer 'anything-c-source-man-pages
"*Anything man woman*"))
1189 (defun anything-org-keywords ()
1190 "Preconfigured `anything' for org keywords."
1192 (anything-other-buffer 'anything-c-source-org-keywords
"*org keywords*"))
1195 (defun anything-emms ()
1196 "Preconfigured `anything' for emms sources."
1198 (anything '(anything-c-source-emms-streams
1199 anything-c-source-emms-files
1200 anything-c-source-emms-dired
)
1205 (defun anything-eev-anchors ()
1206 "Preconfigured `anything' for eev anchors."
1208 (anything-other-buffer 'anything-c-source-eev-anchor
"*Anything eev anchors*"))
1211 (defun anything-bm-list ()
1212 "Preconfigured `anything' for visible bookmarks.
1216 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
1218 (let ((anything-outline-using t
))
1219 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*")))
1222 (defun anything-timers ()
1223 "Preconfigured `anything' for timers."
1225 (anything-other-buffer '(anything-c-source-absolute-time-timers
1226 anything-c-source-idle-time-timers
)
1227 "*anything timers*"))
1230 (defun anything-list-emacs-process ()
1231 "Preconfigured `anything' for emacs process."
1233 (anything-other-buffer 'anything-c-source-emacs-process
"*anything process*"))
1236 (defun anything-occur ()
1237 "Preconfigured Anything for Occur source."
1239 (let ((anything-compile-source-functions
1240 ;; rule out anything-match-plugin because the input is one regexp.
1241 (delq 'anything-compile-source--match-plugin
1242 (copy-sequence anything-compile-source-functions
))))
1243 (anything-other-buffer 'anything-c-source-occur
"*Anything Occur*")))
1246 (defun anything-browse-code ()
1247 "Preconfigured anything to browse code."
1249 (anything-other-buffer 'anything-c-source-browse-code
"*Browse code*"))
1252 (defun anything-org-headlines ()
1253 "Preconfigured anything to show org headlines."
1255 (anything-other-buffer 'anything-c-source-org-headline
"*org headlines*"))
1257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1260 (defun anything-kill-buffers ()
1261 "Preconfigured `anything' to kill buffer you selected."
1264 '(((name .
"Kill Buffers")
1265 (candidates . anything-c-buffer-list
)
1267 ("Kill Buffer" .
(lambda (candidate)
1268 (kill-buffer candidate
)
1269 (anything-kill-buffers)
1274 (defun anything-c-query-replace-regexp (candidate)
1275 (let ((regexp (funcall (anything-attr 'regexp
))))
1276 (apply 'query-replace-regexp
1277 (anything-c-query-replace-args regexp
))))
1279 (defun anything-c-kill-regexp-as-sexp (candidate)
1280 (anything-c-regexp-kill-new
1281 (prin1-to-string (funcall (anything-attr 'regexp
)))))
1283 (defun anything-c-kill-regexp (candidate)
1284 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp
))))
1286 (defun anything-c-query-replace-args (regexp)
1287 "create arguments of `query-replace-regexp' action in `anything-regexp'."
1288 (let ((region-only (anything-region-active-p)))
1291 (query-replace-read-to regexp
1292 (format "Query replace %s regexp %s"
1293 (if anything-current-prefix-arg
"word " "")
1294 (if region-only
"in region " ""))
1296 anything-current-prefix-arg
1297 (when region-only
(region-beginning))
1298 (when region-only
(region-end)))))
1300 (defvar anything-c-source-regexp
1301 '((name .
"Regexp Builder")
1303 (anything-candidate-buffer anything-current-buffer
)))
1304 (candidates-in-buffer)
1305 (get-line . anything-c-regexp-get-line
)
1306 (persistent-action . anything-c-regexp-persistent-action
)
1307 (persistent-help .
"Show this line")
1310 (requires-pattern .
2)
1311 (mode-line .
"Press TAB to select action.")
1313 ;; I use here `anything-input' because `anything-pattern' is lost when
1314 ;; using actions from action buffer (otherwise no e.g from RET, C-e or C-j).
1315 ;; It seem `anything-select-action' reset `anything-pattern' to empty too early.
1316 ;; Though the regexp attribute stay defined (tested with *-attr-defined).
1318 (regexp .
(lambda () anything-input
))
1319 (action .
(("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp
)
1320 ("Query Replace Regexp" . anything-c-query-replace-regexp
)
1321 ("Kill Regexp" . anything-c-kill-regexp
)))))
1323 (defun anything-c-regexp-get-line (s e
)
1327 (format "%5d: %s" (line-number-at-pos (1- s
)) (buffer-substring s e
))
1329 (loop for i from
0 to
(1- (/ (length (match-data)) 2))
1330 collect
(format "\n %s'%s'"
1331 (if (zerop i
) "Group 0: " (format "Group %d: " i
))
1334 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
1335 ;; It is implementation problem of candidates-in-buffer.
1339 (defun anything-goto-line (lineno)
1340 "Goto LINENO without modifying outline visibility if needed."
1341 (flet ((gotoline (numline)
1342 (goto-char (point-min)) (forward-line (1- numline
))))
1343 (if (or (eq major-mode
'org-mode
)
1348 (gotoline lineno
))))
1350 (defun anything-c-regexp-persistent-action (pt)
1352 (anything-persistent-highlight-point))
1354 (defun anything-c-regexp-kill-new (input)
1356 (message "Killed: %s" input
))
1358 (defun anything-region-active-p ()
1359 (and transient-mark-mode mark-active
(/= (mark) (point))))
1361 (defun* anything-current-buffer-narrowed-p
(&optional
1362 (buffer anything-current-buffer
))
1363 "Check if BUFFER is narrowed.
1364 Default is `anything-current-buffer'."
1365 (with-current-buffer buffer
1366 (let ((beg (point-min))
1368 (total (buffer-size)))
1369 (or (/= beg
1) (/= end
(1+ total
))))))
1372 (defun anything-regexp ()
1373 "Preconfigured anything to build regexps and run query-replace-regexp \
1377 (let ((anything-compile-source-functions
1378 ;; rule out anything-match-plugin because the input is one regexp.
1379 (delq 'anything-compile-source--match-plugin
1380 (copy-sequence anything-compile-source-functions
))))
1381 (when (and (anything-region-active-p)
1382 ;; Don't narrow to region if buffer is already narrowed.
1383 (not (anything-current-buffer-narrowed-p)))
1384 (narrow-to-region (region-beginning) (region-end)))
1386 anything-c-source-regexp
1387 :buffer
"*anything regexp*"
1388 :prompt
"Regexp: "))))
1391 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1393 (defun anything-insert-buffer-name ()
1394 "Insert buffer name."
1396 (anything-insert-string
1397 (with-current-buffer anything-current-buffer
1398 (if buffer-file-name
(file-name-nondirectory buffer-file-name
)
1401 (defun anything-insert-symbol ()
1402 "Insert current symbol."
1404 (anything-insert-string
1405 (with-current-buffer anything-current-buffer
1407 (buffer-substring (beginning-of-thing 'symbol
)
1408 (end-of-thing 'symbol
))))))
1410 (defun anything-insert-selection ()
1411 "Insert current selection."
1413 (anything-insert-string
1414 (with-current-buffer anything-current-buffer
1415 (anything-get-selection))))
1417 (defun anything-show-buffer-only ()
1418 "[OBSOLETE] Only show sources about buffer.
1419 Use `anything-for-buffers' instead."
1421 (anything-set-source-filter '("Buffers")))
1423 (defun anything-show-bbdb-only ()
1424 "[OBSOLETE] Only show sources about BBDB.
1425 Use `anything-bbdb' instead."
1427 (anything-set-source-filter '("BBDB")))
1429 (defun anything-show-locate-only ()
1430 "[OBSOLETE] Only show sources about Locate.
1431 Use `anything-locate' instead."
1433 (anything-set-source-filter '("Locate")))
1435 (defun anything-show-info-only ()
1436 "[OBSOLETE] Only show sources about Info.
1437 Use `anything-info-at-point' instead."
1439 (anything-set-source-filter '("Info Pages"
1441 "Info Common-Lisp")))
1443 (defun anything-show-imenu-only ()
1444 "[OBSOLETE] Only show sources about Imenu.
1445 Use `anything-imenu' instead."
1447 (anything-set-source-filter '("Imenu")))
1449 (defun anything-show-files-only ()
1450 "[OBSOLETE] Only show sources about File.
1451 Use `anything-for-files' instead."
1453 (anything-set-source-filter '("File Name History"
1454 "Files from Current Directory"
1457 (defun anything-show-w3m-bookmarks-only ()
1458 "[OBSOLETE] Only show source about w3m bookmark.
1459 Use `anything-w3m-bookmarks' instead."
1461 (anything-set-source-filter '("W3m Bookmarks")))
1463 (defun anything-show-colors-only ()
1464 "[OBSOLETE] Only show source about color.
1465 Use `anything-colors' instead."
1467 (anything-set-source-filter '("Colors"
1468 "Customize Faces")))
1470 (defun anything-show-kill-ring-only ()
1471 "[OBSOLETE] Only show source about kill ring.
1472 Use `anything-show-kill-ring' instead."
1474 (anything-set-source-filter '("Kill Ring")))
1476 (defun anything-show-this-source-only ()
1477 "Only show this source."
1479 (setq anything-candidate-number-limit
9999)
1480 (anything-set-source-filter
1481 (list (assoc-default 'name
(anything-get-current-source)))))
1483 (defun anything-test-sources ()
1484 "List all anything sources for test.
1485 The output is sexps which are evaluated by \\[eval-last-sexp]."
1487 (with-output-to-temp-buffer "*Anything Test Sources*"
1488 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s
)))
1489 (apropos-internal "^anything-c-source" #'boundp
))
1490 (pop-to-buffer standard-output
)))
1492 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1493 ;;; For compatibility
1494 (unless (fboundp 'region-active-p
)
1495 (defun region-active-p ()
1496 "Return t if Transient Mark mode is enabled and the mark is active.
1498 Most commands that act on the region if it is active and
1499 Transient Mark mode is enabled, and on the text near point
1500 otherwise, should use `use-region-p' instead. That function
1501 checks the value of `use-empty-active-region' as well."
1502 (and transient-mark-mode mark-active
)))
1504 (defun anything-nest (&rest same-as-anything
)
1505 "Nested `anything'. If you use `anything' within `anything', use it."
1506 (with-selected-window (anything-window)
1507 (let (anything-current-position
1508 anything-current-buffer
1509 (orig-anything-buffer anything-buffer
)
1513 anything-compiled-sources
1514 anything-buffer-chars-modified-tick
1515 (anything-samewindow t
)
1516 (enable-recursive-minibuffers t
))
1518 (apply #'anything same-as-anything
)
1519 (anything-initialize-overlays orig-anything-buffer
)
1520 (add-hook 'post-command-hook
'anything-check-minibuffer-input
)))))
1522 (defun anything-displaying-source-names ()
1523 "Display sources name."
1524 (with-current-buffer anything-buffer
1525 (goto-char (point-min))
1527 while
(setq pos
(next-single-property-change (point) 'anything-header
))
1529 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
1530 do
(forward-line 1))))
1532 (defun anything-select-source ()
1535 (let ((default (assoc-default 'name
(anything-get-current-source)))
1536 (source-names (anything-displaying-source-names))
1537 (all-source-names (mapcar (lambda (s) (assoc-default 'name s
))
1538 (anything-get-sources))))
1539 (setq anything-candidate-number-limit
9999)
1541 (let (anything-source-filter)
1542 (anything-nest '(((name .
"Anything Source")
1543 (candidates . source-names
)
1544 (action . identity
))
1545 ((name .
"Anything Source (ALL)")
1546 (candidates . all-source-names
)
1547 (action . identity
)))
1549 default
"*anything select source*"))
1550 (anything-set-source-filter (list it
))
1551 (anything-set-source-filter nil
))))
1553 (defun anything-insert-string (str)
1555 (delete-minibuffer-contents)
1558 (defun anything-c-match-on-file-name (candidate)
1559 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1560 (string-match anything-pattern
(file-name-nondirectory candidate
)))
1562 (defun anything-c-match-on-directory-name (candidate)
1563 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1564 (anything-aif (file-name-directory candidate
)
1565 (string-match anything-pattern it
)))
1567 (defun anything-c-string-match (candidate)
1568 "Return non-nil if `anything-pattern' match CANDIDATE.
1569 The match is done with `string-match'."
1570 (string-match anything-pattern candidate
))
1572 ;; `anything-c-compose' is no more needed, it is for compatibility.
1573 (defalias 'anything-c-compose
'anything-compose
)
1575 (defun anything-c-skip-entries (list regexp
)
1576 "Remove entries which matches REGEXP from LIST."
1577 (remove-if (lambda (x) (and (stringp x
) (string-match regexp x
)))
1580 (defun anything-c-shadow-entries (list regexp
)
1581 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1582 (mapcar (lambda (file)
1583 ;; Add shadow face property to boring files.
1584 (let ((face (if (facep 'file-name-shadow
)
1586 ;; fall back to default on XEmacs
1588 (if (string-match regexp file
)
1589 (setq file
(propertize file
'face face
))))
1593 (defsubst anything-c-stringify
(str-or-sym)
1594 "Get string of STR-OR-SYM."
1595 (if (stringp str-or-sym
)
1597 (symbol-name str-or-sym
)))
1599 (defsubst anything-c-symbolify
(str-or-sym)
1600 "Get symbol of STR-OR-SYM."
1601 (if (symbolp str-or-sym
)
1603 (intern str-or-sym
)))
1605 (defun anything-c-describe-function (func)
1606 "FUNC is symbol or string."
1607 (describe-function (anything-c-symbolify func
)))
1609 (defun anything-c-describe-variable (var)
1610 "VAR is symbol or string."
1611 (describe-variable (anything-c-symbolify var
)))
1613 (defun anything-c-find-function (func)
1614 "FUNC is symbol or string."
1615 (find-function (anything-c-symbolify func
)))
1617 (defun anything-c-find-variable (var)
1618 "VAR is symbol or string."
1619 (find-variable (anything-c-symbolify var
)))
1621 (defun anything-c-kill-new (string &optional replace yank-handler
)
1622 "STRING is symbol or string."
1623 (kill-new (anything-c-stringify string
) replace yank-handler
))
1625 ;;; Toggle all marks.
1627 (defun anything-mark-all ()
1628 "Mark all visible unmarked candidates in current source."
1629 (with-anything-window
1631 (goto-char (anything-get-previous-header-pos))
1632 (anything-next-line)
1633 (let* ((next-head (anything-get-next-header-pos))
1636 (goto-char next-head
)
1639 (maxpoint (or end
(point-max))))
1640 (while (< (point) maxpoint
)
1641 (let ((prefix (get-text-property (point-at-bol) 'display
)))
1642 (when (and (not (anything-this-visible-mark))
1643 (not (or (string= prefix
"[?]")
1644 (string= prefix
"[@]"))))
1645 ;; FIXME: This is a bug in `anything-make-visible-mark'
1646 ;; it should not assume that overlay is on line and
1647 ;; BTW not use `anything-get-selection' to get
1648 ;; the real value of candidate.
1649 ;; So for the moment just mark this line.
1650 (anything-mark-current-line)
1651 ;; Don't mark possibles directories ending with . or ..
1652 (unless (string-match "\\.$" (anything-get-selection))
1653 (anything-make-visible-mark))))
1654 (forward-line 1) (end-of-line))))
1655 (anything-mark-current-line)
1656 (message "%s candidates marked" (length anything-marked-candidates
))))
1658 (defun anything-unmark-all ()
1659 "Unmark all candidates in all sources of current anything session."
1660 (with-anything-window
1661 (let ((len (length anything-marked-candidates
)))
1663 (anything-clear-visible-mark))
1664 (setq anything-marked-candidates nil
)
1665 (anything-mark-current-line)
1666 (message "%s candidates unmarked" len
))))
1668 (defun anything-toggle-all-marks ()
1670 Mark all visible candidates of current source or unmark all candidates
1671 visible or invisible in all sources of current anything session"
1673 (let ((marked (anything-marked-candidates)))
1674 (if (and (>= (length marked
) 1)
1675 (with-anything-window anything-visible-mark-overlays
))
1676 (anything-unmark-all)
1677 (anything-mark-all))))
1679 (define-key anything-map
(kbd "M-m") 'anything-toggle-all-marks
)
1681 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1682 (defadvice eval-defun
(after anything-source-hack activate
)
1683 "See `anything-c-enable-eval-defun-hack'."
1684 (when anything-c-enable-eval-defun-hack
1685 (let ((varsym (save-excursion
1686 (beginning-of-defun)
1688 (when (memq (read (current-buffer)) '(defvar setq
))
1689 (read (current-buffer))))))
1690 (when (string-match "^anything-c-source-" (symbol-name varsym
))
1691 (anything varsym
)))))
1692 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1694 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1695 (defconst anything-c-create-summary-index-regexp
1696 "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$")
1697 (defun anything-c-create-summary ()
1698 "Create `anything' summary."
1700 (goto-char (point-min))
1702 while
(re-search-forward anything-c-create-summary-index-regexp nil t
)
1704 (cond ((setq it
(match-string-no-properties 1))
1706 ((setq it
(match-string-no-properties 2))
1708 ,(assoc-default 'name
(symbol-value (intern it
)))))
1709 ((setq it
(match-string-no-properties 3))
1711 ,(assoc-default 'name
(symbol-value (intern it
)))))))))
1713 ;; (find-epp (anything-c-create-summary))
1715 (defun anything-c-insert-summary ()
1716 "Insert `anything' summary."
1718 (goto-char (point-min))
1719 (search-forward ";; Below are complete source list you can setup in")
1721 (delete-region (point)
1722 (progn (search-forward ";;; Change log:" nil t
)
1723 (forward-line -
1) (point)))
1726 for
(kind . value
) in
(anything-c-create-summary)
1728 do
(cond ((eq kind
'section
)
1730 (align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))
1731 (insert ";; " value
":\n")
1734 (insert ";; `" (car value
) "' (" (cdr value
) ")\n")))
1735 finally
(align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))))
1736 ;; (anything-c-insert-summary)
1738 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1740 (defun anything-c-buffer-list ()
1741 "Return the list of names of buffers with boring buffers filtered out.
1742 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1743 The first buffer in the list will be the last recently used
1744 buffer that is not the current buffer."
1745 (let ((buffers (mapcar 'buffer-name
(buffer-list))))
1746 (append (cdr buffers
) (list (car buffers
)))))
1748 (defvar anything-c-source-buffers
1749 '((name .
"Buffers")
1750 (candidates . anything-c-buffer-list
)
1752 ;; (anything 'anything-c-source-buffers)
1754 (defvar anything-c-source-buffer-not-found
1755 '((name .
"Create buffer")
1758 ;; (anything 'anything-c-source-buffer-not-found)
1761 (defface anything-dir-heading
'((t (:foreground
"Blue" :background
"Pink")))
1762 "*Face used for directory headings in dired buffers."
1765 (defface anything-file-name
1766 '((t (:foreground
"Blue")))
1767 "*Face used for file names (without suffixes) in dired buffers."
1770 (defface anything-dir-priv
1771 '((t (:foreground
"DarkRed" :background
"LightGray")))
1772 "*Face used for directory privilege indicator (d) in dired buffers."
1775 (defvar anything-c-buffers-face1
'anything-dir-priv
)
1776 (defvar anything-c-buffers-face2
'font-lock-type-face
)
1777 (defvar anything-c-buffers-face3
'italic
)
1778 (eval-when-compile (require 'dired
))
1779 (defun anything-c-highlight-buffers (buffers)
1781 (loop for i in buffers
1782 if
(rassoc (get-buffer i
) dired-buffers
)
1783 collect
(propertize i
1784 'face anything-c-buffers-face1
1785 'help-echo
(car (rassoc (get-buffer i
) dired-buffers
)))
1786 if
(buffer-file-name (get-buffer i
))
1787 collect
(propertize i
1788 'face anything-c-buffers-face2
1789 'help-echo
(buffer-file-name (get-buffer i
)))
1790 if
(and (not (rassoc (get-buffer i
) dired-buffers
))
1791 (not (buffer-file-name (get-buffer i
))))
1792 collect
(propertize i
1793 'face anything-c-buffers-face3
)))
1795 (defvar anything-c-source-buffers
+
1796 '((name .
"Buffers")
1797 (candidates . anything-c-buffer-list
)
1799 (candidate-transformer anything-c-skip-current-buffer
1800 anything-c-highlight-buffers
1801 anything-c-skip-boring-buffers
)
1802 (persistent-action . anything-c-buffers
+-persistent-action
)
1803 (persistent-help .
"Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1805 (defun anything-c-buffers+-persistent-action
(name)
1807 (with-current-buffer item
1808 (if (and (buffer-modified-p)
1809 (buffer-file-name (current-buffer)))
1813 (kill-buffer item
))))
1815 (switch-to-buffer item
)))
1816 (if current-prefix-arg
1819 (anything-delete-current-selection))
1822 ;; (anything 'anything-c-source-buffers+)
1824 (defadvice anything-quit-and-find-file
(around use-anything-find-files activate
)
1825 "Let `anything-quit-and-find-file' take advantage of `anything-find-files'."
1827 (anything-run-after-quit
1829 (anything-find-files1 f
))
1830 (anything-aif (get-buffer (anything-get-selection))
1831 (or (buffer-file-name it
)
1832 (car (rassoc it dired-buffers
))
1833 (and (with-current-buffer it
1834 (eq major-mode
'org-agenda-mode
))
1836 (expand-file-name org-directory
))
1838 (let ((sel (anything-get-selection)))
1839 (if (file-exists-p sel
)
1840 (expand-file-name sel
)
1841 default-directory
)))))
1844 ;;; File name history
1845 (defvar anything-c-source-file-name-history
1846 '((name .
"File Name History")
1847 (candidates . file-name-history
)
1848 (match anything-c-match-on-file-name
1849 anything-c-match-on-directory-name
)
1851 ;; (anything 'anything-c-source-file-name-history)
1853 ;;; Files in current dir
1854 (defvar anything-c-source-files-in-current-dir
1855 '((name .
"Files from Current Directory")
1856 (candidates .
(lambda ()
1857 (with-current-buffer anything-current-buffer
1858 (directory-files (anything-c-current-directory)))))
1859 ;; volatile is not needed, I think.
1861 ;; (anything 'anything-c-source-files-in-current-dir)
1863 (defvar anything-c-files-face1
'anything-dir-priv
)
1864 (defvar anything-c-files-face2
'anything-file-name
)
1865 (defun anything-c-highlight-files (files)
1866 (loop for i in files
1867 if
(file-directory-p i
)
1868 collect
(propertize (file-name-nondirectory i
)
1869 'face anything-c-files-face1
1870 'help-echo
(expand-file-name i
))
1872 collect
(propertize (file-name-nondirectory i
)
1873 'face anything-c-files-face2
1874 'help-echo
(expand-file-name i
))))
1877 (defvar anything-c-source-files-in-current-dir
+
1878 '((name .
"Files from Current Directory")
1879 (candidates .
(lambda ()
1880 (with-current-buffer anything-current-buffer
1881 (directory-files (anything-c-current-directory) t
))))
1882 (candidate-transformer anything-c-highlight-files
)
1883 ;; volatile is not needed, I think.
1886 ;; (anything 'anything-c-source-files-in-current-dir+)
1888 ;;; Anything replacement of file name completion for `find-file' and friends.
1890 (defvar anything-c-find-files-doc-header
(format " (`%s':Go to precedent level)"
1891 (if window-system
"C-." "C-l"))
1892 "*The doc that is inserted in the Name header of a find-files or dired source.")
1894 (defvar anything-c-source-find-files
1895 `((name .
,(concat "Find Files" anything-c-find-files-doc-header
))
1896 ;; It is needed for filenames with capital letters
1899 (setq ffap-newfile-prompt t
)
1900 ;; This is needed when connecting with emacsclient -t
1901 ;; on remote host that have an anything started on a window-system.
1902 ;; i.e when `C-.' is already loaded.
1903 (unless window-system
1904 (define-key anything-map
(kbd "C-l") 'anything-find-files-down-one-level
))))
1905 (candidates . anything-find-files-get-candidates
)
1906 (filtered-candidate-transformer anything-c-find-files-transformer
)
1907 (image-action1 . anything-ff-rotate-image-left
)
1908 (image-action2 . anything-ff-rotate-image-right
)
1909 (persistent-action . anything-find-files-persistent-action
)
1910 (persistent-help .
"Hit1 Expand Candidate, Hit2 or (C-u) Find file")
1912 (candidate-number-limit .
9999)
1913 (action-transformer . anything-find-files-action-transformer
)
1917 `(("Find File" . anything-c-find-file-or-marked
)
1918 ("Find file in Dired" . anything-c-point-file-in-dired
)
1919 ,(and (locate-library "elscreen")
1920 '("Find file in Elscreen" . anything-elscreen-find-file
))
1921 ("Complete at point"
1922 . anything-c-insert-file-name-completion-at-point
)
1923 ("Open file externally `C-u to choose'"
1924 . anything-c-open-file-externally
)
1925 ("Grep File(s) `C-u Recurse'" . anything-find-files-grep
)
1926 ("Switch to Eshell" . anything-ff-switch-to-eshell
)
1927 ("Eshell command on file(s)"
1928 . anything-find-files-eshell-command-on-file
)
1929 ("Ediff File" . anything-find-files-ediff-files
)
1930 ("Ediff Merge File" . anything-find-files-ediff-merge-files
)
1931 ("Delete File(s)" . anything-delete-marked-files
)
1932 ("Copy file(s) `C-u to follow'" . anything-find-files-copy
)
1933 ("Rename file(s) `C-u to follow'" . anything-find-files-rename
)
1934 ("Symlink files(s) `C-u to follow'" . anything-find-files-symlink
)
1935 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink
)
1936 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink
)
1937 ("Find file other window" . find-file-other-window
)
1938 ("Find file other frame" . find-file-other-frame
)
1939 ("Find file as root" . anything-find-file-as-root
))))))
1940 ;; (anything 'anything-c-source-find-files)
1942 (defun anything-find-files-set-prompt-for-action (prompt files
)
1943 "Set prompt for action in `anything-find-files'."
1944 (let ((len (length files
)))
1946 (format "%s * %d Files to: " prompt len
)
1947 (format "%s %s to: " prompt
(car files
)))))
1949 (defun anything-find-files-do-action (action)
1950 "Generic function for creating action from `anything-c-source-find-files'.
1951 ACTION must be an action supported by `anything-dired-action'."
1952 (let* ((ifiles (anything-marked-candidates))
1953 (buf anything-current-buffer
)
1954 (prompt (anything-find-files-set-prompt-for-action
1955 (capitalize (symbol-name action
)) ifiles
))
1956 (parg anything-current-prefix-arg
)
1957 (dest (anything-c-read-file-name
1959 :initial-input
(car anything-ff-history
)
1960 :history
(anything-find-files-history :comp-read nil
)))
1961 (win-conf (current-window-configuration)))
1963 ;; Create temporarily a dired buffer to call dired functions.
1964 (with-current-buffer (dired anything-ff-default-directory
)
1965 (let ((dir-buf (current-buffer)))
1966 (anything-dired-action
1967 dest
:files ifiles
:action action
:follow parg
)
1968 ;; If we have started in a dired buffer, don't kill it.
1969 (unless (eq dir-buf
(get-buffer buf
))
1970 (kill-buffer dir-buf
))))
1971 (unless parg
(set-window-configuration win-conf
)))))
1973 (defun anything-find-files-copy (candidate)
1974 "Copy files from `anything-find-files'."
1975 (anything-find-files-do-action 'copy
))
1977 (defun anything-find-files-rename (candidate)
1978 "Rename files from `anything-find-files'."
1979 (anything-find-files-do-action 'rename
))
1981 (defun anything-find-files-symlink (candidate)
1982 "Symlink files from `anything-find-files'."
1983 (anything-find-files-do-action 'symlink
))
1985 (defun anything-find-files-relsymlink (candidate)
1986 "Relsymlink files from `anything-find-files'."
1987 (anything-find-files-do-action 'relsymlink
))
1989 (defun anything-find-files-hardlink (candidate)
1990 "Hardlink files from `anything-find-files'."
1991 (anything-find-files-do-action 'hardlink
))
1993 (defun anything-find-files-byte-compile (candidate)
1994 "Byte compile elisp files from `anything-find-files'."
1995 (let ((files (anything-marked-candidates))
1996 (parg anything-current-prefix-arg
))
1997 (loop for fname in files
1998 do
(byte-compile-file fname parg
))))
2000 (defun anything-find-files-load-files (candidate)
2001 "Load elisp files from `anything-find-files'."
2002 (let ((files (anything-marked-candidates)))
2003 (loop for fname in files
2006 (defun anything-find-files-ediff-files (candidate)
2007 "Default action to ediff files in `anything-find-files'."
2010 (anything-c-read-file-name
2011 (format "Ediff `%s' With File: " (file-name-nondirectory candidate
)))))
2013 (defun anything-find-files-ediff-merge-files (candidate)
2014 "Default action to ediff merge files in `anything-find-files'."
2017 (anything-c-read-file-name
2018 (format "Ediff Merge `%s' With File: "
2019 (file-name-nondirectory candidate
)))))
2021 (defun anything-find-files-grep (candidate)
2022 "Default action to grep files from `anything-find-files'."
2023 (if anything-current-prefix-arg
2024 (anything-do-grep1 (anything-marked-candidates) 'recurse
)
2025 (anything-do-grep1 (anything-marked-candidates))))
2027 (defvar eshell-command-aliases-list nil
)
2028 (declare-function eshell-read-aliases-list
"em-alias")
2029 (defun anything-find-files-eshell-command-on-file (candidate)
2030 "Run `eshell-command' on file CANDIDATE possibly with an eshell alias.
2032 If `eshell' or `eshell-command' have not been run once, `eshell-command-aliases-list'
2033 will not be loaded first time you use this."
2034 (when (or eshell-command-aliases-list
2035 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
2036 (and eshell-command-aliases-list
(eshell-read-aliases-list))
2037 (let ((cand-list (anything-marked-candidates))
2038 (default-directory anything-ff-default-directory
)
2039 (command (anything-comp-read
2041 (loop for
(a . c
) in eshell-command-aliases-list
2042 when
(string-match "\\$1$" (car c
))
2046 for com
= (concat command
" " (shell-quote-argument i
))
2047 do
(eshell-command com
)))))
2050 (declare-function eshell-send-input
"esh-mode" (&optional use-region queue-p no-newline
))
2051 (defun anything-ff-switch-to-eshell (candidate)
2052 "Switch to eshell and cd to `anything-ff-default-directory'."
2053 (flet ((cd-eshell ()
2054 (goto-char (point-max))
2056 (format "cd %s" (shell-quote-argument
2057 anything-ff-default-directory
)))
2058 (eshell-send-input)))
2059 (if (get-buffer "*eshell*")
2061 (switch-to-buffer "*eshell*")
2063 (call-interactively 'eshell
)
2066 (defun* anything-reduce-file-name
(fname level
&key unix-close expand
)
2067 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
2068 If LEVEL is positive reduce from end else from beginning.
2069 If UNIX-CLOSE is non--nil close filename with /.
2070 If EXPAND is non--nil expand-file-name."
2071 (let* ((exp-fname (expand-file-name fname
))
2072 (fname-list (split-string (if (or (string= fname
"~/") expand
)
2073 exp-fname fname
) "/" t
))
2074 (len (length fname-list
))
2075 (pop-list (if (< level
0)
2076 (subseq fname-list
(* level -
1))
2077 (subseq fname-list
0 (- len level
))))
2078 (result (mapconcat 'identity pop-list
"/"))
2079 (empty (string= result
"")))
2080 (when unix-close
(setq result
(concat result
"/")))
2081 (if (string-match "^~" result
)
2082 (if (string= result
"~/") "~/" result
)
2084 (if empty
"../" (concat "../" result
))
2085 (cond ((eq system-type
'windows-nt
)
2086 (if empty
"c:/" result
))
2089 (concat "/" result
)))))))
2091 (defun anything-file-completion-source-p ()
2092 "Test if current source is a dired or find-files source."
2093 (let ((ff-sources '("Find Files" "Copy Files"
2094 "Read File Name History"
2095 "Rename Files" "Symlink Files"
2096 "Hardlink Files" "Write File"
2097 "Insert File" "Read file name"))
2098 (cur-source (cdr (assoc 'name
(anything-get-current-source)))))
2099 (loop for i in ff-sources
2100 thereis
(string= cur-source
(concat i anything-c-find-files-doc-header
)))))
2103 (defvar anything-ff-last-expanded nil
2104 "Store last expanded directory or file in `anything-find-files'.")
2106 (defun anything-find-files-down-one-level (arg)
2107 "Go down one level like unix command `cd ..'.
2108 If prefix numeric arg is given go ARG level down."
2110 ;; When going to precedent level we want to be at the line
2111 ;; corresponding to actual directory, so store this info
2112 ;; in `anything-ff-last-expanded'.
2113 (if (and (not (file-directory-p anything-pattern
))
2114 (file-exists-p anything-pattern
))
2115 (setq anything-ff-last-expanded anything-pattern
)
2116 (setq anything-ff-last-expanded anything-ff-default-directory
))
2117 (when (anything-file-completion-source-p)
2118 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
2119 :unix-close t
:expand t
)))
2120 (with-selected-window (minibuffer-window)
2121 (delete-minibuffer-contents)
2122 (insert new-pattern
)))))
2124 (defun anything-ff-retrieve-last-expanded ()
2125 "Move overlay to last visited directory `anything-ff-last-expanded'.
2126 This happen after using `anything-find-files-down-one-level',
2127 or hitting C-z on \"..\"."
2128 (when (and anything-ff-last-expanded
2129 (anything-file-completion-source-p))
2130 (let ((dirname (directory-file-name anything-ff-last-expanded
)))
2131 (with-anything-window
2132 (when (or (re-search-forward (concat dirname
"$") nil t
)
2134 (concat anything-ff-last-expanded
"$") nil t
))
2136 (anything-mark-current-line)))
2137 (setq anything-ff-last-expanded nil
))))
2138 (add-hook 'anything-after-update-hook
'anything-ff-retrieve-last-expanded
)
2140 ;; `C-.' doesn't work in terms use `C-l' instead.
2142 (define-key anything-map
(kbd "C-.") 'anything-find-files-down-one-level
)
2143 (define-key anything-map
(kbd "C-l") 'anything-find-files-down-one-level
))
2145 (defun anything-c-point-file-in-dired (file)
2146 "Put point on filename FILE in dired buffer."
2147 (dired (file-name-directory file
))
2148 (dired-goto-file file
))
2150 (defun anything-create-tramp-name (fname)
2151 "Build filename for `anything-pattern' like /su:: or /sudo::."
2152 (apply #'tramp-make-tramp-file-name
2153 (loop with v
= (tramp-dissect-file-name fname
)
2154 for i across v collect i
)))
2156 (defun anything-ff-set-pattern (pattern)
2157 (let ((methods (mapcar 'car tramp-methods
))
2158 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
2159 cur-method tramp-name
)
2160 (cond ((string= pattern
"") "")
2161 ((string-match "^~" pattern
)
2162 (replace-match (getenv "HOME") nil t pattern
))
2163 ;; Match "/method:maybe_hostname:"
2164 ((and (string-match reg pattern
)
2165 (setq cur-method
(match-string 1 pattern
))
2166 (member cur-method methods
))
2167 (setq tramp-name
(anything-create-tramp-name
2168 (match-string 0 pattern
)))
2169 (replace-match tramp-name nil t pattern
))
2170 ;; Match "/hostname:"
2171 ((and (string-match tramp-file-name-regexp pattern
)
2172 (setq cur-method
(match-string 1 pattern
))
2173 (and cur-method
(not (member cur-method methods
))))
2174 (setq tramp-name
(anything-create-tramp-name
2175 (match-string 0 pattern
)))
2176 (replace-match tramp-name nil t pattern
))
2177 ;; Match "/method:" in this case don't try to connect.
2178 ((and (not (string-match reg pattern
))
2179 (string-match tramp-file-name-regexp pattern
)
2180 (member (match-string 1 pattern
) methods
))
2181 "Invalid tramp file name") ; Write in anything-buffer.
2182 ;; PATTERN is a directory, end it with "/".
2183 ;; This will make PATTERN not ending yet with "/"
2184 ;; candidate for `anything-ff-default-directory',
2185 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
2186 ;; when descending level.
2187 ((file-directory-p pattern
)
2188 (file-name-as-directory pattern
))
2189 ;; Return PATTERN unchanged.
2192 (defvar anything-ff-default-directory nil
)
2193 (defvar anything-ff-history nil
)
2194 (defvar anything-ff-history-max-length
30
2195 "*Number of elements shown in `anything-find-files' history.")
2196 (defun anything-find-files-get-candidates ()
2197 "Create candidate list for `anything-c-source-find-files'."
2198 (let* ((path (anything-ff-set-pattern anything-pattern
))
2199 (path-name-dir (file-name-directory path
))
2200 (tramp-verbose anything-tramp-verbose
)) ; No tramp message when 0.
2201 (set-text-properties 0 (length path
) nil path
)
2202 (if (member 'anything-compile-source--match-plugin
2203 anything-compile-source-functions
)
2204 (setq anything-pattern path
)
2205 (setq anything-pattern
(replace-regexp-in-string " " ".*" path
)))
2206 (setq anything-ff-default-directory
2207 (if (string= anything-pattern
"")
2208 (if (eq system-type
'windows-nt
) "c:/" "/")
2209 (unless (string-match ffap-url-regexp path
)
2211 (cond ((or (string= path
"Invalid tramp file name")
2212 (file-regular-p path
)
2213 (and (not (file-exists-p path
)) (string-match "/$" path
))
2214 (and ffap-url-regexp
(string-match ffap-url-regexp path
)))
2216 ((string= path
"") (directory-files "/" t
))
2217 ((and (file-directory-p path
) (not (file-readable-p path
)))
2218 (list (format "Opening directory: access denied, `%s'" path
)))
2219 ((file-directory-p path
) (directory-files path t
))
2223 (directory-files (file-name-directory path
) t
))))))
2225 (defun anything-ff-save-history ()
2226 "Store the last value of `anything-ff-default-directory' \
2227 in `anything-ff-history'."
2228 (when anything-ff-default-directory
2229 (push anything-ff-default-directory anything-ff-history
)))
2230 (add-hook 'anything-cleanup-hook
'anything-ff-save-history
)
2232 (defface anything-dired-symlink-face
2233 '((t (:foreground
"DarkOrange")))
2234 "*Face used for symlinks in `anything-find-files'."
2237 (defface anything-ffiles-prefix-face
2238 '((t (:background
"yellow" :foreground
"black")))
2239 "*Face used to prefix new file or url paths in `anything-find-files'."
2242 (defun* anything-ff-attributes
2243 (file &key type links uid gid access-time modif-time
2244 status size mode gid-change inode device-num dired
)
2245 "Easy interface for `file-attributes'."
2246 (let ((all (destructuring-bind
2247 (type links uid gid access-time modif-time
2248 status size mode gid-change inode device-num
)
2249 (file-attributes file
'string
)
2254 :access-time access-time
2255 :modif-time modif-time
2259 :gid-change gid-change
2261 :device-num device-num
))))
2263 (let ((result (getf all
:type
)))
2264 (cond ((stringp result
)
2266 (result "directory")
2268 (links (getf all
:links
))
2269 (uid (getf all
:uid
))
2270 (gid (getf all
:gid
))
2272 (format-time-string "%Y-%m-%d %R" (getf all
:access-time
)))
2274 (format-time-string "%Y-%m-%d %R" (getf all
:modif-time
)))
2276 (format-time-string "%Y-%m-%d %R" (getf all
:status
)))
2277 (size (getf all
:size
))
2278 (mode (getf all
:mode
))
2279 (gid-change (getf all
:gid-change
))
2280 (inode (getf all
:inode
))
2281 (device-num (getf all
:device-num
))
2284 (getf all
:mode
) " "
2285 (number-to-string (getf all
:links
)) " "
2288 (number-to-string (getf all
:size
)) " "
2289 (format-time-string "%Y-%m-%d %R" (getf all
:modif-time
))))
2292 (defun anything-c-prefix-filename (fname &optional image
)
2293 "Return fname FNAME prefixed with icon IMAGE."
2294 (let* ((img-name (and image
(expand-file-name
2295 image anything-c-find-files-icons-directory
)))
2296 (img (and image
(create-image img-name
)))
2297 (prefix-img (and image
(propertize " " 'display img
)))
2298 (prefix-new (propertize
2300 (propertize "[?]" 'face
'anything-ffiles-prefix-face
)))
2301 (prefix-url (propertize
2303 (propertize "[@]" 'face
'anything-ffiles-prefix-face
))))
2304 (cond ((or (file-exists-p fname
)
2305 (file-symlink-p fname
))
2306 (if image
(concat prefix-img fname
) fname
))
2307 ((string-match ffap-url-regexp fname
) (concat prefix-url
" " fname
))
2308 (t (concat prefix-new
" " fname
)))))
2310 (defun anything-c-find-files-transformer (files sources
)
2311 "Selector of transformer to use for `anything-c-source-find-files'."
2312 (if (and (window-system) anything-c-find-files-show-icons
)
2313 (anything-c-highlight-ffiles1 files sources
)
2314 (anything-c-highlight-ffiles files sources
)))
2316 (defun anything-c-highlight-ffiles (files sources
)
2317 "Candidate transformer for `anything-c-source-find-files' without icons."
2318 (loop for i in files
2319 collect
(cond ((file-symlink-p i
)
2321 (anything-c-prefix-filename
2323 i
'face
'anything-dired-symlink-face
2324 'help-echo
(file-truename i
)))
2326 ((file-directory-p i
)
2328 (anything-c-prefix-filename
2330 i
'face anything-c-files-face1
2331 'help-echo
(condition-case nil
2332 (anything-ff-attributes i
:dired t
)
2337 (anything-c-prefix-filename
2339 i
'face anything-c-files-face2
2340 'help-echo
(condition-case nil
2341 (anything-ff-attributes i
:dired t
)
2345 (defsubst anything-c-highlight-ffiles1
(files sources
)
2346 "Candidate transformer for `anything-c-source-find-files' that show icons."
2347 (loop for i in files
2348 for af
= (file-name-nondirectory i
)
2349 collect
(cond ( ;; Files.
2350 (eq nil
(car (file-attributes i
)))
2351 (cons (anything-c-prefix-filename
2353 i
'face anything-c-files-face2
2354 'help-echo
(condition-case nil
2355 (anything-ff-attributes i
:dired t
)
2359 ( ;; Empty directories.
2360 (and (eq t
(car (file-attributes i
)))
2361 ;; Be sure to have permission to list content.
2365 i nil directory-files-no-dot-files-regexp t
))))
2366 (cons (anything-c-prefix-filename
2368 i
'face anything-c-files-face1
2369 'help-echo
(condition-case nil
2370 (anything-ff-attributes i
:dired t
)
2374 ( ;; Open directories.
2375 (and (eq t
(car (file-attributes i
))) (get-buffer af
))
2376 (cons (anything-c-prefix-filename
2378 i
'face anything-c-files-face1
2379 'help-echo
(condition-case nil
2380 (anything-ff-attributes i
:dired t
)
2384 (;; Closed directories.
2385 (eq t
(car (file-attributes i
)))
2386 (cons (anything-c-prefix-filename
2388 i
'face anything-c-files-face1
2389 'help-echo
(condition-case nil
2390 (anything-ff-attributes i
:dired t
)
2394 ( ;; Open Symlinks directories.
2395 (and (stringp (car (file-attributes i
)))
2396 (file-directory-p i
) (get-buffer af
))
2397 (cons (anything-c-prefix-filename
2398 (propertize i
'face
'anything-dired-symlink-face
2399 'help-echo
(file-truename i
)) "open.xpm")
2401 ( ;; Closed Symlinks directories.
2402 (and (stringp (car (file-attributes i
)))
2403 (file-directory-p i
))
2404 (cons (anything-c-prefix-filename
2405 (propertize i
'face
'anything-dired-symlink-face
2406 'help-echo
(file-truename i
)) "close.xpm")
2408 ( ;; Files symlinks.
2409 (stringp (car (file-attributes i
)))
2410 (cons (anything-c-prefix-filename
2411 (propertize i
'face
'anything-dired-symlink-face
2412 'help-echo
(file-truename i
))
2416 (defun anything-find-files-action-transformer (actions candidate
)
2417 "Action transformer for `anything-c-source-find-files'."
2418 (cond ((with-current-buffer anything-current-buffer
2419 (eq major-mode
'message-mode
))
2420 (append (subseq actions
0 4)
2421 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files
))
2422 (subseq actions
4)))
2423 ((string-match (image-file-name-regexp) candidate
)
2424 (append (subseq actions
0 4)
2425 '(("Rotate image right" . anything-ff-rotate-image-right
)
2426 ("Rotate image left" . anything-ff-rotate-image-left
))
2427 (subseq actions
4)))
2428 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
2429 (car it
) candidate
))
2430 (append (subseq actions
0 4);(list (car actions))
2431 '(("Byte compile lisp file(s) `C-u to load'"
2432 . anything-find-files-byte-compile
)
2433 ("Load File(s)" . anything-find-files-load-files
))
2434 (subseq actions
4)))
2435 ((and (string-match "\.html$" candidate
)
2436 (file-exists-p candidate
))
2437 (append (subseq actions
0 4)
2438 '(("Browse url file" . browse-url-of-file
))
2439 (subseq actions
5)))
2442 (defun anything-ff-gnus-attach-files (candidate)
2443 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
2444 (let ((flist (anything-marked-candidates)))
2445 (gnus-dired-attach flist
)))
2447 (defun anything-ff-rotate-current-image1 (file &optional num-arg
)
2448 "Rotate current image at NUM-ARG degrees.
2449 This is a destructive operation on FILE made by external tool mogrify."
2450 ;; When FILE is not an image-file, do nothing.
2451 (when (string-match (image-file-name-regexp) file
)
2452 (if (executable-find "mogrify")
2454 (shell-command (format "mogrify -rotate %s %s" (or num-arg
90) file
))
2455 (when (buffer-live-p image-dired-display-image-buffer
)
2456 (kill-buffer image-dired-display-image-buffer
))
2457 (image-dired-display-image file
)
2459 (display-buffer (get-buffer image-dired-display-image-buffer
)))
2460 (error "mogrify not found"))))
2462 (defun anything-ff-rotate-image-left (candidate)
2463 "Rotate image file CANDIDATE left.
2464 This affect directly file CANDIDATE."
2465 (anything-ff-rotate-current-image1 candidate -
90))
2467 (defun anything-ff-rotate-image-right (candidate)
2468 "Rotate image file CANDIDATE right.
2469 This affect directly file CANDIDATE."
2470 (anything-ff-rotate-current-image1 candidate
))
2472 (defun anything-ff-rotate-left-persistent ()
2473 "Rotate image left without quitting anything."
2475 (anything-execute-persistent-action 'image-action1
))
2477 (defun anything-ff-rotate-right-persistent ()
2478 "Rotate image right without quitting anything."
2480 (anything-execute-persistent-action 'image-action2
))
2482 (defcustom anything-ff-exif-data-program
"exiftran"
2483 "*Program used to extract exif data of an image file."
2484 :group
'anything-config
2487 (defcustom anything-ff-exif-data-program-args
"-d"
2488 "*Arguments used for `anything-ff-exif-data-program'."
2489 :group
'anything-config
2492 (defun anything-ff-exif-data (candidate)
2493 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
2494 (if (and anything-ff-exif-data-program
2495 (executable-find anything-ff-exif-data-program
))
2496 (shell-command-to-string (format "%s %s %s"
2497 anything-ff-exif-data-program
2498 anything-ff-exif-data-program-args
2500 (format "No program %s found to extract exif"
2501 anything-ff-exif-data-program
)))
2503 ;; Have no effect if candidate is not an image file.
2504 (define-key anything-map
(kbd "M-l") 'anything-ff-rotate-left-persistent
)
2505 (define-key anything-map
(kbd "M-r") 'anything-ff-rotate-right-persistent
)
2507 (defun anything-find-files-persistent-action (candidate)
2508 "Open subtree CANDIDATE without quitting anything.
2509 If CANDIDATE is not a directory expand CANDIDATE filename.
2510 If CANDIDATE is alone, open file CANDIDATE filename.
2512 First hit on C-z expand CANDIDATE second hit open file.
2513 If a prefix arg is given or `anything-follow-mode' is on open file."
2514 (let ((follow (buffer-local-value
2515 'anything-follow-mode
2516 (get-buffer-create anything-buffer
)))
2517 (new-pattern (anything-get-selection))
2518 (num-lines-buf (with-current-buffer anything-buffer
2519 (count-lines (point-min) (point-max)))))
2520 (flet ((insert-in-minibuffer (fname)
2521 (with-selected-window (minibuffer-window)
2523 (delete-minibuffer-contents)
2524 (set-text-properties 0 (length fname
) nil fname
)
2526 (cond (;; A symlink directory, expand it's truename.
2527 (and (file-directory-p candidate
) (file-symlink-p candidate
))
2528 (insert-in-minibuffer (file-name-as-directory
2530 (expand-file-name candidate
)))))
2531 ;; A directory, open it.
2532 ((file-directory-p candidate
)
2533 (when (string= (anything-c-basename candidate
) "..")
2534 (setq anything-ff-last-expanded anything-ff-default-directory
))
2535 (insert-in-minibuffer (file-name-as-directory
2536 (expand-file-name candidate
))))
2537 ;; A symlink file, expand to it's true name. (first hit)
2538 ((file-symlink-p candidate
)
2539 (insert-in-minibuffer (file-truename candidate
)))
2540 ;; A regular file, expand it, (first hit)
2541 ((and (>= num-lines-buf
3) (not current-prefix-arg
) (not follow
))
2542 (insert-in-minibuffer new-pattern
))
2543 ;; An image file and it is the second hit on C-z,
2544 ;; show the file in `image-dired'.
2545 ((string-match (image-file-name-regexp) candidate
)
2546 (when (buffer-live-p image-dired-display-image-buffer
)
2547 (kill-buffer image-dired-display-image-buffer
))
2548 (image-dired-display-image candidate
)
2550 (display-buffer image-dired-display-image-buffer
)
2551 (with-current-buffer image-dired-display-image-buffer
2552 (let ((exif-data (anything-ff-exif-data candidate
)))
2553 (image-dired-update-property 'help-echo exif-data
))))
2554 ;; Allow browsing archive on avfs fs.
2555 ;; Assume volume is already mounted with mountavfs.
2556 ((and anything-ff-avfs-directory
2558 (regexp-quote (expand-file-name anything-ff-avfs-directory
))
2559 (file-name-directory candidate
))
2560 (anything-ff-file-compressed-p candidate
))
2561 (insert-in-minibuffer (concat candidate
"#")))
2562 ;; On second hit we open file.
2563 (t (find-file candidate
))))))
2565 (defvar anything-ff-avfs-directory nil
2566 "*The default avfs directory, usually '.avfs'.
2567 When this is set you will be able to expand archive filenames with `C-z'
2568 inside an avfs directory mounted with mountavfs.
2569 See <http://sourceforge.net/projects/avf/>.")
2570 (defvar anything-ff-file-compressed-list
'("gz" "bz2" "zip" "7z")
2571 "*Minimal list of compressed files extension.")
2572 (defun anything-ff-file-compressed-p (candidate)
2573 "Whether CANDIDATE is a compressed file or not."
2574 (member (file-name-extension candidate
)
2575 anything-ff-file-compressed-list
))
2577 (defun anything-c-insert-file-name-completion-at-point (candidate)
2578 "Insert file name completion at point."
2579 (if buffer-read-only
2580 (error "Error: Buffer `%s' is read-only" (buffer-name))
2581 (let* ((end (point))
2582 (guess (thing-at-point 'filename
))
2583 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess
)
2584 (string-match "^[^\~]" guess
))))
2585 (set-text-properties 0 (length candidate
) nil candidate
)
2586 (if (and guess
(not (string= guess
"")) (string-match "^~\\|/.*" guess
))
2588 (search-backward guess
(- (point) (length guess
)))
2589 (delete-region (point) end
)
2591 (insert (expand-file-name candidate
))
2592 (insert (abbreviate-file-name candidate
))))
2593 (error "Aborting completion: No valid file name at point")))))
2595 (defun* anything-find-files-history
(&key
(comp-read t
))
2596 "The `anything-find-files' history.
2597 Show the first `anything-ff-history-max-length' elements of `anything-ff-history'
2598 in an `anything-comp-read'."
2599 (let ((history (when anything-ff-history
2600 (loop with dup for i in anything-ff-history
2601 unless
(member i dup
) collect i into dup
2602 finally return dup
)))) ; Remove dups.
2604 (setq anything-ff-history
2605 (if (>= (length history
) anything-ff-history-max-length
)
2606 (subseq history
0 anything-ff-history-max-length
)
2610 "Switch to Directory: "
2612 :name
"Anything Find Files History"
2614 anything-ff-history
))))
2616 (defun anything-find-files-initial-input (&optional input
)
2617 "Return INPUT if present, otherwise try to guess it."
2618 (or (and input
(expand-file-name input
))
2619 (anything-find-files-input
2621 (thing-at-point 'filename
))))
2624 (defun anything-find-files ()
2625 "Preconfigured `anything' for anything implementation of `find-file'.
2626 Called with a prefix arg show history if some.
2627 Don't call it from programs, use `anything-find-files1' instead.
2628 This is the starting point for nearly all actions you can do on files."
2630 (let ((any-input (if (and current-prefix-arg anything-ff-history
)
2631 (anything-find-files-history)
2632 (anything-find-files-initial-input))))
2633 (when (and (eq major-mode
'org-agenda-mode
)
2636 (setq any-input
(expand-file-name org-directory
)))
2638 (anything-find-files1 any-input
)
2639 (setq any-input
(expand-file-name (anything-c-current-directory)))
2640 (anything-find-files1 any-input
(buffer-file-name (current-buffer))))))
2642 (defun anything-find-files1 (fname &optional preselect
)
2643 "Find FNAME with `anything' completion.
2644 Like `find-file' but with `anything' support.
2645 Use it for non--interactive calls of `anything-find-files'."
2646 (when (get-buffer anything-action-buffer
)
2647 (kill-buffer anything-action-buffer
))
2648 (let ((anything-mp-highlight-delay nil
))
2649 (anything :sources
'anything-c-source-find-files
2651 :preselect preselect
2652 :prompt
"Find Files or Url: "
2653 :buffer
"*Anything Find Files*")))
2655 (defun anything-find-files-input (fap tap
)
2656 "Default input of `anything-find-files'."
2657 (let* ((def-dir (anything-c-current-directory))
2658 (lib (anything-find-library-at-point))
2659 (file-p (and fap
(file-exists-p fap
)
2661 (file-name-directory (expand-file-name tap def-dir
))))))
2663 (file-p (expand-file-name tap def-dir
))
2666 (defun anything-c-current-directory ()
2667 "Return current-directory name at point.
2668 Useful in dired buffers when there is inserted subdirs."
2669 (if (eq major-mode
'dired-mode
)
2670 (dired-current-directory)
2673 (defun anything-find-library-at-point ()
2674 "Try to find library path at point.
2675 Find inside `require' and `declare-function' sexp."
2676 (require 'find-func
)
2677 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t
)))
2678 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t
)))
2679 (sexp (and beg-sexp end-sexp
2680 (buffer-substring-no-properties
2681 (1+ beg-sexp
) (1- end-sexp
)))))
2683 (cond ((and sexp
(string-match "require \'.+[^)]" sexp
))
2685 (replace-regexp-in-string
2687 ;; If require use third arg, ignore it,
2688 ;; always use library path found in `load-path'.
2689 (second (split-string (match-string 0 sexp
))))))
2690 ((and sexp
(string-match-p "^declare-function" sexp
))
2692 (replace-regexp-in-string
2694 (third (split-string sexp
)))))
2697 ;;; Anything completion for `write-file'.==> C-x C-w
2698 (defvar anything-c-source-write-file
2699 `((name .
,(concat "Write File" anything-c-find-files-doc-header
))
2700 ;; It is needed for filenames with capital letters
2702 (candidates . anything-find-files-get-candidates
)
2703 (filtered-candidate-transformer anything-c-find-files-transformer
)
2704 (persistent-action . anything-find-files-persistent-action
)
2705 (persistent-help .
"Expand Candidate")
2708 (("Write File" .
(lambda (candidate)
2709 (write-file candidate
'confirm
)))))))
2712 (defun anything-write-file ()
2713 "Preconfigured `anything' providing completion for `write-file'."
2715 (anything 'anything-c-source-write-file
2716 (expand-file-name default-directory
)
2717 "Write buffer to file: " nil nil
"*Anything write file*"))
2719 ;;; Anything completion for `insert-file'.==> C-x i
2720 (defvar anything-c-source-insert-file
2721 `((name .
,(concat "Insert File" anything-c-find-files-doc-header
))
2722 ;; It is needed for filenames with capital letters
2724 (candidates . anything-find-files-get-candidates
)
2725 (filtered-candidate-transformer anything-c-find-files-transformer
)
2726 (persistent-action . anything-find-files-persistent-action
)
2727 (persistent-help .
"Expand Candidate")
2730 (("Insert File" .
(lambda (candidate)
2731 (when (y-or-n-p (format "Really insert %s in %s "
2732 candidate anything-current-buffer
))
2733 (insert-file-contents candidate
))))))))
2736 (defun anything-insert-file ()
2737 "Preconfigured `anything' providing completion for `insert-file'."
2739 (anything 'anything-c-source-insert-file
2740 (expand-file-name default-directory
)
2741 "Insert file: " nil nil
"*Anything insert file*"))
2743 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
2744 (defvar anything-c-source-copy-files
2745 `((name .
,(concat "Copy Files" anything-c-find-files-doc-header
))
2746 ;; It is needed for filenames with capital letters
2748 (candidates . anything-find-files-get-candidates
)
2749 (filtered-candidate-transformer anything-c-find-files-transformer
)
2750 (persistent-action . anything-find-files-persistent-action
)
2751 (persistent-help .
"Expand Candidate")
2755 .
(lambda (candidate)
2756 (anything-dired-action candidate
:action
'copy
)))
2758 .
(lambda (candidate)
2759 (anything-dired-action candidate
:action
'copy
:follow t
)))))))
2762 (defvar anything-c-source-rename-files
2763 `((name .
,(concat "Rename Files" anything-c-find-files-doc-header
))
2764 ;; It is needed for filenames with capital letters
2766 (candidates . anything-find-files-get-candidates
)
2767 (filtered-candidate-transformer anything-c-find-files-transformer
)
2768 (persistent-action . anything-find-files-persistent-action
)
2769 (persistent-help .
"Expand Candidate")
2773 .
(lambda (candidate)
2774 (anything-dired-action candidate
:action
'rename
)))
2775 ("Rename and Follow"
2776 .
(lambda (candidate)
2777 (anything-dired-action candidate
:action
'rename
:follow t
)))))))
2779 (defvar anything-c-source-symlink-files
2780 `((name .
,(concat "Symlink Files" anything-c-find-files-doc-header
))
2781 ;; It is needed for filenames with capital letters
2783 (candidates . anything-find-files-get-candidates
)
2784 (filtered-candidate-transformer anything-c-find-files-transformer
)
2785 (persistent-action . anything-find-files-persistent-action
)
2786 (persistent-help .
"Expand Candidate")
2790 .
(lambda (candidate)
2791 (anything-dired-action candidate
:action
'symlink
)))
2793 .
(lambda (candidate)
2794 (anything-dired-action candidate
:action
'relsymlink
)))))))
2797 (defvar anything-c-source-hardlink-files
2798 `((name .
,(concat "Hardlink Files" anything-c-find-files-doc-header
))
2799 ;; It is needed for filenames with capital letters
2801 (candidates . anything-find-files-get-candidates
)
2802 (filtered-candidate-transformer anything-c-find-files-transformer
)
2803 (persistent-action . anything-find-files-persistent-action
)
2804 (persistent-help .
"Expand Candidate")
2808 .
(lambda (candidate)
2809 (anything-dired-action candidate
:action
'hardlink
)))))))
2812 ;; Emacs bugfix for version < 24.
2813 ;; This fix copying directory recursively from dired and copy-directory
2814 ;; when called interactively and not.
2815 ;; (copy only contents of directory whithout subdir).
2816 (when (< emacs-major-version
24)
2818 (defun copy-directory (directory newname
&optional keep-time parents copy-contents-only
)
2819 "Copy DIRECTORY to NEWNAME. Both args must be strings.
2820 If NEWNAME names an existing directory, copy DIRECTORY as subdirectory there.
2822 This function always sets the file modes of the output files to match
2823 the corresponding input file.
2825 The third arg KEEP-TIME non-nil means give the output files the same
2826 last-modified time as the old ones. (This works on only some systems.)
2828 A prefix arg makes KEEP-TIME non-nil.
2830 Noninteractively, the last argument PARENTS says whether to
2831 create parent directories if they don't exist. Interactively,
2832 this happens by default."
2834 (let ((dir (read-directory-name
2835 "Copy directory: " default-directory default-directory t nil
)))
2838 (format "Copy directory %s to: " dir
)
2839 default-directory default-directory nil nil
)
2840 current-prefix-arg t
)))
2841 ;; If default-directory is a remote directory, make sure we find its
2842 ;; copy-directory handler.
2843 (let ((handler (or (find-file-name-handler directory
'copy-directory
)
2844 (find-file-name-handler newname
'copy-directory
))))
2846 (funcall handler
'copy-directory directory newname keep-time parents
)
2848 ;; Compute target name.
2849 (setq directory
(directory-file-name (expand-file-name directory
))
2850 newname
(directory-file-name (expand-file-name newname
)))
2852 (if (not (file-directory-p newname
))
2853 ;; If NEWNAME is not an existing directory, create it; that
2854 ;; is where we will copy the files of DIRECTORY.
2855 (make-directory newname parents
)
2856 ;; If NEWNAME is an existing directory, we will copy into
2857 ;; NEWNAME/[DIRECTORY-BASENAME].
2858 (unless copy-contents-only
2859 (setq newname
(expand-file-name
2860 (file-name-nondirectory
2861 (directory-file-name directory
))
2863 (and (file-exists-p newname
)
2864 (not (file-directory-p newname
))
2865 (error "Cannot overwrite non-directory %s with a directory"
2867 (make-directory newname t
)))
2869 ;; Copy recursively.
2871 ;; We do not want to copy "." and "..".
2872 (directory-files directory
'full
2873 directory-files-no-dot-files-regexp
))
2874 (if (file-directory-p file
)
2875 (copy-directory file newname keep-time parents
)
2876 (let ((target (expand-file-name (file-name-nondirectory file
) newname
))
2877 (attrs (file-attributes file
)))
2878 (if (stringp (car attrs
)) ; Symbolic link
2879 (make-symbolic-link (car attrs
) target t
)
2880 (copy-file file target t keep-time
)))))
2882 ;; Set directory attributes.
2883 (set-file-modes newname
(file-modes directory
))
2885 (set-file-times newname
(nth 5 (file-attributes directory
)))))))
2887 (defun dired-copy-file (from to ok-flag
)
2888 (when (and (file-directory-p from
)
2889 (file-directory-p to
))
2890 (setq to
(file-name-directory to
)))
2891 (dired-handle-overwrite to
)
2892 (dired-copy-file-recursive from to ok-flag dired-copy-preserve-time t
2893 dired-recursive-copies
)))
2896 (defun* anything-dired-action
(candidate &key action follow
(files (dired-get-marked-files)))
2897 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
2898 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
2899 (let ((fn (case action
2900 ('copy
'dired-copy-file
)
2901 ('rename
'dired-rename-file
)
2902 ('symlink
'make-symbolic-link
)
2903 ('relsymlink
'dired-make-relative-symlink
)
2904 ('hardlink
'dired-hardlink
)))
2905 (marker (case action
2906 ((copy rename
) dired-keep-marker-copy
)
2907 ('symlink dired-keep-marker-symlink
)
2908 ('relsymlink dired-keep-marker-relsymlink
)
2909 ('hardlink dired-keep-marker-hardlink
)))
2910 (dirflag (and (= (length files
) 1)
2911 (file-directory-p (car files
))
2912 (not (file-directory-p candidate
)))))
2914 fn
(symbol-name action
) files
2915 ;; CANDIDATE is the destination.
2916 (if (file-directory-p candidate
)
2917 ;; When CANDIDATE is a directory, build file-name in this directory.
2918 ;; Else we use CANDIDATE.
2920 (expand-file-name (file-name-nondirectory from
) candidate
))
2921 #'(lambda (from) candidate
))
2924 (let ((moved-flist (anything-get-dest-fnames-from-list files candidate dirflag
))
2925 (target (directory-file-name candidate
)))
2928 (setq anything-ff-cand-to-mark moved-flist
)
2929 (if (and dirflag
(eq action
'rename
))
2930 (anything-find-files1 (file-name-directory target
) target
)
2931 (anything-find-files1 candidate
)))
2932 (setq anything-ff-cand-to-mark nil
))))))
2935 (defvar anything-ff-cand-to-mark nil
)
2937 (defun anything-c-basename (fname)
2938 "Resolve basename of file or directory named FNAME."
2939 (file-name-nondirectory (directory-file-name fname
)))
2941 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag
)
2942 "Transform filenames of FLIST to abs of DEST-CAND."
2943 ;; At this point files have been renamed/copied at destination.
2944 ;; That's mean DEST-CAND exists.
2946 with dest
= (expand-file-name dest-cand
)
2948 for basename-src
= (anything-c-basename src
)
2949 for fname
= (cond (rename-dir-flag (directory-file-name dest
))
2950 ((file-directory-p dest
)
2951 (concat (file-name-as-directory dest
) basename-src
))
2953 when
(file-exists-p fname
)
2954 collect fname into tmp-list
2955 finally return
(sort tmp-list
'string
<)))
2957 (defun anything-c-maybe-mark-candidates ()
2958 "Mark all candidates of list `anything-ff-cand-to-mark'."
2959 (when (and (string= (assoc-default 'name
(anything-get-current-source))
2960 (assoc-default 'name anything-c-source-find-files
))
2961 anything-ff-cand-to-mark
)
2962 (with-anything-window
2963 (while anything-ff-cand-to-mark
2964 (if (search-forward (car anything-ff-cand-to-mark
) (point-at-eol) t
)
2966 (anything-mark-current-line)
2967 (anything-make-visible-mark)
2969 (setq anything-ff-cand-to-mark
(cdr anything-ff-cand-to-mark
)))
2971 (unless (anything-this-visible-mark)
2972 (anything-prev-visible-mark)))))
2974 (add-hook 'anything-after-update-hook
#'anything-c-maybe-mark-candidates
)
2976 (defun* anything-dired-do-action-on-file
(&key action
)
2977 (let* ((files (dired-get-marked-files))
2978 (len (length files
))
2979 (fname (if (> len
1)
2980 (format "* %d Files" len
)
2982 (source (case action
2983 ('copy
'anything-c-source-copy-files
)
2984 ('rename
'anything-c-source-rename-files
)
2985 ('symlink
'anything-c-source-symlink-files
)
2986 ('hardlink
'anything-c-source-hardlink-files
)))
2987 (prompt-fm (case action
2988 ('copy
"Copy %s to: ")
2989 ('rename
"Rename %s to: ")
2990 ('symlink
"Symlink %s to: ")
2991 ('hardlink
"Hardlink %s to: ")))
2992 (buffer (case action
2993 ('copy
"*Anything Copy Files*")
2994 ('rename
"*Anything Rename Files*")
2995 ('symlink
"*Anything Symlink Files*")
2996 ('hardlink
"*Anything Hardlink Files*"))))
2998 (or (dired-dwim-target-directory)
2999 (expand-file-name (anything-c-current-directory)))
3000 (format prompt-fm fname
) nil nil buffer
)))
3004 (defun anything-dired-rename-file ()
3005 "Preconfigured `anything' to rename files from dired."
3007 (anything-dired-do-action-on-file :action
'rename
))
3010 (defun anything-dired-copy-file ()
3011 "Preconfigured `anything' to copy files from dired."
3013 (anything-dired-do-action-on-file :action
'copy
))
3016 (defun anything-dired-symlink-file ()
3017 "Preconfigured `anything' to symlink files from dired."
3019 (anything-dired-do-action-on-file :action
'symlink
))
3022 (defun anything-dired-hardlink-file ()
3023 "Preconfigured `anything' to hardlink files from dired."
3025 (anything-dired-do-action-on-file :action
'hardlink
))
3027 (defvar anything-dired-bindings nil
)
3029 (defun anything-dired-bindings (&optional arg
)
3030 "Replace usual dired commands `C' and `R' by anything ones.
3031 When call interactively toggle dired bindings and anything bindings.
3032 When call non--interactively with arg > 0, enable anything bindings.
3033 You can put (anything-dired-binding 1) in init file to enable anything bindings."
3035 (if (or (and arg
(> arg
0)) (not anything-dired-bindings
))
3036 ;; Replace dired bindings.
3038 (substitute-key-definition
3039 'dired-do-copy
'anything-dired-copy-file dired-mode-map
)
3040 (substitute-key-definition
3041 'dired-do-rename
'anything-dired-rename-file dired-mode-map
)
3042 (substitute-key-definition
3043 'dired-do-symlink
'anything-dired-symlink-file dired-mode-map
)
3044 (substitute-key-definition
3045 'dired-do-hardlink
'anything-dired-hardlink-file dired-mode-map
)
3046 (setq anything-dired-bindings t
))
3047 ;; Replace anything bindings.
3048 (substitute-key-definition
3049 'anything-dired-copy-file
'dired-do-copy dired-mode-map
)
3050 (substitute-key-definition
3051 'anything-dired-rename-file
'dired-do-rename dired-mode-map
)
3052 (substitute-key-definition
3053 'anything-dired-symlink-file
'dired-do-symlink dired-mode-map
)
3054 (substitute-key-definition
3055 'anything-dired-hardlink-file
'dired-do-hardlink dired-mode-map
)
3056 (setq anything-dired-bindings nil
)))
3058 (defun* anything-c-read-file-name
(prompt
3060 (initial-input (expand-file-name default-directory
))
3061 (buffer "*Anything Completions*")
3064 (marked-candidates nil
)
3065 (persistent-action 'anything-find-files-persistent-action
)
3066 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
3067 "Anything `read-file-name' emulation.
3068 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
3069 (when (get-buffer anything-action-buffer
)
3070 (kill-buffer anything-action-buffer
))
3071 (let ((anything-mp-highlight-delay nil
))
3072 (flet ((action-fn (candidate)
3073 (if marked-candidates
3074 (anything-marked-candidates)
3075 (identity candidate
))))
3078 `(((name .
,(concat "Read File Name History" anything-c-find-files-doc-header
))
3079 (candidates .
(lambda ()
3080 (anything-comp-read-get-candidates history
)))
3082 (persistent-action .
,persistent-action
)
3083 (persistent-help .
,persistent-help
)
3084 (action .
,'action-fn
))
3085 ((name .
,(concat "Read file name" anything-c-find-files-doc-header
))
3086 ;; It is needed for filenames with capital letters
3088 (candidates .
(lambda ()
3090 (loop with seq
= (anything-find-files-get-candidates)
3091 for fname in seq when
(funcall test fname
)
3093 (anything-find-files-get-candidates))))
3094 (filtered-candidate-transformer anything-c-find-files-transformer
)
3095 (persistent-action .
,persistent-action
)
3096 (persistent-help .
,persistent-help
)
3098 (action .
,'action-fn
)))
3099 :input initial-input
3106 (defvar anything-c-source-file-cache-initialized nil
)
3108 (defvar anything-c-file-cache-files nil
)
3110 (defvar anything-c-source-file-cache
3111 '((name .
"File Cache")
3114 (require 'filecache nil t
)
3115 (unless anything-c-source-file-cache-initialized
3116 (setq anything-c-file-cache-files
3117 (loop for item in file-cache-alist append
3118 (destructuring-bind (base &rest dirs
) item
3119 (loop for dir in dirs collect
3120 (concat dir base
)))))
3121 (defadvice file-cache-add-file
(after file-cache-list activate
)
3122 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
3123 (setq anything-c-source-file-cache-initialized t
))))
3124 (candidates . anything-c-file-cache-files
)
3125 (match anything-c-match-on-file-name
3126 anything-c-match-on-directory-name
)
3128 ;; (anything 'anything-c-source-file-cache)
3131 ;; NOTE for WINDOZE users:
3132 ;; You have to install Everything with his command line interface here:
3133 ;; http://www.voidtools.com/download.php
3135 (defvar anything-c-locate-command
3137 ('gnu
/linux
"locate -i -r %s")
3138 ('berkeley-unix
"locate -i %s")
3139 ('windows-nt
"es -i -r %s")
3141 "A list of arguments for locate program.
3142 The \"-r\" option must be the last option.")
3144 (defun anything-c-locate-init ()
3145 "Initialize async locate process for `anything-c-source-locate'."
3146 (setq mode-line-format
3147 '(" " mode-line-buffer-identification
" "
3148 (line-number-mode "%l") " "
3149 (:eval
(propertize "(Locate Process Running) "
3150 'face
'((:foreground
"red"))))))
3152 (start-process-shell-command "locate-process" nil
3153 (format anything-c-locate-command
3155 (set-process-sentinel (get-process "locate-process")
3156 #'(lambda (process event
)
3157 (when (string= event
"finished\n")
3158 (kill-local-variable 'mode-line-format
)
3159 (with-anything-window
3160 (anything-update-move-first-line)))))))
3162 (defvar anything-c-source-locate
3164 (candidates . anything-c-locate-init
)
3166 (requires-pattern .
3)
3168 "Find files matching the current input pattern with locate.")
3170 ;; (anything 'anything-c-source-locate)
3173 ;; NOTE: the -d option with skip avoid error on windows.
3174 ;; It have no effect on GNU/Linux.
3175 (defvar anything-c-grep-default-command
"grep -d skip -niH -e %s %s %s"
3176 "Default format command for `anything-do-grep'.")
3178 (defvar anything-c-grep-default-function
'anything-c-grep-init
)
3180 (defface anything-grep-match
3181 '((t (:inherit match
)))
3182 "Face used to highlight grep matches."
3185 (defface anything-grep-file
3186 '((t (:foreground
"BlueViolet" :underline t
)))
3187 "Face used to highlight grep results filenames."
3190 (defface anything-grep-lineno
3191 '((t (:foreground
"Darkorange1")))
3192 "Face used to highlight grep number lines."
3195 (defun anything-c-grep-prepare-candidates (candidates)
3196 "Prepare filenames and directories CANDIDATES for grep command line."
3197 ;; If one or more candidate is a directory, search in all files
3198 ;; of this candidate (e.g /home/user/directory/*).
3199 ;; If r option is enabled search also in subdidrectories.
3200 ;; We need here to expand wildcards to support crap windows filenames
3201 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
3202 (loop for i in candidates append
3203 (cond (;; Candidate is a directory and we use recursion.
3204 (and (file-directory-p i
)
3205 (anything-c-grep-recurse-p))
3206 (list (expand-file-name i
)))
3207 ;; Candidate is a directory, search in all files.
3208 ((file-directory-p i
)
3209 (file-expand-wildcards
3210 (concat (file-name-as-directory (expand-file-name i
)) "*") t
))
3211 ;; Candidate use wildcard.
3212 ((string-match "\*" i
) (file-expand-wildcards i t
))
3213 ;; Candidate is a file and we use recursion, use the
3214 ;; current directory instead of candidate.
3215 ((and (file-exists-p i
) (anything-c-grep-recurse-p))
3216 (list (file-name-directory (directory-file-name i
))))
3217 ;; Else should be one or more file.
3218 (t (list i
))) into all-files
3220 (mapconcat 'shell-quote-argument all-files
" ")))
3222 (defun anything-c-grep-recurse-p ()
3223 "Check if `anything-do-grep1' have switched to recursive."
3224 (let ((args (replace-regexp-in-string
3225 "grep" "" anything-c-grep-default-command
)))
3226 (string-match-p "r\\|recurse" args
)))
3228 (defun anything-c-grep-init (only-files &optional include
)
3229 "Start an asynchronous grep process in ONLY-FILES list."
3230 (let* ((fnargs (anything-c-grep-prepare-candidates
3231 (if (file-remote-p anything-ff-default-directory
)
3232 (mapcar #'(lambda (x)
3233 (file-remote-p x
'localname
))
3236 (ignored-files (mapconcat
3238 (concat "--exclude=" (shell-quote-argument x
)))
3239 grep-find-ignored-files
" "))
3240 (ignored-dirs (mapconcat
3241 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
3243 (concat "--exclude-dir=" (shell-quote-argument x
)))
3244 grep-find-ignored-directories
" "))
3245 (exclude (if (anything-c-grep-recurse-p)
3246 (concat (or include ignored-files
) " " ignored-dirs
)
3248 (setq mode-line-format
3249 '(" " mode-line-buffer-identification
" "
3250 (line-number-mode "%l") " "
3251 (:eval
(propertize "(Grep Process Running) "
3252 'face
'((:foreground
"red"))))))
3254 (let ((default-directory anything-ff-default-directory
))
3255 (start-file-process-shell-command
3257 (format anything-c-grep-default-command
3258 (shell-quote-argument anything-pattern
)
3262 (set-process-sentinel
3263 (get-process "grep-process")
3264 #'(lambda (process event
)
3265 (when (string= event
"finished\n")
3266 (kill-local-variable 'mode-line-format
)
3267 (with-anything-window
3268 (anything-update-move-first-line))))))))
3270 (defun anything-c-grep-action (candidate &optional where mark
)
3271 "Define a default action for `anything-do-grep' on CANDIDATE.
3272 WHERE can be one of other-window, elscreen, other-frame."
3273 (let* ((split (anything-c-grep-split-line candidate
))
3274 (lineno (string-to-number (nth 1 split
)))
3275 (loc-fname (car split
))
3276 (tramp-method (file-remote-p anything-ff-default-directory
'method
))
3277 (tramp-host (file-remote-p anything-ff-default-directory
'host
))
3278 (tramp-prefix (concat "/" tramp-method
":" tramp-host
":"))
3279 (fname (if tramp-host
3280 (concat tramp-prefix loc-fname
) loc-fname
)))
3282 (other-window (find-file-other-window fname
))
3283 (elscreen (anything-elscreen-find-file fname
))
3284 (other-frame (find-file-other-frame fname
))
3285 (t (find-file fname
)))
3286 (anything-goto-line lineno
)
3287 (set-marker (mark-marker) (point))
3289 (push-mark (point) 'nomsg
))))
3292 (defun anything-c-grep-persistent-action (candidate)
3293 "Persistent action for `anything-do-grep'.
3294 With a prefix arg record CANDIDATE in `mark-ring'."
3295 (if current-prefix-arg
3296 (anything-c-grep-action candidate nil
'mark
)
3297 (anything-c-grep-action candidate
))
3298 (anything-match-line-color-current-line))
3300 (defun anything-do-grep1 (only &optional recurse
)
3301 "Launch grep with a list of ONLY files.
3302 When RECURSE is given use -r option of grep and prompt user
3303 to set the --include args of grep.
3304 You can give more than one arg separated by space.
3305 e.g *.el *.py *.tex.
3306 If it's empty --exclude `grep-find-ignored-files' is used instead."
3307 (let* ((anything-compile-source-functions
3308 ;; rule out anything-match-plugin because the input is one regexp.
3309 (delq 'anything-compile-source--match-plugin
3310 (copy-sequence anything-compile-source-functions
)))
3311 (include-files (and recurse
(read-string "OnlyExt(*.[ext]): ")))
3312 (anything-c-grep-default-command (if recurse
"grep -nirH -e %s %s %s"
3313 anything-c-grep-default-command
))
3314 ;; Disable match-plugin and use here own highlighting.
3315 (anything-mp-highlight-delay nil
))
3318 (and (not (string= include-files
""))
3319 (mapconcat #'(lambda (x)
3320 (concat "--include=" (shell-quote-argument x
)))
3321 (split-string include-files
) " "))))
3322 ;; When called as action from an other source e.g *-find-files
3323 ;; we have to kill action buffer.
3324 (when (get-buffer anything-action-buffer
)
3325 (kill-buffer anything-action-buffer
))
3328 `(((name .
"Grep (M-up/down - next/prec file)")
3332 (funcall anything-c-grep-default-function only include-files
)
3333 (funcall anything-c-grep-default-function only
))))
3334 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
3335 (candidate-number-limit .
9999)
3338 `(("Find File" . anything-c-grep-action
)
3339 ("Find file other window"
3340 .
(lambda (candidate)
3341 (anything-c-grep-action candidate
'other-window
)))
3342 ,(and (locate-library "elscreen")
3343 '("Find file in Elscreen"
3344 .
(lambda (candidate)
3345 (anything-c-grep-action
3346 candidate
'elscreen
))))
3347 ("Find file other frame"
3348 .
(lambda (candidate)
3349 (anything-c-grep-action candidate
'other-frame
))))))
3350 (persistent-action .
(lambda (candidate)
3351 (anything-c-grep-persistent-action candidate
)))
3352 (persistent-help .
"Jump to line (`C-u' Record in mark ring)")
3353 (requires-pattern .
3)
3355 :buffer
"*anything grep*")))
3358 (defun anything-do-grep ()
3359 "Preconfigured anything for grep.
3360 Contrarily to Emacs `grep' no default directory is given, but
3361 the full path of candidates in ONLY.
3362 That allow to grep different files not only in `default-directory' but anywhere
3363 by marking them (C-<SPACE>). If one or more directory is selected
3364 grep will search in all files of these directories.
3365 You can use also wildcard in the base name of candidate.
3366 If a prefix arg is given use the -r option of grep.
3367 See also `anything-do-grep1'."
3369 (let ((only (anything-c-read-file-name
3370 "Search in file(s): " :marked-candidates t
))
3371 (prefarg current-prefix-arg
))
3372 (anything-do-grep1 only prefarg
)))
3374 (defun anything-c-grep-split-line (line)
3375 "Split a grep output line."
3376 (let (beg fname lineno str
)
3377 ;; Don't print until grep line is valid.
3378 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line
)
3381 (goto-char (point-min))
3384 (re-search-forward ":" nil t
)
3385 (setq fname
(buffer-substring-no-properties beg
(1- (point))))
3387 (re-search-forward ":" nil t
)
3388 (setq lineno
(buffer-substring-no-properties beg
(1- (point))))
3389 (setq str
(buffer-substring-no-properties (point) (point-at-eol))))
3390 (list fname lineno str
))))
3392 (defun anything-c-grep-cand-transformer (candidates sources
)
3393 "Filtered candidate transformer function for `anything-do-grep'."
3394 (loop for i in candidates
3395 for split
= (and i
(anything-c-grep-split-line i
))
3396 for fname
= (car split
)
3397 for lineno
= (nth 1 split
)
3398 for str
= (nth 2 split
)
3399 when
(and fname lineno str
)
3401 (cons (concat (propertize (file-name-nondirectory fname
)
3402 'face
'anything-grep-file
3403 'help-echo fname
) ":"
3404 (propertize lineno
'face
'anything-grep-lineno
) ":"
3405 (anything-c-grep-highlight-match str
))
3408 (defun anything-c-grep-highlight-match (str)
3409 "Highlight in string STR all occurences matching `anything-pattern'."
3413 (goto-char (point-min))
3414 (while (and (re-search-forward anything-pattern nil t
)
3415 (> (- (match-end 0) (match-beginning 0)) 0))
3416 (add-text-properties
3417 (match-beginning 0) (match-end 0)
3418 '(face anything-grep-match
)))
3422 ;; Go to next or precedent file (common to etags and grep).
3423 (defun anything-c-goto-next-or-prec-file (n)
3424 "Go to next or precedent candidate file in anything grep/etags buffers.
3425 If N is positive go forward otherwise go backward."
3426 (let ((cur-source (assoc-default 'name
(anything-get-current-source))))
3427 (with-anything-window
3428 (if (or (string= cur-source
"Grep (M-up/down - next/prec file)")
3429 (string-match "^Etags.*" cur-source
))
3430 (let* ((current-line-list (split-string
3433 (point-at-eol)) ":"))
3434 (current-fname (nth 0 current-line-list
))
3435 (fn-b-o-f (if (eq n
1) 'eobp
'bobp
)))
3437 (while (not (funcall fn-b-o-f
))
3438 (forward-line n
) ; Go forward or backward depending of n value.
3439 (unless (search-forward current-fname
(point-at-eol) t
)
3440 (anything-mark-current-line)
3441 (throw 'break nil
))))
3442 (cond ((and (eq n
1) (eobp))
3443 (re-search-backward ".")
3445 (anything-mark-current-line))
3446 ((and (< n
1) (bobp))
3448 (anything-mark-current-line))))
3450 (anything-next-line)
3451 (anything-previous-line))))))
3454 (defun anything-c-goto-precedent-file ()
3455 "Go to precedent file in anything grep/etags buffers."
3457 (anything-c-goto-next-or-prec-file -
1))
3460 (defun anything-c-goto-next-file ()
3461 "Go to precedent file in anything grep/etags buffers."
3463 (anything-c-goto-next-or-prec-file 1))
3465 ;; This keys affect etags and grep only.
3466 ;; in other sources they do nothing, just going next or precedent line.
3467 (define-key anything-map
(kbd "M-<down>") #'anything-c-goto-next-file
)
3468 (define-key anything-map
(kbd "M-<up>") #'anything-c-goto-precedent-file
)
3470 ;; Yank text at point.
3471 (defvar anything-yank-point nil
)
3473 (defun anything-yank-text-at-point ()
3474 "Yank text at point in minibuffer."
3477 (flet ((insert-in-minibuffer (word)
3478 (with-selected-window (minibuffer-window)
3479 (let ((str anything-pattern
))
3480 (delete-minibuffer-contents)
3481 (set-text-properties 0 (length word
) nil word
)
3482 (insert (concat str word
))))))
3483 (with-current-buffer anything-current-buffer
3484 ;; Start to initial point if C-w have never been hit.
3485 (unless anything-yank-point
(setq anything-yank-point
(point)))
3486 (and anything-yank-point
(goto-char anything-yank-point
))
3488 (setq input
(buffer-substring-no-properties anything-yank-point
(point)))
3489 (setq anything-yank-point
(point))) ; End of last forward-word
3490 (insert-in-minibuffer input
))))
3492 (defun anything-reset-yank-point ()
3493 (setq anything-yank-point nil
))
3495 (add-hook 'anything-after-persistent-action-hook
'anything-reset-yank-point
)
3496 (add-hook 'anything-cleanup-hook
'anything-reset-yank-point
)
3497 (define-key anything-map
(kbd "C-w") 'anything-yank-text-at-point
)
3501 (when (locate-library "anything-etags.el")
3504 "You are using obsolete library `anything-etags.el' and should remove it."
3507 (defcustom anything-c-etags-tag-file-name
"TAGS"
3508 "Etags tag file name."
3510 :group
'anything-config
)
3512 (defcustom anything-c-etags-tag-file-search-limit
10
3513 "The limit level of directory to search tag file.
3514 Don't search tag file deeply if outside this value."
3516 :group
'anything-config
)
3518 (defvar anything-c-etags-tag-file-dir nil
3519 "Etags file directory.")
3520 (defvar anything-c-etags-mtime-alist nil
)
3521 (defvar anything-c-etags-cache
(make-hash-table :test
'equal
))
3523 (defun anything-c-etags-get-tag-file ()
3524 "Get Etags tag file."
3525 ;; Get tag file from `default-directory' or upper directory.
3526 (let ((current-dir (anything-c-etags-find-tag-file default-directory
)))
3527 ;; Return nil if not find tag file.
3529 (setq anything-c-etags-tag-file-dir current-dir
) ;set tag file directory
3530 (expand-file-name anything-c-etags-tag-file-name current-dir
))))
3532 (defun anything-c-etags-find-tag-file (current-dir)
3534 Try to find tag file in upper directory if haven't found in CURRENT-DIR."
3535 (flet ((file-exists?
(dir)
3536 (let ((tag-path (expand-file-name anything-c-etags-tag-file-name dir
)))
3537 (and (stringp tag-path
)
3538 (file-exists-p tag-path
)
3539 (file-readable-p tag-path
)))))
3540 (loop with count
= 0
3541 until
(file-exists? current-dir
)
3542 ;; Return nil if outside the value of
3543 ;; `anything-c-etags-tag-file-search-limit'.
3544 if
(= count anything-c-etags-tag-file-search-limit
)
3546 ;; Or search upper directories.
3549 (setq current-dir
(expand-file-name (concat current-dir
"../")))
3550 finally return current-dir
)))
3552 (defun anything-c-source-etags-header-name (x)
3554 (with-current-buffer anything-current-buffer
3555 (anything-c-etags-get-tag-file))))
3557 (defmacro anything-c-etags-create-buffer
(file)
3558 `(let* ((tag-fname ,file
)
3560 (split (with-current-buffer (find-file-noselect tag-fname
)
3562 (split-string (buffer-string) "\n" 'omit-nulls
)
3563 (setq max
(line-number-at-pos (point-max)))
3565 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max
)))
3569 for i in split for count from
0
3570 for elm
= (unless (string-match "^\x0c" i
)
3571 (anything-aif (string-match "\177" i
)
3574 do
(cond ((and elm
(string-match "^\\(.+\\),[0-9]+" elm
))
3575 (setq fname
(match-string 1 elm
)))
3576 (elm (setq cand
(concat fname
": " elm
)))
3577 (t (setq cand nil
)))
3579 (insert (concat cand
"\n"))
3580 (progress-reporter-update progress-reporter count
)))))
3582 (defun anything-c-etags-init ()
3583 (let ((tagfile (anything-c-etags-get-tag-file)))
3585 (with-current-buffer (anything-candidate-buffer 'global
)
3586 (anything-aif (gethash tagfile anything-c-etags-cache
)
3588 (anything-c-etags-create-buffer tagfile
)
3589 (puthash tagfile
(buffer-string) anything-c-etags-cache
)
3590 (anything-aif (assoc tagfile anything-c-etags-mtime-alist
)
3591 ;; If an entry exists modify it.
3592 (setcdr it
(anything-c-etags-mtime tagfile
))
3593 ;; No entry create a new one.
3594 (add-to-list 'anything-c-etags-mtime-alist
3595 (cons tagfile
(anything-c-etags-mtime tagfile
)))))))))
3597 (defvar anything-c-source-etags-select
3599 (header-name . anything-c-source-etags-header-name
)
3600 (init . anything-c-etags-init
)
3601 (candidates-in-buffer)
3602 (action . anything-c-etags-default-action
)
3603 (persistent-action .
(lambda (candidate)
3604 (anything-c-etags-default-action candidate
)
3605 (anything-match-line-color-current-line)))))
3607 (defun anything-c-etags-default-action (candidate)
3608 (let* ((split (split-string candidate
": "))
3609 (fname (expand-file-name
3610 (car split
) anything-c-etags-tag-file-dir
))
3613 (goto-char (point-min))
3614 (search-forward elm nil t
)
3615 (goto-char (match-beginning 0))))
3617 (defun anything-c-etags-select (arg)
3618 "Preconfigured anything for etags.
3619 Called with one prefix arg use symbol at point as initial input.
3620 Called with two prefix arg reinitialize cache.
3621 If tag file have been modified reinitialize cache."
3623 (let ((tag (anything-c-etags-get-tag-file))
3624 (init (and (equal arg
'(4)) (thing-at-point 'symbol
)))
3625 (anything-quit-if-no-candidate t
)
3626 (anything-execute-action-at-once-if-one t
))
3627 (when (or (equal arg
'(16))
3628 (and anything-c-etags-mtime-alist
3629 (anything-c-etags-file-modified-p tag
)))
3630 (remhash tag anything-c-etags-cache
))
3631 (if (and tag
(file-exists-p tag
))
3632 (anything :sources
'anything-c-source-etags-select
3634 :buffer
"*anything etags*")
3635 (message "Error: No tag file found, please create one with etags shell command."))))
3637 (defun anything-c-etags-mtime (file)
3638 "Last modification time of FILE."
3639 (cadr (nth 5 (file-attributes file
))))
3641 (defun anything-c-etags-file-modified-p (file)
3642 "Check if tag FILE have been modified in this session.
3643 If FILE is nil return nil."
3644 (let ((last-modif (and file
3645 (assoc-default file anything-c-etags-mtime-alist
))))
3647 (/= last-modif
(anything-c-etags-mtime file
)))))
3650 (defvar anything-c-source-recentf
3651 '((name .
"Recentf")
3654 (or recentf-mode
(recentf-mode 1))
3655 ;; Big value empowers anything/recentf
3656 (when (and (numberp recentf-max-saved-items
)
3657 (<= recentf-max-saved-items
20))
3658 (setq recentf-max-saved-items
500))))
3659 (candidates . recentf-list
)
3660 (match anything-c-match-on-file-name
3661 anything-c-match-on-directory-name
)
3663 "See (info \"(emacs)File Conveniences\").
3664 if `recentf-max-saved-items' is too small, set it to 500.")
3665 ;; (anything 'anything-c-source-recentf)
3668 (eval-when-compile (require 'ffap
))
3669 (defvar anything-c-source-ffap-guesser
3670 '((name .
"File at point")
3671 (init .
(lambda () (require 'ffap
)))
3672 (candidates .
(lambda ()
3674 (with-current-buffer anything-current-buffer
3678 ;; (anything 'anything-c-source-ffap-guesser)
3680 ;;; ffap with line number
3681 (defun anything-c-ffap-file-line-at-point ()
3682 "Get (FILENAME . LINENO) at point."
3683 (anything-aif (let (ffap-alist) (ffap-file-at-point))
3686 (when (and (search-forward it nil t
)
3687 (looking-at ":\\([0-9]+\\)"))
3688 (cons it
(string-to-number (match-string 1)))))))
3690 (defvar anything-c-ffap-line-location nil
3691 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
3692 It is cleared after jumping line.")
3694 (defun anything-c-ffap-line-candidates ()
3695 (with-current-buffer anything-current-buffer
3696 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
3697 (when anything-c-ffap-line-location
3698 (destructuring-bind (file . line
) anything-c-ffap-line-location
3699 (list (cons (format "%s (line %d)" file line
) file
)))))
3701 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
3702 (defun anything-c-ffap-line-goto-line ()
3703 (when (car anything-c-ffap-line-location
)
3706 (with-selected-window
3708 (get-file-buffer (car anything-c-ffap-line-location
)))
3709 (anything-goto-line (cdr anything-c-ffap-line-location
)))))))
3710 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
3711 (add-hook 'anything-after-persistent-action-hook
'anything-c-ffap-line-goto-line
)
3713 (defvar anything-c-source-ffap-line
3714 '((name .
"File/Lineno at point")
3715 (init .
(lambda () (require 'ffap
)))
3716 (candidates . anything-c-ffap-line-candidates
)
3718 ;; (anything 'anything-c-source-ffap-line)
3720 ;;; list of files gleaned from every dired buffer
3721 (defun anything-c-files-in-all-dired-candidates ()
3725 (cond ((listp dir
) ;filelist
3727 ((equal "" (file-name-nondirectory dir
)) ;dir
3728 (directory-files dir t
))
3730 (file-expand-wildcards dir t
))))
3732 (mapcar (lambda (buf)
3734 (when (eq major-mode
'dired-mode
)
3735 (if (consp dired-directory
)
3736 (cdr dired-directory
) ;filelist
3737 dired-directory
))) ;dir or wildcard
3739 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
3741 (defvar anything-c-source-files-in-all-dired
3742 '((name .
"Files in all dired buffer.")
3743 (candidates . anything-c-files-in-all-dired-candidates
)
3745 ;; (anything 'anything-c-source-files-in-all-dired)
3747 (defcustom anything-c-filelist-file-name nil
3748 "*Filename of file list.
3749 Accept a list of string for multiple files.
3751 This file tend to be very large (> 100MB) and recommend to be in ramdisk for speed.
3752 File list is created by make-filelist.rb script.
3755 ruby make-filelist.rb > /tmp/all.filelist
3758 ;; Assume that /tmp is ramdisk or tmpfs
3759 (setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\")
3760 (setq anything-c-filelist-file-name \"/tmp/all.filelist\")
3763 :group
'anything-config
)
3764 (defvar anything-c-source-filelist
3765 '((name .
"FileList")
3766 (grep-candidates . anything-c-filelist-file-name
)
3767 (candidate-number-limit .
200)
3768 (requires-pattern .
4)
3770 "Source to find files instantly.
3771 See `anything-c-filelist-file-name' docstring for usage.")
3774 (defun anything-filelist ()
3775 "Preconfigured `anything' to open files instantly.
3777 See `anything-c-filelist-file-name' docstring for usage."
3779 (anything-other-buffer 'anything-c-source-filelist
"*anything file list*"))
3782 (defun anything-filelist+ ()
3783 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
3785 This is a replacement for `anything-for-files'.
3786 See `anything-c-filelist-file-name' docstring for usage."
3788 (anything-other-buffer
3789 '(anything-c-source-ffap-line
3790 anything-c-source-ffap-guesser
3791 anything-c-source-buffers
+
3792 anything-c-source-recentf
3793 anything-c-source-bookmarks
3794 anything-c-source-file-cache
3795 anything-c-source-filelist
)
3796 "*anything file list*"))
3801 (defvar anything-c-info-pages nil
3802 "All info pages on system.
3803 Will be calculated the first time you invoke anything with this
3806 (defvar anything-c-source-info-pages
3807 `((name .
"Info Pages")
3810 (if anything-c-info-pages
3811 anything-c-info-pages
3812 (setq anything-c-info-pages
3813 (save-window-excursion
3816 (Info-find-node "dir" "top")
3817 (goto-char (point-min))
3818 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
3820 (while (re-search-forward info-topic-regexp nil t
)
3821 (add-to-list 'topics
(match-string-no-properties 1)))
3822 (goto-char (point-min))
3825 (action .
(("Show with Info" .
(lambda (node-str)
3826 (info (replace-regexp-in-string
3827 "^[^:]+: " "" node-str
))))))
3828 (requires-pattern .
2)))
3829 ;; (anything 'anything-c-source-info-pages)
3832 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
3833 (defun anything-c-describe-attributes (anything-attribute)
3834 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
3835 Same as `anything-describe-anything-attribute' but with anything completion."
3836 (interactive (list (intern
3838 "Describe anything attribute: "
3839 (mapcar 'symbol-name anything-additional-attributes
)
3842 #'(lambda (candidate)
3843 (with-output-to-temp-buffer "*Help*"
3844 (princ (get (intern candidate
) 'anything-attrdoc
))))))))
3845 (with-output-to-temp-buffer "*Help*"
3846 (princ (get anything-attribute
'anything-attrdoc
))))
3848 ;;; Use info-index plug-in. Note that `name' attribute is
3849 ;;; not needed but `anything-c-insert-summary' uses it.
3851 (defvar anything-c-source-info-elisp
3852 '((name .
"Info index: elisp")
3853 (info-index .
"elisp")))
3854 ;; (anything 'anything-c-source-info-elisp)
3857 (defvar anything-c-source-info-cl
3858 '((name .
"Info index: cl")
3859 (info-index .
"cl")))
3860 ;; (anything 'anything-c-source-info-cl)
3863 (defvar anything-c-source-info-org
3864 '((name .
"Info index: org")
3865 (info-index .
"org")))
3866 ;; (anything 'anything-c-source-info-org)
3868 ;; Info Index ratpoison
3869 (defvar anything-c-source-info-ratpoison
3870 '((name .
"Info index: ratpoison")
3871 (info-index .
"ratpoison")))
3872 ;; (anything 'anything-c-source-info-ratpoison)
3875 (defvar anything-c-source-info-zsh
3876 '((name .
"Info index: zsh")
3877 (info-index .
"zsh")))
3878 ;; (anything 'anything-c-source-info-zsh)
3881 (defvar anything-c-source-info-bash
3882 '((name .
"Info index: bash")
3883 (info-index .
"bash")))
3884 ;; (anything 'anything-c-source-info-bash)
3886 ;; Info Index coreutils
3887 (defvar anything-c-source-info-coreutils
3888 '((name .
"Info index: coreutils")
3889 (info-index .
"coreutils")))
3890 ;; (anything 'anything-c-source-info-coreutils)
3892 ;; Info Index fileutils
3893 (defvar anything-c-source-info-fileutils
3894 '((name .
"Info index: fileutils")
3895 (info-index .
"fileutils")))
3896 ;; (anything 'anything-c-source-info-fileutils)
3899 (defvar anything-c-source-info-find
3900 '((name .
"Info index: find")
3901 (info-index .
"find")))
3902 ;; (anything 'anything-c-source-info-find)
3904 ;; Info Index sh-utils
3905 (defvar anything-c-source-info-sh-utils
3906 '((name .
"Info index: sh-utils")
3907 (info-index .
"sh-utils")))
3908 ;; (anything 'anything-c-source-info-sh-utils)
3910 ;; Info Index textutils
3911 (defvar anything-c-source-info-textutils
3912 '((name .
"Info index: textutils")
3913 (info-index .
"textutils")))
3914 ;; (anything 'anything-c-source-info-textutils)
3917 (defvar anything-c-source-info-libc
3918 '((name .
"Info index: libc")
3919 (info-index .
"libc")))
3920 ;; (anything 'anything-c-source-info-libc)
3923 (defvar anything-c-source-info-make
3924 '((name .
"Info index: make")
3925 (info-index .
"make")))
3926 ;; (anything 'anything-c-source-info-make)
3928 ;; Info Index automake
3929 (defvar anything-c-source-info-automake
3930 '((name .
"Info index: automake")
3931 (info-index .
"automake")))
3932 ;; (anything 'anything-c-source-info-automake)
3934 ;; Info Index autoconf
3935 (defvar anything-c-source-info-autoconf
3936 '((name .
"Info index: autoconf")
3937 (info-index .
"autoconf")))
3938 ;; (anything 'anything-c-source-info-autoconf)
3940 ;; Info Index emacs-lisp-intro
3941 (defvar anything-c-source-info-emacs-lisp-intro
3942 '((name .
"Info index: emacs-lisp-intro")
3943 (info-index .
"emacs-lisp-intro")))
3944 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
3947 (defvar anything-c-source-info-emacs
3948 '((name .
"Info index: emacs")
3949 (info-index .
"emacs")))
3950 ;; (anything 'anything-c-source-info-emacs)
3953 (defvar anything-c-source-info-elib
3954 '((name .
"Info index: elib")
3955 (info-index .
"elib")))
3956 ;; (anything 'anything-c-source-info-elib)
3959 (defvar anything-c-source-info-eieio
3960 '((name .
"Info index: eieio")
3961 (info-index .
"eieio")))
3962 ;; (anything 'anything-c-source-info-eieio)
3964 ;; Info Index gauche-refe
3965 (defvar anything-c-source-info-gauche-refe
3966 '((name .
"Info index: gauche")
3967 (info-index .
"gauche-refe")))
3968 ;; (anything 'anything-c-source-info-gauche-refe)
3971 (defvar anything-c-source-info-guile
3972 '((name .
"Info index: guile")
3973 (info-index .
"guile")))
3974 ;; (anything 'anything-c-source-info-guile)
3976 ;; Info Index guile-tut
3977 (defvar anything-c-source-info-guile-tut
3978 '((name .
"Info index: guile-tut")
3979 (info-index .
"guile-tut")))
3980 ;; (anything 'anything-c-source-info-guile-tut)
3983 (defvar anything-c-source-info-goops
3984 '((name .
"Info index: goops")
3985 (info-index .
"goops")))
3986 ;; (anything 'anything-c-source-info-goops)
3988 ;; Info Index screen
3989 (defvar anything-c-source-info-screen
3990 '((name .
"Info index: screen")
3991 (info-index .
"screen")
3992 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
3993 ;; (anything 'anything-c-source-info-screen)
3996 (defvar anything-c-source-info-latex
3997 '((name .
"Info index: latex")
3998 (info-index .
"latex")))
3999 ;; (anything 'anything-c-source-info-latex)
4002 (defvar anything-c-source-info-gawk
4003 '((name .
"Info index: gawk")
4004 (info-index .
"gawk")))
4005 ;; (anything 'anything-c-source-info-gawk)
4008 (defvar anything-c-source-info-sed
4009 '((name .
"Info index: sed")
4010 (info-index .
"sed")))
4011 ;; (anything 'anything-c-source-info-sed)
4014 (defvar anything-c-source-info-m4
4015 '((name .
"Info index: m4")
4016 (info-index .
"m4")))
4017 ;; (anything 'anything-c-source-info-m4)
4020 (defvar anything-c-source-info-wget
4021 '((name .
"Info index: wget")
4022 (info-index .
"wget")))
4023 ;; (anything 'anything-c-source-info-wget)
4025 ;; Info Index binutils
4026 (defvar anything-c-source-info-binutils
4027 '((name .
"Info index: binutils")
4028 (info-index .
"binutils")))
4029 ;; (anything 'anything-c-source-info-binutils)
4032 (defvar anything-c-source-info-as
4033 '((name .
"Info index: as")
4034 (info-index .
"as")))
4035 ;; (anything 'anything-c-source-info-as)
4038 (defvar anything-c-source-info-bfd
4039 '((name .
"Info index: bfd")
4040 (info-index .
"bfd")))
4041 ;; (anything 'anything-c-source-info-bfd)
4044 (defvar anything-c-source-info-gprof
4045 '((name .
"Info index: gprof")
4046 (info-index .
"gprof")))
4047 ;; (anything 'anything-c-source-info-gprof)
4050 (defvar anything-c-source-info-ld
4051 '((name .
"Info index: ld")
4052 (info-index .
"ld")))
4053 ;; (anything 'anything-c-source-info-ld)
4056 (defvar anything-c-source-info-diff
4057 '((name .
"Info index: diff")
4058 (info-index .
"diff")))
4059 ;; (anything 'anything-c-source-info-diff)
4062 (defvar anything-c-source-info-flex
4063 '((name .
"Info index: flex")
4064 (info-index .
"flex")))
4065 ;; (anything 'anything-c-source-info-flex)
4068 (defvar anything-c-source-info-grep
4069 '((name .
"Info index: grep")
4070 (info-index .
"grep")))
4071 ;; (anything 'anything-c-source-info-grep)
4074 (defvar anything-c-source-info-gzip
4075 '((name .
"Info index: gzip")
4076 (info-index .
"gzip")))
4077 ;; (anything 'anything-c-source-info-gzip)
4079 ;; Info Index libtool
4080 (defvar anything-c-source-info-libtool
4081 '((name .
"Info index: libtool")
4082 (info-index .
"libtool")))
4083 ;; (anything 'anything-c-source-info-libtool)
4085 ;; Info Index texinfo
4086 (defvar anything-c-source-info-texinfo
4087 '((name .
"Info index: texinfo")
4088 (info-index .
"texinfo")))
4089 ;; (anything 'anything-c-source-info-texinfo)
4092 (defvar anything-c-source-info-info
4093 '((name .
"Info index: info")
4094 (info-index .
"info")))
4095 ;; (anything 'anything-c-source-info-info)
4098 (defvar anything-c-source-info-gdb
4099 '((name .
"Info index: gdb")
4100 (info-index .
"gdb")))
4101 ;; (anything 'anything-c-source-info-gdb)
4104 (defvar anything-c-source-info-stabs
4105 '((name .
"Info index: stabs")
4106 (info-index .
"stabs")))
4107 ;; (anything 'anything-c-source-info-stabs)
4109 ;; Info Index cvsbook
4110 (defvar anything-c-source-info-cvsbook
4111 '((name .
"Info index: cvsbook")
4112 (info-index .
"cvsbook")))
4113 ;; (anything 'anything-c-source-info-cvsbook)
4116 (defvar anything-c-source-info-cvs
4117 '((name .
"Info index: cvs")
4118 (info-index .
"cvs")))
4119 ;; (anything 'anything-c-source-info-cvs)
4122 (defvar anything-c-source-info-bison
4123 '((name .
"Info index: bison")
4124 (info-index .
"bison")))
4125 ;; (anything 'anything-c-source-info-bison)
4127 ;; Info Index id-utils
4128 (defvar anything-c-source-info-id-utils
4129 '((name .
"Info index: id-utils")
4130 (info-index .
"id-utils")))
4131 ;; (anything 'anything-c-source-info-id-utils)
4133 ;; Info Index global
4134 (defvar anything-c-source-info-global
4135 '((name .
"Info index: global")
4136 (info-index .
"global")))
4137 ;; (anything 'anything-c-source-info-global)
4141 (defvar anything-c-man-pages nil
4142 "All man pages on system.
4143 Will be calculated the first time you invoke anything with this
4146 (defun anything-c-man-default-action (candidate)
4147 "Default action for jumping to a woman or man page from anything."
4148 (let ((wfiles (woman-file-name-all-completions candidate
)))
4150 (if (> (length wfiles
) 1)
4151 (woman-find-file (anything-comp-read "ManFile: " wfiles
4153 ;; If woman is unable to format correctly
4156 (error (kill-buffer) ; Kill woman buffer.
4159 (defvar anything-c-source-man-pages
4160 `((name .
"Manual Pages")
4161 (candidates .
(lambda ()
4162 (if anything-c-man-pages
4163 anything-c-man-pages
4164 ;; XEmacs doesn't have a woman :)
4165 (setq anything-c-man-pages
4168 (woman-file-name "")
4169 (sort (mapcar 'car woman-topic-all-completions
)
4171 (action ("Show with Woman" . anything-c-man-default-action
))
4172 ;; Woman does not work OS X
4173 ;; http://xahlee.org/emacs/modernization_man_page.html
4174 (action-transformer .
(lambda (actions candidate
)
4175 (if (eq system-type
'darwin
)
4176 '(("Show with Man" . man
))
4178 (requires-pattern .
2)))
4179 ;; (anything 'anything-c-source-man-pages)
4182 ;;; Complex command history
4183 (defvar anything-c-source-complex-command-history
4184 '((name .
"Complex Command History")
4185 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
4187 ;; (anything 'anything-c-source-complex-command-history)
4190 (defvar anything-c-source-extended-command-history
4191 '((name .
"Emacs Commands History")
4192 (candidates . extended-command-history
)
4194 ;; (anything 'anything-c-source-extended-command-history)
4197 (defvar anything-c-source-emacs-commands
4198 '((name .
"Emacs Commands")
4199 (candidates .
(lambda ()
4201 (mapatoms (lambda (a)
4203 (push (symbol-name a
)
4205 (sort commands
'string-lessp
))))
4207 (requires-pattern .
2))
4208 "Source for completing and invoking Emacs commands.
4209 A command is a function with interactive spec that can
4210 be invoked with `M-x'.
4212 To get non-interactive functions listed, use
4213 `anything-c-source-emacs-functions'.")
4214 ;; (anything 'anything-c-source-emacs-commands)
4218 ;; Another replacement of `M-x' that act exactly like the
4219 ;; vanilla Emacs one, no problem of windows configuration, prefix args
4220 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
4221 ;; anything invocation.
4223 (defun anything-M-x ()
4224 "Preconfigured `anything' for Emacs commands.
4225 It is `anything' replacement of regular `M-x' `execute-extended-command'."
4227 (let* (in-help help-cand
4228 (command (anything-comp-read
4233 :name
"Emacs Commands"
4235 #'(lambda (candidate)
4236 (if (and in-help
(string= candidate help-cand
))
4237 (progn (kill-buffer "*Help*") (setq in-help nil
))
4238 (describe-function (intern candidate
))
4240 (setq help-cand candidate
))
4241 :persistent-help
"Describe this command"
4242 :history extended-command-history
4244 :fc-transformer
'anything-M-x-transformer
))
4245 (history (loop with hist
4246 for i in extended-command-history
4247 for com
= (intern i
)
4248 when
(and (fboundp com
) (not (member i hist
)))
4249 collect i into hist finally return hist
)))
4250 (unless current-prefix-arg
(setq current-prefix-arg anything-current-prefix-arg
))
4251 (call-interactively (intern command
))
4252 (setq extended-command-history
(cons command
(delete command history
)))))
4254 (defun* anything-M-x-get-major-mode-command-alist
(mode-map)
4255 "Return alist of MODE-MAP."
4256 (loop for key being the key-seqs of mode-map using
(key-bindings com
)
4257 for str-key
= (key-description key
)
4258 for ismenu
= (string-match "<menu-bar>" str-key
)
4259 unless ismenu collect
(cons str-key com
)))
4261 (defun anything-get-mode-map-from-mode (mode)
4262 "Guess the mode-map name according to MODE.
4263 Some modes don't use conventional mode-map name
4264 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
4265 Return nil if no mode-map found."
4267 ;; Start with a conventional mode-map name.
4268 with mode-map
= (intern-soft (format "%s-map" mode
))
4269 with mode-string
= (symbol-name mode
)
4270 with mode-name
= (replace-regexp-in-string "-mode" "" mode-string
)
4271 while
(not mode-map
)
4272 for count downfrom
(length mode-name
)
4273 ;; Return when no result after parsing entire string.
4274 when
(eq count
0) return nil
4275 for sub-name
= (substring mode-name
0 count
)
4276 do
(setq mode-map
(intern-soft (format "%s-map" (concat sub-name
"-mode"))))
4277 finally return mode-map
))
4279 (defun anything-M-x-current-mode-map-alist ()
4280 "Return mode-map alist of current `major-mode'."
4281 (let ((map (anything-get-mode-map-from-mode major-mode
)))
4282 (when (and map
(boundp map
))
4283 (anything-M-x-get-major-mode-command-alist (symbol-value map
)))))
4285 (defface anything-M-x-key-face
'((t (:foreground
"orange" :underline t
)))
4286 "*Face used in anything-M-x to show keybinding."
4289 (defun anything-M-x-transformer (candidates sources
)
4290 "filtered-candidate-transformer to show bindings in emacs commands.
4291 Show global bindings and local bindings according to current `major-mode'."
4293 with local-map
= (with-current-buffer anything-current-buffer
4294 (anything-M-x-current-mode-map-alist))
4296 for cand
= (symbol-name i
)
4297 for local-key
= (car (rassq i local-map
))
4298 for key
= (substitute-command-keys (format "\\[%s]" cand
))
4300 (cons (if (string-match "^M-x" key
)
4303 cand
" (" (propertize local-key
'face
'anything-M-x-key-face
)
4307 cand
" (" (propertize key
'face
'anything-M-x-key-face
) ")"))
4311 (defvar anything-c-source-lacarte
4312 '((name .
"Lacarte")
4313 (init .
(lambda () (require 'lacarte
)))
4314 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
4315 (candidate-number-limit .
9999)
4316 (action . anything-c-call-interactively
))
4319 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
4320 ;; (anything 'anything-c-source-lacarte)
4324 (defvar anything-c-source-emacs-functions
4325 '((name .
"Emacs Functions")
4326 (candidates .
(lambda ()
4328 (mapatoms (lambda (a)
4330 (push (symbol-name a
) commands
))))
4331 (sort commands
'string-lessp
))))
4333 (requires-pattern .
2))
4334 "Source for completing Emacs functions.")
4335 ;; (anything 'anything-c-source-emacs-functions)
4337 ;;; With abbrev expansion
4338 ;;; Similar to my exec-abbrev-cmd.el
4339 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
4340 (defvar anything-c-function-abbrev-regexp nil
4341 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
4342 Regexp built from the current `anything-pattern' interpreting it
4344 Only for internal use.")
4346 (defun anything-c-match-function-by-abbrev (candidate)
4347 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
4349 Abbreviations are made by taking the first character from each
4350 word in the function's name, e.g. \"bb\" is an abbrev for
4351 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
4352 (string-match anything-c-function-abbrev-regexp candidate
))
4354 (defvar anything-c-source-emacs-functions-with-abbrevs
4355 (append anything-c-source-emacs-functions
4356 '((match anything-c-match-function-by-abbrev
4357 anything-c-string-match
))
4360 (defadvice anything-update
4361 (before anything-c-update-function-abbrev-regexp activate
)
4362 (let ((char-list (append anything-pattern nil
))
4364 (dolist (c char-list
)
4365 (setq str
(concat str
(list c
) "[^-]*-")))
4366 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
4367 (setq anything-c-function-abbrev-regexp str
))))))))
4368 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
4370 (defvar anything-c-source-advice
4371 '((name .
"Function Advice")
4372 (candidates . anything-c-advice-candidates
)
4373 (action ("Toggle Enable/Disable" . anything-c-advice-toggle
))
4374 ;; (real-to-display . anything-c-advice-real-to-display)
4377 (persistent-action . anything-c-advice-persistent-action
)
4378 (persistent-help .
"Describe function / C-u C-z: Toggle advice")))
4379 ;; (anything 'anything-c-source-advice)
4380 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
4383 (defun anything-c-advice-candidates ()
4385 (loop for
(fname) in ad-advised-functions
4386 for function
= (intern fname
)
4388 (loop for class in ad-advice-classes append
4389 (loop for advice in
(ad-get-advice-info-field function class
)
4390 for enabled
= (ad-advice-enabled advice
)
4394 (if enabled
"Enabled " "Disabled")
4395 (propertize fname
'face
'font-lock-function-name-face
)
4396 (ad-make-single-advice-docstring advice class nil
))
4397 (list function class advice
))))))
4399 (defun anything-c-advice-persistent-action (func-class-advice)
4400 (if current-prefix-arg
4401 (anything-c-advice-toggle func-class-advice
)
4402 (describe-function (car func-class-advice
))))
4404 (defun anything-c-advice-toggle (func-class-advice)
4405 (destructuring-bind (function class advice
) func-class-advice
4406 (cond ((ad-advice-enabled advice
)
4407 (ad-advice-set-enabled advice nil
)
4408 (message "Disabled"))
4410 (ad-advice-set-enabled advice t
)
4411 (message "Enabled")))
4412 (ad-activate function
)
4413 (and anything-in-persistent-action
4414 (anything-c-advice-update-current-display-string))))
4416 (defun anything-c-advice-update-current-display-string ()
4417 (anything-edit-current-selection
4418 (let ((newword (cond ((looking-at "Disabled") "Enabled")
4419 ((looking-at "Enabled") "Disabled")))
4422 (delete-region (point) (progn (forward-word 1) (point)))
4423 (insert newword
)))))
4426 (defun anything-manage-advice ()
4427 "Preconfigured `anything' to disable/enable function advices."
4429 (anything-other-buffer 'anything-c-source-advice
"*anything advice*"))
4433 (defvar anything-c-source-emacs-variables
4434 '((name .
"Emacs Variables")
4435 (candidates .
(lambda ()
4436 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
4438 (requires-pattern .
2))
4439 "Source for completing Emacs variables.")
4440 ;; (anything 'anything-c-source-emacs-variables)
4444 (eval-when-compile (require 'bookmark
))
4445 (defvar anything-c-source-bookmarks
4446 '((name .
"Bookmarks")
4448 (require 'bookmark
)))
4449 (candidates . bookmark-all-names
)
4451 "See (info \"(emacs)Bookmarks\").")
4452 ;; (anything 'anything-c-source-bookmarks)
4455 (defvar anything-c-source-bookmark-set
4456 '((name .
"Set Bookmark")
4458 (action . bookmark-set
))
4459 "See (info \"(emacs)Bookmarks\").")
4460 ;; (anything 'anything-c-source-bookmark-set)
4462 ;;; Visible Bookmarks
4463 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
4466 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
4467 (defvar anything-c-source-bm
4468 '((name .
"Visible Bookmarks")
4469 (init . anything-c-bm-init
)
4470 (candidates-in-buffer)
4474 http://www.nongnu.org/bm/")
4476 (defun anything-c-bm-init ()
4477 "Init function for `anything-c-source-bm'."
4478 (when (require 'bm nil t
)
4480 (let ((bookmarks (bm-lists))
4481 (buf (anything-candidate-buffer 'global
)))
4482 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
4483 '< :key
'overlay-start
))
4484 (let ((start (overlay-start bm
))
4485 (end (overlay-end bm
))
4486 (annotation (or (overlay-get bm
'annotation
) "")))
4487 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
4488 (let ((str (format "%5d: [%s]: %s\n"
4489 (line-number-at-pos start
)
4491 (buffer-substring start
(1- end
)))))
4492 (with-current-buffer buf
(insert str
))))))))))
4494 ;;; Special bookmarks
4495 (defvar anything-c-source-bookmarks-ssh
4496 '((name .
"Bookmarks-ssh")
4498 (require 'bookmark
)))
4499 (candidates .
(lambda () (anything-c-collect-bookmarks :ssh t
)))
4501 "See (info \"(emacs)Bookmarks\").")
4502 ;; (anything 'anything-c-source-bookmarks-ssh)
4504 (defvar anything-c-source-bookmarks-su
4505 '((name .
"Bookmarks-root")
4507 (require 'bookmark
)))
4508 (candidates .
(lambda () (anything-c-collect-bookmarks :su t
)))
4509 (filtered-candidate-transformer anything-c-highlight-bookmark-su
)
4512 "See (info \"(emacs)Bookmarks\").")
4513 ;; (anything 'anything-c-source-bookmarks-su)
4515 (defvar anything-c-source-bookmarks-local
4516 '((name .
"Bookmarks-Local")
4518 (require 'bookmark
)))
4519 (candidates .
(lambda () (anything-c-collect-bookmarks :local t
)))
4520 (filtered-candidate-transformer
4521 anything-c-adaptive-sort
4522 anything-c-highlight-bookmark
)
4524 "See (info \"(emacs)Bookmarks\").")
4525 ;; (anything 'anything-c-source-bookmarks-local)
4527 (defun* anything-c-collect-bookmarks
(&key local su sudo ssh
)
4528 (let* ((lis-all (bookmark-all-names))
4529 (lis-loc (cond (local (loop for i in lis-all
4530 unless
(string-match "^(ssh)\\|^(su)" i
)
4532 (su (loop for i in lis-all
4533 when
(string-match "^(su)" i
)
4535 (sudo (loop for i in lis-all
4536 when
(string-match "^(sudo)" i
)
4538 (ssh (loop for i in lis-all
4539 when
(string-match "^(ssh)" i
)
4541 (sort lis-loc
'string-lessp
)))
4543 (defun anything-c-bookmark-root-logged-p ()
4545 (dolist (i (mapcar #'buffer-name
(buffer-list)))
4546 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
4547 (throw 'break t
)))))
4549 (defun anything-c-highlight-bookmark-su (files source
)
4550 (if (anything-c-bookmark-root-logged-p)
4551 (anything-c-highlight-bookmark files source
)
4552 (anything-c-highlight-not-logged files source
)))
4554 (defun anything-c-highlight-not-logged (files source
)
4555 (loop for i in files
4556 collect
(propertize i
'face anything-c-bookmarks-face3
)))
4558 (defun anything-c-highlight-bookmark (bookmarks source
)
4559 "Used as `candidate-transformer' to colorize bookmarks.
4560 Work both with standard Emacs bookmarks and bookmark-extensions.el."
4561 (loop for i in bookmarks
4562 for isfile
= (bookmark-get-filename i
)
4563 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
4564 (bmkext-get-buffer-name i
))
4565 for handlerp
= (and (fboundp 'bookmark-get-handler
)
4566 (bookmark-get-handler i
))
4567 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
4568 (bmkext-w3m-bookmark-p i
))
4569 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
4570 (bmkext-gnus-bookmark-p i
))
4571 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
4572 (bmkext-man-bookmark-p i
))
4573 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
4574 (bmkext-woman-bookmark-p i
))
4575 for handlerp
= (bookmark-get-handler i
)
4576 for isannotation
= (bookmark-get-annotation i
)
4577 for isabook
= (string= (bookmark-prop-get i
'type
) "addressbook")
4578 for isinfo
= (eq handlerp
'Info-bookmark-jump
)
4579 ;; Add a * if bookmark have annotation
4580 if
(and isannotation
(not (string-equal isannotation
"")))
4581 do
(setq i
(concat "*" i
))
4582 collect
(cond (;; info buffers
4584 (propertize i
'face
'anything-bmkext-info
'help-echo isfile
))
4587 (propertize i
'face
'anything-bmkext-w3m
'help-echo isfile
))
4590 (propertize i
'face
'anything-bmkext-gnus
'help-echo isfile
))
4593 (propertize i
'face
'anything-bmkext-man
'help-echo isfile
))
4596 (propertize i
'face
'((:foreground
"Tomato"))))
4598 (and isfile
(file-directory-p isfile
))
4599 (propertize i
'face anything-c-bookmarks-face1
'help-echo isfile
))
4602 (propertize i
'face
'anything-bmkext-file
'help-echo isfile
)))))
4605 ;;; Faces for bookmarks
4606 (defface anything-bmkext-info
4607 '((t (:foreground
"green")))
4608 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
4611 (defface anything-bmkext-w3m
4612 '((t (:foreground
"yellow")))
4613 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
4616 (defface anything-bmkext-gnus
4617 '((t (:foreground
"magenta")))
4618 "*Face used for Gnus bookmarks."
4621 (defface anything-bmkext-man
4622 '((t (:foreground
"Orange4")))
4623 "*Face used for Woman/man bookmarks."
4626 (defface anything-bmkext-no--file
4627 '((t (:foreground
"grey")))
4628 "*Face used for non--file bookmarks."
4631 (defface anything-bmkext-file
4632 '((t (:foreground
"Deepskyblue2")))
4633 "*Face used for non--file bookmarks."
4636 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
4637 "Face for su/sudo bookmarks."
4640 (defvar anything-c-bookmarks-face1
'anything-dir-heading
)
4641 (defvar anything-c-bookmarks-face2
'anything-file-name
)
4642 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
4645 ;;; Sources to filter bookmark-extensions bookmarks.
4646 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
4647 ;; If you want to enable google-maps in addressbook you will need
4648 ;; Julien Danjou google-maps-el package available here:
4649 ;; http://julien.danjou.info/google-maps-el.html
4651 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
4652 "Return a filtered `bookmark-alist' sorted alphabetically."
4654 with alist
= (if args
4655 (apply #'(lambda (x) (funcall fn x
)) args
)
4660 finally return
(sort sa
'string-lessp
)))
4663 (defvar anything-c-source-bmkext-addressbook
4664 '((name .
"Bookmark Addressbook")
4666 (require 'bookmark-extensions
)
4667 (bookmark-maybe-load-default-file)))
4668 (candidates . anything-c-bmkext-addressbook-setup-alist
)
4670 .
(lambda (candidate)
4671 (let ((bmk (anything-bookmark-get-bookmark-from-name
4673 (bookmark--jump-via bmk
'pop-to-buffer
))))
4674 (persistent-help .
"Show contact - Prefix with C-u to append")
4675 (filtered-candidate-transformer
4676 anything-c-adaptive-sort
4677 anything-c-highlight-bookmark
)
4678 (action .
(("Show person's data"
4679 .
(lambda (candidate)
4680 (let ((bmk (anything-bookmark-get-bookmark-from-name
4682 (current-prefix-arg anything-current-prefix-arg
))
4683 (bookmark-jump bmk
))))
4685 .
(lambda (candidate)
4686 (let ((bmk (anything-bookmark-get-bookmark-from-name
4688 (if anything-current-prefix-arg
4689 (addressbook-set-mail-buffer1 bmk
'append
)
4690 (addressbook-set-mail-buffer1 bmk
)))))
4692 .
(lambda (candidate)
4693 (let ((bmk (anything-bookmark-get-bookmark-from-name
4695 (addressbook-bookmark-edit
4696 (assoc bmk bookmark-alist
)))))
4697 ("Insert Email at point"
4698 .
(lambda (candidate)
4699 (let* ((bmk (anything-bookmark-get-bookmark-from-name
4701 (mlist (split-string
4703 'email
(assoc bmk bookmark-alist
))
4706 (if (> (length mlist
) 1)
4708 "Insert Mail Address: " mlist
:must-match t
)
4711 .
(lambda (candidate)
4712 (let ((bmk (anything-bookmark-get-bookmark-from-name
4714 (bookmark-show-annotation bmk
))))
4716 .
(lambda (candidate)
4717 (let ((bmk (anything-bookmark-get-bookmark-from-name
4719 (bookmark-edit-annotation bmk
))))
4721 .
(lambda (candidate)
4722 (let* ((bmk (anything-bookmark-get-bookmark-from-name
4724 (full-bmk (assoc bmk bookmark-alist
)))
4725 (addressbook-google-map full-bmk
))))))))
4728 (defun anything-c-bmkext-addressbook-setup-alist ()
4729 "Specialized filter function for bookmarks w3m."
4730 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only
))
4733 (defvar anything-c-source-bookmark-w3m
4734 '((name .
"Bookmark W3m")
4736 (require 'bookmark-extensions
)
4737 (bookmark-maybe-load-default-file)))
4738 (candidates . anything-c-bookmark-w3m-setup-alist
)
4739 (filtered-candidate-transformer
4740 anything-c-adaptive-sort
4741 anything-c-highlight-bookmark
)
4743 ;; (anything 'anything-c-source-bookmark-w3m)
4745 (defun anything-c-bookmark-w3m-setup-alist ()
4746 "Specialized filter function for bookmarks w3m."
4747 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
4750 (defvar anything-c-source-bookmark-images
4751 '((name .
"Bookmark Images")
4753 (require 'bookmark-extensions
)
4754 (bookmark-maybe-load-default-file)))
4755 (candidates . anything-c-bookmark-images-setup-alist
)
4756 (filtered-candidate-transformer
4757 anything-c-adaptive-sort
4758 anything-c-highlight-bookmark
)
4760 ;; (anything 'anything-c-source-bookmark-images)
4762 (defun anything-c-bookmark-images-setup-alist ()
4763 "Specialized filter function for images bookmarks."
4764 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only
))
4767 (defvar anything-c-source-bookmark-man
4768 '((name .
"Bookmark Woman&Man")
4770 (require 'bookmark-extensions
)
4771 (bookmark-maybe-load-default-file)))
4772 (candidates . anything-c-bookmark-man-setup-alist
)
4773 (filtered-candidate-transformer
4774 anything-c-adaptive-sort
4775 anything-c-highlight-bookmark
)
4777 ;; (anything 'anything-c-source-bookmark-man)
4779 (defun anything-c-bookmark-man-setup-alist ()
4780 "Specialized filter function for bookmarks w3m."
4781 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
4782 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
4785 (defvar anything-c-source-bookmark-gnus
4786 '((name .
"Bookmark Gnus")
4788 (require 'bookmark-extensions
)
4789 (bookmark-maybe-load-default-file)))
4790 (candidates . anything-c-bookmark-gnus-setup-alist
)
4791 (filtered-candidate-transformer
4792 anything-c-adaptive-sort
4793 anything-c-highlight-bookmark
)
4795 ;; (anything 'anything-c-source-bookmark-gnus)
4797 (defun anything-c-bookmark-gnus-setup-alist ()
4798 "Specialized filter function for bookmarks gnus."
4799 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
4802 (defvar anything-c-source-bookmark-info
4803 '((name .
"Bookmark Info")
4805 (require 'bookmark-extensions
)
4806 (bookmark-maybe-load-default-file)))
4807 (candidates . anything-c-bookmark-info-setup-alist
)
4808 (filtered-candidate-transformer
4809 anything-c-adaptive-sort
4810 anything-c-highlight-bookmark
)
4812 ;; (anything 'anything-c-source-bookmark-info)
4814 (defun anything-c-bookmark-info-setup-alist ()
4815 "Specialized filter function for bookmarks info."
4816 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
4818 ;; Local Files&directories
4819 (defvar anything-c-source-bookmark-files
&dirs
4820 '((name .
"Bookmark Files&Directories")
4822 (require 'bookmark-extensions
)
4823 (bookmark-maybe-load-default-file)))
4824 (candidates . anything-c-bookmark-local-files-setup-alist
)
4825 (filtered-candidate-transformer
4826 anything-c-adaptive-sort
4827 anything-c-highlight-bookmark
)
4829 ;; (anything 'anything-c-source-bookmark-files&dirs)
4831 (defun anything-c-bookmark-local-files-setup-alist ()
4832 "Specialized filter function for bookmarks locals files."
4833 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
4835 ;; Su Files&directories
4836 (defvar anything-c-source-bookmark-su-files
&dirs
4837 '((name .
"Bookmark Root-Files&Directories")
4839 (require 'bookmark-extensions
)
4840 (bookmark-maybe-load-default-file)))
4841 (candidates . anything-c-bookmark-su-files-setup-alist
)
4842 (filtered-candidate-transformer
4843 anything-c-adaptive-sort
4844 anything-c-highlight-bookmark-su
)
4846 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
4848 (defun anything-c-bookmark-su-files-setup-alist ()
4849 "Specialized filter function for bookmarks su/sudo files."
4851 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
4853 for isfile
= (bookmark-get-filename i
)
4854 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
4856 (string-match tramp-file-name-regexp isfile
)))
4857 for issu
= (and istramp
4858 (string-match bmkext-su-or-sudo-regexp isfile
))
4862 ;; Ssh Files&directories
4863 (defvar anything-c-source-bookmark-ssh-files
&dirs
4864 '((name .
"Bookmark Ssh-Files&Directories")
4866 (require 'bookmark-extensions
)
4867 (bookmark-maybe-load-default-file)))
4868 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
4869 (filtered-candidate-transformer . anything-c-adaptive-sort
)
4871 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
4873 (defun anything-c-bookmark-ssh-files-setup-alist ()
4874 "Specialized filter function for bookmarks ssh files."
4876 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
4878 for isfile
= (bookmark-get-filename i
)
4879 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
4881 (string-match tramp-file-name-regexp isfile
)))
4882 for isssh
= (and istramp
4883 (string-match "/ssh:" isfile
))
4888 ;; All bookmark-extensions sources.
4890 (defun anything-bookmark-ext ()
4891 "Preconfigured `anything' for bookmark-extensions sources.
4892 Needs bookmark-ext.el
4894 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
4898 '(anything-c-source-bookmark-files&dirs
4899 anything-c-source-bookmark-w3m
4900 anything-c-source-bmkext-addressbook
4901 anything-c-source-bookmark-gnus
4902 anything-c-source-bookmark-info
4903 anything-c-source-bookmark-man
4904 anything-c-source-bookmark-images
4905 anything-c-source-bookmark-su-files
&dirs
4906 anything-c-source-bookmark-ssh-files
&dirs
)
4907 :prompt
"SearchBookmark: "
4908 :buffer
"*anything bmkext*"))
4911 ;; Firefox bookmarks
4912 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
4913 ;; (only for firefox versions >=3)
4914 ;; To achieve that, open about:config in firefox and double click on this line to enable value
4916 ;; user_pref("browser.bookmarks.autoExportHTML", false);
4917 ;; You should have now:
4918 ;; user_pref("browser.bookmarks.autoExportHTML", true);
4920 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
4921 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
4923 (defun anything-get-firefox-user-init-dir ()
4924 "Guess the default Firefox user directory name."
4925 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
4927 (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
4928 (goto-char (point-min))
4930 (when (search-forward "Path=" nil t
)
4931 (buffer-substring-no-properties (point) (point-at-eol)))
4933 (file-name-as-directory (concat moz-dir moz-user-dir
))))
4935 (defun anything-guess-firefox-bookmark-file ()
4936 "Return the path of the Firefox bookmarks file."
4937 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
4939 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
4940 "Parse html bookmark FILE and return an alist with (title . url) as elements."
4941 (let (bookmarks-alist url title
)
4943 (insert-file-contents file
)
4944 (goto-char (point-min))
4945 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
4947 (when (re-search-forward url-regexp nil t
)
4948 (setq url
(match-string 0)))
4949 (when (re-search-forward bmk-regexp nil t
)
4950 (setq title
(match-string 1)))
4951 (push (cons title url
) bookmarks-alist
)
4953 (nreverse bookmarks-alist
)))
4955 (defvar anything-c-firefox-bookmarks-alist nil
)
4956 (defvar anything-c-source-firefox-bookmarks
4957 '((name .
"Firefox Bookmarks")
4959 (setq anything-c-firefox-bookmarks-alist
4960 (anything-html-bookmarks-to-alist
4961 (anything-guess-firefox-bookmark-file)
4962 anything-firefox-bookmark-url-regexp
4963 anything-firefox-bookmarks-regexp
))))
4964 (candidates .
(lambda ()
4965 (mapcar #'car anything-c-firefox-bookmarks-alist
)))
4966 (filtered-candidate-transformer
4967 anything-c-adaptive-sort
4968 anything-c-highlight-firefox-bookmarks
)
4969 (action .
(("Browse Url Firefox"
4970 .
(lambda (candidate)
4972 (anything-c-firefox-bookmarks-get-value candidate
))))
4974 .
(lambda (candidate)
4976 (anything-c-firefox-bookmarks-get-value candidate
))))
4979 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
4981 ;; (anything 'anything-c-source-firefox-bookmarks)
4983 (defun anything-c-firefox-bookmarks-get-value (elm)
4984 (assoc-default elm anything-c-firefox-bookmarks-alist
))
4986 (defun anything-c-highlight-firefox-bookmarks (bookmarks source
)
4987 (loop for i in bookmarks
4989 i
'face
'((:foreground
"YellowGreen"))
4990 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
4994 ;; Some users have the emacs-w3m library in load-path
4995 ;; without having the w3m executable :-;
4996 ;; So check if w3m program is present before trying to load
4999 (when (executable-find "w3m")
5000 (require 'w3m-bookmark nil t
)))
5001 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html")
5004 (defface anything-w3m-bookmarks-face
'((t (:foreground
"cyan1" :underline t
)))
5005 "Face for w3m bookmarks" :group
'anything
)
5007 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
5008 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
5009 (defvar anything-c-w3m-bookmarks-alist nil
)
5010 (defvar anything-c-source-w3m-bookmarks
5011 '((name .
"W3m Bookmarks")
5013 (setq anything-c-w3m-bookmarks-alist
5014 (anything-html-bookmarks-to-alist
5016 anything-w3m-bookmark-url-regexp
5017 anything-w3m-bookmarks-regexp
))))
5018 (candidates .
(lambda ()
5019 (mapcar #'car anything-c-w3m-bookmarks-alist
)))
5020 (filtered-candidate-transformer
5021 anything-c-adaptive-sort
5022 anything-c-highlight-w3m-bookmarks
)
5023 (action .
(("Browse Url"
5024 .
(lambda (candidate)
5025 (anything-c-w3m-browse-bookmark candidate
)))
5028 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
5029 ("Browse Url Firefox"
5030 .
(lambda (candidate)
5031 (anything-c-w3m-browse-bookmark candidate t
)))
5033 .
(lambda (candidate)
5034 (anything-c-w3m-delete-bookmark candidate
)))
5036 .
(lambda (candidate)
5037 (anything-c-w3m-rename-bookmark candidate
)))))
5038 (persistent-action .
(lambda (candidate)
5039 (if current-prefix-arg
5040 (anything-c-w3m-browse-bookmark candidate t
)
5041 (anything-c-w3m-browse-bookmark candidate nil t
))))
5042 (persistent-help .
"Open URL with emacs-w3m in new tab / \
5043 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
5044 "Needs w3m and emacs-w3m.
5046 http://w3m.sourceforge.net/
5047 http://emacs-w3m.namazu.org/")
5049 ;; (anything 'anything-c-source-w3m-bookmarks)
5051 (defun anything-c-w3m-bookmarks-get-value (elm)
5052 (replace-regexp-in-string
5053 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist
))))
5055 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
5056 (let* ((fn (if use-firefox
'browse-url-firefox
'w3m-browse-url
))
5057 (arg (and (eq fn
'w3m-browse-url
) new-tab
)))
5058 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
5060 (defun anything-c-highlight-w3m-bookmarks (bookmarks source
)
5061 (loop for i in bookmarks
5063 i
'face
'anything-w3m-bookmarks-face
5064 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
5067 (defun anything-c-w3m-delete-bookmark (elm)
5069 (find-file-literally w3m-bookmark-file
)
5070 (goto-char (point-min))
5071 (when (re-search-forward elm nil t
)
5073 (delete-region (point)
5074 (line-end-position))
5075 (delete-blank-lines))
5076 (save-buffer (current-buffer))
5077 (kill-buffer (current-buffer))))
5079 (defun anything-c-w3m-rename-bookmark (elm)
5080 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
5081 (new-title (read-string "NewTitle: " old-title
)))
5083 (find-file-literally w3m-bookmark-file
)
5084 (goto-char (point-min))
5085 (when (re-search-forward (concat elm
"<") nil t
)
5086 (goto-char (1- (point)))
5087 (delete-char (- (length old-title
)))
5089 (save-buffer (current-buffer))
5090 (kill-buffer (current-buffer)))))
5093 ;;; Elisp library scan
5094 (defvar anything-c-source-elisp-library-scan
5095 '((name .
"Elisp libraries (Scan)")
5096 (init .
(anything-c-elisp-library-scan-init))
5097 (candidates-in-buffer)
5098 (action ("Find library"
5099 .
(lambda (candidate) (find-file (find-library-name candidate
))))
5100 ("Find library other window"
5101 .
(lambda (candidate)
5102 (find-file-other-window (find-library-name candidate
))))
5104 .
(lambda (candidate) (load-library candidate
))))))
5105 ;; (anything 'anything-c-source-elisp-library-scan)
5107 (defun anything-c-elisp-library-scan-init ()
5108 "Init anything buffer status."
5109 (let ((anything-buffer (anything-candidate-buffer 'global
))
5110 (library-list (anything-c-elisp-library-scan-list)))
5111 (with-current-buffer anything-buffer
5112 (dolist (library library-list
)
5113 (insert (format "%s\n" library
))))))
5115 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
5116 "Do completion for file names passed to `locate-file'.
5117 DIRS is directory to search path.
5118 STRING is string to match."
5119 ;; Use `load-path' as path when ignore `dirs'.
5120 (or dirs
(setq dirs load-path
))
5121 ;; Init with blank when ignore `string'.
5122 (or string
(setq string
""))
5123 ;; Get library list.
5124 (let ((string-dir (file-name-directory string
))
5125 ;; File regexp that suffix match `load-file-rep-suffixes'.
5126 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
5131 (setq dir default-directory
))
5133 (setq dir
(expand-file-name string-dir dir
)))
5134 (when (file-directory-p dir
)
5135 (dolist (file (file-name-all-completions
5136 (file-name-nondirectory string
) dir
))
5137 ;; Suffixes match `load-file-rep-suffixes'.
5138 (setq name
(if string-dir
(concat string-dir file
) file
))
5139 (if (string-match match-regexp name
)
5140 (add-to-list 'names name
)))))
5145 (defvar anything-c-imenu-delimiter
" / ")
5147 (defvar anything-c-imenu-index-filter nil
)
5148 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
5150 (defvar anything-c-cached-imenu-alist nil
)
5151 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
5153 (defvar anything-c-cached-imenu-candidates nil
)
5154 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
5156 (defvar anything-c-cached-imenu-tick nil
)
5157 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
5159 (eval-when-compile (require 'imenu
))
5160 (setq imenu-auto-rescan t
)
5162 (defun anything-imenu-create-candidates (entry)
5163 "Create candidates with ENTRY."
5164 (if (listp (cdr entry
))
5167 (if (consp (cdr sub
))
5170 (concat (car entry
) anything-c-imenu-delimiter subentry
))
5171 (anything-imenu-create-candidates sub
))
5172 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
5176 (defvar anything-c-source-imenu
5178 (init .
(lambda () (require 'imenu
)))
5179 (candidates . anything-c-imenu-candidates
)
5180 (persistent-action .
(lambda (elm)
5181 (anything-c-imenu-default-action elm
)
5182 (unless (fboundp 'semantic-imenu-tag-overlay
)
5183 (anything-match-line-color-current-line))))
5184 (persistent-help .
"Show this entry")
5185 (action . anything-c-imenu-default-action
))
5186 "See (info \"(emacs)Imenu\")")
5188 ;; (anything 'anything-c-source-imenu)
5190 (defun anything-c-imenu-candidates ()
5191 (with-current-buffer anything-current-buffer
5192 (let ((tick (buffer-modified-tick)))
5193 (if (eq anything-c-cached-imenu-tick tick
)
5194 anything-c-cached-imenu-candidates
5195 (setq imenu--index-alist nil
)
5196 (setq anything-c-cached-imenu-tick tick
5197 anything-c-cached-imenu-candidates
5200 'anything-imenu-create-candidates
5201 (setq anything-c-cached-imenu-alist
5202 (let ((index (imenu--make-index-alist)))
5203 (if anything-c-imenu-index-filter
5204 (funcall anything-c-imenu-index-filter index
)
5206 (setq anything-c-cached-imenu-candidates
5207 (mapcar #'(lambda (x)
5211 anything-c-cached-imenu-candidates
))))))
5213 (setq imenu-default-goto-function
'imenu-default-goto-function
)
5214 (defun anything-c-imenu-default-action (elm)
5215 "The default action for `anything-c-source-imenu'."
5216 (let ((path (split-string elm anything-c-imenu-delimiter
))
5217 (alist anything-c-cached-imenu-alist
))
5219 (setq alist
(assoc elm alist
)))
5223 (defvar anything-c-ctags-modes
5224 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
5225 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
5226 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
5228 (defun anything-c-source-ctags-init ()
5229 (when (and buffer-file-name
5230 (memq major-mode anything-c-ctags-modes
)
5231 (anything-current-buffer-is-modified))
5232 (with-current-buffer (anything-candidate-buffer 'local
)
5233 (call-process-shell-command
5234 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
5235 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
5236 anything-buffer-file-name
)
5237 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
5238 nil
(current-buffer))
5239 (goto-char (point-min))
5241 (delete-region (point-min) (point))
5242 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
5243 for lineno-start
= (point)
5244 for lineno
= (buffer-substring
5246 (1- (search-forward "," (point-at-eol) t
)))
5249 (insert (format "%5s:" lineno
))
5250 (search-forward "\177" (point-at-eol) t
)
5251 (delete-region (1- (point)) (point-at-eol))
5252 (forward-line 1)))))
5254 (defvar anything-c-source-ctags
5255 '((name .
"Exuberant ctags")
5256 (init . anything-c-source-ctags-init
)
5257 (candidates-in-buffer)
5260 "Needs Exuberant Ctags.
5262 http://ctags.sourceforge.net/")
5263 ;; (anything 'anything-c-source-ctags)
5266 (eval-when-compile (require 'semantic nil t
))
5267 (declare-function semantic-format-tag-summarize
"ext:format.el" (tag &optional parent color
) t
)
5268 (declare-function semantic-tag-components
"ext:tag.el" (tag) t
)
5269 (declare-function semantic-go-to-tag
"ext:tag-file.el" (tag) t
)
5270 (declare-function semantic-tag-type
"ext:tag-file.el" (tag) t
)
5271 (declare-function semantic-tag-class
"ext:tag-file.el" (tag) t
)
5272 (defvar anything-semantic-candidates nil
)
5274 (defun anything-semantic-construct-candidates (tags depth
)
5275 (when (require 'semantic nil t
)
5281 (let ((type (semantic-tag-type tag
))
5282 (class (semantic-tag-class tag
)))
5283 (if (or (and (stringp type
)
5284 (or (string= type
"class")
5285 (string= type
"namespace")))
5286 (eq class
'function
)
5287 (eq class
'variable
))
5288 (cons (cons (concat (make-string (* depth
2) ?\s
)
5289 (semantic-format-tag-summarize tag nil t
))
5291 (anything-semantic-construct-candidates
5292 (semantic-tag-components tag
) (1+ depth
)))))))
5295 (defun anything-semantic-default-action (candidate)
5296 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
5297 (semantic-go-to-tag tag
)))
5299 (defvar anything-c-source-semantic
5300 '((name .
"Semantic Tags")
5302 (setq anything-semantic-candidates
5303 (ignore-errors (anything-semantic-construct-candidates
5304 (semantic-fetch-tags) 0)))))
5305 (candidates .
(lambda ()
5306 (if anything-semantic-candidates
5307 (mapcar 'car anything-semantic-candidates
))))
5308 (persistent-action .
(lambda (elm)
5309 (anything-semantic-default-action elm
)
5310 (anything-match-line-color-current-line)))
5311 (persistent-help .
"Show this entry")
5312 (action . anything-semantic-default-action
)
5313 "Needs semantic in CEDET.
5315 http://cedet.sourceforge.net/semantic.shtml
5316 http://cedet.sourceforge.net/"))
5318 ;; (anything 'anything-c-source-semantic)
5320 ;;; Function is called by
5322 (defun anything-simple-call-tree ()
5323 "Preconfigured `anything' for simple-call-tree. List function relationships.
5325 Needs simple-call-tree.el.
5326 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
5328 (anything-other-buffer
5329 '(anything-c-source-simple-call-tree-functions-callers
5330 anything-c-source-simple-call-tree-callers-functions
)
5331 "*anything simple-call-tree*"))
5333 (defvar anything-c-source-simple-call-tree-functions-callers
5334 '((name .
"Function is called by")
5335 (init . anything-c-simple-call-tree-functions-callers-init
)
5337 (candidates . anything-c-simple-call-tree-candidates
)
5338 (persistent-action . anything-c-simple-call-tree-persistent-action
)
5339 (persistent-help .
"Show function definitions by rotation")
5340 (action ("Find definition selected by persistent-action" .
5341 anything-c-simple-call-tree-find-definition
)))
5342 "Needs simple-call-tree.el.
5343 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
5345 (defvar anything-c-simple-call-tree-tick nil
)
5346 (make-variable-buffer-local 'anything-c-simple-call-tree-tick
)
5347 (defun anything-c-simple-call-tree-analyze-maybe ()
5348 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick
)
5349 (simple-call-tree-analyze)
5350 (setq anything-c-simple-call-tree-tick
(buffer-chars-modified-tick))))
5352 (defun anything-c-simple-call-tree-init-base (function message
)
5353 (require 'simple-call-tree
)
5355 (when (anything-current-buffer-is-modified)
5356 (anything-c-simple-call-tree-analyze-maybe)
5357 (let ((list (funcall function simple-call-tree-alist
)))
5358 (with-current-buffer (anything-candidate-buffer 'local
)
5359 (dolist (entry list
)
5360 (let ((funcs (concat " " (mapconcat #'identity
(cdr entry
) "\n "))))
5361 (insert (car entry
) message
5362 (if (string= funcs
" ")
5367 (defun anything-c-simple-call-tree-functions-callers-init ()
5368 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
5371 (defun anything-c-simple-call-tree-candidates ()
5372 (with-current-buffer (anything-candidate-buffer)
5373 (split-string (buffer-string) "\n\n")))
5375 (defvar anything-c-simple-call-tree-related-functions nil
)
5376 (defvar anything-c-simple-call-tree-function-index
0)
5377 (defun anything-c-simple-call-tree-persistent-action (candidate)
5378 (unless (eq last-command
'anything-execute-persistent-action
)
5379 (setq anything-c-simple-call-tree-related-functions
5380 (delete "no functions."
5382 (replace-regexp-in-string " \\| is called by\\| calls "
5385 (setq anything-c-simple-call-tree-function-index -
1))
5386 (incf anything-c-simple-call-tree-function-index
)
5387 (anything-c-simple-call-tree-find-definition candidate
))
5389 (defun anything-c-simple-call-tree-find-definition (candidate)
5392 (nth (mod anything-c-simple-call-tree-function-index
5393 (length anything-c-simple-call-tree-related-functions
))
5394 anything-c-simple-call-tree-related-functions
))))
5396 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
5399 (defvar anything-c-source-simple-call-tree-callers-functions
5400 '((name .
"Function calls")
5401 (init . anything-c-simple-call-tree-callers-functions-init
)
5403 (candidates . anything-c-simple-call-tree-candidates
)
5404 (persistent-action . anything-c-simple-call-tree-persistent-action
)
5405 (persistent-help .
"Show function definitions by rotation")
5406 (action ("Find definition selected by persistent-action" .
5407 anything-c-simple-call-tree-find-definition
)))
5408 "Needs simple-call-tree.el.
5409 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
5411 (defun anything-c-simple-call-tree-callers-functions-init ()
5412 (anything-c-simple-call-tree-init-base 'identity
" calls \n"))
5414 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
5416 ;;; Commands/Options with doc
5417 (defvar anything-c-auto-document-data nil
)
5418 (make-variable-buffer-local 'anything-c-auto-document-data
)
5419 (defvar anything-c-source-commands-and-options-in-file
5420 '((name .
"Commands/Options in file")
5422 .
(lambda (x) (format "Commands/Options in %s"
5423 (buffer-local-value 'buffer-file-name
5424 anything-current-buffer
))))
5425 (candidates . anything-command-and-options-candidates
)
5428 "List Commands and Options with doc. It needs auto-document.el .
5430 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
5432 (eval-when-compile (require 'auto-document nil t
))
5433 (defun anything-command-and-options-candidates ()
5434 (with-current-buffer anything-current-buffer
5435 (when (and (require 'auto-document nil t
)
5436 (eq major-mode
'emacs-lisp-mode
)
5437 (or (anything-current-buffer-is-modified)
5438 (not anything-c-auto-document-data
)))
5439 (or imenu--index-alist
(imenu--make-index-alist t
))
5440 (setq anything-c-auto-document-data
5441 (destructuring-bind (commands options
)
5442 (adoc-construct anything-current-buffer
)
5444 (loop for
(command . doc
) in commands
5445 for cmdname
= (symbol-name command
)
5448 (format "Command: %s\n %s"
5449 (propertize cmdname
'face font-lock-function-name-face
)
5450 (adoc-first-line doc
))
5451 (assoc cmdname imenu--index-alist
)))
5452 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
5453 for
(option doc default
) in options
5454 for optname
= (symbol-name option
)
5457 (format "Option: %s\n %s\n default = %s"
5458 (propertize optname
'face font-lock-variable-name-face
)
5459 (adoc-first-line doc
)
5460 (adoc-prin1-to-string default
))
5463 anything-c-auto-document-data
))
5465 ;; (anything 'anything-c-source-commands-and-options-in-file)
5467 ;;;; <Color and Face>
5469 (defvar anything-c-source-customize-face
5470 '((name .
"Customize Face")
5472 (unless (anything-candidate-buffer)
5473 (save-window-excursion (list-faces-display))
5474 (anything-candidate-buffer (get-buffer "*Faces*")))))
5475 (candidates-in-buffer)
5476 (get-line . buffer-substring
)
5477 (action .
(lambda (line)
5478 (customize-face (intern (car (split-string line
))))))
5479 (requires-pattern .
3))
5480 "See (info \"(emacs)Faces\")")
5481 ;; (anything 'anything-c-source-customize-face)
5484 (defvar anything-c-source-colors
5486 (init .
(lambda () (unless (anything-candidate-buffer)
5487 (save-window-excursion (list-colors-display))
5488 (anything-candidate-buffer (get-buffer "*Colors*")))))
5489 (candidates-in-buffer)
5490 (get-line . buffer-substring
)
5492 ("Copy Name" .
(lambda (candidate)
5493 (kill-new (anything-c-colors-get-name candidate
))))
5494 ("Copy RGB" .
(lambda (candidate)
5495 (kill-new (anything-c-colors-get-rgb candidate
))))
5496 ("Insert Name" .
(lambda (candidate)
5497 (with-current-buffer anything-current-buffer
5498 (insert (anything-c-colors-get-name candidate
)))))
5499 ("Insert RGB" .
(lambda (candidate)
5500 (with-current-buffer anything-current-buffer
5501 (insert (anything-c-colors-get-rgb candidate
))))))))
5502 ;; (anything 'anything-c-source-colors)
5504 (defun anything-c-colors-get-name (candidate)
5506 (replace-regexp-in-string
5509 (insert (capitalize candidate
))
5510 (goto-char (point-min))
5511 (search-forward-regexp "\\s-\\{2,\\}")
5512 (delete-region (point) (point-max))
5515 (defun anything-c-colors-get-rgb (candidate)
5517 (replace-regexp-in-string
5520 (insert (capitalize candidate
))
5521 (goto-char (point-max))
5522 (search-backward-regexp "\\s-\\{2,\\}")
5523 (delete-region (point) (point-min))
5526 ;;;; <Search Engine>
5527 ;;; Tracker desktop search
5528 (defvar anything-c-source-tracker-search
5529 '((name .
"Tracker Search")
5530 (candidates .
(lambda ()
5531 (start-process "tracker-search-process" nil
5535 (requires-pattern .
3)
5537 "Source for retrieving files matching the current input pattern
5538 with the tracker desktop search.")
5539 ;; (anything 'anything-c-source-tracker-search)
5541 ;;; Spotlight (MacOS X desktop search)
5542 (defvar anything-c-source-mac-spotlight
5545 .
(lambda () (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
5547 (requires-pattern .
3)
5549 "Source for retrieving files via Spotlight's command line
5551 ;; (anything 'anything-c-source-mac-spotlight)
5556 (defvar anything-c-source-kill-ring
5557 '((name .
"Kill Ring")
5558 (init .
(lambda () (anything-attrset 'last-command last-command
)))
5559 (candidates . anything-c-kill-ring-candidates
)
5560 (action . anything-c-kill-ring-action
)
5564 "Source for browse and insert contents of kill-ring.")
5566 (defun anything-c-kill-ring-candidates ()
5567 (loop for kill in kill-ring
5568 unless
(or (< (length kill
) anything-kill-ring-threshold
)
5569 (string-match "^[\\s\\t]+$" kill
))
5572 (defun anything-c-kill-ring-action (str)
5573 "Insert STR in `kill-ring' and set STR to the head.
5574 If this action is executed just after `yank',
5575 replace with STR as yanked string."
5576 (setq kill-ring
(delete str kill-ring
))
5577 (if (not (eq (anything-attr 'last-command
) 'yank
))
5578 (insert-for-yank str
)
5580 (let ((inhibit-read-only t
)
5581 (before (< (point) (mark t
))))
5583 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
5584 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
5585 (setq yank-undo-function nil
)
5586 (set-marker (mark-marker) (point) (current-buffer))
5587 (insert-for-yank str
)
5588 ;; Set the window start back where it was in the yank command,
5590 (set-window-start (selected-window) yank-window-start t
)
5592 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
5593 ;; It is cleaner to avoid activation, even though the command
5594 ;; loop would deactivate the mark because we inserted text.
5595 (goto-char (prog1 (mark t
)
5596 (set-marker (mark-marker) (point) (current-buffer)))))))
5599 ;; (anything 'anything-c-source-kill-ring)
5602 ;; DO NOT include these sources in `anything-sources' use
5603 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
5604 ;; `anything-all-mark-rings' instead.
5606 (defun anything-c-source-mark-ring-candidates ()
5607 (flet ((get-marks (pos)
5611 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
5612 (when (string= "" line
)
5613 (setq line
"<EMPTY LINE>"))
5614 (format "%7d: %s" (line-number-at-pos) line
)))))
5615 (with-current-buffer anything-current-buffer
5617 with marks
= (cons (mark-marker) mark-ring
)
5620 for m
= (get-marks i
)
5621 unless
(member m recip
)
5622 collect m into recip
5623 finally return recip
))))
5625 (defvar anything-mark-ring-cache nil
)
5626 (defvar anything-c-source-mark-ring
5627 '((name .
"mark-ring")
5629 (setq anything-mark-ring-cache
5630 (ignore-errors (anything-c-source-mark-ring-candidates)))))
5631 (candidates .
(lambda ()
5632 (anything-aif anything-mark-ring-cache
5634 (action .
(("Goto line"
5635 .
(lambda (candidate)
5636 (anything-goto-line (string-to-number candidate
))))))
5637 (persistent-action .
(lambda (candidate)
5638 (anything-goto-line (string-to-number candidate
))
5639 (anything-match-line-color-current-line)))
5640 (persistent-help .
"Show this line")))
5642 ;; (anything 'anything-c-source-mark-ring)
5645 (defun anything-mark-ring ()
5646 "Preconfigured `anything' for `anything-c-source-mark-ring'."
5648 (anything 'anything-c-source-mark-ring
))
5650 ;;; Global-mark-ring
5651 (defvar anything-c-source-global-mark-ring
5652 '((name .
"global-mark-ring")
5653 (candidates . anything-c-source-global-mark-ring-candidates
)
5654 (action .
(("Goto line"
5655 .
(lambda (candidate)
5656 (let ((items (split-string candidate
":")))
5657 (switch-to-buffer (second items
))
5658 (anything-goto-line (string-to-number (car items
))))))))
5659 (persistent-action .
(lambda (candidate)
5660 (let ((items (split-string candidate
":")))
5661 (switch-to-buffer (second items
))
5662 (anything-goto-line (string-to-number (car items
)))
5663 (anything-match-line-color-current-line))))
5664 (persistent-help .
"Show this line")))
5666 (defun anything-c-source-global-mark-ring-candidates ()
5668 (with-current-buffer (marker-buffer m
)
5672 (if (string= "" line
)
5673 (setq line
"<EMPTY LINE>")
5674 (setq line
(car (split-string (thing-at-point 'line
)
5676 (format "%7d:%s: %s"
5677 (line-number-at-pos) (marker-buffer m
) line
)))))
5679 with marks
= global-mark-ring
5682 for gm
= (unless (or (string-match
5683 "^ " (format "%s" (marker-buffer i
)))
5684 (null (marker-buffer i
)))
5686 when
(and gm
(not (member gm recip
)))
5687 collect gm into recip
5688 finally return recip
)))
5690 ;; (anything 'anything-c-source-global-mark-ring)
5693 (defun anything-global-mark-ring ()
5694 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
5696 (anything 'anything-c-source-global-mark-ring
))
5699 (defun anything-all-mark-rings ()
5700 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
5701 `anything-c-source-mark-ring'."
5703 (anything '(anything-c-source-mark-ring
5704 anything-c-source-global-mark-ring
)))
5707 ;;; Insert from register
5708 (defvar anything-c-source-register
5709 '((name .
"Registers")
5710 (candidates . anything-c-register-candidates
)
5711 (action-transformer . anything-c-register-action-transformer
)
5714 "See (info \"(emacs)Registers\")")
5716 (defun anything-c-register-candidates ()
5717 "Collecting register contents and appropriate commands."
5718 (loop for
(char . val
) in register-alist
5719 for key
= (single-key-description char
)
5720 for string-actions
=
5723 (list (int-to-string val
)
5725 'increment-register
))
5727 (let ((buf (marker-buffer val
)))
5729 (list "a marker in no buffer")
5731 "a buffer position:"
5734 (int-to-string (marker-position val
)))
5736 'insert-register
))))
5737 ((and (consp val
) (window-configuration-p (car val
)))
5738 (list "window configuration."
5740 ((and (consp val
) (frame-configuration-p (car val
)))
5741 (list "frame configuration."
5743 ((and (consp val
) (eq (car val
) 'file
))
5744 (list (concat "file:"
5745 (prin1-to-string (cdr val
))
5748 ((and (consp val
) (eq (car val
) 'file-query
))
5749 (list (concat "file:a file-query reference: file "
5752 (int-to-string (car (cdr (cdr val
))))
5756 (let ((lines (format "%4d" (length val
))))
5757 (list (format "%s: %s\n" lines
5758 (truncate-string-to-width
5759 (mapconcat 'identity
(list (car val
))
5760 ;; (mapconcat (lambda (y) y) val
5761 "^J") (- (window-width) 15)))
5764 (list ;; without properties
5765 (substring-no-properties val
)
5768 'prepend-to-register
))
5771 collect
(cons (format "register %3s: %s" key
(car string-actions
))
5772 (cons char
(cdr string-actions
)))))
5774 (defun anything-c-register-action-transformer (actions register-and-functions
)
5775 "Decide actions by the contents of register."
5776 (loop with func-actions
=
5779 (lambda (c) (insert-register (car c
))))
5781 "Jump to Register" .
5782 (lambda (c) (jump-to-register (car c
))))
5784 "Append Region to Register" .
5785 (lambda (c) (append-to-register
5786 (car c
) (region-beginning) (region-end))))
5787 (prepend-to-register
5788 "Prepend Region to Register" .
5789 (lambda (c) (prepend-to-register
5790 (car c
) (region-beginning) (region-end))))
5792 "Increment Prefix Arg to Register" .
5793 (lambda (c) (increment-register
5794 anything-current-prefix-arg
(car c
)))))
5795 for func in
(cdr register-and-functions
)
5796 for cell
= (assq func func-actions
)
5798 collect
(cdr cell
)))
5800 ;; (anything 'anything-c-source-register)
5802 ;;; Latex completion
5803 (defun anything-c-latex-math-candidates ()
5804 "Collect candidates for latex math completion."
5805 (loop for i in
(cddr LaTeX-math-menu
)
5806 for elm
= (loop for s in i when
(vectorp s
)
5807 collect
(cons (aref s
0) (aref s
1)))
5810 (defvar anything-c-source-latex-math
5811 '((name .
"Latex Math Menu")
5813 (with-current-buffer anything-current-buffer
5814 (LaTeX-math-mode 1))))
5815 (candidate-number-limit .
9999)
5816 (candidates . anything-c-latex-math-candidates
)
5817 (action .
(lambda (candidate)
5818 (call-interactively candidate
)))))
5820 ;;;; <Headline Extraction>
5821 (defvar anything-c-source-fixme
5822 '((name .
"TODO/FIXME/DRY comments")
5823 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
5826 "Show TODO/FIXME/DRY comments in current file.")
5827 ;; (anything 'anything-c-source-fixme)
5829 (defvar anything-c-source-rd-headline
5830 '((name .
"RD HeadLine")
5831 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
5832 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
5838 http://en.wikipedia.org/wiki/Ruby_Document_format")
5839 ;; (anything 'anything-c-source-rd-headline)
5841 (defvar anything-c-source-oddmuse-headline
5842 '((name .
"Oddmuse HeadLine")
5843 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
5844 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
5845 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
5848 "Show Oddmuse headlines, such as EmacsWiki.")
5849 ;; (anything 'anything-c-source-oddmuse-headline)
5851 (defvar anything-c-source-emacs-source-defun
5852 '((name .
"Emacs Source DEFUN")
5853 (headline .
"DEFUN\\|DEFVAR")
5854 (condition .
(string-match "/emacs2[0-9].+/src/.+c$"
5855 (or buffer-file-name
""))))
5856 "Show DEFUN/DEFVAR in Emacs C source file.")
5857 ;; (anything 'anything-c-source-emacs-source-defun)
5859 (defvar anything-c-source-emacs-lisp-expectations
5860 '((name .
"Emacs Lisp Expectations")
5861 (headline .
"(desc[ ]\\|(expectations")
5862 (condition .
(eq major-mode
'emacs-lisp-mode
)))
5863 "Show descriptions (desc) in Emacs Lisp Expectations.
5865 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
5866 ;; (anything 'anything-c-source-emacs-lisp-expectations)
5868 (defvar anything-c-source-emacs-lisp-toplevels
5869 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
5870 (headline .
"^(\\|(@\\*\\|^;;;;")
5871 (get-line . buffer-substring
)
5872 (condition .
(eq major-mode
'emacs-lisp-mode
))
5874 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
5875 linkd.el is optional because linkd stars are extracted by regexp.
5876 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
5877 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
5879 (defvar anything-c-source-org-headline
5880 '((name .
"Org HeadLine")
5882 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5883 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5884 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5885 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5886 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5887 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5888 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5889 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
5890 (condition .
(eq major-mode
'org-mode
))
5893 (persistent-action .
(lambda (elm)
5894 (anything-c-action-line-goto elm
)
5897 .
(lambda (actions candidate
)
5898 '(("Go to Line" . anything-c-action-line-goto
)
5899 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline
)))))
5900 "Show Org headlines.
5901 org-mode is very very much extended text-mode/outline-mode.
5903 See (find-library \"org.el\")
5904 See http://orgmode.org for the latest version.")
5906 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
5909 (anything-goto-line (car lineno-and-content
))
5910 (and (looking-at org-complex-heading-regexp
)
5911 (org-make-link-string (concat "*" (match-string 4)))))))
5913 ;; (anything 'anything-c-source-org-headline)
5915 ;;; Anything yaoddmuse
5916 ;; Be sure to have yaoddmuse.el installed
5917 ;; install-elisp may be required if you want to install elisp file from here.
5918 (defvar anything-yaoddmuse-use-cache-file nil
)
5919 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
5920 (defvar anything-c-yaoddmuse-ew-cache nil
)
5921 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
5922 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
5923 (candidates .
(lambda ()
5924 (if anything-yaoddmuse-use-cache-file
5926 (unless anything-c-yaoddmuse-ew-cache
5927 (load anything-c-yaoddmuse-cache-file
)
5928 (setq anything-c-yaoddmuse-ew-cache
5929 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
5930 anything-c-yaoddmuse-ew-cache
)
5931 (yaoddmuse-update-pagename t
)
5932 (gethash "EmacsWiki" yaoddmuse-pages-hash
))))
5933 (action .
(("Edit page" .
(lambda (candidate)
5934 (yaoddmuse-edit "EmacsWiki" candidate
)))
5935 ("Browse page" .
(lambda (candidate)
5936 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
5937 ("Browse page other window" .
(lambda (candidate)
5939 (split-window-vertically))
5940 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
5941 ("Browse diff" .
(lambda (candidate)
5942 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
5943 ("Copy URL" .
(lambda (candidate)
5944 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
5945 (message "Have copy page %s's URL to yank." candidate
)))
5946 ("Create page" .
(lambda (candidate)
5947 (yaoddmuse-edit "EmacsWiki" anything-input
)))
5948 ("Update cache" .
(lambda (candidate)
5949 (if anything-yaoddmuse-use-cache-file
5951 (anything-yaoddmuse-cache-pages t
)
5952 (setq anything-c-yaoddmuse-ew-cache
5953 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
5954 (yaoddmuse-update-pagename))))))
5955 (action-transformer anything-c-yaoddmuse-action-transformer
))
5956 "Needs yaoddmuse.el.
5958 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5960 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
5962 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
5963 '((name .
"Yaoddmuse Post library (EmacsWiki)")
5964 (init .
(anything-yaoddmuse-init))
5965 (candidates-in-buffer)
5966 (action .
(("Post library and Browse" .
(lambda (candidate)
5967 (yaoddmuse-post-file (find-library-name candidate
)
5969 (file-name-nondirectory (find-library-name candidate
))
5971 ("Post library" .
(lambda (candidate)
5972 (yaoddmuse-post-file (find-library-name candidate
)
5974 (file-name-nondirectory (find-library-name candidate
))))))))
5975 "Needs yaoddmuse.el.
5977 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5979 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
5981 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
5982 "Allow the use of `install-elisp' only on elisp files."
5983 (if (string-match "\.el$" candidate
)
5984 (append actions
'(("Install Elisp" .
(lambda (elm)
5985 (install-elisp-from-emacswiki elm
)))))
5989 (defun anything-yaoddmuse-cache-pages (&optional load
)
5990 "Fetch the list of files on emacswiki and create cache file.
5991 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
5993 (yaoddmuse-update-pagename)
5995 (find-file anything-c-yaoddmuse-cache-file
)
5997 (insert "(puthash \"EmacsWiki\" '(")
5998 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
6000 (insert (concat "(\"" (car i
) "\") ")))
6001 (insert ") yaoddmuse-pages-hash)\n")
6003 (kill-buffer (current-buffer))
6004 (when (or current-prefix-arg
6006 (load anything-c-yaoddmuse-cache-file
))))
6009 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
6010 "Preconfigured `anything' to edit or view EmacsWiki page.
6014 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
6016 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
6019 (defun anything-yaoddmuse-emacswiki-post-library ()
6020 "Preconfigured `anything' to post library to EmacsWiki.
6024 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
6026 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library
))
6028 (defun anything-yaoddmuse-init ()
6029 "Init anything buffer status."
6030 (let ((anything-buffer (anything-candidate-buffer 'global
))
6031 (library-list (yaoddmuse-get-library-list)))
6032 (with-current-buffer anything-buffer
6033 ;; Insert library name.
6034 (dolist (library library-list
)
6035 (insert (format "%s\n" library
)))
6037 (sort-lines nil
(point-min) (point-max)))))
6040 (defvar anything-c-source-eev-anchor
6041 '((name .
"Anchors")
6045 (with-current-buffer anything-current-buffer
6046 (loop initially
(goto-char (point-min))
6047 while
(re-search-forward (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
6048 for anchor
= (match-string-no-properties 1)
6049 collect
(cons (format "%5d:%s"
6050 (line-number-at-pos (match-beginning 0))
6051 (format ee-anchor-format anchor
)) anchor
))))))
6052 (persistent-action .
(lambda (item)
6054 (anything-match-line-color-current-line)))
6055 (persistent-help .
"Show this entry")
6056 (action .
(("Goto link" . ee-to
)))))
6057 ;; (anything 'anything-c-source-eev-anchor)
6061 (defvar anything-c-source-org-keywords
6062 '((name .
"Org Keywords")
6063 (init . anything-c-org-keywords-init
)
6064 (candidates . anything-c-org-keywords-candidates
)
6065 (action . anything-c-org-keywords-insert
)
6066 (persistent-action . anything-c-org-keywords-show-help
)
6067 (persistent-help .
"Show an example and info page to describe this keyword.")
6070 ;; (anything 'anything-c-source-org-keywords)
6071 (defvar anything-c-org-keywords-info-location
6072 '(("#+TITLE:" .
"(org)Export options")
6073 ("#+AUTHOR:" .
"(org)Export options")
6074 ("#+DATE:" .
"(org)Export options")
6075 ("#+EMAIL:" .
"(org)Export options")
6076 ("#+DESCRIPTION:" .
"(org)Export options")
6077 ("#+KEYWORDS:" .
"(org)Export options")
6078 ("#+LANGUAGE:" .
"(org)Export options")
6079 ("#+TEXT:" .
"(org)Export options")
6080 ("#+TEXT:" .
"(org)Export options")
6081 ("#+OPTIONS:" .
"(org)Export options")
6082 ("#+BIND:" .
"(org)Export options")
6083 ("#+LINK_UP:" .
"(org)Export options")
6084 ("#+LINK_HOME:" .
"(org)Export options")
6085 ("#+LATEX_HEADER:" .
"(org)Export options")
6086 ("#+EXPORT_SELECT_TAGS:" .
"(org)Export options")
6087 ("#+EXPORT_EXCLUDE_TAGS:" .
"(org)Export options")
6088 ("#+INFOJS_OPT" .
"(org)Javascript support")
6089 ("#+BEGIN_HTML" .
"(org)Quoting HTML tags")
6090 ("#+BEGIN_LaTeX" .
"(org)Quoting LaTeX code")
6091 ("#+ORGTBL" .
"(org)Radio tables")
6092 ("#+HTML:" .
"(org)Quoting HTML tags")
6093 ("#+LaTeX:" .
"(org)Quoting LaTeX code")
6094 ("#+BEGIN:" .
"(org)Dynamic blocks") ;clocktable columnview
6095 ("#+BEGIN_EXAMPLE" .
"(org)Literal examples")
6096 ("#+BEGIN_QUOTE" .
"(org)Paragraphs")
6097 ("#+BEGIN_VERSE" .
"(org)Paragraphs")
6098 ("#+BEGIN_SRC" .
"(org)Literal examples")
6099 ("#+CAPTION" .
"(org)Tables in HTML export")
6100 ("#+LABEL" .
"(org)Tables in LaTeX export")
6101 ("#+ATTR_HTML" .
"(org)Links")
6102 ("#+ATTR_LaTeX" .
"(org)Images in LaTeX export")))
6104 (defun anything-c-org-keywords-init ()
6105 (unless (anything-attr 'keywords-examples
)
6107 (anything-attrset 'keywords-examples
6111 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x
)
6112 (cons (match-string 2 x
) (match-string 1 x
)))
6113 (org-split-string (org-get-current-options) "\n"))
6114 (mapcar 'list org-additional-option-like-keywords
)))
6115 (anything-attrset 'keywords
(mapcar 'car
(anything-attr 'keywords-examples
)))))
6117 (defun anything-c-org-keywords-candidates ()
6118 (and (eq (buffer-local-value 'major-mode anything-current-buffer
) 'org-mode
)
6119 (anything-attr 'keywords
)))
6121 (defun anything-c-org-keywords-insert (keyword)
6122 (cond ((string-match "BEGIN" keyword
)
6123 (insert "#+" keyword
" ")
6125 (insert "\n#+" (replace-regexp-in-string "BEGIN" "END" keyword
) "\n")))
6127 (insert "#+" keyword
" "))))
6129 (defun anything-c-org-keywords-show-help (keyword)
6130 (info (or (assoc-default (concat "#+" keyword
) anything-c-org-keywords-info-location
)
6131 "(org)In-buffer settings"))
6132 (search-forward (concat "#+" keyword
) nil t
)
6133 (anything-persistent-highlight-point)
6134 (message "%s" (or (cdr (assoc keyword
(anything-attr 'keywords-examples
))) "")))
6138 (defvar anything-c-source-picklist
6139 '((name .
"Picklist")
6140 (candidates .
(lambda () (mapcar 'car picklist-list
)))
6142 ;; (anything 'anything-c-source-picklist)
6145 (defvar bbdb-records
)
6146 (defvar bbdb-buffer-name
)
6147 (declare-function bbdb
"ext:bbdb-com")
6148 (declare-function bbdb-current-record
"ext:bbdb-com")
6149 (declare-function bbdb-redisplay-one-record
"ext:bbdb-com")
6150 (declare-function bbdb-record-net
"ext:bbdb-com" (string) t
)
6151 (declare-function bbdb-current-record
"ext:bbdb-com")
6152 (declare-function bbdb-dwim-net-address
"ext:bbdb-com")
6153 (declare-function bbdb-records
"ext:bbdb-com"
6154 (&optional dont-check-disk already-in-db-buffer
))
6156 (defun anything-c-bbdb-candidates ()
6157 "Return a list of all names in the bbdb database. The format
6158 is \"Firstname Lastname\"."
6159 (mapcar (lambda (bbdb-record)
6160 (replace-regexp-in-string
6162 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
6165 (defun anything-c-bbdb-create-contact (actions candidate
)
6166 "Action transformer that returns only an entry to add the
6167 current `anything-pattern' as new contact. All other actions are
6169 (if (string= candidate
"*Add to contacts*")
6170 '(("Add to contacts" .
(lambda (actions)
6171 (bbdb-create-internal
6172 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
6173 (read-from-minibuffer "Company: ")
6174 (read-from-minibuffer "Email: ")
6177 (read-from-minibuffer "Note: ")))))
6180 (defun anything-c-bbdb-get-record (candidate)
6181 "Return record that match CANDIDATE."
6182 (bbdb candidate nil
)
6183 (set-buffer "*BBDB*")
6184 (bbdb-current-record))
6186 (defvar anything-c-bbdb-name nil
6187 "Only for internal use.")
6189 (defvar anything-c-source-bbdb
6191 (candidates . anything-c-bbdb-candidates
)
6192 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
6193 ("View person's data" . anything-c-bbdb-view-person-action
))
6194 (filtered-candidate-transformer .
(lambda (candidates source
)
6195 (setq anything-c-bbdb-name anything-pattern
)
6196 (if (not candidates
)
6197 (list "*Add to contacts*")
6199 (action-transformer .
(lambda (actions candidate
)
6200 (anything-c-bbdb-create-contact actions candidate
))))
6203 http://bbdb.sourceforge.net/")
6204 ;; (anything 'anything-c-source-bbdb)
6206 (defun anything-c-bbdb-view-person-action (candidate)
6207 "View BBDB data of single CANDIDATE or marked candidates."
6208 (anything-aif (anything-marked-candidates)
6209 (let ((bbdb-append-records (length it
)))
6211 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
6212 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
6214 (defun anything-c-bbdb-collect-mail-addresses ()
6215 "Return a list of all mail addresses of records in bbdb buffer."
6216 (with-current-buffer bbdb-buffer-name
6217 (loop for i in bbdb-records
6218 if
(bbdb-record-net (car i
))
6219 collect
(bbdb-dwim-net-address (car i
)))))
6221 (defun anything-c-bbdb-compose-mail (candidate)
6222 "Compose a mail with all records of bbdb buffer."
6223 (anything-c-bbdb-view-person-action candidate
)
6224 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
6225 (address-str (mapconcat 'identity address-list
",\n ")))
6226 (compose-mail address-str
)))
6228 ;;; Evaluation Result
6229 (defvar anything-c-source-evaluation-result
6230 '((name .
"Evaluation Result")
6233 (filtered-candidate-transformer .
(lambda (candidates source
)
6236 (with-current-buffer anything-current-buffer
6238 (eval (read anything-pattern
))))
6240 (action ("Copy result to kill-ring" .
(lambda (candidate)
6241 (with-current-buffer anything-buffer
6242 (let ((end (save-excursion
6243 (goto-char (point-max))
6244 (search-backward "\n")
6246 (kill-region (point) end
))))))))
6247 ;; (anything 'anything-c-source-evaluation-result)
6250 (defun anything-eval-expression (arg)
6251 "Preconfigured anything for `anything-c-source-evaluation-result'."
6253 (anything 'anything-c-source-evaluation-result
(when arg
(thing-at-point 'sexp
))
6254 nil nil nil
"*anything eval*"))
6257 (defun anything-eval-expression-with-eldoc ()
6258 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
6261 (let ((timer (run-with-idle-timer eldoc-idle-delay
6262 'repeat
'anything-eldoc-show-in-eval
)))
6264 (call-interactively 'anything-eval-expression
)
6265 (cancel-timer timer
)))
6266 (call-interactively 'anything-eval-expression
)))
6268 (defun anything-eldoc-show-in-eval ()
6269 "Return eldoc in a tooltip for current minibuffer input."
6270 (let* ((str-all (minibuffer-completion-contents))
6274 (goto-char (point-max))
6275 (unless (looking-back ")\\|\"") (forward-char -
1))
6276 (eldoc-current-symbol))))
6277 (doc (or (eldoc-get-var-docstring sym
)
6278 (eldoc-get-fnsym-args-string
6279 (car (eldoc-fnsym-in-current-sexp))))))
6280 (when doc
(tooltip-show doc
))))
6282 ;;; Calculation Result
6283 (defvar anything-c-source-calculation-result
6284 '((name .
"Calculation Result")
6286 (filtered-candidate-transformer .
(lambda (candidates source
)
6289 (calc-eval anything-pattern
)
6291 (action ("Copy result to kill-ring" . kill-new
))))
6292 ;; (anything 'anything-c-source-calculation-result)
6295 (defun anything-calcul-expression ()
6296 "Preconfigured anything for `anything-c-source-calculation-result'."
6298 (anything-other-buffer 'anything-c-source-calculation-result
"*anything calcul*"))
6300 ;;; Google Suggestions
6301 (defvar anything-gg-sug-lgh-flag
0)
6302 (defun anything-c-google-suggest-fetch (input)
6303 "Fetch suggestions for INPUT from XML buffer.
6304 Return an alist with elements like (data . number_results)."
6305 (let ((request (concat anything-c-google-suggest-url
6306 (url-hexify-string input
))))
6309 with result-alist
= (xml-get-children
6310 (car (xml-parse-region (point-min) (point-max)))
6311 'CompleteSuggestion
)
6312 for i in result-alist
6313 for data
= (cdr (caadr (assoc 'suggestion i
)))
6314 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
6315 for ldata
= (length data
)
6317 (when (> ldata anything-gg-sug-lgh-flag
)
6318 (setq anything-gg-sug-lgh-flag ldata
))
6319 collect
(cons data nqueries
) into cont
6320 finally return cont
)))
6321 (if anything-google-suggest-use-curl-p
6323 (call-process "curl" nil t nil request
)
6325 (with-current-buffer
6326 (url-retrieve-synchronously request
)
6330 (defun anything-c-google-suggest-set-candidates ()
6331 "Set candidates with result and number of google results found."
6332 (let ((suggestions (anything-c-google-suggest-fetch anything-input
)))
6333 (setq suggestions
(loop for i in suggestions
6334 for interval
= (- anything-gg-sug-lgh-flag
(length (car i
)))
6335 for elm
= (concat (car i
)
6336 (make-string (+ 2 interval
) ?
)
6337 "(" (cdr i
) " results)")
6338 collect
(cons elm
(car i
))))
6339 (if (some (lambda (data) (equal (cdr data
) anything-input
)) suggestions
)
6341 ;; if there is no suggestion exactly matching the input then
6342 ;; prepend a Search on Google item to the list
6345 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
6346 anything-input
))))))
6349 (defun anything-c-google-suggest-action (candidate)
6350 "Default action to jump to a google suggested candidate."
6351 (anything-c-browse-url (concat anything-c-google-suggest-search-url
6352 (url-hexify-string candidate
))))
6355 (defvar anything-c-source-google-suggest
6356 '((name .
"Google Suggest")
6357 (candidates . anything-c-google-suggest-set-candidates
)
6358 (action .
(("Google Search" . anything-c-google-suggest-action
)))
6360 (requires-pattern .
3)
6363 ;; (anything 'anything-c-source-google-suggest)
6365 ;;; Yahoo suggestions
6367 (defun anything-c-yahoo-suggest-fetch (input)
6368 "Fetch Yahoo suggestions for INPUT from XML buffer.
6369 Return an alist with elements like (data . number_results)."
6370 (let ((request (concat anything-c-yahoo-suggest-url
6371 (url-hexify-string input
))))
6374 with result-alist
= (xml-get-children
6375 (car (xml-parse-region (point-min) (point-max)))
6377 for i in result-alist
6378 collect
(caddr i
))))
6379 (with-current-buffer
6380 (url-retrieve-synchronously request
)
6383 (defun anything-c-yahoo-suggest-set-candidates ()
6384 "Set candidates with Yahoo results found."
6385 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
6389 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
6390 anything-input
))))))
6392 (defun anything-c-yahoo-suggest-action (candidate)
6393 "Default action to jump to a Yahoo suggested candidate."
6394 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
6395 (url-hexify-string candidate
))))
6397 (defvar anything-c-source-yahoo-suggest
6398 '((name .
"Yahoo Suggest")
6399 (candidates . anything-c-yahoo-suggest-set-candidates
)
6400 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
6402 (requires-pattern .
3)
6405 ;; (anything 'anything-c-source-yahoo-suggest)
6408 ;;; Need external program surfraw.
6409 ;;; http://surfraw.alioth.debian.org/
6411 (require 'browse-url
)
6412 (defvar w3m-command nil
)
6413 (defvar anything-c-home-url
"http://www.google.fr"
6414 "*Default url to use as home url.")
6416 (defvar browse-url-chromium-program
"chromium-bin")
6417 (defvar anything-browse-url-default-browser-alist
6418 `((,w3m-command . w3m-browse-url
)
6419 (,browse-url-firefox-program . browse-url-firefox
)
6420 (,browse-url-chromium-program . browse-url-chromium
)
6421 (,browse-url-kde-program . browse-url-kde
)
6422 (,browse-url-gnome-moz-program . browse-url-gnome-moz
)
6423 (,browse-url-mozilla-program . browse-url-mozilla
)
6424 (,browse-url-galeon-program . browse-url-galeon
)
6425 (,browse-url-netscape-program . browse-url-netscape
)
6426 (,browse-url-mosaic-program . browse-url-mosaic
)
6427 (,browse-url-xterm-program . browse-url-text-xterm
))
6428 "*Alist of (executable . function) to try to find a suitable url browser.")
6430 (defun* anything-c-generic-browser
(url name
&rest args
)
6431 (let ((proc (concat name
" " url
)))
6432 (message "Starting %s..." name
)
6433 (apply 'start-process proc nil name
6434 (append args
(list url
)))
6435 (set-process-sentinel
6437 #'(lambda (process event
)
6438 (when (string= event
"finished\n")
6439 (message "%s process %s" process event
))))))
6441 (defun browse-url-chromium (url)
6442 (interactive "sURL: ")
6443 (anything-c-generic-browser
6444 url browse-url-chromium-program
6445 "--enable-plugins"))
6447 (defun anything-browse-url-default-browser (url &rest args
)
6448 "Find a suitable browser and ask it to load URL."
6449 (let ((default-browser (loop
6450 for i in anything-browse-url-default-browser-alist
6451 thereis
(and (car i
) (executable-find (car i
))))))
6453 (apply default-browser url args
)
6454 (error "No usable browser found"))))
6456 (defun* anything-c-browse-url
(&optional
(url anything-c-home-url
))
6457 "Default command to browse URL."
6458 (if browse-url-browser-function
6459 (funcall browse-url-browser-function url
)
6460 (anything-browse-url-default-browser url
)))
6462 (defun anything-c-build-elvi-list ()
6463 "Return list of all engines and descriptions handled by surfraw."
6466 (call-process "surfraw" nil t nil
6468 (split-string (buffer-string) "\n"))))
6470 (defvar anything-surfraw-default-browser-function nil
6471 "*The browse url function you prefer to use with surfraw.
6472 When nil, fallback to `browse-url-browser-function'.")
6473 (defvar anything-surfraw-engines-history nil
)
6475 (defun anything-surfraw (pattern engine
)
6476 "Preconfigured `anything' to search PATTERN with search ENGINE."
6477 (interactive (list (read-string "SearchFor: ")
6480 (anything-c-build-elvi-list)
6482 :name
"Surfraw Search Engines"
6483 :history anything-surfraw-engines-history
)))
6484 (let* ((engine-nodesc (car (split-string engine
)))
6485 (url (with-temp-buffer
6486 (apply 'call-process
"surfraw" nil t nil
6487 (list engine-nodesc
"-p" pattern
))
6488 (replace-regexp-in-string
6489 "\n" "" (buffer-string))))
6490 (browse-url-browser-function (or anything-surfraw-default-browser-function
6491 browse-url-browser-function
)))
6492 (if (string= engine-nodesc
"W")
6493 (anything-c-browse-url)
6494 (anything-c-browse-url url
)
6495 (setq anything-surfraw-engines-history
6496 (cons engine
(delete engine anything-surfraw-engines-history
))))))
6500 (defun anything-emms-stream-edit-bookmark (elm)
6501 "Change the information of current emms-stream bookmark from anything."
6502 (let* ((cur-buf anything-current-buffer
)
6503 (bookmark (assoc elm emms-stream-list
))
6504 (name (read-from-minibuffer "Description: "
6506 (url (read-from-minibuffer "URL: "
6508 (fd (read-from-minibuffer "Feed Descriptor: "
6509 (int-to-string (nth 2 bookmark
))))
6510 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
6511 (format "%s" (car (last bookmark
))))))
6514 (when (re-search-forward (concat "^" name
) nil t
)
6516 (emms-stream-delete-bookmark)
6517 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
6518 (emms-stream-save-bookmarks-file)
6520 (switch-to-buffer cur-buf
)))))
6522 (defun anything-emms-stream-delete-bookmark (elm)
6523 "Delete an emms-stream bookmark from anything."
6524 (let* ((cur-buf anything-current-buffer
)
6525 (bookmark (assoc elm emms-stream-list
))
6526 (name (nth 0 bookmark
)))
6529 (when (re-search-forward (concat "^" name
) nil t
)
6531 (emms-stream-delete-bookmark)
6532 (emms-stream-save-bookmarks-file)
6534 (switch-to-buffer cur-buf
)))))
6536 (defvar anything-c-source-emms-streams
6537 '((name .
"Emms Streams")
6539 (emms-stream-init)))
6540 (candidates .
(lambda ()
6541 (mapcar 'car emms-stream-list
)))
6542 (action .
(("Play" .
(lambda (elm)
6543 (let* ((stream (assoc elm emms-stream-list
))
6544 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
6545 (url (second stream
)))
6547 ("Delete" . anything-emms-stream-delete-bookmark
)
6548 ("Edit" . anything-emms-stream-edit-bookmark
)))
6549 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
6550 ;; (anything 'anything-c-source-emms-streams)
6552 ;; Don't forget to set `emms-source-file-default-directory'
6553 (defvar anything-c-source-emms-dired
6554 '((name .
"Music Directory")
6555 (candidates .
(lambda ()
6556 (cddr (directory-files emms-source-file-default-directory
))))
6558 (("Play Directory" .
(lambda (item)
6559 (emms-play-directory
6562 emms-source-file-default-directory
))))
6563 ("Open dired in file's directory" .
(lambda (item)
6564 (anything-c-open-dired
6567 emms-source-file-default-directory
))))))
6568 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
6569 ;; (anything 'anything-c-source-emms-dired)
6571 (defface anything-emms-playlist
6572 '((t (:foreground
"Springgreen4" :underline t
)))
6573 "*Face used for tracks in current emms playlist."
6576 (defun anything-c-emms-files-modifier (candidates source
)
6577 (let ((current-playlist (with-current-emms-playlist
6579 with cur-list
= (emms-playlist-tracks-in-region
6580 (point-min) (point-max))
6582 collect
(assoc-default 'name i
)))))
6583 (loop for i in candidates
6584 if
(member (cdr i
) current-playlist
)
6585 collect
(cons (propertize (car i
)
6586 'face
'anything-emms-playlist
)
6588 else collect i into lis
6589 finally return lis
)))
6591 (defun anything-c-emms-play-current-playlist ()
6592 "Play current playlist."
6593 (with-current-emms-playlist
6594 (emms-playlist-first)
6595 (emms-playlist-mode-play-smart)))
6597 (defvar anything-c-source-emms-files
6598 '((name .
"Emms files")
6599 (candidates .
(lambda ()
6600 (loop for v being the hash-values in emms-cache-db
6601 for name
= (assoc-default 'name v
)
6602 for artist
= (or (assoc-default 'info-artist v
) "unknown")
6603 for genre
= (or (assoc-default 'info-genre v
) "unknown")
6604 for tracknum
= (or (assoc-default 'info-tracknumber v
) "unknown")
6605 for song
= (or (assoc-default 'info-title v
) "unknown")
6606 for info
= (concat artist
" - " genre
" - " tracknum
": " song
)
6607 unless
(string-match "^http:" name
) collect
(cons info name
))))
6608 (filtered-candidate-transformer . anything-c-emms-files-modifier
)
6609 (action .
(("Play file" . emms-play-file
)
6610 ("Add to Playlist and play (C-u clear current)"
6611 .
(lambda (candidate)
6612 (when anything-current-prefix-arg
6613 (emms-playlist-current-clear))
6615 (mapc 'emms-add-playlist-file
(anything-marked-candidates))
6616 (unless emms-player-playing-p
6617 (anything-c-emms-play-current-playlist))))))))
6619 ;; (anything 'anything-c-source-emms-files)
6621 ;;; Jabber Contacts (jabber.el)
6622 (defun anything-c-jabber-online-contacts ()
6623 "List online Jabber contacts."
6626 (dolist (item (jabber-concat-rosters) jids
)
6627 (when (get item
'connected
)
6628 (push (if (get item
'name
)
6629 (cons (get item
'name
) item
)
6630 (cons (symbol-name item
) item
)) jids
))))))
6632 (defvar anything-c-source-jabber-contacts
6633 '((name .
"Jabber Contacts")
6634 (init .
(lambda () (require 'jabber
)))
6635 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
6636 (action .
(lambda (x)
6638 (jabber-read-account)
6640 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
6641 ;; (anything 'anything-c-source-jabber-contacts)
6645 (defvar anything-source-select-buffer
"*anything source select*")
6646 (defvar anything-c-source-call-source
6647 `((name .
"Call anything source")
6648 (candidate-number-limit)
6649 (candidates .
(lambda ()
6650 (loop for vname in
(all-completions "anything-c-source-" obarray
)
6651 for var
= (intern vname
)
6652 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
6653 if name collect
(cons (format "%s `%s'"
6654 name
(propertize vname
'face
'font-lock-variable-name-face
))
6656 (action .
(("Invoke anything with selected source" .
6658 (setq anything-candidate-number-limit
9999)
6659 (anything candidate nil nil nil nil
6660 anything-source-select-buffer
)))
6661 ("Describe variable" . describe-variable
)
6662 ("Find variable" . find-variable
)))
6663 (persistent-action . describe-variable
)
6664 (persistent-help .
"Show description of this source")))
6665 ;; (anything 'anything-c-source-call-source)
6668 (defun anything-call-source ()
6669 "Preconfigured `anything' to call anything source."
6671 (anything 'anything-c-source-call-source nil nil nil nil
6672 anything-source-select-buffer
))
6674 (defun anything-call-source-from-anything ()
6675 "Call anything source within `anything' session."
6677 (setq anything-input-idle-delay
0)
6678 (anything-set-sources '(anything-c-source-call-source)))
6680 ;;; Execute Preconfigured anything.
6681 (defvar anything-c-source-anything-commands
6682 '((name .
"Preconfigured Anything")
6683 (candidates . anything-c-anything-commands-candidates
)
6685 (candidate-number-limit)))
6686 ;; (anything 'anything-c-source-anything-commands)
6688 (defun anything-c-anything-commands-candidates ()
6689 (loop for
(cmd . desc
) in
(anything-c-list-preconfigured-anything)
6690 collect
(cons (if (where-is-internal cmd nil t
)
6691 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc
))
6692 (substitute-command-keys (format "\\[%s] : %s" cmd desc
)))
6696 (defun anything-execute-anything-command ()
6697 "Preconfigured `anything' to execute preconfigured `anything'."
6699 (anything-other-buffer 'anything-c-source-anything-commands
6700 "*anything commands*"))
6703 (defun anything-c-occur-init ()
6704 (anything-candidate-buffer anything-current-buffer
))
6706 (defun anything-c-occur-get-line (s e
)
6707 (format "%7d:%s" (line-number-at-pos (1- s
)) (buffer-substring s e
)))
6709 (defvar anything-c-source-occur
6711 (init . anything-c-occur-init
)
6712 (candidates-in-buffer)
6714 (get-line . anything-c-occur-get-line
)
6717 (requires-pattern .
1)
6720 ;; (anything 'anything-c-source-occur)
6722 ;;; Anything browse code.
6723 (defun anything-c-browse-code-get-line (beg end
)
6724 "Select line if it match the regexp corresponding to current `major-mode'.
6725 Line is parsed for BEG position to END position."
6726 (let ((str-line (buffer-substring beg end
))
6727 (regexp (assoc-default major-mode
6728 anything-c-browse-code-regexp-alist
))
6729 (num-line (if (string= anything-pattern
"") beg
(1- beg
))))
6730 (when (and regexp
(string-match regexp str-line
))
6731 (format "%4d:%s" (line-number-at-pos num-line
) str-line
))))
6734 (defvar anything-c-source-browse-code
6735 '((name .
"Browse code")
6737 (anything-candidate-buffer anything-current-buffer
)
6738 (with-current-buffer anything-current-buffer
6739 (jit-lock-fontify-now))))
6740 (candidate-number-limit .
9999)
6741 (candidates-in-buffer)
6742 (get-line . anything-c-browse-code-get-line
)
6746 ;; Do many actions for input
6747 (defvar anything-c-source-create
6751 (action-transformer . anything-create--actions
))
6752 "Do many create actions from `anything-pattern'.
6753 See also `anything-create--actions'.")
6754 ;; (anything 'anything-c-source-create)
6756 (defun anything-create-from-anything ()
6757 "Run `anything-create' from `anything' as a fallback."
6759 (anything-run-after-quit 'anything-create nil anything-pattern
))
6762 (defun anything-create (&optional string initial-input
)
6763 "Preconfigured `anything' to do many create actions from STRING.
6764 See also `anything-create--actions'."
6766 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
6767 (anything '(((name .
"Anything Create")
6768 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
6769 (candidates . anything-create--actions
)
6770 (candidate-number-limit)
6771 (action .
(lambda (func) (funcall func string
)))))))
6773 (defun anything-create--actions (&rest ignored
)
6774 "Default actions for `anything-create' / `anything-c-source-create'."
6776 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
6777 (append anything-create--actions-private
6778 '(("find-file" . find-file
)
6779 ("find-file other window" . find-file-other-window
)
6780 ("New buffer" . switch-to-buffer
)
6781 ("New buffer other window" . switch-to-buffer-other-window
)
6782 ("Bookmark Set" . bookmark-set
)
6784 (lambda (x) (set-register (read-char "Register: ") x
)))
6785 ("Insert Linkd star" . linkd-insert-star
)
6786 ("Insert Linkd Tag" . linkd-insert-tag
)
6787 ("Insert Linkd Link" . linkd-insert-link
)
6788 ("Insert Linkd Lisp" . linkd-insert-lisp
)
6789 ("Insert Linkd Wiki" . linkd-insert-wiki
)
6790 ("Google Search" . google
)))))
6792 ;; Minibuffer History
6793 (defvar anything-c-source-minibuffer-history
6794 '((name .
"Minibuffer History")
6795 (header-name .
(lambda (name) (format "%s (%s)" name minibuffer-history-variable
)))
6796 (candidates .
(lambda () (let ((history (symbol-value minibuffer-history-variable
)))
6797 (if (consp (car history
))
6798 (mapcar 'prin1-to-string history
)
6802 ;; (anything 'anything-c-source-minibuffer-history)
6805 (defvar anything-c-source-elscreen
6806 '((name .
"Elscreen")
6807 (candidates .
(lambda ()
6808 (if (cdr (elscreen-get-screen-to-name-alist))
6810 (loop for sname in
(elscreen-get-screen-to-name-alist)
6811 append
(list (format "[%d] %s" (car sname
) (cdr sname
))) into lst
6812 finally
(return lst
))
6813 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
6814 (action .
(("Change Screen".
6816 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
6819 (dolist (i (anything-marked-candidates))
6820 (elscreen-goto (- (aref i
1) (aref "0" 0)))
6824 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
6825 (elscreen-kill-others)))))))
6826 ;; (anything 'anything-c-source-elscreen)
6831 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
6832 "Top command (batch mode). %s is replaced with `frame-width'.")
6833 (defvar anything-c-source-top
6834 '((name .
"Top (Press C-c C-u to refresh)")
6835 (init . anything-c-top-init
)
6836 (candidates-in-buffer)
6837 (display-to-real . anything-c-top-display-to-real
)
6838 (update . anything-c-top-update
)
6839 (persistent-action . anything-c-top-sh-persistent-action
)
6840 (persistent-help .
"SIGTERM")
6842 ("kill (TERM)" .
(lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid
))))
6843 ("kill (KILL)" .
(lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid
))))
6844 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
6845 ;; (anything 'anything-c-source-top)
6847 (defun anything-c-top-sh (cmd)
6848 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
6850 (defun anything-c-top-sh-persistent-action (pid)
6851 (delete-other-windows)
6852 (anything-c-top-sh (format "kill -TERM %s" pid
))
6853 (anything-force-update))
6855 (defun anything-c-top-init ()
6856 (with-current-buffer (anything-candidate-buffer 'global
)
6857 (call-process-shell-command
6858 (format anything-c-top-command
6859 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
6860 nil
(current-buffer))))
6862 (defun anything-c-top-display-to-real (line)
6863 (car (split-string line
)))
6865 (defun anything-c-top-update ()
6866 (let ((anything-source-name (assoc-default 'name anything-c-source-top
))) ;UGLY HACK
6867 (anything-c-top-init)))
6870 (defun anything-top ()
6871 "Preconfigured `anything' for top command."
6873 (let ((anything-samewindow t
)
6874 (anything-enable-shortcuts)
6875 (anything-display-function 'anything-default-display-buffer
)
6876 (anything-candidate-number-limit 9999))
6877 (save-window-excursion
6878 (delete-other-windows)
6879 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
6882 (defvar anything-c-source-absolute-time-timers
6883 '((name .
"Absolute Time Timers")
6884 (candidates . timer-list
)
6886 ;; (anything 'anything-c-source-absolute-time-timers)
6888 (defvar anything-c-source-idle-time-timers
6889 '((name .
"Idle Time Timers")
6890 (candidates . timer-idle-list
)
6892 ;; (anything 'anything-c-source-idle-time-timers)
6894 (defun anything-c-timer-real-to-display (timer)
6895 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay
)
6896 (append timer nil
) ;use `append' to convert vector->list
6897 (format "%s repeat=%5S %s(%s)"
6898 (let ((time (list t1 t2 t3
)))
6900 (format-time-string "idle-for=%5s" time
)
6901 (format-time-string "%m/%d %T" time
)))
6904 (mapconcat 'prin1-to-string args
" "))))
6906 ;;; X RandR resolution change
6907 ;;; FIXME I do not care multi-display.
6908 (defvar anything-c-xrandr-output
"VGA")
6909 (defvar anything-c-xrandr-screen
"0")
6910 (defvar anything-c-source-xrandr-change-resolution
6911 '((name .
"Change Resolution")
6915 (call-process "xrandr" nil
(current-buffer) nil
6916 "--screen" anything-c-xrandr-screen
"-q")
6918 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
6919 collect
(match-string 1)))))
6921 ("Change Resolution" .
(lambda (mode)
6922 (call-process "xrandr" nil nil nil
6923 "--screen" anything-c-xrandr-screen
6924 "--output" anything-c-xrandr-output
6926 ;; (anything 'anything-c-source-xrandr-change-resolution)
6929 (defun anything-c-persistent-xfont-action (elm)
6930 "Show current font temporarily"
6931 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
6934 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
6935 (set-frame-font current-font
))))
6937 (defvar anything-c-xfonts-cache nil
)
6938 (defvar anything-c-source-xfonts
6939 '((name .
"X Fonts")
6941 (unless anything-c-xfonts-cache
6942 (setq anything-c-xfonts-cache
6943 (x-list-fonts "*")))))
6944 (candidates . anything-c-xfonts-cache
)
6945 (action .
(("Copy to kill ring" .
(lambda (elm)
6947 ("Set Font" .
(lambda (elm)
6949 (set-frame-font elm
'keep-size
)
6950 (message "New font have been copied to kill ring")))))
6951 (persistent-action . anything-c-persistent-xfont-action
)
6952 (persistent-help .
"Switch to this font temporarily")))
6955 (defun anything-select-xfont ()
6956 "Preconfigured `anything' to select Xfont."
6958 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
6960 ;; (anything 'anything-c-source-xfonts)
6964 (defvar anything-c-source-time-world
6965 '((name .
"Time World List")
6967 (let ((anything-buffer (anything-candidate-buffer 'global
)))
6968 (with-current-buffer anything-buffer
6969 (display-time-world-display display-time-world-list
)))))
6970 (candidates-in-buffer)))
6973 (defun anything-world-time ()
6974 "Preconfigured `anything' to show world time."
6976 (anything-other-buffer 'anything-c-source-time-world
"*anything world time*"))
6978 ;;; Source for Debian/Ubuntu users
6979 (defvar anything-c-source-apt
6981 (init . anything-c-apt-init
)
6982 (candidates-in-buffer)
6983 (candidate-transformer anything-c-apt-candidate-transformer
)
6984 (display-to-real . anything-c-apt-display-to-real
)
6985 (candidate-number-limit .
9999)
6987 ("Show package description" . anything-c-apt-cache-show
)
6988 ("Install package" . anything-c-apt-install
)
6989 ("Remove package" . anything-c-apt-uninstall
)
6990 ("Purge package" . anything-c-apt-purge
))
6991 (persistent-action . anything-c-apt-persistent-action
)
6992 (persistent-help .
"Show - C-u Refresh")))
6993 ;; (anything 'anything-c-source-apt)
6995 (defvar anything-c-apt-query
"emacs")
6996 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
6997 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
6998 (defvar anything-c-apt-installed-packages nil
)
7000 (defface anything-apt-installed
7001 '((t (:foreground
"green")))
7002 "*Face used for apt installed candidates."
7005 (defun anything-c-apt-refresh ()
7006 "Refresh installed candidates list."
7007 (setq anything-c-apt-installed-packages nil
)
7008 (anything-force-update))
7010 (defun anything-c-apt-persistent-action (candidate)
7011 "Persistent action for APT source."
7012 (if current-prefix-arg
7013 (anything-c-apt-refresh)
7014 (anything-c-apt-cache-show candidate
)))
7017 (defun anything-apt (query)
7018 "Preconfigured `anything' : frontend of APT package manager."
7019 (interactive "sAPT search: ")
7020 (let ((anything-c-apt-query query
))
7021 (anything 'anything-c-source-apt
)))
7023 (defun anything-c-apt-candidate-transformer (candidates)
7024 "Show installed candidates in a different color."
7027 for cand in candidates
7028 for name
= (anything-c-apt-display-to-real cand
)
7029 if
(member name anything-c-apt-installed-packages
)
7030 collect
(propertize cand
'face
'anything-apt-installed
) into all
7031 else collect cand into all finally return all
))
7033 (defun anything-c-apt-init ()
7034 "Initialize list of debian packages."
7035 (unless anything-c-apt-installed-packages
7036 (message "Updating installed candidate list...")
7037 (setq anything-c-apt-installed-packages
7039 (call-process-shell-command "dpkg --get-selections"
7040 nil
(current-buffer))
7041 (loop for i in
(split-string (buffer-string) "\n" t
)
7042 collect
(car (split-string i
))))))
7043 (with-current-buffer
7044 (anything-candidate-buffer
7045 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query
)))
7047 (call-process-shell-command
7048 (format anything-c-apt-search-command anything-c-apt-query
)
7049 nil
(current-buffer)))
7050 (message "Updating installed candidate list...done"))
7052 (defun anything-c-apt-display-to-real (line)
7053 "Return only name of a debian package.
7054 LINE is displayed like:
7055 package name - description."
7056 (car (split-string line
" - ")))
7059 (defun anything-c-shell-command-if-needed (command)
7060 (interactive "sShell command: ")
7061 (if (get-buffer command
) ; if the buffer already exists
7062 (switch-to-buffer command
) ; then just switch to it
7063 (switch-to-buffer command
) ; otherwise create it
7064 (insert (shell-command-to-string command
))))
7066 (defun anything-c-apt-cache-show (package)
7067 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package
)))
7069 (defun anything-c-apt-install (package)
7070 (anything-c-apt-install1 package
:action
'install
))
7072 (defun anything-c-apt-uninstall (package)
7073 (anything-c-apt-install1 package
:action
'uninstall
))
7075 (defun anything-c-apt-purge (package)
7076 (anything-c-apt-install1 package
:action
'purge
))
7078 (defun* anything-c-apt-install1
(candidate &key action
)
7079 (ansi-term (getenv "SHELL") "anything apt")
7081 (let ((command (case action
7082 ('install
"sudo apt-get install '%s'")
7083 ('uninstall
"sudo apt-get remove '%s'")
7084 ('purge
"sudo apt-get purge '%s'")
7085 (t (error "Unknow action"))))
7087 (goto-char (point-max))
7088 (insert (format command candidate
))
7090 (if (y-or-n-p (format "%s package" (symbol-name action
)))
7092 (setq anything-c-external-commands-list nil
)
7093 (setq anything-c-apt-installed-packages nil
)
7094 (term-char-mode) (term-send-input))
7095 (delete-region beg end
) (term-send-eof) (kill-buffer))))
7097 ;; (anything-c-apt-install "jed")
7099 ;;; Sources for gentoo users
7100 (defvar anything-c-gentoo-use-flags nil
)
7101 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
7102 (defvar anything-c-cache-gentoo nil
)
7103 (defvar anything-c-cache-world nil
)
7104 (defvar anything-c-source-gentoo
7105 '((name .
"Portage sources")
7107 (get-buffer-create anything-c-gentoo-buffer
)
7108 (unless anything-c-cache-gentoo
7109 (anything-c-gentoo-setup-cache))
7110 (unless anything-c-cache-world
7111 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
7112 (anything-c-gentoo-init-list)))
7113 (candidates-in-buffer)
7115 (candidate-transformer anything-c-highlight-world
)
7116 (action .
(("Show package" .
(lambda (elm)
7117 (anything-c-gentoo-eshell-action elm
"eix")))
7118 ("Show history" .
(lambda (elm)
7119 (if (member elm anything-c-cache-world
)
7120 (anything-c-gentoo-eshell-action elm
"genlop -qe")
7121 (message "No infos on packages not yet installed"))))
7122 ("Copy in kill-ring" . kill-new
)
7123 ("insert at point" . insert
)
7124 ("Browse HomePage" .
(lambda (elm)
7125 (let ((urls (anything-c-gentoo-get-url elm
)))
7126 (browse-url (anything-comp-read "Url: " urls
:must-match t
)))))
7127 ("Show extra infos" .
(lambda (elm)
7128 (if (member elm anything-c-cache-world
)
7129 (anything-c-gentoo-eshell-action elm
"genlop -qi")
7130 (message "No infos on packages not yet installed"))))
7131 ("Show use flags" .
(lambda (elm)
7132 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
7133 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
7134 (font-lock-mode 1)))
7135 ("Run emerge pretend" .
(lambda (elm)
7136 (anything-c-gentoo-eshell-action elm
"emerge -p")))
7137 ("Emerge" .
(lambda (elm)
7138 (anything-gentoo-install elm
:action
'install
)))
7139 ("Unmerge" .
(lambda (elm)
7140 (anything-gentoo-install elm
:action
'uninstall
)))
7141 ("Show dependencies" .
(lambda (elm)
7142 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
7143 ("Show related files" .
(lambda (elm)
7144 (anything-c-gentoo-default-action elm
"equery" "files")))
7145 ("Refresh" .
(lambda (elm)
7146 (anything-c-gentoo-setup-cache)
7147 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
7149 ;; (anything 'anything-c-source-gentoo)
7151 (defun* anything-gentoo-install
(candidate &key action
)
7152 (setq anything-c-external-commands-list nil
)
7153 (ansi-term (getenv "SHELL") "Gentoo emerge")
7155 (let ((command (case action
7156 ('install
"sudo emerge -av ")
7157 ('uninstall
"sudo emerge -avC ")
7158 (t (error "Unknow action"))))
7159 (elms (mapconcat 'identity
(anything-marked-candidates) " "))
7161 (goto-char (point-max))
7162 (insert (concat command elms
))
7164 (term-char-mode) (term-send-input)))
7166 (defun anything-c-gentoo-default-action (elm command
&rest args
)
7167 "Gentoo default action that use `anything-c-gentoo-buffer'."
7168 (if (member elm anything-c-cache-world
)
7170 (switch-to-buffer anything-c-gentoo-buffer
)
7172 (let ((com-list (append args
(list elm
))))
7173 (apply #'call-process command nil t nil
7175 (message "No infos on packages not yet installed")))
7177 (defvar anything-c-source-use-flags
7178 '((name .
"Use Flags")
7180 (unless anything-c-gentoo-use-flags
7181 (anything-c-gentoo-setup-use-flags-cache))
7182 (anything-c-gentoo-get-use)))
7183 (candidates-in-buffer)
7185 (candidate-transformer anything-c-highlight-local-use
)
7186 (action .
(("Description"
7188 (switch-to-buffer anything-c-gentoo-buffer
)
7190 (apply #'call-process
"euse" nil t nil
7193 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
7194 (font-lock-mode 1)))
7197 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -E")))
7200 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -D")))
7203 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -P")))
7204 ("Show which dep use this flag"
7206 (switch-to-buffer anything-c-gentoo-buffer
)
7208 (apply #'call-process
"equery" nil t nil
7214 ;; (anything 'anything-c-source-use-flags)
7216 (defun anything-c-gentoo-init-list ()
7217 "Initialize buffer with all packages in Portage."
7218 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
7219 (buf (anything-candidate-buffer 'portage-buf
)))
7220 (with-current-buffer buf
7221 (dolist (i anything-c-cache-gentoo
)
7222 (insert (concat i
"\n"))))))
7224 (defun anything-c-gentoo-setup-cache ()
7225 "Set up `anything-c-cache-gentoo'"
7226 (setq anything-c-cache-gentoo
7227 (split-string (with-temp-buffer
7228 (call-process "eix" nil t nil
7232 (defun anything-c-gentoo-eshell-action (elm command
)
7233 (when (get-buffer "*EShell Command Output*")
7234 (kill-buffer "*EShell Command Output*"))
7235 (message "Wait searching...")
7236 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
7237 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
7239 (save-window-excursion
7240 (pop-to-buffer "*scratch*")
7241 (eshell-command (format "%s %s" command elm
)))
7242 (pop-to-buffer "*EShell Command Output*"))
7243 (eshell-command (format "%s %s" command elm
)))))
7245 (defun anything-c-gentoo-get-use ()
7246 "Initialize buffer with all use flags."
7247 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
7248 (buf (anything-candidate-buffer 'use-buf
)))
7249 (with-current-buffer buf
7250 (dolist (i anything-c-gentoo-use-flags
)
7251 (insert (concat i
"\n"))))))
7254 (defun anything-c-gentoo-setup-use-flags-cache ()
7255 "Setup `anything-c-gentoo-use-flags'"
7256 (setq anything-c-gentoo-use-flags
7257 (split-string (with-temp-buffer
7258 (call-process "eix" nil t nil
7259 "--print-all-useflags")
7262 (defun anything-c-gentoo-get-url (elm)
7263 "Return a list of urls from eix output."
7265 with url-list
= (split-string
7267 (call-process "eix" nil t nil
7268 elm
"--format" "<homepage>\n")
7272 when
(and (string-match "^http://.*" i
)
7273 (not (member i all
)))
7275 finally return all
))
7277 (defun anything-c-gentoo-get-world ()
7278 "Return list of all installed package on your system."
7279 (split-string (with-temp-buffer
7280 (call-process "qlist" nil t nil
7284 (defun anything-c-gentoo-get-local-use ()
7285 (split-string (with-temp-buffer
7286 (call-process "portageq" nil t nil
7291 (defface anything-gentoo-match-face
'((t (:foreground
"red")))
7292 "Face for anything-gentoo installed packages."
7293 :group
'traverse-faces
)
7295 (defun anything-c-highlight-world (eix)
7296 "Highlight all installed package."
7298 if
(member i anything-c-cache-world
)
7299 collect
(propertize i
'face
'anything-gentoo-match-face
)
7303 (defun anything-c-highlight-local-use (use-flags)
7304 (let ((local-uses (anything-c-gentoo-get-local-use)))
7305 (loop for i in use-flags
7306 if
(member i local-uses
)
7307 collect
(propertize i
'face
'anything-gentoo-match-face
)
7311 (defvar anything-c-source-emacs-process
7312 '((name .
"Emacs Process")
7313 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
7314 (persistent-action .
(lambda (elm)
7315 (delete-process (get-process elm
))
7316 (anything-delete-current-selection)))
7317 (persistent-help .
"Kill Process")
7318 (action ("Kill Process" .
(lambda (elm)
7319 (delete-process (get-process elm
)))))))
7321 ;; (anything 'anything-c-source-emacs-process)
7323 ;; Run Externals commands within Emacs
7324 (defmacro* anything-comp-hash-get-items
(hash-table &key test
)
7325 "Get the list of all keys/values of hash-table."
7326 `(let ((li-items ()))
7327 (maphash #'(lambda (x y
)
7329 (when (funcall ,test y
)
7330 (push (list x y
) li-items
))
7331 (push (list x y
) li-items
)))
7335 (defun anything-comp-read-get-candidates (collection &optional test sort-fn
)
7336 "Convert COLLECTION to list removing elements that don't match TEST.
7337 SORT-FN is a predicate to sort COLLECTION.
7338 If collection is an `obarray', a TEST is needed. See `obarray'."
7340 (cond ((and (listp collection
) test
)
7341 (loop for i in collection when
(funcall test i
) collect i
))
7342 ((and (eq collection obarray
) test
)
7343 (loop for s being the symbols of collection
7344 when
(funcall test s
) collect s
))
7345 ((and (vectorp collection
) test
)
7346 (loop for i across collection when
(funcall test i
) collect i
))
7347 ((vectorp collection
)
7348 (loop for i across collection collect i
))
7349 ((and (hash-table-p collection
) test
)
7350 (anything-comp-hash-get-items collection
:test test
))
7351 ((hash-table-p collection
)
7352 (anything-comp-hash-get-items collection
))
7354 (if sort-fn
(sort cands sort-fn
) cands
)))
7356 (defun anything-cr-default-transformer (candidates source
)
7357 "Default filter candidate function for `anything-comp-read'.
7358 Do nothing, just return candidate list unmodified."
7361 (defun* anything-comp-read
(prompt collection
7365 (buffer "*Anything Completions*")
7367 (requires-pattern 0)
7369 (persistent-action nil
)
7370 (persistent-help "DoNothing")
7371 (name "Anything Completions")
7373 (fc-transformer 'anything-cr-default-transformer
)
7374 (marked-candidates nil
))
7375 "Anything `completing-read' emulation.
7376 PROMPT is the prompt name to use.
7377 COLLECTION can be a list, vector, obarray or hash-table.
7380 TEST: A predicate called with one arg i.e candidate.
7381 INITIAL-INPUT: Same as initial-input arg in `anything'.
7382 BUFFER: Name of anything-buffer.
7383 MUST-MATCH: Candidate selected must be one of COLLECTION.
7384 REQUIRES-PATTERN: Same as anything attribute, default is 0.
7385 HISTORY: A list containing specific history, default is nil.
7386 When it is non--nil, all elements of HISTORY are displayed in
7387 anything-buffer before COLLECTION.
7388 PERSISTENT-ACTION: A function called with one arg i.e candidate.
7389 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
7390 NAME: The name related to this local source.
7391 SORT: A predicate to give to `sort' e.g `string-lessp'.
7392 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
7393 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
7395 Any prefix args passed during `anything-comp-read' invocation will be recorded
7396 in `anything-current-prefix-arg', otherwise if prefix args where given before
7397 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
7398 That's mean you can pass prefix arg before or after calling
7399 a command that use `anything-comp-read'."
7400 (when (get-buffer anything-action-buffer
)
7401 (kill-buffer anything-action-buffer
))
7402 (flet ((action-fn (candidate)
7403 (if marked-candidates
7404 (anything-marked-candidates)
7405 (identity candidate
))))
7408 `(((name .
,(format "%s History" name
))
7409 (candidates .
(lambda ()
7410 (anything-comp-read-get-candidates history
)))
7412 (persistent-action .
,persistent-action
)
7413 (persistent-help .
,persistent-help
)
7414 (action .
,'action-fn
))
7418 (let ((cands (anything-comp-read-get-candidates
7419 collection test sort
)))
7420 (if (or must-match
(string= anything-pattern
""))
7421 cands
(append (list anything-pattern
) cands
)))))
7422 (filtered-candidate-transformer ,fc-transformer
)
7423 (requires-pattern .
,requires-pattern
)
7424 (persistent-action .
,persistent-action
)
7425 (persistent-help .
,persistent-help
)
7427 (action .
,'action-fn
)))
7428 :input initial-input
7434 (defun anything-c-get-pid-from-process-name (process-name)
7435 "Get pid from running process PROCESS-NAME."
7436 (loop with process-list
= (list-system-processes)
7437 for pid in process-list
7438 for process
= (assoc-default 'comm
(process-attributes pid
))
7439 when
(and process
(string-match process-name process
))
7443 (defun anything-run-or-raise (exe &optional file
)
7444 "Generic command that run asynchronously EXE.
7445 If EXE is already running just jump to his window if `anything-raise-command'
7447 When FILE argument is provided run EXE with FILE.
7448 In this case EXE must be provided as \"EXE %s\"."
7449 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
7451 (proc (if file
(concat real-com
" " file
) real-com
)))
7452 (if (get-process proc
)
7453 (if anything-raise-command
7454 (shell-command (format anything-raise-command real-com
))
7455 (error "Error: %s is already running" real-com
))
7456 (when (loop for i in anything-c-external-commands-list thereis real-com
)
7457 (message "Starting %s..." real-com
)
7459 (start-process-shell-command proc nil
(format exe file
))
7460 (start-process-shell-command proc nil real-com
))
7461 (set-process-sentinel
7463 #'(lambda (process event
)
7464 (when (and (string= event
"finished\n")
7465 anything-raise-command
7466 (not (anything-c-get-pid-from-process-name real-com
)))
7467 (shell-command (format anything-raise-command
"emacs")))
7468 (message "%s process...Finished." process
))))
7469 (setq anything-c-external-commands-list
7471 (delete real-com anything-c-external-commands-list
))))))
7474 (defvar anything-external-command-history nil
)
7476 (defun anything-c-run-external-command (program)
7477 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
7478 If program is already running exit with error.
7479 You can set your own list of commands with
7480 `anything-c-external-commands-list'."
7484 (anything-c-external-commands-list-1 'sort
)
7486 :name
"External Commands"
7487 :history anything-external-command-history
)))
7488 (anything-run-or-raise program
)
7489 (setq anything-external-command-history
7490 (cons program
(delete program
7491 (loop for i in anything-external-command-history
7492 when
(executable-find i
) collect i
)))))
7494 (defsubst* anything-c-position
(item seq
&key
(test 'eq
))
7495 "A simple and faster replacement of CL `position'."
7496 (loop for i in seq for index from
0
7497 when
(funcall test i item
) return index
))
7499 (defvar anything-c-source-ratpoison-commands
7500 '((name .
"Ratpoison Commands")
7501 (init . anything-c-ratpoison-commands-init
)
7502 (candidates-in-buffer)
7503 (action ("Execute the command" . anything-c-ratpoison-commands-execute
))
7504 (display-to-real . anything-c-ratpoison-commands-display-to-real
)
7505 (candidate-number-limit)))
7506 ;; (anything 'anything-c-source-ratpoison-commands)
7508 (defun anything-c-ratpoison-commands-init ()
7509 (unless (anything-candidate-buffer)
7510 (with-current-buffer (anything-candidate-buffer 'global
)
7511 ;; with ratpoison prefix key
7513 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help"))
7514 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
7515 (replace-match "<ratpoison> \\1: \\2"))
7516 (goto-char (point-max))
7519 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help top"))
7520 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
7521 (replace-match "\\1: \\2")))))
7523 (defun anything-c-ratpoison-commands-display-to-real (display)
7524 (and (string-match ": " display
)
7525 (substring display
(match-end 0))))
7527 (defun anything-c-ratpoison-commands-execute (candidate)
7528 (call-process "ratpoison" nil nil nil
"-ic" candidate
))
7531 (defun anything-ratpoison-commands ()
7532 "Preconfigured `anything' to execute ratpoison commands."
7534 (anything-other-buffer 'anything-c-source-ratpoison-commands
7535 "*anything ratpoison commands*"))
7537 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7539 (defvar anything-c-external-commands-list nil
7540 "A list of all external commands the user can execute. If this
7541 variable is not set by the user, it will be calculated
7544 (defun anything-c-external-commands-list-1 (&optional sort
)
7545 "Returns a list of all external commands the user can execute.
7546 If `anything-c-external-commands-list' is non-nil it will
7547 return its contents. Else it calculates all external commands
7548 and sets `anything-c-external-commands-list'."
7549 (if anything-c-external-commands-list
7550 anything-c-external-commands-list
7551 (setq anything-c-external-commands-list
7553 with paths
= (split-string (getenv "PATH") path-separator
)
7554 with completions
= ()
7556 when
(and (file-exists-p dir
) (file-accessible-directory-p dir
))
7557 for lsdir
= (loop for i in
(directory-files dir t
)
7558 for bn
= (file-name-nondirectory i
)
7559 when
(and (not (member bn completions
))
7560 (not (file-directory-p i
))
7561 (file-executable-p i
))
7563 append lsdir into completions
7564 finally return
(if sort
(sort completions
'string-lessp
) completions
)))))
7567 (defun anything-c-file-buffers (filename)
7568 "Returns a list of buffer names corresponding to FILENAME."
7569 (let ((name (expand-file-name filename
))
7571 (dolist (buf (buffer-list) buf-list
)
7572 (let ((bfn (buffer-file-name buf
)))
7573 (when (and bfn
(string= name bfn
))
7574 (push (buffer-name buf
) buf-list
))))))
7577 (defun anything-c-delete-file (file)
7578 "Delete the given file after querying the user.
7579 Ask to kill buffers associated with that file, too."
7580 (let ((buffers (anything-c-file-buffers file
)))
7581 (if (< emacs-major-version
24)
7582 ;; `dired-delete-file' in Emacs versions < 24
7583 ;; doesn't support delete-by-moving-to-trash
7584 ;; so use `delete-directory' and `delete-file'
7586 (cond ((and (not (file-symlink-p file
))
7587 (file-directory-p file
)
7588 (directory-files file t dired-re-no-dot
))
7589 (when (y-or-n-p (format "Recursive delete of `%s'? " file
))
7590 (delete-directory file
'recursive
)))
7591 ((and (not (file-symlink-p file
))
7592 (file-directory-p file
))
7593 (delete-directory file
))
7594 (t (delete-file file
)))
7596 file
'dired-recursive-deletes delete-by-moving-to-trash
))
7598 (dolist (buf buffers
)
7599 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
7600 (kill-buffer buf
))))))
7602 (defun anything-get-mailcap-for-file (filename)
7603 "Get the command to use for FILENAME from mailcap files.
7604 The command is like <command %s> and is meant to use with `format'."
7605 (mailcap-parse-mailcaps)
7606 (let* ((ext (file-name-extension filename
))
7607 (mime (when ext
(mailcap-extension-to-mime ext
))))
7608 (when mime
(mailcap-mime-info mime
))))
7610 (defun anything-get-default-program-for-file (filename)
7611 "Try to find a default program to open FILENAME.
7612 Try first in `anything-c-external-programs-associations' and then in mailcap file
7613 if nothing found return nil."
7614 (let* ((ext (file-name-extension filename
))
7615 (def-prog (assoc-default ext anything-c-external-programs-associations
)))
7616 (if (and def-prog
(not (string= def-prog
"")))
7617 (concat def-prog
" %s")
7618 (anything-get-mailcap-for-file filename
))))
7620 (defun anything-c-open-file-externally (file)
7621 "Open FILE with an external program.
7622 Try to guess which program to use with `anything-get-default-program-for-file'.
7623 If not found or a prefix arg is given query the user which tool to use."
7624 (let* ((fname (expand-file-name file
))
7625 (collection (anything-c-external-commands-list-1 'sort
))
7626 (def-prog (anything-get-default-program-for-file fname
))
7627 (real-prog-name (if (or anything-current-prefix-arg
(not def-prog
))
7628 ;; Prefix arg or no default program.
7631 "Program: " collection
7633 :name
"Open file Externally"
7634 :history anything-external-command-history
)
7635 ;; Always prompt to set this program as default.
7636 (setq def-prog nil
))
7637 ;; No prefix arg or default program exists.
7638 (replace-regexp-in-string " %s\\| '%s'" "" def-prog
)))
7639 (program (concat real-prog-name
" '%s'")))
7640 (unless (or def-prog
; Association exists, no need to record it.
7641 ;; Don't try to record non--filenames associations (e.g urls).
7642 (not (file-exists-p fname
)))
7646 "Do you want to make `%s' the default program for this kind of files? "
7648 (anything-aif (assoc (file-name-extension fname
)
7649 anything-c-external-programs-associations
)
7650 (setq anything-c-external-programs-associations
7651 (delete it anything-c-external-programs-associations
)))
7652 (push (cons (file-name-extension fname
)
7654 "Program (Add args maybe and confirm): " real-prog-name
))
7655 anything-c-external-programs-associations
)
7656 (customize-save-variable 'anything-c-external-programs-associations
7657 anything-c-external-programs-associations
)))
7658 (anything-run-or-raise program file
)
7659 (setq anything-external-command-history
7660 (cons real-prog-name
7661 (delete real-prog-name
7662 (loop for i in anything-external-command-history
7663 when
(executable-find i
) collect i
))))))
7667 (defun w32-shell-execute-open-file (file)
7668 (interactive "fOpen file:")
7670 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
7672 (replace-regexp-in-string ; strip cygdrive paths
7673 "/cygdrive/\\(.\\)" "\\1:"
7674 file nil nil
) nil t
))))
7676 (defun anything-c-open-file-with-default-tool (file)
7677 "Open FILE with the default tool on this platform."
7678 (if (eq system-type
'windows-nt
)
7679 (w32-shell-execute-open-file file
)
7680 (start-process "anything-c-open-file-with-default-tool"
7682 (cond ((eq system-type
'gnu
/linux
)
7684 ((or (eq system-type
'darwin
) ;; Mac OS X
7685 (eq system-type
'macos
)) ;; Mac OS 9
7689 (defun anything-c-open-dired (file)
7690 "Opens a dired buffer in FILE's directory. If FILE is a
7691 directory, open this directory."
7692 (if (file-directory-p file
)
7694 (dired (file-name-directory file
))
7695 (dired-goto-file file
)))
7697 (defun anything-c-display-to-real-line (candidate)
7698 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
7699 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
7700 (error "Line number not found")))
7702 (defun anything-c-action-line-goto (lineno-and-content)
7703 (apply #'anything-goto-file-line
(anything-interpret-value (anything-attr 'target-file
))
7704 (append lineno-and-content
7705 (list (if (and (anything-attr-defined 'target-file
)
7706 (not anything-in-persistent-action
))
7707 'find-file-other-window
7710 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
7711 (apply #'anything-goto-file-line
7712 (if (stringp file-line-content
)
7713 ;; Case: filtered-candidate-transformer is skipped
7714 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content
))
7715 file-line-content
)))
7718 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
7719 (delq nil
(mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates
)))
7721 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
7722 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
)
7723 (let ((filename (match-string 1 candidate
))
7724 (lineno (match-string 2 candidate
))
7725 (content (match-string 3 candidate
)))
7726 (cons (format "%s:%s\n %s"
7727 (propertize filename
'face compilation-info-face
)
7728 (propertize lineno
'face compilation-line-face
)
7730 (list (expand-file-name
7732 (or (anything-interpret-value (anything-attr 'default-directory
))
7733 (and (anything-candidate-buffer)
7735 'default-directory
(anything-candidate-buffer)))))
7736 (string-to-number lineno
) content
)))))
7738 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
7739 (anything-aif (anything-attr 'before-jump-hook
)
7741 (when file
(funcall find-file-function file
))
7742 (if (anything-attr-defined 'adjust
)
7743 (anything-c-goto-line-with-adjustment lineno content
)
7744 (anything-goto-line lineno
))
7745 (unless (anything-attr-defined 'recenter
)
7746 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
7747 (anything-aif (anything-attr 'after-jump-hook
)
7749 (when anything-in-persistent-action
7750 (anything-match-line-color-current-line)))
7752 (defun anything-find-file-as-root (candidate)
7753 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
7755 (defun anything-find-many-files (ignore)
7756 (mapc 'find-file
(anything-marked-candidates)))
7758 ;; borrowed from etags.el
7759 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
7760 (defun anything-c-goto-line-with-adjustment (line line-content
)
7763 ;; This constant is 1/2 the initial search window.
7764 ;; There is no sense in making it too small,
7765 ;; since just going around the loop once probably
7766 ;; costs about as much as searching 2000 chars.
7769 pat
(concat (if (eq selective-display t
)
7770 "\\(^\\|\^m\\) *" "^ *") ;allow indent
7771 (regexp-quote line-content
)))
7772 ;; If no char pos was given, try the given line number.
7773 (setq startpos
(progn (anything-goto-line line
) (point)))
7774 (or startpos
(setq startpos
(point-min)))
7775 ;; First see if the tag is right at the specified location.
7776 (goto-char startpos
)
7777 (setq found
(looking-at pat
))
7778 (while (and (not found
)
7780 (goto-char (- startpos offset
))
7783 (re-search-forward pat
(+ startpos offset
) t
)
7784 offset
(* 3 offset
))) ; expand search window
7786 (re-search-forward pat nil t
)
7787 (error "not found")))
7788 ;; Position point at the right place
7789 ;; if the search string matched an extra Ctrl-m at the beginning.
7790 (and (eq selective-display t
)
7793 (beginning-of-line))
7795 (anything-document-attribute 'default-directory
"type . file-line"
7796 "`default-directory' to interpret file.")
7797 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
7798 "Function to call before jumping to the target location.")
7799 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
7800 "Function to call after jumping to the target location.")
7801 (anything-document-attribute 'adjust
"type . file-line"
7802 "Search around line matching line contents.")
7803 (anything-document-attribute 'recenter
"type . file-line / line"
7804 "`recenter' after jumping.")
7805 (anything-document-attribute 'target-file
"type . line"
7806 "Goto line of target-file.")
7809 (defun anything-c-call-interactively (cmd-or-name)
7810 "Execute CMD-OR-NAME as Emacs command.
7811 It is added to `extended-command-history'.
7812 `anything-current-prefix-arg' is used as the command's prefix argument."
7813 (setq extended-command-history
7814 (cons (anything-c-stringify cmd-or-name
)
7815 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
7816 (let ((current-prefix-arg anything-current-prefix-arg
)
7817 (cmd (anything-c-symbolify cmd-or-name
)))
7818 (if (stringp (symbol-function cmd
))
7819 (execute-kbd-macro (symbol-function cmd
))
7820 (setq this-command cmd
)
7821 (call-interactively cmd
))))
7824 (defun anything-c-set-variable (var)
7825 "Set value to VAR interactively."
7827 (let ((sym (anything-c-symbolify var
)))
7828 (set sym
(eval-minibuffer (format "Set %s: " var
)
7829 (prin1-to-string (symbol-value sym
))))))
7831 ;; (anything-c-set-variable 'hh)
7833 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7834 (defvar anything-match-line-overlay-face nil
)
7835 (defvar anything-match-line-overlay nil
)
7837 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
7838 "Highlight and underline current position"
7839 (let ((args (list (or start
(line-beginning-position))
7840 (or end
(1+ (line-end-position)))
7842 (if (not anything-match-line-overlay
)
7843 (setq anything-match-line-overlay
(apply 'make-overlay args
))
7844 (apply 'move-overlay anything-match-line-overlay args
)))
7845 (overlay-put anything-match-line-overlay
7846 'face
(or face anything-match-line-overlay-face
))
7851 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
7853 (defface anything-overlay-line-face
'((t (:background
"IndianRed4" :underline t
)))
7854 "Face for source header in the anything buffer." :group
'anything
)
7856 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
7858 (defun anything-match-line-cleanup ()
7859 (when anything-match-line-overlay
7860 (delete-overlay anything-match-line-overlay
)
7861 (setq anything-match-line-overlay nil
)))
7863 (defun anything-match-line-update ()
7864 (when anything-match-line-overlay
7865 (delete-overlay anything-match-line-overlay
)
7866 (anything-match-line-color-current-line)))
7868 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
7869 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
7871 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7873 (defun anything-c-transform-file-load-el (actions candidate
)
7874 "Add action to load the file CANDIDATE if it is an emacs lisp
7875 file. Else return ACTIONS unmodified."
7876 (if (member (file-name-extension candidate
) '("el" "elc"))
7877 (append actions
'(("Load Emacs Lisp File" . load-file
)))
7880 (defun anything-c-transform-file-browse-url (actions candidate
)
7881 "Add an action to browse the file CANDIDATE if it in a html
7882 file or URL. Else return ACTIONS unmodified."
7883 (let ((browse-action '("Browse with Browser" . browse-url
)))
7884 (cond ((string-match "^http\\|^ftp" candidate
)
7885 (cons browse-action actions
))
7886 ((string-match "\\.html?$" candidate
)
7887 (append actions
(list browse-action
)))
7891 (defun anything-c-transform-function-call-interactively (actions candidate
)
7892 "Add an action to call the function CANDIDATE interactively if
7893 it is a command. Else return ACTIONS unmodified."
7894 (if (commandp (intern-soft candidate
))
7895 (append actions
'(("Call Interactively"
7897 anything-c-call-interactively
)))
7901 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
7902 "If CANDIDATE's `car' is a command, then add an action to
7903 evaluate it and put it onto the `command-history'."
7904 (if (commandp (car (read candidate
)))
7905 ;; Make it first entry
7906 (cons '("Eval and put onto command-history" .
7908 (let ((sym (read sexp
)))
7910 (setq command-history
7911 (cons sym command-history
)))))
7915 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7917 (defun anything-c-skip-boring-buffers (buffers)
7918 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
7920 (defun anything-c-skip-current-buffer (buffers)
7921 (if anything-allow-skipping-current-buffer
7922 (remove (buffer-name anything-current-buffer
) buffers
)
7925 (defun anything-c-shadow-boring-buffers (buffers)
7926 "Buffers matching `anything-c-boring-buffer-regexp' will be
7927 displayed with the `file-name-shadow' face if available."
7928 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
7930 (defvar anything-c-buffer-display-string-functions
7931 '(anything-c-buffer-display-string--compilation
7932 anything-c-buffer-display-string--shell
7933 anything-c-buffer-display-string--eshell
)
7934 "Functions to setup display string for buffer.
7936 Function has one argument, buffer name.
7937 If it returns string, use it.
7938 If it returns nil, display buffer name.
7939 See `anything-c-buffer-display-string--compilation' for example.")
7941 (defun anything-c-transform-buffer-display-string (buffers)
7942 "Setup display string for buffer candidates
7943 using `anything-c-buffer-display-string-functions'."
7944 (loop for buf in buffers
7948 for disp
= (progn (set-buffer buf
)
7949 (run-hook-with-args-until-success
7950 'anything-c-buffer-display-string-functions buf
))
7951 collect
(if disp
(cons disp buf
) buf
)))
7953 (defun anything-c-buffer-display-string--compilation (buf)
7954 (anything-aif (car compilation-arguments
)
7955 (format "%s: %s [%s]" buf it default-directory
)))
7956 (defun anything-c-buffer-display-string--eshell (buf)
7957 (when (eq major-mode
'eshell-mode
)
7958 (format "%s: %s [%s]" buf
7959 (ignore-errors (ring-ref eshell-history-ring
0))
7960 default-directory
)))
7961 (defun anything-c-buffer-display-string--shell (buf)
7962 (when (eq major-mode
'shell-mode
)
7963 (format "%s: %s [%s]" buf
7964 (ignore-errors (ring-ref comint-input-ring
0))
7965 default-directory
)))
7968 (defun anything-c-shadow-boring-files (files)
7969 "Files matching `anything-c-boring-file-regexp' will be
7970 displayed with the `file-name-shadow' face if available."
7971 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
7973 (defun anything-c-skip-boring-files (files)
7974 "Files matching `anything-c-boring-file-regexp' will be skipped."
7975 (anything-c-skip-entries files anything-c-boring-file-regexp
))
7976 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
7978 (defun anything-c-skip-current-file (files)
7979 "Current file will be skipped."
7980 (remove (buffer-file-name anything-current-buffer
) files
))
7982 (defun anything-c-w32-pathname-transformer (args)
7983 "Change undesirable features of windows pathnames to ones more acceptable to
7984 other candidate transformers."
7985 (if (eq system-type
'windows-nt
)
7987 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
7989 (replace-regexp-in-string "\\\\" "/" y
)) args
))
7992 (defun anything-c-shorten-home-path (files)
7993 "Replaces /home/user with ~."
7994 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
7996 (mapcar (lambda (file)
7997 (if (and (stringp file
) (string-match home file
))
7998 (cons (replace-match "~" nil nil file
) file
)
8003 (defun anything-c-mark-interactive-functions (functions)
8004 "Mark interactive functions (commands) with (i) after the function name."
8006 (loop for function in functions
8007 do
(push (cons (concat function
8008 (when (commandp (intern-soft function
)) " (i)"))
8011 finally
(return (nreverse list
)))))
8013 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8016 (defvar anything-c-adaptive-done nil
8017 "nil if history information is not yet stored for the current
8020 (defvar anything-c-adaptive-history nil
8021 "Contains the stored history information.
8022 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
8024 (defcustom anything-c-use-adaptative-sorting nil
8025 "*Wheter to use or not adaptative sorting.
8026 Even if a source use it, it will have no effect when set to nil."
8028 :group
'anything-config
)
8030 (defadvice anything-initialize
(before anything-c-adaptive-initialize activate
)
8031 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
8032 when anything is started."
8033 (when anything-c-use-adaptative-sorting
8034 (setq anything-c-adaptive-done nil
)))
8036 (defadvice anything-exit-minibuffer
(before anything-c-adaptive-exit-minibuffer activate
)
8037 "Advise `anything-exit-minibuffer' to store history information
8038 when a candidate is selected with RET."
8039 (when anything-c-use-adaptative-sorting
8040 (anything-c-adaptive-store-selection)))
8042 (defadvice anything-select-action
(before anything-c-adaptive-select-action activate
)
8043 "Advise `anything-select-action' to store history information
8044 when the user goes to the action list with TAB."
8045 (when anything-c-use-adaptative-sorting
8046 (anything-c-adaptive-store-selection)))
8048 (defun anything-c-source-use-adaptative-p (&optional source-name
)
8049 "Return current source only if it use adaptative history, nil otherwise."
8050 (when anything-c-use-adaptative-sorting
8051 (let* ((source (or source-name
(anything-get-current-source)))
8052 (adapt-source (or (assoc-default 'filtered-candidate-transformer
8053 (assoc (assoc-default 'type source
)
8054 anything-type-attributes
))
8055 (assoc-default 'candidate-transformer
8056 (assoc (assoc-default 'type source
)
8057 anything-type-attributes
))
8058 (assoc-default 'filtered-candidate-transformer source
)
8059 (assoc-default 'candidate-transformer source
))))
8060 (if (listp adapt-source
)
8061 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
8062 (when (eq adapt-source
'anything-c-adaptive-sort
) source
)))))
8064 (defun anything-c-adaptive-store-selection ()
8065 "Store history information for the selected candidate."
8066 (unless anything-c-adaptive-done
8067 (setq anything-c-adaptive-done t
)
8068 (let ((source (anything-c-source-use-adaptative-p)))
8070 (let* ((source-name (or (assoc-default 'type source
)
8071 (assoc-default 'name source
)))
8072 (source-info (or (assoc source-name anything-c-adaptive-history
)
8074 (push (list source-name
) anything-c-adaptive-history
)
8075 (car anything-c-adaptive-history
))))
8076 (selection (anything-get-selection))
8077 (selection-info (progn
8080 (let ((found (assoc selection
(cdr source-info
))))
8085 ;; move entry to the beginning of the
8086 ;; list, so that it doesn't get
8087 ;; trimmed when the history is
8090 (delete found
(cdr source-info
)))
8093 (cadr source-info
)))
8094 (pattern-info (progn
8095 (setcdr selection-info
8097 (let ((found (assoc anything-pattern
(cdr selection-info
))))
8100 (cons anything-pattern
0)
8102 ;; move entry to the beginning of the
8103 ;; list, so if two patterns used the
8104 ;; same number of times then the one
8105 ;; used last appears first in the list
8106 (setcdr selection-info
8107 (delete found
(cdr selection-info
)))
8109 (cdr selection-info
)))
8110 (cadr selection-info
))))
8112 ;; increase usage count
8113 (setcdr pattern-info
(1+ (cdr pattern-info
)))
8115 ;; truncate history if needed
8116 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
8117 (setcdr selection-info
8118 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
8120 (defun anything-c-adaptative-maybe-load-history ()
8121 (when (and anything-c-use-adaptative-sorting
8122 (file-readable-p anything-c-adaptive-history-file
))
8123 (load-file anything-c-adaptive-history-file
)))
8125 (add-hook 'emacs-startup-hook
'anything-c-adaptative-maybe-load-history
)
8126 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
8128 (defun anything-c-adaptive-save-history ()
8129 "Save history information to file given by `anything-c-adaptive-history-file'."
8131 (when anything-c-use-adaptative-sorting
8134 ";; -*- mode: emacs-lisp -*-\n"
8135 ";; History entries used for anything adaptive display.\n")
8136 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
8139 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
8140 (unless (interactive-p) 'quiet
)))))
8142 (defun anything-c-adaptive-sort (candidates source
)
8143 "Sort the CANDIDATES for SOURCE by usage frequency.
8144 This is a filtered candidate transformer you can use for the
8145 attribute `filtered-candidate-transformer' of a source in
8146 `anything-sources' or a type in `anything-type-attributes'."
8147 (let* ((source-name (or (assoc-default 'type source
)
8148 (assoc-default 'name source
)))
8149 (source-info (assoc source-name anything-c-adaptive-history
)))
8152 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
8154 (mapcar (lambda (candidate-info)
8156 (dolist (pattern-info (cdr candidate-info
))
8157 (if (not (equal (car pattern-info
)
8159 (incf count
(cdr pattern-info
))
8161 ;; if current pattern is equal to the previously
8162 ;; used one then this candidate has priority
8163 ;; (that's why its count is boosted by 10000) and
8164 ;; it only has to compete with other candidates
8165 ;; which were also selected with the same pattern
8166 (setq count
(+ 10000 (cdr pattern-info
)))
8168 (cons (car candidate-info
) count
)))
8171 (if (and usage
(consp usage
))
8172 ;; sort the list in descending order, so candidates with highest
8173 ;; priorty come first
8175 (setq usage
(sort usage
(lambda (first second
)
8176 (> (cdr first
) (cdr second
)))))
8178 ;; put those candidates first which have the highest usage count
8179 (dolist (info usage
)
8180 (when (member* (car info
) candidates
8181 :test
'anything-c-adaptive-compare
)
8182 (push (car info
) sorted
)
8183 (setq candidates
(remove* (car info
) candidates
8184 :test
'anything-c-adaptive-compare
))))
8186 ;; and append the rest
8187 (append (reverse sorted
) candidates nil
))
8188 (message "Your `%s' is maybe corrupted or too old, \
8189 you should reinitialize it with `anything-c-reset-adaptative-history'"
8190 anything-c-adaptive-history-file
)
8193 ;; if there is no information stored for this source then do nothing
8197 (defun anything-c-reset-adaptative-history ()
8198 "Delete all `anything-c-adaptive-history' and his file.
8199 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
8201 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
8202 (setq anything-c-adaptive-history nil
)
8203 (delete-file anything-c-adaptive-history-file
)))
8205 (defun anything-c-adaptive-compare (x y
)
8206 "Compare candidates X and Y taking into account that the
8207 candidate can be in (DISPLAY . REAL) format."
8208 (equal (if (listp x
)
8215 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8216 (defvar anything-outline-goto-near-line-flag t
)
8217 (defvar anything-outline-using nil
)
8218 (defun anything-after-update-hook--outline ()
8219 (if (and (eq anything-outline-using t
)
8220 (eq anything-outline-goto-near-line-flag t
))
8221 (anything-outline-goto-near-line)))
8222 (add-hook 'anything-after-update-hook
'anything-after-update-hook--outline
)
8224 (defun anything-outline-goto-near-line ()
8225 (with-anything-window
8226 ;; TODO need consideration whether to update position by every input.
8227 (when t
; (equal anything-pattern "")
8228 (anything-goto-line 2)
8229 (let ((lineno (with-current-buffer anything-current-buffer
8230 (line-number-at-pos (car anything-current-position
)))))
8232 (while (<= (progn (skip-chars-forward " ")
8233 (or (number-at-point) lineno
))
8238 (return-from exit
))))
8240 (and (bobp) (forward-line 1))
8241 (and (anything-pos-header-line-p) (forward-line -
2))
8242 (anything-mark-current-line)))))
8244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8245 ;; Plug-in: info-index
8246 (defun* anything-c-info-init
(&optional
(file (anything-attr 'info-file
)))
8248 (unless (anything-candidate-buffer)
8249 (save-window-excursion
8252 (tobuf (anything-candidate-buffer 'global
))
8253 (infobuf (current-buffer))
8255 (dolist (node (or (anything-attr 'index-nodes
) (Info-index-nodes)))
8256 (Info-goto-node node
)
8257 (goto-char (point-min))
8258 (while (search-forward "\n* " nil t
)
8259 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t
)
8260 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result
)
8261 (setq s
(point-at-bol)
8263 (with-current-buffer tobuf
8264 (insert-buffer-substring infobuf s e
)
8265 (insert "\n"))))))))))
8267 (defun anything-c-info-goto (node-line)
8268 (Info-goto-node (car node-line
))
8269 (anything-goto-line (cdr node-line
)))
8271 (defun anything-c-info-display-to-real (line)
8273 ;; This regexp is stolen from Info-apropos-matches
8274 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line
)
8275 (cons (format "(%s)%s" (anything-attr 'info-file
) (match-string 2 line
))
8276 (string-to-number (or (match-string 3 line
) "1")))))
8278 (defun anything-c-make-info-source (source file
)
8280 (name .
,(concat "Info Index: " file
))
8282 (init . anything-c-info-init
)
8283 (display-to-real . anything-c-info-display-to-real
)
8284 (get-line . buffer-substring
)
8285 (candidates-in-buffer)
8286 (action ("Goto node" . anything-c-info-goto
))))
8288 (defun anything-compile-source--info-index (source)
8289 (anything-aif (anything-interpret-value (assoc-default 'info-index source
))
8290 (anything-c-make-info-source source it
)
8292 (add-to-list 'anything-compile-source-functions
'anything-compile-source--info-index
)
8294 (anything-document-attribute 'info-index
"info-index plugin"
8295 "Create a source of info index very easily.
8297 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
8299 (anything-document-attribute 'index-nodes
"info-index plugin (optional)"
8300 "Index nodes of info file.
8302 If it is omitted, `Info-index-nodes' is used to collect index nodes.
8303 Some info files are missing index specification.
8305 ex. See `anything-c-source-info-screen'.")
8307 ;; Plug-in: candidates-file
8308 (defun anything-compile-source--candidates-file (source)
8309 (if (assoc-default 'candidates-file source
)
8310 `((init anything-p-candidats-file-init
8311 ,@(let ((orig-init (assoc-default 'init source
)))
8312 (cond ((null orig-init
) nil
)
8313 ((functionp orig-init
) (list orig-init
))
8315 (candidates-in-buffer)
8318 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
8320 (defun anything-p-candidats-file-init ()
8321 (destructuring-bind (file &optional updating
)
8322 (anything-mklist (anything-attr 'candidates-file
))
8323 (setq file
(anything-interpret-value file
))
8324 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
8326 (buffer-disable-undo)
8328 (auto-revert-mode 1)))))
8330 (anything-document-attribute 'candidates-file
"candidates-file plugin"
8331 "Use a file as the candidates buffer.
8333 1st argument is a filename, string or function name or variable name.
8334 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
8336 ;; Plug-in: headline
8337 (defun anything-compile-source--anything-headline (source)
8338 (if (assoc-default 'headline source
)
8339 (append '((init . anything-headline-init
)
8340 (get-line . buffer-substring
)
8343 '((candidates-in-buffer)
8344 (persistent-help .
"Show this line")))
8346 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
8348 (defun anything-headline-init ()
8349 (when (and (anything-current-buffer-is-modified)
8350 (with-current-buffer anything-current-buffer
8351 (eval (or (anything-attr 'condition
) t
))))
8352 (anything-headline-make-candidate-buffer
8353 (anything-interpret-value (anything-attr 'headline
))
8354 (anything-interpret-value (anything-attr 'subexp
)))))
8356 (anything-document-attribute 'headline
"Headline plug-in"
8357 "Regexp string for anything-headline to scan.")
8358 (anything-document-attribute 'condition
"Headline plug-in"
8359 "A sexp representing the condition to use anything-headline.")
8360 (anything-document-attribute 'subexp
"Headline plug-in"
8361 "Display (match-string-no-properties subexp).")
8364 (defun anything-headline-get-candidates (regexp subexp
)
8365 (with-current-buffer anything-current-buffer
8367 (goto-char (point-min))
8368 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
8369 (let (hierarchy curhead
)
8371 (if (numberp subexp
)
8372 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
8373 (cons (buffer-substring (point-at-bol) (point-at-eol))
8375 (hierarchies (headlines)
8376 (1+ (loop for
(_ . hierarchy
) in headlines
8377 maximize hierarchy
)))
8379 (loop for i from
0 to hierarchy
8380 collecting
(aref curhead i
)))
8381 (arrange (headlines)
8382 (unless (null headlines
) ; FIX headlines empty bug!
8383 (loop with curhead
= (make-vector (hierarchies headlines
) "")
8384 for
((str . pt
) . hierarchy
) in headlines
8385 do
(aset curhead hierarchy str
)
8388 (format "H%d:%s" (1+ hierarchy
)
8389 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / "))
8394 (loop for re in regexp
8395 for hierarchy from
0
8396 do
(goto-char (point-min))
8399 while
(re-search-forward re nil t
)
8400 collect
(cons (matched) hierarchy
)))
8401 (lambda (a b
) (> (cdar b
) (cdar a
)))))
8402 (loop while
(re-search-forward regexp nil t
)
8403 collect
(matched))))))))
8406 (defun anything-headline-make-candidate-buffer (regexp subexp
)
8407 (with-current-buffer (anything-candidate-buffer 'local
)
8408 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
8411 (with-current-buffer anything-current-buffer
8412 (line-number-at-pos pos
))
8415 (defun anything-headline-goto-position (pos recenter
)
8418 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
8420 (defun anything-revert-buffer (candidate)
8421 (with-current-buffer candidate
8422 (when (buffer-modified-p)
8423 (revert-buffer t t
))))
8425 (defun anything-revert-marked-buffers (ignore)
8426 (mapc 'anything-revert-buffer
(anything-marked-candidates)))
8428 (defun anything-kill-marked-buffers (ignore)
8429 (mapc 'kill-buffer
(anything-marked-candidates)))
8431 ;; Plug-in: persistent-help
8432 (defun anything-compile-source--persistent-help (source)
8433 (append source
'((header-line . anything-persistent-help-string
))))
8434 (add-to-list 'anything-compile-source-functions
'anything-compile-source--persistent-help
)
8436 (defun anything-persistent-help-string ()
8437 (substitute-command-keys
8438 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
8439 (or (anything-interpret-value (anything-attr 'persistent-help
))
8440 (anything-aif (or (assoc-default 'persistent-action
8441 (anything-get-current-source))
8442 (assoc-default 'action
8443 (anything-get-current-source)))
8444 (cond ((symbolp it
) (symbol-name it
))
8445 ((listp it
) (or (ignore-errors (caar it
)) ""))))
8447 " (keeping session)")))
8449 (anything-document-attribute 'persistent-help
"persistent-help plug-in"
8450 "A string to explain persistent-action of this source.
8451 It also accepts a function or a variable name.")
8453 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
8455 ;; Plug-in: Type customize
8456 (defun anything-c-uniq-list (lst)
8457 "Like `remove-duplicates' in CL.
8458 But cut deeper duplicates and test by `equal'. "
8459 (reverse (remove-duplicates (reverse lst
) :test
'equal
)))
8460 (defvar anything-additional-type-attributes nil
)
8461 (defun anything-c-arrange-type-attribute (type spec
)
8462 "Override type attributes by `define-anything-type-attribute'.
8464 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
8466 Example: Set `play-sound-file' as default action
8467 (anything-c-arrange-type-attribute 'file
8468 '((action (\"Play sound\" . play-sound-file)
8469 REST ;; Rest of actions (find-file, find-file-other-window, ...)
8472 (add-to-list 'anything-additional-type-attributes
8474 (loop with typeattr
= (assoc-default type anything-type-attributes
)
8475 for
(attr . value
) in spec
8478 (anything-c-uniq-list
8479 (loop for v in value
8481 append
(assoc-default attr typeattr
)
8485 collect
(cons attr value
)))))
8486 (put 'anything-c-arrange-type-attribute
'lisp-indent-function
1)
8488 (defun anything-compile-source--type-customize (source)
8489 (anything-aif (assoc-default (assoc-default 'type source
) anything-additional-type-attributes
)
8492 (add-to-list 'anything-compile-source-functions
'anything-compile-source--type-customize t
)
8494 ;; Plug-in: default-action
8495 (defun anything-compile-source--default-action (source)
8496 (anything-aif (assoc-default 'default-action source
)
8497 (append `((action ,it
,@(remove it
(assoc-default 'action source
))))
8500 (add-to-list 'anything-compile-source-functions
'anything-compile-source--default-action t
)
8501 (anything-document-attribute 'default-action
"default-action plug-in"
8504 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8506 (defun anything-c-find-file-or-marked (candidate)
8507 "Open file CANDIDATE or open anything marked files in background."
8508 (let ((marked (anything-marked-candidates)))
8509 (if (> (length marked
) 1)
8510 ;; Open all marked files in background.
8511 (mapc 'find-file-noselect marked
)
8512 (if (and (not (file-exists-p candidate
))
8513 (and ffap-url-regexp
8514 (not (string-match ffap-url-regexp candidate
)))
8515 (string-match "/$" candidate
))
8516 ;; A a non--existing filename ending with /
8517 ;; Create a directory and jump to it.
8518 (when (y-or-n-p (format "Create directory `%s'? " candidate
))
8519 (make-directory candidate
'parent
)
8520 (anything-find-files1 candidate
))
8521 ;; A non--existing filename NOT ending with / or
8522 ;; an existing filename, create or jump to it.
8523 (find-file-at-point (car marked
))))))
8525 (defun anything-delete-marked-files (ignore)
8526 (let* ((files (anything-marked-candidates))
8527 (len (length files
)))
8529 (format "Delete *%s File(s):\n%s"
8531 (mapconcat (lambda (f) (format "- %s\n" f
)) files
""))))
8532 (message "(No deletions performed)")
8534 (set-text-properties 0 (length i
) nil i
)
8535 (anything-c-delete-file i
))
8536 (message "%s File(s) deleted" len
))))
8538 (defun anything-ediff-marked-buffers (candidate &optional merge
)
8539 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
8540 With optional arg `merge' call `ediff-merge-buffers'."
8541 (let ((lg-lst (length (anything-marked-candidates)))
8545 (error "Error:You have to mark at least 1 buffer"))
8547 (setq buf1 anything-current-buffer
8548 buf2
(first (anything-marked-candidates))))
8550 (setq buf1
(first (anything-marked-candidates))
8551 buf2
(second (anything-marked-candidates))))
8553 (error "Error:To much buffers marked!")))
8555 (ediff-merge-buffers buf1 buf2
)
8556 (ediff-buffers buf1 buf2
))))
8558 (defun anything-bookmark-get-bookmark-from-name (bmk)
8559 "Return bookmark name even if it is a bookmark with annotation.
8560 e.g prepended with *.
8561 Return nil if bmk is not a valid bookmark."
8562 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
8563 (if (assoc bookmark bookmark-alist
)
8565 (when (assoc bmk bookmark-alist
)
8568 (defun anything-delete-marked-bookmarks (ignore)
8569 "Delete this bookmark or all marked bookmarks."
8570 (dolist (i (anything-marked-candidates))
8571 (bookmark-delete (anything-bookmark-get-bookmark-from-name i
)
8574 (defun anything-require-or-error (feature function
)
8575 (or (require feature nil t
)
8576 (error "Need %s to use `%s'." feature function
)))
8578 (defun anything-find-buffer-on-elscreen (candidate)
8579 "Open buffer in new screen, if marked buffers open all in elscreens."
8580 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
8581 (anything-aif (anything-marked-candidates)
8583 (let ((target-screen (elscreen-find-screen-by-buffer
8584 (get-buffer i
) 'create
)))
8585 (elscreen-goto target-screen
)))
8586 (let ((target-screen (elscreen-find-screen-by-buffer
8587 (get-buffer candidate
) 'create
)))
8588 (elscreen-goto target-screen
))))
8590 (defun anything-elscreen-find-file (file)
8591 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
8592 (elscreen-find-file file
))
8594 ;; Toggle anything-match-plugin
8595 (defvar anything-mp-initial-highlight-delay nil
)
8596 (defun anything-c-toggle-match-plugin ()
8597 "Toggle anything-match-plugin."
8599 (let ((anything-match-plugin-enabled
8600 (member 'anything-compile-source--match-plugin
8601 anything-compile-source-functions
)))
8602 (flet ((disable-match-plugin ()
8603 (setq anything-compile-source-functions
8604 (delq 'anything-compile-source--match-plugin
8605 anything-compile-source-functions
))
8606 (setq anything-mp-initial-highlight-delay
8607 anything-mp-highlight-delay
)
8608 (setq anything-mp-highlight-delay nil
))
8609 (enable-match-plugin ()
8610 (require 'anything-match-plugin
)
8611 (unless anything-mp-initial-highlight-delay
8612 (setq anything-mp-initial-highlight-delay
8613 anything-mp-highlight-delay
))
8614 (setq anything-compile-source-functions
8615 (cons 'anything-compile-source--match-plugin
8616 anything-compile-source-functions
))
8617 (unless anything-mp-highlight-delay
8618 (setq anything-mp-highlight-delay
8619 anything-mp-initial-highlight-delay
))))
8620 (if anything-match-plugin-enabled
8621 (when (y-or-n-p "Really disable match-plugin? ")
8622 (disable-match-plugin)
8623 (message "Anything-match-plugin disabled"))
8624 (when (y-or-n-p "Really enable match-plugin? ")
8625 (enable-match-plugin)
8626 (message "Anything-match-plugin enabled"))))))
8629 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8631 ;;;; Type Attributes
8632 (define-anything-type-attribute 'buffer
8635 `(("Switch to buffer other window" . switch-to-buffer-other-window
)
8636 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin
:popup-buffer
))
8637 ("Switch to buffer" . switch-to-buffer
))
8638 `(("Switch to buffer" . switch-to-buffer
)
8639 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin
:popup-buffer
))
8640 ("Switch to buffer other window" . switch-to-buffer-other-window
)
8641 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)))
8642 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
8643 ("View buffer" . view-buffer
)
8644 ("Display buffer" . display-buffer
)
8645 ("Revert buffer" . anything-revert-buffer
)
8646 ("Revert Marked buffers" . anything-revert-marked-buffers
)
8647 ("Insert buffer" . insert-buffer
)
8648 ("Kill buffer" . kill-buffer
)
8649 ("Kill Marked buffers" . anything-kill-marked-buffers
)
8650 ("Diff with file" . diff-buffer-with-file
)
8651 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
8652 ("Ediff Merge marked buffers" .
(lambda (candidate)
8653 (anything-ediff-marked-buffers candidate t
))))
8654 (persistent-help .
"Show this buffer")
8655 (candidate-transformer anything-c-skip-current-buffer
8656 anything-c-skip-boring-buffers
8657 anything-c-transform-buffer-display-string
))
8658 "Buffer or buffer name.")
8660 (define-anything-type-attribute 'file
8663 `(("Find file other window" . find-file-other-window
)
8664 ,(and (locate-library "popwin") '("Find file in popup window" . popwin
:find-file
))
8665 ("Find file(s)" . anything-find-many-files
)
8666 ("Find file as root" . anything-find-file-as-root
))
8667 `(("Find file" . anything-find-many-files
)
8668 ,(and (locate-library "popwin") '("Find file in popup window" . popwin
:find-file
))
8669 ("Find file as root" . anything-find-file-as-root
)
8670 ("Find file other window" . find-file-other-window
)
8671 ("Find file other frame" . find-file-other-frame
)))
8672 ("Open dired in file's directory" . anything-c-open-dired
)
8673 ("Grep File(s) `C-u recurse'"
8674 .
(lambda (candidate)
8675 (if anything-current-prefix-arg
8676 (anything-do-grep1 (anything-marked-candidates) 'recurse
)
8677 (anything-do-grep1 (anything-marked-candidates)))))
8678 ("View file" . view-file
)
8679 ("Insert file" . insert-file
)
8680 ("Delete file(s)" . anything-delete-marked-files
)
8681 ("Open file externally (C-u to choose)" . anything-c-open-file-externally
)
8682 ("Open file with default tool" . anything-c-open-file-with-default-tool
)
8683 ("Find file in hex dump" . hexl-find-file
))
8684 (persistent-help .
"Show this file")
8685 (action-transformer anything-c-transform-file-load-el
8686 anything-c-transform-file-browse-url
)
8687 (candidate-transformer anything-c-w32-pathname-transformer
8688 anything-c-skip-current-file
8689 anything-c-skip-boring-files
8690 anything-c-shorten-home-path
))
8693 (let ((actions '(("Describe command" . describe-function
)
8694 ("Add command to kill ring" . anything-c-kill-new
)
8695 ("Go to command's definition" . find-function
)
8696 ("Debug on entry" . debug-on-entry
)
8697 ("Cancel debug on entry" . cancel-debug-on-entry
)
8698 ("Trace function" . trace-function
)
8699 ("Trace function (background)" . trace-function-background
)
8700 ("Untrace function" . untrace-function
))))
8701 (define-anything-type-attribute 'command
8702 `((action ("Call interactively" . anything-c-call-interactively
)
8704 ;; Sort commands according to their usage count.
8705 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
8706 (coerce . anything-c-symbolify
)
8707 (persistent-action . describe-function
))
8708 "Command. (string or symbol)")
8710 (define-anything-type-attribute 'function
8711 `((action .
,actions
)
8712 (action-transformer anything-c-transform-function-call-interactively
)
8713 (candidate-transformer anything-c-mark-interactive-functions
)
8714 (coerce . anything-c-symbolify
))
8715 "Function. (string or symbol)"))
8717 (define-anything-type-attribute 'variable
8718 '((action ("Describe variable" . describe-variable
)
8719 ("Add variable to kill ring" . anything-c-kill-new
)
8720 ("Go to variable's definition" . find-variable
)
8721 ("Set variable" . anything-c-set-variable
))
8722 (coerce . anything-c-symbolify
))
8725 (define-anything-type-attribute 'sexp
8726 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
8727 ("Add s-expression to kill ring" . kill-new
))
8728 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
8729 "String representing S-Expressions.")
8731 (define-anything-type-attribute 'bookmark
8732 `((coerce . anything-bookmark-get-bookmark-from-name
)
8734 ("Jump to bookmark" .
(lambda (bookmark)
8735 (let ((current-prefix-arg anything-current-prefix-arg
))
8736 (bookmark-jump bookmark
))
8738 ("Jump to BM other window" .
(lambda (bookmark)
8739 (bookmark-jump-other-window bookmark
)
8741 ("Bookmark edit annotation" . bookmark-edit-annotation
)
8742 ("Bookmark show annotation" . bookmark-show-annotation
)
8743 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
8744 ,@(when (fboundp 'bmkext-edit-bookmark
)
8745 '(("Edit Bookmark" . bmkext-edit-bookmark
)))
8746 ("Rename bookmark" . bookmark-rename
)
8747 ("Relocate bookmark" . bookmark-relocate
)))
8750 (define-anything-type-attribute 'line
8751 '((display-to-real . anything-c-display-to-real-line
)
8752 (action ("Go to Line" . anything-c-action-line-goto
)))
8753 "LINENO:CONTENT string, eg. \" 16:foo\".
8755 Optional `target-file' attribute is a name of target file.
8757 Optional `before-jump-hook' attribute is a function with no
8758 arguments which is called before jumping to position.
8760 Optional `after-jump-hook' attribute is a function with no
8761 arguments which is called after jumping to position.
8763 If `adjust' attribute is specified, searches the line whose
8764 content is CONTENT near the LINENO.
8766 If `recenter' attribute is specified, the line is displayed at
8767 the center of window, otherwise at the top of window.
8770 (define-anything-type-attribute 'file-line
8771 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
8773 (action ("Go to" . anything-c-action-file-line-goto
)))
8774 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
8776 Optional `default-directory' attribute is a default-directory
8777 FILENAME is interpreted.
8779 Optional `before-jump-hook' attribute is a function with no
8780 arguments which is called before jumping to position.
8782 Optional `after-jump-hook' attribute is a function with no
8783 arguments which is called after jumping to position.
8785 If `adjust' attribute is specified, searches the line whose
8786 content is CONTENT near the LINENO.
8788 If `recenter' attribute is specified, the line is displayed at
8789 the center of window, otherwise at the top of window.
8792 (define-anything-type-attribute 'timer
8793 '((real-to-display . anything-c-timer-real-to-display
)
8794 (action ("Cancel Timer" . cancel-timer
)
8795 ("Describe Function" .
(lambda (tm) (describe-function (timer--function tm
))))
8796 ("Find Function" .
(lambda (tm) (find-function (timer--function tm
)))))
8797 (persistent-action .
(lambda (tm) (describe-function (timer--function tm
))))
8798 (persistent-help .
"Describe Function"))
8801 ;;;; Default `anything-sources'
8802 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
8803 ;; tend to invoke M-x anything directly. So I offer default setting.
8804 (setq anything-sources
8805 '(anything-c-source-buffers+
8806 anything-c-source-recentf
8807 anything-c-source-files-in-current-dir
+))
8810 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
8811 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
8813 (when (fboundp 'expectations
)
8815 (desc "candidates-file plug-in")
8816 (expect '(anything-p-candidats-file-init)
8817 (assoc-default 'init
8818 (car (anything-compile-sources
8820 (candidates-file .
"test.txt")))
8821 '(anything-compile-source--candidates-file)))))
8822 (expect '(anything-p-candidats-file-init
8824 (assoc-default 'init
8825 (car (anything-compile-sources
8827 (candidates-file .
"test.txt")
8828 (init .
(lambda () 1))))
8829 '(anything-compile-source--candidates-file)))))
8830 (expect '(anything-p-candidats-file-init
8832 (assoc-default 'init
8833 (car (anything-compile-sources
8835 (candidates-file .
"test.txt")
8836 (init (lambda () 1))))
8837 '(anything-compile-source--candidates-file)))))
8839 ;; (desc "anything-c-source-buffers")
8840 ;; (expect '(("Buffers" ("foo" "curbuf")))
8841 ;; (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
8842 ;; (let ((anything-c-boring-buffer-regexp
8847 ;; " *Echo Area" " *Minibuf"))))
8848 ;; (flet ((buffer-name (&optional x) x))
8849 ;; (anything-test-candidates 'anything-c-source-buffers))))
8850 (desc "anything-c-stringify")
8852 (anything-c-stringify "str1"))
8854 (anything-c-stringify 'str2
))
8855 (desc "anything-c-symbolify")
8857 (anything-c-symbolify "sym1"))
8859 (anything-c-symbolify 'sym2
))
8860 (desc "plug-in:default-action")
8861 (expect '(((action ("default" . default
) ("original" . original
))
8862 (default-action .
("default" . default
))
8863 (action ("original" . original
))))
8864 (anything-compile-sources
8865 '(((default-action .
("default" . default
))
8866 (action ("original" . original
))))
8867 '(anything-compile-source--default-action)))
8868 (expect '(((action ("a1" . a1
) ("a2" . a2
))
8869 (default-action .
("a1" . a1
))
8870 (action ("a1" . a1
) ("a2" . a2
))))
8871 (anything-compile-sources
8872 '(((default-action .
("a1" . a1
))
8873 (action ("a1" . a1
) ("a2" . a2
))))
8874 '(anything-compile-source--default-action)))
8875 (expect '(((action ("a2" . a2
) ("a1" . a1
))
8876 (default-action .
("a2" . a2
))
8877 (action ("a1" . a1
) ("a2" . a2
))))
8878 (anything-compile-sources
8879 '(((default-action .
("a2" . a2
))
8880 (action ("a1" . a1
) ("a2" . a2
))))
8881 '(anything-compile-source--default-action))))))
8883 (provide 'anything-config
)
8885 ;;; Local Variables:
8886 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
8889 ;; How to save (DO NOT REMOVE!!)
8890 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
8891 ;;; anything-config.el ends here
8893 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
8894 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
8895 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
8896 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
8897 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
8898 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
8899 ;;; LocalWords: dotimes Thierry online vname
8900 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
8901 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
8902 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
8903 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
8904 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
8905 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
8906 ;;; LocalWords: startpos noselect dont desc