help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: emacs equivalent of vi %


From: Scott Frazer
Subject: Re: emacs equivalent of vi %
Date: Wed, 13 Aug 2008 13:24:43 -0400
User-agent: Thunderbird 2.0.0.16 (Windows/20080708)

Rustom Mody wrote:
In vi one can do, for example,
:!gcc %
and the current file gets compiled -- ingeneral :
:!someCommand options % otherStuff
and the filename gets interpolated.
Is there any way to get the '%' behavior in emacs?
[Note: I know about compile; I am asking a more general question about
getting the filename]



How about this:

(defun shell-command-on-current-file (command &optional output-buffer 
error-buffer)
  (interactive (list (read-from-minibuffer "Shell command: "
                                           nil nil nil 'shell-command-history)
                     current-prefix-arg
                     shell-command-default-error-buffer))
  (unless (buffer-file-name)
    (error "No file associated with this buffer"))
  (setq command (replace-regexp-in-string "%" (buffer-file-name) command nil t))
  (shell-command command output-buffer error-buffer))


Scott


reply via email to

[Prev in Thread] Current Thread [Next in Thread]