Re: sending multiple arguments to shell command with defun and interactive
Glynn Clements <[email protected]> Tue, 18 Oct 2005 13:56:51 +0100
| Newsgroups | gmane.emacs.xemacs.general |
|---|---|
| Message-ID | <[email protected]> |
John Bullock wrote: > I often want to process a block of text with a Perl script, and then > have the original block replaced by the output from the Perl script. I think > this should be very easy to do in XEmacs. Indeed, I've almost done it. But > not quite. > This is the not-quite-working function I have in custom.el: > > (defun perlhello (old new) > (interactive) > (shell-command-on-region (point) > (mark) "perl c:/perl/misc/perlhello.pl" nil t)) > > The problem is simple: I don't know how to pass arguments "old" and "new" to > perlhello.pl. Something like: (shell-command-on-region (point) (mark) (format "perl c:/perl/misc/perlhello.pl \"%s\" \"%s\"" old new) nil t) This might fall down if either old or new contain characters which are meaningful to the shell when inside quotes (e.g. quotes). In that case, you'd have to use call-process directly. > I am sure that the fix has something to do with > (interactive) -- but more than that, I don't know. That's a separate issue. > I'd like to execute this command just by highlighting a block of text and > typing "M-x perlhello old new", where "old" and "new" are just strings that I > will pass to the script. You can't include the arguments along with the command (apart from anything else, Space is bound to minibuffer-complete-word for minibuffer input). You can use e.g.: (interactive "sOld: \nsNew: ") You would type "M-x perlhello RET", and it will prompt for Old: and New: separately. Also, you can get the region via (interactive "r"), e.g. (defun perlhello (start end old new) (interactive "rsOld: \nsNew: ") This has the advantage (over using (point) and (mark) directly) that the arguments will always be passed smallest-first. -- Glynn Clements <[email protected]>