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)
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.
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
44 ;; Below are complete command list:
47 ;; Call `anything' outside Emacs.
49 ;;; Customizable Options:
51 ;; Below are customizable option list:
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)
70 ;; All of the above can customize by:
71 ;; M-x customize-group RET anything-menu RET
77 ;; $Log: anything-menu.el,v $
78 ;; Revision 1.6 2010-04-01 12:10:35 rubikitch
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
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
94 ;; Revision 1.1 2010/02/23 09:44:09 rubikitch
100 (defvar anything-menu-version
"$Id: anything-menu.el,v 1.6 2010-04-01 12:10:35 rubikitch Exp $")
102 (defgroup anything-menu nil
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
)
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\"
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."
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
))
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
)
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
)
154 (with-current-buffer (anything-candidate-buffer 'global
)
155 (insert-file-contents am-filename
))))
156 (candidates-in-buffer)
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