From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Matthias Newsgroups: gmane.emacs.help Subject: Re: dired: "!" How to see not just result, but !-cmd too? Date: 20 Jan 2005 14:23:48 +0100 Organization: Dans quel but ? Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1106227847 24091 80.91.229.6 (20 Jan 2005 13:30:47 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 20 Jan 2005 13:30:47 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jan 20 14:30:39 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CrcOV-0003Hl-00 for ; Thu, 20 Jan 2005 14:30:39 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1CrcaV-00020Y-OA for geh-help-gnu-emacs@m.gmane.org; Thu, 20 Jan 2005 08:43:03 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news2.google.com!proxad.net!freenix!uvsq.fr!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 95 Original-NNTP-Posting-Host: fermat.math.uvsq.fr Original-X-Trace: io.uvsq.fr 1106227428 64323 193.51.32.1 (20 Jan 2005 13:23:48 GMT) Original-X-Complaints-To: Newsmaster@uvsq.fr Original-NNTP-Posting-Date: Thu, 20 Jan 2005 13:23:48 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Original-Xref: shelby.stanford.edu gnu.emacs.help:128016 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:23506 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:23506 Here is a modified `shell-command': it shows the command in the header line of the output buffer. Note that the new code is only four or five lines long (you can use the `fixme' comments as flags to found it); I've removed the documentation spec to shorten the code. (defun shell-command-default-error-buffer ;; Look for a handler in case default-directory is a remote file name. (let ((handler (find-file-name-handler (directory-file-name default-directory) 'shell-command))) (if handler (funcall handler 'shell-command command output-buffer error-buffer) (if (and output-buffer (not (or (bufferp output-buffer) (stringp output-buffer)))) (let ((error-file (if error-buffer (make-temp-file (expand-file-name "scor" (or small-temporary-file-directory temporary-file-directory))) nil))) (barf-if-buffer-read-only) (push-mark nil t) ;; We do not use -f for csh; we will not support broken use of ;; .cshrcs. Even the BSD csh manual says to use ;; "if ($?prompt) exit" before things which are not useful ;; non-interactively. Besides, if someone wants their other ;; aliases for shell commands then they can still have them. (call-process shell-file-name nil (if error-file (list t error-file) t) nil shell-command-switch command) (when (and error-file (file-exists-p error-file)) (if (< 0 (nth 7 (file-attributes error-file))) (with-current-buffer (get-buffer-create error-buffer) (let ((pos-from-end (- (point-max) (point)))) (or (bobp) (insert "\f\n")) ;; Do no formatting while reading error file, ;; because that can run a shell command, and we ;; don't want that to cause an infinite recursion. (format-insert-file error-file nil) ;; Put point after the inserted errors. (goto-char (- (point-max) pos-from-end))) (display-buffer (current-buffer)))) (delete-file error-file)) ;; This is like exchange-point-and-mark, but doesn't ;; activate the mark. It is cleaner to avoid activation, ;; even though the command loop would deactivate the mark ;; because we inserted text. (goto-char (prog1 (mark t) (set-marker (mark-marker) (point) (current-buffer))))) ;; Preserve the match data in case called from a program. (save-match-data (if (string-match "[ \t]*&[ \t]*$" command) ;; Command ending with ampersand means asynchronous. (let ((buffer (get-buffer-create (or output-buffer "*Async Shell Command*"))) (directory default-directory) proc) ;; Remove the ampersand. (setq command (substring command 0 (match-beginning 0))) ;; If will kill a process, query first. (setq proc (get-buffer-process buffer)) (if proc (if (yes-or-no-p "A command is running. Kill it? ") (kill-process proc) (error "Shell command in progress"))) (save-excursion (set-buffer buffer) (setq buffer-read-only nil) (erase-buffer) (display-buffer buffer) (setq default-directory directory) (setq proc (start-process "Shell" buffer shell-file-name shell-command-switch command)) (setq mode-line-process '(":%s")) (require 'shell) (shell-mode) ;; Fixme: ensure that it is one line only; add the ampersand (setq header-line-format command) (set-process-sentinel proc 'shell-command-sentinel) )) (shell-command-on-region (point) (point) command output-buffer nil error-buffer) ;; Fixme: ensure that it is one line only (let ((buffer (or output-buffer "*Shell Command Output*"))) (save-excursion (set-buffer buffer) (setq header-line-format command))))))))) -- Matthias