Article View: gnu.emacs.bug
Article #99402shell-command-on-region
From: Jamie Zawinski
Date: Thu, 20 Sep 1990 06:51
Date: Thu, 20 Sep 1990 06:51
53 lines
2837 bytes
2837 bytes
I think it's bad for shell-command-on-region to start the shell such that it
executes my .cshrc. If the .cshrc generates any output or errors, things get
confused. Granted, in a perfect world, your .cshrc wouldn't do anything
untoward, but, for example, when shell-command-on-region starts a shell,
stdin is not a pty and "tset" and "stty" bomb on some systems.
(It's a lot faster without the init file anyway, and is it really appropriate
for shell-command-on-region to see your aliases?)
Here's a version that has it on a switch.
-- Jamie
(defvar shell-command-on-region-use-init-file-p nil
"*Whether the shell started by shell-command-on-region will execute your
.cshrc (for csh) or .profile (for sh) on startup. If this is nil, it will
be faster, and things are more likely to work in general.")
(defun shell-command-on-region (start end command &optional flag interactive)
"Execute string COMMAND in inferior shell with region as input.
Normally display output (if any) in temp buffer;
Prefix arg means replace the region with it.
Noninteractive args are START, END, COMMAND, FLAG.
Noninteractively FLAG means insert output in place of text from START to END,
and put point at the end, but don't alter the mark."
(interactive "r\nsShell command on region: \nP\np")
(if flag
;; Replace specified region with output from command.
(let ((swap (and interactive (< (point) (mark)))))
;; Don't muck with mark
;; unless called interactively.
(and interactive (push-mark))
(call-process-region start end shell-file-name t t nil
(if shell-command-on-region-use-init-file-p
"-c" "-fc")
command)
(and interactive swap (exchange-point-and-mark)))
(let ((buffer (get-buffer-create "*Shell Command Output*")))
(save-excursion
(set-buffer buffer)
(erase-buffer))
(if (eq buffer (current-buffer))
(setq start 1 end 1))
(call-process-region start end shell-file-name
nil buffer nil
(if shell-command-on-region-use-init-file-p
"-c" "-fc")
command)
(if (save-excursion
(set-buffer buffer)
(> (buffer-size) 0))
(set-window-start (display-buffer buffer) 1)
(message "(Shell command completed with no output)")))))
Technical Details
Message-ID:
<JWZ.90Sep19235137@kolyma.lucid.com>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!rutgers!shelby!neon!lucid.com!jwzShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fb2f1,f37c36abb0176cfd,start X-Google-Attributes: gidfb2f1,public X-Google-ArrivalTime: 1990-09-20 18:58:21 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!rutgers!shelby!neon!lucid.com!jwz From: jwz@lucid.com (Jamie Zawinski) Newsgroups: gnu.emacs.bug Subject: shell-command-on-region Message-ID: <JWZ.90Sep19235137@kolyma.lucid.com> Date: 20 Sep 90 06:51:37 GMT Sender: jwz@lucid.com Organization: Lucid, Inc., Menlo Park, CA Lines: 53 Posted: Thu Sep 20 07:51:37 1990