[OS X Emacs] Re: How to call "call-process"
David Reitter
david.reitter at gmail.com
Wed May 5 12:01:58 EDT 2010
On May 5, 2010, at 11:54 AM, <siemsen at ucar.edu> <siemsen at ucar.edu> wrote:
> Thanks! Here's what I'm using now:
>
> ; bind Command-Shift-7 to execute PetesLookup and feed it the highlighted string
> (define-key osx-key-mode-map (kbd "A-&")
> (defun execute-PetesLookup ()
> "Execute PetesLookup, feeding it the current selected region as a command-line argument."
> (interactive)
> (call-process "/Users/siemsen/Applications/PetesLookup.app/Contents/MacOS/PetesLookup" nil nil nil
> (buffer-substring (point) (mark)))
> )
> )
>
> This works and is clearly better, but it smells funny to define a named function when the name is never referenced. Is there a way to just invoke call-process, without a defun?
Of course. You would use a lambda expression:
(lambda () "..." (interactive) ...)
instead of the defun.
As I said, it is more flexible to have a named function in things like keymaps or hooks. One reason is that users can do M-x execute-PetesLookup RET, if you have a named command.
By the way, you can add point and mark as optional arguments to the function, and use (interactive "something") to set them automatically. See the DOC string for `interactive'. I don't know what the advantages are beyond being able to call it as a function with arguments.
- D
--
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