[OS X Emacs] Re: How to call "call-process"
David Reitter
david.reitter at gmail.com
Wed May 5 08:32:30 EDT 2010
On May 5, 2010, at 2:10 AM, Pete Siemsen wrote:
> (defun call-PetesLookup ()
> "Execute PetesLookup, feeding it the current selected region as a command-line argument."
> (interactive)
> (progn
> (setq searchterm (buffer-substring (point) (mark)))
> (call-process "/Users/siemsen/Applications/PetesLookup.app/Contents/MacOS/PetesLookup" nil nil nil searchterm)
> )
> )
> (define-key osx-key-mode-map (kbd "A-&") 'call-PetesLookup)
>
> I'm certainly no Elisp wizard, so this may not be optimal, but it works.
Good. A couple of things to make it perfect:
- there's no need for the `progn'.
- you don't want to define a global variable ("dynamic" variable) when you don't need to. So you'd want to let-bind it:
(let ((searchterm ...))
(call-process ... searchterm))
- However, you don't need the variable at all: it is referred to only once. Just put the buffer-substring expression directly into the `call-process' form.
(In the same vein, you could put the `defun' right into the `define-key' form, because it returns the name of the defined function, like this:
(define-key osx-key-mode-map (kbd "A-&")
(defun call-PetesLookup ()
...))
but most people don't do that.
--
http://aquamacs.org -- Aquamacs: Emacs on Mac OS X
http://aquamacs.org/donate -- Could we help you? Return the favor and support the Aquamacs Project!
More information about the MacOSX-Emacs
mailing list