* anything.el (define-anything-type-attribute): remove nil entries.
[anything-config.git] / anything-config.el
blob0cf1c126c19060241dcd39a5d9f0bb4957c0a273
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
15 ;; Version: 0.4.1
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:
22 ;; `anything'
25 ;;; This file is NOT part of GNU Emacs
27 ;;; License
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)
32 ;; any later version.
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.
44 ;;; !NOTICE!
46 ;; If this file does not work, upgrade anything.el!
47 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
49 ;;; Commentary:
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 ()
59 ;; (interactive)
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)
68 ;; " *my-anything*"))
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.
86 ;; `anything-mini'
87 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
88 ;; `anything-for-files'
89 ;; Preconfigured `anything' for opening files.
90 ;; `anything-recentf'
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'.
100 ;; `anything-gentoo'
101 ;; Preconfigured `anything' for gentoo linux.
102 ;; `anything-imenu'
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.
112 ;; `anything-bbdb'
113 ;; Preconfigured `anything' for BBDB.
114 ;; `anything-locate'
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.
120 ;; `anything-colors'
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.
134 ;; `anything-emms'
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.
140 ;; `anything-timers'
141 ;; Preconfigured `anything' for timers.
142 ;; `anything-list-emacs-process'
143 ;; Preconfigured `anything' for emacs process.
144 ;; `anything-occur'
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.
152 ;; `anything-regexp'
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'
183 ;; Select source.
184 ;; `anything-toggle-all-marks'
185 ;; 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).
218 ;; `anything-M-x'
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.
252 ;; `anything-create'
253 ;; Preconfigured `anything' to do many create actions from STRING.
254 ;; `anything-top'
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.
260 ;; `anything-apt'
261 ;; Preconfigured `anything' : frontend of APT package manager.
262 ;; `anything-c-shell-command-if-needed'
263 ;; Not documented.
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'
282 ;; Default Value: 50
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'
298 ;; Default Value: 10
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'
306 ;; Default Value: t
307 ;; `anything-c-enable-eval-defun-hack'
308 ;; Default Value: t
309 ;; `anything-tramp-verbose'
310 ;; Default Value: 0
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'
330 ;; Default Value: 10
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
492 ;;; Change log:
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
500 ;;; Contributors:
502 ;; Tamas Patrovics
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>
516 ;;; For Maintainers:
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
531 ;;; TODO
533 ;; - Fix documentation, now many functions haven't documentations.
536 ;;; Require
537 (require 'anything)
538 (require 'thingatpt)
539 (require 'ffap)
540 (require 'cl)
541 (require 'dired-aux)
542 (require 'tramp)
543 (require 'grep)
545 ;;; Code:
547 ;; version check
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")))
559 ;; compatibility
560 (unless (fboundp 'window-system)
561 (defun window-system (&optional arg)
562 window-system))
564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
565 (defgroup anything-config nil
566 "Predefined configurations for `anything.el'."
567 :group 'anything)
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'. "
580 :type 'boolean
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."
585 :type 'string
586 :group 'anything-config)
588 (defcustom anything-c-adaptive-history-length 50
589 "Maximum number of candidates stored for a source."
590 :type 'number
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."
596 :type 'string
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."
602 :type 'string
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."
608 :type 'boolean
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."
614 :type 'string
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."
620 :type 'string
621 :group 'anything-config)
623 (defcustom anything-c-boring-buffer-regexp
624 (rx (or
625 (group bos " ")
626 ;; anything-buffer
627 "*anything"
628 ;; echo area
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."
636 :type 'string
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
643 (rx (or
644 ;; Boring directories
645 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
646 ;; Boring files
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."
655 :type 'string
656 :group 'anything-config)
658 (defcustom anything-kill-ring-threshold 10
659 "*Minimum length to be listed by `anything-c-source-kill-ring'."
660 :type 'integer
661 :group 'anything-config)
663 (defcustom anything-su-or-sudo "su"
664 "What command to use for root access."
665 :type 'string
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."
678 :type 'list
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."
687 :type 'list
688 :group 'anything-config)
690 (defcustom anything-allow-skipping-current-buffer t
691 "Show current buffer or not in anything buffer"
692 :type 'boolean
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 ...)."
699 :type 'boolean
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."
706 :type 'integer
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\"."
713 :type 'string
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.
726 !!WARNING!!
727 This default value is very likely to be changed,
728 because it is under discussion."
729 :type 'string
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'."
735 :type 'boolean
736 :group 'anything-config)
738 (defcustom anything-c-find-files-icons-directory
739 (and (window-system)
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."
744 :type 'string
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."
751 :type 'string
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."
757 :type 'string
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'."
767 :type 'list
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\"\)\) "
774 :type 'list
775 :group 'anything-config)
777 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
778 ;; TODO: This should be integrated in anything.el instead of having
779 ;; a defadvice here.
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)))
798 ;;;###autoload
799 (defun anything-configuration ()
800 "Customize `anything'."
801 (interactive)
802 (customize-group "anything-config"))
804 ;;; Anything-command-map
805 ;;;###autoload
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
853 minibuffer-local-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))
859 ;;; Menu
860 (easy-menu-define nil global-map
861 "`anything' menu"
862 '("Anything"
863 ["All anything commands" anything-execute-anything-command t]
864 ["Find any Files/Buffers" anything-for-files t]
865 "----"
866 ("Files:"
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])
871 ("Buffers:"
872 ["Find buffers" anything-buffers+ t])
873 ("Commands:"
874 ["Emacs Commands" anything-M-x t]
875 ["Externals Commands" anything-c-run-external-command t])
876 ("Info:"
877 ["Info at point" anything-info-at-point t]
878 ["Emacs Manual index" anything-info-emacs t])
879 ("Org:"
880 ["Org keywords" anything-org-keywords t]
881 ["Org headlines" anything-org-headlines t])
882 ("Tools:"
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])
900 "----"
901 ["Prefered Options" anything-configuration t]))
904 ;;; Documentation
905 ;; It is replaced by `anything-help'
906 (defun anything-c-describe-anything-bindings ()
907 "[OBSOLETE] Describe `anything' bindings."
908 (interactive)
909 (anything-run-after-quit
910 #'(lambda ()
911 (with-current-buffer (get-buffer-create "*Anything Help*")
912 (erase-buffer)
913 (insert
914 (substitute-command-keys
915 "The keys that are defined for `anything' are:
916 \\{anything-map}")))
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))
924 ;;; Help message
925 (defun anything-c-list-preconfigured-anything ()
926 (loop with doc
927 with sym
928 for entry in (cdr (assoc
929 (file-truename (locate-library "anything-config"))
930 load-history))
931 if (and (consp entry)
932 (eq (car entry) 'defun)
933 (string-match "^Preconfigured.+$"
934 (setq doc (or (documentation (setq sym (cdr entry)))
935 ""))))
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
943 (lambda ()
944 (concat
945 "\\<anything-map>"
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
962 M-< : First Line
963 M-> : Last Line
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
970 C-k : Delete pattern
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
978 == Visible Marks ==
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))
1007 Enjoy!")))
1009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1010 ;;;###autoload
1011 (defun anything-mini ()
1012 "Preconfigured `anything' lightweight version (buffer -> recentf)."
1013 (interactive)
1014 (anything-other-buffer '(anything-c-source-buffers+ anything-c-source-recentf)
1015 "*anything mini*"))
1016 ;;;###autoload
1017 (defun anything-for-files ()
1018 "Preconfigured `anything' for opening files.
1019 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
1020 (interactive)
1021 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
1023 ;;;###autoload
1024 (defun anything-recentf ()
1025 "Preconfigured `anything' for `recentf'."
1026 (interactive)
1027 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
1029 ;;;###autoload
1030 (defun anything-info-at-point ()
1031 "Preconfigured `anything' for searching info at point."
1032 (interactive)
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*"))
1038 ;;;###autoload
1039 (defun anything-info-emacs ()
1040 "Preconfigured anything for Emacs manual index."
1041 (interactive)
1042 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
1044 ;;;###autoload
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."
1048 (interactive)
1049 (anything-other-buffer 'anything-c-source-kill-ring "*anything kill-ring*"))
1051 ;;;###autoload
1052 (defun anything-minibuffer-history ()
1053 "Preconfigured `anything' for `minibuffer-history'."
1054 (interactive)
1055 (let ((enable-recursive-minibuffers t))
1056 (anything-other-buffer 'anything-c-source-minibuffer-history
1057 "*anything minibuffer-history*")))
1059 ;;;###autoload
1060 (defun anything-gentoo ()
1061 "Preconfigured `anything' for gentoo linux."
1062 (interactive)
1063 (anything-other-buffer '(anything-c-source-gentoo
1064 anything-c-source-use-flags)
1065 "*anything gentoo*"))
1067 ;;;###autoload
1068 (defun anything-imenu ()
1069 "Preconfigured `anything' for `imenu'."
1070 (interactive)
1071 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
1073 ;;;###autoload
1074 (defun anything-google-suggest ()
1075 "Preconfigured `anything' for google search with google suggest."
1076 (interactive)
1077 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
1079 ;;;###autoload
1080 (defun anything-yahoo-suggest ()
1081 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
1082 (interactive)
1083 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
1085 ;;; Converted from anything-show-*-only
1086 ;;;###autoload
1087 (defun anything-for-buffers ()
1088 "Preconfigured `anything' for buffer."
1089 (interactive)
1090 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
1092 ;;;###autoload
1093 (defun anything-buffers+ ()
1094 "Enhanced preconfigured `anything' for buffer."
1095 (interactive)
1096 (anything-other-buffer 'anything-c-source-buffers+ "*anything buffers*"))
1098 ;;;###autoload
1099 (defun anything-bbdb ()
1100 "Preconfigured `anything' for BBDB.
1102 Needs BBDB.
1104 http://bbdb.sourceforge.net/"
1105 (interactive)
1106 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
1108 ;;;###autoload
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."
1113 (interactive)
1114 (anything-other-buffer 'anything-c-source-locate "*anything locate*"))
1116 ;;;###autoload
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/"
1124 (interactive)
1125 (anything-other-buffer 'anything-c-source-w3m-bookmarks
1126 "*anything w3m bookmarks*"))
1128 ;;;###autoload
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 \
1133 to true:
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.
1143 (interactive)
1144 (anything-other-buffer 'anything-c-source-firefox-bookmarks
1145 "*Anything Firefox*"))
1147 ;;;###autoload
1148 (defun anything-colors ()
1149 "Preconfigured `anything' for color."
1150 (interactive)
1151 (anything-other-buffer
1152 '(anything-c-source-colors anything-c-source-customize-face)
1153 "*anything colors*"))
1155 ;;;###autoload
1156 (defun anything-bookmarks ()
1157 "Preconfigured `anything' for bookmarks."
1158 (interactive)
1159 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
1161 ;;;###autoload
1162 (defun anything-c-pp-bookmarks ()
1163 "Preconfigured `anything' for bookmarks (pretty-printed)."
1164 (interactive)
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*"))
1170 ;;;###autoload
1171 (defun anything-c-insert-latex-math ()
1172 "Preconfigured anything for latex math symbols completion."
1173 (interactive)
1174 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
1176 ;;;###autoload
1177 (defun anything-register ()
1178 "Preconfigured `anything' for Emacs registers."
1179 (interactive)
1180 (anything-other-buffer 'anything-c-source-register "*anything register*"))
1182 ;;;###autoload
1183 (defun anything-man-woman ()
1184 "Preconfigured `anything' for Man and Woman pages."
1185 (interactive)
1186 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
1188 ;;;###autoload
1189 (defun anything-org-keywords ()
1190 "Preconfigured `anything' for org keywords."
1191 (interactive)
1192 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
1194 ;;;###autoload
1195 (defun anything-emms ()
1196 "Preconfigured `anything' for emms sources."
1197 (interactive)
1198 (anything '(anything-c-source-emms-streams
1199 anything-c-source-emms-files
1200 anything-c-source-emms-dired)
1201 nil nil nil nil
1202 "*Anything Emms*"))
1204 ;;;###autoload
1205 (defun anything-eev-anchors ()
1206 "Preconfigured `anything' for eev anchors."
1207 (interactive)
1208 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
1210 ;;;###autoload
1211 (defun anything-bm-list ()
1212 "Preconfigured `anything' for visible bookmarks.
1214 Needs bm.el
1216 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
1217 (interactive)
1218 (let ((anything-outline-using t))
1219 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
1221 ;;;###autoload
1222 (defun anything-timers ()
1223 "Preconfigured `anything' for timers."
1224 (interactive)
1225 (anything-other-buffer '(anything-c-source-absolute-time-timers
1226 anything-c-source-idle-time-timers)
1227 "*anything timers*"))
1229 ;;;###autoload
1230 (defun anything-list-emacs-process ()
1231 "Preconfigured `anything' for emacs process."
1232 (interactive)
1233 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
1235 ;;;###autoload
1236 (defun anything-occur ()
1237 "Preconfigured Anything for Occur source."
1238 (interactive)
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*")))
1245 ;;;###autoload
1246 (defun anything-browse-code ()
1247 "Preconfigured anything to browse code."
1248 (interactive)
1249 (anything-other-buffer 'anything-c-source-browse-code "*Browse code*"))
1251 ;;;###autoload
1252 (defun anything-org-headlines ()
1253 "Preconfigured anything to show org headlines."
1254 (interactive)
1255 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
1257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1258 ;;; kill buffers
1259 ;;;###autoload
1260 (defun anything-kill-buffers ()
1261 "Preconfigured `anything' to kill buffer you selected."
1262 (interactive)
1263 (anything
1264 '(((name . "Kill Buffers")
1265 (candidates . anything-c-buffer-list)
1266 (action
1267 ("Kill Buffer" . (lambda (candidate)
1268 (kill-buffer candidate)
1269 (anything-kill-buffers)
1270 )))))
1271 nil nil))
1273 ;;; Regexp
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)))
1289 (list
1290 regexp
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")
1302 (init . (lambda ()
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")
1308 (multiline)
1309 (delayed)
1310 (requires-pattern . 2)
1311 (mode-line . "Press TAB to select action.")
1312 ;; RUBIKITCH:
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).
1317 ;; Can you fix it?
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)
1324 (propertize
1325 (apply 'concat
1326 ;; Line contents
1327 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
1328 ;; subexps
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))
1332 (match-string i))))
1333 ;; match beginning
1334 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
1335 ;; It is implementation problem of candidates-in-buffer.
1336 'anything-realvalue
1337 (1- s)))
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)
1344 outline-minor-mode)
1345 (progn
1346 (gotoline lineno)
1347 (org-reveal))
1348 (gotoline lineno))))
1350 (defun anything-c-regexp-persistent-action (pt)
1351 (goto-char pt)
1352 (anything-persistent-highlight-point))
1354 (defun anything-c-regexp-kill-new (input)
1355 (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))
1367 (end (point-max))
1368 (total (buffer-size)))
1369 (or (/= beg 1) (/= end (1+ total))))))
1371 ;;;###autoload
1372 (defun anything-regexp ()
1373 "Preconfigured anything to build regexps and run query-replace-regexp \
1374 against."
1375 (interactive)
1376 (save-restriction
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)))
1385 (anything :sources
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."
1395 (interactive)
1396 (anything-insert-string
1397 (with-current-buffer anything-current-buffer
1398 (if buffer-file-name (file-name-nondirectory buffer-file-name)
1399 (buffer-name)))))
1401 (defun anything-insert-symbol ()
1402 "Insert current symbol."
1403 (interactive)
1404 (anything-insert-string
1405 (with-current-buffer anything-current-buffer
1406 (save-excursion
1407 (buffer-substring (beginning-of-thing 'symbol)
1408 (end-of-thing 'symbol))))))
1410 (defun anything-insert-selection ()
1411 "Insert current selection."
1412 (interactive)
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."
1420 (interactive)
1421 (anything-set-source-filter '("Buffers")))
1423 (defun anything-show-bbdb-only ()
1424 "[OBSOLETE] Only show sources about BBDB.
1425 Use `anything-bbdb' instead."
1426 (interactive)
1427 (anything-set-source-filter '("BBDB")))
1429 (defun anything-show-locate-only ()
1430 "[OBSOLETE] Only show sources about Locate.
1431 Use `anything-locate' instead."
1432 (interactive)
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."
1438 (interactive)
1439 (anything-set-source-filter '("Info Pages"
1440 "Info Elisp"
1441 "Info Common-Lisp")))
1443 (defun anything-show-imenu-only ()
1444 "[OBSOLETE] Only show sources about Imenu.
1445 Use `anything-imenu' instead."
1446 (interactive)
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."
1452 (interactive)
1453 (anything-set-source-filter '("File Name History"
1454 "Files from Current Directory"
1455 "Recentf")))
1457 (defun anything-show-w3m-bookmarks-only ()
1458 "[OBSOLETE] Only show source about w3m bookmark.
1459 Use `anything-w3m-bookmarks' instead."
1460 (interactive)
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."
1466 (interactive)
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."
1473 (interactive)
1474 (anything-set-source-filter '("Kill Ring")))
1476 (defun anything-show-this-source-only ()
1477 "Only show this source."
1478 (interactive)
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]."
1486 (interactive)
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)
1510 anything-pattern
1511 anything-buffer
1512 anything-sources
1513 anything-compiled-sources
1514 anything-buffer-chars-modified-tick
1515 (anything-samewindow t)
1516 (enable-recursive-minibuffers t))
1517 (unwind-protect
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))
1526 (loop with pos
1527 while (setq pos (next-single-property-change (point) 'anything-header))
1528 do (goto-char pos)
1529 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
1530 do (forward-line 1))))
1532 (defun anything-select-source ()
1533 "Select source."
1534 (interactive)
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)
1540 (anything-aif
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)))
1548 nil "Source: " nil
1549 default "*anything select source*"))
1550 (anything-set-source-filter (list it))
1551 (anything-set-source-filter nil))))
1553 (defun anything-insert-string (str)
1554 "Insert STR."
1555 (delete-minibuffer-contents)
1556 (insert str))
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)))
1578 list))
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)
1585 'file-name-shadow
1586 ;; fall back to default on XEmacs
1587 'default)))
1588 (if (string-match regexp file)
1589 (setq file (propertize file 'face face))))
1590 file)
1591 list))
1593 (defsubst anything-c-stringify (str-or-sym)
1594 "Get string of STR-OR-SYM."
1595 (if (stringp str-or-sym)
1596 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)
1602 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
1630 (save-excursion
1631 (goto-char (anything-get-previous-header-pos))
1632 (anything-next-line)
1633 (let* ((next-head (anything-get-next-header-pos))
1634 (end (and next-head
1635 (save-excursion
1636 (goto-char next-head)
1637 (forward-line -2)
1638 (point))))
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)))
1662 (save-excursion
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 ()
1669 "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"
1672 (interactive)
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)
1687 (forward-char 1)
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."
1699 (save-excursion
1700 (goto-char (point-min))
1701 (loop with it
1702 while (re-search-forward anything-c-create-summary-index-regexp nil t)
1703 collect
1704 (cond ((setq it (match-string-no-properties 1))
1705 (cons 'section it))
1706 ((setq it (match-string-no-properties 2))
1707 `(source ,it .
1708 ,(assoc-default 'name (symbol-value (intern it)))))
1709 ((setq it (match-string-no-properties 3))
1710 `(source ,it .
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."
1717 (save-excursion
1718 (goto-char (point-min))
1719 (search-forward ";; Below are complete source list you can setup in")
1720 (forward-line 1)
1721 (delete-region (point)
1722 (progn (search-forward ";;; Change log:" nil t)
1723 (forward-line -1) (point)))
1724 (insert ";;\n")
1725 (loop with beg
1726 for (kind . value) in (anything-c-create-summary)
1727 for i from 0
1728 do (cond ((eq kind 'section)
1729 (unless (zerop i)
1730 (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))
1731 (insert ";; " value ":\n")
1732 (setq beg (point)))
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1739 ;;;; <Buffer>
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)
1751 (type . buffer)))
1752 ;; (anything 'anything-c-source-buffers)
1754 (defvar anything-c-source-buffer-not-found
1755 '((name . "Create buffer")
1756 (dummy)
1757 (type . buffer)))
1758 ;; (anything 'anything-c-source-buffer-not-found)
1760 ;;; Buffers+
1761 (defface anything-dir-heading '((t (:foreground "Blue" :background "Pink")))
1762 "*Face used for directory headings in dired buffers."
1763 :group 'anything)
1765 (defface anything-file-name
1766 '((t (:foreground "Blue")))
1767 "*Face used for file names (without suffixes) in dired buffers."
1768 :group 'anything)
1770 (defface anything-dir-priv
1771 '((t (:foreground "DarkRed" :background "LightGray")))
1772 "*Face used for directory privilege indicator (d) in dired buffers."
1773 :group 'anything)
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)
1780 (require 'dired)
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)
1798 (type . buffer)
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)
1806 (flet ((kill (item)
1807 (with-current-buffer item
1808 (if (and (buffer-modified-p)
1809 (buffer-file-name (current-buffer)))
1810 (progn
1811 (save-buffer)
1812 (kill-buffer item))
1813 (kill-buffer item))))
1814 (goto (item)
1815 (switch-to-buffer item)))
1816 (if current-prefix-arg
1817 (progn
1818 (kill name)
1819 (anything-delete-current-selection))
1820 (goto name))))
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'."
1826 (interactive)
1827 (anything-run-after-quit
1828 (lambda (f)
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))
1835 org-directory
1836 (expand-file-name org-directory))
1837 default-directory)
1838 (let ((sel (anything-get-selection)))
1839 (if (file-exists-p sel)
1840 (expand-file-name sel)
1841 default-directory)))))
1843 ;;;; <File>
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)
1850 (type . file)))
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.
1860 (type . file)))
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))
1871 else
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.
1884 (type . file)))
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
1897 (disable-shortcuts)
1898 (init . (lambda ()
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")
1911 (volatile)
1912 (candidate-number-limit . 9999)
1913 (action-transformer . anything-find-files-action-transformer)
1914 (action
1915 . ,(delq
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)))
1945 (if (> len 1)
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
1958 prompt
1959 :initial-input (car anything-ff-history)
1960 :history (anything-find-files-history :comp-read nil)))
1961 (win-conf (current-window-configuration)))
1962 (unwind-protect
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
2004 do (load fname))))
2006 (defun anything-find-files-ediff-files (candidate)
2007 "Default action to ediff files in `anything-find-files'."
2008 (ediff-files
2009 candidate
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'."
2015 (ediff-merge-files
2016 candidate
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.
2031 NOTE:
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
2040 "Command: "
2041 (loop for (a . c) in eshell-command-aliases-list
2042 when (string-match "\\$1$" (car c))
2043 collect a))))
2044 (loop
2045 for i in cand-list
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))
2055 (insert
2056 (format "cd %s" (shell-quote-argument
2057 anything-ff-default-directory)))
2058 (eshell-send-input)))
2059 (if (get-buffer "*eshell*")
2060 (progn
2061 (switch-to-buffer "*eshell*")
2062 (cd-eshell))
2063 (call-interactively 'eshell)
2064 (cd-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)
2083 (if (< level 0)
2084 (if empty "../" (concat "../" result))
2085 (cond ((eq system-type 'windows-nt)
2086 (if empty "c:/" result))
2087 (empty "/")
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)))))
2102 ;; Internal.
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."
2109 (interactive "p")
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)
2133 (re-search-forward
2134 (concat anything-ff-last-expanded "$") nil t))
2135 (forward-line 0)
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.
2141 (if window-system
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.
2190 (t pattern))))
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)
2210 path-name-dir)))
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)))
2215 (list 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))
2221 (append
2222 (list path)
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'."
2235 :group 'anything)
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'."
2240 :group 'anything)
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)
2250 (list :type type
2251 :links links
2252 :uid uid
2253 :gid gid
2254 :access-time access-time
2255 :modif-time modif-time
2256 :status status
2257 :size size
2258 :mode mode
2259 :gid-change gid-change
2260 :inode inode
2261 :device-num device-num))))
2262 (cond (type
2263 (let ((result (getf all :type)))
2264 (cond ((stringp result)
2265 "symlink")
2266 (result "directory")
2267 (t "file"))))
2268 (links (getf all :links))
2269 (uid (getf all :uid))
2270 (gid (getf all :gid))
2271 (access-time
2272 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
2273 (modif-time
2274 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
2275 (status
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))
2282 (dired
2283 (concat
2284 (getf all :mode) " "
2285 (number-to-string (getf all :links)) " "
2286 (getf all :uid) ":"
2287 (getf all :gid) " "
2288 (number-to-string (getf all :size)) " "
2289 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
2290 (t all))))
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
2299 " " 'display
2300 (propertize "[?]" 'face 'anything-ffiles-prefix-face)))
2301 (prefix-url (propertize
2302 " " 'display
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)
2320 (cons
2321 (anything-c-prefix-filename
2322 (propertize
2323 i 'face 'anything-dired-symlink-face
2324 'help-echo (file-truename i)))
2326 ((file-directory-p i)
2327 (cons
2328 (anything-c-prefix-filename
2329 (propertize
2330 i 'face anything-c-files-face1
2331 'help-echo (condition-case nil
2332 (anything-ff-attributes i :dired t)
2333 (error nil))))
2336 (cons
2337 (anything-c-prefix-filename
2338 (propertize
2339 i 'face anything-c-files-face2
2340 'help-echo (condition-case nil
2341 (anything-ff-attributes i :dired t)
2342 (error nil))))
2343 i)))))
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
2352 (propertize
2353 i 'face anything-c-files-face2
2354 'help-echo (condition-case nil
2355 (anything-ff-attributes i :dired t)
2356 (error nil)))
2357 "leaf.xpm")
2359 ( ;; Empty directories.
2360 (and (eq t (car (file-attributes i)))
2361 ;; Be sure to have permission to list content.
2362 (file-readable-p i)
2363 (eq 0 (length
2364 (directory-files
2365 i nil directory-files-no-dot-files-regexp t))))
2366 (cons (anything-c-prefix-filename
2367 (propertize
2368 i 'face anything-c-files-face1
2369 'help-echo (condition-case nil
2370 (anything-ff-attributes i :dired t)
2371 (error nil)))
2372 "empty.xpm")
2374 ( ;; Open directories.
2375 (and (eq t (car (file-attributes i))) (get-buffer af))
2376 (cons (anything-c-prefix-filename
2377 (propertize
2378 i 'face anything-c-files-face1
2379 'help-echo (condition-case nil
2380 (anything-ff-attributes i :dired t)
2381 (error nil)))
2382 "open.xpm")
2384 (;; Closed directories.
2385 (eq t (car (file-attributes i)))
2386 (cons (anything-c-prefix-filename
2387 (propertize
2388 i 'face anything-c-files-face1
2389 'help-echo (condition-case nil
2390 (anything-ff-attributes i :dired t)
2391 (error nil)))
2392 "close.xpm")
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))
2413 "leaf.xpm")
2414 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 5)))
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 5)))
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 5)))
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)))
2440 (t actions)))
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")
2453 (progn
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)
2458 (message nil)
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."
2474 (interactive)
2475 (anything-execute-persistent-action 'image-action1))
2477 (defun anything-ff-rotate-right-persistent ()
2478 "Rotate image right without quitting anything."
2479 (interactive)
2480 (anything-execute-persistent-action 'image-action2))
2482 ;; Have no effect if candidate is not an image file.
2483 (define-key anything-map (kbd "M-l") 'anything-ff-rotate-left-persistent)
2484 (define-key anything-map (kbd "M-r") 'anything-ff-rotate-right-persistent)
2486 (defun anything-find-files-persistent-action (candidate)
2487 "Open subtree CANDIDATE without quitting anything.
2488 If CANDIDATE is not a directory expand CANDIDATE filename.
2489 If CANDIDATE is alone, open file CANDIDATE filename.
2490 That's mean:
2491 First hit on C-z expand CANDIDATE second hit open file.
2492 If a prefix arg is given or `anything-follow-mode' is on open file."
2493 (let ((follow (buffer-local-value
2494 'anything-follow-mode
2495 (get-buffer-create anything-buffer)))
2496 (new-pattern (anything-get-selection))
2497 (num-lines-buf (with-current-buffer anything-buffer
2498 (count-lines (point-min) (point-max)))))
2499 (flet ((insert-in-minibuffer (fname)
2500 (with-selected-window (minibuffer-window)
2501 (unless follow
2502 (delete-minibuffer-contents)
2503 (set-text-properties 0 (length fname) nil fname)
2504 (insert fname)))))
2505 (cond (;; A symlink directory, expand it's truename.
2506 (and (file-directory-p candidate) (file-symlink-p candidate))
2507 (insert-in-minibuffer (file-name-as-directory
2508 (file-truename
2509 (expand-file-name candidate)))))
2510 ;; A directory, open it.
2511 ((file-directory-p candidate)
2512 (when (string= (anything-c-basename candidate) "..")
2513 (setq anything-ff-last-expanded anything-ff-default-directory))
2514 (insert-in-minibuffer (file-name-as-directory
2515 (expand-file-name candidate))))
2516 ;; A symlink file, expand to it's true name. (first hit)
2517 ((file-symlink-p candidate)
2518 (insert-in-minibuffer (file-truename candidate)))
2519 ;; A regular file, expand it, (first hit)
2520 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
2521 (insert-in-minibuffer new-pattern))
2522 ;; An image file and it is the second hit on C-z,
2523 ;; show the file in `image-dired'.
2524 ((string-match (image-file-name-regexp) candidate)
2525 (when (buffer-live-p image-dired-display-image-buffer)
2526 (kill-buffer image-dired-display-image-buffer))
2527 (image-dired-display-image candidate)
2528 (message nil)
2529 (display-buffer image-dired-display-image-buffer))
2530 ;; Allow browsing archive on avfs fs.
2531 ;; Assume volume is already mounted with mountavfs.
2532 ((and anything-ff-avfs-directory
2533 (string-match
2534 (regexp-quote (expand-file-name anything-ff-avfs-directory))
2535 (file-name-directory candidate))
2536 (anything-ff-file-compressed-p candidate))
2537 (insert-in-minibuffer (concat candidate "#")))
2538 ;; On second hit we open file.
2539 (t (find-file candidate))))))
2541 (defvar anything-ff-avfs-directory nil
2542 "*The default avfs directory, usually '.avfs'.
2543 When this is set you will be able to expand archive filenames with `C-z'
2544 inside an avfs directory mounted with mountavfs.
2545 See <http://sourceforge.net/projects/avf/>.")
2546 (defvar anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
2547 "*Minimal list of compressed files extension.")
2548 (defun anything-ff-file-compressed-p (candidate)
2549 "Whether CANDIDATE is a compressed file or not."
2550 (member (file-name-extension candidate)
2551 anything-ff-file-compressed-list))
2553 (defun anything-c-insert-file-name-completion-at-point (candidate)
2554 "Insert file name completion at point."
2555 (if buffer-read-only
2556 (error "Error: Buffer `%s' is read-only" (buffer-name))
2557 (let* ((end (point))
2558 (guess (thing-at-point 'filename))
2559 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess)
2560 (string-match "^[^\~]" guess))))
2561 (set-text-properties 0 (length candidate) nil candidate)
2562 (if (and guess (not (string= guess "")) (string-match "^~\\|/.*" guess))
2563 (progn
2564 (search-backward guess (- (point) (length guess)))
2565 (delete-region (point) end)
2566 (if full-path-p
2567 (insert (expand-file-name candidate))
2568 (insert (abbreviate-file-name candidate))))
2569 (error "Aborting completion: No valid file name at point")))))
2571 (defun* anything-find-files-history (&key (comp-read t))
2572 "The `anything-find-files' history.
2573 Show the first `anything-ff-history-max-length' elements of `anything-ff-history'
2574 in an `anything-comp-read'."
2575 (let ((history (when anything-ff-history
2576 (loop with dup for i in anything-ff-history
2577 unless (member i dup) collect i into dup
2578 finally return dup)))) ; Remove dups.
2579 (when history
2580 (setq anything-ff-history
2581 (if (>= (length history) anything-ff-history-max-length)
2582 (subseq history 0 anything-ff-history-max-length)
2583 history))
2584 (if comp-read
2585 (anything-comp-read
2586 "Switch to Directory: "
2587 anything-ff-history
2588 :name "Anything Find Files History"
2589 :must-match t)
2590 anything-ff-history))))
2592 (defun anything-find-files-initial-input (&optional input)
2593 "Return INPUT if present, otherwise try to guess it."
2594 (or (and input (expand-file-name input))
2595 (anything-find-files-input
2596 (ffap-guesser)
2597 (thing-at-point 'filename))))
2599 ;;;###autoload
2600 (defun anything-find-files ()
2601 "Preconfigured `anything' for anything implementation of `find-file'.
2602 Called with a prefix arg show history if some.
2603 Don't call it from programs, use `anything-find-files1' instead.
2604 This is the starting point for nearly all actions you can do on files."
2605 (interactive)
2606 (let ((any-input (if (and current-prefix-arg anything-ff-history)
2607 (anything-find-files-history)
2608 (anything-find-files-initial-input))))
2609 (when (and (eq major-mode 'org-agenda-mode)
2610 org-directory
2611 (not any-input))
2612 (setq any-input (expand-file-name org-directory)))
2613 (if any-input
2614 (anything-find-files1 any-input)
2615 (setq any-input (expand-file-name (anything-c-current-directory)))
2616 (anything-find-files1 any-input (buffer-file-name (current-buffer))))))
2618 (defun anything-find-files1 (fname &optional preselect)
2619 "Find FNAME with `anything' completion.
2620 Like `find-file' but with `anything' support.
2621 Use it for non--interactive calls of `anything-find-files'."
2622 (when (get-buffer anything-action-buffer)
2623 (kill-buffer anything-action-buffer))
2624 (let ((anything-mp-highlight-delay nil))
2625 (anything :sources 'anything-c-source-find-files
2626 :input fname
2627 :preselect preselect
2628 :prompt "Find Files or Url: "
2629 :buffer "*Anything Find Files*")))
2631 (defun anything-find-files-input (fap tap)
2632 "Default input of `anything-find-files'."
2633 (let* ((def-dir (anything-c-current-directory))
2634 (lib (anything-find-library-at-point))
2635 (file-p (and fap (file-exists-p fap)
2636 (file-exists-p
2637 (file-name-directory (expand-file-name tap def-dir))))))
2638 (cond (lib)
2639 (file-p (expand-file-name tap def-dir))
2640 (t fap))))
2642 (defun anything-c-current-directory ()
2643 "Return current-directory name at point.
2644 Useful in dired buffers when there is inserted subdirs."
2645 (if (eq major-mode 'dired-mode)
2646 (dired-current-directory)
2647 default-directory))
2649 (defun anything-find-library-at-point ()
2650 "Try to find library path at point.
2651 Find inside `require' and `declare-function' sexp."
2652 (require 'find-func)
2653 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
2654 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
2655 (sexp (and beg-sexp end-sexp
2656 (buffer-substring-no-properties
2657 (1+ beg-sexp) (1- end-sexp)))))
2658 (ignore-errors
2659 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
2660 (find-library-name
2661 (replace-regexp-in-string
2662 "'\\|\)\\|\(" ""
2663 ;; If require use third arg, ignore it,
2664 ;; always use library path found in `load-path'.
2665 (second (split-string (match-string 0 sexp))))))
2666 ((and sexp (string-match-p "^declare-function" sexp))
2667 (find-library-name
2668 (replace-regexp-in-string
2669 "\"\\|ext:" ""
2670 (third (split-string sexp)))))
2671 (t nil)))))
2673 ;;; Anything completion for `write-file'.==> C-x C-w
2674 (defvar anything-c-source-write-file
2675 `((name . ,(concat "Write File" anything-c-find-files-doc-header))
2676 ;; It is needed for filenames with capital letters
2677 (disable-shortcuts)
2678 (candidates . anything-find-files-get-candidates)
2679 (filtered-candidate-transformer anything-c-find-files-transformer)
2680 (persistent-action . anything-find-files-persistent-action)
2681 (persistent-help . "Expand Candidate")
2682 (volatile)
2683 (action .
2684 (("Write File" . (lambda (candidate)
2685 (write-file candidate 'confirm)))))))
2687 ;;;###autoload
2688 (defun anything-write-file ()
2689 "Preconfigured `anything' providing completion for `write-file'."
2690 (interactive)
2691 (anything 'anything-c-source-write-file
2692 (expand-file-name default-directory)
2693 "Write buffer to file: " nil nil "*Anything write file*"))
2695 ;;; Anything completion for `insert-file'.==> C-x i
2696 (defvar anything-c-source-insert-file
2697 `((name . ,(concat "Insert File" anything-c-find-files-doc-header))
2698 ;; It is needed for filenames with capital letters
2699 (disable-shortcuts)
2700 (candidates . anything-find-files-get-candidates)
2701 (filtered-candidate-transformer anything-c-find-files-transformer)
2702 (persistent-action . anything-find-files-persistent-action)
2703 (persistent-help . "Expand Candidate")
2704 (volatile)
2705 (action .
2706 (("Insert File" . (lambda (candidate)
2707 (when (y-or-n-p (format "Really insert %s in %s "
2708 candidate anything-current-buffer))
2709 (insert-file-contents candidate))))))))
2711 ;;;###autoload
2712 (defun anything-insert-file ()
2713 "Preconfigured `anything' providing completion for `insert-file'."
2714 (interactive)
2715 (anything 'anything-c-source-insert-file
2716 (expand-file-name default-directory)
2717 "Insert file: " nil nil "*Anything insert file*"))
2719 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
2720 (defvar anything-c-source-copy-files
2721 `((name . ,(concat "Copy Files" anything-c-find-files-doc-header))
2722 ;; It is needed for filenames with capital letters
2723 (disable-shortcuts)
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")
2728 (volatile)
2729 (action .
2730 (("Copy File"
2731 . (lambda (candidate)
2732 (anything-dired-action candidate :action 'copy)))
2733 ("Copy and Follow"
2734 . (lambda (candidate)
2735 (anything-dired-action candidate :action 'copy :follow t)))))))
2738 (defvar anything-c-source-rename-files
2739 `((name . ,(concat "Rename Files" anything-c-find-files-doc-header))
2740 ;; It is needed for filenames with capital letters
2741 (disable-shortcuts)
2742 (candidates . anything-find-files-get-candidates)
2743 (filtered-candidate-transformer anything-c-find-files-transformer)
2744 (persistent-action . anything-find-files-persistent-action)
2745 (persistent-help . "Expand Candidate")
2746 (volatile)
2747 (action .
2748 (("Rename File"
2749 . (lambda (candidate)
2750 (anything-dired-action candidate :action 'rename)))
2751 ("Rename and Follow"
2752 . (lambda (candidate)
2753 (anything-dired-action candidate :action 'rename :follow t)))))))
2755 (defvar anything-c-source-symlink-files
2756 `((name . ,(concat "Symlink Files" anything-c-find-files-doc-header))
2757 ;; It is needed for filenames with capital letters
2758 (disable-shortcuts)
2759 (candidates . anything-find-files-get-candidates)
2760 (filtered-candidate-transformer anything-c-find-files-transformer)
2761 (persistent-action . anything-find-files-persistent-action)
2762 (persistent-help . "Expand Candidate")
2763 (volatile)
2764 (action
2765 . (("Symlink File"
2766 . (lambda (candidate)
2767 (anything-dired-action candidate :action 'symlink)))
2768 ("RelSymlink File"
2769 . (lambda (candidate)
2770 (anything-dired-action candidate :action 'relsymlink)))))))
2773 (defvar anything-c-source-hardlink-files
2774 `((name . ,(concat "Hardlink Files" anything-c-find-files-doc-header))
2775 ;; It is needed for filenames with capital letters
2776 (disable-shortcuts)
2777 (candidates . anything-find-files-get-candidates)
2778 (filtered-candidate-transformer anything-c-find-files-transformer)
2779 (persistent-action . anything-find-files-persistent-action)
2780 (persistent-help . "Expand Candidate")
2781 (volatile)
2782 (action
2783 . (("Hardlink File"
2784 . (lambda (candidate)
2785 (anything-dired-action candidate :action 'hardlink)))))))
2788 ;; Emacs bugfix for version < 24.
2789 ;; This fix copying directory recursively from dired and copy-directory
2790 ;; when called interactively and not.
2791 ;; (copy only contents of directory whithout subdir).
2792 (when (< emacs-major-version 24)
2794 (defun copy-directory (directory newname &optional keep-time parents copy-contents-only)
2795 "Copy DIRECTORY to NEWNAME. Both args must be strings.
2796 If NEWNAME names an existing directory, copy DIRECTORY as subdirectory there.
2798 This function always sets the file modes of the output files to match
2799 the corresponding input file.
2801 The third arg KEEP-TIME non-nil means give the output files the same
2802 last-modified time as the old ones. (This works on only some systems.)
2804 A prefix arg makes KEEP-TIME non-nil.
2806 Noninteractively, the last argument PARENTS says whether to
2807 create parent directories if they don't exist. Interactively,
2808 this happens by default."
2809 (interactive
2810 (let ((dir (read-directory-name
2811 "Copy directory: " default-directory default-directory t nil)))
2812 (list dir
2813 (read-file-name
2814 (format "Copy directory %s to: " dir)
2815 default-directory default-directory nil nil)
2816 current-prefix-arg t)))
2817 ;; If default-directory is a remote directory, make sure we find its
2818 ;; copy-directory handler.
2819 (let ((handler (or (find-file-name-handler directory 'copy-directory)
2820 (find-file-name-handler newname 'copy-directory))))
2821 (if handler
2822 (funcall handler 'copy-directory directory newname keep-time parents)
2824 ;; Compute target name.
2825 (setq directory (directory-file-name (expand-file-name directory))
2826 newname (directory-file-name (expand-file-name newname)))
2828 (if (not (file-directory-p newname))
2829 ;; If NEWNAME is not an existing directory, create it; that
2830 ;; is where we will copy the files of DIRECTORY.
2831 (make-directory newname parents)
2832 ;; If NEWNAME is an existing directory, we will copy into
2833 ;; NEWNAME/[DIRECTORY-BASENAME].
2834 (unless copy-contents-only
2835 (setq newname (expand-file-name
2836 (file-name-nondirectory
2837 (directory-file-name directory))
2838 newname))
2839 (and (file-exists-p newname)
2840 (not (file-directory-p newname))
2841 (error "Cannot overwrite non-directory %s with a directory"
2842 newname))
2843 (make-directory newname t)))
2845 ;; Copy recursively.
2846 (dolist (file
2847 ;; We do not want to copy "." and "..".
2848 (directory-files directory 'full
2849 directory-files-no-dot-files-regexp))
2850 (if (file-directory-p file)
2851 (copy-directory file newname keep-time parents)
2852 (let ((target (expand-file-name (file-name-nondirectory file) newname))
2853 (attrs (file-attributes file)))
2854 (if (stringp (car attrs)) ; Symbolic link
2855 (make-symbolic-link (car attrs) target t)
2856 (copy-file file target t keep-time)))))
2858 ;; Set directory attributes.
2859 (set-file-modes newname (file-modes directory))
2860 (when keep-time
2861 (set-file-times newname (nth 5 (file-attributes directory)))))))
2863 (defun dired-copy-file (from to ok-flag)
2864 (when (and (file-directory-p from)
2865 (file-directory-p to))
2866 (setq to (file-name-directory to)))
2867 (dired-handle-overwrite to)
2868 (dired-copy-file-recursive from to ok-flag dired-copy-preserve-time t
2869 dired-recursive-copies)))
2872 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
2873 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
2874 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
2875 (let ((fn (case action
2876 ('copy 'dired-copy-file)
2877 ('rename 'dired-rename-file)
2878 ('symlink 'make-symbolic-link)
2879 ('relsymlink 'dired-make-relative-symlink)
2880 ('hardlink 'dired-hardlink)))
2881 (marker (case action
2882 ((copy rename) dired-keep-marker-copy)
2883 ('symlink dired-keep-marker-symlink)
2884 ('relsymlink dired-keep-marker-relsymlink)
2885 ('hardlink dired-keep-marker-hardlink)))
2886 (dirflag (and (= (length files) 1)
2887 (file-directory-p (car files))
2888 (not (file-directory-p candidate)))))
2889 (dired-create-files
2890 fn (symbol-name action) files
2891 ;; CANDIDATE is the destination.
2892 (if (file-directory-p candidate)
2893 ;; When CANDIDATE is a directory, build file-name in this directory.
2894 ;; Else we use CANDIDATE.
2895 #'(lambda (from)
2896 (expand-file-name (file-name-nondirectory from) candidate))
2897 #'(lambda (from) candidate))
2898 marker)
2899 (when follow
2900 (let ((moved-flist (anything-get-dest-fnames-from-list files candidate dirflag))
2901 (target (directory-file-name candidate)))
2902 (unwind-protect
2903 (progn
2904 (setq anything-ff-cand-to-mark moved-flist)
2905 (if (and dirflag (eq action 'rename))
2906 (anything-find-files1 (file-name-directory target) target)
2907 (anything-find-files1 candidate)))
2908 (setq anything-ff-cand-to-mark nil))))))
2910 ;; Internal
2911 (defvar anything-ff-cand-to-mark nil)
2913 (defun anything-c-basename (fname)
2914 "Resolve basename of file or directory named FNAME."
2915 (file-name-nondirectory (directory-file-name fname)))
2917 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
2918 "Transform filenames of FLIST to abs of DEST-CAND."
2919 ;; At this point files have been renamed/copied at destination.
2920 ;; That's mean DEST-CAND exists.
2921 (loop
2922 with dest = (expand-file-name dest-cand)
2923 for src in flist
2924 for basename-src = (anything-c-basename src)
2925 for fname = (cond (rename-dir-flag (directory-file-name dest))
2926 ((file-directory-p dest)
2927 (concat (file-name-as-directory dest) basename-src))
2928 (t dest))
2929 when (file-exists-p fname)
2930 collect fname into tmp-list
2931 finally return (sort tmp-list 'string<)))
2933 (defun anything-c-maybe-mark-candidates ()
2934 "Mark all candidates of list `anything-ff-cand-to-mark'."
2935 (when (and (string= (assoc-default 'name (anything-get-current-source))
2936 (assoc-default 'name anything-c-source-find-files))
2937 anything-ff-cand-to-mark)
2938 (with-anything-window
2939 (while anything-ff-cand-to-mark
2940 (if (search-forward (car anything-ff-cand-to-mark) (point-at-eol) t)
2941 (progn
2942 (anything-mark-current-line)
2943 (anything-make-visible-mark)
2944 (forward-line 1)
2945 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
2946 (forward-line 1)))
2947 (unless (anything-this-visible-mark)
2948 (anything-prev-visible-mark)))))
2950 (add-hook 'anything-after-update-hook #'anything-c-maybe-mark-candidates)
2952 (defun* anything-dired-do-action-on-file (&key action)
2953 (let* ((files (dired-get-marked-files))
2954 (len (length files))
2955 (fname (if (> len 1)
2956 (format "* %d Files" len)
2957 (car files)))
2958 (source (case action
2959 ('copy 'anything-c-source-copy-files)
2960 ('rename 'anything-c-source-rename-files)
2961 ('symlink 'anything-c-source-symlink-files)
2962 ('hardlink 'anything-c-source-hardlink-files)))
2963 (prompt-fm (case action
2964 ('copy "Copy %s to: ")
2965 ('rename "Rename %s to: ")
2966 ('symlink "Symlink %s to: ")
2967 ('hardlink "Hardlink %s to: ")))
2968 (buffer (case action
2969 ('copy "*Anything Copy Files*")
2970 ('rename "*Anything Rename Files*")
2971 ('symlink "*Anything Symlink Files*")
2972 ('hardlink "*Anything Hardlink Files*"))))
2973 (anything source
2974 (or (dired-dwim-target-directory)
2975 (expand-file-name (anything-c-current-directory)))
2976 (format prompt-fm fname) nil nil buffer)))
2979 ;;;###autoload
2980 (defun anything-dired-rename-file ()
2981 "Preconfigured `anything' to rename files from dired."
2982 (interactive)
2983 (anything-dired-do-action-on-file :action 'rename))
2985 ;;;###autoload
2986 (defun anything-dired-copy-file ()
2987 "Preconfigured `anything' to copy files from dired."
2988 (interactive)
2989 (anything-dired-do-action-on-file :action 'copy))
2991 ;;;###autoload
2992 (defun anything-dired-symlink-file ()
2993 "Preconfigured `anything' to symlink files from dired."
2994 (interactive)
2995 (anything-dired-do-action-on-file :action 'symlink))
2997 ;;;###autoload
2998 (defun anything-dired-hardlink-file ()
2999 "Preconfigured `anything' to hardlink files from dired."
3000 (interactive)
3001 (anything-dired-do-action-on-file :action 'hardlink))
3003 (defvar anything-dired-bindings nil)
3004 ;;;###autoload
3005 (defun anything-dired-bindings (&optional arg)
3006 "Replace usual dired commands `C' and `R' by anything ones.
3007 When call interactively toggle dired bindings and anything bindings.
3008 When call non--interactively with arg > 0, enable anything bindings.
3009 You can put (anything-dired-binding 1) in init file to enable anything bindings."
3010 (interactive)
3011 (if (or (and arg (> arg 0)) (not anything-dired-bindings))
3012 ;; Replace dired bindings.
3013 (progn
3014 (substitute-key-definition
3015 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
3016 (substitute-key-definition
3017 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
3018 (substitute-key-definition
3019 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
3020 (substitute-key-definition
3021 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map)
3022 (setq anything-dired-bindings t))
3023 ;; Replace anything bindings.
3024 (substitute-key-definition
3025 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
3026 (substitute-key-definition
3027 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
3028 (substitute-key-definition
3029 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
3030 (substitute-key-definition
3031 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)
3032 (setq anything-dired-bindings nil)))
3034 (defun* anything-c-read-file-name (prompt
3035 &key
3036 (initial-input (expand-file-name default-directory))
3037 (buffer "*Anything Completions*")
3038 test
3039 (history nil)
3040 (marked-candidates nil)
3041 (persistent-action 'anything-find-files-persistent-action)
3042 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
3043 "Anything `read-file-name' emulation.
3044 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
3045 (when (get-buffer anything-action-buffer)
3046 (kill-buffer anything-action-buffer))
3047 (let ((anything-mp-highlight-delay nil))
3048 (flet ((action-fn (candidate)
3049 (if marked-candidates
3050 (anything-marked-candidates)
3051 (identity candidate))))
3052 (or (anything
3053 :sources
3054 `(((name . ,(concat "Read File Name History" anything-c-find-files-doc-header))
3055 (candidates . (lambda ()
3056 (anything-comp-read-get-candidates history)))
3057 (volatile)
3058 (persistent-action . ,persistent-action)
3059 (persistent-help . ,persistent-help)
3060 (action . ,'action-fn))
3061 ((name . ,(concat "Read file name" anything-c-find-files-doc-header))
3062 ;; It is needed for filenames with capital letters
3063 (disable-shortcuts)
3064 (candidates . (lambda ()
3065 (if test
3066 (loop with seq = (anything-find-files-get-candidates)
3067 for fname in seq when (funcall test fname)
3068 collect fname)
3069 (anything-find-files-get-candidates))))
3070 (filtered-candidate-transformer anything-c-find-files-transformer)
3071 (persistent-action . ,persistent-action)
3072 (persistent-help . ,persistent-help)
3073 (volatile)
3074 (action . ,'action-fn)))
3075 :input initial-input
3076 :prompt prompt
3077 :resume 'noresume
3078 :buffer buffer)
3079 (keyboard-quit)))))
3081 ;;; File Cache
3082 (defvar anything-c-source-file-cache-initialized nil)
3084 (defvar anything-c-file-cache-files nil)
3086 (defvar anything-c-source-file-cache
3087 '((name . "File Cache")
3088 (init
3089 . (lambda ()
3090 (require 'filecache nil t)
3091 (unless anything-c-source-file-cache-initialized
3092 (setq anything-c-file-cache-files
3093 (loop for item in file-cache-alist append
3094 (destructuring-bind (base &rest dirs) item
3095 (loop for dir in dirs collect
3096 (concat dir base)))))
3097 (defadvice file-cache-add-file (after file-cache-list activate)
3098 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
3099 (setq anything-c-source-file-cache-initialized t))))
3100 (candidates . anything-c-file-cache-files)
3101 (match anything-c-match-on-file-name
3102 anything-c-match-on-directory-name)
3103 (type . file)))
3104 ;; (anything 'anything-c-source-file-cache)
3106 ;;; Locate
3107 ;; NOTE for WINDOZE users:
3108 ;; You have to install Everything with his command line interface here:
3109 ;; http://www.voidtools.com/download.php
3111 (defvar anything-c-locate-command
3112 (case system-type
3113 ('gnu/linux "locate -i -r %s")
3114 ('berkeley-unix "locate -i %s")
3115 ('windows-nt "es -i -r %s")
3116 (t "locate %s"))
3117 "A list of arguments for locate program.
3118 The \"-r\" option must be the last option.")
3120 (defun anything-c-locate-init ()
3121 "Initialize async locate process for `anything-c-source-locate'."
3122 (setq mode-line-format
3123 '(" " mode-line-buffer-identification " "
3124 (line-number-mode "%l") " "
3125 (:eval (propertize "(Locate Process Running) "
3126 'face '((:foreground "red"))))))
3127 (prog1
3128 (start-process-shell-command "locate-process" nil
3129 (format anything-c-locate-command
3130 anything-pattern))
3131 (set-process-sentinel (get-process "locate-process")
3132 #'(lambda (process event)
3133 (when (string= event "finished\n")
3134 (kill-local-variable 'mode-line-format)
3135 (with-anything-window
3136 (anything-update-move-first-line)))))))
3138 (defvar anything-c-source-locate
3139 '((name . "Locate")
3140 (candidates . anything-c-locate-init)
3141 (type . file)
3142 (requires-pattern . 3)
3143 (delayed))
3144 "Find files matching the current input pattern with locate.")
3146 ;; (anything 'anything-c-source-locate)
3148 ;;; Grep
3149 ;; NOTE: the -d option with skip avoid error on windows.
3150 ;; It have no effect on GNU/Linux.
3151 (defvar anything-c-grep-default-command "grep -d skip -niH -e %s %s %s"
3152 "Default format command for `anything-do-grep'.")
3154 (defvar anything-c-grep-default-function 'anything-c-grep-init)
3156 (defface anything-grep-match
3157 '((t (:inherit match)))
3158 "Face used to highlight grep matches."
3159 :group 'anything)
3161 (defface anything-grep-file
3162 '((t (:foreground "BlueViolet" :underline t)))
3163 "Face used to highlight grep results filenames."
3164 :group 'anything)
3166 (defface anything-grep-lineno
3167 '((t (:foreground "Darkorange1")))
3168 "Face used to highlight grep number lines."
3169 :group 'anything)
3171 (defun anything-c-grep-prepare-candidates (candidates)
3172 "Prepare filenames and directories CANDIDATES for grep command line."
3173 ;; If one or more candidate is a directory, search in all files
3174 ;; of this candidate (e.g /home/user/directory/*).
3175 ;; If r option is enabled search also in subdidrectories.
3176 ;; We need here to expand wildcards to support crap windows filenames
3177 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
3178 (loop for i in candidates append
3179 (cond ((and (file-directory-p i)
3180 (anything-c-grep-recurse-p))
3181 (list (expand-file-name i)))
3182 ((file-directory-p i)
3183 (file-expand-wildcards (concat (file-name-as-directory
3184 (expand-file-name i))
3185 "*") t))
3186 ((string-match "\*" i) (file-expand-wildcards i t))
3187 (t (list i))) into of
3188 finally return
3189 (mapconcat #'(lambda (x) (shell-quote-argument x)) of " ")))
3191 (defun anything-c-grep-recurse-p ()
3192 "Check if `anything-do-grep1' have switched to recursive."
3193 (let ((args (replace-regexp-in-string
3194 "grep" "" anything-c-grep-default-command)))
3195 (string-match-p "r\\|recurse" args)))
3197 (defun anything-c-grep-init (only-files &optional include)
3198 "Start an asynchronous grep process in ONLY-FILES list."
3199 (let* ((fnargs (anything-c-grep-prepare-candidates
3200 (if (file-remote-p anything-ff-default-directory)
3201 (mapcar #'(lambda (x) (file-remote-p x 'localname)) only-files)
3202 only-files)))
3203 (ignored-files (mapconcat
3204 #'(lambda (x)
3205 (concat "--exclude=" (shell-quote-argument x)))
3206 grep-find-ignored-files " "))
3207 (ignored-dirs (mapconcat ; Need grep version 2.5.4 of Gnuwin32 on windoze.
3208 #'(lambda (x)
3209 (concat "--exclude-dir=" (shell-quote-argument x)))
3210 grep-find-ignored-directories " "))
3211 (exclude (if (anything-c-grep-recurse-p)
3212 (concat (or include ignored-files) " " ignored-dirs)
3213 ignored-files)))
3214 (setq mode-line-format
3215 '(" " mode-line-buffer-identification " "
3216 (line-number-mode "%l") " "
3217 (:eval (propertize "(Grep Process Running) "
3218 'face '((:foreground "red"))))))
3219 (prog1
3220 (let ((default-directory anything-ff-default-directory))
3221 (start-file-process-shell-command
3222 "grep-process" nil
3223 (format anything-c-grep-default-command
3224 (shell-quote-argument anything-pattern)
3225 fnargs
3226 exclude)))
3227 (message nil)
3228 (set-process-sentinel
3229 (get-process "grep-process")
3230 #'(lambda (process event)
3231 (when (string= event "finished\n")
3232 (kill-local-variable 'mode-line-format)
3233 (with-anything-window
3234 (anything-update-move-first-line))))))))
3236 (defun anything-c-grep-action (candidate &optional where mark)
3237 "Define a default action for `anything-do-grep' on CANDIDATE.
3238 WHERE can be one of other-window, elscreen, other-frame."
3239 (let* ((split (anything-c-grep-split-line candidate))
3240 (lineno (string-to-number (nth 1 split)))
3241 (loc-fname (car split))
3242 (tramp-method (file-remote-p anything-ff-default-directory 'method))
3243 (tramp-host (file-remote-p anything-ff-default-directory 'host))
3244 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
3245 (fname (if tramp-host (concat tramp-prefix loc-fname) loc-fname)))
3246 (case where
3247 (other-window (find-file-other-window fname))
3248 (elscreen (anything-elscreen-find-file fname))
3249 (other-frame (find-file-other-frame fname))
3250 (t (find-file fname)))
3251 (anything-goto-line lineno)
3252 (set-marker (mark-marker) (point))
3253 (when mark
3254 (push-mark (point) 'nomsg))))
3257 (defun anything-c-grep-persistent-action (candidate)
3258 "Persistent action for `anything-do-grep'.
3259 With a prefix arg record CANDIDATE in `mark-ring'."
3260 (if current-prefix-arg
3261 (anything-c-grep-action candidate nil 'mark)
3262 (anything-c-grep-action candidate))
3263 (anything-match-line-color-current-line))
3265 (defun anything-do-grep1 (only &optional recurse)
3266 "Launch grep with a list of ONLY files.
3267 When RECURSE is given use -r option of grep and prompt user
3268 to set the --include args of grep.
3269 You can give more than one arg separated by space.
3270 e.g *.el *.py *.tex.
3271 If it's empty --exclude `grep-find-ignored-files' is used instead."
3272 (let* ((anything-compile-source-functions
3273 ;; rule out anything-match-plugin because the input is one regexp.
3274 (delq 'anything-compile-source--match-plugin
3275 (copy-sequence anything-compile-source-functions)))
3276 (include-files (and recurse (read-string "OnlyExt(*.[ext]): ")))
3277 (anything-c-grep-default-command (if recurse "grep -nirH -e %s %s %s"
3278 anything-c-grep-default-command))
3279 ;; Disable match-plugin and use here own highlighting.
3280 (anything-mp-highlight-delay nil))
3281 (when include-files
3282 (setq include-files
3283 (and (not (string= include-files ""))
3284 (mapconcat #'(lambda (x)
3285 (concat "--include=" (shell-quote-argument x)))
3286 (split-string include-files) " "))))
3287 ;; When called as action from an other source e.g *-find-files
3288 ;; we have to kill action buffer.
3289 (when (get-buffer anything-action-buffer)
3290 (kill-buffer anything-action-buffer))
3291 (anything
3292 :sources
3293 `(((name . "Grep (M-up/down - next/prec file)")
3294 (candidates
3295 . (lambda () (if include-files
3296 (funcall anything-c-grep-default-function only include-files)
3297 (funcall anything-c-grep-default-function only))))
3298 (filtered-candidate-transformer anything-c-grep-cand-transformer)
3299 (candidate-number-limit . 9999)
3300 (action . ,(delq
3302 `(("Find File" . anything-c-grep-action)
3303 ("Find file other window"
3304 . (lambda (candidate)
3305 (anything-c-grep-action candidate 'other-window)))
3306 ,(and (locate-library "elscreen")
3307 '("Find file in Elscreen"
3308 . (lambda (candidate)
3309 (anything-c-grep-action candidate 'elscreen))))
3310 ("Find file other frame"
3311 . (lambda (candidate)
3312 (anything-c-grep-action candidate 'other-frame))))))
3313 (persistent-action . (lambda (candidate)
3314 (anything-c-grep-persistent-action candidate)))
3315 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
3316 (requires-pattern . 3)
3317 (delayed)))
3318 :buffer "*anything grep*")))
3320 ;;;###autoload
3321 (defun anything-do-grep ()
3322 "Preconfigured anything for grep.
3323 Contrarily to Emacs `grep' no default directory is given, but
3324 the full path of candidates in ONLY.
3325 That allow to grep different files not only in `default-directory' but anywhere
3326 by marking them (C-<SPACE>). If one or more directory is selected
3327 grep will search in all files of these directories.
3328 You can use also wildcard in the base name of candidate.
3329 If a prefix arg is given use the -r option of grep.
3330 See also `anything-do-grep1'."
3331 (interactive)
3332 (let ((only (anything-c-read-file-name
3333 "Search in file(s): " :marked-candidates t))
3334 (prefarg current-prefix-arg))
3335 (anything-do-grep1 only prefarg)))
3337 (defun anything-c-grep-split-line (line)
3338 "Split a grep output line."
3339 (let (beg fname lineno str)
3340 ;; Don't print until grep line is valid.
3341 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
3342 (with-temp-buffer
3343 (insert line)
3344 (goto-char (point-min))
3345 (setq beg (point))
3346 (forward-char 2)
3347 (re-search-forward ":" nil t)
3348 (setq fname (buffer-substring-no-properties beg (1- (point))))
3349 (setq beg (point))
3350 (re-search-forward ":" nil t)
3351 (setq lineno (buffer-substring-no-properties beg (1- (point))))
3352 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
3353 (list fname lineno str))))
3355 (defun anything-c-grep-cand-transformer (candidates sources)
3356 "Filtered candidate transformer function for `anything-do-grep'."
3357 (loop for i in candidates
3358 for split = (and i (anything-c-grep-split-line i))
3359 for fname = (car split)
3360 for lineno = (nth 1 split)
3361 for str = (nth 2 split)
3362 when (and fname lineno str)
3363 collect
3364 (cons (concat (propertize (file-name-nondirectory fname)
3365 'face 'anything-grep-file
3366 'help-echo fname) ":"
3367 (propertize lineno 'face 'anything-grep-lineno) ":"
3368 (anything-c-grep-highlight-match str))
3369 i)))
3371 (defun anything-c-grep-highlight-match (str)
3372 "Highlight in string STR all occurences matching `anything-pattern'."
3373 (condition-case nil
3374 (with-temp-buffer
3375 (insert str)
3376 (goto-char (point-min))
3377 (while (and (re-search-forward anything-pattern nil t)
3378 (> (- (match-end 0) (match-beginning 0)) 0))
3379 (add-text-properties
3380 (match-beginning 0) (match-end 0)
3381 '(face anything-grep-match)))
3382 (buffer-string))
3383 (error nil)))
3385 ;; Go to next or precedent file (common to etags and grep).
3386 (defun anything-c-goto-next-or-prec-file (n)
3387 "Go to next or precedent candidate file in anything grep/etags buffers.
3388 If N is positive go forward otherwise go backward."
3389 (let ((cur-source (assoc-default 'name (anything-get-current-source))))
3390 (with-anything-window
3391 (if (or (string= cur-source "Grep (M-up/down - next/prec file)")
3392 (string-match "^Etags.*" cur-source))
3393 (let* ((current-line-list (split-string
3394 (buffer-substring
3395 (point-at-bol)
3396 (point-at-eol)) ":"))
3397 (current-fname (nth 0 current-line-list))
3398 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
3399 (catch 'break
3400 (while (not (funcall fn-b-o-f))
3401 (forward-line n) ; Go forward or backward depending of n value.
3402 (unless (search-forward current-fname (point-at-eol) t)
3403 (anything-mark-current-line)
3404 (throw 'break nil))))
3405 (cond ((and (eq n 1) (eobp))
3406 (re-search-backward ".")
3407 (forward-line 0)
3408 (anything-mark-current-line))
3409 ((and (< n 1) (bobp))
3410 (forward-line 1)
3411 (anything-mark-current-line))))
3412 (if (eq n 1)
3413 (anything-next-line)
3414 (anything-previous-line))))))
3416 ;;;###autoload
3417 (defun anything-c-goto-precedent-file ()
3418 "Go to precedent file in anything grep/etags buffers."
3419 (interactive)
3420 (anything-c-goto-next-or-prec-file -1))
3422 ;;;###autoload
3423 (defun anything-c-goto-next-file ()
3424 "Go to precedent file in anything grep/etags buffers."
3425 (interactive)
3426 (anything-c-goto-next-or-prec-file 1))
3428 ;; This keys affect etags and grep only.
3429 ;; in other sources they do nothing, just going next or precedent line.
3430 (define-key anything-map (kbd "M-<down>") #'anything-c-goto-next-file)
3431 (define-key anything-map (kbd "M-<up>") #'anything-c-goto-precedent-file)
3433 ;; Yank text at point.
3434 (defvar anything-yank-point nil)
3435 ;;;###autoload
3436 (defun anything-yank-text-at-point ()
3437 "Yank text at point in minibuffer."
3438 (interactive)
3439 (let (input)
3440 (flet ((insert-in-minibuffer (word)
3441 (with-selected-window (minibuffer-window)
3442 (let ((str anything-pattern))
3443 (delete-minibuffer-contents)
3444 (set-text-properties 0 (length word) nil word)
3445 (insert (concat str word))))))
3446 (with-current-buffer anything-current-buffer
3447 ;; Start to initial point if C-w have never been hit.
3448 (unless anything-yank-point (setq anything-yank-point (point)))
3449 (and anything-yank-point (goto-char anything-yank-point))
3450 (forward-word 1)
3451 (setq input (buffer-substring-no-properties anything-yank-point (point)))
3452 (setq anything-yank-point (point))) ; End of last forward-word
3453 (insert-in-minibuffer input))))
3455 (defun anything-reset-yank-point ()
3456 (setq anything-yank-point nil))
3458 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
3459 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
3460 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
3462 ;;; Etags
3463 (eval-when-compile
3464 (when (locate-library "anything-etags.el")
3465 (display-warning
3466 '(anything-config)
3467 "You are using obsolete library `anything-etags.el' and should remove it."
3468 :warning)))
3470 (defcustom anything-c-etags-tag-file-name "TAGS"
3471 "Etags tag file name."
3472 :type 'string
3473 :group 'anything-config)
3475 (defcustom anything-c-etags-tag-file-search-limit 10
3476 "The limit level of directory to search tag file.
3477 Don't search tag file deeply if outside this value."
3478 :type 'number
3479 :group 'anything-config)
3481 (defvar anything-c-etags-tag-file-dir nil
3482 "Etags file directory.")
3483 (defvar anything-c-etags-mtime-alist nil)
3484 (defvar anything-c-etags-cache (make-hash-table :test 'equal))
3486 (defun anything-c-etags-get-tag-file ()
3487 "Get Etags tag file."
3488 ;; Get tag file from `default-directory' or upper directory.
3489 (let ((current-dir (anything-c-etags-find-tag-file default-directory)))
3490 ;; Return nil if not find tag file.
3491 (when current-dir
3492 (setq anything-c-etags-tag-file-dir current-dir) ;set tag file directory
3493 (expand-file-name anything-c-etags-tag-file-name current-dir))))
3495 (defun anything-c-etags-find-tag-file (current-dir)
3496 "Find tag file.
3497 Try to find tag file in upper directory if haven't found in CURRENT-DIR."
3498 (flet ((file-exists? (dir)
3499 (let ((tag-path (expand-file-name anything-c-etags-tag-file-name dir)))
3500 (and (stringp tag-path)
3501 (file-exists-p tag-path)
3502 (file-readable-p tag-path)))))
3503 (loop with count = 0
3504 until (file-exists? current-dir)
3505 ;; Return nil if outside the value of
3506 ;; `anything-c-etags-tag-file-search-limit'.
3507 if (= count anything-c-etags-tag-file-search-limit)
3508 do (return nil)
3509 ;; Or search upper directories.
3510 else
3511 do (incf count)
3512 (setq current-dir (expand-file-name (concat current-dir "../")))
3513 finally return current-dir)))
3515 (defun anything-c-source-etags-header-name (x)
3516 (concat "Etags in "
3517 (with-current-buffer anything-current-buffer
3518 (anything-c-etags-get-tag-file))))
3520 (defmacro anything-c-etags-create-buffer (file)
3521 `(let* ((tag-fname ,file)
3523 (split (with-current-buffer (find-file-noselect tag-fname)
3524 (prog1
3525 (split-string (buffer-string) "\n" 'omit-nulls)
3526 (setq max (line-number-at-pos (point-max)))
3527 (kill-buffer))))
3528 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
3529 (loop
3530 with fname
3531 with cand
3532 for i in split for count from 0
3533 for elm = (unless (string-match "^\x0c" i)
3534 (anything-aif (string-match "\177" i)
3535 (substring i 0 it)
3537 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
3538 (setq fname (match-string 1 elm)))
3539 (elm (setq cand (concat fname ": " elm)))
3540 (t (setq cand nil)))
3541 when cand do (progn
3542 (insert (concat cand "\n"))
3543 (progress-reporter-update progress-reporter count)))))
3545 (defun anything-c-etags-init ()
3546 (let ((tagfile (anything-c-etags-get-tag-file)))
3547 (when tagfile
3548 (with-current-buffer (anything-candidate-buffer 'global)
3549 (anything-aif (gethash tagfile anything-c-etags-cache)
3550 (insert it)
3551 (anything-c-etags-create-buffer tagfile)
3552 (puthash tagfile (buffer-string) anything-c-etags-cache)
3553 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
3554 ;; If an entry exists modify it.
3555 (setcdr it (anything-c-etags-mtime tagfile))
3556 ;; No entry create a new one.
3557 (add-to-list 'anything-c-etags-mtime-alist
3558 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
3560 (defvar anything-c-source-etags-select
3561 '((name . "Etags")
3562 (header-name . anything-c-source-etags-header-name)
3563 (init . anything-c-etags-init)
3564 (candidates-in-buffer)
3565 (action . anything-c-etags-default-action)
3566 (persistent-action . (lambda (candidate)
3567 (anything-c-etags-default-action candidate)
3568 (anything-match-line-color-current-line)))))
3570 (defun anything-c-etags-default-action (candidate)
3571 (let* ((split (split-string candidate ": "))
3572 (fname (expand-file-name
3573 (car split) anything-c-etags-tag-file-dir))
3574 (elm (cadr split)))
3575 (find-file fname)
3576 (goto-char (point-min))
3577 (search-forward elm nil t)
3578 (goto-char (match-beginning 0))))
3580 (defun anything-c-etags-select (arg)
3581 "Preconfigured anything for etags.
3582 Called with one prefix arg use symbol at point as initial input.
3583 Called with two prefix arg reinitialize cache.
3584 If tag file have been modified reinitialize cache."
3585 (interactive "P")
3586 (let ((tag (anything-c-etags-get-tag-file))
3587 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
3588 (anything-quit-if-no-candidate t)
3589 (anything-execute-action-at-once-if-one t))
3590 (when (or (equal arg '(16))
3591 (and anything-c-etags-mtime-alist
3592 (anything-c-etags-file-modified-p tag)))
3593 (remhash tag anything-c-etags-cache))
3594 (if (and tag (file-exists-p tag))
3595 (anything :sources 'anything-c-source-etags-select
3596 :input init
3597 :buffer "*anything etags*")
3598 (message "Error: No tag file found, please create one with etags shell command."))))
3600 (defun anything-c-etags-mtime (file)
3601 "Last modification time of FILE."
3602 (cadr (nth 5 (file-attributes file))))
3604 (defun anything-c-etags-file-modified-p (file)
3605 "Check if tag FILE have been modified in this session.
3606 If FILE is nil return nil."
3607 (let ((last-modif (and file
3608 (assoc-default file anything-c-etags-mtime-alist))))
3609 (and last-modif
3610 (/= last-modif (anything-c-etags-mtime file)))))
3612 ;;; Recentf files
3613 (defvar anything-c-source-recentf
3614 '((name . "Recentf")
3615 (init . (lambda ()
3616 (require 'recentf)
3617 (or recentf-mode (recentf-mode 1))
3618 ;; Big value empowers anything/recentf
3619 (when (and (numberp recentf-max-saved-items)
3620 (<= recentf-max-saved-items 20))
3621 (setq recentf-max-saved-items 500))))
3622 (candidates . recentf-list)
3623 (match anything-c-match-on-file-name
3624 anything-c-match-on-directory-name)
3625 (type . file))
3626 "See (info \"(emacs)File Conveniences\").
3627 if `recentf-max-saved-items' is too small, set it to 500.")
3628 ;; (anything 'anything-c-source-recentf)
3630 ;;; ffap
3631 (eval-when-compile (require 'ffap))
3632 (defvar anything-c-source-ffap-guesser
3633 '((name . "File at point")
3634 (init . (lambda () (require 'ffap)))
3635 (candidates . (lambda ()
3636 (anything-aif
3637 (with-current-buffer anything-current-buffer
3638 (ffap-guesser))
3639 (list it))))
3640 (type . file)))
3641 ;; (anything 'anything-c-source-ffap-guesser)
3643 ;;; ffap with line number
3644 (defun anything-c-ffap-file-line-at-point ()
3645 "Get (FILENAME . LINENO) at point."
3646 (anything-aif (let (ffap-alist) (ffap-file-at-point))
3647 (save-excursion
3648 (beginning-of-line)
3649 (when (and (search-forward it nil t)
3650 (looking-at ":\\([0-9]+\\)"))
3651 (cons it (string-to-number (match-string 1)))))))
3653 (defvar anything-c-ffap-line-location nil
3654 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
3655 It is cleared after jumping line.")
3657 (defun anything-c-ffap-line-candidates ()
3658 (with-current-buffer anything-current-buffer
3659 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
3660 (when anything-c-ffap-line-location
3661 (destructuring-bind (file . line) anything-c-ffap-line-location
3662 (list (cons (format "%s (line %d)" file line) file)))))
3664 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
3665 (defun anything-c-ffap-line-goto-line ()
3666 (when (car anything-c-ffap-line-location)
3667 (unwind-protect
3668 (ignore-errors
3669 (with-selected-window
3670 (get-buffer-window
3671 (get-file-buffer (car anything-c-ffap-line-location)))
3672 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
3673 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
3674 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
3676 (defvar anything-c-source-ffap-line
3677 '((name . "File/Lineno at point")
3678 (init . (lambda () (require 'ffap)))
3679 (candidates . anything-c-ffap-line-candidates)
3680 (type . file)))
3681 ;; (anything 'anything-c-source-ffap-line)
3683 ;;; list of files gleaned from every dired buffer
3684 (defun anything-c-files-in-all-dired-candidates ()
3685 (save-excursion
3686 (mapcan
3687 (lambda (dir)
3688 (cond ((listp dir) ;filelist
3689 dir)
3690 ((equal "" (file-name-nondirectory dir)) ;dir
3691 (directory-files dir t))
3692 (t ;wildcard
3693 (file-expand-wildcards dir t))))
3694 (delq nil
3695 (mapcar (lambda (buf)
3696 (set-buffer buf)
3697 (when (eq major-mode 'dired-mode)
3698 (if (consp dired-directory)
3699 (cdr dired-directory) ;filelist
3700 dired-directory))) ;dir or wildcard
3701 (buffer-list))))))
3702 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
3704 (defvar anything-c-source-files-in-all-dired
3705 '((name . "Files in all dired buffer.")
3706 (candidates . anything-c-files-in-all-dired-candidates)
3707 (type . file)))
3708 ;; (anything 'anything-c-source-files-in-all-dired)
3710 (defcustom anything-c-filelist-file-name nil
3711 "*Filename of file list.
3712 Accept a list of string for multiple files.
3714 This file tend to be very large (> 100MB) and recommend to be in ramdisk for speed.
3715 File list is created by make-filelist.rb script.
3717 Usage:
3718 ruby make-filelist.rb > /tmp/all.filelist
3720 Then
3721 ;; Assume that /tmp is ramdisk or tmpfs
3722 (setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\")
3723 (setq anything-c-filelist-file-name \"/tmp/all.filelist\")
3725 :type 'string
3726 :group 'anything-config)
3727 (defvar anything-c-source-filelist
3728 '((name . "FileList")
3729 (grep-candidates . anything-c-filelist-file-name)
3730 (candidate-number-limit . 200)
3731 (requires-pattern . 4)
3732 (type . file))
3733 "Source to find files instantly.
3734 See `anything-c-filelist-file-name' docstring for usage.")
3736 ;;;###autoload
3737 (defun anything-filelist ()
3738 "Preconfigured `anything' to open files instantly.
3740 See `anything-c-filelist-file-name' docstring for usage."
3741 (interactive)
3742 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
3744 ;;;###autoload
3745 (defun anything-filelist+ ()
3746 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
3748 This is a replacement for `anything-for-files'.
3749 See `anything-c-filelist-file-name' docstring for usage."
3750 (interactive)
3751 (anything-other-buffer
3752 '(anything-c-source-ffap-line
3753 anything-c-source-ffap-guesser
3754 anything-c-source-buffers+
3755 anything-c-source-recentf
3756 anything-c-source-bookmarks
3757 anything-c-source-file-cache
3758 anything-c-source-filelist)
3759 "*anything file list*"))
3762 ;;;; <info>
3763 ;;; Info pages
3764 (defvar anything-c-info-pages nil
3765 "All info pages on system.
3766 Will be calculated the first time you invoke anything with this
3767 source.")
3769 (defvar anything-c-source-info-pages
3770 `((name . "Info Pages")
3771 (candidates
3772 . (lambda ()
3773 (if anything-c-info-pages
3774 anything-c-info-pages
3775 (setq anything-c-info-pages
3776 (save-window-excursion
3777 (save-excursion
3778 (require 'info)
3779 (Info-find-node "dir" "top")
3780 (goto-char (point-min))
3781 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
3782 topics)
3783 (while (re-search-forward info-topic-regexp nil t)
3784 (add-to-list 'topics (match-string-no-properties 1)))
3785 (goto-char (point-min))
3786 (Info-exit)
3787 topics)))))))
3788 (action . (("Show with Info" .(lambda (node-str)
3789 (info (replace-regexp-in-string
3790 "^[^:]+: " "" node-str))))))
3791 (requires-pattern . 2)))
3792 ;; (anything 'anything-c-source-info-pages)
3795 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
3796 (defun anything-c-describe-attributes (anything-attribute)
3797 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
3798 Same as `anything-describe-anything-attribute' but with anything completion."
3799 (interactive (list (intern
3800 (anything-comp-read
3801 "Describe anything attribute: "
3802 (mapcar 'symbol-name anything-additional-attributes)
3803 :must-match t
3804 :persistent-action
3805 #'(lambda (candidate)
3806 (with-output-to-temp-buffer "*Help*"
3807 (princ (get (intern candidate) 'anything-attrdoc))))))))
3808 (with-output-to-temp-buffer "*Help*"
3809 (princ (get anything-attribute 'anything-attrdoc))))
3811 ;;; Use info-index plug-in. Note that `name' attribute is
3812 ;;; not needed but `anything-c-insert-summary' uses it.
3813 ;; Info Elisp
3814 (defvar anything-c-source-info-elisp
3815 '((name . "Info index: elisp")
3816 (info-index . "elisp")))
3817 ;; (anything 'anything-c-source-info-elisp)
3819 ;; Info-Common-Lisp
3820 (defvar anything-c-source-info-cl
3821 '((name . "Info index: cl")
3822 (info-index . "cl")))
3823 ;; (anything 'anything-c-source-info-cl)
3825 ;; Info Index org
3826 (defvar anything-c-source-info-org
3827 '((name . "Info index: org")
3828 (info-index . "org")))
3829 ;; (anything 'anything-c-source-info-org)
3831 ;; Info Index ratpoison
3832 (defvar anything-c-source-info-ratpoison
3833 '((name . "Info index: ratpoison")
3834 (info-index . "ratpoison")))
3835 ;; (anything 'anything-c-source-info-ratpoison)
3837 ;; Info Index zsh
3838 (defvar anything-c-source-info-zsh
3839 '((name . "Info index: zsh")
3840 (info-index . "zsh")))
3841 ;; (anything 'anything-c-source-info-zsh)
3843 ;; Info Index bash
3844 (defvar anything-c-source-info-bash
3845 '((name . "Info index: bash")
3846 (info-index . "bash")))
3847 ;; (anything 'anything-c-source-info-bash)
3849 ;; Info Index coreutils
3850 (defvar anything-c-source-info-coreutils
3851 '((name . "Info index: coreutils")
3852 (info-index . "coreutils")))
3853 ;; (anything 'anything-c-source-info-coreutils)
3855 ;; Info Index fileutils
3856 (defvar anything-c-source-info-fileutils
3857 '((name . "Info index: fileutils")
3858 (info-index . "fileutils")))
3859 ;; (anything 'anything-c-source-info-fileutils)
3861 ;; Info Index find
3862 (defvar anything-c-source-info-find
3863 '((name . "Info index: find")
3864 (info-index . "find")))
3865 ;; (anything 'anything-c-source-info-find)
3867 ;; Info Index sh-utils
3868 (defvar anything-c-source-info-sh-utils
3869 '((name . "Info index: sh-utils")
3870 (info-index . "sh-utils")))
3871 ;; (anything 'anything-c-source-info-sh-utils)
3873 ;; Info Index textutils
3874 (defvar anything-c-source-info-textutils
3875 '((name . "Info index: textutils")
3876 (info-index . "textutils")))
3877 ;; (anything 'anything-c-source-info-textutils)
3879 ;; Info Index libc
3880 (defvar anything-c-source-info-libc
3881 '((name . "Info index: libc")
3882 (info-index . "libc")))
3883 ;; (anything 'anything-c-source-info-libc)
3885 ;; Info Index make
3886 (defvar anything-c-source-info-make
3887 '((name . "Info index: make")
3888 (info-index . "make")))
3889 ;; (anything 'anything-c-source-info-make)
3891 ;; Info Index automake
3892 (defvar anything-c-source-info-automake
3893 '((name . "Info index: automake")
3894 (info-index . "automake")))
3895 ;; (anything 'anything-c-source-info-automake)
3897 ;; Info Index autoconf
3898 (defvar anything-c-source-info-autoconf
3899 '((name . "Info index: autoconf")
3900 (info-index . "autoconf")))
3901 ;; (anything 'anything-c-source-info-autoconf)
3903 ;; Info Index emacs-lisp-intro
3904 (defvar anything-c-source-info-emacs-lisp-intro
3905 '((name . "Info index: emacs-lisp-intro")
3906 (info-index . "emacs-lisp-intro")))
3907 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
3909 ;; Info Index emacs
3910 (defvar anything-c-source-info-emacs
3911 '((name . "Info index: emacs")
3912 (info-index . "emacs")))
3913 ;; (anything 'anything-c-source-info-emacs)
3915 ;; Info Index elib
3916 (defvar anything-c-source-info-elib
3917 '((name . "Info index: elib")
3918 (info-index . "elib")))
3919 ;; (anything 'anything-c-source-info-elib)
3921 ;; Info Index eieio
3922 (defvar anything-c-source-info-eieio
3923 '((name . "Info index: eieio")
3924 (info-index . "eieio")))
3925 ;; (anything 'anything-c-source-info-eieio)
3927 ;; Info Index gauche-refe
3928 (defvar anything-c-source-info-gauche-refe
3929 '((name . "Info index: gauche")
3930 (info-index . "gauche-refe")))
3931 ;; (anything 'anything-c-source-info-gauche-refe)
3933 ;; Info Index guile
3934 (defvar anything-c-source-info-guile
3935 '((name . "Info index: guile")
3936 (info-index . "guile")))
3937 ;; (anything 'anything-c-source-info-guile)
3939 ;; Info Index guile-tut
3940 (defvar anything-c-source-info-guile-tut
3941 '((name . "Info index: guile-tut")
3942 (info-index . "guile-tut")))
3943 ;; (anything 'anything-c-source-info-guile-tut)
3945 ;; Info Index goops
3946 (defvar anything-c-source-info-goops
3947 '((name . "Info index: goops")
3948 (info-index . "goops")))
3949 ;; (anything 'anything-c-source-info-goops)
3951 ;; Info Index screen
3952 (defvar anything-c-source-info-screen
3953 '((name . "Info index: screen")
3954 (info-index . "screen")
3955 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
3956 ;; (anything 'anything-c-source-info-screen)
3958 ;; Info Index latex
3959 (defvar anything-c-source-info-latex
3960 '((name . "Info index: latex")
3961 (info-index . "latex")))
3962 ;; (anything 'anything-c-source-info-latex)
3964 ;; Info Index gawk
3965 (defvar anything-c-source-info-gawk
3966 '((name . "Info index: gawk")
3967 (info-index . "gawk")))
3968 ;; (anything 'anything-c-source-info-gawk)
3970 ;; Info Index sed
3971 (defvar anything-c-source-info-sed
3972 '((name . "Info index: sed")
3973 (info-index . "sed")))
3974 ;; (anything 'anything-c-source-info-sed)
3976 ;; Info Index m4
3977 (defvar anything-c-source-info-m4
3978 '((name . "Info index: m4")
3979 (info-index . "m4")))
3980 ;; (anything 'anything-c-source-info-m4)
3982 ;; Info Index wget
3983 (defvar anything-c-source-info-wget
3984 '((name . "Info index: wget")
3985 (info-index . "wget")))
3986 ;; (anything 'anything-c-source-info-wget)
3988 ;; Info Index binutils
3989 (defvar anything-c-source-info-binutils
3990 '((name . "Info index: binutils")
3991 (info-index . "binutils")))
3992 ;; (anything 'anything-c-source-info-binutils)
3994 ;; Info Index as
3995 (defvar anything-c-source-info-as
3996 '((name . "Info index: as")
3997 (info-index . "as")))
3998 ;; (anything 'anything-c-source-info-as)
4000 ;; Info Index bfd
4001 (defvar anything-c-source-info-bfd
4002 '((name . "Info index: bfd")
4003 (info-index . "bfd")))
4004 ;; (anything 'anything-c-source-info-bfd)
4006 ;; Info Index gprof
4007 (defvar anything-c-source-info-gprof
4008 '((name . "Info index: gprof")
4009 (info-index . "gprof")))
4010 ;; (anything 'anything-c-source-info-gprof)
4012 ;; Info Index ld
4013 (defvar anything-c-source-info-ld
4014 '((name . "Info index: ld")
4015 (info-index . "ld")))
4016 ;; (anything 'anything-c-source-info-ld)
4018 ;; Info Index diff
4019 (defvar anything-c-source-info-diff
4020 '((name . "Info index: diff")
4021 (info-index . "diff")))
4022 ;; (anything 'anything-c-source-info-diff)
4024 ;; Info Index flex
4025 (defvar anything-c-source-info-flex
4026 '((name . "Info index: flex")
4027 (info-index . "flex")))
4028 ;; (anything 'anything-c-source-info-flex)
4030 ;; Info Index grep
4031 (defvar anything-c-source-info-grep
4032 '((name . "Info index: grep")
4033 (info-index . "grep")))
4034 ;; (anything 'anything-c-source-info-grep)
4036 ;; Info Index gzip
4037 (defvar anything-c-source-info-gzip
4038 '((name . "Info index: gzip")
4039 (info-index . "gzip")))
4040 ;; (anything 'anything-c-source-info-gzip)
4042 ;; Info Index libtool
4043 (defvar anything-c-source-info-libtool
4044 '((name . "Info index: libtool")
4045 (info-index . "libtool")))
4046 ;; (anything 'anything-c-source-info-libtool)
4048 ;; Info Index texinfo
4049 (defvar anything-c-source-info-texinfo
4050 '((name . "Info index: texinfo")
4051 (info-index . "texinfo")))
4052 ;; (anything 'anything-c-source-info-texinfo)
4054 ;; Info Index info
4055 (defvar anything-c-source-info-info
4056 '((name . "Info index: info")
4057 (info-index . "info")))
4058 ;; (anything 'anything-c-source-info-info)
4060 ;; Info Index gdb
4061 (defvar anything-c-source-info-gdb
4062 '((name . "Info index: gdb")
4063 (info-index . "gdb")))
4064 ;; (anything 'anything-c-source-info-gdb)
4066 ;; Info Index stabs
4067 (defvar anything-c-source-info-stabs
4068 '((name . "Info index: stabs")
4069 (info-index . "stabs")))
4070 ;; (anything 'anything-c-source-info-stabs)
4072 ;; Info Index cvsbook
4073 (defvar anything-c-source-info-cvsbook
4074 '((name . "Info index: cvsbook")
4075 (info-index . "cvsbook")))
4076 ;; (anything 'anything-c-source-info-cvsbook)
4078 ;; Info Index cvs
4079 (defvar anything-c-source-info-cvs
4080 '((name . "Info index: cvs")
4081 (info-index . "cvs")))
4082 ;; (anything 'anything-c-source-info-cvs)
4084 ;; Info Index bison
4085 (defvar anything-c-source-info-bison
4086 '((name . "Info index: bison")
4087 (info-index . "bison")))
4088 ;; (anything 'anything-c-source-info-bison)
4090 ;; Info Index id-utils
4091 (defvar anything-c-source-info-id-utils
4092 '((name . "Info index: id-utils")
4093 (info-index . "id-utils")))
4094 ;; (anything 'anything-c-source-info-id-utils)
4096 ;; Info Index global
4097 (defvar anything-c-source-info-global
4098 '((name . "Info index: global")
4099 (info-index . "global")))
4100 ;; (anything 'anything-c-source-info-global)
4102 ;;;; <Help>
4103 ;;; Man Pages
4104 (defvar anything-c-man-pages nil
4105 "All man pages on system.
4106 Will be calculated the first time you invoke anything with this
4107 source.")
4109 (defun anything-c-man-default-action (candidate)
4110 "Default action for jumping to a woman or man page from anything."
4111 (let ((wfiles (woman-file-name-all-completions candidate)))
4112 (condition-case err
4113 (if (> (length wfiles) 1)
4114 (woman-find-file (anything-comp-read "ManFile: " wfiles
4115 :must-match t))
4116 ;; If woman is unable to format correctly
4117 ;; use man instead.
4118 (woman candidate))
4119 (error (kill-buffer) ; Kill woman buffer.
4120 (man candidate)))))
4122 (defvar anything-c-source-man-pages
4123 `((name . "Manual Pages")
4124 (candidates . (lambda ()
4125 (if anything-c-man-pages
4126 anything-c-man-pages
4127 ;; XEmacs doesn't have a woman :)
4128 (setq anything-c-man-pages
4129 (ignore-errors
4130 (require 'woman)
4131 (woman-file-name "")
4132 (sort (mapcar 'car woman-topic-all-completions)
4133 'string-lessp))))))
4134 (action ("Show with Woman" . anything-c-man-default-action))
4135 ;; Woman does not work OS X
4136 ;; http://xahlee.org/emacs/modernization_man_page.html
4137 (action-transformer . (lambda (actions candidate)
4138 (if (eq system-type 'darwin)
4139 '(("Show with Man" . man))
4140 actions)))
4141 (requires-pattern . 2)))
4142 ;; (anything 'anything-c-source-man-pages)
4144 ;;;; <Command>
4145 ;;; Complex command history
4146 (defvar anything-c-source-complex-command-history
4147 '((name . "Complex Command History")
4148 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
4149 (type . sexp)))
4150 ;; (anything 'anything-c-source-complex-command-history)
4152 ;;; M-x history
4153 (defvar anything-c-source-extended-command-history
4154 '((name . "Emacs Commands History")
4155 (candidates . extended-command-history)
4156 (type . command)))
4157 ;; (anything 'anything-c-source-extended-command-history)
4159 ;;; Emacs commands
4160 (defvar anything-c-source-emacs-commands
4161 '((name . "Emacs Commands")
4162 (candidates . (lambda ()
4163 (let (commands)
4164 (mapatoms (lambda (a)
4165 (if (commandp a)
4166 (push (symbol-name a)
4167 commands))))
4168 (sort commands 'string-lessp))))
4169 (type . command)
4170 (requires-pattern . 2))
4171 "Source for completing and invoking Emacs commands.
4172 A command is a function with interactive spec that can
4173 be invoked with `M-x'.
4175 To get non-interactive functions listed, use
4176 `anything-c-source-emacs-functions'.")
4177 ;; (anything 'anything-c-source-emacs-commands)
4179 ;;; Anything M-x
4181 ;; Another replacement of `M-x' that act exactly like the
4182 ;; vanilla Emacs one, no problem of windows configuration, prefix args
4183 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
4184 ;; anything invocation.
4185 ;;;###autoload
4186 (defun anything-M-x ()
4187 "Preconfigured `anything' for Emacs commands.
4188 It is `anything' replacement of regular `M-x' `execute-extended-command'."
4189 (interactive)
4190 (let* (in-help help-cand
4191 (command (anything-comp-read
4192 "M-x " obarray
4193 :test 'commandp
4194 :must-match t
4195 :requires-pattern 2
4196 :name "Emacs Commands"
4197 :persistent-action
4198 #'(lambda (candidate)
4199 (if (and in-help (string= candidate help-cand))
4200 (progn (kill-buffer "*Help*") (setq in-help nil))
4201 (describe-function (intern candidate))
4202 (setq in-help t))
4203 (setq help-cand candidate))
4204 :persistent-help "Describe this command"
4205 :history extended-command-history
4206 :sort 'string-lessp
4207 :fc-transformer 'anything-M-x-transformer))
4208 (history (loop with hist
4209 for i in extended-command-history
4210 for com = (intern i)
4211 when (and (fboundp com) (not (member i hist)))
4212 collect i into hist finally return hist)))
4213 (unless current-prefix-arg (setq current-prefix-arg anything-current-prefix-arg))
4214 (call-interactively (intern command))
4215 (setq extended-command-history (cons command (delete command history)))))
4217 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
4218 "Return alist of MODE-MAP."
4219 (loop for key being the key-seqs of mode-map using (key-bindings com)
4220 for str-key = (key-description key)
4221 for ismenu = (string-match "<menu-bar>" str-key)
4222 unless ismenu collect (cons str-key com)))
4224 (defun anything-get-mode-map-from-mode (mode)
4225 "Guess the mode-map name according to MODE.
4226 Some modes don't use conventional mode-map name
4227 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
4228 Return nil if no mode-map found."
4229 (loop
4230 ;; Start with a conventional mode-map name.
4231 with mode-map = (intern-soft (format "%s-map" mode))
4232 with mode-string = (symbol-name mode)
4233 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
4234 while (not mode-map)
4235 for count downfrom (length mode-name)
4236 ;; Return when no result after parsing entire string.
4237 when (eq count 0) return nil
4238 for sub-name = (substring mode-name 0 count)
4239 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
4240 finally return mode-map))
4242 (defun anything-M-x-current-mode-map-alist ()
4243 "Return mode-map alist of current `major-mode'."
4244 (let ((map (anything-get-mode-map-from-mode major-mode)))
4245 (when (and map (boundp map))
4246 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
4248 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
4249 "*Face used in anything-M-x to show keybinding."
4250 :group 'anything)
4252 (defun anything-M-x-transformer (candidates sources)
4253 "filtered-candidate-transformer to show bindings in emacs commands.
4254 Show global bindings and local bindings according to current `major-mode'."
4255 (loop
4256 with local-map = (with-current-buffer anything-current-buffer
4257 (anything-M-x-current-mode-map-alist))
4258 for i in candidates
4259 for cand = (symbol-name i)
4260 for local-key = (car (rassq i local-map))
4261 for key = (substitute-command-keys (format "\\[%s]" cand))
4262 collect
4263 (cons (if (string-match "^M-x" key)
4264 (if local-key
4265 (concat
4266 cand " (" (propertize local-key 'face 'anything-M-x-key-face)
4267 ")")
4268 cand)
4269 (concat
4270 cand " (" (propertize key 'face 'anything-M-x-key-face) ")"))
4271 cand)))
4273 ;;; LaCarte
4274 (defvar anything-c-source-lacarte
4275 '((name . "Lacarte")
4276 (init . (lambda () (require 'lacarte )))
4277 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
4278 (candidate-number-limit . 9999)
4279 (action . anything-c-call-interactively))
4280 "Needs lacarte.el.
4282 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
4283 ;; (anything 'anything-c-source-lacarte)
4285 ;;;; <Function>
4286 ;;; Emacs functions
4287 (defvar anything-c-source-emacs-functions
4288 '((name . "Emacs Functions")
4289 (candidates . (lambda ()
4290 (let (commands)
4291 (mapatoms (lambda (a)
4292 (if (functionp a)
4293 (push (symbol-name a) commands))))
4294 (sort commands 'string-lessp))))
4295 (type . function)
4296 (requires-pattern . 2))
4297 "Source for completing Emacs functions.")
4298 ;; (anything 'anything-c-source-emacs-functions)
4300 ;;; With abbrev expansion
4301 ;;; Similar to my exec-abbrev-cmd.el
4302 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
4303 (defvar anything-c-function-abbrev-regexp nil
4304 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
4305 Regexp built from the current `anything-pattern' interpreting it
4306 as abbreviation.
4307 Only for internal use.")
4309 (defun anything-c-match-function-by-abbrev (candidate)
4310 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
4312 Abbreviations are made by taking the first character from each
4313 word in the function's name, e.g. \"bb\" is an abbrev for
4314 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
4315 (string-match anything-c-function-abbrev-regexp candidate))
4317 (defvar anything-c-source-emacs-functions-with-abbrevs
4318 (append anything-c-source-emacs-functions
4319 '((match anything-c-match-function-by-abbrev
4320 anything-c-string-match))
4321 '((init
4322 . (lambda ()
4323 (defadvice anything-update
4324 (before anything-c-update-function-abbrev-regexp activate)
4325 (let ((char-list (append anything-pattern nil))
4326 (str "^"))
4327 (dolist (c char-list)
4328 (setq str (concat str (list c) "[^-]*-")))
4329 (setq str (concat (substring str 0 (1- (length str))) "$"))
4330 (setq anything-c-function-abbrev-regexp str))))))))
4331 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
4333 (defvar anything-c-source-advice
4334 '((name . "Function Advice")
4335 (candidates . anything-c-advice-candidates)
4336 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
4337 ;; (real-to-display . anything-c-advice-real-to-display)
4340 (persistent-action . anything-c-advice-persistent-action)
4341 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
4342 ;; (anything 'anything-c-source-advice)
4343 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
4344 ;; (testadvice)
4346 (defun anything-c-advice-candidates ()
4347 (require 'advice)
4348 (loop for (fname) in ad-advised-functions
4349 for function = (intern fname)
4350 append
4351 (loop for class in ad-advice-classes append
4352 (loop for advice in (ad-get-advice-info-field function class)
4353 for enabled = (ad-advice-enabled advice)
4354 collect
4355 (cons (format
4356 "%s %s %s"
4357 (if enabled "Enabled " "Disabled")
4358 (propertize fname 'face 'font-lock-function-name-face)
4359 (ad-make-single-advice-docstring advice class nil))
4360 (list function class advice))))))
4362 (defun anything-c-advice-persistent-action (func-class-advice)
4363 (if current-prefix-arg
4364 (anything-c-advice-toggle func-class-advice)
4365 (describe-function (car func-class-advice))))
4367 (defun anything-c-advice-toggle (func-class-advice)
4368 (destructuring-bind (function class advice) func-class-advice
4369 (cond ((ad-advice-enabled advice)
4370 (ad-advice-set-enabled advice nil)
4371 (message "Disabled"))
4372 (t ;disabled
4373 (ad-advice-set-enabled advice t)
4374 (message "Enabled")))
4375 (ad-activate function)
4376 (and anything-in-persistent-action
4377 (anything-c-advice-update-current-display-string))))
4379 (defun anything-c-advice-update-current-display-string ()
4380 (anything-edit-current-selection
4381 (let ((newword (cond ((looking-at "Disabled") "Enabled")
4382 ((looking-at "Enabled") "Disabled")))
4383 realvalue)
4384 (when newword
4385 (delete-region (point) (progn (forward-word 1) (point)))
4386 (insert newword)))))
4388 ;;;###autoload
4389 (defun anything-manage-advice ()
4390 "Preconfigured `anything' to disable/enable function advices."
4391 (interactive)
4392 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
4394 ;;;; <Variable>
4395 ;;; Emacs variables
4396 (defvar anything-c-source-emacs-variables
4397 '((name . "Emacs Variables")
4398 (candidates . (lambda ()
4399 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
4400 (type . variable)
4401 (requires-pattern . 2))
4402 "Source for completing Emacs variables.")
4403 ;; (anything 'anything-c-source-emacs-variables)
4405 ;;;; <Bookmark>
4406 ;;; Bookmarks
4407 (eval-when-compile (require 'bookmark))
4408 (defvar anything-c-source-bookmarks
4409 '((name . "Bookmarks")
4410 (init . (lambda ()
4411 (require 'bookmark)))
4412 (candidates . bookmark-all-names)
4413 (type . bookmark))
4414 "See (info \"(emacs)Bookmarks\").")
4415 ;; (anything 'anything-c-source-bookmarks)
4417 ;;; bookmark-set
4418 (defvar anything-c-source-bookmark-set
4419 '((name . "Set Bookmark")
4420 (dummy)
4421 (action . bookmark-set))
4422 "See (info \"(emacs)Bookmarks\").")
4423 ;; (anything 'anything-c-source-bookmark-set)
4425 ;;; Visible Bookmarks
4426 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
4429 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
4430 (defvar anything-c-source-bm
4431 '((name . "Visible Bookmarks")
4432 (init . anything-c-bm-init)
4433 (candidates-in-buffer)
4434 (type . line))
4435 "Needs bm.el.
4437 http://www.nongnu.org/bm/")
4439 (defun anything-c-bm-init ()
4440 "Init function for `anything-c-source-bm'."
4441 (when (require 'bm nil t)
4442 (with-no-warnings
4443 (let ((bookmarks (bm-lists))
4444 (buf (anything-candidate-buffer 'global)))
4445 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
4446 '< :key 'overlay-start))
4447 (let ((start (overlay-start bm))
4448 (end (overlay-end bm))
4449 (annotation (or (overlay-get bm 'annotation) "")))
4450 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
4451 (let ((str (format "%5d: [%s]: %s\n"
4452 (line-number-at-pos start)
4453 annotation
4454 (buffer-substring start (1- end)))))
4455 (with-current-buffer buf (insert str))))))))))
4457 ;;; Special bookmarks
4458 (defvar anything-c-source-bookmarks-ssh
4459 '((name . "Bookmarks-ssh")
4460 (init . (lambda ()
4461 (require 'bookmark)))
4462 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
4463 (type . bookmark))
4464 "See (info \"(emacs)Bookmarks\").")
4465 ;; (anything 'anything-c-source-bookmarks-ssh)
4467 (defvar anything-c-source-bookmarks-su
4468 '((name . "Bookmarks-root")
4469 (init . (lambda ()
4470 (require 'bookmark)))
4471 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
4472 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
4474 (type . bookmark))
4475 "See (info \"(emacs)Bookmarks\").")
4476 ;; (anything 'anything-c-source-bookmarks-su)
4478 (defvar anything-c-source-bookmarks-local
4479 '((name . "Bookmarks-Local")
4480 (init . (lambda ()
4481 (require 'bookmark)))
4482 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
4483 (filtered-candidate-transformer
4484 anything-c-adaptive-sort
4485 anything-c-highlight-bookmark)
4486 (type . bookmark))
4487 "See (info \"(emacs)Bookmarks\").")
4488 ;; (anything 'anything-c-source-bookmarks-local)
4490 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
4491 (let* ((lis-all (bookmark-all-names))
4492 (lis-loc (cond (local (loop for i in lis-all
4493 unless (string-match "^(ssh)\\|^(su)" i)
4494 collect i))
4495 (su (loop for i in lis-all
4496 when (string-match "^(su)" i)
4497 collect i))
4498 (sudo (loop for i in lis-all
4499 when (string-match "^(sudo)" i)
4500 collect i))
4501 (ssh (loop for i in lis-all
4502 when (string-match "^(ssh)" i)
4503 collect i)))))
4504 (sort lis-loc 'string-lessp)))
4506 (defun anything-c-bookmark-root-logged-p ()
4507 (catch 'break
4508 (dolist (i (mapcar #'buffer-name (buffer-list)))
4509 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
4510 (throw 'break t)))))
4512 (defun anything-c-highlight-bookmark-su (files source)
4513 (if (anything-c-bookmark-root-logged-p)
4514 (anything-c-highlight-bookmark files source)
4515 (anything-c-highlight-not-logged files source)))
4517 (defun anything-c-highlight-not-logged (files source)
4518 (loop for i in files
4519 collect (propertize i 'face anything-c-bookmarks-face3)))
4521 (defun anything-c-highlight-bookmark (bookmarks source)
4522 "Used as `candidate-transformer' to colorize bookmarks.
4523 Work both with standard Emacs bookmarks and bookmark-extensions.el."
4524 (loop for i in bookmarks
4525 for isfile = (bookmark-get-filename i)
4526 for bufp = (and (fboundp 'bmkext-get-buffer-name)
4527 (bmkext-get-buffer-name i))
4528 for handlerp = (and (fboundp 'bookmark-get-handler)
4529 (bookmark-get-handler i))
4530 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
4531 (bmkext-w3m-bookmark-p i))
4532 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
4533 (bmkext-gnus-bookmark-p i))
4534 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
4535 (bmkext-man-bookmark-p i))
4536 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
4537 (bmkext-woman-bookmark-p i))
4538 for handlerp = (bookmark-get-handler i)
4539 for isannotation = (bookmark-get-annotation i)
4540 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
4541 for isinfo = (eq handlerp 'Info-bookmark-jump)
4542 ;; Add a * if bookmark have annotation
4543 if (and isannotation (not (string-equal isannotation "")))
4544 do (setq i (concat "*" i))
4545 collect (cond (;; info buffers
4546 isinfo
4547 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
4548 (;; w3m buffers
4549 isw3m
4550 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
4551 (;; gnus buffers
4552 isgnus
4553 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
4554 (;; Man Woman
4555 (or iswoman isman)
4556 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
4557 (;; Addressbook
4558 isabook
4559 (propertize i 'face '((:foreground "Tomato"))))
4560 (;; directories
4561 (and isfile (file-directory-p isfile))
4562 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
4563 (;; regular files
4565 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
4568 ;;; Faces for bookmarks
4569 (defface anything-bmkext-info
4570 '((t (:foreground "green")))
4571 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
4572 :group 'anything)
4574 (defface anything-bmkext-w3m
4575 '((t (:foreground "yellow")))
4576 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
4577 :group 'anything)
4579 (defface anything-bmkext-gnus
4580 '((t (:foreground "magenta")))
4581 "*Face used for Gnus bookmarks."
4582 :group 'anything)
4584 (defface anything-bmkext-man
4585 '((t (:foreground "Orange4")))
4586 "*Face used for Woman/man bookmarks."
4587 :group 'anything)
4589 (defface anything-bmkext-no--file
4590 '((t (:foreground "grey")))
4591 "*Face used for non--file bookmarks."
4592 :group 'anything)
4594 (defface anything-bmkext-file
4595 '((t (:foreground "Deepskyblue2")))
4596 "*Face used for non--file bookmarks."
4597 :group 'anything)
4599 (defface anything-bookmarks-su-face '((t (:foreground "red")))
4600 "Face for su/sudo bookmarks."
4601 :group 'anything)
4603 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
4604 (defvar anything-c-bookmarks-face2 'anything-file-name)
4605 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
4608 ;;; Sources to filter bookmark-extensions bookmarks.
4609 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
4610 ;; If you want to enable google-maps in addressbook you will need
4611 ;; Julien Danjou google-maps-el package available here:
4612 ;; http://julien.danjou.info/google-maps-el.html
4614 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
4615 "Return a filtered `bookmark-alist' sorted alphabetically."
4616 (loop
4617 with alist = (if args
4618 (apply #'(lambda (x) (funcall fn x)) args)
4619 (funcall fn))
4620 for i in alist
4621 for b = (car i)
4622 collect b into sa
4623 finally return (sort sa 'string-lessp)))
4625 ;; Addressbook
4626 (defvar anything-c-source-bmkext-addressbook
4627 '((name . "Bookmark Addressbook")
4628 (init . (lambda ()
4629 (require 'bookmark-extensions)
4630 (bookmark-maybe-load-default-file)))
4631 (candidates . anything-c-bmkext-addressbook-setup-alist)
4632 (persistent-action
4633 . (lambda (candidate)
4634 (let ((bmk (anything-bookmark-get-bookmark-from-name
4635 candidate)))
4636 (bookmark--jump-via bmk 'pop-to-buffer))))
4637 (persistent-help . "Show contact - Prefix with C-u to append")
4638 (filtered-candidate-transformer
4639 anything-c-adaptive-sort
4640 anything-c-highlight-bookmark)
4641 (action . (("Show person's data"
4642 . (lambda (candidate)
4643 (let ((bmk (anything-bookmark-get-bookmark-from-name
4644 candidate))
4645 (current-prefix-arg anything-current-prefix-arg))
4646 (bookmark-jump bmk))))
4647 ("Send Mail"
4648 . (lambda (candidate)
4649 (let ((bmk (anything-bookmark-get-bookmark-from-name
4650 candidate)))
4651 (if anything-current-prefix-arg
4652 (addressbook-set-mail-buffer1 bmk 'append)
4653 (addressbook-set-mail-buffer1 bmk)))))
4654 ("Edit Bookmark"
4655 . (lambda (candidate)
4656 (let ((bmk (anything-bookmark-get-bookmark-from-name
4657 candidate)))
4658 (addressbook-bookmark-edit
4659 (assoc bmk bookmark-alist)))))
4660 ("Insert Email at point"
4661 . (lambda (candidate)
4662 (let* ((bmk (anything-bookmark-get-bookmark-from-name
4663 candidate))
4664 (mlist (split-string
4665 (assoc-default
4666 'email (assoc bmk bookmark-alist))
4667 ", ")))
4668 (insert
4669 (if (> (length mlist) 1)
4670 (anything-comp-read
4671 "Insert Mail Address: " mlist :must-match t)
4672 (car mlist))))))
4673 ("Show annotation"
4674 . (lambda (candidate)
4675 (let ((bmk (anything-bookmark-get-bookmark-from-name
4676 candidate)))
4677 (bookmark-show-annotation bmk))))
4678 ("Edit annotation"
4679 . (lambda (candidate)
4680 (let ((bmk (anything-bookmark-get-bookmark-from-name
4681 candidate)))
4682 (bookmark-edit-annotation bmk))))
4683 ("Show Google map"
4684 . (lambda (candidate)
4685 (let* ((bmk (anything-bookmark-get-bookmark-from-name
4686 candidate))
4687 (full-bmk (assoc bmk bookmark-alist)))
4688 (addressbook-google-map full-bmk))))))))
4691 (defun anything-c-bmkext-addressbook-setup-alist ()
4692 "Specialized filter function for bookmarks w3m."
4693 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
4695 ;; W3m
4696 (defvar anything-c-source-bookmark-w3m
4697 '((name . "Bookmark W3m")
4698 (init . (lambda ()
4699 (require 'bookmark-extensions)
4700 (bookmark-maybe-load-default-file)))
4701 (candidates . anything-c-bookmark-w3m-setup-alist)
4702 (filtered-candidate-transformer
4703 anything-c-adaptive-sort
4704 anything-c-highlight-bookmark)
4705 (type . bookmark)))
4706 ;; (anything 'anything-c-source-bookmark-w3m)
4708 (defun anything-c-bookmark-w3m-setup-alist ()
4709 "Specialized filter function for bookmarks w3m."
4710 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
4712 ;; Images
4713 (defvar anything-c-source-bookmark-images
4714 '((name . "Bookmark Images")
4715 (init . (lambda ()
4716 (require 'bookmark-extensions)
4717 (bookmark-maybe-load-default-file)))
4718 (candidates . anything-c-bookmark-images-setup-alist)
4719 (filtered-candidate-transformer
4720 anything-c-adaptive-sort
4721 anything-c-highlight-bookmark)
4722 (type . bookmark)))
4723 ;; (anything 'anything-c-source-bookmark-images)
4725 (defun anything-c-bookmark-images-setup-alist ()
4726 "Specialized filter function for images bookmarks."
4727 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
4729 ;; Woman Man
4730 (defvar anything-c-source-bookmark-man
4731 '((name . "Bookmark Woman&Man")
4732 (init . (lambda ()
4733 (require 'bookmark-extensions)
4734 (bookmark-maybe-load-default-file)))
4735 (candidates . anything-c-bookmark-man-setup-alist)
4736 (filtered-candidate-transformer
4737 anything-c-adaptive-sort
4738 anything-c-highlight-bookmark)
4739 (type . bookmark)))
4740 ;; (anything 'anything-c-source-bookmark-man)
4742 (defun anything-c-bookmark-man-setup-alist ()
4743 "Specialized filter function for bookmarks w3m."
4744 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
4745 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
4747 ;; Gnus
4748 (defvar anything-c-source-bookmark-gnus
4749 '((name . "Bookmark Gnus")
4750 (init . (lambda ()
4751 (require 'bookmark-extensions)
4752 (bookmark-maybe-load-default-file)))
4753 (candidates . anything-c-bookmark-gnus-setup-alist)
4754 (filtered-candidate-transformer
4755 anything-c-adaptive-sort
4756 anything-c-highlight-bookmark)
4757 (type . bookmark)))
4758 ;; (anything 'anything-c-source-bookmark-gnus)
4760 (defun anything-c-bookmark-gnus-setup-alist ()
4761 "Specialized filter function for bookmarks gnus."
4762 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
4764 ;; Info
4765 (defvar anything-c-source-bookmark-info
4766 '((name . "Bookmark Info")
4767 (init . (lambda ()
4768 (require 'bookmark-extensions)
4769 (bookmark-maybe-load-default-file)))
4770 (candidates . anything-c-bookmark-info-setup-alist)
4771 (filtered-candidate-transformer
4772 anything-c-adaptive-sort
4773 anything-c-highlight-bookmark)
4774 (type . bookmark)))
4775 ;; (anything 'anything-c-source-bookmark-info)
4777 (defun anything-c-bookmark-info-setup-alist ()
4778 "Specialized filter function for bookmarks info."
4779 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
4781 ;; Local Files&directories
4782 (defvar anything-c-source-bookmark-files&dirs
4783 '((name . "Bookmark Files&Directories")
4784 (init . (lambda ()
4785 (require 'bookmark-extensions)
4786 (bookmark-maybe-load-default-file)))
4787 (candidates . anything-c-bookmark-local-files-setup-alist)
4788 (filtered-candidate-transformer
4789 anything-c-adaptive-sort
4790 anything-c-highlight-bookmark)
4791 (type . bookmark)))
4792 ;; (anything 'anything-c-source-bookmark-files&dirs)
4794 (defun anything-c-bookmark-local-files-setup-alist ()
4795 "Specialized filter function for bookmarks locals files."
4796 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
4798 ;; Su Files&directories
4799 (defvar anything-c-source-bookmark-su-files&dirs
4800 '((name . "Bookmark Root-Files&Directories")
4801 (init . (lambda ()
4802 (require 'bookmark-extensions)
4803 (bookmark-maybe-load-default-file)))
4804 (candidates . anything-c-bookmark-su-files-setup-alist)
4805 (filtered-candidate-transformer
4806 anything-c-adaptive-sort
4807 anything-c-highlight-bookmark-su)
4808 (type . bookmark)))
4809 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
4811 (defun anything-c-bookmark-su-files-setup-alist ()
4812 "Specialized filter function for bookmarks su/sudo files."
4813 (loop
4814 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
4815 for i in l
4816 for isfile = (bookmark-get-filename i)
4817 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
4818 (save-match-data
4819 (string-match tramp-file-name-regexp isfile)))
4820 for issu = (and istramp
4821 (string-match bmkext-su-or-sudo-regexp isfile))
4822 if issu
4823 collect i))
4825 ;; Ssh Files&directories
4826 (defvar anything-c-source-bookmark-ssh-files&dirs
4827 '((name . "Bookmark Ssh-Files&Directories")
4828 (init . (lambda ()
4829 (require 'bookmark-extensions)
4830 (bookmark-maybe-load-default-file)))
4831 (candidates . anything-c-bookmark-ssh-files-setup-alist)
4832 (filtered-candidate-transformer . anything-c-adaptive-sort)
4833 (type . bookmark)))
4834 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
4836 (defun anything-c-bookmark-ssh-files-setup-alist ()
4837 "Specialized filter function for bookmarks ssh files."
4838 (loop
4839 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
4840 for i in l
4841 for isfile = (bookmark-get-filename i)
4842 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
4843 (save-match-data
4844 (string-match tramp-file-name-regexp isfile)))
4845 for isssh = (and istramp
4846 (string-match "/ssh:" isfile))
4847 if isssh
4848 collect i))
4851 ;; All bookmark-extensions sources.
4852 ;;;###autoload
4853 (defun anything-bookmark-ext ()
4854 "Preconfigured `anything' for bookmark-extensions sources.
4855 Needs bookmark-ext.el
4857 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
4858 (interactive)
4859 (anything
4860 :sources
4861 '(anything-c-source-bookmark-files&dirs
4862 anything-c-source-bookmark-w3m
4863 anything-c-source-bmkext-addressbook
4864 anything-c-source-bookmark-gnus
4865 anything-c-source-bookmark-info
4866 anything-c-source-bookmark-man
4867 anything-c-source-bookmark-images
4868 anything-c-source-bookmark-su-files&dirs
4869 anything-c-source-bookmark-ssh-files&dirs)
4870 :prompt "SearchBookmark: "
4871 :buffer "*anything bmkext*"))
4874 ;; Firefox bookmarks
4875 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
4876 ;; (only for firefox versions >=3)
4877 ;; To achieve that, open about:config in firefox and double click on this line to enable value
4878 ;; to true:
4879 ;; user_pref("browser.bookmarks.autoExportHTML", false);
4880 ;; You should have now:
4881 ;; user_pref("browser.bookmarks.autoExportHTML", true);
4883 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
4884 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
4886 (defun anything-get-firefox-user-init-dir ()
4887 "Guess the default Firefox user directory name."
4888 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
4889 (moz-user-dir
4890 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
4891 (goto-char (point-min))
4892 (prog1
4893 (when (search-forward "Path=" nil t)
4894 (buffer-substring-no-properties (point) (point-at-eol)))
4895 (kill-buffer)))))
4896 (file-name-as-directory (concat moz-dir moz-user-dir))))
4898 (defun anything-guess-firefox-bookmark-file ()
4899 "Return the path of the Firefox bookmarks file."
4900 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
4902 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
4903 "Parse html bookmark FILE and return an alist with (title . url) as elements."
4904 (let (bookmarks-alist url title)
4905 (with-temp-buffer
4906 (insert-file-contents file)
4907 (goto-char (point-min))
4908 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
4909 (forward-line 0)
4910 (when (re-search-forward url-regexp nil t)
4911 (setq url (match-string 0)))
4912 (when (re-search-forward bmk-regexp nil t)
4913 (setq title (match-string 1)))
4914 (push (cons title url) bookmarks-alist)
4915 (forward-line)))
4916 (nreverse bookmarks-alist)))
4918 (defvar anything-c-firefox-bookmarks-alist nil)
4919 (defvar anything-c-source-firefox-bookmarks
4920 '((name . "Firefox Bookmarks")
4921 (init . (lambda ()
4922 (setq anything-c-firefox-bookmarks-alist
4923 (anything-html-bookmarks-to-alist
4924 (anything-guess-firefox-bookmark-file)
4925 anything-firefox-bookmark-url-regexp
4926 anything-firefox-bookmarks-regexp))))
4927 (candidates . (lambda ()
4928 (mapcar #'car anything-c-firefox-bookmarks-alist)))
4929 (filtered-candidate-transformer
4930 anything-c-adaptive-sort
4931 anything-c-highlight-firefox-bookmarks)
4932 (action . (("Browse Url Firefox"
4933 . (lambda (candidate)
4934 (browse-url-firefox
4935 (anything-c-firefox-bookmarks-get-value candidate))))
4936 ("Browse Url w3m"
4937 . (lambda (candidate)
4938 (w3m-browse-url
4939 (anything-c-firefox-bookmarks-get-value candidate))))
4940 ("Copy Url"
4941 . (lambda (elm)
4942 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
4944 ;; (anything 'anything-c-source-firefox-bookmarks)
4946 (defun anything-c-firefox-bookmarks-get-value (elm)
4947 (assoc-default elm anything-c-firefox-bookmarks-alist))
4949 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
4950 (loop for i in bookmarks
4951 collect (propertize
4952 i 'face '((:foreground "YellowGreen"))
4953 'help-echo (anything-c-firefox-bookmarks-get-value i))))
4955 ;; W3m bookmark
4956 ;; Bugfix:
4957 ;; Some users have the emacs-w3m library in load-path
4958 ;; without having the w3m executable :-;
4959 ;; So check if w3m program is present before trying to load
4960 ;; emacs-w3m.
4961 (eval-when-compile
4962 (when (executable-find "w3m")
4963 (require 'w3m-bookmark nil t)))
4964 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
4967 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
4968 "Face for w3m bookmarks" :group 'anything)
4970 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
4971 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
4972 (defvar anything-c-w3m-bookmarks-alist nil)
4973 (defvar anything-c-source-w3m-bookmarks
4974 '((name . "W3m Bookmarks")
4975 (init . (lambda ()
4976 (setq anything-c-w3m-bookmarks-alist
4977 (anything-html-bookmarks-to-alist
4978 w3m-bookmark-file
4979 anything-w3m-bookmark-url-regexp
4980 anything-w3m-bookmarks-regexp))))
4981 (candidates . (lambda ()
4982 (mapcar #'car anything-c-w3m-bookmarks-alist)))
4983 (filtered-candidate-transformer
4984 anything-c-adaptive-sort
4985 anything-c-highlight-w3m-bookmarks)
4986 (action . (("Browse Url"
4987 . (lambda (candidate)
4988 (anything-c-w3m-browse-bookmark candidate)))
4989 ("Copy Url"
4990 . (lambda (elm)
4991 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
4992 ("Browse Url Firefox"
4993 . (lambda (candidate)
4994 (anything-c-w3m-browse-bookmark candidate t)))
4995 ("Delete Bookmark"
4996 . (lambda (candidate)
4997 (anything-c-w3m-delete-bookmark candidate)))
4998 ("Rename Bookmark"
4999 . (lambda (candidate)
5000 (anything-c-w3m-rename-bookmark candidate)))))
5001 (persistent-action . (lambda (candidate)
5002 (if current-prefix-arg
5003 (anything-c-w3m-browse-bookmark candidate t)
5004 (anything-c-w3m-browse-bookmark candidate nil t))))
5005 (persistent-help . "Open URL with emacs-w3m in new tab / \
5006 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
5007 "Needs w3m and emacs-w3m.
5009 http://w3m.sourceforge.net/
5010 http://emacs-w3m.namazu.org/")
5012 ;; (anything 'anything-c-source-w3m-bookmarks)
5014 (defun anything-c-w3m-bookmarks-get-value (elm)
5015 (replace-regexp-in-string
5016 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
5018 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
5019 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
5020 (arg (and (eq fn 'w3m-browse-url) new-tab)))
5021 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
5023 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
5024 (loop for i in bookmarks
5025 collect (propertize
5026 i 'face 'anything-w3m-bookmarks-face
5027 'help-echo (anything-c-w3m-bookmarks-get-value i))))
5030 (defun anything-c-w3m-delete-bookmark (elm)
5031 (save-excursion
5032 (find-file-literally w3m-bookmark-file)
5033 (goto-char (point-min))
5034 (when (re-search-forward elm nil t)
5035 (beginning-of-line)
5036 (delete-region (point)
5037 (line-end-position))
5038 (delete-blank-lines))
5039 (save-buffer (current-buffer))
5040 (kill-buffer (current-buffer))))
5042 (defun anything-c-w3m-rename-bookmark (elm)
5043 (let* ((old-title (replace-regexp-in-string ">" "" elm))
5044 (new-title (read-string "NewTitle: " old-title)))
5045 (save-excursion
5046 (find-file-literally w3m-bookmark-file)
5047 (goto-char (point-min))
5048 (when (re-search-forward (concat elm "<") nil t)
5049 (goto-char (1- (point)))
5050 (delete-char (- (length old-title)))
5051 (insert new-title))
5052 (save-buffer (current-buffer))
5053 (kill-buffer (current-buffer)))))
5055 ;;;; <Library>
5056 ;;; Elisp library scan
5057 (defvar anything-c-source-elisp-library-scan
5058 '((name . "Elisp libraries (Scan)")
5059 (init . (anything-c-elisp-library-scan-init))
5060 (candidates-in-buffer)
5061 (action ("Find library"
5062 . (lambda (candidate) (find-file (find-library-name candidate))))
5063 ("Find library other window"
5064 . (lambda (candidate)
5065 (find-file-other-window (find-library-name candidate))))
5066 ("Load library"
5067 . (lambda (candidate) (load-library candidate))))))
5068 ;; (anything 'anything-c-source-elisp-library-scan)
5070 (defun anything-c-elisp-library-scan-init ()
5071 "Init anything buffer status."
5072 (let ((anything-buffer (anything-candidate-buffer 'global))
5073 (library-list (anything-c-elisp-library-scan-list)))
5074 (with-current-buffer anything-buffer
5075 (dolist (library library-list)
5076 (insert (format "%s\n" library))))))
5078 (defun anything-c-elisp-library-scan-list (&optional dirs string)
5079 "Do completion for file names passed to `locate-file'.
5080 DIRS is directory to search path.
5081 STRING is string to match."
5082 ;; Use `load-path' as path when ignore `dirs'.
5083 (or dirs (setq dirs load-path))
5084 ;; Init with blank when ignore `string'.
5085 (or string (setq string ""))
5086 ;; Get library list.
5087 (let ((string-dir (file-name-directory string))
5088 ;; File regexp that suffix match `load-file-rep-suffixes'.
5089 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
5090 name
5091 names)
5092 (dolist (dir dirs)
5093 (unless dir
5094 (setq dir default-directory))
5095 (if string-dir
5096 (setq dir (expand-file-name string-dir dir)))
5097 (when (file-directory-p dir)
5098 (dolist (file (file-name-all-completions
5099 (file-name-nondirectory string) dir))
5100 ;; Suffixes match `load-file-rep-suffixes'.
5101 (setq name (if string-dir (concat string-dir file) file))
5102 (if (string-match match-regexp name)
5103 (add-to-list 'names name)))))
5104 names))
5106 ;;;; <Programming>
5107 ;;; Imenu
5108 (defvar anything-c-imenu-delimiter " / ")
5110 (defvar anything-c-imenu-index-filter nil)
5111 (make-variable-buffer-local 'anything-c-imenu-index-filter)
5113 (defvar anything-c-cached-imenu-alist nil)
5114 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
5116 (defvar anything-c-cached-imenu-candidates nil)
5117 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
5119 (defvar anything-c-cached-imenu-tick nil)
5120 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
5122 (eval-when-compile (require 'imenu))
5123 (setq imenu-auto-rescan t)
5125 (defun anything-imenu-create-candidates (entry)
5126 "Create candidates with ENTRY."
5127 (if (listp (cdr entry))
5128 (mapcan
5129 (lambda (sub)
5130 (if (consp (cdr sub))
5131 (mapcar
5132 (lambda (subentry)
5133 (concat (car entry) anything-c-imenu-delimiter subentry))
5134 (anything-imenu-create-candidates sub))
5135 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
5136 (cdr entry))
5137 (list entry)))
5139 (defvar anything-c-source-imenu
5140 '((name . "Imenu")
5141 (init . (lambda () (require 'imenu)))
5142 (candidates . anything-c-imenu-candidates)
5143 (persistent-action . (lambda (elm)
5144 (anything-c-imenu-default-action elm)
5145 (unless (fboundp 'semantic-imenu-tag-overlay)
5146 (anything-match-line-color-current-line))))
5147 (persistent-help . "Show this entry")
5148 (action . anything-c-imenu-default-action))
5149 "See (info \"(emacs)Imenu\")")
5151 ;; (anything 'anything-c-source-imenu)
5153 (defun anything-c-imenu-candidates ()
5154 (with-current-buffer anything-current-buffer
5155 (let ((tick (buffer-modified-tick)))
5156 (if (eq anything-c-cached-imenu-tick tick)
5157 anything-c-cached-imenu-candidates
5158 (setq imenu--index-alist nil)
5159 (setq anything-c-cached-imenu-tick tick
5160 anything-c-cached-imenu-candidates
5161 (ignore-errors
5162 (mapcan
5163 'anything-imenu-create-candidates
5164 (setq anything-c-cached-imenu-alist
5165 (let ((index (imenu--make-index-alist)))
5166 (if anything-c-imenu-index-filter
5167 (funcall anything-c-imenu-index-filter index)
5168 index))))))
5169 (setq anything-c-cached-imenu-candidates
5170 (mapcar #'(lambda (x)
5171 (if (stringp x)
5173 (car x)))
5174 anything-c-cached-imenu-candidates))))))
5176 (setq imenu-default-goto-function 'imenu-default-goto-function)
5177 (defun anything-c-imenu-default-action (elm)
5178 "The default action for `anything-c-source-imenu'."
5179 (let ((path (split-string elm anything-c-imenu-delimiter))
5180 (alist anything-c-cached-imenu-alist))
5181 (dolist (elm path)
5182 (setq alist (assoc elm alist)))
5183 (imenu alist)))
5185 ;;; Ctags
5186 (defvar anything-c-ctags-modes
5187 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
5188 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
5189 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
5191 (defun anything-c-source-ctags-init ()
5192 (when (and buffer-file-name
5193 (memq major-mode anything-c-ctags-modes)
5194 (anything-current-buffer-is-modified))
5195 (with-current-buffer (anything-candidate-buffer 'local)
5196 (call-process-shell-command
5197 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
5198 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
5199 anything-buffer-file-name)
5200 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
5201 nil (current-buffer))
5202 (goto-char (point-min))
5203 (forward-line 2)
5204 (delete-region (point-min) (point))
5205 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
5206 for lineno-start = (point)
5207 for lineno = (buffer-substring
5208 lineno-start
5209 (1- (search-forward "," (point-at-eol) t)))
5211 (beginning-of-line)
5212 (insert (format "%5s:" lineno))
5213 (search-forward "\177" (point-at-eol) t)
5214 (delete-region (1- (point)) (point-at-eol))
5215 (forward-line 1)))))
5217 (defvar anything-c-source-ctags
5218 '((name . "Exuberant ctags")
5219 (init . anything-c-source-ctags-init)
5220 (candidates-in-buffer)
5221 (adjust)
5222 (type . line))
5223 "Needs Exuberant Ctags.
5225 http://ctags.sourceforge.net/")
5226 ;; (anything 'anything-c-source-ctags)
5228 ;; Semantic
5229 (eval-when-compile (require 'semantic nil t))
5230 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
5231 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
5232 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
5233 (declare-function semantic-tag-type "ext:tag-file.el" (tag) t)
5234 (declare-function semantic-tag-class "ext:tag-file.el" (tag) t)
5235 (defvar anything-semantic-candidates nil)
5237 (defun anything-semantic-construct-candidates (tags depth)
5238 (when (require 'semantic nil t)
5239 (apply
5240 'append
5241 (mapcar
5242 (lambda (tag)
5243 (if (listp tag)
5244 (let ((type (semantic-tag-type tag))
5245 (class (semantic-tag-class tag)))
5246 (if (or (and (stringp type)
5247 (or (string= type "class")
5248 (string= type "namespace")))
5249 (eq class 'function)
5250 (eq class 'variable))
5251 (cons (cons (concat (make-string (* depth 2) ?\s)
5252 (semantic-format-tag-summarize tag nil t))
5253 tag)
5254 (anything-semantic-construct-candidates
5255 (semantic-tag-components tag) (1+ depth)))))))
5256 tags))))
5258 (defun anything-semantic-default-action (candidate)
5259 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
5260 (semantic-go-to-tag tag)))
5262 (defvar anything-c-source-semantic
5263 '((name . "Semantic Tags")
5264 (init . (lambda ()
5265 (setq anything-semantic-candidates
5266 (ignore-errors (anything-semantic-construct-candidates
5267 (semantic-fetch-tags) 0)))))
5268 (candidates . (lambda ()
5269 (if anything-semantic-candidates
5270 (mapcar 'car anything-semantic-candidates))))
5271 (persistent-action . (lambda (elm)
5272 (anything-semantic-default-action elm)
5273 (anything-match-line-color-current-line)))
5274 (persistent-help . "Show this entry")
5275 (action . anything-semantic-default-action)
5276 "Needs semantic in CEDET.
5278 http://cedet.sourceforge.net/semantic.shtml
5279 http://cedet.sourceforge.net/"))
5281 ;; (anything 'anything-c-source-semantic)
5283 ;;; Function is called by
5284 ;;;###autoload
5285 (defun anything-simple-call-tree ()
5286 "Preconfigured `anything' for simple-call-tree. List function relationships.
5288 Needs simple-call-tree.el.
5289 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
5290 (interactive)
5291 (anything-other-buffer
5292 '(anything-c-source-simple-call-tree-functions-callers
5293 anything-c-source-simple-call-tree-callers-functions)
5294 "*anything simple-call-tree*"))
5296 (defvar anything-c-source-simple-call-tree-functions-callers
5297 '((name . "Function is called by")
5298 (init . anything-c-simple-call-tree-functions-callers-init)
5299 (multiline)
5300 (candidates . anything-c-simple-call-tree-candidates)
5301 (persistent-action . anything-c-simple-call-tree-persistent-action)
5302 (persistent-help . "Show function definitions by rotation")
5303 (action ("Find definition selected by persistent-action" .
5304 anything-c-simple-call-tree-find-definition)))
5305 "Needs simple-call-tree.el.
5306 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
5308 (defvar anything-c-simple-call-tree-tick nil)
5309 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
5310 (defun anything-c-simple-call-tree-analyze-maybe ()
5311 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
5312 (simple-call-tree-analyze)
5313 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
5315 (defun anything-c-simple-call-tree-init-base (function message)
5316 (require 'simple-call-tree)
5317 (with-no-warnings
5318 (when (anything-current-buffer-is-modified)
5319 (anything-c-simple-call-tree-analyze-maybe)
5320 (let ((list (funcall function simple-call-tree-alist)))
5321 (with-current-buffer (anything-candidate-buffer 'local)
5322 (dolist (entry list)
5323 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
5324 (insert (car entry) message
5325 (if (string= funcs " ")
5326 " no functions."
5327 funcs)
5328 "\n\n"))))))))
5330 (defun anything-c-simple-call-tree-functions-callers-init ()
5331 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
5332 " is called by\n"))
5334 (defun anything-c-simple-call-tree-candidates ()
5335 (with-current-buffer (anything-candidate-buffer)
5336 (split-string (buffer-string) "\n\n")))
5338 (defvar anything-c-simple-call-tree-related-functions nil)
5339 (defvar anything-c-simple-call-tree-function-index 0)
5340 (defun anything-c-simple-call-tree-persistent-action (candidate)
5341 (unless (eq last-command 'anything-execute-persistent-action)
5342 (setq anything-c-simple-call-tree-related-functions
5343 (delete "no functions."
5344 (split-string
5345 (replace-regexp-in-string " \\| is called by\\| calls "
5346 "" candidate)
5347 "\n")))
5348 (setq anything-c-simple-call-tree-function-index -1))
5349 (incf anything-c-simple-call-tree-function-index)
5350 (anything-c-simple-call-tree-find-definition candidate))
5352 (defun anything-c-simple-call-tree-find-definition (candidate)
5353 (find-function
5354 (intern
5355 (nth (mod anything-c-simple-call-tree-function-index
5356 (length anything-c-simple-call-tree-related-functions))
5357 anything-c-simple-call-tree-related-functions))))
5359 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
5361 ;;; Function calls
5362 (defvar anything-c-source-simple-call-tree-callers-functions
5363 '((name . "Function calls")
5364 (init . anything-c-simple-call-tree-callers-functions-init)
5365 (multiline)
5366 (candidates . anything-c-simple-call-tree-candidates)
5367 (persistent-action . anything-c-simple-call-tree-persistent-action)
5368 (persistent-help . "Show function definitions by rotation")
5369 (action ("Find definition selected by persistent-action" .
5370 anything-c-simple-call-tree-find-definition)))
5371 "Needs simple-call-tree.el.
5372 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
5374 (defun anything-c-simple-call-tree-callers-functions-init ()
5375 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
5377 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
5379 ;;; Commands/Options with doc
5380 (defvar anything-c-auto-document-data nil)
5381 (make-variable-buffer-local 'anything-c-auto-document-data)
5382 (defvar anything-c-source-commands-and-options-in-file
5383 '((name . "Commands/Options in file")
5384 (header-name
5385 . (lambda (x) (format "Commands/Options in %s"
5386 (buffer-local-value 'buffer-file-name
5387 anything-current-buffer))))
5388 (candidates . anything-command-and-options-candidates)
5389 (multiline)
5390 (action . imenu))
5391 "List Commands and Options with doc. It needs auto-document.el .
5393 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
5395 (eval-when-compile (require 'auto-document nil t))
5396 (defun anything-command-and-options-candidates ()
5397 (with-current-buffer anything-current-buffer
5398 (when (and (require 'auto-document nil t)
5399 (eq major-mode 'emacs-lisp-mode)
5400 (or (anything-current-buffer-is-modified)
5401 (not anything-c-auto-document-data)))
5402 (or imenu--index-alist (imenu--make-index-alist t))
5403 (setq anything-c-auto-document-data
5404 (destructuring-bind (commands options)
5405 (adoc-construct anything-current-buffer)
5406 (append
5407 (loop for (command . doc) in commands
5408 for cmdname = (symbol-name command)
5409 collect
5410 (cons
5411 (format "Command: %s\n %s"
5412 (propertize cmdname 'face font-lock-function-name-face)
5413 (adoc-first-line doc))
5414 (assoc cmdname imenu--index-alist)))
5415 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
5416 for (option doc default) in options
5417 for optname = (symbol-name option)
5418 collect
5419 (cons
5420 (format "Option: %s\n %s\n default = %s"
5421 (propertize optname 'face font-lock-variable-name-face)
5422 (adoc-first-line doc)
5423 (adoc-prin1-to-string default))
5424 (assoc optname
5425 var-alist)))))))
5426 anything-c-auto-document-data))
5428 ;; (anything 'anything-c-source-commands-and-options-in-file)
5430 ;;;; <Color and Face>
5431 ;;; Customize Face
5432 (defvar anything-c-source-customize-face
5433 '((name . "Customize Face")
5434 (init . (lambda ()
5435 (unless (anything-candidate-buffer)
5436 (save-window-excursion (list-faces-display))
5437 (anything-candidate-buffer (get-buffer "*Faces*")))))
5438 (candidates-in-buffer)
5439 (get-line . buffer-substring)
5440 (action . (lambda (line)
5441 (customize-face (intern (car (split-string line))))))
5442 (requires-pattern . 3))
5443 "See (info \"(emacs)Faces\")")
5444 ;; (anything 'anything-c-source-customize-face)
5446 ;; Color
5447 (defvar anything-c-source-colors
5448 '((name . "Colors")
5449 (init . (lambda () (unless (anything-candidate-buffer)
5450 (save-window-excursion (list-colors-display))
5451 (anything-candidate-buffer (get-buffer "*Colors*")))))
5452 (candidates-in-buffer)
5453 (get-line . buffer-substring)
5454 (action
5455 ("Copy Name" . (lambda (candidate)
5456 (kill-new (anything-c-colors-get-name candidate))))
5457 ("Copy RGB" . (lambda (candidate)
5458 (kill-new (anything-c-colors-get-rgb candidate))))
5459 ("Insert Name" . (lambda (candidate)
5460 (with-current-buffer anything-current-buffer
5461 (insert (anything-c-colors-get-name candidate)))))
5462 ("Insert RGB" . (lambda (candidate)
5463 (with-current-buffer anything-current-buffer
5464 (insert (anything-c-colors-get-rgb candidate))))))))
5465 ;; (anything 'anything-c-source-colors)
5467 (defun anything-c-colors-get-name (candidate)
5468 "Get color name."
5469 (replace-regexp-in-string
5470 " " ""
5471 (with-temp-buffer
5472 (insert (capitalize candidate))
5473 (goto-char (point-min))
5474 (search-forward-regexp "\\s-\\{2,\\}")
5475 (delete-region (point) (point-max))
5476 (buffer-string))))
5478 (defun anything-c-colors-get-rgb (candidate)
5479 "Get color RGB."
5480 (replace-regexp-in-string
5481 " " ""
5482 (with-temp-buffer
5483 (insert (capitalize candidate))
5484 (goto-char (point-max))
5485 (search-backward-regexp "\\s-\\{2,\\}")
5486 (delete-region (point) (point-min))
5487 (buffer-string))))
5489 ;;;; <Search Engine>
5490 ;;; Tracker desktop search
5491 (defvar anything-c-source-tracker-search
5492 '((name . "Tracker Search")
5493 (candidates . (lambda ()
5494 (start-process "tracker-search-process" nil
5495 "tracker-search"
5496 anything-pattern)))
5497 (type . file)
5498 (requires-pattern . 3)
5499 (delayed))
5500 "Source for retrieving files matching the current input pattern
5501 with the tracker desktop search.")
5502 ;; (anything 'anything-c-source-tracker-search)
5504 ;;; Spotlight (MacOS X desktop search)
5505 (defvar anything-c-source-mac-spotlight
5506 '((name . "mdfind")
5507 (candidates
5508 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
5509 (type . file)
5510 (requires-pattern . 3)
5511 (delayed))
5512 "Source for retrieving files via Spotlight's command line
5513 utility mdfind.")
5514 ;; (anything 'anything-c-source-mac-spotlight)
5517 ;;;; <Kill ring>
5518 ;;; Kill ring
5519 (defvar anything-c-source-kill-ring
5520 '((name . "Kill Ring")
5521 (init . (lambda () (anything-attrset 'last-command last-command)))
5522 (candidates . anything-c-kill-ring-candidates)
5523 (action . anything-c-kill-ring-action)
5524 (last-command)
5525 (migemo)
5526 (multiline))
5527 "Source for browse and insert contents of kill-ring.")
5529 (defun anything-c-kill-ring-candidates ()
5530 (loop for kill in kill-ring
5531 unless (or (< (length kill) anything-kill-ring-threshold)
5532 (string-match "^[\\s\\t]+$" kill))
5533 collect kill))
5535 (defun anything-c-kill-ring-action (str)
5536 "Insert STR in `kill-ring' and set STR to the head.
5537 If this action is executed just after `yank',
5538 replace with STR as yanked string."
5539 (setq kill-ring (delete str kill-ring))
5540 (if (not (eq (anything-attr 'last-command) 'yank))
5541 (insert-for-yank str)
5542 ;; from `yank-pop'
5543 (let ((inhibit-read-only t)
5544 (before (< (point) (mark t))))
5545 (if before
5546 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
5547 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
5548 (setq yank-undo-function nil)
5549 (set-marker (mark-marker) (point) (current-buffer))
5550 (insert-for-yank str)
5551 ;; Set the window start back where it was in the yank command,
5552 ;; if possible.
5553 (set-window-start (selected-window) yank-window-start t)
5554 (if before
5555 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
5556 ;; It is cleaner to avoid activation, even though the command
5557 ;; loop would deactivate the mark because we inserted text.
5558 (goto-char (prog1 (mark t)
5559 (set-marker (mark-marker) (point) (current-buffer)))))))
5560 (kill-new str))
5562 ;; (anything 'anything-c-source-kill-ring)
5564 ;;;; <Mark ring>
5565 ;; DO NOT include these sources in `anything-sources' use
5566 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
5567 ;; `anything-all-mark-rings' instead.
5569 (defun anything-c-source-mark-ring-candidates ()
5570 (flet ((get-marks (pos)
5571 (save-excursion
5572 (goto-char pos)
5573 (beginning-of-line)
5574 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
5575 (when (string= "" line)
5576 (setq line "<EMPTY LINE>"))
5577 (format "%7d: %s" (line-number-at-pos) line)))))
5578 (with-current-buffer anything-current-buffer
5579 (loop
5580 with marks = (cons (mark-marker) mark-ring)
5581 with recip = nil
5582 for i in marks
5583 for m = (get-marks i)
5584 unless (member m recip)
5585 collect m into recip
5586 finally return recip))))
5588 (defvar anything-mark-ring-cache nil)
5589 (defvar anything-c-source-mark-ring
5590 '((name . "mark-ring")
5591 (init . (lambda ()
5592 (setq anything-mark-ring-cache
5593 (ignore-errors (anything-c-source-mark-ring-candidates)))))
5594 (candidates . (lambda ()
5595 (anything-aif anything-mark-ring-cache
5596 it)))
5597 (action . (("Goto line"
5598 . (lambda (candidate)
5599 (anything-goto-line (string-to-number candidate))))))
5600 (persistent-action . (lambda (candidate)
5601 (anything-goto-line (string-to-number candidate))
5602 (anything-match-line-color-current-line)))
5603 (persistent-help . "Show this line")))
5605 ;; (anything 'anything-c-source-mark-ring)
5607 ;;;###autoload
5608 (defun anything-mark-ring ()
5609 "Preconfigured `anything' for `anything-c-source-mark-ring'."
5610 (interactive)
5611 (anything 'anything-c-source-mark-ring))
5613 ;;; Global-mark-ring
5614 (defvar anything-c-source-global-mark-ring
5615 '((name . "global-mark-ring")
5616 (candidates . anything-c-source-global-mark-ring-candidates)
5617 (action . (("Goto line"
5618 . (lambda (candidate)
5619 (let ((items (split-string candidate ":")))
5620 (switch-to-buffer (second items))
5621 (anything-goto-line (string-to-number (car items))))))))
5622 (persistent-action . (lambda (candidate)
5623 (let ((items (split-string candidate ":")))
5624 (switch-to-buffer (second items))
5625 (anything-goto-line (string-to-number (car items)))
5626 (anything-match-line-color-current-line))))
5627 (persistent-help . "Show this line")))
5629 (defun anything-c-source-global-mark-ring-candidates ()
5630 (flet ((buf-fn (m)
5631 (with-current-buffer (marker-buffer m)
5632 (goto-char m)
5633 (beginning-of-line)
5634 (let (line)
5635 (if (string= "" line)
5636 (setq line "<EMPTY LINE>")
5637 (setq line (car (split-string (thing-at-point 'line)
5638 "[\n\r]"))))
5639 (format "%7d:%s: %s"
5640 (line-number-at-pos) (marker-buffer m) line)))))
5641 (loop
5642 with marks = global-mark-ring
5643 with recip = nil
5644 for i in marks
5645 for gm = (unless (or (string-match
5646 "^ " (format "%s" (marker-buffer i)))
5647 (null (marker-buffer i)))
5648 (buf-fn i))
5649 when (and gm (not (member gm recip)))
5650 collect gm into recip
5651 finally return recip)))
5653 ;; (anything 'anything-c-source-global-mark-ring)
5655 ;;;###autoload
5656 (defun anything-global-mark-ring ()
5657 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
5658 (interactive)
5659 (anything 'anything-c-source-global-mark-ring))
5661 ;;;###autoload
5662 (defun anything-all-mark-rings ()
5663 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
5664 `anything-c-source-mark-ring'."
5665 (interactive)
5666 (anything '(anything-c-source-mark-ring
5667 anything-c-source-global-mark-ring)))
5669 ;;;; <Register>
5670 ;;; Insert from register
5671 (defvar anything-c-source-register
5672 '((name . "Registers")
5673 (candidates . anything-c-register-candidates)
5674 (action-transformer . anything-c-register-action-transformer)
5675 (multiline)
5676 (action))
5677 "See (info \"(emacs)Registers\")")
5679 (defun anything-c-register-candidates ()
5680 "Collecting register contents and appropriate commands."
5681 (loop for (char . val) in register-alist
5682 for key = (single-key-description char)
5683 for string-actions =
5684 (cond
5685 ((numberp val)
5686 (list (int-to-string val)
5687 'insert-register
5688 'increment-register))
5689 ((markerp val)
5690 (let ((buf (marker-buffer val)))
5691 (if (null buf)
5692 (list "a marker in no buffer")
5693 (list (concat
5694 "a buffer position:"
5695 (buffer-name buf)
5696 ", position "
5697 (int-to-string (marker-position val)))
5698 'jump-to-register
5699 'insert-register))))
5700 ((and (consp val) (window-configuration-p (car val)))
5701 (list "window configuration."
5702 'jump-to-register))
5703 ((and (consp val) (frame-configuration-p (car val)))
5704 (list "frame configuration."
5705 'jump-to-register))
5706 ((and (consp val) (eq (car val) 'file))
5707 (list (concat "file:"
5708 (prin1-to-string (cdr val))
5709 ".")
5710 'jump-to-register))
5711 ((and (consp val) (eq (car val) 'file-query))
5712 (list (concat "file:a file-query reference: file "
5713 (car (cdr val))
5714 ", position "
5715 (int-to-string (car (cdr (cdr val))))
5716 ".")
5717 'jump-to-register))
5718 ((consp val)
5719 (let ((lines (format "%4d" (length val))))
5720 (list (format "%s: %s\n" lines
5721 (truncate-string-to-width
5722 (mapconcat 'identity (list (car val))
5723 ;; (mapconcat (lambda (y) y) val
5724 "^J") (- (window-width) 15)))
5725 'insert-register)))
5726 ((stringp val)
5727 (list ;; without properties
5728 (substring-no-properties val)
5729 'insert-register
5730 'append-to-register
5731 'prepend-to-register))
5733 "GARBAGE!"))
5734 collect (cons (format "register %3s: %s" key (car string-actions))
5735 (cons char (cdr string-actions)))))
5737 (defun anything-c-register-action-transformer (actions register-and-functions)
5738 "Decide actions by the contents of register."
5739 (loop with func-actions =
5740 '((insert-register
5741 "Insert Register" .
5742 (lambda (c) (insert-register (car c))))
5743 (jump-to-register
5744 "Jump to Register" .
5745 (lambda (c) (jump-to-register (car c))))
5746 (append-to-register
5747 "Append Region to Register" .
5748 (lambda (c) (append-to-register
5749 (car c) (region-beginning) (region-end))))
5750 (prepend-to-register
5751 "Prepend Region to Register" .
5752 (lambda (c) (prepend-to-register
5753 (car c) (region-beginning) (region-end))))
5754 (increment-register
5755 "Increment Prefix Arg to Register" .
5756 (lambda (c) (increment-register
5757 anything-current-prefix-arg (car c)))))
5758 for func in (cdr register-and-functions)
5759 for cell = (assq func func-actions)
5760 when cell
5761 collect (cdr cell)))
5763 ;; (anything 'anything-c-source-register)
5765 ;;; Latex completion
5766 (defun anything-c-latex-math-candidates ()
5767 "Collect candidates for latex math completion."
5768 (loop for i in (cddr LaTeX-math-menu)
5769 for elm = (loop for s in i when (vectorp s)
5770 collect (cons (aref s 0) (aref s 1)))
5771 append elm))
5773 (defvar anything-c-source-latex-math
5774 '((name . "Latex Math Menu")
5775 (init . (lambda ()
5776 (with-current-buffer anything-current-buffer
5777 (LaTeX-math-mode 1))))
5778 (candidate-number-limit . 9999)
5779 (candidates . anything-c-latex-math-candidates)
5780 (action . (lambda (candidate)
5781 (call-interactively candidate)))))
5783 ;;;; <Headline Extraction>
5784 (defvar anything-c-source-fixme
5785 '((name . "TODO/FIXME/DRY comments")
5786 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
5787 (adjust)
5788 (recenter))
5789 "Show TODO/FIXME/DRY comments in current file.")
5790 ;; (anything 'anything-c-source-fixme)
5792 (defvar anything-c-source-rd-headline
5793 '((name . "RD HeadLine")
5794 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
5795 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
5796 (migemo)
5797 (subexp . 1))
5798 "Show RD headlines.
5800 RD is Ruby's POD.
5801 http://en.wikipedia.org/wiki/Ruby_Document_format")
5802 ;; (anything 'anything-c-source-rd-headline)
5804 (defvar anything-c-source-oddmuse-headline
5805 '((name . "Oddmuse HeadLine")
5806 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
5807 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
5808 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
5809 (migemo)
5810 (subexp . 1))
5811 "Show Oddmuse headlines, such as EmacsWiki.")
5812 ;; (anything 'anything-c-source-oddmuse-headline)
5814 (defvar anything-c-source-emacs-source-defun
5815 '((name . "Emacs Source DEFUN")
5816 (headline . "DEFUN\\|DEFVAR")
5817 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
5818 (or buffer-file-name ""))))
5819 "Show DEFUN/DEFVAR in Emacs C source file.")
5820 ;; (anything 'anything-c-source-emacs-source-defun)
5822 (defvar anything-c-source-emacs-lisp-expectations
5823 '((name . "Emacs Lisp Expectations")
5824 (headline . "(desc[ ]\\|(expectations")
5825 (condition . (eq major-mode 'emacs-lisp-mode)))
5826 "Show descriptions (desc) in Emacs Lisp Expectations.
5828 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
5829 ;; (anything 'anything-c-source-emacs-lisp-expectations)
5831 (defvar anything-c-source-emacs-lisp-toplevels
5832 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
5833 (headline . "^(\\|(@\\*\\|^;;;;")
5834 (get-line . buffer-substring)
5835 (condition . (eq major-mode 'emacs-lisp-mode))
5836 (adjust))
5837 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
5838 linkd.el is optional because linkd stars are extracted by regexp.
5839 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
5840 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
5842 (defvar anything-c-source-org-headline
5843 '((name . "Org HeadLine")
5844 (headline
5845 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5846 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5847 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5848 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5849 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5850 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5851 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5852 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
5853 (condition . (eq major-mode 'org-mode))
5854 (migemo)
5855 (subexp . 1)
5856 (persistent-action . (lambda (elm)
5857 (anything-c-action-line-goto elm)
5858 (org-cycle)))
5859 (action-transformer
5860 . (lambda (actions candidate)
5861 '(("Go to Line" . anything-c-action-line-goto)
5862 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
5863 "Show Org headlines.
5864 org-mode is very very much extended text-mode/outline-mode.
5866 See (find-library \"org.el\")
5867 See http://orgmode.org for the latest version.")
5869 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
5870 (insert
5871 (save-excursion
5872 (anything-goto-line (car lineno-and-content))
5873 (and (looking-at org-complex-heading-regexp)
5874 (org-make-link-string (concat "*" (match-string 4)))))))
5876 ;; (anything 'anything-c-source-org-headline)
5878 ;;; Anything yaoddmuse
5879 ;; Be sure to have yaoddmuse.el installed
5880 ;; install-elisp may be required if you want to install elisp file from here.
5881 (defvar anything-yaoddmuse-use-cache-file nil)
5882 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
5883 (defvar anything-c-yaoddmuse-ew-cache nil)
5884 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
5885 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
5886 (candidates . (lambda ()
5887 (if anything-yaoddmuse-use-cache-file
5888 (ignore-errors
5889 (unless anything-c-yaoddmuse-ew-cache
5890 (load anything-c-yaoddmuse-cache-file)
5891 (setq anything-c-yaoddmuse-ew-cache
5892 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
5893 anything-c-yaoddmuse-ew-cache)
5894 (yaoddmuse-update-pagename t)
5895 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
5896 (action . (("Edit page" . (lambda (candidate)
5897 (yaoddmuse-edit "EmacsWiki" candidate)))
5898 ("Browse page" . (lambda (candidate)
5899 (yaoddmuse-browse-page "EmacsWiki" candidate)))
5900 ("Browse page other window" . (lambda (candidate)
5901 (if (one-window-p)
5902 (split-window-vertically))
5903 (yaoddmuse-browse-page "EmacsWiki" candidate)))
5904 ("Browse diff" . (lambda (candidate)
5905 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
5906 ("Copy URL" . (lambda (candidate)
5907 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
5908 (message "Have copy page %s's URL to yank." candidate)))
5909 ("Create page" . (lambda (candidate)
5910 (yaoddmuse-edit "EmacsWiki" anything-input)))
5911 ("Update cache" . (lambda (candidate)
5912 (if anything-yaoddmuse-use-cache-file
5913 (progn
5914 (anything-yaoddmuse-cache-pages t)
5915 (setq anything-c-yaoddmuse-ew-cache
5916 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
5917 (yaoddmuse-update-pagename))))))
5918 (action-transformer anything-c-yaoddmuse-action-transformer))
5919 "Needs yaoddmuse.el.
5921 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5923 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
5925 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
5926 '((name . "Yaoddmuse Post library (EmacsWiki)")
5927 (init . (anything-yaoddmuse-init))
5928 (candidates-in-buffer)
5929 (action . (("Post library and Browse" . (lambda (candidate)
5930 (yaoddmuse-post-file (find-library-name candidate)
5931 "EmacsWiki"
5932 (file-name-nondirectory (find-library-name candidate))
5933 nil t)))
5934 ("Post library" . (lambda (candidate)
5935 (yaoddmuse-post-file (find-library-name candidate)
5936 "EmacsWiki"
5937 (file-name-nondirectory (find-library-name candidate))))))))
5938 "Needs yaoddmuse.el.
5940 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5942 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
5944 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
5945 "Allow the use of `install-elisp' only on elisp files."
5946 (if (string-match "\.el$" candidate)
5947 (append actions '(("Install Elisp" . (lambda (elm)
5948 (install-elisp-from-emacswiki elm)))))
5949 actions))
5951 ;;;###autoload
5952 (defun anything-yaoddmuse-cache-pages (&optional load)
5953 "Fetch the list of files on emacswiki and create cache file.
5954 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
5955 (interactive)
5956 (yaoddmuse-update-pagename)
5957 (save-excursion
5958 (find-file anything-c-yaoddmuse-cache-file)
5959 (erase-buffer)
5960 (insert "(puthash \"EmacsWiki\" '(")
5961 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
5963 (insert (concat "(\"" (car i) "\") ")))
5964 (insert ") yaoddmuse-pages-hash)\n")
5965 (save-buffer)
5966 (kill-buffer (current-buffer))
5967 (when (or current-prefix-arg
5968 load)
5969 (load anything-c-yaoddmuse-cache-file))))
5971 ;;;###autoload
5972 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
5973 "Preconfigured `anything' to edit or view EmacsWiki page.
5975 Needs yaoddmuse.el.
5977 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5978 (interactive)
5979 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
5981 ;;;###autoload
5982 (defun anything-yaoddmuse-emacswiki-post-library ()
5983 "Preconfigured `anything' to post library to EmacsWiki.
5985 Needs yaoddmuse.el.
5987 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5988 (interactive)
5989 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
5991 (defun anything-yaoddmuse-init ()
5992 "Init anything buffer status."
5993 (let ((anything-buffer (anything-candidate-buffer 'global))
5994 (library-list (yaoddmuse-get-library-list)))
5995 (with-current-buffer anything-buffer
5996 ;; Insert library name.
5997 (dolist (library library-list)
5998 (insert (format "%s\n" library)))
5999 ;; Sort lines.
6000 (sort-lines nil (point-min) (point-max)))))
6002 ;;; Eev anchors
6003 (defvar anything-c-source-eev-anchor
6004 '((name . "Anchors")
6005 (candidates
6006 . (lambda ()
6007 (ignore-errors
6008 (with-current-buffer anything-current-buffer
6009 (loop initially (goto-char (point-min))
6010 while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
6011 for anchor = (match-string-no-properties 1)
6012 collect (cons (format "%5d:%s"
6013 (line-number-at-pos (match-beginning 0))
6014 (format ee-anchor-format anchor)) anchor))))))
6015 (persistent-action . (lambda (item)
6016 (ee-to item)
6017 (anything-match-line-color-current-line)))
6018 (persistent-help . "Show this entry")
6019 (action . (("Goto link" . ee-to)))))
6020 ;; (anything 'anything-c-source-eev-anchor)
6022 ;;;; <Misc>
6023 ;;; Org keywords
6024 (defvar anything-c-source-org-keywords
6025 '((name . "Org Keywords")
6026 (init . anything-c-org-keywords-init)
6027 (candidates . anything-c-org-keywords-candidates)
6028 (action . anything-c-org-keywords-insert)
6029 (persistent-action . anything-c-org-keywords-show-help)
6030 (persistent-help . "Show an example and info page to describe this keyword.")
6031 (keywords-examples)
6032 (keywords)))
6033 ;; (anything 'anything-c-source-org-keywords)
6034 (defvar anything-c-org-keywords-info-location
6035 '(("#+TITLE:" . "(org)Export options")
6036 ("#+AUTHOR:" . "(org)Export options")
6037 ("#+DATE:" . "(org)Export options")
6038 ("#+EMAIL:" . "(org)Export options")
6039 ("#+DESCRIPTION:" . "(org)Export options")
6040 ("#+KEYWORDS:" . "(org)Export options")
6041 ("#+LANGUAGE:" . "(org)Export options")
6042 ("#+TEXT:" . "(org)Export options")
6043 ("#+TEXT:" . "(org)Export options")
6044 ("#+OPTIONS:" . "(org)Export options")
6045 ("#+BIND:" . "(org)Export options")
6046 ("#+LINK_UP:" . "(org)Export options")
6047 ("#+LINK_HOME:" . "(org)Export options")
6048 ("#+LATEX_HEADER:" . "(org)Export options")
6049 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
6050 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
6051 ("#+INFOJS_OPT" . "(org)Javascript support")
6052 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
6053 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
6054 ("#+ORGTBL" . "(org)Radio tables")
6055 ("#+HTML:" . "(org)Quoting HTML tags")
6056 ("#+LaTeX:" . "(org)Quoting LaTeX code")
6057 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
6058 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
6059 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
6060 ("#+BEGIN_VERSE" . "(org)Paragraphs")
6061 ("#+BEGIN_SRC" . "(org)Literal examples")
6062 ("#+CAPTION" . "(org)Tables in HTML export")
6063 ("#+LABEL" . "(org)Tables in LaTeX export")
6064 ("#+ATTR_HTML" . "(org)Links")
6065 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
6067 (defun anything-c-org-keywords-init ()
6068 (unless (anything-attr 'keywords-examples)
6069 (require 'org)
6070 (anything-attrset 'keywords-examples
6071 (append
6072 (mapcar
6073 (lambda (x)
6074 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
6075 (cons (match-string 2 x) (match-string 1 x)))
6076 (org-split-string (org-get-current-options) "\n"))
6077 (mapcar 'list org-additional-option-like-keywords)))
6078 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
6080 (defun anything-c-org-keywords-candidates ()
6081 (and (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
6082 (anything-attr 'keywords)))
6084 (defun anything-c-org-keywords-insert (keyword)
6085 (cond ((string-match "BEGIN" keyword)
6086 (insert "#+" keyword " ")
6087 (save-excursion
6088 (insert "\n#+" (replace-regexp-in-string "BEGIN" "END" keyword) "\n")))
6090 (insert "#+" keyword " "))))
6092 (defun anything-c-org-keywords-show-help (keyword)
6093 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
6094 "(org)In-buffer settings"))
6095 (search-forward (concat "#+" keyword) nil t)
6096 (anything-persistent-highlight-point)
6097 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
6100 ;;; Picklist
6101 (defvar anything-c-source-picklist
6102 '((name . "Picklist")
6103 (candidates . (lambda () (mapcar 'car picklist-list)))
6104 (type . file)))
6105 ;; (anything 'anything-c-source-picklist)
6107 ;;; BBDB
6108 (defvar bbdb-records)
6109 (defvar bbdb-buffer-name)
6110 (declare-function bbdb "ext:bbdb-com")
6111 (declare-function bbdb-current-record "ext:bbdb-com")
6112 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
6113 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
6114 (declare-function bbdb-current-record "ext:bbdb-com")
6115 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
6116 (declare-function bbdb-records "ext:bbdb-com"
6117 (&optional dont-check-disk already-in-db-buffer))
6119 (defun anything-c-bbdb-candidates ()
6120 "Return a list of all names in the bbdb database. The format
6121 is \"Firstname Lastname\"."
6122 (mapcar (lambda (bbdb-record)
6123 (replace-regexp-in-string
6124 "\\s-+$" ""
6125 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
6126 (bbdb-records)))
6128 (defun anything-c-bbdb-create-contact (actions candidate)
6129 "Action transformer that returns only an entry to add the
6130 current `anything-pattern' as new contact. All other actions are
6131 removed."
6132 (if (string= candidate "*Add to contacts*")
6133 '(("Add to contacts" . (lambda (actions)
6134 (bbdb-create-internal
6135 (read-from-minibuffer "Name: " anything-c-bbdb-name)
6136 (read-from-minibuffer "Company: ")
6137 (read-from-minibuffer "Email: ")
6140 (read-from-minibuffer "Note: ")))))
6141 actions))
6143 (defun anything-c-bbdb-get-record (candidate)
6144 "Return record that match CANDIDATE."
6145 (bbdb candidate nil)
6146 (set-buffer "*BBDB*")
6147 (bbdb-current-record))
6149 (defvar anything-c-bbdb-name nil
6150 "Only for internal use.")
6152 (defvar anything-c-source-bbdb
6153 '((name . "BBDB")
6154 (candidates . anything-c-bbdb-candidates)
6155 (action ("Send a mail" . anything-c-bbdb-compose-mail)
6156 ("View person's data" . anything-c-bbdb-view-person-action))
6157 (filtered-candidate-transformer . (lambda (candidates source)
6158 (setq anything-c-bbdb-name anything-pattern)
6159 (if (not candidates)
6160 (list "*Add to contacts*")
6161 candidates)))
6162 (action-transformer . (lambda (actions candidate)
6163 (anything-c-bbdb-create-contact actions candidate))))
6164 "Needs BBDB.
6166 http://bbdb.sourceforge.net/")
6167 ;; (anything 'anything-c-source-bbdb)
6169 (defun anything-c-bbdb-view-person-action (candidate)
6170 "View BBDB data of single CANDIDATE or marked candidates."
6171 (anything-aif (anything-marked-candidates)
6172 (let ((bbdb-append-records (length it)))
6173 (dolist (i it)
6174 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
6175 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
6177 (defun anything-c-bbdb-collect-mail-addresses ()
6178 "Return a list of all mail addresses of records in bbdb buffer."
6179 (with-current-buffer bbdb-buffer-name
6180 (loop for i in bbdb-records
6181 if (bbdb-record-net (car i))
6182 collect (bbdb-dwim-net-address (car i)))))
6184 (defun anything-c-bbdb-compose-mail (candidate)
6185 "Compose a mail with all records of bbdb buffer."
6186 (anything-c-bbdb-view-person-action candidate)
6187 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
6188 (address-str (mapconcat 'identity address-list ",\n ")))
6189 (compose-mail address-str)))
6191 ;;; Evaluation Result
6192 (defvar anything-c-source-evaluation-result
6193 '((name . "Evaluation Result")
6194 (disable-shortcuts)
6195 (dummy)
6196 (filtered-candidate-transformer . (lambda (candidates source)
6197 (list
6198 (condition-case nil
6199 (with-current-buffer anything-current-buffer
6200 (pp-to-string
6201 (eval (read anything-pattern))))
6202 (error "Error")))))
6203 (action ("Copy result to kill-ring" . (lambda (candidate)
6204 (with-current-buffer anything-buffer
6205 (let ((end (save-excursion
6206 (goto-char (point-max))
6207 (search-backward "\n")
6208 (point))))
6209 (kill-region (point) end))))))))
6210 ;; (anything 'anything-c-source-evaluation-result)
6212 ;;;###autoload
6213 (defun anything-eval-expression (arg)
6214 "Preconfigured anything for `anything-c-source-evaluation-result'."
6215 (interactive "P")
6216 (anything 'anything-c-source-evaluation-result (when arg (thing-at-point 'sexp))
6217 nil nil nil "*anything eval*"))
6219 ;;;###autoload
6220 (defun anything-eval-expression-with-eldoc ()
6221 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
6222 (interactive)
6223 (if (window-system)
6224 (let ((timer (run-with-idle-timer eldoc-idle-delay
6225 'repeat 'anything-eldoc-show-in-eval)))
6226 (unwind-protect
6227 (call-interactively 'anything-eval-expression)
6228 (cancel-timer timer)))
6229 (call-interactively 'anything-eval-expression)))
6231 (defun anything-eldoc-show-in-eval ()
6232 "Return eldoc in a tooltip for current minibuffer input."
6233 (let* ((str-all (minibuffer-completion-contents))
6234 (sym (when str-all
6235 (with-temp-buffer
6236 (insert str-all)
6237 (goto-char (point-max))
6238 (unless (looking-back ")\\|\"") (forward-char -1))
6239 (eldoc-current-symbol))))
6240 (doc (or (eldoc-get-var-docstring sym)
6241 (eldoc-get-fnsym-args-string
6242 (car (eldoc-fnsym-in-current-sexp))))))
6243 (when doc (tooltip-show doc))))
6245 ;;; Calculation Result
6246 (defvar anything-c-source-calculation-result
6247 '((name . "Calculation Result")
6248 (dummy)
6249 (filtered-candidate-transformer . (lambda (candidates source)
6250 (list
6251 (condition-case nil
6252 (calc-eval anything-pattern)
6253 (error "error")))))
6254 (action ("Copy result to kill-ring" . kill-new))))
6255 ;; (anything 'anything-c-source-calculation-result)
6257 ;;;###autoload
6258 (defun anything-calcul-expression ()
6259 "Preconfigured anything for `anything-c-source-calculation-result'."
6260 (interactive)
6261 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
6263 ;;; Google Suggestions
6264 (defvar anything-gg-sug-lgh-flag 0)
6265 (defun anything-c-google-suggest-fetch (input)
6266 "Fetch suggestions for INPUT from XML buffer.
6267 Return an alist with elements like (data . number_results)."
6268 (let ((request (concat anything-c-google-suggest-url
6269 (url-hexify-string input))))
6270 (flet ((fetch ()
6271 (loop
6272 with result-alist = (xml-get-children
6273 (car (xml-parse-region (point-min) (point-max)))
6274 'CompleteSuggestion)
6275 for i in result-alist
6276 for data = (cdr (caadr (assoc 'suggestion i)))
6277 for nqueries = (cdr (caadr (assoc 'num_queries i)))
6278 for ldata = (length data)
6280 (when (> ldata anything-gg-sug-lgh-flag)
6281 (setq anything-gg-sug-lgh-flag ldata))
6282 collect (cons data nqueries) into cont
6283 finally return cont)))
6284 (if anything-google-suggest-use-curl-p
6285 (with-temp-buffer
6286 (call-process "curl" nil t nil request)
6287 (fetch))
6288 (with-current-buffer
6289 (url-retrieve-synchronously request)
6290 (fetch))))))
6293 (defun anything-c-google-suggest-set-candidates ()
6294 "Set candidates with result and number of google results found."
6295 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
6296 (setq suggestions (loop for i in suggestions
6297 for interval = (- anything-gg-sug-lgh-flag (length (car i)))
6298 for elm = (concat (car i)
6299 (make-string (+ 2 interval) ? )
6300 "(" (cdr i) " results)")
6301 collect (cons elm (car i))))
6302 (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
6303 suggestions
6304 ;; if there is no suggestion exactly matching the input then
6305 ;; prepend a Search on Google item to the list
6306 (append
6307 suggestions
6308 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
6309 anything-input))))))
6312 (defun anything-c-google-suggest-action (candidate)
6313 "Default action to jump to a google suggested candidate."
6314 (anything-c-browse-url (concat anything-c-google-suggest-search-url
6315 (url-hexify-string candidate))))
6318 (defvar anything-c-source-google-suggest
6319 '((name . "Google Suggest")
6320 (candidates . anything-c-google-suggest-set-candidates)
6321 (action . (("Google Search" . anything-c-google-suggest-action)))
6322 (volatile)
6323 (requires-pattern . 3)
6324 (delayed)))
6326 ;; (anything 'anything-c-source-google-suggest)
6328 ;;; Yahoo suggestions
6330 (defun anything-c-yahoo-suggest-fetch (input)
6331 "Fetch Yahoo suggestions for INPUT from XML buffer.
6332 Return an alist with elements like (data . number_results)."
6333 (let ((request (concat anything-c-yahoo-suggest-url
6334 (url-hexify-string input))))
6335 (flet ((fetch ()
6336 (loop
6337 with result-alist = (xml-get-children
6338 (car (xml-parse-region (point-min) (point-max)))
6339 'Result)
6340 for i in result-alist
6341 collect (caddr i))))
6342 (with-current-buffer
6343 (url-retrieve-synchronously request)
6344 (fetch)))))
6346 (defun anything-c-yahoo-suggest-set-candidates ()
6347 "Set candidates with Yahoo results found."
6348 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
6349 (or suggestions
6350 (append
6351 suggestions
6352 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
6353 anything-input))))))
6355 (defun anything-c-yahoo-suggest-action (candidate)
6356 "Default action to jump to a Yahoo suggested candidate."
6357 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
6358 (url-hexify-string candidate))))
6360 (defvar anything-c-source-yahoo-suggest
6361 '((name . "Yahoo Suggest")
6362 (candidates . anything-c-yahoo-suggest-set-candidates)
6363 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
6364 (volatile)
6365 (requires-pattern . 3)
6366 (delayed)))
6368 ;; (anything 'anything-c-source-yahoo-suggest)
6370 ;;; Surfraw
6371 ;;; Need external program surfraw.
6372 ;;; http://surfraw.alioth.debian.org/
6373 ;; user variables
6374 (require 'browse-url)
6375 (defvar w3m-command nil)
6376 (defvar anything-c-home-url "http://www.google.fr"
6377 "*Default url to use as home url.")
6379 (defvar browse-url-chromium-program "chromium-bin")
6380 (defvar anything-browse-url-default-browser-alist
6381 `((,w3m-command . w3m-browse-url)
6382 (,browse-url-firefox-program . browse-url-firefox)
6383 (,browse-url-chromium-program . browse-url-chromium)
6384 (,browse-url-kde-program . browse-url-kde)
6385 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
6386 (,browse-url-mozilla-program . browse-url-mozilla)
6387 (,browse-url-galeon-program . browse-url-galeon)
6388 (,browse-url-netscape-program . browse-url-netscape)
6389 (,browse-url-mosaic-program . browse-url-mosaic)
6390 (,browse-url-xterm-program . browse-url-text-xterm))
6391 "*Alist of (executable . function) to try to find a suitable url browser.")
6393 (defun* anything-c-generic-browser (url name &rest args)
6394 (let ((proc (concat name " " url)))
6395 (message "Starting %s..." name)
6396 (apply 'start-process proc nil name
6397 (append args (list url)))
6398 (set-process-sentinel
6399 (get-process proc)
6400 #'(lambda (process event)
6401 (when (string= event "finished\n")
6402 (message "%s process %s" process event))))))
6404 (defun browse-url-chromium (url)
6405 (interactive "sURL: ")
6406 (anything-c-generic-browser
6407 url browse-url-chromium-program
6408 "--enable-plugins"))
6410 (defun anything-browse-url-default-browser (url &rest args)
6411 "Find a suitable browser and ask it to load URL."
6412 (let ((default-browser (loop
6413 for i in anything-browse-url-default-browser-alist
6414 thereis (and (car i) (executable-find (car i))))))
6415 (if default-browser
6416 (apply default-browser url args)
6417 (error "No usable browser found"))))
6419 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
6420 "Default command to browse URL."
6421 (if browse-url-browser-function
6422 (funcall browse-url-browser-function url)
6423 (anything-browse-url-default-browser url)))
6425 (defun anything-c-build-elvi-list ()
6426 "Return list of all engines and descriptions handled by surfraw."
6427 (cdr
6428 (with-temp-buffer
6429 (call-process "surfraw" nil t nil
6430 "-elvi")
6431 (split-string (buffer-string) "\n"))))
6433 (defvar anything-surfraw-default-browser-function nil
6434 "*The browse url function you prefer to use with surfraw.
6435 When nil, fallback to `browse-url-browser-function'.")
6436 (defvar anything-surfraw-engines-history nil)
6437 ;;;###autoload
6438 (defun anything-surfraw (pattern engine)
6439 "Preconfigured `anything' to search PATTERN with search ENGINE."
6440 (interactive (list (read-string "SearchFor: ")
6441 (anything-comp-read
6442 "Engine: "
6443 (anything-c-build-elvi-list)
6444 :must-match t
6445 :name "Surfraw Search Engines"
6446 :history anything-surfraw-engines-history)))
6447 (let* ((engine-nodesc (car (split-string engine)))
6448 (url (with-temp-buffer
6449 (apply 'call-process "surfraw" nil t nil
6450 (list engine-nodesc "-p" pattern))
6451 (replace-regexp-in-string
6452 "\n" "" (buffer-string))))
6453 (browse-url-browser-function (or anything-surfraw-default-browser-function
6454 browse-url-browser-function)))
6455 (if (string= engine-nodesc "W")
6456 (anything-c-browse-url)
6457 (anything-c-browse-url url)
6458 (setq anything-surfraw-engines-history
6459 (cons engine (delete engine anything-surfraw-engines-history))))))
6461 ;;; Emms
6463 (defun anything-emms-stream-edit-bookmark (elm)
6464 "Change the information of current emms-stream bookmark from anything."
6465 (let* ((cur-buf anything-current-buffer)
6466 (bookmark (assoc elm emms-stream-list))
6467 (name (read-from-minibuffer "Description: "
6468 (nth 0 bookmark)))
6469 (url (read-from-minibuffer "URL: "
6470 (nth 1 bookmark)))
6471 (fd (read-from-minibuffer "Feed Descriptor: "
6472 (int-to-string (nth 2 bookmark))))
6473 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
6474 (format "%s" (car (last bookmark))))))
6475 (save-excursion
6476 (emms-streams)
6477 (when (re-search-forward (concat "^" name) nil t)
6478 (beginning-of-line)
6479 (emms-stream-delete-bookmark)
6480 (emms-stream-add-bookmark name url (string-to-number fd) type)
6481 (emms-stream-save-bookmarks-file)
6482 (emms-stream-quit)
6483 (switch-to-buffer cur-buf)))))
6485 (defun anything-emms-stream-delete-bookmark (elm)
6486 "Delete an emms-stream bookmark from anything."
6487 (let* ((cur-buf anything-current-buffer)
6488 (bookmark (assoc elm emms-stream-list))
6489 (name (nth 0 bookmark)))
6490 (save-excursion
6491 (emms-streams)
6492 (when (re-search-forward (concat "^" name) nil t)
6493 (beginning-of-line)
6494 (emms-stream-delete-bookmark)
6495 (emms-stream-save-bookmarks-file)
6496 (emms-stream-quit)
6497 (switch-to-buffer cur-buf)))))
6499 (defvar anything-c-source-emms-streams
6500 '((name . "Emms Streams")
6501 (init . (lambda ()
6502 (emms-stream-init)))
6503 (candidates . (lambda ()
6504 (mapcar 'car emms-stream-list)))
6505 (action . (("Play" . (lambda (elm)
6506 (let* ((stream (assoc elm emms-stream-list))
6507 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
6508 (url (second stream)))
6509 (funcall fn url))))
6510 ("Delete" . anything-emms-stream-delete-bookmark)
6511 ("Edit" . anything-emms-stream-edit-bookmark)))
6512 (filtered-candidate-transformer . anything-c-adaptive-sort)))
6513 ;; (anything 'anything-c-source-emms-streams)
6515 ;; Don't forget to set `emms-source-file-default-directory'
6516 (defvar anything-c-source-emms-dired
6517 '((name . "Music Directory")
6518 (candidates . (lambda ()
6519 (cddr (directory-files emms-source-file-default-directory))))
6520 (action .
6521 (("Play Directory" . (lambda (item)
6522 (emms-play-directory
6523 (expand-file-name
6524 item
6525 emms-source-file-default-directory))))
6526 ("Open dired in file's directory" . (lambda (item)
6527 (anything-c-open-dired
6528 (expand-file-name
6529 item
6530 emms-source-file-default-directory))))))
6531 (filtered-candidate-transformer . anything-c-adaptive-sort)))
6532 ;; (anything 'anything-c-source-emms-dired)
6534 (defface anything-emms-playlist
6535 '((t (:foreground "Springgreen4" :underline t)))
6536 "*Face used for tracks in current emms playlist."
6537 :group 'anything)
6539 (defun anything-c-emms-files-modifier (candidates source)
6540 (let ((current-playlist (with-current-emms-playlist
6541 (loop
6542 with cur-list = (emms-playlist-tracks-in-region
6543 (point-min) (point-max))
6544 for i in cur-list
6545 collect (assoc-default 'name i)))))
6546 (loop for i in candidates
6547 if (member (cdr i) current-playlist)
6548 collect (cons (propertize (car i)
6549 'face 'anything-emms-playlist)
6550 (cdr i)) into lis
6551 else collect i into lis
6552 finally return lis)))
6554 (defun anything-c-emms-play-current-playlist ()
6555 "Play current playlist."
6556 (with-current-emms-playlist
6557 (emms-playlist-first)
6558 (emms-playlist-mode-play-smart)))
6560 (defvar anything-c-source-emms-files
6561 '((name . "Emms files")
6562 (candidates . (lambda ()
6563 (loop for v being the hash-values in emms-cache-db
6564 for name = (assoc-default 'name v)
6565 for artist = (or (assoc-default 'info-artist v) "unknown")
6566 for genre = (or (assoc-default 'info-genre v) "unknown")
6567 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
6568 for song = (or (assoc-default 'info-title v) "unknown")
6569 for info = (concat artist " - " genre " - " tracknum ": " song)
6570 unless (string-match "^http:" name) collect (cons info name))))
6571 (filtered-candidate-transformer . anything-c-emms-files-modifier)
6572 (action . (("Play file" . emms-play-file)
6573 ("Add to Playlist and play (C-u clear current)"
6574 . (lambda (candidate)
6575 (when anything-current-prefix-arg
6576 (emms-playlist-current-clear))
6577 (emms-playlist-new)
6578 (mapc 'emms-add-playlist-file (anything-marked-candidates))
6579 (unless emms-player-playing-p
6580 (anything-c-emms-play-current-playlist))))))))
6582 ;; (anything 'anything-c-source-emms-files)
6584 ;;; Jabber Contacts (jabber.el)
6585 (defun anything-c-jabber-online-contacts ()
6586 "List online Jabber contacts."
6587 (with-no-warnings
6588 (let (jids)
6589 (dolist (item (jabber-concat-rosters) jids)
6590 (when (get item 'connected)
6591 (push (if (get item 'name)
6592 (cons (get item 'name) item)
6593 (cons (symbol-name item) item)) jids))))))
6595 (defvar anything-c-source-jabber-contacts
6596 '((name . "Jabber Contacts")
6597 (init . (lambda () (require 'jabber)))
6598 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
6599 (action . (lambda (x)
6600 (jabber-chat-with
6601 (jabber-read-account)
6602 (symbol-name
6603 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
6604 ;; (anything 'anything-c-source-jabber-contacts)
6607 ;;; Call source.
6608 (defvar anything-source-select-buffer "*anything source select*")
6609 (defvar anything-c-source-call-source
6610 `((name . "Call anything source")
6611 (candidate-number-limit)
6612 (candidates . (lambda ()
6613 (loop for vname in (all-completions "anything-c-source-" obarray)
6614 for var = (intern vname)
6615 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
6616 if name collect (cons (format "%s `%s'"
6617 name (propertize vname 'face 'font-lock-variable-name-face))
6618 var))))
6619 (action . (("Invoke anything with selected source" .
6620 (lambda (candidate)
6621 (setq anything-candidate-number-limit 9999)
6622 (anything candidate nil nil nil nil
6623 anything-source-select-buffer)))
6624 ("Describe variable" . describe-variable)
6625 ("Find variable" . find-variable)))
6626 (persistent-action . describe-variable)
6627 (persistent-help . "Show description of this source")))
6628 ;; (anything 'anything-c-source-call-source)
6630 ;;;###autoload
6631 (defun anything-call-source ()
6632 "Preconfigured `anything' to call anything source."
6633 (interactive)
6634 (anything 'anything-c-source-call-source nil nil nil nil
6635 anything-source-select-buffer))
6637 (defun anything-call-source-from-anything ()
6638 "Call anything source within `anything' session."
6639 (interactive)
6640 (setq anything-input-idle-delay 0)
6641 (anything-set-sources '(anything-c-source-call-source)))
6643 ;;; Execute Preconfigured anything.
6644 (defvar anything-c-source-anything-commands
6645 '((name . "Preconfigured Anything")
6646 (candidates . anything-c-anything-commands-candidates)
6647 (type . command)
6648 (candidate-number-limit)))
6649 ;; (anything 'anything-c-source-anything-commands)
6651 (defun anything-c-anything-commands-candidates ()
6652 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
6653 collect (cons (if (where-is-internal cmd nil t)
6654 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
6655 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
6656 cmd)))
6658 ;;;###autoload
6659 (defun anything-execute-anything-command ()
6660 "Preconfigured `anything' to execute preconfigured `anything'."
6661 (interactive)
6662 (anything-other-buffer 'anything-c-source-anything-commands
6663 "*anything commands*"))
6665 ;; Occur
6666 (defun anything-c-occur-init ()
6667 (anything-candidate-buffer anything-current-buffer))
6669 (defun anything-c-occur-get-line (s e)
6670 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
6672 (defvar anything-c-source-occur
6673 '((name . "Occur")
6674 (init . anything-c-occur-init)
6675 (candidates-in-buffer)
6676 (migemo)
6677 (get-line . anything-c-occur-get-line)
6678 (type . line)
6679 (recenter)
6680 (requires-pattern . 1)
6681 (delayed)
6682 (volatile)))
6683 ;; (anything 'anything-c-source-occur)
6685 ;;; Anything browse code.
6686 (defun anything-c-browse-code-get-line (beg end)
6687 "Select line if it match the regexp corresponding to current `major-mode'.
6688 Line is parsed for BEG position to END position."
6689 (let ((str-line (buffer-substring beg end))
6690 (regexp (assoc-default major-mode
6691 anything-c-browse-code-regexp-alist))
6692 (num-line (if (string= anything-pattern "") beg (1- beg))))
6693 (when (and regexp (string-match regexp str-line))
6694 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
6697 (defvar anything-c-source-browse-code
6698 '((name . "Browse code")
6699 (init . (lambda ()
6700 (anything-candidate-buffer anything-current-buffer)
6701 (with-current-buffer anything-current-buffer
6702 (jit-lock-fontify-now))))
6703 (candidate-number-limit . 9999)
6704 (candidates-in-buffer)
6705 (get-line . anything-c-browse-code-get-line)
6706 (type . line)
6707 (recenter)))
6709 ;; Do many actions for input
6710 (defvar anything-c-source-create
6711 '((name . "Create")
6712 (dummy)
6713 (action)
6714 (action-transformer . anything-create--actions))
6715 "Do many create actions from `anything-pattern'.
6716 See also `anything-create--actions'.")
6717 ;; (anything 'anything-c-source-create)
6719 (defun anything-create-from-anything ()
6720 "Run `anything-create' from `anything' as a fallback."
6721 (interactive)
6722 (anything-run-after-quit 'anything-create nil anything-pattern))
6724 ;;;###autoload
6725 (defun anything-create (&optional string initial-input)
6726 "Preconfigured `anything' to do many create actions from STRING.
6727 See also `anything-create--actions'."
6728 (interactive)
6729 (setq string (or string (read-string "Create Anything: " initial-input)))
6730 (anything '(((name . "Anything Create")
6731 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
6732 (candidates . anything-create--actions)
6733 (candidate-number-limit)
6734 (action . (lambda (func) (funcall func string)))))))
6736 (defun anything-create--actions (&rest ignored)
6737 "Default actions for `anything-create' / `anything-c-source-create'."
6738 (remove-if-not
6739 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
6740 (append anything-create--actions-private
6741 '(("find-file" . find-file)
6742 ("find-file other window" . find-file-other-window)
6743 ("New buffer" . switch-to-buffer)
6744 ("New buffer other window" . switch-to-buffer-other-window)
6745 ("Bookmark Set" . bookmark-set)
6746 ("Set Register" .
6747 (lambda (x) (set-register (read-char "Register: ") x)))
6748 ("Insert Linkd star" . linkd-insert-star)
6749 ("Insert Linkd Tag" . linkd-insert-tag)
6750 ("Insert Linkd Link" . linkd-insert-link)
6751 ("Insert Linkd Lisp" . linkd-insert-lisp)
6752 ("Insert Linkd Wiki" . linkd-insert-wiki)
6753 ("Google Search" . google)))))
6755 ;; Minibuffer History
6756 (defvar anything-c-source-minibuffer-history
6757 '((name . "Minibuffer History")
6758 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
6759 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
6760 (if (consp (car history))
6761 (mapcar 'prin1-to-string history)
6762 history))))
6763 (migemo)
6764 (action . insert)))
6765 ;; (anything 'anything-c-source-minibuffer-history)
6767 ;; elscreen
6768 (defvar anything-c-source-elscreen
6769 '((name . "Elscreen")
6770 (candidates . (lambda ()
6771 (if (cdr (elscreen-get-screen-to-name-alist))
6772 (sort
6773 (loop for sname in (elscreen-get-screen-to-name-alist)
6774 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
6775 finally (return lst))
6776 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
6777 (action . (("Change Screen".
6778 (lambda (candidate)
6779 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
6780 ("Kill Screen(s)".
6781 (lambda (candidate)
6782 (dolist (i (anything-marked-candidates))
6783 (elscreen-goto (- (aref i 1) (aref "0" 0)))
6784 (elscreen-kill))))
6785 ("Only Screen".
6786 (lambda (candidate)
6787 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
6788 (elscreen-kill-others)))))))
6789 ;; (anything 'anything-c-source-elscreen)
6791 ;;;; <System>
6793 ;;; Top (process)
6794 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
6795 "Top command (batch mode). %s is replaced with `frame-width'.")
6796 (defvar anything-c-source-top
6797 '((name . "Top (Press C-c C-u to refresh)")
6798 (init . anything-c-top-init)
6799 (candidates-in-buffer)
6800 (display-to-real . anything-c-top-display-to-real)
6801 (update . anything-c-top-update)
6802 (persistent-action . anything-c-top-sh-persistent-action)
6803 (persistent-help . "SIGTERM")
6804 (action
6805 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
6806 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
6807 ("Copy PID" . (lambda (pid) (kill-new pid))))))
6808 ;; (anything 'anything-c-source-top)
6810 (defun anything-c-top-sh (cmd)
6811 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
6813 (defun anything-c-top-sh-persistent-action (pid)
6814 (delete-other-windows)
6815 (anything-c-top-sh (format "kill -TERM %s" pid))
6816 (anything-force-update))
6818 (defun anything-c-top-init ()
6819 (with-current-buffer (anything-candidate-buffer 'global)
6820 (call-process-shell-command
6821 (format anything-c-top-command
6822 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
6823 nil (current-buffer))))
6825 (defun anything-c-top-display-to-real (line)
6826 (car (split-string line)))
6828 (defun anything-c-top-update ()
6829 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
6830 (anything-c-top-init)))
6832 ;;;###autoload
6833 (defun anything-top ()
6834 "Preconfigured `anything' for top command."
6835 (interactive)
6836 (let ((anything-samewindow t)
6837 (anything-enable-shortcuts)
6838 (anything-display-function 'anything-default-display-buffer)
6839 (anything-candidate-number-limit 9999))
6840 (save-window-excursion
6841 (delete-other-windows)
6842 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
6844 ;;; Timers
6845 (defvar anything-c-source-absolute-time-timers
6846 '((name . "Absolute Time Timers")
6847 (candidates . timer-list)
6848 (type . timer)))
6849 ;; (anything 'anything-c-source-absolute-time-timers)
6851 (defvar anything-c-source-idle-time-timers
6852 '((name . "Idle Time Timers")
6853 (candidates . timer-idle-list)
6854 (type . timer)))
6855 ;; (anything 'anything-c-source-idle-time-timers)
6857 (defun anything-c-timer-real-to-display (timer)
6858 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
6859 (append timer nil) ;use `append' to convert vector->list
6860 (format "%s repeat=%5S %s(%s)"
6861 (let ((time (list t1 t2 t3)))
6862 (if idle-delay
6863 (format-time-string "idle-for=%5s" time)
6864 (format-time-string "%m/%d %T" time)))
6865 repeat-delay
6866 func
6867 (mapconcat 'prin1-to-string args " "))))
6869 ;;; X RandR resolution change
6870 ;;; FIXME I do not care multi-display.
6871 (defvar anything-c-xrandr-output "VGA")
6872 (defvar anything-c-xrandr-screen "0")
6873 (defvar anything-c-source-xrandr-change-resolution
6874 '((name . "Change Resolution")
6875 (candidates
6876 . (lambda ()
6877 (with-temp-buffer
6878 (call-process "xrandr" nil (current-buffer) nil
6879 "--screen" anything-c-xrandr-screen "-q")
6880 (goto-char 1)
6881 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
6882 collect (match-string 1)))))
6883 (action
6884 ("Change Resolution" . (lambda (mode)
6885 (call-process "xrandr" nil nil nil
6886 "--screen" anything-c-xrandr-screen
6887 "--output" anything-c-xrandr-output
6888 "--mode" mode))))))
6889 ;; (anything 'anything-c-source-xrandr-change-resolution)
6891 ;;; Xfont selection
6892 (defun anything-c-persistent-xfont-action (elm)
6893 "Show current font temporarily"
6894 (let ((current-font (cdr (assoc 'font (frame-parameters))))
6895 (default-font elm))
6896 (unwind-protect
6897 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
6898 (set-frame-font current-font))))
6900 (defvar anything-c-xfonts-cache nil)
6901 (defvar anything-c-source-xfonts
6902 '((name . "X Fonts")
6903 (init . (lambda ()
6904 (unless anything-c-xfonts-cache
6905 (setq anything-c-xfonts-cache
6906 (x-list-fonts "*")))))
6907 (candidates . anything-c-xfonts-cache)
6908 (action . (("Copy to kill ring" . (lambda (elm)
6909 (kill-new elm)))
6910 ("Set Font" . (lambda (elm)
6911 (kill-new elm)
6912 (set-frame-font elm 'keep-size)
6913 (message "New font have been copied to kill ring")))))
6914 (persistent-action . anything-c-persistent-xfont-action)
6915 (persistent-help . "Switch to this font temporarily")))
6917 ;;;###autoload
6918 (defun anything-select-xfont ()
6919 "Preconfigured `anything' to select Xfont."
6920 (interactive)
6921 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
6923 ;; (anything 'anything-c-source-xfonts)
6925 ;;; World time
6927 (defvar anything-c-source-time-world
6928 '((name . "Time World List")
6929 (init . (lambda ()
6930 (let ((anything-buffer (anything-candidate-buffer 'global)))
6931 (with-current-buffer anything-buffer
6932 (display-time-world-display display-time-world-list)))))
6933 (candidates-in-buffer)))
6935 ;;;###autoload
6936 (defun anything-world-time ()
6937 "Preconfigured `anything' to show world time."
6938 (interactive)
6939 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
6941 ;;; Source for Debian/Ubuntu users
6942 (defvar anything-c-source-apt
6943 '((name . "APT")
6944 (init . anything-c-apt-init)
6945 (candidates-in-buffer)
6946 (candidate-transformer anything-c-apt-candidate-transformer)
6947 (display-to-real . anything-c-apt-display-to-real)
6948 (candidate-number-limit . 9999)
6949 (action
6950 ("Show package description" . anything-c-apt-cache-show)
6951 ("Install package" . anything-c-apt-install)
6952 ("Remove package" . anything-c-apt-uninstall)
6953 ("Purge package" . anything-c-apt-purge))
6954 (persistent-action . anything-c-apt-persistent-action)
6955 (persistent-help . "Show - C-u Refresh")))
6956 ;; (anything 'anything-c-source-apt)
6958 (defvar anything-c-apt-query "emacs")
6959 (defvar anything-c-apt-search-command "apt-cache search '%s'")
6960 (defvar anything-c-apt-show-command "apt-cache show '%s'")
6961 (defvar anything-c-apt-installed-packages nil)
6963 (defface anything-apt-installed
6964 '((t (:foreground "green")))
6965 "*Face used for apt installed candidates."
6966 :group 'anything)
6968 (defun anything-c-apt-refresh ()
6969 "Refresh installed candidates list."
6970 (setq anything-c-apt-installed-packages nil)
6971 (anything-force-update))
6973 (defun anything-c-apt-persistent-action (candidate)
6974 "Persistent action for APT source."
6975 (if current-prefix-arg
6976 (anything-c-apt-refresh)
6977 (anything-c-apt-cache-show candidate)))
6979 ;;;###autoload
6980 (defun anything-apt (query)
6981 "Preconfigured `anything' : frontend of APT package manager."
6982 (interactive "sAPT search: ")
6983 (let ((anything-c-apt-query query))
6984 (anything 'anything-c-source-apt)))
6986 (defun anything-c-apt-candidate-transformer (candidates)
6987 "Show installed candidates in a different color."
6988 (loop
6989 with all
6990 for cand in candidates
6991 for name = (anything-c-apt-display-to-real cand)
6992 if (member name anything-c-apt-installed-packages)
6993 collect (propertize cand 'face 'anything-apt-installed) into all
6994 else collect cand into all finally return all))
6996 (defun anything-c-apt-init ()
6997 "Initialize list of debian packages."
6998 (unless anything-c-apt-installed-packages
6999 (message "Updating installed candidate list...")
7000 (setq anything-c-apt-installed-packages
7001 (with-temp-buffer
7002 (call-process-shell-command "dpkg --get-selections"
7003 nil (current-buffer))
7004 (loop for i in (split-string (buffer-string) "\n" t)
7005 collect (car (split-string i))))))
7006 (with-current-buffer
7007 (anything-candidate-buffer
7008 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query)))
7009 (erase-buffer)
7010 (call-process-shell-command
7011 (format anything-c-apt-search-command anything-c-apt-query)
7012 nil (current-buffer)))
7013 (message "Updating installed candidate list...done"))
7015 (defun anything-c-apt-display-to-real (line)
7016 "Return only name of a debian package.
7017 LINE is displayed like:
7018 package name - description."
7019 (car (split-string line " - ")))
7021 ;;;###autoload
7022 (defun anything-c-shell-command-if-needed (command)
7023 (interactive "sShell command: ")
7024 (if (get-buffer command) ; if the buffer already exists
7025 (switch-to-buffer command) ; then just switch to it
7026 (switch-to-buffer command) ; otherwise create it
7027 (insert (shell-command-to-string command))))
7029 (defun anything-c-apt-cache-show (package)
7030 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package)))
7032 (defun anything-c-apt-install (package)
7033 (anything-c-apt-install1 package :action 'install))
7035 (defun anything-c-apt-uninstall (package)
7036 (anything-c-apt-install1 package :action 'uninstall))
7038 (defun anything-c-apt-purge (package)
7039 (anything-c-apt-install1 package :action 'purge))
7041 (defun* anything-c-apt-install1 (candidate &key action)
7042 (ansi-term (getenv "SHELL") "anything apt")
7043 (term-line-mode)
7044 (let ((command (case action
7045 ('install "sudo apt-get install '%s'")
7046 ('uninstall "sudo apt-get remove '%s'")
7047 ('purge "sudo apt-get purge '%s'")
7048 (t (error "Unknow action"))))
7049 (beg (point)) end)
7050 (goto-char (point-max))
7051 (insert (format command candidate))
7052 (setq end (point))
7053 (if (y-or-n-p (format "%s package" (symbol-name action)))
7054 (progn
7055 (setq anything-c-external-commands-list nil)
7056 (setq anything-c-apt-installed-packages nil)
7057 (term-char-mode) (term-send-input))
7058 (delete-region beg end) (term-send-eof) (kill-buffer))))
7060 ;; (anything-c-apt-install "jed")
7062 ;;; Sources for gentoo users
7063 (defvar anything-c-gentoo-use-flags nil)
7064 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
7065 (defvar anything-c-cache-gentoo nil)
7066 (defvar anything-c-cache-world nil)
7067 (defvar anything-c-source-gentoo
7068 '((name . "Portage sources")
7069 (init . (lambda ()
7070 (get-buffer-create anything-c-gentoo-buffer)
7071 (unless anything-c-cache-gentoo
7072 (anything-c-gentoo-setup-cache))
7073 (unless anything-c-cache-world
7074 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
7075 (anything-c-gentoo-init-list)))
7076 (candidates-in-buffer)
7077 (match . identity)
7078 (candidate-transformer anything-c-highlight-world)
7079 (action . (("Show package" . (lambda (elm)
7080 (anything-c-gentoo-eshell-action elm "eix")))
7081 ("Show history" . (lambda (elm)
7082 (if (member elm anything-c-cache-world)
7083 (anything-c-gentoo-eshell-action elm "genlop -qe")
7084 (message "No infos on packages not yet installed"))))
7085 ("Copy in kill-ring" . kill-new)
7086 ("insert at point" . insert)
7087 ("Browse HomePage" . (lambda (elm)
7088 (let ((urls (anything-c-gentoo-get-url elm)))
7089 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
7090 ("Show extra infos" . (lambda (elm)
7091 (if (member elm anything-c-cache-world)
7092 (anything-c-gentoo-eshell-action elm "genlop -qi")
7093 (message "No infos on packages not yet installed"))))
7094 ("Show use flags" . (lambda (elm)
7095 (anything-c-gentoo-default-action elm "equery" "-C" "u")
7096 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
7097 (font-lock-mode 1)))
7098 ("Run emerge pretend" . (lambda (elm)
7099 (anything-c-gentoo-eshell-action elm "emerge -p")))
7100 ("Emerge" . (lambda (elm)
7101 (anything-gentoo-install elm :action 'install)))
7102 ("Unmerge" . (lambda (elm)
7103 (anything-gentoo-install elm :action 'uninstall)))
7104 ("Show dependencies" . (lambda (elm)
7105 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
7106 ("Show related files" . (lambda (elm)
7107 (anything-c-gentoo-default-action elm "equery" "files")))
7108 ("Refresh" . (lambda (elm)
7109 (anything-c-gentoo-setup-cache)
7110 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
7112 ;; (anything 'anything-c-source-gentoo)
7114 (defun* anything-gentoo-install (candidate &key action)
7115 (setq anything-c-external-commands-list nil)
7116 (ansi-term (getenv "SHELL") "Gentoo emerge")
7117 (term-line-mode)
7118 (let ((command (case action
7119 ('install "sudo emerge -av ")
7120 ('uninstall "sudo emerge -avC ")
7121 (t (error "Unknow action"))))
7122 (elms (mapconcat 'identity (anything-marked-candidates) " "))
7123 (beg (point)) end)
7124 (goto-char (point-max))
7125 (insert (concat command elms))
7126 (setq end (point))
7127 (term-char-mode) (term-send-input)))
7129 (defun anything-c-gentoo-default-action (elm command &rest args)
7130 "Gentoo default action that use `anything-c-gentoo-buffer'."
7131 (if (member elm anything-c-cache-world)
7132 (progn
7133 (switch-to-buffer anything-c-gentoo-buffer)
7134 (erase-buffer)
7135 (let ((com-list (append args (list elm))))
7136 (apply #'call-process command nil t nil
7137 com-list)))
7138 (message "No infos on packages not yet installed")))
7140 (defvar anything-c-source-use-flags
7141 '((name . "Use Flags")
7142 (init . (lambda ()
7143 (unless anything-c-gentoo-use-flags
7144 (anything-c-gentoo-setup-use-flags-cache))
7145 (anything-c-gentoo-get-use)))
7146 (candidates-in-buffer)
7147 (match . identity)
7148 (candidate-transformer anything-c-highlight-local-use)
7149 (action . (("Description"
7150 . (lambda (elm)
7151 (switch-to-buffer anything-c-gentoo-buffer)
7152 (erase-buffer)
7153 (apply #'call-process "euse" nil t nil
7154 `("-i"
7155 ,elm))
7156 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
7157 (font-lock-mode 1)))
7158 ("Enable"
7159 . (lambda (elm)
7160 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
7161 ("Disable"
7162 . (lambda (elm)
7163 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
7164 ("Remove"
7165 . (lambda (elm)
7166 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
7167 ("Show which dep use this flag"
7168 . (lambda (elm)
7169 (switch-to-buffer anything-c-gentoo-buffer)
7170 (erase-buffer)
7171 (apply #'call-process "equery" nil t nil
7172 `("-C"
7174 ,elm))))))))
7177 ;; (anything 'anything-c-source-use-flags)
7179 (defun anything-c-gentoo-init-list ()
7180 "Initialize buffer with all packages in Portage."
7181 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
7182 (buf (anything-candidate-buffer 'portage-buf)))
7183 (with-current-buffer buf
7184 (dolist (i anything-c-cache-gentoo)
7185 (insert (concat i "\n"))))))
7187 (defun anything-c-gentoo-setup-cache ()
7188 "Set up `anything-c-cache-gentoo'"
7189 (setq anything-c-cache-gentoo
7190 (split-string (with-temp-buffer
7191 (call-process "eix" nil t nil
7192 "--only-names")
7193 (buffer-string)))))
7195 (defun anything-c-gentoo-eshell-action (elm command)
7196 (when (get-buffer "*EShell Command Output*")
7197 (kill-buffer "*EShell Command Output*"))
7198 (message "Wait searching...")
7199 (let ((buf-fname (buffer-file-name anything-current-buffer)))
7200 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
7201 (progn
7202 (save-window-excursion
7203 (pop-to-buffer "*scratch*")
7204 (eshell-command (format "%s %s" command elm)))
7205 (pop-to-buffer "*EShell Command Output*"))
7206 (eshell-command (format "%s %s" command elm)))))
7208 (defun anything-c-gentoo-get-use ()
7209 "Initialize buffer with all use flags."
7210 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
7211 (buf (anything-candidate-buffer 'use-buf)))
7212 (with-current-buffer buf
7213 (dolist (i anything-c-gentoo-use-flags)
7214 (insert (concat i "\n"))))))
7217 (defun anything-c-gentoo-setup-use-flags-cache ()
7218 "Setup `anything-c-gentoo-use-flags'"
7219 (setq anything-c-gentoo-use-flags
7220 (split-string (with-temp-buffer
7221 (call-process "eix" nil t nil
7222 "--print-all-useflags")
7223 (buffer-string)))))
7225 (defun anything-c-gentoo-get-url (elm)
7226 "Return a list of urls from eix output."
7227 (loop
7228 with url-list = (split-string
7229 (with-temp-buffer
7230 (call-process "eix" nil t nil
7231 elm "--format" "<homepage>\n")
7232 (buffer-string)))
7233 with all
7234 for i in url-list
7235 when (and (string-match "^http://.*" i)
7236 (not (member i all)))
7237 collect i into all
7238 finally return all))
7240 (defun anything-c-gentoo-get-world ()
7241 "Return list of all installed package on your system."
7242 (split-string (with-temp-buffer
7243 (call-process "qlist" nil t nil
7244 "-I")
7245 (buffer-string))))
7247 (defun anything-c-gentoo-get-local-use ()
7248 (split-string (with-temp-buffer
7249 (call-process "portageq" nil t nil
7250 "envvar"
7251 "USE")
7252 (buffer-string))))
7254 (defface anything-gentoo-match-face '((t (:foreground "red")))
7255 "Face for anything-gentoo installed packages."
7256 :group 'traverse-faces)
7258 (defun anything-c-highlight-world (eix)
7259 "Highlight all installed package."
7260 (loop for i in eix
7261 if (member i anything-c-cache-world)
7262 collect (propertize i 'face 'anything-gentoo-match-face)
7263 else
7264 collect i))
7266 (defun anything-c-highlight-local-use (use-flags)
7267 (let ((local-uses (anything-c-gentoo-get-local-use)))
7268 (loop for i in use-flags
7269 if (member i local-uses)
7270 collect (propertize i 'face 'anything-gentoo-match-face)
7271 else
7272 collect i)))
7274 (defvar anything-c-source-emacs-process
7275 '((name . "Emacs Process")
7276 (candidates . (lambda () (mapcar #'process-name (process-list))))
7277 (persistent-action . (lambda (elm)
7278 (delete-process (get-process elm))
7279 (anything-delete-current-selection)))
7280 (persistent-help . "Kill Process")
7281 (action ("Kill Process" . (lambda (elm)
7282 (delete-process (get-process elm)))))))
7284 ;; (anything 'anything-c-source-emacs-process)
7286 ;; Run Externals commands within Emacs
7287 (defmacro* anything-comp-hash-get-items (hash-table &key test)
7288 "Get the list of all keys/values of hash-table."
7289 `(let ((li-items ()))
7290 (maphash #'(lambda (x y)
7291 (if ,test
7292 (when (funcall ,test y)
7293 (push (list x y) li-items))
7294 (push (list x y) li-items)))
7295 ,hash-table)
7296 li-items))
7298 (defun anything-comp-read-get-candidates (collection &optional test sort-fn)
7299 "Convert COLLECTION to list removing elements that don't match TEST.
7300 SORT-FN is a predicate to sort COLLECTION.
7301 If collection is an `obarray', a TEST is needed. See `obarray'."
7302 (let ((cands
7303 (cond ((and (listp collection) test)
7304 (loop for i in collection when (funcall test i) collect i))
7305 ((and (eq collection obarray) test)
7306 (loop for s being the symbols of collection
7307 when (funcall test s) collect s))
7308 ((and (vectorp collection) test)
7309 (loop for i across collection when (funcall test i) collect i))
7310 ((vectorp collection)
7311 (loop for i across collection collect i))
7312 ((and (hash-table-p collection) test)
7313 (anything-comp-hash-get-items collection :test test))
7314 ((hash-table-p collection)
7315 (anything-comp-hash-get-items collection))
7316 (t collection))))
7317 (if sort-fn (sort cands sort-fn) cands)))
7319 (defun anything-cr-default-transformer (candidates source)
7320 "Default filter candidate function for `anything-comp-read'.
7321 Do nothing, just return candidate list unmodified."
7322 candidates)
7324 (defun* anything-comp-read (prompt collection
7325 &key
7326 test
7327 initial-input
7328 (buffer "*Anything Completions*")
7329 must-match
7330 (requires-pattern 0)
7331 (history nil)
7332 (persistent-action nil)
7333 (persistent-help "DoNothing")
7334 (name "Anything Completions")
7335 sort
7336 (fc-transformer 'anything-cr-default-transformer)
7337 (marked-candidates nil))
7338 "Anything `completing-read' emulation.
7339 PROMPT is the prompt name to use.
7340 COLLECTION can be a list, vector, obarray or hash-table.
7341 Keys:
7343 TEST: A predicate called with one arg i.e candidate.
7344 INITIAL-INPUT: Same as initial-input arg in `anything'.
7345 BUFFER: Name of anything-buffer.
7346 MUST-MATCH: Candidate selected must be one of COLLECTION.
7347 REQUIRES-PATTERN: Same as anything attribute, default is 0.
7348 HISTORY: A list containing specific history, default is nil.
7349 When it is non--nil, all elements of HISTORY are displayed in
7350 anything-buffer before COLLECTION.
7351 PERSISTENT-ACTION: A function called with one arg i.e candidate.
7352 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
7353 NAME: The name related to this local source.
7354 SORT: A predicate to give to `sort' e.g `string-lessp'.
7355 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
7356 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
7358 Any prefix args passed during `anything-comp-read' invocation will be recorded
7359 in `anything-current-prefix-arg', otherwise if prefix args where given before
7360 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
7361 That's mean you can pass prefix arg before or after calling
7362 a command that use `anything-comp-read'."
7363 (when (get-buffer anything-action-buffer)
7364 (kill-buffer anything-action-buffer))
7365 (flet ((action-fn (candidate)
7366 (if marked-candidates
7367 (anything-marked-candidates)
7368 (identity candidate))))
7369 (or (anything
7370 :sources
7371 `(((name . ,(format "%s History" name))
7372 (candidates . (lambda ()
7373 (anything-comp-read-get-candidates history)))
7374 (volatile)
7375 (persistent-action . ,persistent-action)
7376 (persistent-help . ,persistent-help)
7377 (action . ,'action-fn))
7378 ((name . ,name)
7379 (candidates
7380 . (lambda ()
7381 (let ((cands (anything-comp-read-get-candidates
7382 collection test sort)))
7383 (if (or must-match (string= anything-pattern ""))
7384 cands (append (list anything-pattern) cands)))))
7385 (filtered-candidate-transformer ,fc-transformer)
7386 (requires-pattern . ,requires-pattern)
7387 (persistent-action . ,persistent-action)
7388 (persistent-help . ,persistent-help)
7389 (volatile)
7390 (action . ,'action-fn)))
7391 :input initial-input
7392 :prompt prompt
7393 :resume 'noresume
7394 :buffer buffer)
7395 (keyboard-quit))))
7397 (defun anything-c-get-pid-from-process-name (process-name)
7398 "Get pid from running process PROCESS-NAME."
7399 (loop with process-list = (list-system-processes)
7400 for pid in process-list
7401 for process = (assoc-default 'comm (process-attributes pid))
7402 when (and process (string-match process-name process))
7403 return pid))
7406 (defun anything-run-or-raise (exe &optional file)
7407 "Generic command that run asynchronously EXE.
7408 If EXE is already running just jump to his window if `anything-raise-command'
7409 is non--nil.
7410 When FILE argument is provided run EXE with FILE.
7411 In this case EXE must be provided as \"EXE %s\"."
7412 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string "'%s'" "" exe))))
7413 (proc (if file (concat real-com " " file) real-com)))
7414 (if (get-process proc)
7415 (if anything-raise-command
7416 (shell-command (format anything-raise-command real-com))
7417 (error "Error: %s is already running" real-com))
7418 (when (member real-com anything-c-external-commands-list)
7419 (message "Starting %s..." real-com)
7420 (if file
7421 (start-process-shell-command proc nil (format exe file))
7422 (start-process-shell-command proc nil real-com))
7423 (set-process-sentinel
7424 (get-process proc)
7425 #'(lambda (process event)
7426 (when (and (string= event "finished\n")
7427 anything-raise-command
7428 (not (anything-c-get-pid-from-process-name real-com)))
7429 (shell-command (format anything-raise-command "emacs")))
7430 (message "%s process...Finished." process))))
7431 (setq anything-c-external-commands-list
7432 (cons real-com (delete real-com anything-c-external-commands-list))))))
7435 (defvar anything-external-command-history nil)
7436 ;;;###autoload
7437 (defun anything-c-run-external-command (program)
7438 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
7439 If program is already running exit with error.
7440 You can set your own list of commands with
7441 `anything-c-external-commands-list'."
7442 (interactive (list
7443 (anything-comp-read
7444 "RunProgram: "
7445 (anything-c-external-commands-list-1 'sort)
7446 :must-match t
7447 :name "External Commands"
7448 :history anything-external-command-history)))
7449 (anything-run-or-raise program)
7450 (setq anything-external-command-history
7451 (cons program (delete program
7452 (loop for i in anything-external-command-history
7453 when (executable-find i) collect i)))))
7455 (defsubst* anything-c-position (item seq &key (test 'eq))
7456 "A simple and faster replacement of CL `position'."
7457 (loop for i in seq for index from 0
7458 when (funcall test i item) return index))
7460 (defvar anything-c-source-ratpoison-commands
7461 '((name . "Ratpoison Commands")
7462 (init . anything-c-ratpoison-commands-init)
7463 (candidates-in-buffer)
7464 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
7465 (display-to-real . anything-c-ratpoison-commands-display-to-real)
7466 (candidate-number-limit)))
7467 ;; (anything 'anything-c-source-ratpoison-commands)
7469 (defun anything-c-ratpoison-commands-init ()
7470 (unless (anything-candidate-buffer)
7471 (with-current-buffer (anything-candidate-buffer 'global)
7472 ;; with ratpoison prefix key
7473 (save-excursion
7474 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
7475 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
7476 (replace-match "<ratpoison> \\1: \\2"))
7477 (goto-char (point-max))
7478 ;; direct binding
7479 (save-excursion
7480 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
7481 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
7482 (replace-match "\\1: \\2")))))
7484 (defun anything-c-ratpoison-commands-display-to-real (display)
7485 (and (string-match ": " display)
7486 (substring display (match-end 0))))
7488 (defun anything-c-ratpoison-commands-execute (candidate)
7489 (call-process "ratpoison" nil nil nil "-ic" candidate))
7491 ;;;###autoload
7492 (defun anything-ratpoison-commands ()
7493 "Preconfigured `anything' to execute ratpoison commands."
7494 (interactive)
7495 (anything-other-buffer 'anything-c-source-ratpoison-commands
7496 "*anything ratpoison commands*"))
7498 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7499 ;;; Files
7500 (defvar anything-c-external-commands-list nil
7501 "A list of all external commands the user can execute. If this
7502 variable is not set by the user, it will be calculated
7503 automatically.")
7505 (defun anything-c-external-commands-list-1 (&optional sort)
7506 "Returns a list of all external commands the user can execute.
7507 If `anything-c-external-commands-list' is non-nil it will
7508 return its contents. Else it calculates all external commands
7509 and sets `anything-c-external-commands-list'."
7510 (if anything-c-external-commands-list
7511 anything-c-external-commands-list
7512 (setq anything-c-external-commands-list
7513 (loop
7514 with paths = (split-string (getenv "PATH") path-separator)
7515 with completions = ()
7516 for dir in paths
7517 when (and (file-exists-p dir) (file-accessible-directory-p dir))
7518 for lsdir = (loop for i in (directory-files dir t)
7519 for bn = (file-name-nondirectory i)
7520 when (and (not (member bn completions))
7521 (not (file-directory-p i))
7522 (file-executable-p i))
7523 collect bn)
7524 append lsdir into completions
7525 finally return (if sort (sort completions 'string-lessp) completions)))))
7528 (defun anything-c-file-buffers (filename)
7529 "Returns a list of buffer names corresponding to FILENAME."
7530 (let ((name (expand-file-name filename))
7531 (buf-list ()))
7532 (dolist (buf (buffer-list) buf-list)
7533 (let ((bfn (buffer-file-name buf)))
7534 (when (and bfn (string= name bfn))
7535 (push (buffer-name buf) buf-list))))))
7538 (defun anything-c-delete-file (file)
7539 "Delete the given file after querying the user.
7540 Ask to kill buffers associated with that file, too."
7541 (let ((buffers (anything-c-file-buffers file)))
7542 (if (< emacs-major-version 24)
7543 ;; `dired-delete-file' in Emacs versions < 24
7544 ;; doesn't support delete-by-moving-to-trash
7545 ;; so use `delete-directory' and `delete-file'
7546 ;; that handle it.
7547 (cond ((and (not (file-symlink-p file))
7548 (file-directory-p file)
7549 (directory-files file t dired-re-no-dot))
7550 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
7551 (delete-directory file 'recursive)))
7552 ((and (not (file-symlink-p file))
7553 (file-directory-p file))
7554 (delete-directory file))
7555 (t (delete-file file)))
7556 (dired-delete-file
7557 file 'dired-recursive-deletes delete-by-moving-to-trash))
7558 (when buffers
7559 (dolist (buf buffers)
7560 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
7561 (kill-buffer buf))))))
7563 (defun anything-get-mailcap-for-file (filename)
7564 "Get the command to use for FILENAME from mailcap files.
7565 The command is like <command %s> and is meant to use with `format'."
7566 (mailcap-parse-mailcaps)
7567 (let* ((ext (file-name-extension filename))
7568 (mime (when ext (mailcap-extension-to-mime ext))))
7569 (when mime (mailcap-mime-info mime))))
7571 (defun anything-get-default-program-for-file (filename)
7572 "Try to find a default program to open FILENAME.
7573 Try first in `anything-c-external-programs-associations' and then in mailcap file
7574 if nothing found return nil."
7575 (let* ((ext (file-name-extension filename))
7576 (def-prog (assoc-default ext anything-c-external-programs-associations)))
7577 (if (and def-prog (not (string= def-prog "")))
7578 (concat def-prog " %s")
7579 (anything-get-mailcap-for-file filename))))
7581 (defun anything-c-open-file-externally (file)
7582 "Open FILE with an external program.
7583 Try to guess which program to use with `anything-get-default-program-for-file'.
7584 If not found or a prefix arg is given query the user which tool to use."
7585 (let* ((fname (expand-file-name file))
7586 (collection (anything-c-external-commands-list-1 'sort))
7587 (def-prog (anything-get-default-program-for-file fname))
7588 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
7589 ;; Prefix arg or no default program.
7590 (prog1
7591 (anything-comp-read
7592 "Program: " collection
7593 :must-match t
7594 :name "Open file Externally"
7595 :history anything-external-command-history)
7596 ;; Always prompt to set this program as default.
7597 (setq def-prog nil))
7598 ;; No prefix arg or default program exists.
7599 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
7600 (program (concat real-prog-name " '%s'")))
7601 (unless (or def-prog ; Association exists, no need to record it.
7602 ;; Don't try to record non--filenames associations (e.g urls).
7603 (not (file-exists-p fname)))
7604 (when
7605 (y-or-n-p
7606 (format
7607 "Do you want to make `%s' the default program for this kind of files? "
7608 real-prog-name))
7609 (anything-aif (assoc (file-name-extension fname)
7610 anything-c-external-programs-associations)
7611 (setq anything-c-external-programs-associations
7612 (delete it anything-c-external-programs-associations)))
7613 (push (cons (file-name-extension fname)
7614 (read-string
7615 "Program (Add args maybe and confirm): " real-prog-name))
7616 anything-c-external-programs-associations)
7617 (customize-save-variable 'anything-c-external-programs-associations
7618 anything-c-external-programs-associations)))
7619 (anything-run-or-raise program file)
7620 (setq anything-external-command-history
7621 (cons real-prog-name
7622 (delete real-prog-name
7623 (loop for i in anything-external-command-history
7624 when (executable-find i) collect i))))))
7627 ;;;###autoload
7628 (defun w32-shell-execute-open-file (file)
7629 (interactive "fOpen file:")
7630 (with-no-warnings
7631 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
7632 "/" "\\"
7633 (replace-regexp-in-string ; strip cygdrive paths
7634 "/cygdrive/\\(.\\)" "\\1:"
7635 file nil nil) nil t))))
7637 (defun anything-c-open-file-with-default-tool (file)
7638 "Open FILE with the default tool on this platform."
7639 (if (eq system-type 'windows-nt)
7640 (w32-shell-execute-open-file file)
7641 (start-process "anything-c-open-file-with-default-tool"
7643 (cond ((eq system-type 'gnu/linux)
7644 "xdg-open")
7645 ((or (eq system-type 'darwin) ;; Mac OS X
7646 (eq system-type 'macos)) ;; Mac OS 9
7647 "open"))
7648 file)))
7650 (defun anything-c-open-dired (file)
7651 "Opens a dired buffer in FILE's directory. If FILE is a
7652 directory, open this directory."
7653 (if (file-directory-p file)
7654 (dired file)
7655 (dired (file-name-directory file))
7656 (dired-goto-file file)))
7658 (defun anything-c-display-to-real-line (candidate)
7659 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
7660 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
7661 (error "Line number not found")))
7663 (defun anything-c-action-line-goto (lineno-and-content)
7664 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
7665 (append lineno-and-content
7666 (list (if (and (anything-attr-defined 'target-file)
7667 (not anything-in-persistent-action))
7668 'find-file-other-window
7669 'find-file)))))
7671 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
7672 (apply #'anything-goto-file-line
7673 (if (stringp file-line-content)
7674 ;; Case: filtered-candidate-transformer is skipped
7675 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
7676 file-line-content)))
7678 (require 'compile)
7679 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
7680 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
7682 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
7683 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
7684 (let ((filename (match-string 1 candidate))
7685 (lineno (match-string 2 candidate))
7686 (content (match-string 3 candidate)))
7687 (cons (format "%s:%s\n %s"
7688 (propertize filename 'face compilation-info-face)
7689 (propertize lineno 'face compilation-line-face)
7690 content)
7691 (list (expand-file-name
7692 filename
7693 (or (anything-interpret-value (anything-attr 'default-directory))
7694 (and (anything-candidate-buffer)
7695 (buffer-local-value
7696 'default-directory (anything-candidate-buffer)))))
7697 (string-to-number lineno) content)))))
7699 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
7700 (anything-aif (anything-attr 'before-jump-hook)
7701 (funcall it))
7702 (when file (funcall find-file-function file))
7703 (if (anything-attr-defined 'adjust)
7704 (anything-c-goto-line-with-adjustment lineno content)
7705 (anything-goto-line lineno))
7706 (unless (anything-attr-defined 'recenter)
7707 (set-window-start (get-buffer-window anything-current-buffer) (point)))
7708 (anything-aif (anything-attr 'after-jump-hook)
7709 (funcall it))
7710 (when anything-in-persistent-action
7711 (anything-match-line-color-current-line)))
7713 (defun anything-find-file-as-root (candidate)
7714 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
7716 (defun anything-find-many-files (ignore)
7717 (mapc 'find-file (anything-marked-candidates)))
7719 ;; borrowed from etags.el
7720 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
7721 (defun anything-c-goto-line-with-adjustment (line line-content)
7722 (let ((startpos)
7723 offset found pat)
7724 ;; This constant is 1/2 the initial search window.
7725 ;; There is no sense in making it too small,
7726 ;; since just going around the loop once probably
7727 ;; costs about as much as searching 2000 chars.
7728 (setq offset 1000
7729 found nil
7730 pat (concat (if (eq selective-display t)
7731 "\\(^\\|\^m\\) *" "^ *") ;allow indent
7732 (regexp-quote line-content)))
7733 ;; If no char pos was given, try the given line number.
7734 (setq startpos (progn (anything-goto-line line) (point)))
7735 (or startpos (setq startpos (point-min)))
7736 ;; First see if the tag is right at the specified location.
7737 (goto-char startpos)
7738 (setq found (looking-at pat))
7739 (while (and (not found)
7740 (progn
7741 (goto-char (- startpos offset))
7742 (not (bobp))))
7743 (setq found
7744 (re-search-forward pat (+ startpos offset) t)
7745 offset (* 3 offset))) ; expand search window
7746 (or found
7747 (re-search-forward pat nil t)
7748 (error "not found")))
7749 ;; Position point at the right place
7750 ;; if the search string matched an extra Ctrl-m at the beginning.
7751 (and (eq selective-display t)
7752 (looking-at "\^m")
7753 (forward-char 1))
7754 (beginning-of-line))
7756 (anything-document-attribute 'default-directory "type . file-line"
7757 "`default-directory' to interpret file.")
7758 (anything-document-attribute 'before-jump-hook "type . file-line / line"
7759 "Function to call before jumping to the target location.")
7760 (anything-document-attribute 'after-jump-hook "type . file-line / line"
7761 "Function to call after jumping to the target location.")
7762 (anything-document-attribute 'adjust "type . file-line"
7763 "Search around line matching line contents.")
7764 (anything-document-attribute 'recenter "type . file-line / line"
7765 "`recenter' after jumping.")
7766 (anything-document-attribute 'target-file "type . line"
7767 "Goto line of target-file.")
7769 ;;;###autoload
7770 (defun anything-c-call-interactively (cmd-or-name)
7771 "Execute CMD-OR-NAME as Emacs command.
7772 It is added to `extended-command-history'.
7773 `anything-current-prefix-arg' is used as the command's prefix argument."
7774 (setq extended-command-history
7775 (cons (anything-c-stringify cmd-or-name)
7776 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
7777 (let ((current-prefix-arg anything-current-prefix-arg)
7778 (cmd (anything-c-symbolify cmd-or-name)))
7779 (if (stringp (symbol-function cmd))
7780 (execute-kbd-macro (symbol-function cmd))
7781 (setq this-command cmd)
7782 (call-interactively cmd))))
7784 ;;;###autoload
7785 (defun anything-c-set-variable (var)
7786 "Set value to VAR interactively."
7787 (interactive)
7788 (let ((sym (anything-c-symbolify var)))
7789 (set sym (eval-minibuffer (format "Set %s: " var)
7790 (prin1-to-string (symbol-value sym))))))
7791 ;; (setq hh 12)
7792 ;; (anything-c-set-variable 'hh)
7794 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7795 (defvar anything-match-line-overlay-face nil)
7796 (defvar anything-match-line-overlay nil)
7798 (defun anything-match-line-color-current-line (&optional start end buf face rec)
7799 "Highlight and underline current position"
7800 (let ((args (list (or start (line-beginning-position))
7801 (or end (1+ (line-end-position)))
7802 buf)))
7803 (if (not anything-match-line-overlay)
7804 (setq anything-match-line-overlay (apply 'make-overlay args))
7805 (apply 'move-overlay anything-match-line-overlay args)))
7806 (overlay-put anything-match-line-overlay
7807 'face (or face anything-match-line-overlay-face))
7808 (when rec
7809 (goto-char start)
7810 (recenter)))
7812 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
7814 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
7815 "Face for source header in the anything buffer." :group 'anything)
7817 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
7819 (defun anything-match-line-cleanup ()
7820 (when anything-match-line-overlay
7821 (delete-overlay anything-match-line-overlay)
7822 (setq anything-match-line-overlay nil)))
7824 (defun anything-match-line-update ()
7825 (when anything-match-line-overlay
7826 (delete-overlay anything-match-line-overlay)
7827 (anything-match-line-color-current-line)))
7829 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
7830 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
7832 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7833 ;;; Files
7834 (defun anything-c-transform-file-load-el (actions candidate)
7835 "Add action to load the file CANDIDATE if it is an emacs lisp
7836 file. Else return ACTIONS unmodified."
7837 (if (member (file-name-extension candidate) '("el" "elc"))
7838 (append actions '(("Load Emacs Lisp File" . load-file)))
7839 actions))
7841 (defun anything-c-transform-file-browse-url (actions candidate)
7842 "Add an action to browse the file CANDIDATE if it in a html
7843 file or URL. Else return ACTIONS unmodified."
7844 (let ((browse-action '("Browse with Browser" . browse-url)))
7845 (cond ((string-match "^http\\|^ftp" candidate)
7846 (cons browse-action actions))
7847 ((string-match "\\.html?$" candidate)
7848 (append actions (list browse-action)))
7849 (t actions))))
7851 ;;;; Function
7852 (defun anything-c-transform-function-call-interactively (actions candidate)
7853 "Add an action to call the function CANDIDATE interactively if
7854 it is a command. Else return ACTIONS unmodified."
7855 (if (commandp (intern-soft candidate))
7856 (append actions '(("Call Interactively"
7858 anything-c-call-interactively)))
7859 actions))
7861 ;;;; S-Expressions
7862 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
7863 "If CANDIDATE's `car' is a command, then add an action to
7864 evaluate it and put it onto the `command-history'."
7865 (if (commandp (car (read candidate)))
7866 ;; Make it first entry
7867 (cons '("Eval and put onto command-history" .
7868 (lambda (sexp)
7869 (let ((sym (read sexp)))
7870 (eval sym)
7871 (setq command-history
7872 (cons sym command-history)))))
7873 actions)
7874 actions))
7876 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7877 ;;; Buffers
7878 (defun anything-c-skip-boring-buffers (buffers)
7879 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
7881 (defun anything-c-skip-current-buffer (buffers)
7882 (if anything-allow-skipping-current-buffer
7883 (remove (buffer-name anything-current-buffer) buffers)
7884 buffers))
7886 (defun anything-c-shadow-boring-buffers (buffers)
7887 "Buffers matching `anything-c-boring-buffer-regexp' will be
7888 displayed with the `file-name-shadow' face if available."
7889 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
7891 ;;; Files
7892 (defun anything-c-shadow-boring-files (files)
7893 "Files matching `anything-c-boring-file-regexp' will be
7894 displayed with the `file-name-shadow' face if available."
7895 (anything-c-shadow-entries files anything-c-boring-file-regexp))
7897 (defun anything-c-skip-boring-files (files)
7898 "Files matching `anything-c-boring-file-regexp' will be skipped."
7899 (anything-c-skip-entries files anything-c-boring-file-regexp))
7900 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
7902 (defun anything-c-skip-current-file (files)
7903 "Current file will be skipped."
7904 (remove (buffer-file-name anything-current-buffer) files))
7906 (defun anything-c-w32-pathname-transformer (args)
7907 "Change undesirable features of windows pathnames to ones more acceptable to
7908 other candidate transformers."
7909 (if (eq system-type 'windows-nt)
7910 (mapcar (lambda (x)
7911 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
7912 (mapcar (lambda (y)
7913 (replace-regexp-in-string "\\\\" "/" y)) args))
7914 args))
7916 (defun anything-c-shorten-home-path (files)
7917 "Replaces /home/user with ~."
7918 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
7919 (getenv "HOME"))))
7920 (mapcar (lambda (file)
7921 (if (and (stringp file) (string-match home file))
7922 (cons (replace-match "~" nil nil file) file)
7923 file))
7924 files)))
7926 ;;; Functions
7927 (defun anything-c-mark-interactive-functions (functions)
7928 "Mark interactive functions (commands) with (i) after the function name."
7929 (let (list)
7930 (loop for function in functions
7931 do (push (cons (concat function
7932 (when (commandp (intern-soft function)) " (i)"))
7933 function)
7934 list)
7935 finally (return (nreverse list)))))
7937 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7939 ;; Internal
7940 (defvar anything-c-adaptive-done nil
7941 "nil if history information is not yet stored for the current
7942 selection.")
7944 (defvar anything-c-adaptive-history nil
7945 "Contains the stored history information.
7946 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
7948 (defcustom anything-c-use-adaptative-sorting nil
7949 "*Wheter to use or not adaptative sorting.
7950 Even if a source use it, it will have no effect when set to nil."
7951 :type 'boolean
7952 :group 'anything-config)
7954 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
7955 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
7956 when anything is started."
7957 (when anything-c-use-adaptative-sorting
7958 (setq anything-c-adaptive-done nil)))
7960 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
7961 "Advise `anything-exit-minibuffer' to store history information
7962 when a candidate is selected with RET."
7963 (when anything-c-use-adaptative-sorting
7964 (anything-c-adaptive-store-selection)))
7966 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
7967 "Advise `anything-select-action' to store history information
7968 when the user goes to the action list with TAB."
7969 (when anything-c-use-adaptative-sorting
7970 (anything-c-adaptive-store-selection)))
7972 (defun anything-c-source-use-adaptative-p (&optional source-name)
7973 "Return current source only if it use adaptative history, nil otherwise."
7974 (when anything-c-use-adaptative-sorting
7975 (let* ((source (or source-name (anything-get-current-source)))
7976 (adapt-source (or (assoc-default 'filtered-candidate-transformer
7977 (assoc (assoc-default 'type source)
7978 anything-type-attributes))
7979 (assoc-default 'candidate-transformer
7980 (assoc (assoc-default 'type source)
7981 anything-type-attributes))
7982 (assoc-default 'filtered-candidate-transformer source)
7983 (assoc-default 'candidate-transformer source))))
7984 (if (listp adapt-source)
7985 (when (member 'anything-c-adaptive-sort adapt-source) source)
7986 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
7988 (defun anything-c-adaptive-store-selection ()
7989 "Store history information for the selected candidate."
7990 (unless anything-c-adaptive-done
7991 (setq anything-c-adaptive-done t)
7992 (let ((source (anything-c-source-use-adaptative-p)))
7993 (when source
7994 (let* ((source-name (or (assoc-default 'type source)
7995 (assoc-default 'name source)))
7996 (source-info (or (assoc source-name anything-c-adaptive-history)
7997 (progn
7998 (push (list source-name) anything-c-adaptive-history)
7999 (car anything-c-adaptive-history))))
8000 (selection (anything-get-selection))
8001 (selection-info (progn
8002 (setcdr source-info
8003 (cons
8004 (let ((found (assoc selection (cdr source-info))))
8005 (if (not found)
8006 ;; new entry
8007 (list selection)
8009 ;; move entry to the beginning of the
8010 ;; list, so that it doesn't get
8011 ;; trimmed when the history is
8012 ;; truncated
8013 (setcdr source-info
8014 (delete found (cdr source-info)))
8015 found))
8016 (cdr source-info)))
8017 (cadr source-info)))
8018 (pattern-info (progn
8019 (setcdr selection-info
8020 (cons
8021 (let ((found (assoc anything-pattern (cdr selection-info))))
8022 (if (not found)
8023 ;; new entry
8024 (cons anything-pattern 0)
8026 ;; move entry to the beginning of the
8027 ;; list, so if two patterns used the
8028 ;; same number of times then the one
8029 ;; used last appears first in the list
8030 (setcdr selection-info
8031 (delete found (cdr selection-info)))
8032 found))
8033 (cdr selection-info)))
8034 (cadr selection-info))))
8036 ;; increase usage count
8037 (setcdr pattern-info (1+ (cdr pattern-info)))
8039 ;; truncate history if needed
8040 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
8041 (setcdr selection-info
8042 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
8044 (defun anything-c-adaptative-maybe-load-history ()
8045 (when (and anything-c-use-adaptative-sorting
8046 (file-readable-p anything-c-adaptive-history-file))
8047 (load-file anything-c-adaptive-history-file)))
8049 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
8050 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
8052 (defun anything-c-adaptive-save-history ()
8053 "Save history information to file given by `anything-c-adaptive-history-file'."
8054 (interactive)
8055 (when anything-c-use-adaptative-sorting
8056 (with-temp-buffer
8057 (insert
8058 ";; -*- mode: emacs-lisp -*-\n"
8059 ";; History entries used for anything adaptive display.\n")
8060 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
8061 (current-buffer))
8062 (insert ?\n)
8063 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
8064 (unless (interactive-p) 'quiet)))))
8066 (defun anything-c-adaptive-sort (candidates source)
8067 "Sort the CANDIDATES for SOURCE by usage frequency.
8068 This is a filtered candidate transformer you can use for the
8069 attribute `filtered-candidate-transformer' of a source in
8070 `anything-sources' or a type in `anything-type-attributes'."
8071 (let* ((source-name (or (assoc-default 'type source)
8072 (assoc-default 'name source)))
8073 (source-info (assoc source-name anything-c-adaptive-history)))
8074 (if source-info
8075 (let ((usage
8076 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
8077 ;; pairs
8078 (mapcar (lambda (candidate-info)
8079 (let ((count 0))
8080 (dolist (pattern-info (cdr candidate-info))
8081 (if (not (equal (car pattern-info)
8082 anything-pattern))
8083 (incf count (cdr pattern-info))
8085 ;; if current pattern is equal to the previously
8086 ;; used one then this candidate has priority
8087 ;; (that's why its count is boosted by 10000) and
8088 ;; it only has to compete with other candidates
8089 ;; which were also selected with the same pattern
8090 (setq count (+ 10000 (cdr pattern-info)))
8091 (return)))
8092 (cons (car candidate-info) count)))
8093 (cdr source-info)))
8094 sorted)
8095 (if (and usage (consp usage))
8096 ;; sort the list in descending order, so candidates with highest
8097 ;; priorty come first
8098 (progn
8099 (setq usage (sort usage (lambda (first second)
8100 (> (cdr first) (cdr second)))))
8102 ;; put those candidates first which have the highest usage count
8103 (dolist (info usage)
8104 (when (member* (car info) candidates
8105 :test 'anything-c-adaptive-compare)
8106 (push (car info) sorted)
8107 (setq candidates (remove* (car info) candidates
8108 :test 'anything-c-adaptive-compare))))
8110 ;; and append the rest
8111 (append (reverse sorted) candidates nil))
8112 (message "Your `%s' is maybe corrupted or too old, \
8113 you should reinitialize it with `anything-c-reset-adaptative-history'"
8114 anything-c-adaptive-history-file)
8115 (sit-for 1)
8116 candidates))
8117 ;; if there is no information stored for this source then do nothing
8118 candidates)))
8120 ;;;###autoload
8121 (defun anything-c-reset-adaptative-history ()
8122 "Delete all `anything-c-adaptive-history' and his file.
8123 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
8124 (interactive)
8125 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
8126 (setq anything-c-adaptive-history nil)
8127 (delete-file anything-c-adaptive-history-file)))
8129 (defun anything-c-adaptive-compare (x y)
8130 "Compare candidates X and Y taking into account that the
8131 candidate can be in (DISPLAY . REAL) format."
8132 (equal (if (listp x)
8133 (cdr x)
8135 (if (listp y)
8136 (cdr y)
8137 y)))
8139 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8140 (defvar anything-outline-goto-near-line-flag t)
8141 (defvar anything-outline-using nil)
8142 (defun anything-after-update-hook--outline ()
8143 (if (and (eq anything-outline-using t)
8144 (eq anything-outline-goto-near-line-flag t))
8145 (anything-outline-goto-near-line)))
8146 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
8148 (defun anything-outline-goto-near-line ()
8149 (with-anything-window
8150 ;; TODO need consideration whether to update position by every input.
8151 (when t ; (equal anything-pattern "")
8152 (anything-goto-line 2)
8153 (let ((lineno (with-current-buffer anything-current-buffer
8154 (line-number-at-pos (car anything-current-position)))))
8155 (block exit
8156 (while (<= (progn (skip-chars-forward " ")
8157 (or (number-at-point) lineno))
8158 lineno)
8159 (forward-line 1)
8160 (when (eobp)
8161 (forward-line -1)
8162 (return-from exit))))
8163 (forward-line -1)
8164 (and (bobp) (forward-line 1))
8165 (and (anything-pos-header-line-p) (forward-line -2))
8166 (anything-mark-current-line)))))
8168 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8169 ;; Plug-in: info-index
8170 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
8171 (let (result)
8172 (unless (anything-candidate-buffer)
8173 (save-window-excursion
8174 (info file)
8175 (let (Info-history
8176 (tobuf (anything-candidate-buffer 'global))
8177 (infobuf (current-buffer))
8178 s e)
8179 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
8180 (Info-goto-node node)
8181 (goto-char (point-min))
8182 (while (search-forward "\n* " nil t)
8183 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
8184 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
8185 (setq s (point-at-bol)
8186 e (point-at-eol))
8187 (with-current-buffer tobuf
8188 (insert-buffer-substring infobuf s e)
8189 (insert "\n"))))))))))
8191 (defun anything-c-info-goto (node-line)
8192 (Info-goto-node (car node-line))
8193 (anything-goto-line (cdr node-line)))
8195 (defun anything-c-info-display-to-real (line)
8196 (and (string-match
8197 ;; This regexp is stolen from Info-apropos-matches
8198 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
8199 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
8200 (string-to-number (or (match-string 3 line) "1")))))
8202 (defun anything-c-make-info-source (source file)
8203 `(,@source
8204 (name . ,(concat "Info Index: " file))
8205 (info-file . ,file)
8206 (init . anything-c-info-init)
8207 (display-to-real . anything-c-info-display-to-real)
8208 (get-line . buffer-substring)
8209 (candidates-in-buffer)
8210 (action ("Goto node" . anything-c-info-goto))))
8212 (defun anything-compile-source--info-index (source)
8213 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
8214 (anything-c-make-info-source source it)
8215 source))
8216 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
8218 (anything-document-attribute 'info-index "info-index plugin"
8219 "Create a source of info index very easily.
8221 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
8223 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
8224 "Index nodes of info file.
8226 If it is omitted, `Info-index-nodes' is used to collect index nodes.
8227 Some info files are missing index specification.
8229 ex. See `anything-c-source-info-screen'.")
8231 ;; Plug-in: candidates-file
8232 (defun anything-compile-source--candidates-file (source)
8233 (if (assoc-default 'candidates-file source)
8234 `((init anything-p-candidats-file-init
8235 ,@(let ((orig-init (assoc-default 'init source)))
8236 (cond ((null orig-init) nil)
8237 ((functionp orig-init) (list orig-init))
8238 (t orig-init))))
8239 (candidates-in-buffer)
8240 ,@source)
8241 source))
8242 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
8244 (defun anything-p-candidats-file-init ()
8245 (destructuring-bind (file &optional updating)
8246 (anything-mklist (anything-attr 'candidates-file))
8247 (setq file (anything-interpret-value file))
8248 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
8249 (when updating
8250 (buffer-disable-undo)
8251 (font-lock-mode -1)
8252 (auto-revert-mode 1)))))
8254 (anything-document-attribute 'candidates-file "candidates-file plugin"
8255 "Use a file as the candidates buffer.
8257 1st argument is a filename, string or function name or variable name.
8258 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
8260 ;; Plug-in: headline
8261 (defun anything-compile-source--anything-headline (source)
8262 (if (assoc-default 'headline source)
8263 (append '((init . anything-headline-init)
8264 (get-line . buffer-substring)
8265 (type . line))
8266 source
8267 '((candidates-in-buffer)
8268 (persistent-help . "Show this line")))
8269 source))
8270 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
8272 (defun anything-headline-init ()
8273 (when (and (anything-current-buffer-is-modified)
8274 (with-current-buffer anything-current-buffer
8275 (eval (or (anything-attr 'condition) t))))
8276 (anything-headline-make-candidate-buffer
8277 (anything-interpret-value (anything-attr 'headline))
8278 (anything-interpret-value (anything-attr 'subexp)))))
8280 (anything-document-attribute 'headline "Headline plug-in"
8281 "Regexp string for anything-headline to scan.")
8282 (anything-document-attribute 'condition "Headline plug-in"
8283 "A sexp representing the condition to use anything-headline.")
8284 (anything-document-attribute 'subexp "Headline plug-in"
8285 "Display (match-string-no-properties subexp).")
8288 (defun anything-headline-get-candidates (regexp subexp)
8289 (with-current-buffer anything-current-buffer
8290 (save-excursion
8291 (goto-char (point-min))
8292 (if (functionp regexp) (setq regexp (funcall regexp)))
8293 (let (hierarchy curhead)
8294 (flet ((matched ()
8295 (if (numberp subexp)
8296 (cons (match-string-no-properties subexp) (match-beginning subexp))
8297 (cons (buffer-substring (point-at-bol) (point-at-eol))
8298 (point-at-bol))))
8299 (hierarchies (headlines)
8300 (1+ (loop for (_ . hierarchy) in headlines
8301 maximize hierarchy)))
8302 (vector-0-n (v n)
8303 (loop for i from 0 to hierarchy
8304 collecting (aref curhead i)))
8305 (arrange (headlines)
8306 (unless (null headlines) ; FIX headlines empty bug!
8307 (loop with curhead = (make-vector (hierarchies headlines) "")
8308 for ((str . pt) . hierarchy) in headlines
8309 do (aset curhead hierarchy str)
8310 collecting
8311 (cons
8312 (format "H%d:%s" (1+ hierarchy)
8313 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
8314 pt)))))
8315 (if (listp regexp)
8316 (arrange
8317 (sort
8318 (loop for re in regexp
8319 for hierarchy from 0
8320 do (goto-char (point-min))
8321 appending
8322 (loop
8323 while (re-search-forward re nil t)
8324 collect (cons (matched) hierarchy)))
8325 (lambda (a b) (> (cdar b) (cdar a)))))
8326 (loop while (re-search-forward regexp nil t)
8327 collect (matched))))))))
8330 (defun anything-headline-make-candidate-buffer (regexp subexp)
8331 (with-current-buffer (anything-candidate-buffer 'local)
8332 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
8333 do (insert
8334 (format "%5d:%s\n"
8335 (with-current-buffer anything-current-buffer
8336 (line-number-at-pos pos))
8337 content)))))
8339 (defun anything-headline-goto-position (pos recenter)
8340 (goto-char pos)
8341 (unless recenter
8342 (set-window-start (get-buffer-window anything-current-buffer) (point))))
8344 (defun anything-revert-buffer (candidate)
8345 (with-current-buffer candidate
8346 (when (buffer-modified-p)
8347 (revert-buffer t t))))
8349 (defun anything-revert-marked-buffers (ignore)
8350 (mapc 'anything-revert-buffer (anything-marked-candidates)))
8352 (defun anything-kill-marked-buffers (ignore)
8353 (mapc 'kill-buffer (anything-marked-candidates)))
8355 ;; Plug-in: persistent-help
8356 (defun anything-compile-source--persistent-help (source)
8357 (append source '((header-line . anything-persistent-help-string))))
8358 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
8360 (defun anything-persistent-help-string ()
8361 (substitute-command-keys
8362 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
8363 (or (anything-interpret-value (anything-attr 'persistent-help))
8364 (anything-aif (or (assoc-default 'persistent-action
8365 (anything-get-current-source))
8366 (assoc-default 'action
8367 (anything-get-current-source)))
8368 (cond ((symbolp it) (symbol-name it))
8369 ((listp it) (or (ignore-errors (caar it)) ""))))
8371 " (keeping session)")))
8373 (anything-document-attribute 'persistent-help "persistent-help plug-in"
8374 "A string to explain persistent-action of this source.
8375 It also accepts a function or a variable name.")
8377 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
8379 ;; Plug-in: Type customize
8380 (defun anything-c-uniq-list (lst)
8381 "Like `remove-duplicates' in CL.
8382 But cut deeper duplicates and test by `equal'. "
8383 (reverse (remove-duplicates (reverse lst) :test 'equal)))
8384 (defvar anything-additional-type-attributes nil)
8385 (defun anything-c-arrange-type-attribute (type spec)
8386 "Override type attributes by `define-anything-type-attribute'.
8388 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
8390 Example: Set `play-sound-file' as default action
8391 (anything-c-arrange-type-attribute 'file
8392 '((action (\"Play sound\" . play-sound-file)
8393 REST ;; Rest of actions (find-file, find-file-other-window, ...)
8396 (add-to-list 'anything-additional-type-attributes
8397 (cons type
8398 (loop with typeattr = (assoc-default type anything-type-attributes)
8399 for (attr . value) in spec
8400 if (listp value)
8401 collect (cons attr
8402 (anything-c-uniq-list
8403 (loop for v in value
8404 if (eq v 'REST)
8405 append (assoc-default attr typeattr)
8406 else
8407 collect v)))
8408 else
8409 collect (cons attr value)))))
8410 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
8412 (defun anything-compile-source--type-customize (source)
8413 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
8414 (append it source)
8415 source))
8416 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
8418 ;; Plug-in: default-action
8419 (defun anything-compile-source--default-action (source)
8420 (anything-aif (assoc-default 'default-action source)
8421 (append `((action ,it ,@(remove it (assoc-default 'action source))))
8422 source)
8423 source))
8424 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
8425 (anything-document-attribute 'default-action "default-action plug-in"
8426 "Default action.")
8428 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8430 (defun anything-c-find-file-or-marked (candidate)
8431 "Open file CANDIDATE or open anything marked files in background."
8432 (let ((marked (anything-marked-candidates)))
8433 (if (> (length marked) 1)
8434 ;; Open all marked files in background.
8435 (mapc 'find-file-noselect marked)
8436 (if (and (not (file-exists-p candidate))
8437 (and ffap-url-regexp
8438 (not (string-match ffap-url-regexp candidate)))
8439 (string-match "/$" candidate))
8440 ;; A a non--existing filename ending with /
8441 ;; Create a directory and jump to it.
8442 (when (y-or-n-p (format "Create directory `%s'? " candidate))
8443 (make-directory candidate 'parent)
8444 (anything-find-files1 candidate))
8445 ;; A non--existing filename NOT ending with / or
8446 ;; an existing filename, create or jump to it.
8447 (find-file-at-point (car marked))))))
8449 (defun anything-delete-marked-files (ignore)
8450 (let* ((files (anything-marked-candidates))
8451 (len (length files)))
8452 (if (not (y-or-n-p
8453 (format "Delete *%s File(s):\n%s"
8455 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
8456 (message "(No deletions performed)")
8457 (dolist (i files)
8458 (set-text-properties 0 (length i) nil i)
8459 (anything-c-delete-file i))
8460 (message "%s File(s) deleted" len))))
8462 (defun anything-ediff-marked-buffers (candidate &optional merge)
8463 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
8464 With optional arg `merge' call `ediff-merge-buffers'."
8465 (let ((lg-lst (length (anything-marked-candidates)))
8466 buf1 buf2)
8467 (case lg-lst
8469 (error "Error:You have to mark at least 1 buffer"))
8471 (setq buf1 anything-current-buffer
8472 buf2 (first (anything-marked-candidates))))
8474 (setq buf1 (first (anything-marked-candidates))
8475 buf2 (second (anything-marked-candidates))))
8477 (error "Error:To much buffers marked!")))
8478 (if merge
8479 (ediff-merge-buffers buf1 buf2)
8480 (ediff-buffers buf1 buf2))))
8482 (defun anything-bookmark-get-bookmark-from-name (bmk)
8483 "Return bookmark name even if it is a bookmark with annotation.
8484 e.g prepended with *.
8485 Return nil if bmk is not a valid bookmark."
8486 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
8487 (if (assoc bookmark bookmark-alist)
8488 bookmark
8489 (when (assoc bmk bookmark-alist)
8490 bmk))))
8492 (defun anything-delete-marked-bookmarks (ignore)
8493 "Delete this bookmark or all marked bookmarks."
8494 (dolist (i (anything-marked-candidates))
8495 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
8496 'batch)))
8498 (defun anything-require-or-error (feature function)
8499 (or (require feature nil t)
8500 (error "Need %s to use `%s'." feature function)))
8502 (defun anything-find-buffer-on-elscreen (candidate)
8503 "Open buffer in new screen, if marked buffers open all in elscreens."
8504 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
8505 (anything-aif (anything-marked-candidates)
8506 (dolist (i it)
8507 (let ((target-screen (elscreen-find-screen-by-buffer
8508 (get-buffer i) 'create)))
8509 (elscreen-goto target-screen)))
8510 (let ((target-screen (elscreen-find-screen-by-buffer
8511 (get-buffer candidate) 'create)))
8512 (elscreen-goto target-screen))))
8514 (defun anything-elscreen-find-file (file)
8515 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
8516 (elscreen-find-file file))
8518 ;; Toggle anything-match-plugin
8519 (defvar anything-mp-initial-highlight-delay nil)
8520 (defun anything-c-toggle-match-plugin ()
8521 "Toggle anything-match-plugin."
8522 (interactive)
8523 (let ((anything-match-plugin-enabled
8524 (member 'anything-compile-source--match-plugin
8525 anything-compile-source-functions)))
8526 (flet ((disable-match-plugin ()
8527 (setq anything-compile-source-functions
8528 (delq 'anything-compile-source--match-plugin
8529 anything-compile-source-functions))
8530 (setq anything-mp-initial-highlight-delay
8531 anything-mp-highlight-delay)
8532 (setq anything-mp-highlight-delay nil))
8533 (enable-match-plugin ()
8534 (require 'anything-match-plugin)
8535 (unless anything-mp-initial-highlight-delay
8536 (setq anything-mp-initial-highlight-delay
8537 anything-mp-highlight-delay))
8538 (setq anything-compile-source-functions
8539 (cons 'anything-compile-source--match-plugin
8540 anything-compile-source-functions))
8541 (unless anything-mp-highlight-delay
8542 (setq anything-mp-highlight-delay
8543 anything-mp-initial-highlight-delay))))
8544 (if anything-match-plugin-enabled
8545 (when (y-or-n-p "Really disable match-plugin? ")
8546 (disable-match-plugin)
8547 (message "Anything-match-plugin disabled"))
8548 (when (y-or-n-p "Really enable match-plugin? ")
8549 (enable-match-plugin)
8550 (message "Anything-match-plugin enabled"))))))
8553 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8555 ;;;; Type Attributes
8556 (define-anything-type-attribute 'buffer
8557 `((action
8558 ,@(if pop-up-frames
8559 `(("Switch to buffer other window" . switch-to-buffer-other-window)
8560 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
8561 ("Switch to buffer" . switch-to-buffer))
8562 `(("Switch to buffer" . switch-to-buffer)
8563 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
8564 ("Switch to buffer other window" . switch-to-buffer-other-window)
8565 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
8566 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
8567 ("View buffer" . view-buffer)
8568 ("Display buffer" . display-buffer)
8569 ("Revert buffer" . anything-revert-buffer)
8570 ("Revert Marked buffers" . anything-revert-marked-buffers)
8571 ("Insert buffer" . insert-buffer)
8572 ("Kill buffer" . kill-buffer)
8573 ("Kill Marked buffers" . anything-kill-marked-buffers)
8574 ("Diff with file" . diff-buffer-with-file)
8575 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
8576 ("Ediff Merge marked buffers" . (lambda (candidate)
8577 (anything-ediff-marked-buffers candidate t))))
8578 (persistent-help . "Show this buffer")
8579 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
8580 "Buffer or buffer name.")
8582 (define-anything-type-attribute 'file
8583 `((action
8584 ,@(if pop-up-frames
8585 `(("Find file other window" . find-file-other-window)
8586 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
8587 ("Find file(s)" . anything-find-many-files)
8588 ("Find file as root" . anything-find-file-as-root))
8589 `(("Find file" . anything-find-many-files)
8590 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
8591 ("Find file as root" . anything-find-file-as-root)
8592 ("Find file other window" . find-file-other-window)
8593 ("Find file other frame" . find-file-other-frame)))
8594 ("Open dired in file's directory" . anything-c-open-dired)
8595 ("Grep File(s) `C-u recurse'"
8596 . (lambda (candidate)
8597 (if anything-current-prefix-arg
8598 (anything-do-grep1 (anything-marked-candidates) 'recurse)
8599 (anything-do-grep1 (anything-marked-candidates)))))
8600 ("View file" . view-file)
8601 ("Insert file" . insert-file)
8602 ("Delete file(s)" . anything-delete-marked-files)
8603 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
8604 ("Open file with default tool" . anything-c-open-file-with-default-tool)
8605 ("Find file in hex dump" . hexl-find-file))
8606 (persistent-help . "Show this file")
8607 (action-transformer anything-c-transform-file-load-el
8608 anything-c-transform-file-browse-url)
8609 (candidate-transformer anything-c-w32-pathname-transformer
8610 anything-c-skip-current-file
8611 anything-c-skip-boring-files
8612 anything-c-shorten-home-path))
8613 "File name.")
8615 (let ((actions '(("Describe command" . describe-function)
8616 ("Add command to kill ring" . anything-c-kill-new)
8617 ("Go to command's definition" . find-function)
8618 ("Debug on entry" . debug-on-entry)
8619 ("Cancel debug on entry" . cancel-debug-on-entry)
8620 ("Trace function" . trace-function)
8621 ("Trace function (background)" . trace-function-background)
8622 ("Untrace function" . untrace-function))))
8623 (define-anything-type-attribute 'command
8624 `((action ("Call interactively" . anything-c-call-interactively)
8625 ,@actions)
8626 ;; Sort commands according to their usage count.
8627 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
8628 (coerce . anything-c-symbolify)
8629 (persistent-action . describe-function))
8630 "Command. (string or symbol)")
8632 (define-anything-type-attribute 'function
8633 `((action . ,actions)
8634 (action-transformer anything-c-transform-function-call-interactively)
8635 (candidate-transformer anything-c-mark-interactive-functions)
8636 (coerce . anything-c-symbolify))
8637 "Function. (string or symbol)"))
8639 (define-anything-type-attribute 'variable
8640 '((action ("Describe variable" . describe-variable)
8641 ("Add variable to kill ring" . anything-c-kill-new)
8642 ("Go to variable's definition" . find-variable)
8643 ("Set variable" . anything-c-set-variable))
8644 (coerce . anything-c-symbolify))
8645 "Variable.")
8647 (define-anything-type-attribute 'sexp
8648 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
8649 ("Add s-expression to kill ring" . kill-new))
8650 (action-transformer anything-c-transform-sexp-eval-command-sexp))
8651 "String representing S-Expressions.")
8653 (define-anything-type-attribute 'bookmark
8654 `((coerce . anything-bookmark-get-bookmark-from-name)
8655 (action
8656 ("Jump to bookmark" . (lambda (bookmark)
8657 (let ((current-prefix-arg anything-current-prefix-arg))
8658 (bookmark-jump bookmark))
8659 (anything-update)))
8660 ("Jump to BM other window" . (lambda (bookmark)
8661 (bookmark-jump-other-window bookmark)
8662 (anything-update)))
8663 ("Bookmark edit annotation" . bookmark-edit-annotation)
8664 ("Bookmark show annotation" . bookmark-show-annotation)
8665 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
8666 ,@(when (fboundp 'bmkext-edit-bookmark)
8667 '(("Edit Bookmark" . bmkext-edit-bookmark)))
8668 ("Rename bookmark" . bookmark-rename)
8669 ("Relocate bookmark" . bookmark-relocate)))
8670 "Bookmark name.")
8672 (define-anything-type-attribute 'line
8673 '((display-to-real . anything-c-display-to-real-line)
8674 (action ("Go to Line" . anything-c-action-line-goto)))
8675 "LINENO:CONTENT string, eg. \" 16:foo\".
8677 Optional `target-file' attribute is a name of target file.
8679 Optional `before-jump-hook' attribute is a function with no
8680 arguments which is called before jumping to position.
8682 Optional `after-jump-hook' attribute is a function with no
8683 arguments which is called after jumping to position.
8685 If `adjust' attribute is specified, searches the line whose
8686 content is CONTENT near the LINENO.
8688 If `recenter' attribute is specified, the line is displayed at
8689 the center of window, otherwise at the top of window.
8692 (define-anything-type-attribute 'file-line
8693 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
8694 (multiline)
8695 (action ("Go to" . anything-c-action-file-line-goto)))
8696 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
8698 Optional `default-directory' attribute is a default-directory
8699 FILENAME is interpreted.
8701 Optional `before-jump-hook' attribute is a function with no
8702 arguments which is called before jumping to position.
8704 Optional `after-jump-hook' attribute is a function with no
8705 arguments which is called after jumping to position.
8707 If `adjust' attribute is specified, searches the line whose
8708 content is CONTENT near the LINENO.
8710 If `recenter' attribute is specified, the line is displayed at
8711 the center of window, otherwise at the top of window.
8714 (define-anything-type-attribute 'timer
8715 '((real-to-display . anything-c-timer-real-to-display)
8716 (action ("Cancel Timer" . cancel-timer)
8717 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
8718 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
8719 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
8720 (persistent-help . "Describe Function"))
8721 "Timer.")
8723 ;;;; Default `anything-sources'
8724 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
8725 ;; tend to invoke M-x anything directly. So I offer default setting.
8726 (setq anything-sources
8727 '(anything-c-source-buffers+
8728 anything-c-source-recentf
8729 anything-c-source-files-in-current-dir+))
8731 ;;;; unit test
8732 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
8733 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
8734 (dont-compile
8735 (when (fboundp 'expectations)
8736 (expectations
8737 (desc "candidates-file plug-in")
8738 (expect '(anything-p-candidats-file-init)
8739 (assoc-default 'init
8740 (car (anything-compile-sources
8741 '(((name . "test")
8742 (candidates-file . "test.txt")))
8743 '(anything-compile-source--candidates-file)))))
8744 (expect '(anything-p-candidats-file-init
8745 (lambda () 1))
8746 (assoc-default 'init
8747 (car (anything-compile-sources
8748 '(((name . "test")
8749 (candidates-file . "test.txt")
8750 (init . (lambda () 1))))
8751 '(anything-compile-source--candidates-file)))))
8752 (expect '(anything-p-candidats-file-init
8753 (lambda () 1))
8754 (assoc-default 'init
8755 (car (anything-compile-sources
8756 '(((name . "test")
8757 (candidates-file . "test.txt")
8758 (init (lambda () 1))))
8759 '(anything-compile-source--candidates-file)))))
8760 ;; FIXME error
8761 ;; (desc "anything-c-source-buffers")
8762 ;; (expect '(("Buffers" ("foo" "curbuf")))
8763 ;; (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
8764 ;; (let ((anything-c-boring-buffer-regexp
8765 ;; (rx (or
8766 ;; (group bos " ")
8767 ;; "*anything"
8768 ;; ;; echo area
8769 ;; " *Echo Area" " *Minibuf"))))
8770 ;; (flet ((buffer-name (&optional x) x))
8771 ;; (anything-test-candidates 'anything-c-source-buffers))))
8772 (desc "anything-c-stringify")
8773 (expect "str1"
8774 (anything-c-stringify "str1"))
8775 (expect "str2"
8776 (anything-c-stringify 'str2))
8777 (desc "anything-c-symbolify")
8778 (expect 'sym1
8779 (anything-c-symbolify "sym1"))
8780 (expect 'sym2
8781 (anything-c-symbolify 'sym2))
8782 (desc "plug-in:default-action")
8783 (expect '(((action ("default" . default) ("original" . original))
8784 (default-action . ("default" . default))
8785 (action ("original" . original))))
8786 (anything-compile-sources
8787 '(((default-action . ("default" . default))
8788 (action ("original" . original))))
8789 '(anything-compile-source--default-action)))
8790 (expect '(((action ("a1" . a1) ("a2" . a2))
8791 (default-action . ("a1" . a1))
8792 (action ("a1" . a1) ("a2" . a2))))
8793 (anything-compile-sources
8794 '(((default-action . ("a1" . a1))
8795 (action ("a1" . a1) ("a2" . a2))))
8796 '(anything-compile-source--default-action)))
8797 (expect '(((action ("a2" . a2) ("a1" . a1))
8798 (default-action . ("a2" . a2))
8799 (action ("a1" . a1) ("a2" . a2))))
8800 (anything-compile-sources
8801 '(((default-action . ("a2" . a2))
8802 (action ("a1" . a1) ("a2" . a2))))
8803 '(anything-compile-source--default-action))))))
8805 (provide 'anything-config)
8807 ;;; Local Variables:
8808 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
8809 ;;; End:
8811 ;; How to save (DO NOT REMOVE!!)
8812 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
8813 ;;; anything-config.el ends here
8815 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
8816 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
8817 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
8818 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
8819 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
8820 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
8821 ;;; LocalWords: dotimes Thierry online vname
8822 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
8823 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
8824 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
8825 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
8826 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
8827 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
8828 ;;; LocalWords: startpos noselect dont desc