contrib/anything-grep.el: fontify when grep-highlight-matches is auto
[anything-config.git] / contrib / anything-menu.el
blobd7a9fea7a3c57d5e9d357bd23dd2c1b3a82f277d
1 ;;;; anything-menu.el --- anything.el candidate selection outside Emacs
2 ;; $Id: anything-menu.el,v 1.6 2010-04-01 12:10:35 rubikitch Exp $
4 ;; Copyright (C) 2010 rubikitch
6 ;; Author: rubikitch <rubikitch@ruby-lang.org>
7 ;; Keywords: menu, tools, convenience, anything
8 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/download/anything-menu.el
10 ;; This file is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; This file is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
25 ;;; Commentary:
27 ;; This file provides anything.el candidate selection outside
28 ;; Emacs. You have to enable emacsserver or gnuserv by M-x
29 ;; server-start or M-x gnuserv-start.
31 ;; [EVAL IT] (describe-function 'anything-menu)
32 ;; [EVAL IT] (describe-function 'anything-menu-select)
33 ;; [EVAL IT] (describe-function 'anything-menu-select-from-file)
35 ;; First you have to install anything-menu script, which takes one argument, candidate file.
36 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-menu
38 ;; To demonstrate anything-menu, execute the following from shell
39 ;; $ anything-menu ~/.emacs
42 ;;; Commands:
44 ;; Below are complete command list:
46 ;; `anything-menu'
47 ;; Call `anything' outside Emacs.
49 ;;; Customizable Options:
51 ;; Below are customizable option list:
54 ;;; Installation:
56 ;; Put anything-menu.el to your load-path.
57 ;; The load-path is usually ~/elisp/.
58 ;; It's set in your ~/.emacs like this:
59 ;; (add-to-list 'load-path (expand-file-name "~/elisp"))
61 ;; And the following to your ~/.emacs startup file.
63 ;; (require 'anything-menu)
65 ;; No need more.
67 ;;; Customize:
70 ;; All of the above can customize by:
71 ;; M-x customize-group RET anything-menu RET
75 ;;; History:
77 ;; $Log: anything-menu.el,v $
78 ;; Revision 1.6 2010-04-01 12:10:35 rubikitch
79 ;; * document
80 ;; * `anything-menu': ANY-KEYMAP argument
82 ;; Revision 1.5 2010/02/23 20:39:41 rubikitch
83 ;; add `make-frame-visible'
85 ;; Revision 1.4 2010/02/23 16:48:41 rubikitch
86 ;; migemized
88 ;; Revision 1.3 2010/02/23 10:23:52 rubikitch
89 ;; New function `anything-menu-select-from-file'
91 ;; Revision 1.2 2010/02/23 10:10:34 rubikitch
92 ;; implemented
94 ;; Revision 1.1 2010/02/23 09:44:09 rubikitch
95 ;; initial
98 ;;; Code:
100 (defvar anything-menu-version "$Id: anything-menu.el,v 1.6 2010-04-01 12:10:35 rubikitch Exp $")
101 (require 'anything)
102 (defgroup anything-menu nil
103 "anything-menu"
104 :group 'emacs)
106 (defvar am/tmp-file "/tmp/.am-tmp-file")
107 (defvar am/frame nil)
108 (defun am/set-frame ()
109 (unless (and am/frame (frame-live-p am/frame))
110 (setq am/frame (make-frame '((name . "anything menu")
111 (title . "anything menu")))))
112 (select-frame am/frame)
113 (make-frame-visible am/frame)
114 (sit-for 0))
116 (defun am/close-frame ()
117 (ignore-errors (make-frame-invisible am/frame))
118 (when (fboundp 'do-applescript)
119 (funcall 'do-applescript "tell application \"iTerm\"
120 activate
121 end")))
122 (defun am/write-result (line)
123 (write-region (or line "") nil am/tmp-file nil 'silent))
125 (defun anything-menu (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer any-keymap)
126 "Call `anything' outside Emacs.
127 Arguments are the same as `anything'.
128 Pop up anything frame and close it after session."
129 (interactive)
130 (am/set-frame)
131 (unwind-protect
132 (let ((anything-samewindow t)
133 (anything-display-function 'anything-default-display-buffer)
134 (anything-after-action-hook (lambda () (am/write-result (anything-get-selection)))))
135 (anything any-sources any-input any-prompt any-resume any-preselect any-buffer any-keymap))
136 (am/close-frame)))
138 (defun anything-menu-select (am-prompt &rest am-selections)
139 "Select from a list AM-SELECTIONS and write selection to /tmp/.am-tmp-file,
140 the default file of `am/tmp-file'. "
141 (anything-menu `(((name . ,am-prompt)
142 (candidates . am-selections)
143 (migemo)
144 (action . am/write-result)))
145 nil (concat am-prompt ": ") nil nil "*anything menu select*"))
147 (defun* anything-menu-select-from-file (am-filename &optional (am-prompt "selection"))
148 "Select a candidate in file AM-FILENAME and write selection to /tmp/.am-tmp-file,
149 the default file of `am/tmp-file'.
151 The anything-menu script calls this function and print selection to stdout."
152 (anything-menu `(((name . ,am-prompt)
153 (init . (lambda ()
154 (with-current-buffer (anything-candidate-buffer 'global)
155 (insert-file-contents am-filename))))
156 (candidates-in-buffer)
157 (migemo)
158 (action . am/write-result)))
159 nil (concat am-prompt ": ") nil nil "*anything menu select*"))
161 (provide 'anything-menu)
163 ;; (save-window-excursion (bg2 "gnudoit '(anything-menu-select \"selections\" \"a\" \"b\")'"))
164 ;; (find-sh0 "cat /tmp/.am-tmp-file")
166 ;; How to save (DO NOT REMOVE!!)
167 ;; (progn (magit-push) (emacswiki-post "anything-menu.el"))
168 ;;; anything-menu.el ends here