Late editing . As far as I value upvotes, Jurta's answer is the way to go. And Greg hacked more accurately than mine.
I will leave it all here because it may be worth something, but ...
Mx shell-command-on-region , which by default is bound to M-| .
I see that this does not do what Rohit requested. Using Ch f shell-command-on-region shows that the desired behavior is available in the non-interactive version of the command (by setting the replace argument to non-nil). To do this, we must write a wrapper.
Try this (upload it to *scratch* and run Mx eval-buffer , if it works, copy it to the .emacs file):
(defun shell-command-on-region-replace (start end command) "Run shell-command-on-region interactivly replacing the region in place" (interactive (let (string) (unless (mark) (error "The mark is not set now, so there is no region")) ;; Do this before calling region-beginning ;; and region-end, in case subprocess output ;; relocates them while we are in the minibuffer. ;; call-interactively recognizes region-beginning and ;; region-end specially, leaving them in the history. (setq string (read-from-minibuffer "Shell command on region: " nil nil nil 'shell-command-history)) (list (region-beginning) (region-end) string))) (shell-command-on-region start end command tt) )
And pay attention, as I say in the comments, that this is not a very spectacular thing. But I think it works.
For all readers who do not know how to choose a region:
- Move the βpointβ (current cursor position) to one end of the area and use
C-space to activate the βlabelβ - Move the point to the other end of the area.
- After doing this, call the command
dmckee Oct. 15 '08 at 22:43 2008-10-15 22:43
source share