- 2007-01-30 (Tue) 01:49
- ソフトウェア ( Meadow/Emacs )
ついでなので,元のリージョンの内容を出力の上部にコメントとして出力するものも作った.
(defun perform-command-region (start end command)
(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.
(setq string (read-from-minibuffer "Shell command on region: "
nil nil nil
'shell-command-history))
;; call-interactively recognizes region-beginning and
;; region-end specially, leaving them in the history.
(list (region-beginning) (region-end) string)))
(let (exit-status)
;; Replace specified region with output from command.
(let ((swap (< start end)))
(goto-char start)
(kill-region start end)
(yank)
(push-mark (point) 'nomsg)
(setq exit-status
;; see describe-function
;; error output is marged into standard output
(call-process-region start end shell-file-name t
(list t t)
nil shell-command-switch command))
;; swap the point and mark if necessary
(and swap (exchange-point-and-mark))
;; mark current position
(setq p1 (point-marker))
(set-marker-insertion-type p1 nil)
;; yank the original contents
(yank nil)
(setq p2 (point-marker))
;; comment the yanked contents
(comment-region (marker-position p1) (marker-position p2))
(setq p1 nil)
(setq p1 nil))
exit-status))
(define-key global-map [(control meta ?!)] 'perform-command-region)
そして C-M-! で発動すると.これって comment-region がない場合にどうなるんだろう?
- Newer: Meadow で Ispell