1 ;;; anything-config.el --- Predefined configurations for `anything.el'
3 ;; Filename: anything-config.el
5 ;; Description: Predefined configurations for `anything.el'
6 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
7 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
8 ;; rubikitch <rubikitch@ruby-lang.org>
9 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
10 ;; Copyright (C) 2007 ~ 2010, Tassilo Horn, all rights reserved.
11 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
12 ;; Copyright (C) 2009 ~ 2010, rubikitch, all rights reserved.
13 ;; Copyright (C) 2009 ~ 2010, Thierry Volpiatto, all rights reserved.
14 ;; Created: 2009-02-16 21:38:23
16 ;; URL: http://www.emacswiki.org/emacs/download/anything-config.el
17 ;; Keywords: anything, anything-config
18 ;; Compatibility: GNU Emacs 22 ~ 23
20 ;; Features that might be required by this library:
25 ;;; This file is NOT part of GNU Emacs
29 ;; This program is free software; you can redistribute it and/or modify
30 ;; it under the terms of the GNU General Public License as published by
31 ;; the Free Software Foundation; either version 3, or (at your option)
34 ;; This program is distributed in the hope that it will be useful,
35 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 ;; GNU General Public License for more details.
39 ;; You should have received a copy of the GNU General Public License
40 ;; along with this program; see the file COPYING. If not, write to
41 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
42 ;; Floor, Boston, MA 02110-1301, USA.
46 ;; If this file does not work, upgrade anything.el!
47 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
51 ;; Predefined configurations for `anything.el'
53 ;; For quick start, try `anything-for-files' to open files.
55 ;; To configure anything you should define anything command
56 ;; with your favorite sources, like below:
58 ;; (defun my-anything ()
60 ;; (anything-other-buffer
61 ;; '(anything-c-source-buffers
62 ;; anything-c-source-file-name-history
63 ;; anything-c-source-info-pages
64 ;; anything-c-source-info-elisp
65 ;; anything-c-source-man-pages
66 ;; anything-c-source-locate
67 ;; anything-c-source-emacs-commands)
70 ;; Then type M-x my-anything to use sources.
72 ;; Defining own command is better than setup `anything-sources'
73 ;; directly, because you can define multiple anything commands with
74 ;; different sources. Each anything command should have own anything
75 ;; buffer, because M-x anything-resume revives anything command.
77 ;;; Autodoc documentation:
78 ;; ---------------------
80 ;; * Commands defined here are:
81 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
82 ;; `anything-configuration'
83 ;; Customize `anything'.
84 ;; `anything-c-describe-anything-bindings'
85 ;; [OBSOLETE] Describe `anything' bindings.
87 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
88 ;; `anything-for-files'
89 ;; Preconfigured `anything' for opening files.
91 ;; Preconfigured `anything' for `recentf'.
92 ;; `anything-info-at-point'
93 ;; Preconfigured `anything' for searching info at point.
94 ;; `anything-info-emacs'
95 ;; Preconfigured anything for Emacs manual index.
96 ;; `anything-show-kill-ring'
97 ;; Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
98 ;; `anything-minibuffer-history'
99 ;; Preconfigured `anything' for `minibuffer-history'.
101 ;; Preconfigured `anything' for gentoo linux.
103 ;; Preconfigured `anything' for `imenu'.
104 ;; `anything-google-suggest'
105 ;; Preconfigured `anything' for google search with google suggest.
106 ;; `anything-yahoo-suggest'
107 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
108 ;; `anything-for-buffers'
109 ;; Preconfigured `anything' for buffer.
110 ;; `anything-buffers+'
111 ;; Enhanced preconfigured `anything' for buffer.
113 ;; Preconfigured `anything' for BBDB.
115 ;; Preconfigured `anything' for Locate.
116 ;; `anything-w3m-bookmarks'
117 ;; Preconfigured `anything' for w3m bookmark.
118 ;; `anything-firefox-bookmarks'
119 ;; Preconfigured `anything' for firefox bookmark.
121 ;; Preconfigured `anything' for color.
122 ;; `anything-bookmarks'
123 ;; Preconfigured `anything' for bookmarks.
124 ;; `anything-c-pp-bookmarks'
125 ;; Preconfigured `anything' for bookmarks (pretty-printed).
126 ;; `anything-register'
127 ;; Preconfigured `anything' for Emacs registers.
128 ;; `anything-bm-list'
129 ;; Preconfigured `anything' for visible bookmarks.
131 ;; Preconfigured `anything' for timers.
132 ;; `anything-kill-buffers'
133 ;; Preconfigured `anything' to kill buffer you selected.
135 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
136 ;; `anything-insert-buffer-name'
137 ;; Insert buffer name.
138 ;; `anything-insert-symbol'
139 ;; Insert current symbol.
140 ;; `anything-insert-selection'
141 ;; Insert current selection.
142 ;; `anything-show-buffer-only'
143 ;; [OBSOLETE] Only show sources about buffer.
144 ;; `anything-show-bbdb-only'
145 ;; [OBSOLETE] Only show sources about BBDB.
146 ;; `anything-show-locate-only'
147 ;; [OBSOLETE] Only show sources about Locate.
148 ;; `anything-show-info-only'
149 ;; [OBSOLETE] Only show sources about Info.
150 ;; `anything-show-imenu-only'
151 ;; [OBSOLETE] Only show sources about Imenu.
152 ;; `anything-show-files-only'
153 ;; [OBSOLETE] Only show sources about File.
154 ;; `anything-show-w3m-bookmarks-only'
155 ;; [OBSOLETE] Only show source about w3m bookmark.
156 ;; `anything-show-colors-only'
157 ;; [OBSOLETE] Only show source about color.
158 ;; `anything-show-kill-ring-only'
159 ;; [OBSOLETE] Only show source about kill ring.
160 ;; `anything-show-this-source-only'
161 ;; Only show this source.
162 ;; `anything-test-sources'
163 ;; List all anything sources for test.
164 ;; `anything-select-source'
166 ;; `anything-find-files-down-one-level'
167 ;; Go down one level like unix command `cd ..'.
168 ;; `anything-find-files'
169 ;; Preconfigured `anything' for anything implementation of `find-file'.
170 ;; `anything-write-file'
171 ;; Preconfigured `anything' providing completion for `write-file'.
172 ;; `anything-insert-file'
173 ;; Preconfigured `anything' providing completion for `insert-file'.
174 ;; `anything-dired-rename-file'
175 ;; Preconfigured `anything' to rename files from dired.
176 ;; `anything-dired-copy-file'
177 ;; Preconfigured `anything' to copy files from dired.
178 ;; `anything-dired-symlink-file'
179 ;; Preconfigured `anything' to symlink files from dired.
180 ;; `anything-dired-hardlink-file'
181 ;; Preconfigured `anything' to hardlink files from dired.
182 ;; `anything-dired-bindings'
183 ;; Replace usual dired commands `C' and `R' by anything ones.
185 ;; Preconfigured `anything' for Emacs commands.
186 ;; `anything-manage-advice'
187 ;; Preconfigured `anything' to disable/enable function advices.
188 ;; `anything-bookmark-ext'
189 ;; Preconfigured `anything' for bookmark-extensions sources.
190 ;; `anything-simple-call-tree'
191 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
192 ;; `anything-mark-ring'
193 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
194 ;; `anything-global-mark-ring'
195 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
196 ;; `anything-all-mark-rings'
197 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
198 ;; `anything-yaoddmuse-cache-pages'
199 ;; Fetch the list of files on emacswiki and create cache file.
200 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
201 ;; Preconfigured `anything' to edit or view EmacsWiki page.
202 ;; `anything-yaoddmuse-emacswiki-post-library'
203 ;; Preconfigured `anything' to post library to EmacsWiki.
204 ;; `anything-eval-expression'
205 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
206 ;; `anything-eval-expression-with-eldoc'
207 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
208 ;; `anything-surfraw'
209 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
210 ;; `anything-emms-stream-edit-bookmark'
211 ;; Change the information of current emms-stream bookmark from anything.
212 ;; `anything-emms-stream-delete-bookmark'
213 ;; Delete an emms-stream bookmark from anything.
214 ;; `anything-call-source'
215 ;; Preconfigured `anything' to call anything source.
216 ;; `anything-call-source-from-anything'
217 ;; Call anything source within `anything' session.
218 ;; `anything-execute-anything-command'
219 ;; Preconfigured `anything' to execute preconfigured `anything'.
221 ;; Preconfigured Anything for Occur source.
222 ;; `anything-create-from-anything'
223 ;; Run `anything-create' from `anything' as a fallback.
225 ;; Preconfigured `anything' to do many create actions from STRING.
227 ;; Preconfigured `anything' for top command.
228 ;; `anything-select-xfont'
229 ;; Preconfigured `anything' to select Xfont.
231 ;; Preconfigured `anything' : frontend of APT package manager.
232 ;; `anything-c-shell-command-if-needed'
234 ;; `anything-c-run-external-command'
235 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
236 ;; `anything-ratpoison-commands'
237 ;; Preconfigured `anything' to execute ratpoison commands.
238 ;; `anything-c-set-variable'
239 ;; Set value to VAR interactively.
240 ;; `anything-c-adaptive-save-history'
241 ;; Save history information to file given by `anything-c-adaptive-history-file'.
243 ;; * User variables defined here:
244 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
245 ;; `anything-c-use-standard-keys'
246 ;; Default Value: nil
247 ;; `anything-c-adaptive-history-file'
248 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
249 ;; `anything-c-adaptive-history-length'
251 ;; `anything-c-google-suggest-url'
252 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
253 ;; `anything-c-google-suggest-search-url'
254 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
255 ;; `anything-google-suggest-use-curl-p'
256 ;; Default Value: nil
257 ;; `anything-c-yahoo-suggest-url'
258 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
259 ;; `anything-c-yahoo-suggest-search-url'
260 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
261 ;; `anything-c-boring-buffer-regexp'
262 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
263 ;; `anything-c-boring-file-regexp'
264 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
265 ;; `anything-kill-ring-threshold'
267 ;; `anything-su-or-sudo'
268 ;; Default Value: "su"
269 ;; `anything-for-files-prefered-list'
270 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
271 ;; `anything-create--actions-private'
272 ;; Default Value: nil
273 ;; `anything-allow-skipping-current-buffer'
275 ;; `anything-c-enable-eval-defun-hack'
277 ;; `anything-tramp-verbose'
279 ;; `anything-raise-command'
280 ;; Default Value: nil
281 ;; `anything-command-map-prefix-key'
282 ;; Default Value: "<f5> a"
284 ;; * Anything sources defined here:
285 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
286 ;; `anything-c-source-regexp' (Regexp Builder)
287 ;; `anything-c-source-buffers' (Buffers)
288 ;; `anything-c-source-buffer-not-found' (Create buffer)
289 ;; `anything-c-source-buffers+' (Buffers)
290 ;; `anything-c-source-file-name-history' (File Name History)
291 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
292 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
293 ;; `anything-c-source-find-files' (Find Files (`C-.':Go to precedent level))
294 ;; `anything-c-source-write-file' (Write File (`C-.':Go to precedent level))
295 ;; `anything-c-source-insert-file' (Insert File (`C-.':Go to precedent level))
296 ;; `anything-c-source-copy-files' (Copy Files (`C-.':Go to precedent level))
297 ;; `anything-c-source-symlink-files' (Symlink Files (`C-.':Go to precedent level))
298 ;; `anything-c-source-hardlink-files' (Hardlink Files (`C-.':Go to precedent level))
299 ;; `anything-c-source-file-cache-initialized' ()
300 ;; `anything-c-source-file-cache' (File Cache)
301 ;; `anything-c-source-locate' (Locate)
302 ;; `anything-c-source-recentf' (Recentf)
303 ;; `anything-c-source-ffap-guesser' (File at point)
304 ;; `anything-c-source-ffap-line' (File/Lineno at point)
305 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
306 ;; `anything-c-source-info-pages' (Info Pages)
307 ;; `anything-c-source-info-elisp' (Info index: elisp)
308 ;; `anything-c-source-info-cl' (Info index: cl)
309 ;; `anything-c-source-info-org' (Info index: org)
310 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
311 ;; `anything-c-source-info-zsh' (Info index: zsh)
312 ;; `anything-c-source-info-bash' (Info index: bash)
313 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
314 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
315 ;; `anything-c-source-info-find' (Info index: find)
316 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
317 ;; `anything-c-source-info-textutils' (Info index: textutils)
318 ;; `anything-c-source-info-libc' (Info index: libc)
319 ;; `anything-c-source-info-make' (Info index: make)
320 ;; `anything-c-source-info-automake' (Info index: automake)
321 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
322 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
323 ;; `anything-c-source-info-emacs' (Info index: emacs)
324 ;; `anything-c-source-info-elib' (Info index: elib)
325 ;; `anything-c-source-info-eieio' (Info index: eieio)
326 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
327 ;; `anything-c-source-info-guile' (Info index: guile)
328 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
329 ;; `anything-c-source-info-goops' (Info index: goops)
330 ;; `anything-c-source-info-screen' (Info index: screen)
331 ;; `anything-c-source-info-latex' (Info index: latex)
332 ;; `anything-c-source-info-gawk' (Info index: gawk)
333 ;; `anything-c-source-info-sed' (Info index: sed)
334 ;; `anything-c-source-info-m4' (Info index: m4)
335 ;; `anything-c-source-info-wget' (Info index: wget)
336 ;; `anything-c-source-info-binutils' (Info index: binutils)
337 ;; `anything-c-source-info-as' (Info index: as)
338 ;; `anything-c-source-info-bfd' (Info index: bfd)
339 ;; `anything-c-source-info-gprof' (Info index: gprof)
340 ;; `anything-c-source-info-ld' (Info index: ld)
341 ;; `anything-c-source-info-diff' (Info index: diff)
342 ;; `anything-c-source-info-flex' (Info index: flex)
343 ;; `anything-c-source-info-grep' (Info index: grep)
344 ;; `anything-c-source-info-gzip' (Info index: gzip)
345 ;; `anything-c-source-info-libtool' (Info index: libtool)
346 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
347 ;; `anything-c-source-info-info' (Info index: info)
348 ;; `anything-c-source-info-gdb' (Info index: gdb)
349 ;; `anything-c-source-info-stabs' (Info index: stabs)
350 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
351 ;; `anything-c-source-info-cvs' (Info index: cvs)
352 ;; `anything-c-source-info-bison' (Info index: bison)
353 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
354 ;; `anything-c-source-info-global' (Info index: global)
355 ;; `anything-c-source-man-pages' (Manual Pages)
356 ;; `anything-c-source-complex-command-history' (Complex Command History)
357 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
358 ;; `anything-c-source-emacs-commands' (Emacs Commands)
359 ;; `anything-c-source-lacarte' (Lacarte)
360 ;; `anything-c-source-emacs-functions' (Emacs Functions)
361 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
362 ;; `anything-c-source-advice' (Function Advice)
363 ;; `anything-c-source-emacs-variables' (Emacs Variables)
364 ;; `anything-c-source-bookmarks' (Bookmarks)
365 ;; `anything-c-source-bookmark-set' (Set Bookmark)
366 ;; `anything-c-source-bm' (Visible Bookmarks)
367 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
368 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
369 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
370 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
371 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
372 ;; `anything-c-source-bookmark-images' (Bookmark Images)
373 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
374 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
375 ;; `anything-c-source-bookmark-info' (Bookmark Info)
376 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
377 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
378 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
379 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
380 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
381 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
382 ;; `anything-c-source-imenu' (Imenu)
383 ;; `anything-c-source-ctags' (Exuberant ctags)
384 ;; `anything-c-source-semantic' (Semantic Tags)
385 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
386 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
387 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
388 ;; `anything-c-source-customize-face' (Customize Face)
389 ;; `anything-c-source-colors' (Colors)
390 ;; `anything-c-source-tracker-search' (Tracker Search)
391 ;; `anything-c-source-mac-spotlight' (mdfind)
392 ;; `anything-c-source-kill-ring' (Kill Ring)
393 ;; `anything-c-source-mark-ring' (mark-ring)
394 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
395 ;; `anything-c-source-register' (Registers)
396 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
397 ;; `anything-c-source-rd-headline' (RD HeadLine)
398 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
399 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
400 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
401 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
402 ;; `anything-c-source-org-headline' (Org HeadLine)
403 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
404 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
405 ;; `anything-c-source-eev-anchor' (Anchors)
406 ;; `anything-c-source-org-keywords' (Org Keywords)
407 ;; `anything-c-source-picklist' (Picklist)
408 ;; `anything-c-source-bbdb' (BBDB)
409 ;; `anything-c-source-evaluation-result' (Evaluation Result)
410 ;; `anything-c-source-calculation-result' (Calculation Result)
411 ;; `anything-c-source-google-suggest' (Google Suggest)
412 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
413 ;; `anything-c-source-emms-streams' (Emms Streams)
414 ;; `anything-c-source-emms-dired' (Music Directory)
415 ;; `anything-c-source-emms-files' (Emms files)
416 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
417 ;; `anything-c-source-call-source' (Call anything source)
418 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
419 ;; `anything-c-source-occur' (Occur)
420 ;; `anything-c-source-create' (Create)
421 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
422 ;; `anything-c-source-elscreen' (Elscreen)
423 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
424 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
425 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
426 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
427 ;; `anything-c-source-xfonts' (X Fonts)
428 ;; `anything-c-source-apt' (APT)
429 ;; `anything-c-source-gentoo' (Portage sources)
430 ;; `anything-c-source-use-flags' (Use Flags)
431 ;; `anything-c-source-emacs-process' (Emacs Process)
432 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
434 ;; *** END auto-documentation
439 ;; Change log of this file is found at
440 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
442 ;; Change log of this project is found at
443 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
448 ;; Tassilo Horn <tassilo@member.fsf.org>
449 ;; Vagn Johansen <gonz808@hotmail.com>
450 ;; Mathias Dahl <mathias.dahl@gmail.com>
451 ;; Bill Clementson <billclem@gmail.com>
452 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
453 ;; Drew Adams <drew.adams@oracle.com>
454 ;; Jason McBrayer <jmcbray@carcosa.net>
455 ;; Andy Stewart <lazycat.manatee@gmail.com>
456 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
457 ;; rubikitch <rubikitch@ruby-lang.org>
458 ;; Scott Vokes <vokes.s@gmail.com>
463 ;; Evaluate (autodoc-update-all) before commit. This function
464 ;; generates anything-c-source-* / functions / options list.
466 ;; Install also developer-tools/autodoc.el
467 ;; And eval it or run interactively.
469 ;; [EVAL IT] (autodoc-update-all)
471 ;; Please write details documentation about function, then others will
472 ;; read code more easier. -- Andy Stewart
478 ;; - Fix documentation, now many functions haven't documentations.
490 (let ((version "1.263"))
491 (when (and (string= "1." (substring version
0 2))
492 (string-match "1\.\\([0-9]+\\)" anything-version
)
493 (< (string-to-number (match-string 1 anything-version
))
494 (string-to-number (substring version
2))))
495 (error "Please update anything.el!!
497 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
499 or M-x install-elisp-from-emacswiki anything.el")))
501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
502 (defgroup anything-config nil
503 "Predefined configurations for `anything.el'."
506 (defcustom anything-c-use-standard-keys nil
507 "Whether use standard keybindings. (no effect)
509 Key definitions in anything-config.el are removed because
510 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
511 minibuffer history, C-s for isearch, etc.
513 If you use `iswitchb' with `anything',
514 evaluate (anything-iswitchb-setup) . Then some bindings that
515 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
516 history, are removed from `anything-map'. "
518 :group
'anything-config
)
520 (defcustom anything-c-adaptive-history-file
"~/.emacs.d/anything-c-adaptive-history"
521 "Path of file where history information is stored."
523 :group
'anything-config
)
525 (defcustom anything-c-adaptive-history-length
50
526 "Maximum number of candidates stored for a source."
528 :group
'anything-config
)
530 (defcustom anything-c-google-suggest-url
531 "http://google.com/complete/search?output=toolbar&q="
532 "URL used for looking up Google suggestions."
534 :group
'anything-config
)
536 (defcustom anything-c-google-suggest-search-url
537 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
538 "URL used for Google searching."
540 :group
'anything-config
)
542 (defcustom anything-google-suggest-use-curl-p nil
543 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
544 Otherwise `url-retrieve-synchronously' is used."
546 :group
'anything-config
)
548 (defcustom anything-c-yahoo-suggest-url
549 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
550 "Url used for looking up Yahoo suggestions."
552 :group
'anything-config
)
554 (defcustom anything-c-yahoo-suggest-search-url
555 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
556 "Url used for Yahoo searching."
558 :group
'anything-config
)
560 (defcustom anything-c-boring-buffer-regexp
566 " *Echo Area" " *Minibuf"))
567 "The regexp that match boring buffers.
568 Buffer candidates matching this regular expression will be
569 filtered from the list of candidates if the
570 `anything-c-skip-boring-buffers' candidate transformer is used, or
571 they will be displayed with face `file-name-shadow' if
572 `anything-c-shadow-boring-buffers' is used."
574 :group
'anything-config
)
575 ;; (string-match anything-c-boring-buffer-regexp "buf")
576 ;; (string-match anything-c-boring-buffer-regexp " hidden")
577 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
579 (defcustom anything-c-boring-file-regexp
581 ;; Boring directories
582 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol
))
584 (and line-start
".#")
585 (and (or ".class" ".la" ".o" "~") eol
)))
586 "The regexp that match boring files.
587 File candidates matching this regular expression will be
588 filtered from the list of candidates if the
589 `anything-c-skip-boring-files' candidate transformer is used, or
590 they will be displayed with face `file-name-shadow' if
591 `anything-c-shadow-boring-files' is used."
593 :group
'anything-config
)
595 (defcustom anything-kill-ring-threshold
10
596 "*Minimum length to be listed by `anything-c-source-kill-ring'."
598 :group
'anything-config
)
600 (defcustom anything-su-or-sudo
"su"
601 "What command to use for root access."
603 :group
'anything-config
)
605 (defcustom anything-for-files-prefered-list
606 '(anything-c-source-ffap-line
607 anything-c-source-ffap-guesser
608 anything-c-source-buffers
+
609 anything-c-source-recentf
610 anything-c-source-bookmarks
611 anything-c-source-file-cache
612 anything-c-source-files-in-current-dir
+
613 anything-c-source-locate
)
614 "Your prefered sources to find files."
616 :group
'anything-config
)
618 (defcustom anything-create--actions-private nil
619 "User defined actions for `anything-create' / `anything-c-source-create'.
620 It is a list of (DISPLAY . FUNCTION) pairs like `action'
621 attribute of `anything-sources'.
623 It is prepended to predefined pairs."
625 :group
'anything-config
)
627 (defcustom anything-allow-skipping-current-buffer t
628 "Show current buffer or not in anything buffer"
630 :group
'anything-config
)
632 (defcustom anything-c-enable-eval-defun-hack t
633 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
634 This hack is invoked when pressing C-M-x in the form \
635 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
637 :group
'anything-config
)
639 (defcustom anything-tramp-verbose
0
640 "*Just like `tramp-verbose' but specific to anything.
641 When set to 0 don't show tramp messages in anything.
642 If you want to have the default tramp messages set it to 3."
644 :group
'anything-config
)
646 (defcustom anything-raise-command nil
647 "*A shell command to jump to a window running specific program.
648 Stumpwm users could use:
649 \"stumpish eval \"\(stumpwm::%s\)\"\".
650 With others windows manager you could use:
652 Though wmctrl work also with stumpwm."
654 :group
'anything-config
)
656 (defun anything-set-anything-command-map-prefix-key (var key
)
657 (when (boundp 'anything-command-map-prefix-key
)
658 (global-unset-key (read-kbd-macro anything-command-map-prefix-key
)))
659 (setq anything-command-map-prefix-key key
)
660 (global-set-key (read-kbd-macro anything-command-map-prefix-key
)
661 'anything-command-map
))
663 (defcustom anything-command-map-prefix-key
"<f5> a"
664 "*The prefix key for all `anything-command-map' commands.
667 This default value is very likely to be changed,
668 because it is under discussion."
670 :set
'anything-set-anything-command-map-prefix-key
671 :group
'anything-config
)
674 (defun anything-configuration ()
675 "Customize `anything'."
677 (customize-group "anything-config"))
679 ;;; Anything-command-map
681 (defvar anything-command-map
)
682 (define-prefix-command 'anything-command-map
)
684 ;; rubikitch: Please change it freely because it is in discussion. I'll track from git.
685 (define-key anything-command-map
(kbd "<SPC>") 'anything-execute-anything-command
)
686 (define-key anything-command-map
(kbd "e") 'anything-etags-maybe-at-point
)
687 (define-key anything-command-map
(kbd "l") 'anything-locate
)
688 (define-key anything-command-map
(kbd "s") 'anything-surfraw
)
689 (define-key anything-command-map
(kbd "r") 'anything-regexp
)
690 (define-key anything-command-map
(kbd "w") 'anything-w3m-bookmarks
)
691 (define-key anything-command-map
(kbd "x") 'anything-firefox-bookmarks
)
692 (define-key anything-command-map
(kbd "#") 'anything-emms
)
693 (define-key anything-command-map
(kbd "m") 'anything-man-woman
)
694 (define-key anything-command-map
(kbd "t") 'anything-top
)
695 (define-key anything-command-map
(kbd "i") 'anything-imenu
)
696 (define-key anything-command-map
(kbd "C-x r b") 'anything-c-pp-bookmarks
)
697 (define-key anything-command-map
(kbd "M-y") 'anything-show-kill-ring
)
698 (define-key anything-command-map
(kbd "C-c <SPC>") 'anything-all-mark-rings
)
699 (define-key anything-command-map
(kbd "C-x C-f") 'anything-find-files
)
700 (define-key anything-command-map
(kbd "f") 'anything-for-files
)
701 (define-key anything-command-map
(kbd "C-:") 'anything-eval-expression-with-eldoc
)
702 (define-key anything-command-map
(kbd "C-,") 'anything-calcul-expression
)
703 (define-key anything-command-map
(kbd "M-x") 'anything-M-x
)
704 (define-key anything-command-map
(kbd "C-x C-w") 'anything-write-file
)
705 (define-key anything-command-map
(kbd "C-x i") 'anything-insert-file
)
706 (define-key anything-command-map
(kbd "M-s o") 'anything-occur
)
707 (define-key anything-command-map
(kbd "c") 'anything-colors
)
708 (define-key anything-command-map
(kbd "F") 'anything-select-xfont
)
709 (define-key anything-command-map
(kbd "C-c f") 'anything-recentf
)
710 (define-key anything-command-map
(kbd "C-c g") 'anything-google-suggest
)
711 (define-key anything-command-map
(kbd "h i") 'anything-info-at-point
)
712 (define-key anything-command-map
(kbd "h r") 'anything-info-emacs
)
713 (define-key anything-command-map
(kbd "C-x C-b") 'anything-buffers
+)
714 (define-key anything-command-map
(kbd "C-x r i") 'anything-register
)
715 (define-key anything-command-map
(kbd "C-c C-x") 'anything-c-run-external-command
)
718 (easy-menu-define nil global-map
721 ["All anything commands" anything-execute-anything-command t
]
722 ["Find any Files/Buffers" anything-for-files t
]
725 ["Find files" anything-find-files t
]
726 ["Recent Files" anything-recentf t
]
727 ["Locate" anything-locate t
]
728 ["Bookmarks" anything-c-pp-bookmarks t
])
730 ["Find buffers" anything-buffers
+ t
])
732 ["Emacs Commands" anything-M-x t
]
733 ["Externals Commands" anything-c-run-external-command t
])
735 ["Info at point" anything-info-at-point t
]
736 ["Emacs Manual index" anything-info-emacs t
])
738 ["Occur" anything-occur t
]
739 ["Browse Kill ring" anything-show-kill-ring t
]
740 ["Browse register" anything-register t
]
741 ["Mark Ring" anything-all-mark-rings t
]
742 ["Regexp handler" anything-regexp t
]
743 ["Colors & Faces" anything-colors t
]
744 ["Show xfonts" anything-select-xfont t
]
745 ["Imenu" anything-imenu t
]
746 ["Google Suggest" anything-google-suggest t
]
747 ["Eval expression" anything-eval-expression-with-eldoc t
]
748 ["Calcul expression" anything-calcul-expression t
]
749 ["Man pages" anything-man-woman t
]
750 ["Top externals process" anything-top t
])
752 ["Prefered Options" anything-configuration t
]))
755 ;; It is replaced by `anything-help'
756 (defun anything-c-describe-anything-bindings ()
757 "[OBSOLETE] Describe `anything' bindings."
759 (anything-run-after-quit
761 (with-current-buffer (get-buffer-create "*Anything Help*")
764 (substitute-command-keys
765 "The keys that are defined for `anything' are:
767 (pop-to-buffer "*Anything Help*")
768 (goto-char (point-min)))))
770 ;; Use `describe-mode' key in `global-map'
771 ;; (dolist (k (where-is-internal 'describe-mode global-map))
772 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
775 (defun anything-c-list-preconfigured-anything ()
778 for entry in
(cdr (assoc
779 (file-truename (locate-library "anything-config"))
781 if
(and (consp entry
)
782 (eq (car entry
) 'defun
)
783 (string-match "^Preconfigured.+$"
784 (setq doc
(or (documentation (setq sym
(cdr entry
)))
786 collect
(cons sym
(match-string 0 doc
))))
788 (defun anything-c-format-preconfigured-anything ()
789 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x
) (cdr x
)))
790 (anything-c-list-preconfigured-anything)))
792 (setq anything-help-message
796 "`anything' is QuickSilver-like candidate-selection framework.
798 Narrow the list by typing some pattern,
799 Multiple patterns are allowed by splitting by space.
800 Select with natural Emacs operations, choose with RET.
802 If you have any problems, press C-c C-x C-b!!
803 Feel free to send bug reports. I'll fix them.
804 The steps are described in the beginning of anything.el file.
806 == Basic Operations ==
807 C-p, Up: Previous Line
808 C-n, Down : Next Line
809 M-v, PageUp : Previous Page
810 C-v, PageDown : Next Page
811 Enter : Execute first (default) action / Select
814 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
815 M-PageDown, C-M-v : Next Page (other-window)
817 Tab, C-i : Show action list
818 Left : Previous Source
819 Right, C-o : Next Source
821 C-z : Persistent Action (Execute action with anything session kept)
822 C-c C-x C-b: Send a bug report
824 == Shortcuts For 2nd/3rd Action ==
825 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
826 \\[anything-select-3rd-action] : Execute 3rd Action
829 Visible marks store candidate. Some actions uses marked candidates.
831 \\[anything-toggle-visible-mark] : Toggle Visible Mark
832 \\[anything-prev-visible-mark] : Previous Mark
833 \\[anything-next-visible-mark] : Next Mark
835 == Miscellaneous Commands ==
836 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
837 \\[anything-quit-and-find-file] : Drop into `find-file'
838 \\[anything-delete-current-selection] : Delete Selected Item (visually)
839 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
840 \\[anything-yank-selection] : Yank Selected Item Into Pattern
841 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
842 \\[anything-force-update] : Recalculate And Redisplay Candidates
844 == Global Commands ==
845 \\<global-map>\\[anything-resume] revives last `anything' session.
846 It is very useful, so you should bind any key.
848 Single source is executed by \\[anything-call-source].
850 == Preconfigured `anything' ==
851 Preconfigured `anything' is commands that uses `anything' interface.
852 You can use them without configuration.
855 (apply 'concat
(anything-c-format-preconfigured-anything))
859 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
861 (defun anything-mini ()
862 "Preconfigured `anything' lightweight version (buffer -> recentf)."
864 (anything-other-buffer '(anything-c-source-buffers+ anything-c-source-recentf
)
867 (defun anything-for-files ()
868 "Preconfigured `anything' for opening files.
869 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
871 (anything-other-buffer anything-for-files-prefered-list
"*anything for files*"))
874 (defun anything-recentf ()
875 "Preconfigured `anything' for `recentf'."
877 (anything-other-buffer 'anything-c-source-recentf
"*anything recentf*"))
880 (defun anything-info-at-point ()
881 "Preconfigured `anything' for searching info at point."
883 (anything '(anything-c-source-info-elisp
884 anything-c-source-info-cl
885 anything-c-source-info-pages
)
886 (thing-at-point 'symbol
) nil nil nil
"*anything info*"))
889 (defun anything-info-emacs ()
890 "Preconfigured anything for Emacs manual index."
892 (anything-other-buffer 'anything-c-source-info-emacs
"*info emacs*"))
895 (defun anything-show-kill-ring ()
896 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
897 You may bind this command to M-y."
899 (anything-other-buffer 'anything-c-source-kill-ring
"*anything kill-ring*"))
902 (defun anything-minibuffer-history ()
903 "Preconfigured `anything' for `minibuffer-history'."
905 (let ((enable-recursive-minibuffers t
))
906 (anything-other-buffer 'anything-c-source-minibuffer-history
907 "*anything minibuffer-history*")))
909 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
910 ;; minibuffer-local-filename-must-match-map.
911 (defvar minibuffer-local-filename-must-match-map
(make-sparse-keymap)) ;; Emacs 23.1.+
912 (defvar minibuffer-local-must-match-filename-map
(make-sparse-keymap)) ;; Older Emacsen
913 (dolist (map (list minibuffer-local-filename-completion-map
914 minibuffer-local-completion-map
915 minibuffer-local-must-match-filename-map
916 minibuffer-local-filename-must-match-map
918 minibuffer-local-isearch-map
919 minibuffer-local-must-match-map
920 minibuffer-local-ns-map
))
921 (define-key map
"\C-r" 'anything-minibuffer-history
))
924 (defun anything-gentoo ()
925 "Preconfigured `anything' for gentoo linux."
927 (anything-other-buffer '(anything-c-source-gentoo
928 anything-c-source-use-flags
)
929 "*anything gentoo*"))
932 (defun anything-imenu ()
933 "Preconfigured `anything' for `imenu'."
935 (anything 'anything-c-source-imenu nil nil nil nil
"*anything imenu*"))
938 (defun anything-google-suggest ()
939 "Preconfigured `anything' for google search with google suggest."
941 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
944 (defun anything-yahoo-suggest ()
945 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
947 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
949 ;;; Converted from anything-show-*-only
951 (defun anything-for-buffers ()
952 "Preconfigured `anything' for buffer."
954 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
957 (defun anything-buffers+ ()
958 "Enhanced preconfigured `anything' for buffer."
960 (anything-other-buffer 'anything-c-source-buffers
+ "*anything buffers*"))
963 (defun anything-bbdb ()
964 "Preconfigured `anything' for BBDB.
968 http://bbdb.sourceforge.net/"
970 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
973 (defun anything-locate ()
974 "Preconfigured `anything' for Locate.
975 Note you can add locate command after entering pattern.
976 See man locate for more infos."
978 (anything-other-buffer 'anything-c-source-locate
"*anything locate*"))
981 (defun anything-w3m-bookmarks ()
982 "Preconfigured `anything' for w3m bookmark.
984 Needs w3m and emacs-w3m.
986 http://w3m.sourceforge.net/
987 http://emacs-w3m.namazu.org/"
989 (anything-other-buffer 'anything-c-source-w3m-bookmarks
990 "*anything w3m bookmarks*"))
993 (defun anything-firefox-bookmarks ()
994 "Preconfigured `anything' for firefox bookmark.
995 You will have to enable html bookmarks in firefox:
996 open about:config in firefox and double click on this line to enable value \
999 user_pref(\"browser.bookmarks.autoExportHTML\", false);
1001 You should have now:
1003 user_pref(\"browser.bookmarks.autoExportHTML\", true);
1005 After closing firefox, you will be able to browse you bookmarks.
1008 (anything-other-buffer 'anything-c-source-firefox-bookmarks
1009 "*Anything Firefox*"))
1012 (defun anything-colors ()
1013 "Preconfigured `anything' for color."
1015 (anything-other-buffer
1016 '(anything-c-source-colors anything-c-source-customize-face
)
1017 "*anything colors*"))
1020 (defun anything-bookmarks ()
1021 "Preconfigured `anything' for bookmarks."
1023 (anything-other-buffer 'anything-c-source-bookmarks
"*anything bookmarks*"))
1026 (defun anything-c-pp-bookmarks ()
1027 "Preconfigured `anything' for bookmarks (pretty-printed)."
1029 (anything-other-buffer '(anything-c-source-bookmarks-local
1030 anything-c-source-bookmarks-su
1031 anything-c-source-bookmarks-ssh
)
1032 "*anything pp bookmarks*"))
1035 (defun anything-register ()
1036 "Preconfigured `anything' for Emacs registers."
1038 (anything-other-buffer 'anything-c-source-register
"*anything register*"))
1041 (defun anything-man-woman ()
1042 "Preconfigured `anything' for Man and Woman pages."
1044 (anything-other-buffer 'anything-c-source-man-pages
"*Anything man woman*"))
1047 (defun anything-org-keywords ()
1048 "Preconfigured `anything' for org keywords."
1050 (anything-other-buffer 'anything-c-source-org-keywords
"*org keywords*"))
1053 (defun anything-emms ()
1054 "Preconfigured `anything' for emms sources."
1056 (anything '(anything-c-source-emms-streams
1057 anything-c-source-emms-files
1058 anything-c-source-emms-dired
)
1063 (defun anything-eev-anchors ()
1064 "Preconfigured `anything' for eev anchors."
1066 (anything-other-buffer 'anything-c-source-eev-anchor
"*Anything eev anchors*"))
1069 (defun anything-bm-list ()
1070 "Preconfigured `anything' for visible bookmarks.
1074 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
1076 (let ((anything-outline-using t
))
1077 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*")))
1080 (defun anything-timers ()
1081 "Preconfigured `anything' for timers."
1083 (anything-other-buffer '(anything-c-source-absolute-time-timers
1084 anything-c-source-idle-time-timers
)
1085 "*anything timers*"))
1087 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1090 (defun anything-kill-buffers ()
1091 "Preconfigured `anything' to kill buffer you selected."
1094 '(((name .
"Kill Buffers")
1095 (candidates . anything-c-buffer-list
)
1097 ("Kill Buffer" .
(lambda (candidate)
1098 (kill-buffer candidate
)
1099 (anything-kill-buffers)
1104 (defun anything-c-query-replace-regexp (candidate)
1105 (let ((regexp (funcall (anything-attr 'regexp
))))
1106 (apply 'query-replace-regexp
1107 (anything-c-query-replace-args regexp
))))
1109 (defun anything-c-kill-regexp-as-sexp (candidate)
1110 (anything-c-regexp-kill-new
1111 (prin1-to-string (funcall (anything-attr 'regexp
)))))
1113 (defun anything-c-kill-regexp (candidate)
1114 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp
))))
1116 (defun anything-c-query-replace-args (regexp)
1117 "create arguments of `query-replace-regexp' action in `anything-regexp'."
1118 (let ((region-only (anything-region-active-p)))
1121 (query-replace-read-to regexp
1122 (format "Query replace %s regexp %s"
1123 (if anything-current-prefix-arg
"word " "")
1124 (if region-only
"in region " ""))
1126 anything-current-prefix-arg
1127 (when region-only
(region-beginning))
1128 (when region-only
(region-end)))))
1130 (defvar anything-c-source-regexp
1131 '((name .
"Regexp Builder")
1133 (anything-candidate-buffer anything-current-buffer
)))
1134 (candidates-in-buffer)
1135 (get-line . anything-c-regexp-get-line
)
1136 (persistent-action . anything-c-regexp-persistent-action
)
1137 (persistent-help .
"Show this line")
1140 (requires-pattern .
2)
1141 (mode-line .
"Press TAB to select action.")
1143 ;; I use here `anything-input' because `anything-pattern' is lost when
1144 ;; using actions from action buffer (otherwise no e.g from RET, C-e or C-j).
1145 ;; It seem `anything-select-action' reset `anything-pattern' to empty too early.
1146 ;; Though the regexp attribute stay defined (tested with *-attr-defined).
1148 (regexp .
(lambda () anything-input
))
1149 (action .
(("Query Replace Regexp" . anything-c-query-replace-regexp
)
1150 ("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp
)
1151 ("Kill Regexp" . anything-c-kill-regexp
)))))
1153 (defun anything-c-regexp-get-line (s e
)
1157 (format "%5d: %s" (line-number-at-pos (1- s
)) (buffer-substring s e
))
1159 (loop for i from
0 to
(1- (/ (length (match-data)) 2))
1160 collect
(format "\n %s'%s'"
1161 (if (zerop i
) "Group 0: " (format "Group %d: " i
))
1164 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
1165 ;; It is implementation problem of candidates-in-buffer.
1169 ;; Shut up byte compiler
1170 (defun anything-goto-line (numline)
1171 "Replacement of `goto-line'."
1172 (goto-char (point-min))
1173 (forward-line (1- numline
)))
1175 (defun anything-c-regexp-persistent-action (pt)
1177 (anything-persistent-highlight-point))
1179 (defun anything-c-regexp-kill-new (input)
1181 (message "Killed: %s" input
))
1183 (defun anything-region-active-p ()
1184 (and transient-mark-mode mark-active
(/= (mark) (point))))
1186 (defun* anything-current-buffer-narrowed-p
(&optional
1187 (buffer anything-current-buffer
))
1188 "Check if BUFFER is narrowed.
1189 Default is `anything-current-buffer'."
1190 (with-current-buffer buffer
1191 (let ((beg (point-min))
1193 (total (buffer-size)))
1194 (or (/= beg
1) (/= end
(1+ total
))))))
1197 (defun anything-regexp ()
1198 "Preconfigured anything to build regexps and run query-replace-regexp \
1202 (let ((anything-compile-source-functions
1203 ;; rule out anything-match-plugin because the input is one regexp.
1204 (delq 'anything-compile-source--match-plugin
1205 (copy-sequence anything-compile-source-functions
))))
1206 (when (and (anything-region-active-p)
1207 ;; Don't narrow to region if buffer is already narrowed.
1208 (not (anything-current-buffer-narrowed-p)))
1209 (narrow-to-region (region-beginning) (region-end)))
1211 anything-c-source-regexp
1212 :buffer
"*anything regexp*"
1213 :prompt
"Regexp: "))))
1216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1218 (defun anything-insert-buffer-name ()
1219 "Insert buffer name."
1221 (anything-insert-string
1222 (with-current-buffer anything-current-buffer
1223 (if buffer-file-name
(file-name-nondirectory buffer-file-name
)
1226 (defun anything-insert-symbol ()
1227 "Insert current symbol."
1229 (anything-insert-string
1230 (with-current-buffer anything-current-buffer
1232 (buffer-substring (beginning-of-thing 'symbol
)
1233 (end-of-thing 'symbol
))))))
1235 (defun anything-insert-selection ()
1236 "Insert current selection."
1238 (anything-insert-string
1239 (with-current-buffer anything-current-buffer
1240 (anything-get-selection))))
1242 (defun anything-show-buffer-only ()
1243 "[OBSOLETE] Only show sources about buffer.
1244 Use `anything-for-buffers' instead."
1246 (anything-set-source-filter '("Buffers")))
1248 (defun anything-show-bbdb-only ()
1249 "[OBSOLETE] Only show sources about BBDB.
1250 Use `anything-bbdb' instead."
1252 (anything-set-source-filter '("BBDB")))
1254 (defun anything-show-locate-only ()
1255 "[OBSOLETE] Only show sources about Locate.
1256 Use `anything-locate' instead."
1258 (anything-set-source-filter '("Locate")))
1260 (defun anything-show-info-only ()
1261 "[OBSOLETE] Only show sources about Info.
1262 Use `anything-info-at-point' instead."
1264 (anything-set-source-filter '("Info Pages"
1266 "Info Common-Lisp")))
1268 (defun anything-show-imenu-only ()
1269 "[OBSOLETE] Only show sources about Imenu.
1270 Use `anything-imenu' instead."
1272 (anything-set-source-filter '("Imenu")))
1274 (defun anything-show-files-only ()
1275 "[OBSOLETE] Only show sources about File.
1276 Use `anything-for-files' instead."
1278 (anything-set-source-filter '("File Name History"
1279 "Files from Current Directory"
1282 (defun anything-show-w3m-bookmarks-only ()
1283 "[OBSOLETE] Only show source about w3m bookmark.
1284 Use `anything-w3m-bookmarks' instead."
1286 (anything-set-source-filter '("W3m Bookmarks")))
1288 (defun anything-show-colors-only ()
1289 "[OBSOLETE] Only show source about color.
1290 Use `anything-colors' instead."
1292 (anything-set-source-filter '("Colors"
1293 "Customize Faces")))
1295 (defun anything-show-kill-ring-only ()
1296 "[OBSOLETE] Only show source about kill ring.
1297 Use `anything-show-kill-ring' instead."
1299 (anything-set-source-filter '("Kill Ring")))
1301 (defun anything-show-this-source-only ()
1302 "Only show this source."
1304 (setq anything-candidate-number-limit
9999)
1305 (anything-set-source-filter
1306 (list (assoc-default 'name
(anything-get-current-source)))))
1308 (defun anything-test-sources ()
1309 "List all anything sources for test.
1310 The output is sexps which are evaluated by \\[eval-last-sexp]."
1312 (with-output-to-temp-buffer "*Anything Test Sources*"
1313 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s
)))
1314 (apropos-internal "^anything-c-source" #'boundp
))
1315 (pop-to-buffer standard-output
)))
1317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1318 ;;; For compatibility
1319 (unless (fboundp 'region-active-p
)
1320 (defun region-active-p ()
1321 "Return t if Transient Mark mode is enabled and the mark is active.
1323 Most commands that act on the region if it is active and
1324 Transient Mark mode is enabled, and on the text near point
1325 otherwise, should use `use-region-p' instead. That function
1326 checks the value of `use-empty-active-region' as well."
1327 (and transient-mark-mode mark-active
)))
1329 (defun anything-nest (&rest same-as-anything
)
1330 "Nested `anything'. If you use `anything' within `anything', use it."
1331 (with-selected-window (anything-window)
1332 (let (anything-current-position
1333 anything-current-buffer
1334 (orig-anything-buffer anything-buffer
)
1338 anything-compiled-sources
1339 anything-buffer-chars-modified-tick
1340 (anything-samewindow t
)
1341 (enable-recursive-minibuffers t
))
1343 (apply #'anything same-as-anything
)
1344 (anything-initialize-overlays orig-anything-buffer
)
1345 (add-hook 'post-command-hook
'anything-check-minibuffer-input
)))))
1347 (defun anything-displaying-source-names ()
1348 "Display sources name."
1349 (with-current-buffer anything-buffer
1350 (goto-char (point-min))
1352 while
(setq pos
(next-single-property-change (point) 'anything-header
))
1354 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
1355 do
(forward-line 1))))
1357 (defun anything-select-source ()
1360 (let ((default (assoc-default 'name
(anything-get-current-source)))
1361 (source-names (anything-displaying-source-names))
1362 (all-source-names (mapcar (lambda (s) (assoc-default 'name s
))
1363 (anything-get-sources))))
1364 (setq anything-candidate-number-limit
9999)
1366 (let (anything-source-filter)
1367 (anything-nest '(((name .
"Anything Source")
1368 (candidates . source-names
)
1369 (action . identity
))
1370 ((name .
"Anything Source (ALL)")
1371 (candidates . all-source-names
)
1372 (action . identity
)))
1374 default
"*anything select source*"))
1375 (anything-set-source-filter (list it
))
1376 (anything-set-source-filter nil
))))
1378 (defun anything-insert-string (str)
1380 (delete-minibuffer-contents)
1383 (defun anything-c-match-on-file-name (candidate)
1384 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1385 (string-match anything-pattern
(file-name-nondirectory candidate
)))
1387 (defun anything-c-match-on-directory-name (candidate)
1388 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1389 (anything-aif (file-name-directory candidate
)
1390 (string-match anything-pattern it
)))
1392 (defun anything-c-string-match (candidate)
1393 "Return non-nil if `anything-pattern' match CANDIDATE.
1394 The match is done with `string-match'."
1395 (string-match anything-pattern candidate
))
1397 ;; `anything-c-compose' is no more needed, it is for compatibility.
1398 (defalias 'anything-c-compose
'anything-compose
)
1400 (defun anything-c-skip-entries (list regexp
)
1401 "Remove entries which matches REGEXP from LIST."
1402 (remove-if (lambda (x) (and (stringp x
) (string-match regexp x
)))
1405 (defun anything-c-shadow-entries (list regexp
)
1406 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1407 (mapcar (lambda (file)
1408 ;; Add shadow face property to boring files.
1409 (let ((face (if (facep 'file-name-shadow
)
1411 ;; fall back to default on XEmacs
1413 (if (string-match regexp file
)
1414 (setq file
(propertize file
'face face
))))
1418 (defsubst anything-c-stringify
(str-or-sym)
1419 "Get string of STR-OR-SYM."
1420 (if (stringp str-or-sym
)
1422 (symbol-name str-or-sym
)))
1424 (defsubst anything-c-symbolify
(str-or-sym)
1425 "Get symbol of STR-OR-SYM."
1426 (if (symbolp str-or-sym
)
1428 (intern str-or-sym
)))
1430 (defun anything-c-describe-function (func)
1431 "FUNC is symbol or string."
1432 (describe-function (anything-c-symbolify func
)))
1434 (defun anything-c-describe-variable (var)
1435 "VAR is symbol or string."
1436 (describe-variable (anything-c-symbolify var
)))
1438 (defun anything-c-find-function (func)
1439 "FUNC is symbol or string."
1440 (find-function (anything-c-symbolify func
)))
1442 (defun anything-c-find-variable (var)
1443 "VAR is symbol or string."
1444 (find-variable (anything-c-symbolify var
)))
1446 (defun anything-c-kill-new (string &optional replace yank-handler
)
1447 "STRING is symbol or string."
1448 (kill-new (anything-c-stringify string
) replace yank-handler
))
1450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1452 (defvar anything-current-prefix-arg nil
1453 "`current-prefix-arg' when selecting action.
1454 It is cleared after executing action.")
1456 (defadvice anything-exit-minibuffer
(before anything-current-prefix-arg activate
)
1457 (unless anything-current-prefix-arg
1458 (setq anything-current-prefix-arg current-prefix-arg
)))
1460 (add-hook 'anything-after-action-hook
1461 (lambda () (setq anything-current-prefix-arg nil
)))
1464 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1465 (defadvice eval-defun
(after anything-source-hack activate
)
1466 "See `anything-c-enable-eval-defun-hack'."
1467 (when anything-c-enable-eval-defun-hack
1468 (let ((varsym (save-excursion
1469 (beginning-of-defun)
1471 (when (memq (read (current-buffer)) '(defvar setq
))
1472 (read (current-buffer))))))
1473 (when (string-match "^anything-c-source-" (symbol-name varsym
))
1474 (anything varsym
)))))
1475 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1477 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1478 (defconst anything-c-create-summary-index-regexp
1479 "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$")
1480 (defun anything-c-create-summary ()
1481 "Create `anything' summary."
1483 (goto-char (point-min))
1485 while
(re-search-forward anything-c-create-summary-index-regexp nil t
)
1487 (cond ((setq it
(match-string-no-properties 1))
1489 ((setq it
(match-string-no-properties 2))
1491 ,(assoc-default 'name
(symbol-value (intern it
)))))
1492 ((setq it
(match-string-no-properties 3))
1494 ,(assoc-default 'name
(symbol-value (intern it
)))))))))
1496 ;; (find-epp (anything-c-create-summary))
1498 (defun anything-c-insert-summary ()
1499 "Insert `anything' summary."
1501 (goto-char (point-min))
1502 (search-forward ";; Below are complete source list you can setup in")
1504 (delete-region (point)
1505 (progn (search-forward ";;; Change log:" nil t
)
1506 (forward-line -
1) (point)))
1509 for
(kind . value
) in
(anything-c-create-summary)
1511 do
(cond ((eq kind
'section
)
1513 (align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))
1514 (insert ";; " value
":\n")
1517 (insert ";; `" (car value
) "' (" (cdr value
) ")\n")))
1518 finally
(align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))))
1519 ;; (anything-c-insert-summary)
1521 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1523 (defun anything-c-buffer-list ()
1524 "Return the list of names of buffers with boring buffers filtered out.
1525 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1526 The first buffer in the list will be the last recently used
1527 buffer that is not the current buffer."
1528 (let ((buffers (mapcar 'buffer-name
(buffer-list))))
1529 (append (cdr buffers
) (list (car buffers
)))))
1531 (defvar anything-c-source-buffers
1532 '((name .
"Buffers")
1533 (candidates . anything-c-buffer-list
)
1535 ;; (anything 'anything-c-source-buffers)
1537 (defvar anything-c-source-buffer-not-found
1538 '((name .
"Create buffer")
1541 ;; (anything 'anything-c-source-buffer-not-found)
1544 (defface anything-dir-heading
'((t (:foreground
"Blue" :background
"Pink")))
1545 "*Face used for directory headings in dired buffers."
1548 (defface anything-file-name
1549 '((t (:foreground
"Blue")))
1550 "*Face used for file names (without suffixes) in dired buffers."
1553 (defface anything-dir-priv
1554 '((t (:foreground
"DarkRed" :background
"LightGray")))
1555 "*Face used for directory privilege indicator (d) in dired buffers."
1558 (defvar anything-c-buffers-face1
'anything-dir-priv
)
1559 (defvar anything-c-buffers-face2
'font-lock-type-face
)
1560 (defvar anything-c-buffers-face3
'italic
)
1561 (eval-when-compile (require 'dired
))
1562 (defun anything-c-highlight-buffers (buffers)
1564 (loop for i in buffers
1565 if
(rassoc (get-buffer i
) dired-buffers
)
1566 collect
(propertize i
1567 'face anything-c-buffers-face1
1568 'help-echo
(car (rassoc (get-buffer i
) dired-buffers
)))
1569 if
(buffer-file-name (get-buffer i
))
1570 collect
(propertize i
1571 'face anything-c-buffers-face2
1572 'help-echo
(buffer-file-name (get-buffer i
)))
1573 if
(and (not (rassoc (get-buffer i
) dired-buffers
))
1574 (not (buffer-file-name (get-buffer i
))))
1575 collect
(propertize i
1576 'face anything-c-buffers-face3
)))
1578 (defvar anything-c-source-buffers
+
1579 '((name .
"Buffers")
1580 (candidates . anything-c-buffer-list
)
1582 (candidate-transformer anything-c-skip-current-buffer
1583 anything-c-highlight-buffers
1584 anything-c-skip-boring-buffers
)
1585 (persistent-action . anything-c-buffers
+-persistent-action
)
1586 (persistent-help .
"Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1588 (defun anything-c-buffers+-persistent-action
(name)
1590 (with-current-buffer item
1591 (if (and (buffer-modified-p)
1592 (buffer-file-name (current-buffer)))
1596 (kill-buffer item
))))
1598 (switch-to-buffer item
)))
1599 (if current-prefix-arg
1602 (anything-delete-current-selection))
1605 ;; (anything 'anything-c-source-buffers+)
1609 ;;; File name history
1610 (defvar anything-c-source-file-name-history
1611 '((name .
"File Name History")
1612 (candidates . file-name-history
)
1613 (match anything-c-match-on-file-name
1614 anything-c-match-on-directory-name
)
1616 ;; (anything 'anything-c-source-file-name-history)
1618 ;;; Files in current dir
1619 (defvar anything-c-source-files-in-current-dir
1620 '((name .
"Files from Current Directory")
1621 (candidates .
(lambda ()
1622 (with-current-buffer anything-current-buffer
1623 (directory-files (anything-c-current-directory)))))
1624 ;; volatile is not needed, I think.
1626 ;; (anything 'anything-c-source-files-in-current-dir)
1628 (defvar anything-c-files-face1
'anything-dir-priv
)
1629 (defvar anything-c-files-face2
'anything-file-name
)
1630 (defun anything-c-highlight-files (files)
1631 (loop for i in files
1632 if
(file-directory-p i
)
1633 collect
(propertize (file-name-nondirectory i
)
1634 'face anything-c-files-face1
1635 'help-echo
(expand-file-name i
))
1637 collect
(propertize (file-name-nondirectory i
)
1638 'face anything-c-files-face2
1639 'help-echo
(expand-file-name i
))))
1642 (defvar anything-c-source-files-in-current-dir
+
1643 '((name .
"Files from Current Directory")
1644 (candidates .
(lambda ()
1645 (with-current-buffer anything-current-buffer
1646 (directory-files (anything-c-current-directory) t
))))
1647 (candidate-transformer anything-c-highlight-files
)
1648 ;; volatile is not needed, I think.
1651 ;; (anything 'anything-c-source-files-in-current-dir+)
1653 ;;; Anything replacement of file name completion for `find-file' and friends.
1655 (defvar anything-c-find-files-doc-header
(format " (`%s':Go to precedent level)"
1656 (if window-system
"C-." "C-l"))
1657 "*The doc that is inserted in the Name header of a find-files or dired source.")
1659 (defvar anything-c-source-find-files
1660 `((name .
,(concat "Find Files" anything-c-find-files-doc-header
))
1661 ;; It is needed for filenames with capital letters
1664 (setq ffap-newfile-prompt t
)))
1665 (candidates . anything-find-files-get-candidates
)
1666 (candidate-transformer anything-c-highlight-ffiles
)
1667 (persistent-action . anything-find-files-persistent-action
)
1668 (persistent-help .
"Expand Candidate")
1673 `(("Find File" . anything-c-find-file-or-marked
)
1674 ("Find file in Dired" . anything-c-point-file-in-dired
)
1675 ,(and (locate-library "elscreen")
1676 '("Find file in Elscreen" . anything-elscreen-find-file
))
1677 ("Complete at point"
1678 . anything-c-insert-file-name-completion-at-point
)
1679 ("Delete File(s)" . anything-delete-marked-files
)
1680 ("Find file as root" . anything-find-file-as-root
)
1681 ("Open file externally (C-u to choose)"
1682 . anything-c-open-file-externally
)
1683 ;; ("Create dired buffer on marked"
1684 ;; . anything-c-create-dired-on-marked)
1685 ("Find file other window" . find-file-other-window
)
1686 ("Find file other frame" . find-file-other-frame
))))))
1688 ;; (anything 'anything-c-source-find-files)
1690 (defun* anything-reduce-file-name
(fname level
&key unix-close expand
)
1691 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1692 If LEVEL is positive reduce from end else from beginning.
1693 If UNIX-CLOSE is non--nil close filename with /.
1694 If EXPAND is non--nil expand-file-name."
1695 (let* ((exp-fname (expand-file-name fname
))
1696 (fname-list (split-string (if (or (string= fname
"~/") expand
)
1697 exp-fname fname
) "/" t
))
1698 (len (length fname-list
))
1699 (pop-list (if (< level
0)
1700 (subseq fname-list
(* level -
1))
1701 (subseq fname-list
0 (- len level
))))
1702 (result (mapconcat 'identity pop-list
"/"))
1703 (empty (string= result
"")))
1704 (when unix-close
(setq result
(concat result
"/")))
1705 (if (string-match "^~" result
)
1706 (if (string= result
"~/") "~/" result
)
1708 (if empty
"../" (concat "../" result
))
1709 (cond ((eq system-type
'windows-nt
)
1710 (if empty
"c:/" result
))
1713 (concat "/" result
)))))))
1715 (defun anything-file-completion-source-p ()
1716 "Test if current source is a dired or find-files source."
1717 (let ((ff-sources '("Find Files" "Copy Files"
1718 "Rename Files" "Symlink Files"
1719 "Hardlink Files" "Write File"
1720 "Insert File" "Read file name"))
1721 (cur-source (cdr (assoc 'name
(anything-get-current-source)))))
1723 (dolist (i ff-sources
)
1724 (when (equal cur-source
(concat i anything-c-find-files-doc-header
))
1725 (throw 'break t
))))))
1727 (defun anything-find-files-down-one-level (arg)
1728 "Go down one level like unix command `cd ..'.
1729 If prefix numeric arg is given go ARG level down."
1731 (when (anything-file-completion-source-p)
1732 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
1733 :unix-close t
:expand t
)))
1734 (with-selected-window (minibuffer-window)
1735 (delete-minibuffer-contents)
1736 (insert new-pattern
)))))
1738 ;; `C-.' doesn't work in terms use `C-l' instead.
1740 (define-key anything-map
(kbd "C-.") 'anything-find-files-down-one-level
)
1741 (define-key anything-map
(kbd "C-l") 'anything-find-files-down-one-level
))
1743 (defun anything-c-point-file-in-dired (file)
1744 "Put point on filename FILE in dired buffer."
1745 (dired (file-name-directory file
))
1746 (dired-goto-file file
))
1748 (defun anything-create-tramp-name (fname)
1749 "Build filename for `anything-pattern' like /su:: or /sudo::."
1750 (apply #'tramp-make-tramp-file-name
1752 with v
= (tramp-dissect-file-name fname
)
1753 for i across v collect i
)))
1755 (defun anything-find-files-get-candidates ()
1756 "Create candidate list for `anything-c-source-find-files'."
1757 (let* ( ; Don't try to tramp connect before entering the second ":".
1758 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:?")
1759 (path (cond ((string-match "^~" anything-pattern
)
1760 (replace-match (getenv "HOME") nil t anything-pattern
))
1761 ((string-match tramp-file-name-regexp anything-pattern
)
1762 (let ((tramp-name (anything-create-tramp-name
1763 (match-string 0 anything-pattern
))))
1764 (replace-match tramp-name nil t anything-pattern
)))
1765 (t anything-pattern
)))
1766 (tramp-verbose anything-tramp-verbose
)) ; No tramp message when 0.
1767 ;; Inlined version (<2010-02-18 Jeu.>.) of `tramp-handle-directory-files'
1768 ;; to fix bug in tramp that doesn't show the dot file names(i.e "." "..")
1770 (flet ((tramp-handle-directory-files
1771 (directory &optional full match nosort files-only
)
1772 "Like `directory-files' for Tramp files."
1773 ;; FILES-ONLY is valid for XEmacs only.
1774 (when (file-directory-p directory
)
1775 (setq directory
(file-name-as-directory (expand-file-name directory
)))
1776 (let ((temp (nreverse (file-name-all-completions "" directory
)))
1780 (setq item
(directory-file-name (pop temp
)))
1781 (when (and (or (null match
) (string-match match item
))
1782 (or (null files-only
)
1784 (and (equal files-only t
) (file-regular-p item
))
1785 ;; Directories only.
1786 (file-directory-p item
)))
1787 (push (if full
(concat directory item
) item
)
1789 (if nosort result
(sort result
'string
<))))))
1791 (set-text-properties 0 (length path
) nil path
)
1792 (setq anything-pattern
(replace-regexp-in-string " " ".*" path
))
1793 (cond ((or (file-regular-p path
)
1794 (and ffap-url-regexp
(string-match ffap-url-regexp path
)))
1796 ((string= anything-pattern
"") (directory-files "/" t
))
1797 ((file-directory-p path
) (directory-files path t
))
1801 (directory-files (file-name-directory path
) t
)))))))
1803 (defface anything-dired-symlink-face
1804 '((t (:foreground
"DarkOrange")))
1805 "*Face used for symlinks in `anything-find-files'."
1808 (defun anything-c-highlight-ffiles (files)
1809 "Candidate transformer for `anything-c-source-find-files'."
1810 (loop for i in files
1811 if
(file-symlink-p i
)
1812 collect
(propertize i
'face
'anything-dired-symlink-face
1813 'help-echo
(file-truename i
)) into a
1814 if
(file-directory-p i
)
1815 collect
(propertize i
'face anything-c-files-face1
) into a
1817 collect
(propertize i
'face anything-c-files-face2
) into a
1821 (defun anything-find-files-persistent-action (candidate)
1822 "Open subtree CANDIDATE without quitting anything.
1823 If CANDIDATE is not a directory expand CANDIDATE filename.
1824 If CANDIDATE is alone, open file CANDIDATE filename."
1825 (flet ((insert-in-minibuffer (elm)
1826 (with-selected-window (minibuffer-window)
1827 (delete-minibuffer-contents)
1828 (set-text-properties 0 (length elm
) nil elm
)
1830 (cond ((and (file-directory-p candidate
) (file-symlink-p candidate
))
1831 (insert-in-minibuffer (file-name-as-directory
1833 (expand-file-name candidate
)))))
1834 ((file-directory-p candidate
)
1835 (insert-in-minibuffer (file-name-as-directory
1836 (expand-file-name candidate
))))
1837 ((file-symlink-p candidate
)
1838 (insert-in-minibuffer (file-truename candidate
)))
1839 (t ; First hit on C-z expand CANDIDATE second hit open file.
1840 (let ((new-pattern (anything-get-selection anything-last-buffer
))
1841 (num-lines-buf (with-current-buffer anything-last-buffer
1842 (count-lines (point-min) (point-max)))))
1843 (if (> num-lines-buf
3)
1844 (insert-in-minibuffer new-pattern
) (find-file candidate
)))))))
1846 (defun anything-c-insert-file-name-completion-at-point (candidate)
1847 "Insert file name completion at point."
1848 (if buffer-read-only
1849 (error "Error: Buffer `%s' is read-only" (buffer-name))
1850 (let* ((end (point))
1851 (guess (thing-at-point 'filename
))
1852 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess
)
1853 (string-match "^[^\~]" guess
))))
1854 (set-text-properties 0 (length candidate
) nil candidate
)
1855 (if (and guess
(not (string= guess
"")) (string-match "^~\\|/.*" guess
))
1857 (search-backward guess
(- (point) (length guess
)))
1858 (delete-region (point) end
)
1860 (insert (expand-file-name candidate
))
1861 (insert (abbreviate-file-name candidate
))))
1862 (error "Aborting completion: No valid file name at point")))))
1865 (defun anything-find-files ()
1866 "Preconfigured `anything' for anything implementation of `find-file'."
1868 (anything :sources
'anything-c-source-find-files
1869 :input
(anything-find-files-input (ffap-guesser)
1870 (thing-at-point 'filename
))
1871 :prompt
"Find Files or Url: "
1872 :buffer
"*Anything Find Files*"))
1874 (defun anything-c-current-directory ()
1875 "Return current-directory name at point.
1876 Useful in dired buffers when there is inserted subdirs."
1877 (if (eq major-mode
'dired-mode
)
1878 (dired-current-directory)
1881 (defun anything-find-files-input (fap tap
)
1882 "Default input of `anything-find-files'."
1883 (let* ((def-dir (anything-c-current-directory))
1884 (lib (anything-find-library-at-point))
1885 (file-p (and fap
(file-exists-p fap
)
1887 (file-name-directory (expand-file-name tap def-dir
)))))
1889 (file-p (expand-file-name tap def-dir
))
1891 (or input
(expand-file-name def-dir
))))
1893 (defun anything-find-library-at-point ()
1894 "Try to find library path at point.
1895 Find inside `require' and `declare-function' sexp."
1896 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t
)))
1897 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t
)))
1898 (sexp (and beg-sexp end-sexp
1899 (buffer-substring-no-properties
1900 (1+ beg-sexp
) (1- end-sexp
)))))
1902 (cond ((and sexp
(string-match "require \'.+[^)]" sexp
))
1904 (replace-regexp-in-string
1906 ;; If require use third arg, ignore it,
1907 ;; always use library path found in `load-path'.
1908 (second (split-string (match-string 0 sexp
))))))
1909 ((and sexp
(string-match-p "^declare-function" sexp
))
1911 (replace-regexp-in-string
1913 (third (split-string sexp
)))))
1916 ;;; Anything completion for `write-file'.==> C-x C-w
1917 (defvar anything-c-source-write-file
1918 `((name .
,(concat "Write File" anything-c-find-files-doc-header
))
1919 ;; It is needed for filenames with capital letters
1921 (candidates . anything-find-files-get-candidates
)
1922 (candidate-transformer anything-c-highlight-ffiles
)
1923 (persistent-action . anything-find-files-persistent-action
)
1924 (persistent-help .
"Expand Candidate")
1927 (("Write File" .
(lambda (candidate)
1928 (write-file candidate
'confirm
)))))))
1931 (defun anything-write-file ()
1932 "Preconfigured `anything' providing completion for `write-file'."
1934 (anything 'anything-c-source-write-file
1935 (expand-file-name default-directory
)
1936 "Write buffer to file: " nil nil
"*Anything write file*"))
1938 ;;; Anything completion for `insert-file'.==> C-x i
1939 (defvar anything-c-source-insert-file
1940 `((name .
,(concat "Insert File" anything-c-find-files-doc-header
))
1941 ;; It is needed for filenames with capital letters
1943 (candidates . anything-find-files-get-candidates
)
1944 (candidate-transformer anything-c-highlight-ffiles
)
1945 (persistent-action . anything-find-files-persistent-action
)
1946 (persistent-help .
"Expand Candidate")
1949 (("Insert File" .
(lambda (candidate)
1950 (when (y-or-n-p (format "Really insert %s in %s "
1951 candidate anything-current-buffer
))
1952 (insert-file-contents candidate
))))))))
1955 (defun anything-insert-file ()
1956 "Preconfigured `anything' providing completion for `insert-file'."
1958 (anything 'anything-c-source-insert-file
1959 (expand-file-name default-directory
)
1960 "Insert file: " nil nil
"*Anything insert file*"))
1962 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
1963 (defvar anything-c-source-copy-files
1964 `((name .
,(concat "Copy Files" anything-c-find-files-doc-header
))
1965 ;; It is needed for filenames with capital letters
1967 (candidates . anything-find-files-get-candidates
)
1968 (candidate-transformer anything-c-highlight-ffiles
)
1969 (persistent-action . anything-find-files-persistent-action
)
1970 (persistent-help .
"Expand Candidate")
1974 .
(lambda (candidate)
1975 (anything-dired-action candidate
:action
'copy
)))
1977 .
(lambda (candidate)
1978 (anything-dired-action candidate
:action
'copy
:follow t
)))))))
1981 (defvar anything-c-source-rename-files
1982 `((name .
,(concat "Rename Files" anything-c-find-files-doc-header
))
1983 ;; It is needed for filenames with capital letters
1985 (candidates . anything-find-files-get-candidates
)
1986 (candidate-transformer anything-c-highlight-ffiles
)
1987 (persistent-action . anything-find-files-persistent-action
)
1988 (persistent-help .
"Expand Candidate")
1992 .
(lambda (candidate)
1993 (anything-dired-action candidate
:action
'rename
)))
1994 ("Rename and Follow"
1995 .
(lambda (candidate)
1996 (anything-dired-action candidate
:action
'rename
:follow t
)))))))
1998 (defvar anything-c-source-symlink-files
1999 `((name .
,(concat "Symlink Files" anything-c-find-files-doc-header
))
2000 ;; It is needed for filenames with capital letters
2002 (candidates . anything-find-files-get-candidates
)
2003 (candidate-transformer anything-c-highlight-ffiles
)
2004 (persistent-action . anything-find-files-persistent-action
)
2005 (persistent-help .
"Expand Candidate")
2009 .
(lambda (candidate)
2010 (anything-dired-action candidate
:action
'symlink
)))
2012 .
(lambda (candidate)
2013 (anything-dired-action candidate
:action
'relsymlink
)))))))
2016 (defvar anything-c-source-hardlink-files
2017 `((name .
,(concat "Hardlink Files" anything-c-find-files-doc-header
))
2018 ;; It is needed for filenames with capital letters
2020 (candidates . anything-find-files-get-candidates
)
2021 (candidate-transformer anything-c-highlight-ffiles
)
2022 (persistent-action . anything-find-files-persistent-action
)
2023 (persistent-help .
"Expand Candidate")
2027 .
(lambda (candidate)
2028 (anything-dired-action candidate
:action
'hardlink
)))))))
2030 (defun* anything-dired-action
(candidate &key action follow
)
2031 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
2032 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
2033 (let ((files (dired-get-marked-files))
2035 ('copy
'dired-copy-file
)
2036 ('rename
'dired-rename-file
)
2037 ('symlink
'make-symbolic-link
)
2038 ('relsymlink
'dired-make-relative-symlink
)
2039 ('hardlink
'dired-hardlink
)))
2040 (marker (case action
2041 ((copy rename
) dired-keep-marker-copy
)
2042 ('symlink dired-keep-marker-symlink
)
2043 ('relsymlink dired-keep-marker-relsymlink
)
2044 ('hardlink dired-keep-marker-hardlink
))))
2046 fn
(symbol-name action
) files
2047 (if (file-directory-p candidate
)
2048 ;; When CANDIDATE is a directory, build file-name in this directory.
2049 ;; Else we use CANDIDATE.
2051 (expand-file-name (file-name-nondirectory from
) candidate
))
2052 #'(lambda (from) candidate
))
2055 (let* ((src (car files
))
2056 (dest (expand-file-name candidate
))
2057 (basename-src (if (file-directory-p src
)
2059 (directory-file-name src
)
2060 (file-name-directory src
))
2061 (file-name-nondirectory src
)))
2062 (fname (if (file-directory-p dest
)
2063 (concat (file-name-as-directory dest
)
2066 (anything-c-point-file-in-dired fname
)))))
2069 (defun* anything-dired-do-action-on-file
(&key action
)
2070 (let* ((files (dired-get-marked-files))
2071 (len (length files
))
2072 (fname (if (> len
1)
2073 (format "* %d Files" len
)
2075 (source (case action
2076 ('copy
'anything-c-source-copy-files
)
2077 ('rename
'anything-c-source-rename-files
)
2078 ('symlink
'anything-c-source-symlink-files
)
2079 ('hardlink
'anything-c-source-hardlink-files
)))
2080 (prompt-fm (case action
2081 ('copy
"Copy %s to: ")
2082 ('rename
"Rename %s to: ")
2083 ('symlink
"Symlink %s to: ")
2084 ('hardlink
"Hardlink %s to: ")))
2085 (buffer (case action
2086 ('copy
"*Anything Copy Files*")
2087 ('rename
"*Anything Rename Files*")
2088 ('symlink
"*Anything Symlink Files*")
2089 ('hardlink
"*Anything Hardlink Files*"))))
2091 (or (dired-dwim-target-directory)
2092 (expand-file-name (anything-c-current-directory)))
2093 (format prompt-fm fname
) nil nil buffer
)))
2097 (defun anything-dired-rename-file ()
2098 "Preconfigured `anything' to rename files from dired."
2100 (anything-dired-do-action-on-file :action
'rename
))
2103 (defun anything-dired-copy-file ()
2104 "Preconfigured `anything' to copy files from dired."
2106 (anything-dired-do-action-on-file :action
'copy
))
2109 (defun anything-dired-symlink-file ()
2110 "Preconfigured `anything' to symlink files from dired."
2112 (anything-dired-do-action-on-file :action
'symlink
))
2115 (defun anything-dired-hardlink-file ()
2116 "Preconfigured `anything' to hardlink files from dired."
2118 (anything-dired-do-action-on-file :action
'hardlink
))
2120 (defvar anything-dired-bindings nil
)
2122 (defun anything-dired-bindings (&optional arg
)
2123 "Replace usual dired commands `C' and `R' by anything ones.
2124 When call interactively toggle dired bindings and anything bindings.
2125 When call non--interactively with arg > 0, enable anything bindings.
2126 You can put (anything-dired-binding 1) in init file to enable anything bindings."
2128 (if (or (when arg
(> arg
0)) (not anything-dired-bindings
))
2130 (define-key dired-mode-map
(kbd "C") 'anything-dired-copy-file
)
2131 (define-key dired-mode-map
(kbd "R") 'anything-dired-rename-file
)
2132 (define-key dired-mode-map
(kbd "S") 'anything-dired-symlink-file
)
2133 (define-key dired-mode-map
(kbd "H") 'anything-dired-hardlink-file
)
2134 (setq anything-dired-bindings t
))
2135 (define-key dired-mode-map
(kbd "C") 'dired-do-copy
)
2136 (define-key dired-mode-map
(kbd "R") 'dired-do-rename
)
2137 (define-key dired-mode-map
(kbd "S") 'dired-do-symlink
)
2138 (define-key dired-mode-map
(kbd "H") 'dired-do-hardlink
)
2139 (setq anything-dired-bindings nil
)))
2141 (defun* anything-c-read-file-name
(prompt &key
2142 (initial-input (expand-file-name default-directory
))
2143 (buffer "*Anything Completions*")
2145 "Anything `read-file-name' emulation.
2146 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
2147 (when (get-buffer anything-action-buffer
)
2148 (kill-buffer anything-action-buffer
))
2151 `((name .
,(concat "Read file name" anything-c-find-files-doc-header
))
2152 ;; It is needed for filenames with capital letters
2154 (candidates .
(lambda ()
2156 (loop with seq
= (anything-find-files-get-candidates)
2157 for fname in seq when
(funcall test fname
)
2159 (anything-find-files-get-candidates))))
2160 (candidate-transformer anything-c-highlight-ffiles
)
2161 (persistent-action . anything-find-files-persistent-action
)
2162 (persistent-help .
"Expand Candidate")
2164 (action .
(("candidate" .
,'identity
))))
2165 :input initial-input
2172 (defvar anything-c-source-file-cache-initialized nil
)
2174 (defvar anything-c-file-cache-files nil
)
2176 (defvar anything-c-source-file-cache
2177 '((name .
"File Cache")
2180 (require 'filecache nil t
)
2181 (unless anything-c-source-file-cache-initialized
2182 (setq anything-c-file-cache-files
2183 (loop for item in file-cache-alist append
2184 (destructuring-bind (base &rest dirs
) item
2185 (loop for dir in dirs collect
2186 (concat dir base
)))))
2187 (defadvice file-cache-add-file
(after file-cache-list activate
)
2188 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
2189 (setq anything-c-source-file-cache-initialized t
))))
2190 (candidates . anything-c-file-cache-files
)
2191 (match anything-c-match-on-file-name
2192 anything-c-match-on-directory-name
)
2194 ;; (anything 'anything-c-source-file-cache)
2197 ;; NOTE for WINDOZE users:
2198 ;; You have to install Everything with his command line interface here:
2199 ;; http://www.voidtools.com/download.php
2201 (defvar anything-c-locate-command
2203 ('gnu
/linux
"locate -i -r %s")
2204 ('berkeley-unix
"locate -i %s")
2205 ('windows-nt
"es -i -r %s")
2207 "A list of arguments for locate program.
2208 The \"-r\" option must be the last option.")
2210 (defun anything-c-locate-init ()
2211 "Initialize async locate process for `anything-c-source-locate'."
2212 (start-process-shell-command "locate-process" nil
2213 (format anything-c-locate-command
2216 (defvar anything-c-source-locate
2218 (candidates . anything-c-locate-init
)
2220 (requires-pattern .
3)
2222 "Find files matching the current input pattern with locate.")
2224 ;; (anything 'anything-c-source-locate)
2227 (defvar anything-c-source-recentf
2228 '((name .
"Recentf")
2231 (or recentf-mode
(recentf-mode 1))
2232 ;; Big value empowers anything/recentf
2233 (when (and (numberp recentf-max-saved-items
)
2234 (<= recentf-max-saved-items
20))
2235 (setq recentf-max-saved-items
500))))
2236 (candidates . recentf-list
)
2237 (match anything-c-match-on-file-name
2238 anything-c-match-on-directory-name
)
2240 "See (info \"(emacs)File Conveniences\").
2241 if `recentf-max-saved-items' is too small, set it to 500.")
2242 ;; (anything 'anything-c-source-recentf)
2245 (eval-when-compile (require 'ffap
))
2246 (defvar anything-c-source-ffap-guesser
2247 '((name .
"File at point")
2248 (init .
(lambda () (require 'ffap
)))
2249 (candidates .
(lambda ()
2251 (with-current-buffer anything-current-buffer
2255 ;; (anything 'anything-c-source-ffap-guesser)
2257 ;;; ffap with line number
2258 (defun anything-c-ffap-file-line-at-point ()
2259 "Get (FILENAME . LINENO) at point."
2260 (anything-aif (let (ffap-alist) (ffap-file-at-point))
2263 (when (and (search-forward it nil t
)
2264 (looking-at ":\\([0-9]+\\)"))
2265 (cons it
(string-to-number (match-string 1)))))))
2267 (defvar anything-c-ffap-line-location nil
2268 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
2269 It is cleared after jumping line.")
2271 (defun anything-c-ffap-line-candidates ()
2272 (with-current-buffer anything-current-buffer
2273 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
2274 (when anything-c-ffap-line-location
2275 (destructuring-bind (file . line
) anything-c-ffap-line-location
2276 (list (cons (format "%s (line %d)" file line
) file
)))))
2278 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
2279 (defun anything-c-ffap-line-goto-line ()
2280 (when (car anything-c-ffap-line-location
)
2283 (with-selected-window
2285 (get-file-buffer (car anything-c-ffap-line-location
)))
2286 (anything-goto-line (cdr anything-c-ffap-line-location
)))))))
2287 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
2288 (add-hook 'anything-after-persistent-action-hook
'anything-c-ffap-line-goto-line
)
2290 (defvar anything-c-source-ffap-line
2291 '((name .
"File/Lineno at point")
2292 (init .
(lambda () (require 'ffap
)))
2293 (candidates . anything-c-ffap-line-candidates
)
2295 ;; (anything 'anything-c-source-ffap-line)
2297 ;;; list of files gleaned from every dired buffer
2298 (defun anything-c-files-in-all-dired-candidates ()
2302 (cond ((listp dir
) ;filelist
2304 ((equal "" (file-name-nondirectory dir
)) ;dir
2305 (directory-files dir t
))
2307 (file-expand-wildcards dir t
))))
2309 (mapcar (lambda (buf)
2311 (when (eq major-mode
'dired-mode
)
2312 (if (consp dired-directory
)
2313 (cdr dired-directory
) ;filelist
2314 dired-directory
))) ;dir or wildcard
2316 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
2318 (defvar anything-c-source-files-in-all-dired
2319 '((name .
"Files in all dired buffer.")
2320 (candidates . anything-c-files-in-all-dired-candidates
)
2322 ;; (anything 'anything-c-source-files-in-all-dired)
2326 (defvar anything-c-info-pages nil
2327 "All info pages on system.
2328 Will be calculated the first time you invoke anything with this
2331 (defvar anything-c-source-info-pages
2332 `((name .
"Info Pages")
2335 (if anything-c-info-pages
2336 anything-c-info-pages
2337 (setq anything-c-info-pages
2338 (save-window-excursion
2341 (Info-find-node "dir" "top")
2342 (goto-char (point-min))
2343 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
2345 (while (re-search-forward info-topic-regexp nil t
)
2346 (add-to-list 'topics
(match-string-no-properties 1)))
2347 (goto-char (point-min))
2350 (action .
(("Show with Info" .
(lambda (node-str)
2351 (info (replace-regexp-in-string
2352 "^[^:]+: " "" node-str
))))))
2353 (requires-pattern .
2)))
2354 ;; (anything 'anything-c-source-info-pages)
2357 ;;; Use info-index plug-in. Note that `name' attribute is
2358 ;;; not needed but `anything-c-insert-summary' uses it.
2360 (defvar anything-c-source-info-elisp
2361 '((name .
"Info index: elisp")
2362 (info-index .
"elisp")))
2363 ;; (anything 'anything-c-source-info-elisp)
2366 (defvar anything-c-source-info-cl
2367 '((name .
"Info index: cl")
2368 (info-index .
"cl")))
2369 ;; (anything 'anything-c-source-info-cl)
2372 (defvar anything-c-source-info-org
2373 '((name .
"Info index: org")
2374 (info-index .
"org")))
2375 ;; (anything 'anything-c-source-info-org)
2377 ;; Info Index ratpoison
2378 (defvar anything-c-source-info-ratpoison
2379 '((name .
"Info index: ratpoison")
2380 (info-index .
"ratpoison")))
2381 ;; (anything 'anything-c-source-info-ratpoison)
2384 (defvar anything-c-source-info-zsh
2385 '((name .
"Info index: zsh")
2386 (info-index .
"zsh")))
2387 ;; (anything 'anything-c-source-info-zsh)
2390 (defvar anything-c-source-info-bash
2391 '((name .
"Info index: bash")
2392 (info-index .
"bash")))
2393 ;; (anything 'anything-c-source-info-bash)
2395 ;; Info Index coreutils
2396 (defvar anything-c-source-info-coreutils
2397 '((name .
"Info index: coreutils")
2398 (info-index .
"coreutils")))
2399 ;; (anything 'anything-c-source-info-coreutils)
2401 ;; Info Index fileutils
2402 (defvar anything-c-source-info-fileutils
2403 '((name .
"Info index: fileutils")
2404 (info-index .
"fileutils")))
2405 ;; (anything 'anything-c-source-info-fileutils)
2408 (defvar anything-c-source-info-find
2409 '((name .
"Info index: find")
2410 (info-index .
"find")))
2411 ;; (anything 'anything-c-source-info-find)
2413 ;; Info Index sh-utils
2414 (defvar anything-c-source-info-sh-utils
2415 '((name .
"Info index: sh-utils")
2416 (info-index .
"sh-utils")))
2417 ;; (anything 'anything-c-source-info-sh-utils)
2419 ;; Info Index textutils
2420 (defvar anything-c-source-info-textutils
2421 '((name .
"Info index: textutils")
2422 (info-index .
"textutils")))
2423 ;; (anything 'anything-c-source-info-textutils)
2426 (defvar anything-c-source-info-libc
2427 '((name .
"Info index: libc")
2428 (info-index .
"libc")))
2429 ;; (anything 'anything-c-source-info-libc)
2432 (defvar anything-c-source-info-make
2433 '((name .
"Info index: make")
2434 (info-index .
"make")))
2435 ;; (anything 'anything-c-source-info-make)
2437 ;; Info Index automake
2438 (defvar anything-c-source-info-automake
2439 '((name .
"Info index: automake")
2440 (info-index .
"automake")))
2441 ;; (anything 'anything-c-source-info-automake)
2443 ;; Info Index autoconf
2444 (defvar anything-c-source-info-autoconf
2445 '((name .
"Info index: autoconf")
2446 (info-index .
"autoconf")))
2447 ;; (anything 'anything-c-source-info-autoconf)
2449 ;; Info Index emacs-lisp-intro
2450 (defvar anything-c-source-info-emacs-lisp-intro
2451 '((name .
"Info index: emacs-lisp-intro")
2452 (info-index .
"emacs-lisp-intro")))
2453 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
2456 (defvar anything-c-source-info-emacs
2457 '((name .
"Info index: emacs")
2458 (info-index .
"emacs")))
2459 ;; (anything 'anything-c-source-info-emacs)
2462 (defvar anything-c-source-info-elib
2463 '((name .
"Info index: elib")
2464 (info-index .
"elib")))
2465 ;; (anything 'anything-c-source-info-elib)
2468 (defvar anything-c-source-info-eieio
2469 '((name .
"Info index: eieio")
2470 (info-index .
"eieio")))
2471 ;; (anything 'anything-c-source-info-eieio)
2473 ;; Info Index gauche-refe
2474 (defvar anything-c-source-info-gauche-refe
2475 '((name .
"Info index: gauche")
2476 (info-index .
"gauche-refe")))
2477 ;; (anything 'anything-c-source-info-gauche-refe)
2480 (defvar anything-c-source-info-guile
2481 '((name .
"Info index: guile")
2482 (info-index .
"guile")))
2483 ;; (anything 'anything-c-source-info-guile)
2485 ;; Info Index guile-tut
2486 (defvar anything-c-source-info-guile-tut
2487 '((name .
"Info index: guile-tut")
2488 (info-index .
"guile-tut")))
2489 ;; (anything 'anything-c-source-info-guile-tut)
2492 (defvar anything-c-source-info-goops
2493 '((name .
"Info index: goops")
2494 (info-index .
"goops")))
2495 ;; (anything 'anything-c-source-info-goops)
2497 ;; Info Index screen
2498 (defvar anything-c-source-info-screen
2499 '((name .
"Info index: screen")
2500 (info-index .
"screen")
2501 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
2502 ;; (anything 'anything-c-source-info-screen)
2505 (defvar anything-c-source-info-latex
2506 '((name .
"Info index: latex")
2507 (info-index .
"latex")))
2508 ;; (anything 'anything-c-source-info-latex)
2511 (defvar anything-c-source-info-gawk
2512 '((name .
"Info index: gawk")
2513 (info-index .
"gawk")))
2514 ;; (anything 'anything-c-source-info-gawk)
2517 (defvar anything-c-source-info-sed
2518 '((name .
"Info index: sed")
2519 (info-index .
"sed")))
2520 ;; (anything 'anything-c-source-info-sed)
2523 (defvar anything-c-source-info-m4
2524 '((name .
"Info index: m4")
2525 (info-index .
"m4")))
2526 ;; (anything 'anything-c-source-info-m4)
2529 (defvar anything-c-source-info-wget
2530 '((name .
"Info index: wget")
2531 (info-index .
"wget")))
2532 ;; (anything 'anything-c-source-info-wget)
2534 ;; Info Index binutils
2535 (defvar anything-c-source-info-binutils
2536 '((name .
"Info index: binutils")
2537 (info-index .
"binutils")))
2538 ;; (anything 'anything-c-source-info-binutils)
2541 (defvar anything-c-source-info-as
2542 '((name .
"Info index: as")
2543 (info-index .
"as")))
2544 ;; (anything 'anything-c-source-info-as)
2547 (defvar anything-c-source-info-bfd
2548 '((name .
"Info index: bfd")
2549 (info-index .
"bfd")))
2550 ;; (anything 'anything-c-source-info-bfd)
2553 (defvar anything-c-source-info-gprof
2554 '((name .
"Info index: gprof")
2555 (info-index .
"gprof")))
2556 ;; (anything 'anything-c-source-info-gprof)
2559 (defvar anything-c-source-info-ld
2560 '((name .
"Info index: ld")
2561 (info-index .
"ld")))
2562 ;; (anything 'anything-c-source-info-ld)
2565 (defvar anything-c-source-info-diff
2566 '((name .
"Info index: diff")
2567 (info-index .
"diff")))
2568 ;; (anything 'anything-c-source-info-diff)
2571 (defvar anything-c-source-info-flex
2572 '((name .
"Info index: flex")
2573 (info-index .
"flex")))
2574 ;; (anything 'anything-c-source-info-flex)
2577 (defvar anything-c-source-info-grep
2578 '((name .
"Info index: grep")
2579 (info-index .
"grep")))
2580 ;; (anything 'anything-c-source-info-grep)
2583 (defvar anything-c-source-info-gzip
2584 '((name .
"Info index: gzip")
2585 (info-index .
"gzip")))
2586 ;; (anything 'anything-c-source-info-gzip)
2588 ;; Info Index libtool
2589 (defvar anything-c-source-info-libtool
2590 '((name .
"Info index: libtool")
2591 (info-index .
"libtool")))
2592 ;; (anything 'anything-c-source-info-libtool)
2594 ;; Info Index texinfo
2595 (defvar anything-c-source-info-texinfo
2596 '((name .
"Info index: texinfo")
2597 (info-index .
"texinfo")))
2598 ;; (anything 'anything-c-source-info-texinfo)
2601 (defvar anything-c-source-info-info
2602 '((name .
"Info index: info")
2603 (info-index .
"info")))
2604 ;; (anything 'anything-c-source-info-info)
2607 (defvar anything-c-source-info-gdb
2608 '((name .
"Info index: gdb")
2609 (info-index .
"gdb")))
2610 ;; (anything 'anything-c-source-info-gdb)
2613 (defvar anything-c-source-info-stabs
2614 '((name .
"Info index: stabs")
2615 (info-index .
"stabs")))
2616 ;; (anything 'anything-c-source-info-stabs)
2618 ;; Info Index cvsbook
2619 (defvar anything-c-source-info-cvsbook
2620 '((name .
"Info index: cvsbook")
2621 (info-index .
"cvsbook")))
2622 ;; (anything 'anything-c-source-info-cvsbook)
2625 (defvar anything-c-source-info-cvs
2626 '((name .
"Info index: cvs")
2627 (info-index .
"cvs")))
2628 ;; (anything 'anything-c-source-info-cvs)
2631 (defvar anything-c-source-info-bison
2632 '((name .
"Info index: bison")
2633 (info-index .
"bison")))
2634 ;; (anything 'anything-c-source-info-bison)
2636 ;; Info Index id-utils
2637 (defvar anything-c-source-info-id-utils
2638 '((name .
"Info index: id-utils")
2639 (info-index .
"id-utils")))
2640 ;; (anything 'anything-c-source-info-id-utils)
2642 ;; Info Index global
2643 (defvar anything-c-source-info-global
2644 '((name .
"Info index: global")
2645 (info-index .
"global")))
2646 ;; (anything 'anything-c-source-info-global)
2650 (defvar anything-c-man-pages nil
2651 "All man pages on system.
2652 Will be calculated the first time you invoke anything with this
2655 (defvar anything-c-source-man-pages
2656 `((name .
"Manual Pages")
2657 (candidates .
(lambda ()
2658 (if anything-c-man-pages
2659 anything-c-man-pages
2660 ;; XEmacs doesn't have a woman :)
2661 (setq anything-c-man-pages
2664 (woman-file-name "")
2665 (sort (mapcar 'car woman-topic-all-completions
)
2667 (action ("Show with Woman"
2668 .
(lambda (candidate)
2669 (let ((wfiles (woman-file-name-all-completions candidate
)))
2670 (if (> (length wfiles
) 1)
2671 (woman-find-file (anything-comp-read "ManFile: " wfiles
2673 (woman candidate
))))))
2674 ;; Woman does not work OS X
2675 ;; http://xahlee.org/emacs/modernization_man_page.html
2676 (action-transformer .
(lambda (actions candidate
)
2677 (if (eq system-type
'darwin
)
2678 '(("Show with Man" . man
))
2680 (requires-pattern .
2)))
2681 ;; (anything 'anything-c-source-man-pages)
2684 ;;; Complex command history
2685 (defvar anything-c-source-complex-command-history
2686 '((name .
"Complex Command History")
2687 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
2689 ;; (anything 'anything-c-source-complex-command-history)
2692 (defvar anything-c-source-extended-command-history
2693 '((name .
"Emacs Commands History")
2694 (candidates . extended-command-history
)
2696 ;; (anything 'anything-c-source-extended-command-history)
2699 (defvar anything-c-source-emacs-commands
2700 '((name .
"Emacs Commands")
2701 (candidates .
(lambda ()
2703 (mapatoms (lambda (a)
2705 (push (symbol-name a
)
2707 (sort commands
'string-lessp
))))
2709 (requires-pattern .
2))
2710 "Source for completing and invoking Emacs commands.
2711 A command is a function with interactive spec that can
2712 be invoked with `M-x'.
2714 To get non-interactive functions listed, use
2715 `anything-c-source-emacs-functions'.")
2716 ;; (anything 'anything-c-source-emacs-commands)
2718 ;; Another replacement of `M-x' that act exactly like the
2719 ;; vanilla Emacs one, no problem of windows configuration, prefix args
2720 ;; are passed before calling `M-x' (e.g C-u M-x..).
2722 (defun anything-M-x ()
2723 "Preconfigured `anything' for Emacs commands.
2724 It is `anything' replacement of regular `M-x' `execute-extended-command'."
2726 (let ((command (anything-comp-read "M-x " obarray
2730 :name
"Emacs Commands"
2732 #'(lambda (candidate)
2733 (describe-function (intern candidate
)))
2734 :persistent-help
"Describe this command"
2735 :history extended-command-history
)))
2736 (call-interactively (intern command
))
2737 (setq extended-command-history
2738 (cons command
(delete command extended-command-history
)))))
2741 (defvar anything-c-source-lacarte
2742 '((name .
"Lacarte")
2743 (init .
(lambda () (require 'lacarte
)))
2744 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
2745 (candidate-number-limit .
9999)
2746 (action . anything-c-call-interactively
))
2749 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
2750 ;; (anything 'anything-c-source-lacarte)
2754 (defvar anything-c-source-emacs-functions
2755 '((name .
"Emacs Functions")
2756 (candidates .
(lambda ()
2758 (mapatoms (lambda (a)
2760 (push (symbol-name a
) commands
))))
2761 (sort commands
'string-lessp
))))
2763 (requires-pattern .
2))
2764 "Source for completing Emacs functions.")
2765 ;; (anything 'anything-c-source-emacs-functions)
2767 ;;; With abbrev expansion
2768 ;;; Similar to my exec-abbrev-cmd.el
2769 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
2770 (defvar anything-c-function-abbrev-regexp nil
2771 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
2772 Regexp built from the current `anything-pattern' interpreting it
2774 Only for internal use.")
2776 (defun anything-c-match-function-by-abbrev (candidate)
2777 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
2779 Abbreviations are made by taking the first character from each
2780 word in the function's name, e.g. \"bb\" is an abbrev for
2781 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
2782 (string-match anything-c-function-abbrev-regexp candidate
))
2784 (defvar anything-c-source-emacs-functions-with-abbrevs
2785 (append anything-c-source-emacs-functions
2786 '((match anything-c-match-function-by-abbrev
2787 anything-c-string-match
))
2790 (defadvice anything-update
2791 (before anything-c-update-function-abbrev-regexp activate
)
2792 (let ((char-list (append anything-pattern nil
))
2794 (dolist (c char-list
)
2795 (setq str
(concat str
(list c
) "[^-]*-")))
2796 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
2797 (setq anything-c-function-abbrev-regexp str
))))))))
2798 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
2800 (defvar anything-c-source-advice
2801 '((name .
"Function Advice")
2802 (candidates . anything-c-advice-candidates
)
2803 (action ("Toggle Enable/Disable" . anything-c-advice-toggle
))
2804 ;; (real-to-display . anything-c-advice-real-to-display)
2807 (persistent-action . anything-c-advice-persistent-action
)
2808 (persistent-help .
"Describe function / C-u C-z: Toggle advice")))
2809 ;; (anything 'anything-c-source-advice)
2810 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
2813 (defun anything-c-advice-candidates ()
2815 (loop for
(fname) in ad-advised-functions
2816 for function
= (intern fname
)
2818 (loop for class in ad-advice-classes append
2819 (loop for advice in
(ad-get-advice-info-field function class
)
2820 for enabled
= (ad-advice-enabled advice
)
2824 (if enabled
"Enabled " "Disabled")
2825 (propertize fname
'face
'font-lock-function-name-face
)
2826 (ad-make-single-advice-docstring advice class nil
))
2827 (list function class advice
))))))
2829 (defun anything-c-advice-persistent-action (func-class-advice)
2830 (if current-prefix-arg
2831 (anything-c-advice-toggle func-class-advice
)
2832 (describe-function (car func-class-advice
))))
2834 (defun anything-c-advice-toggle (func-class-advice)
2835 (destructuring-bind (function class advice
) func-class-advice
2836 (cond ((ad-advice-enabled advice
)
2837 (ad-advice-set-enabled advice nil
)
2838 (message "Disabled"))
2840 (ad-advice-set-enabled advice t
)
2841 (message "Enabled")))
2842 (ad-activate function
)
2843 (and anything-in-persistent-action
2844 (anything-c-advice-update-current-display-string))))
2846 (defun anything-c-advice-update-current-display-string ()
2847 (anything-edit-current-selection
2848 (let ((newword (cond ((looking-at "Disabled") "Enabled")
2849 ((looking-at "Enabled") "Disabled")))
2852 (delete-region (point) (progn (forward-word 1) (point)))
2853 (insert newword
)))))
2856 (defun anything-manage-advice ()
2857 "Preconfigured `anything' to disable/enable function advices."
2859 (anything-other-buffer 'anything-c-source-advice
"*anything advice*"))
2863 (defvar anything-c-source-emacs-variables
2864 '((name .
"Emacs Variables")
2865 (candidates .
(lambda ()
2866 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
2868 (requires-pattern .
2))
2869 "Source for completing Emacs variables.")
2870 ;; (anything 'anything-c-source-emacs-variables)
2874 (eval-when-compile (require 'bookmark
))
2875 (defvar anything-c-source-bookmarks
2876 '((name .
"Bookmarks")
2878 (require 'bookmark
)))
2879 (candidates . bookmark-all-names
)
2881 "See (info \"(emacs)Bookmarks\").")
2882 ;; (anything 'anything-c-source-bookmarks)
2885 (defvar anything-c-source-bookmark-set
2886 '((name .
"Set Bookmark")
2888 (action . bookmark-set
))
2889 "See (info \"(emacs)Bookmarks\").")
2890 ;; (anything 'anything-c-source-bookmark-set)
2892 ;;; Visible Bookmarks
2893 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
2896 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
2897 (defvar anything-c-source-bm
2898 '((name .
"Visible Bookmarks")
2899 (init . anything-c-bm-init
)
2900 (candidates-in-buffer)
2904 http://www.nongnu.org/bm/")
2906 (defun anything-c-bm-init ()
2907 "Init function for `anything-c-source-bm'."
2908 (when (require 'bm nil t
)
2910 (let ((bookmarks (bm-lists))
2911 (buf (anything-candidate-buffer 'global
)))
2912 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
2913 '< :key
'overlay-start
))
2914 (let ((start (overlay-start bm
))
2915 (end (overlay-end bm
))
2916 (annotation (or (overlay-get bm
'annotation
) "")))
2917 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
2918 (let ((str (format "%5d: [%s]: %s\n"
2919 (line-number-at-pos start
)
2921 (buffer-substring start
(1- end
)))))
2922 (with-current-buffer buf
(insert str
))))))))))
2924 ;;; Special bookmarks
2925 (defvar anything-c-source-bookmarks-ssh
2926 '((name .
"Bookmarks-ssh")
2928 (require 'bookmark
)))
2929 (candidates .
(lambda () (anything-c-collect-bookmarks :ssh t
)))
2931 "See (info \"(emacs)Bookmarks\").")
2932 ;; (anything 'anything-c-source-bookmarks-ssh)
2934 (defvar anything-c-source-bookmarks-su
2935 '((name .
"Bookmarks-root")
2937 (require 'bookmark
)))
2938 (candidates .
(lambda () (anything-c-collect-bookmarks :su t
)))
2939 (filtered-candidate-transformer anything-c-highlight-bookmark-su
)
2942 "See (info \"(emacs)Bookmarks\").")
2943 ;; (anything 'anything-c-source-bookmarks-su)
2945 (defvar anything-c-source-bookmarks-local
2946 '((name .
"Bookmarks-Local")
2948 (require 'bookmark
)))
2949 (candidates .
(lambda () (anything-c-collect-bookmarks :local t
)))
2950 (filtered-candidate-transformer
2951 anything-c-adaptive-sort
2952 anything-c-highlight-bookmark
)
2954 "See (info \"(emacs)Bookmarks\").")
2955 ;; (anything 'anything-c-source-bookmarks-local)
2957 (defun* anything-c-collect-bookmarks
(&key local su sudo ssh
)
2958 (let* ((lis-all (bookmark-all-names))
2959 (lis-loc (cond (local (loop for i in lis-all
2960 unless
(string-match "^(ssh)\\|^(su)" i
)
2962 (su (loop for i in lis-all
2963 when
(string-match "^(su)" i
)
2965 (sudo (loop for i in lis-all
2966 when
(string-match "^(sudo)" i
)
2968 (ssh (loop for i in lis-all
2969 when
(string-match "^(ssh)" i
)
2971 (sort lis-loc
'string-lessp
)))
2973 (defun anything-c-bookmark-root-logged-p ()
2975 (dolist (i (mapcar #'buffer-name
(buffer-list)))
2976 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
2977 (throw 'break t
)))))
2979 (defun anything-c-highlight-bookmark-su (files source
)
2980 (if (anything-c-bookmark-root-logged-p)
2981 (anything-c-highlight-bookmark files source
)
2982 (anything-c-highlight-not-logged files source
)))
2984 (defun anything-c-highlight-not-logged (files source
)
2985 (loop for i in files
2986 collect
(propertize i
'face anything-c-bookmarks-face3
)))
2988 (defun anything-c-highlight-bookmark (bookmarks source
)
2989 "Used as `candidate-transformer' to colorize bookmarks.
2990 Work both with standard Emacs bookmarks and bookmark-extensions.el."
2991 (loop for i in bookmarks
2992 for pred
= (bookmark-get-filename i
)
2993 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
2994 (bmkext-get-buffer-name i
))
2995 for handlerp
= (and (fboundp 'bookmark-get-handler
)
2996 (bookmark-get-handler i
))
2997 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
2998 (bmkext-w3m-bookmark-p i
))
2999 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
3000 (bmkext-gnus-bookmark-p i
))
3001 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
3002 (bmkext-man-bookmark-p i
))
3003 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
3004 (bmkext-woman-bookmark-p i
))
3005 for handlerp
= (bookmark-get-handler i
)
3006 for isannotation
= (bookmark-get-annotation i
)
3007 for isabook
= (string= (bookmark-prop-get i
'type
) "addressbook")
3008 ;; Add a * if bookmark have annotation
3009 if
(and isannotation
(not (string-equal isannotation
"")))
3010 do
(setq i
(concat "*" i
))
3012 if
(eq handlerp
'Info-bookmark-jump
)
3013 collect
(propertize i
'face
'anything-bmkext-info
'help-echo pred
)
3016 collect
(propertize i
'face
'anything-bmkext-w3m
'help-echo pred
)
3019 collect
(propertize i
'face
'anything-bmkext-gnus
'help-echo pred
)
3021 if
(or iswoman isman
)
3022 collect
(propertize i
'face
'anything-bmkext-man
'help-echo pred
)
3024 if
(and (not pred
) isabook
)
3025 collect
(propertize i
'face
'((:foreground
"Tomato")))
3027 if
(and pred
(file-directory-p pred
))
3028 collect
(propertize i
'face anything-c-bookmarks-face1
'help-echo pred
)
3030 if
(and pred
(not (file-directory-p pred
)) (file-exists-p pred
)
3031 (not (or iswoman isman
)))
3032 collect
(propertize i
'face
'anything-bmkext-file
'help-echo pred
)))
3035 ;;; Faces for bookmarks
3036 (defface anything-bmkext-info
3037 '((t (:foreground
"green")))
3038 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
3041 (defface anything-bmkext-w3m
3042 '((t (:foreground
"yellow")))
3043 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
3046 (defface anything-bmkext-gnus
3047 '((t (:foreground
"magenta")))
3048 "*Face used for Gnus bookmarks."
3051 (defface anything-bmkext-man
3052 '((t (:foreground
"Orange4")))
3053 "*Face used for Woman/man bookmarks."
3056 (defface anything-bmkext-no--file
3057 '((t (:foreground
"grey")))
3058 "*Face used for non--file bookmarks."
3061 (defface anything-bmkext-file
3062 '((t (:foreground
"Deepskyblue2")))
3063 "*Face used for non--file bookmarks."
3066 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
3067 "Face for su/sudo bookmarks."
3070 (defvar anything-c-bookmarks-face1
'anything-dir-heading
)
3071 (defvar anything-c-bookmarks-face2
'anything-file-name
)
3072 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
3075 ;;; Sources to filter bookmark-extensions bookmarks.
3076 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
3077 ;; If you want to enable google-maps in addressbook you will need
3078 ;; Julien Danjou google-maps-el package available here:
3079 ;; http://julien.danjou.info/google-maps-el.html
3081 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
3082 "Return a filtered `bookmark-alist' sorted alphabetically."
3084 with alist
= (if args
3085 (apply #'(lambda (x) (funcall fn x
)) args
)
3090 finally return
(sort sa
'string-lessp
)))
3093 (defvar anything-c-source-bmkext-addressbook
3094 '((name .
"Bookmark Addressbook")
3096 (require 'bookmark-extensions
)
3097 (bookmark-maybe-load-default-file)))
3098 (candidates . anything-c-bmkext-addressbook-setup-alist
)
3100 .
(lambda (candidate)
3101 (let ((bmk (anything-bookmark-get-bookmark-from-name
3103 (bookmark--jump-via bmk
'pop-to-buffer
))))
3104 (persistent-help .
"Show contact - Prefix with C-u to append")
3105 (filtered-candidate-transformer
3106 anything-c-adaptive-sort
3107 anything-c-highlight-bookmark
)
3108 (action .
(("Show person's data"
3109 .
(lambda (candidate)
3110 (let ((bmk (anything-bookmark-get-bookmark-from-name
3112 (current-prefix-arg anything-current-prefix-arg
))
3113 (bookmark-jump bmk
))))
3115 .
(lambda (candidate)
3116 (let ((bmk (anything-bookmark-get-bookmark-from-name
3118 (if anything-current-prefix-arg
3119 (addressbook-set-mail-buffer1 bmk
'append
)
3120 (addressbook-set-mail-buffer1 bmk
)))))
3122 .
(lambda (candidate)
3123 (let ((bmk (anything-bookmark-get-bookmark-from-name
3125 (addressbook-bookmark-edit
3126 (assoc bmk bookmark-alist
)))))
3127 ("Insert Email at point"
3128 .
(lambda (candidate)
3129 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3131 (mlist (split-string
3133 'email
(assoc bmk bookmark-alist
))
3136 (if (> (length mlist
) 1)
3138 "Insert Mail Address: " mlist
:must-match t
)
3141 .
(lambda (candidate)
3142 (let ((bmk (anything-bookmark-get-bookmark-from-name
3144 (bookmark-show-annotation bmk
))))
3146 .
(lambda (candidate)
3147 (let ((bmk (anything-bookmark-get-bookmark-from-name
3149 (bookmark-edit-annotation bmk
))))
3151 .
(lambda (candidate)
3152 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3154 (full-bmk (assoc bmk bookmark-alist
)))
3155 (addressbook-google-map full-bmk
))))))))
3158 (defun anything-c-bmkext-addressbook-setup-alist ()
3159 "Specialized filter function for bookmarks w3m."
3160 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only
))
3163 (defvar anything-c-source-bookmark-w3m
3164 '((name .
"Bookmark W3m")
3166 (require 'bookmark-extensions
)
3167 (bookmark-maybe-load-default-file)))
3168 (candidates . anything-c-bookmark-w3m-setup-alist
)
3169 (filtered-candidate-transformer
3170 anything-c-adaptive-sort
3171 anything-c-highlight-bookmark
)
3173 ;; (anything 'anything-c-source-bookmark-w3m)
3175 (defun anything-c-bookmark-w3m-setup-alist ()
3176 "Specialized filter function for bookmarks w3m."
3177 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
3180 (defvar anything-c-source-bookmark-images
3181 '((name .
"Bookmark Images")
3183 (require 'bookmark-extensions
)
3184 (bookmark-maybe-load-default-file)))
3185 (candidates . anything-c-bookmark-images-setup-alist
)
3186 (filtered-candidate-transformer
3187 anything-c-adaptive-sort
3188 anything-c-highlight-bookmark
)
3190 ;; (anything 'anything-c-source-bookmark-images)
3192 (defun anything-c-bookmark-images-setup-alist ()
3193 "Specialized filter function for images bookmarks."
3194 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only
))
3197 (defvar anything-c-source-bookmark-man
3198 '((name .
"Bookmark Woman&Man")
3200 (require 'bookmark-extensions
)
3201 (bookmark-maybe-load-default-file)))
3202 (candidates . anything-c-bookmark-man-setup-alist
)
3203 (filtered-candidate-transformer
3204 anything-c-adaptive-sort
3205 anything-c-highlight-bookmark
)
3207 ;; (anything 'anything-c-source-bookmark-man)
3209 (defun anything-c-bookmark-man-setup-alist ()
3210 "Specialized filter function for bookmarks w3m."
3211 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
3212 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
3215 (defvar anything-c-source-bookmark-gnus
3216 '((name .
"Bookmark Gnus")
3218 (require 'bookmark-extensions
)
3219 (bookmark-maybe-load-default-file)))
3220 (candidates . anything-c-bookmark-gnus-setup-alist
)
3221 (filtered-candidate-transformer
3222 anything-c-adaptive-sort
3223 anything-c-highlight-bookmark
)
3225 ;; (anything 'anything-c-source-bookmark-gnus)
3227 (defun anything-c-bookmark-gnus-setup-alist ()
3228 "Specialized filter function for bookmarks gnus."
3229 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
3232 (defvar anything-c-source-bookmark-info
3233 '((name .
"Bookmark Info")
3235 (require 'bookmark-extensions
)
3236 (bookmark-maybe-load-default-file)))
3237 (candidates . anything-c-bookmark-info-setup-alist
)
3238 (filtered-candidate-transformer
3239 anything-c-adaptive-sort
3240 anything-c-highlight-bookmark
)
3242 ;; (anything 'anything-c-source-bookmark-info)
3244 (defun anything-c-bookmark-info-setup-alist ()
3245 "Specialized filter function for bookmarks info."
3246 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
3248 ;; Local Files&directories
3249 (defvar anything-c-source-bookmark-files
&dirs
3250 '((name .
"Bookmark Files&Directories")
3252 (require 'bookmark-extensions
)
3253 (bookmark-maybe-load-default-file)))
3254 (candidates . anything-c-bookmark-local-files-setup-alist
)
3255 (filtered-candidate-transformer
3256 anything-c-adaptive-sort
3257 anything-c-highlight-bookmark
)
3259 ;; (anything 'anything-c-source-bookmark-files&dirs)
3261 (defun anything-c-bookmark-local-files-setup-alist ()
3262 "Specialized filter function for bookmarks locals files."
3263 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
3265 ;; Su Files&directories
3266 (defvar anything-c-source-bookmark-su-files
&dirs
3267 '((name .
"Bookmark Root-Files&Directories")
3269 (require 'bookmark-extensions
)
3270 (bookmark-maybe-load-default-file)))
3271 (candidates . anything-c-bookmark-su-files-setup-alist
)
3272 (filtered-candidate-transformer
3273 anything-c-adaptive-sort
3274 anything-c-highlight-bookmark-su
)
3276 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
3278 (defun anything-c-bookmark-su-files-setup-alist ()
3279 "Specialized filter function for bookmarks su/sudo files."
3281 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
3283 for isfile
= (bookmark-get-filename i
)
3284 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
3286 (string-match tramp-file-name-regexp isfile
)))
3287 for issu
= (and istramp
3288 (string-match bmkext-su-or-sudo-regexp isfile
))
3292 ;; Ssh Files&directories
3293 (defvar anything-c-source-bookmark-ssh-files
&dirs
3294 '((name .
"Bookmark Ssh-Files&Directories")
3296 (require 'bookmark-extensions
)
3297 (bookmark-maybe-load-default-file)))
3298 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
3299 (filtered-candidate-transformer . anything-c-adaptive-sort
)
3301 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
3303 (defun anything-c-bookmark-ssh-files-setup-alist ()
3304 "Specialized filter function for bookmarks ssh files."
3306 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
3308 for isfile
= (bookmark-get-filename i
)
3309 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
3311 (string-match tramp-file-name-regexp isfile
)))
3312 for isssh
= (and istramp
3313 (string-match "/ssh:" isfile
))
3318 ;; All bookmark-extensions sources.
3320 (defun anything-bookmark-ext ()
3321 "Preconfigured `anything' for bookmark-extensions sources.
3322 Needs bookmark-ext.el
3324 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
3328 '(anything-c-source-bookmark-files&dirs
3329 anything-c-source-bookmark-w3m
3330 anything-c-source-bmkext-addressbook
3331 anything-c-source-bookmark-gnus
3332 anything-c-source-bookmark-info
3333 anything-c-source-bookmark-man
3334 anything-c-source-bookmark-images
3335 anything-c-source-bookmark-su-files
&dirs
3336 anything-c-source-bookmark-ssh-files
&dirs
)
3337 :prompt
"SearchBookmark: "
3338 :buffer
"*anything bmkext*"))
3341 ;; Firefox bookmarks
3342 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
3343 ;; (only for firefox versions >=3)
3344 ;; To achieve that, open about:config in firefox and double click on this line to enable value
3346 ;; user_pref("browser.bookmarks.autoExportHTML", false);
3347 ;; You should have now:
3348 ;; user_pref("browser.bookmarks.autoExportHTML", true);
3350 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ ]*")
3351 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
3353 (defun anything-get-firefox-user-init-dir ()
3354 "Guess the default Firefox user directory name."
3355 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
3357 (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
3358 (goto-char (point-min))
3359 (when (search-forward "Path=" nil t
)
3360 (buffer-substring-no-properties (point) (point-at-eol))))))
3361 (file-name-as-directory (concat moz-dir moz-user-dir
))))
3363 (defun anything-guess-firefox-bookmark-file ()
3364 "Return the path of the Firefox bookmarks file."
3365 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
3367 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
3368 "Parse html bookmark FILE and return an alist with (title . url) as elements."
3369 (let (bookmarks-alist url title
)
3371 (insert-file-contents file
)
3372 (goto-char (point-min))
3375 (when (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
3377 (when (re-search-forward url-regexp nil t
)
3378 (setq url
(concat "\"" (match-string 0))))
3380 (when (re-search-forward bmk-regexp nil t
)
3381 (setq title
(match-string 1)))
3382 (push (cons title url
) bookmarks-alist
))))
3383 (nreverse bookmarks-alist
)))
3386 (defvar anything-c-firefox-bookmarks-alist nil
)
3387 (defvar anything-c-source-firefox-bookmarks
3388 '((name .
"Firefox Bookmarks")
3390 (setq anything-c-firefox-bookmarks-alist
3391 (anything-html-bookmarks-to-alist
3392 (anything-guess-firefox-bookmark-file)
3393 anything-firefox-bookmark-url-regexp
3394 anything-firefox-bookmarks-regexp
))))
3395 (candidates .
(lambda ()
3397 anything-c-firefox-bookmarks-alist
)))
3398 (filtered-candidate-transformer
3399 anything-c-adaptive-sort
3400 anything-c-highlight-firefox-bookmarks
)
3401 (action .
(("Browse Url Firefox"
3402 .
(lambda (candidate)
3404 (anything-c-firefox-bookmarks-get-value candidate
))))
3406 .
(lambda (candidate)
3408 (anything-c-firefox-bookmarks-get-value candidate
))))
3411 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
3413 ;; (anything 'anything-c-source-firefox-bookmarks)
3415 (defun anything-c-firefox-bookmarks-get-value (elm)
3416 (replace-regexp-in-string "\"" ""
3418 anything-c-firefox-bookmarks-alist
))))
3421 (defun anything-c-highlight-firefox-bookmarks (bookmarks source
)
3422 (loop for i in bookmarks
3425 'face
'((:foreground
"YellowGreen"))
3426 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
3429 (eval-when-compile (require 'w3m-bookmark nil t
))
3430 (unless (and (require 'w3m nil t
)
3431 (require 'w3m-bookmark nil t
))
3432 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html"))
3435 (defface anything-w3m-bookmarks-face
'((t (:foreground
"cyan1" :underline t
)))
3436 "Face for w3m bookmarks" :group
'anything
)
3438 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
3439 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
3440 (defvar anything-c-w3m-bookmarks-alist nil
)
3441 (defvar anything-c-source-w3m-bookmarks
3442 '((name .
"W3m Bookmarks")
3444 (setq anything-c-w3m-bookmarks-alist
3445 (anything-html-bookmarks-to-alist
3447 anything-w3m-bookmark-url-regexp
3448 anything-w3m-bookmarks-regexp
))))
3449 (candidates .
(lambda ()
3450 (mapcar #'car anything-c-w3m-bookmarks-alist
)))
3451 (filtered-candidate-transformer
3452 anything-c-adaptive-sort
3453 anything-c-highlight-w3m-bookmarks
)
3454 (action .
(("Browse Url"
3455 .
(lambda (candidate)
3456 (anything-c-w3m-browse-bookmark candidate
)))
3459 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
3460 ("Browse Url Firefox"
3461 .
(lambda (candidate)
3462 (anything-c-w3m-browse-bookmark candidate t
)))
3464 .
(lambda (candidate)
3465 (anything-c-w3m-delete-bookmark candidate
)))
3467 .
(lambda (candidate)
3468 (anything-c-w3m-rename-bookmark candidate
)))))
3469 (persistent-action .
(lambda (candidate)
3470 (if current-prefix-arg
3471 (anything-c-w3m-browse-bookmark candidate t
)
3472 (anything-c-w3m-browse-bookmark candidate nil t
))))
3473 (persistent-help .
"Open URL with emacs-w3m in new tab / \
3474 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
3475 "Needs w3m and emacs-w3m.
3477 http://w3m.sourceforge.net/
3478 http://emacs-w3m.namazu.org/")
3480 ;; (anything 'anything-c-source-w3m-bookmarks)
3482 (defun anything-c-w3m-bookmarks-get-value (elm)
3483 (replace-regexp-in-string
3484 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist
))))
3486 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
3487 (let* ((fn (if use-firefox
'browse-url-firefox
'w3m-browse-url
))
3488 (arg (and (eq fn
'w3m-browse-url
) new-tab
)))
3489 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
3491 (defun anything-c-highlight-w3m-bookmarks (bookmarks source
)
3492 (loop for i in bookmarks
3494 i
'face
'anything-w3m-bookmarks-face
3495 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
3498 (defun anything-c-w3m-delete-bookmark (elm)
3500 (find-file-literally w3m-bookmark-file
)
3501 (goto-char (point-min))
3502 (when (re-search-forward elm nil t
)
3504 (delete-region (point)
3505 (line-end-position))
3506 (delete-blank-lines))
3507 (save-buffer (current-buffer))
3508 (kill-buffer (current-buffer))))
3510 (defun anything-c-w3m-rename-bookmark (elm)
3511 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
3512 (new-title (read-string "NewTitle: " old-title
)))
3514 (find-file-literally w3m-bookmark-file
)
3515 (goto-char (point-min))
3516 (when (re-search-forward (concat elm
"<") nil t
)
3517 (goto-char (1- (point)))
3518 (delete-char (- (length old-title
)))
3520 (save-buffer (current-buffer))
3521 (kill-buffer (current-buffer)))))
3524 ;;; Elisp library scan
3525 (defvar anything-c-source-elisp-library-scan
3526 '((name .
"Elisp libraries (Scan)")
3527 (init .
(anything-c-elisp-library-scan-init))
3528 (candidates-in-buffer)
3529 (action ("Find library"
3530 .
(lambda (candidate) (find-file (find-library-name candidate
))))
3531 ("Find library other window"
3532 .
(lambda (candidate)
3533 (find-file-other-window (find-library-name candidate
))))
3535 .
(lambda (candidate) (load-library candidate
))))))
3536 ;; (anything 'anything-c-source-elisp-library-scan)
3538 (defun anything-c-elisp-library-scan-init ()
3539 "Init anything buffer status."
3540 (let ((anything-buffer (anything-candidate-buffer 'global
))
3541 (library-list (anything-c-elisp-library-scan-list)))
3542 (with-current-buffer anything-buffer
3543 (dolist (library library-list
)
3544 (insert (format "%s\n" library
))))))
3546 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
3547 "Do completion for file names passed to `locate-file'.
3548 DIRS is directory to search path.
3549 STRING is string to match."
3550 ;; Use `load-path' as path when ignore `dirs'.
3551 (or dirs
(setq dirs load-path
))
3552 ;; Init with blank when ignore `string'.
3553 (or string
(setq string
""))
3554 ;; Get library list.
3555 (let ((string-dir (file-name-directory string
))
3556 ;; File regexp that suffix match `load-file-rep-suffixes'.
3557 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
3562 (setq dir default-directory
))
3564 (setq dir
(expand-file-name string-dir dir
)))
3565 (when (file-directory-p dir
)
3566 (dolist (file (file-name-all-completions
3567 (file-name-nondirectory string
) dir
))
3568 ;; Suffixes match `load-file-rep-suffixes'.
3569 (setq name
(if string-dir
(concat string-dir file
) file
))
3570 (if (string-match match-regexp name
)
3571 (add-to-list 'names name
)))))
3576 (defvar anything-c-imenu-delimiter
" / ")
3578 (defvar anything-c-imenu-index-filter nil
)
3579 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
3581 (defvar anything-c-cached-imenu-alist nil
)
3582 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
3584 (defvar anything-c-cached-imenu-candidates nil
)
3585 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
3587 (defvar anything-c-cached-imenu-tick nil
)
3588 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
3590 (eval-when-compile (require 'imenu
))
3591 (setq imenu-auto-rescan t
)
3593 (defun anything-imenu-create-candidates (entry)
3594 "Create candidates with ENTRY."
3595 (if (listp (cdr entry
))
3598 (if (consp (cdr sub
))
3601 (concat (car entry
) anything-c-imenu-delimiter subentry
))
3602 (anything-imenu-create-candidates sub
))
3603 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
3607 (defvar anything-c-source-imenu
3609 (init .
(lambda () (require 'imenu
)))
3610 (candidates . anything-c-imenu-candidates
)
3611 (persistent-action .
(lambda (elm)
3612 (anything-c-imenu-default-action elm
)
3613 (unless (fboundp 'semantic-imenu-tag-overlay
)
3614 (anything-match-line-color-current-line))))
3615 (persistent-help .
"Show this entry")
3616 (action . anything-c-imenu-default-action
))
3617 "See (info \"(emacs)Imenu\")")
3619 ;; (anything 'anything-c-source-imenu)
3621 (defun anything-c-imenu-candidates ()
3622 (with-current-buffer anything-current-buffer
3623 (let ((tick (buffer-modified-tick)))
3624 (if (eq anything-c-cached-imenu-tick tick
)
3625 anything-c-cached-imenu-candidates
3626 (setq imenu--index-alist nil
)
3627 (setq anything-c-cached-imenu-tick tick
3628 anything-c-cached-imenu-candidates
3631 'anything-imenu-create-candidates
3632 (setq anything-c-cached-imenu-alist
3633 (let ((index (imenu--make-index-alist)))
3634 (if anything-c-imenu-index-filter
3635 (funcall anything-c-imenu-index-filter index
)
3637 (setq anything-c-cached-imenu-candidates
3638 (mapcar #'(lambda (x)
3642 anything-c-cached-imenu-candidates
))))))
3644 (setq imenu-default-goto-function
'imenu-default-goto-function
)
3645 (defun anything-c-imenu-default-action (elm)
3646 "The default action for `anything-c-source-imenu'."
3647 (let ((path (split-string elm anything-c-imenu-delimiter
))
3648 (alist anything-c-cached-imenu-alist
))
3649 (if (> (length path
) 1)
3651 (setq alist
(assoc (car path
) alist
))
3652 (setq elm
(cadr path
))
3653 (imenu (assoc elm alist
)))
3654 (imenu (assoc elm alist
)))))
3657 (defvar anything-c-ctags-modes
3658 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
3659 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
3660 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
3662 (defun anything-c-source-ctags-init ()
3663 (when (and buffer-file-name
3664 (memq major-mode anything-c-ctags-modes
)
3665 (anything-current-buffer-is-modified))
3666 (with-current-buffer (anything-candidate-buffer 'local
)
3667 (call-process-shell-command
3668 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
3669 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
3670 anything-buffer-file-name
)
3671 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
3672 nil
(current-buffer))
3673 (goto-char (point-min))
3675 (delete-region (point-min) (point))
3676 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
3677 for lineno-start
= (point)
3678 for lineno
= (buffer-substring
3680 (1- (search-forward "," (point-at-eol) t
)))
3683 (insert (format "%5s:" lineno
))
3684 (search-forward "\177" (point-at-eol) t
)
3685 (delete-region (1- (point)) (point-at-eol))
3686 (forward-line 1)))))
3688 (defvar anything-c-source-ctags
3689 '((name .
"Exuberant ctags")
3690 (init . anything-c-source-ctags-init
)
3691 (candidates-in-buffer)
3694 "Needs Exuberant Ctags.
3696 http://ctags.sourceforge.net/")
3697 ;; (anything 'anything-c-source-ctags)
3700 (eval-when-compile (require 'semantic nil t
))
3701 (declare-function semantic-format-tag-summarize
"ext:format.el" (tag &optional parent color
) t
)
3702 (declare-function semantic-tag-components
"ext:tag.el" (tag) t
)
3703 (declare-function semantic-go-to-tag
"ext:tag-file.el" (tag) t
)
3704 (defvar anything-semantic-candidates nil
)
3706 (defun anything-semantic-construct-candidates (tags depth
)
3707 (when (require 'semantic nil t
)
3713 (let ((type (semantic-tag-type tag
))
3714 (class (semantic-tag-class tag
)))
3715 (if (or (and (stringp type
)
3716 (or (string= type
"class")
3717 (string= type
"namespace")))
3718 (eq class
'function
)
3719 (eq class
'variable
))
3720 (cons (cons (concat (make-string (* depth
2) ?\s
)
3721 (semantic-format-tag-summarize tag nil t
))
3723 (anything-semantic-construct-candidates
3724 (semantic-tag-components tag
) (1+ depth
)))))))
3727 (defun anything-semantic-default-action (candidate)
3728 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
3729 (semantic-go-to-tag tag
)))
3731 (defvar anything-c-source-semantic
3732 '((name .
"Semantic Tags")
3734 (setq anything-semantic-candidates
3735 (ignore-errors (anything-semantic-construct-candidates
3736 (semantic-fetch-tags) 0)))))
3737 (candidates .
(lambda ()
3738 (if anything-semantic-candidates
3739 (mapcar 'car anything-semantic-candidates
))))
3740 (persistent-action .
(lambda (elm)
3741 (anything-semantic-default-action elm
)
3742 (anything-match-line-color-current-line)))
3743 (persistent-help .
"Show this entry")
3744 (action . anything-semantic-default-action
)
3745 "Needs semantic in CEDET.
3747 http://cedet.sourceforge.net/semantic.shtml
3748 http://cedet.sourceforge.net/"))
3750 ;; (anything 'anything-c-source-semantic)
3752 ;;; Function is called by
3754 (defun anything-simple-call-tree ()
3755 "Preconfigured `anything' for simple-call-tree. List function relationships.
3757 Needs simple-call-tree.el.
3758 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
3760 (anything-other-buffer
3761 '(anything-c-source-simple-call-tree-functions-callers
3762 anything-c-source-simple-call-tree-callers-functions
)
3763 "*anything simple-call-tree*"))
3765 (defvar anything-c-source-simple-call-tree-functions-callers
3766 '((name .
"Function is called by")
3767 (init . anything-c-simple-call-tree-functions-callers-init
)
3769 (candidates . anything-c-simple-call-tree-candidates
)
3770 (persistent-action . anything-c-simple-call-tree-persistent-action
)
3771 (persistent-help .
"Show function definitions by rotation")
3772 (action ("Find definition selected by persistent-action" .
3773 anything-c-simple-call-tree-find-definition
)))
3774 "Needs simple-call-tree.el.
3775 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3777 (defvar anything-c-simple-call-tree-tick nil
)
3778 (make-variable-buffer-local 'anything-c-simple-call-tree-tick
)
3779 (defun anything-c-simple-call-tree-analyze-maybe ()
3780 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick
)
3781 (simple-call-tree-analyze)
3782 (setq anything-c-simple-call-tree-tick
(buffer-chars-modified-tick))))
3784 (defun anything-c-simple-call-tree-init-base (function message
)
3785 (require 'simple-call-tree
)
3787 (when (anything-current-buffer-is-modified)
3788 (anything-c-simple-call-tree-analyze-maybe)
3789 (let ((list (funcall function simple-call-tree-alist
)))
3790 (with-current-buffer (anything-candidate-buffer 'local
)
3791 (dolist (entry list
)
3792 (let ((funcs (concat " " (mapconcat #'identity
(cdr entry
) "\n "))))
3793 (insert (car entry
) message
3794 (if (string= funcs
" ")
3799 (defun anything-c-simple-call-tree-functions-callers-init ()
3800 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
3803 (defun anything-c-simple-call-tree-candidates ()
3804 (with-current-buffer (anything-candidate-buffer)
3805 (split-string (buffer-string) "\n\n")))
3807 (defvar anything-c-simple-call-tree-related-functions nil
)
3808 (defvar anything-c-simple-call-tree-function-index
0)
3809 (defun anything-c-simple-call-tree-persistent-action (candidate)
3810 (unless (eq last-command
'anything-execute-persistent-action
)
3811 (setq anything-c-simple-call-tree-related-functions
3812 (delete "no functions."
3814 (replace-regexp-in-string " \\| is called by\\| calls "
3817 (setq anything-c-simple-call-tree-function-index -
1))
3818 (incf anything-c-simple-call-tree-function-index
)
3819 (anything-c-simple-call-tree-find-definition candidate
))
3821 (defun anything-c-simple-call-tree-find-definition (candidate)
3824 (nth (mod anything-c-simple-call-tree-function-index
3825 (length anything-c-simple-call-tree-related-functions
))
3826 anything-c-simple-call-tree-related-functions
))))
3828 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
3831 (defvar anything-c-source-simple-call-tree-callers-functions
3832 '((name .
"Function calls")
3833 (init . anything-c-simple-call-tree-callers-functions-init
)
3835 (candidates . anything-c-simple-call-tree-candidates
)
3836 (persistent-action . anything-c-simple-call-tree-persistent-action
)
3837 (persistent-help .
"Show function definitions by rotation")
3838 (action ("Find definition selected by persistent-action" .
3839 anything-c-simple-call-tree-find-definition
)))
3840 "Needs simple-call-tree.el.
3841 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3843 (defun anything-c-simple-call-tree-callers-functions-init ()
3844 (anything-c-simple-call-tree-init-base 'identity
" calls \n"))
3846 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
3848 ;;; Commands/Options with doc
3849 (defvar anything-c-auto-document-data nil
)
3850 (make-variable-buffer-local 'anything-c-auto-document-data
)
3851 (defvar anything-c-source-commands-and-options-in-file
3852 '((name .
"Commands/Options in file")
3854 .
(lambda (x) (format "Commands/Options in %s"
3855 (buffer-local-value 'buffer-file-name
3856 anything-current-buffer
))))
3857 (candidates . anything-command-and-options-candidates
)
3860 "List Commands and Options with doc. It needs auto-document.el .
3862 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
3864 (eval-when-compile (require 'auto-document nil t
))
3865 (defun anything-command-and-options-candidates ()
3866 (with-current-buffer anything-current-buffer
3867 (when (and (require 'auto-document nil t
)
3868 (eq major-mode
'emacs-lisp-mode
)
3869 (or (anything-current-buffer-is-modified)
3870 (not anything-c-auto-document-data
)))
3871 (or imenu--index-alist
(imenu--make-index-alist t
))
3872 (setq anything-c-auto-document-data
3873 (destructuring-bind (commands options
)
3874 (adoc-construct anything-current-buffer
)
3876 (loop for
(command . doc
) in commands
3877 for cmdname
= (symbol-name command
)
3880 (format "Command: %s\n %s"
3881 (propertize cmdname
'face font-lock-function-name-face
)
3882 (adoc-first-line doc
))
3883 (assoc cmdname imenu--index-alist
)))
3884 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
3885 for
(option doc default
) in options
3886 for optname
= (symbol-name option
)
3889 (format "Option: %s\n %s\n default = %s"
3890 (propertize optname
'face font-lock-variable-name-face
)
3891 (adoc-first-line doc
)
3892 (adoc-prin1-to-string default
))
3895 anything-c-auto-document-data
))
3897 ;; (anything 'anything-c-source-commands-and-options-in-file)
3899 ;;;; <Color and Face>
3901 (defvar anything-c-source-customize-face
3902 '((name .
"Customize Face")
3904 (unless (anything-candidate-buffer)
3905 (save-window-excursion (list-faces-display))
3906 (anything-candidate-buffer (get-buffer "*Faces*")))))
3907 (candidates-in-buffer)
3908 (get-line . buffer-substring
)
3909 (action .
(lambda (line)
3910 (customize-face (intern (car (split-string line
))))))
3911 (requires-pattern .
3))
3912 "See (info \"(emacs)Faces\")")
3913 ;; (anything 'anything-c-source-customize-face)
3916 (defvar anything-c-source-colors
3918 (init .
(lambda () (unless (anything-candidate-buffer)
3919 (save-window-excursion (list-colors-display))
3920 (anything-candidate-buffer (get-buffer "*Colors*")))))
3921 (candidates-in-buffer)
3922 (get-line . buffer-substring
)
3924 ("Copy Name" .
(lambda (candidate)
3925 (kill-new (anything-c-colors-get-name candidate
))))
3926 ("Copy RGB" .
(lambda (candidate)
3927 (kill-new (anything-c-colors-get-rgb candidate
))))
3928 ("Insert Name" .
(lambda (candidate)
3929 (with-current-buffer anything-current-buffer
3930 (insert (anything-c-colors-get-name candidate
)))))
3931 ("Insert RGB" .
(lambda (candidate)
3932 (with-current-buffer anything-current-buffer
3933 (insert (anything-c-colors-get-rgb candidate
))))))))
3934 ;; (anything 'anything-c-source-colors)
3936 (defun anything-c-colors-get-name (candidate)
3938 (replace-regexp-in-string
3941 (insert (capitalize candidate
))
3942 (goto-char (point-min))
3943 (search-forward-regexp "\\s-\\{2,\\}")
3944 (delete-region (point) (point-max))
3947 (defun anything-c-colors-get-rgb (candidate)
3949 (replace-regexp-in-string
3952 (insert (capitalize candidate
))
3953 (goto-char (point-max))
3954 (search-backward-regexp "\\s-\\{2,\\}")
3955 (delete-region (point) (point-min))
3958 ;;;; <Search Engine>
3959 ;;; Tracker desktop search
3960 (defvar anything-c-source-tracker-search
3961 '((name .
"Tracker Search")
3962 (candidates .
(lambda ()
3963 (start-process "tracker-search-process" nil
3967 (requires-pattern .
3)
3969 "Source for retrieving files matching the current input pattern
3970 with the tracker desktop search.")
3971 ;; (anything 'anything-c-source-tracker-search)
3973 ;;; Spotlight (MacOS X desktop search)
3974 (defvar anything-c-source-mac-spotlight
3977 .
(lambda () (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
3979 (requires-pattern .
3)
3981 "Source for retrieving files via Spotlight's command line
3983 ;; (anything 'anything-c-source-mac-spotlight)
3988 (defvar anything-c-source-kill-ring
3989 '((name .
"Kill Ring")
3990 (init .
(lambda () (anything-attrset 'last-command last-command
)))
3991 (candidates . anything-c-kill-ring-candidates
)
3992 (action . anything-c-kill-ring-action
)
3996 "Source for browse and insert contents of kill-ring.")
3998 (defun anything-c-kill-ring-candidates ()
3999 (loop for kill in kill-ring
4000 unless
(or (< (length kill
) anything-kill-ring-threshold
)
4001 (string-match "^[\\s\\t]+$" kill
))
4004 (defun anything-c-kill-ring-action (str)
4005 "Insert STR in `kill-ring' and set STR to the head.
4006 If this action is executed just after `yank',
4007 replace with STR as yanked string."
4008 (setq kill-ring
(delete str kill-ring
))
4009 (if (not (eq (anything-attr 'last-command
) 'yank
))
4010 (insert-for-yank str
)
4012 (let ((inhibit-read-only t
)
4013 (before (< (point) (mark t
))))
4015 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
4016 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
4017 (setq yank-undo-function nil
)
4018 (set-marker (mark-marker) (point) (current-buffer))
4019 (insert-for-yank str
)
4020 ;; Set the window start back where it was in the yank command,
4022 (set-window-start (selected-window) yank-window-start t
)
4024 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
4025 ;; It is cleaner to avoid activation, even though the command
4026 ;; loop would deactivate the mark because we inserted text.
4027 (goto-char (prog1 (mark t
)
4028 (set-marker (mark-marker) (point) (current-buffer)))))))
4031 ;; (anything 'anything-c-source-kill-ring)
4034 ;; DO NOT include these sources in `anything-sources' use
4035 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
4036 ;; `anything-all-mark-rings' instead.
4038 (defun anything-c-source-mark-ring-candidates ()
4039 (flet ((get-marks (pos)
4043 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
4044 (when (string= "" line
)
4045 (setq line
"<EMPTY LINE>"))
4046 (format "%7d: %s" (line-number-at-pos) line
)))))
4047 (with-current-buffer anything-current-buffer
4049 with marks
= (cons (mark-marker) mark-ring
)
4052 for m
= (get-marks i
)
4053 unless
(member m recip
)
4054 collect m into recip
4055 finally return recip
))))
4057 (defvar anything-mark-ring-cache nil
)
4058 (defvar anything-c-source-mark-ring
4059 '((name .
"mark-ring")
4061 (setq anything-mark-ring-cache
4062 (ignore-errors (anything-c-source-mark-ring-candidates)))))
4063 (candidates .
(lambda ()
4064 (anything-aif anything-mark-ring-cache
4066 (action .
(("Goto line"
4067 .
(lambda (candidate)
4068 (anything-goto-line (string-to-number candidate
))))))
4069 (persistent-action .
(lambda (candidate)
4070 (anything-goto-line (string-to-number candidate
))
4071 (anything-match-line-color-current-line)))
4072 (persistent-help .
"Show this line")))
4074 ;; (anything 'anything-c-source-mark-ring)
4077 (defun anything-mark-ring ()
4078 "Preconfigured `anything' for `anything-c-source-mark-ring'."
4080 (anything 'anything-c-source-mark-ring
))
4082 ;;; Global-mark-ring
4083 (defvar anything-c-source-global-mark-ring
4084 '((name .
"global-mark-ring")
4085 (candidates . anything-c-source-global-mark-ring-candidates
)
4086 (action .
(("Goto line"
4087 .
(lambda (candidate)
4088 (let ((items (split-string candidate
":")))
4089 (switch-to-buffer (second items
))
4090 (anything-goto-line (string-to-number (car items
))))))))
4091 (persistent-action .
(lambda (candidate)
4092 (let ((items (split-string candidate
":")))
4093 (switch-to-buffer (second items
))
4094 (anything-goto-line (string-to-number (car items
)))
4095 (anything-match-line-color-current-line))))
4096 (persistent-help .
"Show this line")))
4098 (defun anything-c-source-global-mark-ring-candidates ()
4100 (with-current-buffer (marker-buffer m
)
4104 (if (string= "" line
)
4105 (setq line
"<EMPTY LINE>")
4106 (setq line
(car (split-string (thing-at-point 'line
)
4108 (format "%7d:%s: %s"
4109 (line-number-at-pos) (marker-buffer m
) line
)))))
4111 with marks
= global-mark-ring
4114 for gm
= (unless (or (string-match
4115 "^ " (format "%s" (marker-buffer i
)))
4116 (null (marker-buffer i
)))
4118 when
(and gm
(not (member gm recip
)))
4119 collect gm into recip
4120 finally return recip
)))
4122 ;; (anything 'anything-c-source-global-mark-ring)
4125 (defun anything-global-mark-ring ()
4126 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
4128 (anything 'anything-c-source-global-mark-ring
))
4131 (defun anything-all-mark-rings ()
4132 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
4133 `anything-c-source-mark-ring'."
4135 (anything '(anything-c-source-global-mark-ring
4136 anything-c-source-mark-ring
)))
4139 ;;; Insert from register
4140 (defvar anything-c-source-register
4141 '((name .
"Registers")
4142 (candidates . anything-c-register-candidates
)
4143 (action-transformer . anything-c-register-action-transformer
)
4146 "See (info \"(emacs)Registers\")")
4148 (defun anything-c-register-candidates ()
4149 "Collecting register contents and appropriate commands."
4150 (loop for
(char . val
) in register-alist
4151 for key
= (single-key-description char
)
4152 for string-actions
=
4155 (list (int-to-string val
)
4157 'increment-register
))
4159 (let ((buf (marker-buffer val
)))
4161 (list "a marker in no buffer")
4163 "a buffer position:"
4166 (int-to-string (marker-position val
)))
4168 'insert-register
))))
4169 ((and (consp val
) (window-configuration-p (car val
)))
4170 (list "window configuration."
4172 ((and (consp val
) (frame-configuration-p (car val
)))
4173 (list "frame configuration."
4175 ((and (consp val
) (eq (car val
) 'file
))
4176 (list (concat "file:"
4177 (prin1-to-string (cdr val
))
4180 ((and (consp val
) (eq (car val
) 'file-query
))
4181 (list (concat "file:a file-query reference: file "
4184 (int-to-string (car (cdr (cdr val
))))
4188 (let ((lines (format "%4d" (length val
))))
4189 (list (format "%s: %s\n" lines
4190 (truncate-string-to-width
4191 (mapconcat 'identity
(list (car val
))
4192 ;; (mapconcat (lambda (y) y) val
4193 "^J") (- (window-width) 15)))
4196 (list ;; without properties
4197 (substring-no-properties val
)
4200 'prepend-to-register
))
4203 collect
(cons (format "register %3s: %s" key
(car string-actions
))
4204 (cons char
(cdr string-actions
)))))
4206 (defun anything-c-register-action-transformer (actions register-and-functions
)
4207 "Decide actions by the contents of register."
4208 (loop with func-actions
=
4211 (lambda (c) (insert-register (car c
))))
4213 "Jump to Register" .
4214 (lambda (c) (jump-to-register (car c
))))
4216 "Append Region to Register" .
4217 (lambda (c) (append-to-register
4218 (car c
) (region-beginning) (region-end))))
4219 (prepend-to-register
4220 "Prepend Region to Register" .
4221 (lambda (c) (prepend-to-register
4222 (car c
) (region-beginning) (region-end))))
4224 "Increment Prefix Arg to Register" .
4225 (lambda (c) (increment-register
4226 anything-current-prefix-arg
(car c
)))))
4227 for func in
(cdr register-and-functions
)
4228 for cell
= (assq func func-actions
)
4230 collect
(cdr cell
)))
4232 ;; (anything 'anything-c-source-register)
4234 ;;;; <Headline Extraction>
4235 (defvar anything-c-source-fixme
4236 '((name .
"TODO/FIXME/DRY comments")
4237 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
4240 "Show TODO/FIXME/DRY comments in current file.")
4241 ;; (anything 'anything-c-source-fixme)
4243 (defvar anything-c-source-rd-headline
4244 '((name .
"RD HeadLine")
4245 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
4246 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
4252 http://en.wikipedia.org/wiki/Ruby_Document_format")
4253 ;; (anything 'anything-c-source-rd-headline)
4255 (defvar anything-c-source-oddmuse-headline
4256 '((name .
"Oddmuse HeadLine")
4257 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
4258 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
4259 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
4262 "Show Oddmuse headlines, such as EmacsWiki.")
4263 ;; (anything 'anything-c-source-oddmuse-headline)
4265 (defvar anything-c-source-emacs-source-defun
4266 '((name .
"Emacs Source DEFUN")
4267 (headline .
"DEFUN\\|DEFVAR")
4268 (condition .
(string-match "/emacs2[0-9].+/src/.+c$"
4269 (or buffer-file-name
""))))
4270 "Show DEFUN/DEFVAR in Emacs C source file.")
4271 ;; (anything 'anything-c-source-emacs-source-defun)
4273 (defvar anything-c-source-emacs-lisp-expectations
4274 '((name .
"Emacs Lisp Expectations")
4275 (headline .
"(desc[ ]\\|(expectations")
4276 (condition .
(eq major-mode
'emacs-lisp-mode
)))
4277 "Show descriptions (desc) in Emacs Lisp Expectations.
4279 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4280 ;; (anything 'anything-c-source-emacs-lisp-expectations)
4282 (defvar anything-c-source-emacs-lisp-toplevels
4283 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
4284 (headline .
"^(\\|(@\\*\\|^;;;;")
4285 (get-line . buffer-substring
)
4286 (condition .
(eq major-mode
'emacs-lisp-mode
))
4288 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
4289 linkd.el is optional because linkd stars are extracted by regexp.
4290 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
4291 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
4293 (defvar anything-c-source-org-headline
4294 '((name .
"Org HeadLine")
4296 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4297 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4298 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4299 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4300 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4301 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4302 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4303 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
4304 (condition .
(eq major-mode
'org-mode
))
4307 (persistent-action .
(lambda (elm)
4308 (anything-c-action-line-goto elm
)
4311 .
(lambda (actions candidate
)
4312 '(("Go to Line" . anything-c-action-line-goto
)
4313 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline
)))))
4314 "Show Org headlines.
4315 org-mode is very very much extended text-mode/outline-mode.
4317 See (find-library \"org.el\")
4318 See http://orgmode.org for the latest version.")
4320 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
4323 (anything-goto-line (car lineno-and-content
))
4324 (and (looking-at org-complex-heading-regexp
)
4325 (org-make-link-string (concat "*" (match-string 4)))))))
4327 ;; (anything 'anything-c-source-org-headline)
4329 ;;; Anything yaoddmuse
4330 ;; Be sure to have yaoddmuse.el installed
4331 ;; install-elisp may be required if you want to install elisp file from here.
4332 (defvar anything-yaoddmuse-use-cache-file nil
)
4333 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
4334 (defvar anything-c-yaoddmuse-ew-cache nil
)
4335 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
4336 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
4337 (candidates .
(lambda ()
4338 (if anything-yaoddmuse-use-cache-file
4340 (unless anything-c-yaoddmuse-ew-cache
4341 (load anything-c-yaoddmuse-cache-file
)
4342 (setq anything-c-yaoddmuse-ew-cache
4343 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
4344 anything-c-yaoddmuse-ew-cache
)
4345 (yaoddmuse-update-pagename t
)
4346 (gethash "EmacsWiki" yaoddmuse-pages-hash
))))
4347 (action .
(("Edit page" .
(lambda (candidate)
4348 (yaoddmuse-edit "EmacsWiki" candidate
)))
4349 ("Browse page" .
(lambda (candidate)
4350 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
4351 ("Browse page other window" .
(lambda (candidate)
4353 (split-window-vertically))
4354 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
4355 ("Browse diff" .
(lambda (candidate)
4356 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
4357 ("Copy URL" .
(lambda (candidate)
4358 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
4359 (message "Have copy page %s's URL to yank." candidate
)))
4360 ("Create page" .
(lambda (candidate)
4361 (yaoddmuse-edit "EmacsWiki" anything-input
)))
4362 ("Update cache" .
(lambda (candidate)
4363 (if anything-yaoddmuse-use-cache-file
4365 (anything-yaoddmuse-cache-pages t
)
4366 (setq anything-c-yaoddmuse-ew-cache
4367 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
4368 (yaoddmuse-update-pagename))))))
4369 (action-transformer anything-c-yaoddmuse-action-transformer
))
4370 "Needs yaoddmuse.el.
4372 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4374 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
4376 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
4377 '((name .
"Yaoddmuse Post library (EmacsWiki)")
4378 (init .
(anything-yaoddmuse-init))
4379 (candidates-in-buffer)
4380 (action .
(("Post library and Browse" .
(lambda (candidate)
4381 (yaoddmuse-post-file (find-library-name candidate
)
4383 (file-name-nondirectory (find-library-name candidate
))
4385 ("Post library" .
(lambda (candidate)
4386 (yaoddmuse-post-file (find-library-name candidate
)
4388 (file-name-nondirectory (find-library-name candidate
))))))))
4389 "Needs yaoddmuse.el.
4391 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4393 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
4395 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
4396 "Allow the use of `install-elisp' only on elisp files."
4397 (if (string-match "\.el$" candidate
)
4398 (append actions
'(("Install Elisp" .
(lambda (elm)
4399 (install-elisp-from-emacswiki elm
)))))
4403 (defun anything-yaoddmuse-cache-pages (&optional load
)
4404 "Fetch the list of files on emacswiki and create cache file.
4405 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
4407 (yaoddmuse-update-pagename)
4409 (find-file anything-c-yaoddmuse-cache-file
)
4411 (insert "(puthash \"EmacsWiki\" '(")
4412 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
4414 (insert (concat "(\"" (car i
) "\") ")))
4415 (insert ") yaoddmuse-pages-hash)\n")
4417 (kill-buffer (current-buffer))
4418 (when (or current-prefix-arg
4420 (load anything-c-yaoddmuse-cache-file
))))
4423 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
4424 "Preconfigured `anything' to edit or view EmacsWiki page.
4428 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4430 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
4433 (defun anything-yaoddmuse-emacswiki-post-library ()
4434 "Preconfigured `anything' to post library to EmacsWiki.
4438 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4440 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library
))
4442 (defun anything-yaoddmuse-init ()
4443 "Init anything buffer status."
4444 (let ((anything-buffer (anything-candidate-buffer 'global
))
4445 (library-list (yaoddmuse-get-library-list)))
4446 (with-current-buffer anything-buffer
4447 ;; Insert library name.
4448 (dolist (library library-list
)
4449 (insert (format "%s\n" library
)))
4451 (sort-lines nil
(point-min) (point-max)))))
4454 (defvar anything-c-source-eev-anchor
4455 '((name .
"Anchors")
4459 (with-current-buffer anything-current-buffer
4460 (loop initially
(goto-char (point-min))
4461 while
(re-search-forward (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
4462 for anchor
= (match-string-no-properties 1)
4463 collect
(cons (format "%5d:%s"
4464 (line-number-at-pos (match-beginning 0))
4465 (format ee-anchor-format anchor
)) anchor
))))))
4466 (persistent-action .
(lambda (item)
4468 (anything-match-line-color-current-line)))
4469 (persistent-help .
"Show this entry")
4470 (action .
(("Goto link" . ee-to
)))))
4471 ;; (anything 'anything-c-source-eev-anchor)
4475 (defvar anything-c-source-org-keywords
4476 '((name .
"Org Keywords")
4477 (init . anything-c-org-keywords-init
)
4478 (candidates . anything-c-org-keywords-candidates
)
4479 (action . anything-c-org-keywords-insert
)
4480 (persistent-action . anything-c-org-keywords-show-help
)
4481 (persistent-help .
"Show an example and info page to describe this keyword.")
4484 ;; (anything 'anything-c-source-org-keywords)
4485 (defvar anything-c-org-keywords-info-location
4486 '(("#+TITLE:" .
"(org)Export options")
4487 ("#+AUTHOR:" .
"(org)Export options")
4488 ("#+DATE:" .
"(org)Export options")
4489 ("#+EMAIL:" .
"(org)Export options")
4490 ("#+DESCRIPTION:" .
"(org)Export options")
4491 ("#+KEYWORDS:" .
"(org)Export options")
4492 ("#+LANGUAGE:" .
"(org)Export options")
4493 ("#+TEXT:" .
"(org)Export options")
4494 ("#+TEXT:" .
"(org)Export options")
4495 ("#+OPTIONS:" .
"(org)Export options")
4496 ("#+BIND:" .
"(org)Export options")
4497 ("#+LINK_UP:" .
"(org)Export options")
4498 ("#+LINK_HOME:" .
"(org)Export options")
4499 ("#+LATEX_HEADER:" .
"(org)Export options")
4500 ("#+EXPORT_SELECT_TAGS:" .
"(org)Export options")
4501 ("#+EXPORT_EXCLUDE_TAGS:" .
"(org)Export options")
4502 ("#+INFOJS_OPT" .
"(org)Javascript support")
4503 ("#+BEGIN_HTML" .
"(org)Quoting HTML tags")
4504 ("#+BEGIN_LaTeX" .
"(org)Quoting LaTeX code")
4505 ("#+ORGTBL" .
"(org)Radio tables")
4506 ("#+HTML:" .
"(org)Quoting HTML tags")
4507 ("#+LaTeX:" .
"(org)Quoting LaTeX code")
4508 ("#+BEGIN:" .
"(org)Dynamic blocks") ;clocktable columnview
4509 ("#+BEGIN_EXAMPLE" .
"(org)Literal examples")
4510 ("#+BEGIN_QUOTE" .
"(org)Paragraphs")
4511 ("#+BEGIN_VERSE" .
"(org)Paragraphs")
4512 ("#+BEGIN_SRC" .
"(org)Literal examples")
4513 ("#+CAPTION" .
"(org)Tables in HTML export")
4514 ("#+LABEL" .
"(org)Tables in LaTeX export")
4515 ("#+ATTR_HTML" .
"(org)Links")
4516 ("#+ATTR_LaTeX" .
"(org)Images in LaTeX export")))
4518 (defun anything-c-org-keywords-init ()
4519 (unless (anything-attr 'keywords-examples
)
4521 (anything-attrset 'keywords-examples
4525 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x
)
4526 (cons (match-string 2 x
) (match-string 1 x
)))
4527 (org-split-string (org-get-current-options) "\n"))
4528 (mapcar 'list org-additional-option-like-keywords
)))
4529 (anything-attrset 'keywords
(mapcar 'car
(anything-attr 'keywords-examples
)))))
4531 (defun anything-c-org-keywords-candidates ()
4532 (and (eq (buffer-local-value 'major-mode anything-current-buffer
) 'org-mode
)
4533 (anything-attr 'keywords
)))
4535 (defun anything-c-org-keywords-insert (keyword)
4536 (cond ((string-match "BEGIN" keyword
)
4537 (insert "#+" keyword
" ")
4539 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword
) "\n")))
4541 (insert "#+" keyword
" "))))
4543 (defun anything-c-org-keywords-show-help (keyword)
4544 (info (or (assoc-default (concat "#+" keyword
) anything-c-org-keywords-info-location
)
4545 "(org)In-buffer settings"))
4546 (search-forward (concat "#+" keyword
) nil t
)
4547 (anything-persistent-highlight-point)
4548 (message "%s" (or (cdr (assoc keyword
(anything-attr 'keywords-examples
))) "")))
4552 (defvar anything-c-source-picklist
4553 '((name .
"Picklist")
4554 (candidates .
(lambda () (mapcar 'car picklist-list
)))
4556 ;; (anything 'anything-c-source-picklist)
4559 (defvar bbdb-records
)
4560 (defvar bbdb-buffer-name
)
4561 (declare-function bbdb
"ext:bbdb-com")
4562 (declare-function bbdb-current-record
"ext:bbdb-com")
4563 (declare-function bbdb-redisplay-one-record
"ext:bbdb-com")
4564 (declare-function bbdb-record-net
"ext:bbdb-com" (string) t
)
4565 (declare-function bbdb-current-record
"ext:bbdb-com")
4566 (declare-function bbdb-dwim-net-address
"ext:bbdb-com")
4567 (declare-function bbdb-records
"ext:bbdb-com"
4568 (&optional dont-check-disk already-in-db-buffer
))
4570 (defun anything-c-bbdb-candidates ()
4571 "Return a list of all names in the bbdb database. The format
4572 is \"Firstname Lastname\"."
4573 (mapcar (lambda (bbdb-record)
4574 (replace-regexp-in-string
4576 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
4579 (defun anything-c-bbdb-create-contact (actions candidate
)
4580 "Action transformer that returns only an entry to add the
4581 current `anything-pattern' as new contact. All other actions are
4583 (if (string= candidate
"*Add to contacts*")
4584 '(("Add to contacts" .
(lambda (actions)
4585 (bbdb-create-internal
4586 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
4587 (read-from-minibuffer "Company: ")
4588 (read-from-minibuffer "Email: ")
4591 (read-from-minibuffer "Note: ")))))
4594 (defun anything-c-bbdb-get-record (candidate)
4595 "Return record that match CANDIDATE."
4596 (bbdb candidate nil
)
4597 (set-buffer "*BBDB*")
4598 (bbdb-current-record))
4600 (defvar anything-c-bbdb-name nil
4601 "Only for internal use.")
4603 (defvar anything-c-source-bbdb
4605 (candidates . anything-c-bbdb-candidates
)
4606 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
4607 ("View person's data" . anything-c-bbdb-view-person-action
))
4608 (filtered-candidate-transformer .
(lambda (candidates source
)
4609 (setq anything-c-bbdb-name anything-pattern
)
4610 (if (not candidates
)
4611 (list "*Add to contacts*")
4613 (action-transformer .
(lambda (actions candidate
)
4614 (anything-c-bbdb-create-contact actions candidate
))))
4617 http://bbdb.sourceforge.net/")
4618 ;; (anything 'anything-c-source-bbdb)
4620 (defun anything-c-bbdb-view-person-action (candidate)
4621 "View BBDB data of single CANDIDATE or marked candidates."
4622 (anything-aif (anything-marked-candidates)
4623 (let ((bbdb-append-records (length it
)))
4625 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
4626 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
4628 (defun anything-c-bbdb-collect-mail-addresses ()
4629 "Return a list of all mail addresses of records in bbdb buffer."
4630 (with-current-buffer bbdb-buffer-name
4631 (loop for i in bbdb-records
4632 if
(bbdb-record-net (car i
))
4633 collect
(bbdb-dwim-net-address (car i
)))))
4635 (defun anything-c-bbdb-compose-mail (candidate)
4636 "Compose a mail with all records of bbdb buffer."
4637 (anything-c-bbdb-view-person-action candidate
)
4638 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
4639 (address-str (mapconcat 'identity address-list
",\n ")))
4640 (compose-mail address-str
)))
4642 ;;; Evaluation Result
4643 (defvar anything-c-source-evaluation-result
4644 '((name .
"Evaluation Result")
4647 (filtered-candidate-transformer .
(lambda (candidates source
)
4650 (with-current-buffer anything-current-buffer
4652 (eval (read anything-pattern
))))
4654 (action ("Copy result to kill-ring" .
(lambda (candidate)
4655 (with-current-buffer anything-buffer
4656 (let ((end (save-excursion
4657 (goto-char (point-max))
4658 (search-backward "\n")
4660 (kill-region (point) end
))))))))
4661 ;; (anything 'anything-c-source-evaluation-result)
4664 (defun anything-eval-expression (arg)
4665 "Preconfigured anything for `anything-c-source-evaluation-result'."
4667 (anything 'anything-c-source-evaluation-result
(when arg
(thing-at-point 'sexp
))
4668 nil nil nil
"*anything eval*"))
4671 (defun anything-eval-expression-with-eldoc ()
4672 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
4675 (let ((timer (run-with-idle-timer eldoc-idle-delay
4676 'repeat
'anything-eldoc-show-in-eval
)))
4678 (call-interactively 'anything-eval-expression
)
4679 (cancel-timer timer
)))
4680 (call-interactively 'anything-eval-expression
)))
4682 (defun anything-eldoc-show-in-eval ()
4683 "Return eldoc in a tooltip for current minibuffer input."
4684 (let* ((str-all (minibuffer-completion-contents))
4688 (goto-char (point-max))
4689 (unless (looking-back ")\\|\"") (forward-char -
1))
4690 (eldoc-current-symbol))))
4691 (doc (or (eldoc-get-var-docstring sym
)
4692 (eldoc-get-fnsym-args-string
4693 (car (eldoc-fnsym-in-current-sexp))))))
4694 (when doc
(tooltip-show doc
))))
4696 ;;; Calculation Result
4697 (defvar anything-c-source-calculation-result
4698 '((name .
"Calculation Result")
4700 (filtered-candidate-transformer .
(lambda (candidates source
)
4703 (calc-eval anything-pattern
)
4705 (action ("Copy result to kill-ring" . kill-new
))))
4706 ;; (anything 'anything-c-source-calculation-result)
4708 ;;; Google Suggestions
4709 (defvar anything-gg-sug-lgh-flag
0)
4710 (defun anything-c-google-suggest-fetch (input)
4711 "Fetch suggestions for INPUT from XML buffer.
4712 Return an alist with elements like (data . number_results)."
4713 (let ((request (concat anything-c-google-suggest-url
4714 (url-hexify-string input
))))
4717 with result-alist
= (xml-get-children
4718 (car (xml-parse-region (point-min) (point-max)))
4719 'CompleteSuggestion
)
4720 for i in result-alist
4721 for data
= (cdr (caadr (assoc 'suggestion i
)))
4722 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
4723 for ldata
= (length data
)
4725 (when (> ldata anything-gg-sug-lgh-flag
)
4726 (setq anything-gg-sug-lgh-flag ldata
))
4727 collect
(cons data nqueries
) into cont
4728 finally return cont
)))
4729 (if anything-google-suggest-use-curl-p
4731 (call-process "curl" nil t nil request
)
4733 (with-current-buffer
4734 (url-retrieve-synchronously request
)
4738 (defun anything-c-google-suggest-set-candidates ()
4739 "Set candidates with result and number of google results found."
4740 (let ((suggestions (anything-c-google-suggest-fetch anything-input
)))
4741 (setq suggestions
(loop for i in suggestions
4742 for interval
= (- anything-gg-sug-lgh-flag
(length (car i
)))
4743 for elm
= (concat (car i
)
4744 (make-string (+ 2 interval
) ?
)
4745 "(" (cdr i
) " results)")
4746 collect
(cons elm
(car i
))))
4747 (if (some (lambda (data) (equal (cdr data
) anything-input
)) suggestions
)
4749 ;; if there is no suggestion exactly matching the input then
4750 ;; prepend a Search on Google item to the list
4753 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
4754 anything-input
))))))
4757 (defun anything-c-google-suggest-action (candidate)
4758 "Default action to jump to a google suggested candidate."
4759 (anything-c-browse-url (concat anything-c-google-suggest-search-url
4760 (url-hexify-string candidate
))))
4763 (defvar anything-c-source-google-suggest
4764 '((name .
"Google Suggest")
4765 (candidates . anything-c-google-suggest-set-candidates
)
4766 (action .
(("Google Search" . anything-c-google-suggest-action
)))
4768 (requires-pattern .
3)
4771 ;; (anything 'anything-c-source-google-suggest)
4773 ;;; Yahoo suggestions
4775 (defun anything-c-yahoo-suggest-fetch (input)
4776 "Fetch Yahoo suggestions for INPUT from XML buffer.
4777 Return an alist with elements like (data . number_results)."
4778 (let ((request (concat anything-c-yahoo-suggest-url
4779 (url-hexify-string input
))))
4782 with result-alist
= (xml-get-children
4783 (car (xml-parse-region (point-min) (point-max)))
4785 for i in result-alist
4786 collect
(caddr i
))))
4787 (with-current-buffer
4788 (url-retrieve-synchronously request
)
4791 (defun anything-c-yahoo-suggest-set-candidates ()
4792 "Set candidates with Yahoo results found."
4793 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
4797 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
4798 anything-input
))))))
4800 (defun anything-c-yahoo-suggest-action (candidate)
4801 "Default action to jump to a Yahoo suggested candidate."
4802 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
4803 (url-hexify-string candidate
))))
4805 (defvar anything-c-source-yahoo-suggest
4806 '((name .
"Yahoo Suggest")
4807 (candidates . anything-c-yahoo-suggest-set-candidates
)
4808 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
4810 (requires-pattern .
3)
4813 ;; (anything 'anything-c-source-yahoo-suggest)
4816 ;;; Need external program surfraw.
4817 ;;; http://surfraw.alioth.debian.org/
4819 (require 'browse-url
)
4820 (defvar w3m-command nil
)
4821 (defvar anything-c-home-url
"http://www.google.fr"
4822 "*Default url to use as home url.")
4824 (defvar anything-browse-url-default-browser-alist
4825 `((,w3m-command . w3m-browse-url
)
4826 (,browse-url-firefox-program . browse-url-firefox
)
4827 (,browse-url-kde-program . browse-url-kde
)
4828 (,browse-url-gnome-moz-program . browse-url-gnome-moz
)
4829 (,browse-url-mozilla-program . browse-url-mozilla
)
4830 (,browse-url-galeon-program . browse-url-galeon
)
4831 (,browse-url-netscape-program . browse-url-netscape
)
4832 (,browse-url-mosaic-program . browse-url-mosaic
)
4833 (,browse-url-xterm-program . browse-url-text-xterm
))
4834 "*Alist of (executable . function) to try to find a suitable url browser.")
4836 (defun anything-browse-url-default-browser (url &rest args
)
4837 "Find a suitable browser and ask it to load URL."
4838 (let ((default-browser (loop
4839 for i in anything-browse-url-default-browser-alist
4840 when
(and (car i
) (executable-find (car i
))) return
(cdr i
))))
4842 (apply default-browser url args
)
4843 (error "No usable browser found"))))
4845 (defun* anything-c-browse-url
(&optional
(url anything-c-home-url
))
4846 "Default command to browse URL."
4847 (if browse-url-browser-function
4849 (anything-browse-url-default-browser url
)))
4851 (defun anything-c-build-elvi-list ()
4852 "Return list of all engines and descriptions handled by surfraw."
4855 (call-process "surfraw" nil t nil
4857 (split-string (buffer-string) "\n"))))
4859 (defvar anything-surfraw-engines-history nil
)
4861 (defun anything-surfraw (pattern engine
)
4862 "Preconfigured `anything' to search PATTERN with search ENGINE."
4863 (interactive (list (read-string "SearchFor: ")
4866 (anything-c-build-elvi-list)
4868 :name
"Surfraw Search Engines"
4869 :history anything-surfraw-engines-history
)))
4870 (let* ((engine-nodesc (car (split-string engine
)))
4871 (url (with-temp-buffer
4872 (apply 'call-process
"surfraw" nil t nil
4873 (list engine-nodesc
"-p" pattern
))
4874 (replace-regexp-in-string
4875 "\n" "" (buffer-string)))))
4876 (if (string= engine-nodesc
"W")
4877 (anything-c-browse-url)
4878 (anything-c-browse-url url
)
4879 (setq anything-surfraw-engines-history
4880 (cons engine
(delete engine anything-surfraw-engines-history
))))))
4885 (defun anything-emms-stream-edit-bookmark (elm)
4886 "Change the information of current emms-stream bookmark from anything."
4888 (let* ((cur-buf anything-current-buffer
)
4889 (bookmark (assoc elm emms-stream-list
))
4890 (name (read-from-minibuffer "Description: "
4892 (url (read-from-minibuffer "URL: "
4894 (fd (read-from-minibuffer "Feed Descriptor: "
4895 (int-to-string (nth 2 bookmark
))))
4896 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
4897 (format "%s" (car (last bookmark
))))))
4900 (when (re-search-forward (concat "^" name
) nil t
)
4902 (emms-stream-delete-bookmark)
4903 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
4904 (emms-stream-save-bookmarks-file)
4906 (switch-to-buffer cur-buf
)))))
4908 (defun anything-emms-stream-delete-bookmark (elm)
4909 "Delete an emms-stream bookmark from anything."
4911 (let* ((cur-buf anything-current-buffer
)
4912 (bookmark (assoc elm emms-stream-list
))
4913 (name (nth 0 bookmark
)))
4916 (when (re-search-forward (concat "^" name
) nil t
)
4918 (emms-stream-delete-bookmark)
4919 (emms-stream-save-bookmarks-file)
4921 (switch-to-buffer cur-buf
)))))
4923 (defvar anything-c-source-emms-streams
4924 '((name .
"Emms Streams")
4926 (emms-stream-init)))
4927 (candidates .
(lambda ()
4928 (mapcar 'car emms-stream-list
)))
4929 (action .
(("Play" .
(lambda (elm)
4930 (let* ((stream (assoc elm emms-stream-list
))
4931 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
4932 (url (second stream
)))
4934 ("Delete" . anything-emms-stream-delete-bookmark
)
4935 ("Edit" . anything-emms-stream-edit-bookmark
)))
4936 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
4937 ;; (anything 'anything-c-source-emms-streams)
4939 ;; Don't forget to set `emms-source-file-default-directory'
4940 (defvar anything-c-source-emms-dired
4941 '((name .
"Music Directory")
4942 (candidates .
(lambda ()
4943 (cddr (directory-files emms-source-file-default-directory
))))
4945 (("Play Directory" .
(lambda (item)
4946 (emms-play-directory
4949 emms-source-file-default-directory
))))
4950 ("Open dired in file's directory" .
(lambda (item)
4951 (anything-c-open-dired
4954 emms-source-file-default-directory
))))))
4955 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
4956 ;; (anything 'anything-c-source-emms-dired)
4958 (defface anything-emms-playlist
4959 '((t (:foreground
"Springgreen4" :underline t
)))
4960 "*Face used for tracks in current emms playlist."
4963 (defun anything-c-emms-files-modifier (candidates)
4964 (let ((current-playlist (with-current-emms-playlist
4966 with cur-list
= (emms-playlist-tracks-in-region
4967 (point-min) (point-max))
4969 collect
(assoc-default 'info-file i
)))))
4970 (loop for i in candidates
4971 if
(member i current-playlist
)
4972 collect
(propertize i
'face
'anything-emms-playlist
) into lis
4973 else collect i into lis finally return lis
)))
4975 (defun anything-c-emms-play-current-playlist ()
4976 "Play current playlist."
4977 (with-current-emms-playlist
4978 (emms-playlist-first)
4979 (emms-playlist-mode-play-smart)))
4981 (defvar anything-c-source-emms-files
4982 '((name .
"Emms files")
4983 (candidates .
(lambda ()
4984 (loop for v being the hash-values in emms-cache-db
4985 for name
= (assoc-default 'name v
)
4986 unless
(string-match "^http:" name
) collect name
)))
4987 (candidate-transformer . anything-c-emms-files-modifier
)
4988 (action .
(("Play file" . emms-play-file
)
4989 ("Add to Playlist and play"
4990 .
(lambda (candidate)
4992 (dolist (i (anything-marked-candidates))
4993 (emms-add-playlist-file i
))
4994 (unless emms-player-playing-p
4995 (anything-c-emms-play-current-playlist))))))))
4997 ;; (anything 'anything-c-source-emms-files)
4999 ;;; Jabber Contacts (jabber.el)
5000 (defun anything-c-jabber-online-contacts ()
5001 "List online Jabber contacts."
5004 (dolist (item (jabber-concat-rosters) jids
)
5005 (when (get item
'connected
)
5006 (push (if (get item
'name
)
5007 (cons (get item
'name
) item
)
5008 (cons (symbol-name item
) item
)) jids
))))))
5010 (defvar anything-c-source-jabber-contacts
5011 '((name .
"Jabber Contacts")
5012 (init .
(lambda () (require 'jabber
)))
5013 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
5014 (action .
(lambda (x)
5016 (jabber-read-account)
5018 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
5019 ;; (anything 'anything-c-source-jabber-contacts)
5023 (defvar anything-source-select-buffer
"*anything source select*")
5024 (defvar anything-c-source-call-source
5025 `((name .
"Call anything source")
5026 (candidate-number-limit)
5027 (candidates .
(lambda ()
5028 (loop for vname in
(all-completions "anything-c-source-" obarray
)
5029 for var
= (intern vname
)
5030 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
5031 if name collect
(cons (format "%s `%s'"
5032 name
(propertize vname
'face
'font-lock-variable-name-face
))
5034 (action .
(("Invoke anything with selected source" .
5036 (setq anything-candidate-number-limit
9999)
5037 (anything candidate nil nil nil nil
5038 anything-source-select-buffer
)))
5039 ("Describe variable" . describe-variable
)
5040 ("Find variable" . find-variable
)))
5041 (persistent-action . describe-variable
)
5042 (persistent-help .
"Show description of this source")))
5043 ;; (anything 'anything-c-source-call-source)
5046 (defun anything-call-source ()
5047 "Preconfigured `anything' to call anything source."
5049 (anything 'anything-c-source-call-source nil nil nil nil
5050 anything-source-select-buffer
))
5052 (defun anything-call-source-from-anything ()
5053 "Call anything source within `anything' session."
5055 (setq anything-input-idle-delay
0)
5056 (anything-set-sources '(anything-c-source-call-source)))
5058 ;;; Execute Preconfigured anything.
5059 (defvar anything-c-source-anything-commands
5060 '((name .
"Preconfigured Anything")
5061 (candidates . anything-c-anything-commands-candidates
)
5063 (candidate-number-limit)))
5064 ;; (anything 'anything-c-source-anything-commands)
5066 (defun anything-c-anything-commands-candidates ()
5067 (loop for
(cmd . desc
) in
(anything-c-list-preconfigured-anything)
5068 collect
(cons (if (where-is-internal cmd nil t
)
5069 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc
))
5070 (substitute-command-keys (format "\\[%s] : %s" cmd desc
)))
5074 (defun anything-execute-anything-command ()
5075 "Preconfigured `anything' to execute preconfigured `anything'."
5077 (anything-other-buffer 'anything-c-source-anything-commands
5078 "*anything commands*"))
5081 (defun anything-c-occur-init ()
5082 (anything-candidate-buffer anything-current-buffer
))
5084 (defun anything-c-occur-get-line (s e
)
5085 (format "%7d:%s" (line-number-at-pos (1- s
)) (buffer-substring s e
)))
5087 (defvar anything-c-source-occur
5089 (init . anything-c-occur-init
)
5090 (candidates-in-buffer)
5092 (get-line . anything-c-occur-get-line
)
5095 (requires-pattern .
1)
5098 ;; (anything 'anything-c-source-occur)
5101 (defun anything-occur ()
5102 "Preconfigured Anything for Occur source."
5104 (let ((anything-compile-source-functions
5105 ;; rule out anything-match-plugin because the input is one regexp.
5106 (delq 'anything-compile-source--match-plugin
5107 (copy-sequence anything-compile-source-functions
))))
5108 (anything-other-buffer 'anything-c-source-occur
"*Anything Occur*")))
5110 ;; Do many actions for input
5111 (defvar anything-c-source-create
5115 (action-transformer . anything-create--actions
))
5116 "Do many create actions from `anything-pattern'.
5117 See also `anything-create--actions'.")
5118 ;; (anything 'anything-c-source-create)
5120 (defun anything-create-from-anything ()
5121 "Run `anything-create' from `anything' as a fallback."
5123 (anything-run-after-quit 'anything-create nil anything-pattern
))
5126 (defun anything-create (&optional string initial-input
)
5127 "Preconfigured `anything' to do many create actions from STRING.
5128 See also `anything-create--actions'."
5130 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
5131 (anything '(((name .
"Anything Create")
5132 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
5133 (candidates . anything-create--actions
)
5134 (candidate-number-limit)
5135 (action .
(lambda (func) (funcall func string
)))))))
5137 (defun anything-create--actions (&rest ignored
)
5138 "Default actions for `anything-create' / `anything-c-source-create'."
5140 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
5141 (append anything-create--actions-private
5142 '(("find-file" . find-file
)
5143 ("find-file other window" . find-file-other-window
)
5144 ("New buffer" . switch-to-buffer
)
5145 ("New buffer other window" . switch-to-buffer-other-window
)
5146 ("Bookmark Set" . bookmark-set
)
5148 (lambda (x) (set-register (read-char "Register: ") x
)))
5149 ("Insert Linkd star" . linkd-insert-star
)
5150 ("Insert Linkd Tag" . linkd-insert-tag
)
5151 ("Insert Linkd Link" . linkd-insert-link
)
5152 ("Insert Linkd Lisp" . linkd-insert-lisp
)
5153 ("Insert Linkd Wiki" . linkd-insert-wiki
)
5154 ("Google Search" . google
)))))
5156 ;; Minibuffer History
5157 (defvar anything-c-source-minibuffer-history
5158 '((name .
"Minibuffer History")
5159 (header-name .
(lambda (name) (format "%s (%s)" name minibuffer-history-variable
)))
5160 (candidates .
(lambda () (let ((history (symbol-value minibuffer-history-variable
)))
5161 (if (consp (car history
))
5162 (mapcar 'prin1-to-string history
)
5166 ;; (anything 'anything-c-source-minibuffer-history)
5169 (defvar anything-c-source-elscreen
5170 '((name .
"Elscreen")
5171 (candidates .
(lambda ()
5172 (if (cdr (elscreen-get-screen-to-name-alist))
5174 (loop for sname in
(elscreen-get-screen-to-name-alist)
5175 append
(list (format "[%d] %s" (car sname
) (cdr sname
))) into lst
5176 finally
(return lst
))
5177 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
5178 (action .
(("Change Screen".
5180 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
5183 (dolist (i (anything-marked-candidates))
5184 (elscreen-goto (- (aref i
1) (aref "0" 0)))
5188 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
5189 (elscreen-kill-others)))))))
5190 ;; (anything 'anything-c-source-elscreen)
5195 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
5196 "Top command (batch mode). %s is replaced with `frame-width'.")
5197 (defvar anything-c-source-top
5198 '((name .
"Top (Press C-c C-u to refresh)")
5199 (init . anything-c-top-init
)
5200 (candidates-in-buffer)
5201 (display-to-real . anything-c-top-display-to-real
)
5202 (update . anything-c-top-update
)
5204 ("kill (TERM)" .
(lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid
))))
5205 ("kill (KILL)" .
(lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid
))))
5206 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
5207 ;; (anything 'anything-c-source-top)
5209 (defun anything-c-top-sh (cmd)
5210 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
5212 (defun anything-c-top-init ()
5213 (with-current-buffer (anything-candidate-buffer 'global
)
5214 (call-process-shell-command
5215 (format anything-c-top-command
5216 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
5217 nil
(current-buffer))))
5219 (defun anything-c-top-display-to-real (line)
5220 (car (split-string line
)))
5222 (defun anything-c-top-update ()
5223 (let ((anything-source-name (assoc-default 'name anything-c-source-top
))) ;UGLY HACK
5224 (anything-c-top-init)))
5227 (defun anything-top ()
5228 "Preconfigured `anything' for top command."
5230 (let ((anything-samewindow t
)
5231 (anything-enable-shortcuts)
5232 (anything-display-function 'anything-default-display-buffer
)
5233 (anything-candidate-number-limit 9999))
5234 (save-window-excursion
5235 (delete-other-windows)
5236 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
5239 (defvar anything-c-source-absolute-time-timers
5240 '((name .
"Absolute Time Timers")
5241 (candidates . timer-list
)
5243 ;; (anything 'anything-c-source-absolute-time-timers)
5245 (defvar anything-c-source-idle-time-timers
5246 '((name .
"Idle Time Timers")
5247 (candidates . timer-idle-list
)
5249 ;; (anything 'anything-c-source-idle-time-timers)
5251 (defun anything-c-timer-real-to-display (timer)
5252 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay
)
5253 (append timer nil
) ;use `append' to convert vector->list
5254 (format "%s repeat=%5S %s(%s)"
5255 (let ((time (list t1 t2 t3
)))
5257 (format-time-string "idle-for=%5s" time
)
5258 (format-time-string "%m/%d %T" time
)))
5261 (mapconcat 'prin1-to-string args
" "))))
5263 ;;; X RandR resolution change
5264 ;;; FIXME I do not care multi-display.
5265 (defvar anything-c-xrandr-output
"VGA")
5266 (defvar anything-c-xrandr-screen
"0")
5267 (defvar anything-c-source-xrandr-change-resolution
5268 '((name .
"Change Resolution")
5272 (call-process "xrandr" nil
(current-buffer) nil
5273 "--screen" anything-c-xrandr-screen
"-q")
5275 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
5276 collect
(match-string 1)))))
5278 ("Change Resolution" .
(lambda (mode)
5279 (call-process "xrandr" nil nil nil
5280 "--screen" anything-c-xrandr-screen
5281 "--output" anything-c-xrandr-output
5283 ;; (anything 'anything-c-source-xrandr-change-resolution)
5286 (defun anything-c-persistent-xfont-action (elm)
5287 "Show current font temporarily"
5288 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
5291 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
5292 (set-frame-font current-font
))))
5294 (defvar anything-c-xfonts-cache nil
)
5295 (defvar anything-c-source-xfonts
5296 '((name .
"X Fonts")
5298 (unless anything-c-xfonts-cache
5299 (setq anything-c-xfonts-cache
5300 (x-list-fonts "*")))))
5301 (candidates . anything-c-xfonts-cache
)
5302 (action .
(("Copy to kill ring" .
(lambda (elm)
5304 ("Set Font" .
(lambda (elm)
5306 (set-frame-font elm
'keep-size
)
5307 (message "New font have been copied to kill ring")))))
5308 (persistent-action . anything-c-persistent-xfont-action
)
5309 (persistent-help .
"Switch to this font temporarily")))
5312 (defun anything-select-xfont ()
5313 "Preconfigured `anything' to select Xfont."
5315 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
5317 ;; (anything 'anything-c-source-xfonts)
5319 ;;; Source for Debian/Ubuntu users
5320 (defvar anything-c-source-apt
5322 (init . anything-c-apt-init
)
5323 (candidates-in-buffer)
5324 (candidate-transformer anything-c-apt-candidate-transformer
)
5325 (display-to-real . anything-c-apt-display-to-real
)
5326 (candidate-number-limit .
9999)
5328 ("Show package description" . anything-c-apt-cache-show
)
5329 ("Install package" . anything-c-apt-install
)
5330 ("Remove package" . anything-c-apt-uninstall
)
5331 ("Purge package" . anything-c-apt-purge
))
5332 (persistent-action . anything-c-apt-persistent-action
)
5333 (persistent-help .
"Show - C-u Refresh")))
5334 ;; (anything 'anything-c-source-apt)
5336 (defvar anything-c-apt-query
"emacs")
5337 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
5338 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
5339 (defvar anything-c-apt-installed-packages nil
)
5341 (defface anything-apt-installed
5342 '((t (:foreground
"green")))
5343 "*Face used for apt installed candidates."
5346 (defun anything-c-apt-refresh ()
5347 "Refresh installed candidates list."
5348 (setq anything-c-apt-installed-packages nil
)
5349 (anything-force-update))
5351 (defun anything-c-apt-persistent-action (candidate)
5352 "Persistent action for APT source."
5353 (if current-prefix-arg
5354 (anything-c-apt-refresh)
5355 (anything-c-apt-cache-show candidate
)))
5358 (defun anything-apt (query)
5359 "Preconfigured `anything' : frontend of APT package manager."
5360 (interactive "sAPT search: ")
5361 (let ((anything-c-apt-query query
))
5362 (anything 'anything-c-source-apt
)))
5364 (defun anything-c-apt-candidate-transformer (candidates)
5365 "Show installed candidates in a different color."
5368 for cand in candidates
5369 for name
= (anything-c-apt-display-to-real cand
)
5370 if
(member name anything-c-apt-installed-packages
)
5371 collect
(propertize cand
'face
'anything-apt-installed
) into all
5372 else collect cand into all finally return all
))
5374 (defun anything-c-apt-init ()
5375 "Initialize list of debian packages."
5376 (unless anything-c-apt-installed-packages
5377 (message "Updating installed candidate list...")
5378 (setq anything-c-apt-installed-packages
5380 (call-process-shell-command "dpkg --get-selections"
5381 nil
(current-buffer))
5382 (loop for i in
(split-string (buffer-string) "\n" t
)
5383 collect
(car (split-string i
))))))
5384 (with-current-buffer
5385 (anything-candidate-buffer
5386 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query
)))
5388 (call-process-shell-command
5389 (format anything-c-apt-search-command anything-c-apt-query
)
5390 nil
(current-buffer)))
5391 (message "Updating installed candidate list...done"))
5393 (defun anything-c-apt-display-to-real (line)
5394 "Return only name of a debian package.
5395 LINE is displayed like:
5396 package name - description."
5397 (car (split-string line
" - ")))
5400 (defun anything-c-shell-command-if-needed (command)
5401 (interactive "sShell command: ")
5402 (if (get-buffer command
) ; if the buffer already exists
5403 (switch-to-buffer command
) ; then just switch to it
5404 (switch-to-buffer command
) ; otherwise create it
5405 (insert (shell-command-to-string command
))))
5407 (defun anything-c-apt-cache-show (package)
5408 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package
)))
5410 (defun anything-c-apt-install (package)
5411 (anything-c-apt-install1 package
:action
'install
))
5413 (defun anything-c-apt-uninstall (package)
5414 (anything-c-apt-install1 package
:action
'uninstall
))
5416 (defun anything-c-apt-purge (package)
5417 (anything-c-apt-install1 package
:action
'purge
))
5419 (defun* anything-c-apt-install1
(candidate &key action
)
5420 (ansi-term (getenv "SHELL") "anything apt")
5422 (let ((command (case action
5423 ('install
"sudo apt-get install '%s'")
5424 ('uninstall
"sudo apt-get remove '%s'")
5425 ('purge
"sudo apt-get purge '%s'")
5426 (t (error "Unknow action"))))
5428 (goto-char (point-max))
5429 (insert (format command candidate
))
5431 (if (y-or-n-p (format "%s package" (symbol-name action
)))
5433 (setq anything-c-external-commands-list nil
)
5434 (setq anything-c-apt-installed-packages nil
)
5435 (term-char-mode) (term-send-input))
5436 (delete-region beg end
) (term-send-eof) (kill-buffer))))
5438 ;; (anything-c-apt-install "jed")
5440 ;;; Sources for gentoo users
5441 (defvar anything-c-gentoo-use-flags nil
)
5442 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
5443 (defvar anything-c-cache-gentoo nil
)
5444 (defvar anything-c-cache-world nil
)
5445 (defvar anything-c-source-gentoo
5446 '((name .
"Portage sources")
5448 (get-buffer-create anything-c-gentoo-buffer
)
5449 (unless anything-c-cache-gentoo
5450 (anything-c-gentoo-setup-cache))
5451 (unless anything-c-cache-world
5452 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
5453 (anything-c-gentoo-init-list)))
5454 (candidates-in-buffer)
5456 (candidate-transformer anything-c-highlight-world
)
5457 (action .
(("Show package" .
(lambda (elm)
5458 (anything-c-gentoo-eshell-action elm
"eix")))
5459 ("Show history" .
(lambda (elm)
5460 (if (member elm anything-c-cache-world
)
5461 (anything-c-gentoo-eshell-action elm
"genlop -qe")
5462 (message "No infos on packages not yet installed"))))
5463 ("Copy in kill-ring" . kill-new
)
5464 ("insert at point" . insert
)
5465 ("Browse HomePage" .
(lambda (elm)
5466 (let ((urls (anything-c-gentoo-get-url elm
)))
5467 (browse-url (anything-comp-read "Url: " urls
:must-match t
)))))
5468 ("Show extra infos" .
(lambda (elm)
5469 (if (member elm anything-c-cache-world
)
5470 (anything-c-gentoo-eshell-action elm
"genlop -qi")
5471 (message "No infos on packages not yet installed"))))
5472 ("Show use flags" .
(lambda (elm)
5473 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
5474 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
5475 (font-lock-mode 1)))
5476 ("Run emerge pretend" .
(lambda (elm)
5477 (anything-c-gentoo-eshell-action elm
"emerge -p")))
5478 ("Emerge" .
(lambda (elm)
5479 (anything-gentoo-install elm
:action
'install
)))
5480 ("Unmerge" .
(lambda (elm)
5481 (anything-gentoo-install elm
:action
'uninstall
)))
5482 ("Show dependencies" .
(lambda (elm)
5483 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
5484 ("Show related files" .
(lambda (elm)
5485 (anything-c-gentoo-default-action elm
"equery" "files")))
5486 ("Refresh" .
(lambda (elm)
5487 (anything-c-gentoo-setup-cache)
5488 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
5490 ;; (anything 'anything-c-source-gentoo)
5492 (defun* anything-gentoo-install
(candidate &key action
)
5493 (setq anything-c-external-commands-list nil
)
5494 (ansi-term (getenv "SHELL") "anything gentoo")
5496 (let ((command (case action
5497 ('install
"sudo emerge -av ")
5498 ('uninstall
"sudo emerge -avC ")
5499 (t (error "Unknow action"))))
5500 (elms (mapconcat 'identity
(anything-marked-candidates) " "))
5502 (goto-char (point-max))
5503 (insert (concat command elms
))
5505 (term-char-mode) (term-send-input)))
5507 (defun anything-c-gentoo-default-action (elm command
&rest args
)
5508 "Gentoo default action that use `anything-c-gentoo-buffer'."
5509 (if (member elm anything-c-cache-world
)
5511 (switch-to-buffer anything-c-gentoo-buffer
)
5513 (let ((com-list (append args
(list elm
))))
5514 (apply #'call-process command nil t nil
5516 (message "No infos on packages not yet installed")))
5518 (defvar anything-c-source-use-flags
5519 '((name .
"Use Flags")
5521 (unless anything-c-gentoo-use-flags
5522 (anything-c-gentoo-setup-use-flags-cache))
5523 (anything-c-gentoo-get-use)))
5524 (candidates-in-buffer)
5526 (candidate-transformer anything-c-highlight-local-use
)
5527 (action .
(("Description"
5529 (switch-to-buffer anything-c-gentoo-buffer
)
5531 (apply #'call-process
"euse" nil t nil
5534 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
5535 (font-lock-mode 1)))
5538 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -E")))
5541 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -D")))
5544 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -P")))
5545 ("Show which dep use this flag"
5547 (switch-to-buffer anything-c-gentoo-buffer
)
5549 (apply #'call-process
"equery" nil t nil
5555 ;; (anything 'anything-c-source-use-flags)
5557 (defun anything-c-gentoo-init-list ()
5558 "Initialize buffer with all packages in Portage."
5559 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
5560 (buf (anything-candidate-buffer 'portage-buf
)))
5561 (with-current-buffer buf
5562 (dolist (i anything-c-cache-gentoo
)
5563 (insert (concat i
"\n"))))))
5565 (defun anything-c-gentoo-setup-cache ()
5566 "Set up `anything-c-cache-gentoo'"
5567 (setq anything-c-cache-gentoo
5568 (split-string (with-temp-buffer
5569 (call-process "eix" nil t nil
5573 (defun anything-c-gentoo-eshell-action (elm command
)
5574 (when (get-buffer "*EShell Command Output*")
5575 (kill-buffer "*EShell Command Output*"))
5576 (message "Wait searching...")
5577 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
5578 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
5580 (save-window-excursion
5581 (pop-to-buffer "*scratch*")
5582 (eshell-command (format "%s %s" command elm
)))
5583 (pop-to-buffer "*EShell Command Output*"))
5584 (eshell-command (format "%s %s" command elm
)))))
5586 (defun anything-c-gentoo-get-use ()
5587 "Initialize buffer with all use flags."
5588 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
5589 (buf (anything-candidate-buffer 'use-buf
)))
5590 (with-current-buffer buf
5591 (dolist (i anything-c-gentoo-use-flags
)
5592 (insert (concat i
"\n"))))))
5595 (defun anything-c-gentoo-setup-use-flags-cache ()
5596 "Setup `anything-c-gentoo-use-flags'"
5597 (setq anything-c-gentoo-use-flags
5598 (split-string (with-temp-buffer
5599 (call-process "eix" nil t nil
5600 "--print-all-useflags")
5603 (defun anything-c-gentoo-get-url (elm)
5604 "Return a list of urls from eix output."
5606 with url-list
= (split-string
5608 (call-process "eix" nil t nil
5609 elm
"--format" "<homepage>\n")
5613 when
(and (string-match "^http://.*" i
)
5614 (not (member i all
)))
5616 finally return all
))
5618 (defun anything-c-gentoo-get-world ()
5619 "Return list of all installed package on your system."
5620 (split-string (with-temp-buffer
5621 (call-process "qlist" nil t nil
5625 (defun anything-c-gentoo-get-local-use ()
5626 (split-string (with-temp-buffer
5627 (call-process "portageq" nil t nil
5632 (defface anything-gentoo-match-face
'((t (:foreground
"red")))
5633 "Face for anything-gentoo installed packages."
5634 :group
'traverse-faces
)
5636 (defun anything-c-highlight-world (eix)
5637 "Highlight all installed package."
5639 if
(member i anything-c-cache-world
)
5640 collect
(propertize i
'face
'anything-gentoo-match-face
)
5644 (defun anything-c-highlight-local-use (use-flags)
5645 (let ((local-uses (anything-c-gentoo-get-local-use)))
5646 (loop for i in use-flags
5647 if
(member i local-uses
)
5648 collect
(propertize i
'face
'anything-gentoo-match-face
)
5652 (defvar anything-c-source-emacs-process
5653 '((name .
"Emacs Process")
5654 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
5655 (action ("Kill Process" .
(lambda (elm) (delete-process (get-process elm
)))))))
5657 ;; (anything 'anything-c-source-emacs-process)
5659 ;; Run Externals commands within Emacs
5660 (defmacro* anything-comp-hash-get-items
(hash-table &key test
)
5661 "Get the list of all keys/values of hash-table."
5662 `(let ((li-items ()))
5663 (maphash #'(lambda (x y
)
5665 (when (funcall ,test y
)
5666 (push (list x y
) li-items
))
5667 (push (list x y
) li-items
)))
5671 (defun anything-comp-read-get-candidates (collection &optional test
)
5672 "Convert collection to list.
5673 If collection is an `obarray', a test is maybe needed, otherwise
5674 the list would be incomplete.
5676 (cond ((and (listp collection
) test
)
5677 (loop for i in collection when
(funcall test i
) collect i
))
5678 ((and (eq collection obarray
) test
)
5679 (loop for s being the symbols of collection
5680 when
(funcall test s
) collect s
))
5681 ((and (vectorp collection
) test
)
5682 (loop for i across collection when
(funcall test i
) collect i
))
5683 ((vectorp collection
)
5684 (loop for i across collection collect i
))
5685 ((and (hash-table-p collection
) test
)
5686 (anything-comp-hash-get-items collection
:test test
))
5687 ((hash-table-p collection
)
5688 (anything-comp-hash-get-items collection
))
5691 (defun* anything-comp-read
(prompt collection
5695 (buffer "*Anything Completions*")
5697 (requires-pattern 0)
5699 (persistent-action nil
)
5700 (persistent-help "DoNothing")
5701 (name "Anything Completions"))
5702 "Anything `completing-read' emulation.
5703 Collection can be a list, vector, obarray or hash-table."
5704 (when (get-buffer anything-action-buffer
)
5705 (kill-buffer anything-action-buffer
))
5708 `(((name .
,(format "%s History" name
))
5709 (candidates .
(lambda ()
5710 (anything-comp-read-get-candidates history
)))
5712 (persistent-action .
,persistent-action
)
5713 (persistent-help .
,persistent-help
)
5714 (action .
,'identity
))
5718 (let ((cands (anything-comp-read-get-candidates
5720 (if (or must-match
(string= anything-pattern
""))
5721 cands
(append (list anything-pattern
) cands
)))))
5722 (requires-pattern .
,requires-pattern
)
5723 (persistent-action .
,persistent-action
)
5724 (persistent-help .
,persistent-help
)
5726 (action .
(("candidate" .
,'identity
)))))
5727 :input initial-input
5733 (defun anything-c-get-pid-from-process-name (process-name)
5734 "Get pid from running process PROCESS-NAME."
5735 (loop with process-list
= (list-system-processes)
5736 for pid in process-list
5737 for process
= (assoc-default 'comm
(process-attributes pid
))
5738 when
(and process
(string-match process-name process
))
5742 (defun anything-run-or-raise (exe &optional file
)
5743 "Generic command that run asynchronously EXE.
5744 If EXE is already running just jump to his window if `anything-raise-command'
5746 When FILE argument is provided run EXE with FILE.
5747 In this case EXE must be provided as \"EXE %s\"."
5748 (let ((real-com (car (split-string (replace-regexp-in-string " %s" "" exe
)))))
5749 (if (or (get-process real-com
)
5750 (anything-c-get-pid-from-process-name real-com
))
5751 (if anything-raise-command
5752 (shell-command (format anything-raise-command real-com
))
5753 (error "Error: %s is already running" real-com
))
5754 (when (member real-com anything-c-external-commands-list
)
5755 (message "Starting %s..." real-com
)
5757 (start-process-shell-command real-com nil
(format exe file
))
5758 (start-process-shell-command real-com nil real-com
))
5759 (set-process-sentinel
5760 (get-process real-com
)
5761 #'(lambda (process event
)
5762 (when (string= event
"finished\n")
5763 (when anything-raise-command
5764 (shell-command (format anything-raise-command
"emacs")))
5765 (message "%s process...Finished." process
))))
5766 (setq anything-c-external-commands-list
5767 (push (pop (nthcdr (anything-c-position
5768 real-com anything-c-external-commands-list
5770 anything-c-external-commands-list
))
5771 anything-c-external-commands-list
))))))
5773 (defvar anything-external-command-history nil
)
5775 (defun anything-c-run-external-command (program)
5776 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
5777 If program is already running exit with error.
5778 You can set your own list of commands with
5779 `anything-c-external-commands-list'."
5783 (anything-c-external-commands-list-1 'sort
)
5785 :name
"External Commands"
5786 :history anything-external-command-history
)))
5787 (anything-run-or-raise program
)
5788 (setq anything-external-command-history
5789 (cons program
(delete program anything-external-command-history
))))
5791 (defsubst* anything-c-position
(item seq
&key
(test 'eq
))
5792 "A simple and faster replacement of CL `position'."
5793 (loop for i in seq for index from
0
5794 when
(funcall test i item
) return index
))
5796 (defvar anything-c-source-ratpoison-commands
5797 '((name .
"Ratpoison Commands")
5798 (init . anything-c-ratpoison-commands-init
)
5799 (candidates-in-buffer)
5800 (action ("Execute the command" . anything-c-ratpoison-commands-execute
))
5801 (display-to-real . anything-c-ratpoison-commands-display-to-real
)
5802 (candidate-number-limit)))
5803 ;; (anything 'anything-c-source-ratpoison-commands)
5805 (defun anything-c-ratpoison-commands-init ()
5806 (unless (anything-candidate-buffer)
5807 (with-current-buffer (anything-candidate-buffer 'global
)
5808 ;; with ratpoison prefix key
5810 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help"))
5811 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
5812 (replace-match "<ratpoison> \\1: \\2"))
5813 (goto-char (point-max))
5816 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help top"))
5817 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
5818 (replace-match "\\1: \\2")))))
5820 (defun anything-c-ratpoison-commands-display-to-real (display)
5821 (and (string-match ": " display
)
5822 (substring display
(match-end 0))))
5824 (defun anything-c-ratpoison-commands-execute (candidate)
5825 (call-process "ratpoison" nil nil nil
"-ic" candidate
))
5828 (defun anything-ratpoison-commands ()
5829 "Preconfigured `anything' to execute ratpoison commands."
5831 (anything-other-buffer 'anything-c-source-ratpoison-commands
5832 "*anything ratpoison commands*"))
5834 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5836 (defvar anything-c-external-commands-list nil
5837 "A list of all external commands the user can execute. If this
5838 variable is not set by the user, it will be calculated
5841 (defun anything-c-external-commands-list-1 (&optional sort
)
5842 "Returns a list of all external commands the user can execute.
5844 If `anything-c-external-commands-list' is non-nil it will
5845 return its contents. Else it calculates all external commands
5846 and sets `anything-c-external-commands-list'.
5848 The code is ripped out of `eshell-complete-commands-list'."
5849 (if anything-c-external-commands-list
5850 anything-c-external-commands-list
5851 (setq anything-c-external-commands-list
5852 (let* ((paths (split-string (getenv "PATH") path-separator
))
5853 (cwd (file-name-as-directory
5854 (expand-file-name default-directory
)))
5855 (path "") (comps-in-path ())
5856 (file "") (filepath "") (completions ()))
5857 ;; Go thru each path in the search path, finding completions.
5859 (setq path
(file-name-as-directory
5860 (expand-file-name (or (car paths
) ".")))
5862 (and (file-accessible-directory-p path
)
5863 (file-name-all-completions "" path
)))
5864 ;; Go thru each completion found, to see whether it should be
5865 ;; used, e.g. see if it's executable.
5866 (while comps-in-path
5867 (setq file
(car comps-in-path
)
5868 filepath
(concat path file
))
5869 (if (and (not (member file completions
))
5870 (or (string-equal path cwd
)
5871 (not (file-directory-p filepath
)))
5872 (file-executable-p filepath
))
5873 (setq completions
(cons file completions
)))
5874 (setq comps-in-path
(cdr comps-in-path
)))
5875 (setq paths
(cdr paths
)))
5877 (sort completions
#'(lambda (x y
) (string< x y
)))
5880 (defun anything-c-file-buffers (filename)
5881 "Returns a list of buffer names corresponding to FILENAME."
5882 (let ((name (expand-file-name filename
))
5884 (dolist (buf (buffer-list) buf-list
)
5885 (let ((bfn (buffer-file-name buf
)))
5886 (when (and bfn
(string= name bfn
))
5887 (push (buffer-name buf
) buf-list
))))))
5889 (defun anything-c-delete-file (file)
5890 "Delete the given file after querying the user.
5891 Ask to kill buffers associated with that file, too."
5892 (let ((buffers (anything-c-file-buffers file
)))
5893 (dired-delete-file file
'dired-recursive-deletes
)
5895 (dolist (buf buffers
)
5896 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
5897 (kill-buffer buf
))))))
5899 (defun anything-get-mailcap-for-file (filename)
5900 "Get the command to use for FILENAME from mailcap files.
5901 The command is like <command %s> and is meant to use with `format'."
5902 (mailcap-parse-mailcaps)
5903 (let* ((ext (file-name-extension filename
))
5904 (mime (when ext
(mailcap-extension-to-mime ext
))))
5905 (when mime
(mailcap-mime-info mime
))))
5907 (defun anything-c-open-file-externally (file)
5908 "Open FILE with an external tool found in .mailcap file.
5909 If not found or a prefix arg is given query the user which tool to use."
5910 (let* ((fname (expand-file-name file
))
5911 (collection (anything-c-external-commands-list-1 'sort
))
5912 (def-prog (anything-get-mailcap-for-file fname
))
5913 (program (or (unless (or anything-current-prefix-arg
5918 "Program: " collection
5920 :name
"Open file Externally"
5921 :history anything-external-command-history
)
5923 (anything-run-or-raise program file
)
5924 (setq anything-external-command-history
5925 (cons program
(delete program anything-external-command-history
)))))
5928 (defun w32-shell-execute-open-file (file)
5929 (interactive "fOpen file:")
5931 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
5933 (replace-regexp-in-string ; strip cygdrive paths
5934 "/cygdrive/\\(.\\)" "\\1:"
5935 file nil nil
) nil t
))))
5937 (defun anything-c-open-file-with-default-tool (file)
5938 "Open FILE with the default tool on this platform."
5939 (if (eq system-type
'windows-nt
)
5940 (w32-shell-execute-open-file file
)
5941 (start-process "anything-c-open-file-with-default-tool"
5943 (cond ((eq system-type
'gnu
/linux
)
5945 ((or (eq system-type
'darwin
) ;; Mac OS X
5946 (eq system-type
'macos
)) ;; Mac OS 9
5950 (defun anything-c-open-dired (file)
5951 "Opens a dired buffer in FILE's directory. If FILE is a
5952 directory, open this directory."
5953 (if (file-directory-p file
)
5955 (dired (file-name-directory file
))
5956 (dired-goto-file file
)))
5958 (defun anything-c-display-to-real-line (candidate)
5959 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
5960 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
5961 (error "Line number not found")))
5963 (defun anything-c-action-line-goto (lineno-and-content)
5964 (apply #'anything-goto-file-line
(anything-interpret-value (anything-attr 'target-file
))
5965 (append lineno-and-content
5966 (list (if (and (anything-attr-defined 'target-file
)
5967 (not anything-in-persistent-action
))
5968 'find-file-other-window
5971 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
5972 (apply #'anything-goto-file-line
5973 (if (stringp file-line-content
)
5974 ;; Case: filtered-candidate-transformer is skipped
5975 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content
))
5976 file-line-content
)))
5979 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
5980 (delq nil
(mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates
)))
5982 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
5983 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
)
5984 (let ((filename (match-string 1 candidate
))
5985 (lineno (match-string 2 candidate
))
5986 (content (match-string 3 candidate
)))
5987 (cons (format "%s:%s\n %s"
5988 (propertize filename
'face compilation-info-face
)
5989 (propertize lineno
'face compilation-line-face
)
5991 (list (expand-file-name
5993 (or (anything-interpret-value (anything-attr 'default-directory
))
5994 (and (anything-candidate-buffer)
5996 'default-directory
(anything-candidate-buffer)))))
5997 (string-to-number lineno
) content
)))))
5999 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
6000 (anything-aif (anything-attr 'before-jump-hook
)
6002 (when file
(funcall find-file-function file
))
6003 (if (anything-attr-defined 'adjust
)
6004 (anything-c-goto-line-with-adjustment lineno content
)
6005 (anything-goto-line lineno
))
6006 (unless (anything-attr-defined 'recenter
)
6007 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
6008 (anything-aif (anything-attr 'after-jump-hook
)
6010 (when anything-in-persistent-action
6011 (anything-match-line-color-current-line)))
6013 (defun anything-find-file-as-root (candidate)
6014 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
6016 (defun anything-find-many-files (ignore)
6017 (mapc 'find-file
(anything-marked-candidates)))
6019 ;; borrowed from etags.el
6020 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
6021 (defun anything-c-goto-line-with-adjustment (line line-content
)
6024 ;; This constant is 1/2 the initial search window.
6025 ;; There is no sense in making it too small,
6026 ;; since just going around the loop once probably
6027 ;; costs about as much as searching 2000 chars.
6030 pat
(concat (if (eq selective-display t
)
6031 "\\(^\\|\^m\\) *" "^ *") ;allow indent
6032 (regexp-quote line-content
)))
6033 ;; If no char pos was given, try the given line number.
6034 (setq startpos
(progn (anything-goto-line line
) (point)))
6035 (or startpos
(setq startpos
(point-min)))
6036 ;; First see if the tag is right at the specified location.
6037 (goto-char startpos
)
6038 (setq found
(looking-at pat
))
6039 (while (and (not found
)
6041 (goto-char (- startpos offset
))
6044 (re-search-forward pat
(+ startpos offset
) t
)
6045 offset
(* 3 offset
))) ; expand search window
6047 (re-search-forward pat nil t
)
6048 (error "not found")))
6049 ;; Position point at the right place
6050 ;; if the search string matched an extra Ctrl-m at the beginning.
6051 (and (eq selective-display t
)
6054 (beginning-of-line))
6056 (anything-document-attribute 'default-directory
"type . file-line"
6057 "`default-directory' to interpret file.")
6058 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
6059 "Function to call before jumping to the target location.")
6060 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
6061 "Function to call after jumping to the target location.")
6062 (anything-document-attribute 'adjust
"type . file-line"
6063 "Search around line matching line contents.")
6064 (anything-document-attribute 'recenter
"type . file-line / line"
6065 "`recenter' after jumping.")
6066 (anything-document-attribute 'target-file
"type . line"
6067 "Goto line of target-file.")
6070 (defun anything-c-call-interactively (cmd-or-name)
6071 "Execute CMD-OR-NAME as Emacs command.
6072 It is added to `extended-command-history'.
6073 `anything-current-prefix-arg' is used as the command's prefix argument."
6074 (setq extended-command-history
6075 (cons (anything-c-stringify cmd-or-name
)
6076 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
6077 (let ((current-prefix-arg anything-current-prefix-arg
)
6078 (cmd (anything-c-symbolify cmd-or-name
)))
6079 (if (stringp (symbol-function cmd
))
6080 (execute-kbd-macro (symbol-function cmd
))
6081 (setq this-command cmd
)
6082 (call-interactively cmd
))))
6085 (defun anything-c-set-variable (var)
6086 "Set value to VAR interactively."
6088 (let ((sym (anything-c-symbolify var
)))
6089 (set sym
(eval-minibuffer (format "Set %s: " var
)
6090 (prin1-to-string (symbol-value sym
))))))
6092 ;; (anything-c-set-variable 'hh)
6094 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6095 (defvar anything-match-line-overlay-face nil
)
6096 (defvar anything-match-line-overlay nil
)
6098 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
6099 "Highlight and underline current position"
6100 (let ((args (list (or start
(line-beginning-position))
6101 (or end
(1+ (line-end-position)))
6103 (if (not anything-match-line-overlay
)
6104 (setq anything-match-line-overlay
(apply 'make-overlay args
))
6105 (apply 'move-overlay anything-match-line-overlay args
)))
6106 (overlay-put anything-match-line-overlay
6107 'face
(or face anything-match-line-overlay-face
))
6112 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
6114 (defface anything-overlay-line-face
'((t (:background
"IndianRed4" :underline t
)))
6115 "Face for source header in the anything buffer." :group
'anything
)
6117 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
6119 (defun anything-match-line-cleanup ()
6120 (when anything-match-line-overlay
6121 (delete-overlay anything-match-line-overlay
)
6122 (setq anything-match-line-overlay nil
)))
6124 (defun anything-match-line-update ()
6125 (when anything-match-line-overlay
6126 (delete-overlay anything-match-line-overlay
)
6127 (anything-match-line-color-current-line)))
6129 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
6130 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
6132 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6134 (defun anything-c-transform-file-load-el (actions candidate
)
6135 "Add action to load the file CANDIDATE if it is an emacs lisp
6136 file. Else return ACTIONS unmodified."
6137 (if (member (file-name-extension candidate
) '("el" "elc"))
6138 (append actions
'(("Load Emacs Lisp File" . load-file
)))
6141 (defun anything-c-transform-file-browse-url (actions candidate
)
6142 "Add an action to browse the file CANDIDATE if it in a html
6143 file or URL. Else return ACTIONS unmodified."
6144 (let ((browse-action '("Browse with Browser" . browse-url
)))
6145 (cond ((string-match "^http\\|^ftp" candidate
)
6146 (cons browse-action actions
))
6147 ((string-match "\\.html?$" candidate
)
6148 (append actions
(list browse-action
)))
6152 (defun anything-c-transform-function-call-interactively (actions candidate
)
6153 "Add an action to call the function CANDIDATE interactively if
6154 it is a command. Else return ACTIONS unmodified."
6155 (if (commandp (intern-soft candidate
))
6156 (append actions
'(("Call Interactively"
6158 anything-c-call-interactively
)))
6162 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
6163 "If CANDIDATE's `car' is a command, then add an action to
6164 evaluate it and put it onto the `command-history'."
6165 (if (commandp (car (read candidate
)))
6166 ;; Make it first entry
6167 (cons '("Eval and put onto command-history" .
6169 (let ((sym (read sexp
)))
6171 (setq command-history
6172 (cons sym command-history
)))))
6176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6178 (defun anything-c-skip-boring-buffers (buffers)
6179 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
6181 (defun anything-c-skip-current-buffer (buffers)
6182 (if anything-allow-skipping-current-buffer
6183 (remove (buffer-name anything-current-buffer
) buffers
)
6186 (defun anything-c-shadow-boring-buffers (buffers)
6187 "Buffers matching `anything-c-boring-buffer-regexp' will be
6188 displayed with the `file-name-shadow' face if available."
6189 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
6192 (defun anything-c-shadow-boring-files (files)
6193 "Files matching `anything-c-boring-file-regexp' will be
6194 displayed with the `file-name-shadow' face if available."
6195 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
6197 (defun anything-c-skip-boring-files (files)
6198 "Files matching `anything-c-boring-file-regexp' will be skipped."
6199 (anything-c-skip-entries files anything-c-boring-file-regexp
))
6200 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
6202 (defun anything-c-skip-current-file (files)
6203 "Current file will be skipped."
6204 (remove (buffer-file-name anything-current-buffer
) files
))
6206 (defun anything-c-w32-pathname-transformer (args)
6207 "Change undesirable features of windows pathnames to ones more acceptable to
6208 other candidate transformers."
6209 (if (eq system-type
'windows-nt
)
6211 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
6213 (replace-regexp-in-string "\\\\" "/" y
)) args
))
6216 (defun anything-c-shorten-home-path (files)
6217 "Replaces /home/user with ~."
6218 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
6220 (mapcar (lambda (file)
6221 (if (and (stringp file
) (string-match home file
))
6222 (cons (replace-match "~" nil nil file
) file
)
6227 (defun anything-c-mark-interactive-functions (functions)
6228 "Mark interactive functions (commands) with (i) after the function name."
6230 (loop for function in functions
6231 do
(push (cons (concat function
6232 (when (commandp (intern-soft function
)) " (i)"))
6235 finally
(return (nreverse list
)))))
6237 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6238 (defvar anything-c-adaptive-done nil
6239 "nil if history information is not yet stored for the current
6242 (defvar anything-c-adaptive-history nil
6243 "Contains the stored history information.
6244 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
6246 (defadvice anything-initialize
(before anything-c-adaptive-initialize activate
)
6247 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
6248 when anything is started."
6249 (setq anything-c-adaptive-done nil
))
6251 (defadvice anything-exit-minibuffer
(before anything-c-adaptive-exit-minibuffer activate
)
6252 "Advise `anything-exit-minibuffer' to store history information
6253 when a candidate is selected with RET."
6254 (anything-c-adaptive-store-selection))
6256 (defadvice anything-select-action
(before anything-c-adaptive-select-action activate
)
6257 "Advise `anything-select-action' to store history information
6258 when the user goes to the action list with TAB."
6259 (anything-c-adaptive-store-selection))
6261 (defun anything-c-source-use-adaptative-p (&optional source-name
)
6262 "Return current source only if it use adaptative history, nil otherwise."
6263 (let* ((source (or source-name
(anything-get-current-source)))
6264 (adapt-source (or (assoc-default 'filtered-candidate-transformer
6265 (assoc (assoc-default 'type source
)
6266 anything-type-attributes
))
6267 (assoc-default 'candidate-transformer
6268 (assoc (assoc-default 'type source
)
6269 anything-type-attributes
))
6270 (assoc-default 'filtered-candidate-transformer source
)
6271 (assoc-default 'candidate-transformer source
))))
6272 (if (listp adapt-source
)
6273 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
6274 (when (eq adapt-source
'anything-c-adaptive-sort
) source
))))
6276 (defun anything-c-adaptive-store-selection ()
6277 "Store history information for the selected candidate."
6278 (unless anything-c-adaptive-done
6279 (setq anything-c-adaptive-done t
)
6280 (let ((source (anything-c-source-use-adaptative-p)))
6282 (let* ((source-name (or (assoc-default 'type source
)
6283 (assoc-default 'name source
)))
6284 (source-info (or (assoc source-name anything-c-adaptive-history
)
6286 (push (list source-name
) anything-c-adaptive-history
)
6287 (car anything-c-adaptive-history
))))
6288 (selection (anything-get-selection))
6289 (selection-info (progn
6292 (let ((found (assoc selection
(cdr source-info
))))
6297 ;; move entry to the beginning of the
6298 ;; list, so that it doesn't get
6299 ;; trimmed when the history is
6302 (delete found
(cdr source-info
)))
6305 (cadr source-info
)))
6306 (pattern-info (progn
6307 (setcdr selection-info
6309 (let ((found (assoc anything-pattern
(cdr selection-info
))))
6312 (cons anything-pattern
0)
6314 ;; move entry to the beginning of the
6315 ;; list, so if two patterns used the
6316 ;; same number of times then the one
6317 ;; used last appears first in the list
6318 (setcdr selection-info
6319 (delete found
(cdr selection-info
)))
6321 (cdr selection-info
)))
6322 (cadr selection-info
))))
6324 ;; increase usage count
6325 (setcdr pattern-info
(1+ (cdr pattern-info
)))
6327 ;; truncate history if needed
6328 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
6329 (setcdr selection-info
6330 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
6332 (if (file-readable-p anything-c-adaptive-history-file
)
6333 (load-file anything-c-adaptive-history-file
))
6334 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
6336 (defun anything-c-adaptive-save-history ()
6337 "Save history information to file given by `anything-c-adaptive-history-file'."
6341 ";; -*- mode: emacs-lisp -*-\n"
6342 ";; History entries used for anything adaptive display.\n")
6343 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
6346 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
6347 (unless (interactive-p) 'quiet
))))
6349 (defun anything-c-adaptive-sort (candidates source
)
6350 "Sort the CANDIDATES for SOURCE by usage frequency.
6351 This is a filtered candidate transformer you can use for the
6352 attribute `filtered-candidate-transformer' of a source in
6353 `anything-sources' or a type in `anything-type-attributes'."
6354 (let* ((source-name (or (assoc-default 'type source
)
6355 (assoc-default 'name source
)))
6356 (source-info (assoc source-name anything-c-adaptive-history
)))
6357 (if (not source-info
)
6358 ;; if there is no information stored for this source then do nothing
6362 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
6364 (mapcar (lambda (candidate-info)
6366 (dolist (pattern-info (cdr candidate-info
))
6367 (if (not (equal (car pattern-info
)
6369 (incf count
(cdr pattern-info
))
6371 ;; if current pattern is equal to the previously
6372 ;; used one then this candidate has priority
6373 ;; (that's why its count is boosted by 10000) and
6374 ;; it only has to compete with other candidates
6375 ;; which were also selected with the same pattern
6376 (setq count
(+ 10000 (cdr pattern-info
)))
6378 (cons (car candidate-info
) count
)))
6382 ;; sort the list in descending order, so candidates with highest
6383 ;; priorty come first
6384 (setq usage
(sort usage
(lambda (first second
)
6385 (> (cdr first
) (cdr second
)))))
6387 ;; put those candidates first which have the highest usage count
6388 (dolist (info usage
)
6389 (when (member* (car info
) candidates
6390 :test
'anything-c-adaptive-compare
)
6391 (push (car info
) sorted
)
6392 (setq candidates
(remove* (car info
) candidates
6393 :test
'anything-c-adaptive-compare
))))
6395 ;; and append the rest
6396 (append (reverse sorted
) candidates nil
)))))
6398 (defun anything-c-adaptive-compare (x y
)
6399 "Compare candidates X and Y taking into account that the
6400 candidate can be in (DISPLAY . REAL) format."
6401 (equal (if (listp x
)
6408 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6409 (defvar anything-outline-goto-near-line-flag t
)
6410 (defvar anything-outline-using nil
)
6411 (defun anything-after-update-hook--outline ()
6412 (if (and (eq anything-outline-using t
)
6413 (eq anything-outline-goto-near-line-flag t
))
6414 (anything-outline-goto-near-line)))
6415 (add-hook 'anything-after-update-hook
'anything-after-update-hook--outline
)
6417 (defun anything-outline-goto-near-line ()
6418 (with-anything-window
6419 ;; TODO need consideration whether to update position by every input.
6420 (when t
; (equal anything-pattern "")
6421 (anything-goto-line 2)
6422 (let ((lineno (with-current-buffer anything-current-buffer
6423 (line-number-at-pos (car anything-current-position
)))))
6425 (while (<= (progn (skip-chars-forward " ")
6426 (or (number-at-point) lineno
))
6431 (return-from exit
))))
6433 (and (bobp) (forward-line 1))
6434 (and (anything-pos-header-line-p) (forward-line -
2))
6435 (anything-mark-current-line)))))
6437 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6438 ;; Plug-in: info-index
6439 (defun* anything-c-info-init
(&optional
(file (anything-attr 'info-file
)))
6441 (unless (anything-candidate-buffer)
6442 (save-window-excursion
6445 (tobuf (anything-candidate-buffer 'global
))
6446 (infobuf (current-buffer))
6448 (dolist (node (or (anything-attr 'index-nodes
) (Info-index-nodes)))
6449 (Info-goto-node node
)
6450 (goto-char (point-min))
6451 (while (search-forward "\n* " nil t
)
6452 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t
)
6453 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result
)
6454 (setq s
(point-at-bol)
6456 (with-current-buffer tobuf
6457 (insert-buffer-substring infobuf s e
)
6458 (insert "\n"))))))))))
6460 (defun anything-c-info-goto (node-line)
6461 (Info-goto-node (car node-line
))
6462 (anything-goto-line (cdr node-line
)))
6464 (defun anything-c-info-display-to-real (line)
6466 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line
)
6467 (cons (format "(%s)%s" (anything-attr 'info-file
) (match-string 2 line
))
6468 (string-to-number (or (match-string 3 line
) "1")))))
6470 (defun anything-c-make-info-source (file)
6471 `((name .
,(concat "Info Index: " file
))
6473 (init . anything-c-info-init
)
6474 (display-to-real . anything-c-info-display-to-real
)
6475 (get-line . buffer-substring
)
6476 (candidates-in-buffer)
6477 (action ("Goto node" . anything-c-info-goto
))))
6479 (defun anything-compile-source--info-index (source)
6480 (anything-aif (anything-interpret-value (assoc-default 'info-index source
))
6481 (anything-c-make-info-source it
)
6483 (add-to-list 'anything-compile-source-functions
'anything-compile-source--info-index
)
6485 (anything-document-attribute 'info-index
"info-index plugin"
6486 "Create a source of info index very easily.
6488 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
6490 (anything-document-attribute 'index-nodes
"info-index plugin (optional)"
6491 "Index nodes of info file.
6493 If it is omitted, `Info-index-nodes' is used to collect index nodes.
6494 Some info files are missing index specification.
6496 ex. See `anything-c-source-info-screen'.")
6498 ;; Plug-in: candidates-file
6499 (defun anything-compile-source--candidates-file (source)
6500 (if (assoc-default 'candidates-file source
)
6501 `((init anything-p-candidats-file-init
6502 ,@(let ((orig-init (assoc-default 'init source
)))
6503 (cond ((null orig-init
) nil
)
6504 ((functionp orig-init
) (list orig-init
))
6506 (candidates-in-buffer)
6509 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
6511 (defun anything-p-candidats-file-init ()
6512 (destructuring-bind (file &optional updating
)
6513 (anything-mklist (anything-attr 'candidates-file
))
6514 (setq file
(anything-interpret-value file
))
6515 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
6517 (buffer-disable-undo)
6519 (auto-revert-mode 1)))))
6521 (anything-document-attribute 'candidates-file
"candidates-file plugin"
6522 "Use a file as the candidates buffer.
6524 1st argument is a filename, string or function name or variable name.
6525 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
6527 ;; Plug-in: headline
6528 (defun anything-compile-source--anything-headline (source)
6529 (if (assoc-default 'headline source
)
6530 (append '((init . anything-headline-init
)
6531 (get-line . buffer-substring
)
6534 '((candidates-in-buffer)
6535 (persistent-help .
"Show this line")))
6537 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
6539 (defun anything-headline-init ()
6540 (when (and (anything-current-buffer-is-modified)
6541 (with-current-buffer anything-current-buffer
6542 (eval (or (anything-attr 'condition
) t
))))
6543 (anything-headline-make-candidate-buffer
6544 (anything-interpret-value (anything-attr 'headline
))
6545 (anything-interpret-value (anything-attr 'subexp
)))))
6547 (anything-document-attribute 'headline
"Headline plug-in"
6548 "Regexp string for anything-headline to scan.")
6549 (anything-document-attribute 'condition
"Headline plug-in"
6550 "A sexp representing the condition to use anything-headline.")
6551 (anything-document-attribute 'subexp
"Headline plug-in"
6552 "Display (match-string-no-properties subexp).")
6555 (defun anything-headline-get-candidates (regexp subexp
)
6556 (with-current-buffer anything-current-buffer
6558 (goto-char (point-min))
6559 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
6560 (let (hierarchy curhead
)
6562 (if (numberp subexp
)
6563 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
6564 (cons (buffer-substring (point-at-bol) (point-at-eol))
6566 (hierarchies (headlines)
6567 (1+ (loop for
(_ . hierarchy
) in headlines
6568 maximize hierarchy
)))
6570 (loop for i from
0 to hierarchy
6571 collecting
(aref curhead i
)))
6572 (arrange (headlines)
6573 (unless (null headlines
) ; FIX headlines empty bug!
6574 (loop with curhead
= (make-vector (hierarchies headlines
) "")
6575 for
((str . pt
) . hierarchy
) in headlines
6576 do
(aset curhead hierarchy str
)
6579 (format "H%d:%s" (1+ hierarchy
)
6580 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / "))
6585 (loop for re in regexp
6586 for hierarchy from
0
6587 do
(goto-char (point-min))
6590 while
(re-search-forward re nil t
)
6591 collect
(cons (matched) hierarchy
)))
6592 (lambda (a b
) (> (cdar b
) (cdar a
)))))
6593 (loop while
(re-search-forward regexp nil t
)
6594 collect
(matched))))))))
6597 (defun anything-headline-make-candidate-buffer (regexp subexp
)
6598 (with-current-buffer (anything-candidate-buffer 'local
)
6599 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
6602 (with-current-buffer anything-current-buffer
6603 (line-number-at-pos pos
))
6606 (defun anything-headline-goto-position (pos recenter
)
6609 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
6611 (defun anything-revert-buffer (candidate)
6612 (with-current-buffer candidate
6613 (when (buffer-modified-p)
6614 (revert-buffer t t
))))
6616 (defun anything-revert-marked-buffers (candidate)
6617 (dolist (i (anything-marked-candidates))
6618 (anything-revert-buffer i
)))
6620 (defun anything-kill-marked-buffers (candidate)
6621 (dolist (i (anything-marked-candidates))
6624 ;; Plug-in: persistent-help
6625 (defun anything-compile-source--persistent-help (source)
6626 (append source
'((header-line . anything-persistent-help-string
))))
6627 (add-to-list 'anything-compile-source-functions
'anything-compile-source--persistent-help
)
6629 (defun anything-persistent-help-string ()
6630 (substitute-command-keys
6631 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
6632 (or (anything-interpret-value (anything-attr 'persistent-help
))
6633 (anything-aif (or (assoc-default 'persistent-action
6634 (anything-get-current-source))
6635 (assoc-default 'action
6636 (anything-get-current-source)))
6637 (cond ((symbolp it
) (symbol-name it
))
6638 ((listp it
) (or (ignore-errors (caar it
)) ""))))
6640 " (keeping session)")))
6642 (anything-document-attribute 'persistent-help
"persistent-help plug-in"
6643 "A string to explain persistent-action of this source.
6644 It also accepts a function or a variable name.")
6646 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
6648 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6650 (defun anything-c-find-file-or-marked (candidate)
6651 "Open file CANDIDATE or open anything marked files in background."
6652 (let ((marked (anything-marked-candidates)))
6653 (if (> (length marked
) 1)
6654 (dolist (i marked
) (find-file-noselect i
))
6655 (find-file-at-point candidate
))))
6657 ;; FIXME there is a bug in dired that confuse all dired commands
6658 ;; when using this feature, so i suspend it until bug is fixed in emacs.
6660 ;; (defun anything-c-create-dired-on-marked (candidate)
6661 ;; "Create a new dired buffer with only marked candidates."
6662 ;; (let ((marked (anything-marked-candidates))
6663 ;; (buffer-name (read-string "New Dired Buffer: ")))
6664 ;; (dired (cons buffer-name marked))))
6666 (defun anything-delete-marked-files (ignore)
6667 (let* ((files (anything-marked-candidates))
6668 (len (length files
)))
6670 (format "Delete *%s File(s):\n%s"
6672 (mapconcat (lambda (f) (format "- %s\n" f
)) files
""))))
6673 (message "(No deletions performed)")
6675 (set-text-properties 0 (length i
) nil i
)
6676 (anything-c-delete-file i
))
6677 (message "%s File(s) deleted" len
))))
6679 (defun anything-ediff-marked-buffers (candidate &optional merge
)
6680 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
6681 With optional arg `merge' call `ediff-merge-buffers'."
6682 (let ((lg-lst (length (anything-marked-candidates)))
6686 (error "Error:You have to mark at least 1 buffer"))
6688 (setq buf1 anything-current-buffer
6689 buf2
(first (anything-marked-candidates))))
6691 (setq buf1
(first (anything-marked-candidates))
6692 buf2
(second (anything-marked-candidates))))
6694 (error "Error:To much buffers marked!")))
6696 (ediff-merge-buffers buf1 buf2
)
6697 (ediff-buffers buf1 buf2
))))
6699 (defun anything-bookmark-get-bookmark-from-name (bmk)
6700 "Return bookmark name even if it is a bookmark with annotation.
6701 e.g prepended with *.
6702 Return nil if bmk is not a valid bookmark."
6703 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
6704 (if (assoc bookmark bookmark-alist
)
6706 (when (assoc bmk bookmark-alist
)
6709 (defun anything-delete-marked-bookmarks (elm)
6710 "Delete this bookmark or all marked bookmarks."
6711 (let ((bookmark (anything-bookmark-get-bookmark-from-name elm
)))
6712 (anything-aif (anything-marked-candidates)
6714 (let ((bmk (anything-bookmark-get-bookmark-from-name i
)))
6715 (bookmark-delete bmk
'batch
)))
6716 (bookmark-delete bookmark
'batch
))))
6718 (defun anything-require-or-error (feature function
)
6719 (or (require feature nil t
)
6720 (error "Need %s to use `%s'." feature function
)))
6722 (defun anything-find-buffer-on-elscreen (candidate)
6723 "Open buffer in new screen, if marked buffers open all in elscreens."
6724 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
6725 (anything-aif (anything-marked-candidates)
6727 (let ((target-screen (elscreen-find-screen-by-buffer
6728 (get-buffer i
) 'create
)))
6729 (elscreen-goto target-screen
)))
6730 (let ((target-screen (elscreen-find-screen-by-buffer
6731 (get-buffer candidate
) 'create
)))
6732 (elscreen-goto target-screen
))))
6734 (defun anything-elscreen-find-file (file)
6735 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
6736 (elscreen-find-file file
))
6738 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6740 ;;;; Type Attributes
6741 (define-anything-type-attribute 'buffer
6744 '(("Switch to buffer other window" . switch-to-buffer-other-window
)
6745 ("Switch to buffer" . switch-to-buffer
))
6746 '(("Switch to buffer" . switch-to-buffer
)
6747 ("Switch to buffer other window" . switch-to-buffer-other-window
)
6748 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)))
6749 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
6750 ("Display buffer" . display-buffer
)
6751 ("Revert buffer" . anything-revert-buffer
)
6752 ("Revert Marked buffers" . anything-revert-marked-buffers
)
6753 ("Kill buffer" . kill-buffer
)
6754 ("Kill Marked buffers" . anything-kill-marked-buffers
)
6755 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
6756 ("Ediff Merge marked buffers" .
(lambda (candidate)
6757 (anything-ediff-marked-buffers candidate t
))))
6758 (persistent-help .
"Show this buffer")
6759 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers
))
6760 "Buffer or buffer name.")
6762 (define-anything-type-attribute 'file
6765 '(("Find file other window" . find-file-other-window
)
6766 ("Find file(s)" . anything-find-many-files
)
6767 ("Find file as root" . anything-find-file-as-root
))
6768 '(("Find file" . anything-find-many-files
)
6769 ("Find file as root" . anything-find-file-as-root
)
6770 ("Find file other window" . find-file-other-window
)
6771 ("Find file other frame" . find-file-other-frame
)))
6772 ("Open dired in file's directory" . anything-c-open-dired
)
6773 ("Delete file(s)" . anything-delete-marked-files
)
6774 ("Open file externally" . anything-c-open-file-externally
)
6775 ("Open file with default tool" . anything-c-open-file-with-default-tool
))
6776 (persistent-help .
"Show this file")
6777 (action-transformer anything-c-transform-file-load-el
6778 anything-c-transform-file-browse-url
)
6779 (candidate-transformer anything-c-w32-pathname-transformer
6780 anything-c-skip-current-file
6781 anything-c-skip-boring-files
6782 anything-c-shorten-home-path
))
6785 (define-anything-type-attribute 'command
6786 `((action ("Call interactively" . anything-c-call-interactively
)
6787 ("Describe command" . anything-c-describe-function
)
6788 ("Add command to kill ring" . anything-c-kill-new
)
6789 ("Go to command's definition" . anything-c-find-function
))
6790 ;; Sort commands according to their usage count.
6791 (filtered-candidate-transformer . anything-c-adaptive-sort
)
6792 (persistent-action . anything-c-describe-function
))
6793 "Command. (string or symbol)")
6795 (define-anything-type-attribute 'function
6796 '((action ("Describe function" . anything-c-describe-function
)
6797 ("Add function to kill ring" . anything-c-kill-new
)
6798 ("Go to function's definition" . anything-c-find-function
))
6799 (action-transformer anything-c-transform-function-call-interactively
)
6800 (candidate-transformer anything-c-mark-interactive-functions
))
6801 "Function. (string or symbol)")
6803 (define-anything-type-attribute 'variable
6804 '((action ("Describe variable" . anything-c-describe-variable
)
6805 ("Add variable to kill ring" . anything-c-kill-new
)
6806 ("Go to variable's definition" . anything-c-find-variable
)
6807 ("Set variable" . anything-c-set-variable
)))
6810 (define-anything-type-attribute 'sexp
6811 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
6812 ("Add s-expression to kill ring" . kill-new
))
6813 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
6814 "String representing S-Expressions.")
6816 (define-anything-type-attribute 'bookmark
6818 ("Jump to bookmark" .
(lambda (candidate)
6819 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
))
6820 (current-prefix-arg anything-current-prefix-arg
))
6821 (bookmark-jump bookmark
))
6823 ("Jump to BM other window" .
(lambda (candidate)
6824 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
6825 (bookmark-jump-other-window bookmark
))
6827 ("Bookmark edit annotation" .
(lambda (candidate)
6828 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
6829 (bookmark-edit-annotation bookmark
))))
6830 ("Bookmark show annotation" .
(lambda (candidate)
6831 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
6832 (bookmark-show-annotation bookmark
))))
6833 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
6834 ,@(when (fboundp 'bmkext-edit-bookmark
)
6835 '(("Edit Bookmark" .
(lambda (candidate)
6836 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
6837 (bmkext-edit-bookmark bookmark
))))))
6838 ("Rename bookmark" .
(lambda (candidate)
6839 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
6840 (bookmark-rename bookmark
))))
6841 ("Relocate bookmark" .
(lambda (candidate)
6842 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
6843 (bookmark-relocate bookmark
))))))
6846 (define-anything-type-attribute 'line
6847 '((display-to-real . anything-c-display-to-real-line
)
6848 (action ("Go to Line" . anything-c-action-line-goto
)))
6849 "LINENO:CONTENT string, eg. \" 16:foo\".
6851 Optional `target-file' attribute is a name of target file.
6853 Optional `before-jump-hook' attribute is a function with no
6854 arguments which is called before jumping to position.
6856 Optional `after-jump-hook' attribute is a function with no
6857 arguments which is called after jumping to position.
6859 If `adjust' attribute is specified, searches the line whose
6860 content is CONTENT near the LINENO.
6862 If `recenter' attribute is specified, the line is displayed at
6863 the center of window, otherwise at the top of window.
6866 (define-anything-type-attribute 'file-line
6867 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
6869 (action ("Go to" . anything-c-action-file-line-goto
)))
6870 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
6872 Optional `default-directory' attribute is a default-directory
6873 FILENAME is interpreted.
6875 Optional `before-jump-hook' attribute is a function with no
6876 arguments which is called before jumping to position.
6878 Optional `after-jump-hook' attribute is a function with no
6879 arguments which is called after jumping to position.
6881 If `adjust' attribute is specified, searches the line whose
6882 content is CONTENT near the LINENO.
6884 If `recenter' attribute is specified, the line is displayed at
6885 the center of window, otherwise at the top of window.
6888 (define-anything-type-attribute 'timer
6889 '((real-to-display . anything-c-timer-real-to-display
)
6890 (action ("Cancel Timer" . cancel-timer
)
6891 ("Describe Function" .
(lambda (tm) (describe-function (timer--function tm
))))
6892 ("Find Function" .
(lambda (tm) (find-function (timer--function tm
)))))
6893 (persistent-action .
(lambda (tm) (describe-function (timer--function tm
))))
6894 (persistent-help .
"Describe Function"))
6897 ;;;; Default `anything-sources'
6898 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
6899 ;; tend to invoke M-x anything directly. So I offer default setting.
6900 (setq anything-sources
6901 '(anything-c-source-buffers+
6902 anything-c-source-recentf
6903 anything-c-source-files-in-current-dir
+))
6906 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
6907 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
6909 (when (fboundp 'expectations
)
6911 (desc "candidates-file plug-in")
6912 (expect '(anything-p-candidats-file-init)
6913 (assoc-default 'init
6914 (car (anything-compile-sources
6916 (candidates-file .
"test.txt")))
6917 '(anything-compile-source--candidates-file)))))
6918 (expect '(anything-p-candidats-file-init
6920 (assoc-default 'init
6921 (car (anything-compile-sources
6923 (candidates-file .
"test.txt")
6924 (init .
(lambda () 1))))
6925 '(anything-compile-source--candidates-file)))))
6926 (expect '(anything-p-candidats-file-init
6928 (assoc-default 'init
6929 (car (anything-compile-sources
6931 (candidates-file .
"test.txt")
6932 (init (lambda () 1))))
6933 '(anything-compile-source--candidates-file)))))
6934 (desc "anything-c-source-buffers")
6935 (expect '(("Buffers" ("foo" "curbuf")))
6936 (stub buffer-list
=> '("curbuf" " hidden" "foo" "*anything*"))
6937 (let ((anything-c-boring-buffer-regexp
6942 " *Echo Area" " *Minibuf"))))
6943 (flet ((buffer-name (x) x
))
6944 (anything-test-candidates 'anything-c-source-buffers
))))
6945 (desc "anything-c-stringify")
6947 (anything-c-stringify "str1"))
6949 (anything-c-stringify 'str2
))
6950 (desc "anything-c-symbolify")
6952 (anything-c-symbolify "sym1"))
6954 (anything-c-symbolify 'sym2
)))))
6956 (provide 'anything-config
)
6958 ;;; Local Variables:
6959 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
6962 ;; How to save (DO NOT REMOVE!!)
6963 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
6964 ;;; anything-config.el ends here
6966 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
6967 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
6968 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
6969 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
6970 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
6971 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
6972 ;;; LocalWords: dotimes Thierry online vname
6973 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
6974 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
6975 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
6976 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
6977 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
6978 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
6979 ;;; LocalWords: startpos noselect dont desc