all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* dired: "!" How to see not just result, but !-cmd too?
@ 2005-01-15  5:21 David Combs
  2005-01-17 16:40 ` Kevin Rodgers
  2005-01-20 13:23 ` Matthias
  0 siblings, 2 replies; 6+ messages in thread
From: David Combs @ 2005-01-15  5:21 UTC (permalink / raw)




Problem: the dired "!"-cmd leaves only it's *output* in *Shell Command
Output*; sure be nice if it also left the *command* (and args) that
got *executed*.

So that if you come back to that buffer later on, there's
no question as to what !-cmd you did "way back then" 
to *create* the buffer!

Sure would be a lot more user-friendly!


Thanks,

David

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dired: "!" How to see not just result, but !-cmd too?
  2005-01-15  5:21 dired: "!" How to see not just result, but !-cmd too? David Combs
@ 2005-01-17 16:40 ` Kevin Rodgers
  2005-01-20 13:23 ` Matthias
  1 sibling, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2005-01-17 16:40 UTC (permalink / raw)


David Combs wrote:
 > Problem: the dired "!"-cmd leaves only it's *output* in *Shell Command
 > Output*; sure be nice if it also left the *command* (and args) that
 > got *executed*.
 >
 > So that if you come back to that buffer later on, there's
 > no question as to what !-cmd you did "way back then"
 > to *create* the buffer!

You can access previous shell commands at the `!' prompt via `M-p'.

If you want to keep each Dired buffer's commands separate from other
shell commands, try this:

(add-hook 'dired-mode-hook
           (lambda () (make-local-variable 'shell-command-history)))

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dired: "!" How to see not just result, but !-cmd too?
  2005-01-15  5:21 dired: "!" How to see not just result, but !-cmd too? David Combs
  2005-01-17 16:40 ` Kevin Rodgers
@ 2005-01-20 13:23 ` Matthias
  2005-01-20 16:28   ` Kevin Rodgers
  2005-01-21 17:38   ` Kevin Rodgers
  1 sibling, 2 replies; 6+ messages in thread
From: Matthias @ 2005-01-20 13:23 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dired: "!" How to see not just result, but !-cmd too?
  2005-01-20 13:23 ` Matthias
@ 2005-01-20 16:28   ` Kevin Rodgers
  2005-01-21 17:38   ` Kevin Rodgers
  1 sibling, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2005-01-20 16:28 UTC (permalink / raw)


Matthias wrote:
 > 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.

Sigh.

(defadvice shell-command (after insert-command-comment activate)
   "Insert COMMAND as a comment at the top of the output buffer."
   (save-excursion
     (set-buffer (or (ad-get-arg 1)      ; OUTPUT-BUFFER
                     "*Shell Command Output*"))
     (goto-char (point-min))
     (insert "# " (ad-get-arg 0) "\n"))) ; COMMAND

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dired: "!" How to see not just result, but !-cmd too?
  2005-01-20 13:23 ` Matthias
  2005-01-20 16:28   ` Kevin Rodgers
@ 2005-01-21 17:38   ` Kevin Rodgers
  2005-01-24 12:49     ` Matthias
  1 sibling, 1 reply; 6+ messages in thread
From: Kevin Rodgers @ 2005-01-21 17:38 UTC (permalink / raw)


Matthias wrote:
 > Here is a modified `shell-command': it shows the command in the header
 > line of the output buffer.

Ah, now I see what you've done.  Using header-line-format format is much
better than inserting a comment.  But using defadvice is much better
than redefining an 86-line function:

(defadvice shell-command (after insert-command-comment activate)
   "Insert COMMAND as a comment at the top of the output buffer."
   ;; Alternatives to truncating multi-line commands:
   ;; 1. Replace each newline with a semicolon.
   ;; 2. Truncate, but append an ellipsis.
   (save-excursion
     ;; (ad-get-arg 0) == COMMAND
     ;; (ad-get-arg 1) == OUTPUT-BUFFER
     (set-buffer (or (ad-get-arg 1)
                     "*Shell Command Output*"))
     (setq header-line-format
           (replace-regexp-in-string "%" "%%"
                                     (substring (ad-get-arg 0)
                                                0
                                                (string-match "\n"
 
(ad-get-arg 0)))
                                     nil t))))

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: dired: "!" How to see not just result, but !-cmd too?
  2005-01-21 17:38   ` Kevin Rodgers
@ 2005-01-24 12:49     ` Matthias
  0 siblings, 0 replies; 6+ messages in thread
From: Matthias @ 2005-01-24 12:49 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> wrote:

> (...) But using defadvice is much better than redefining an 86-line
> function:

Sure!

Your code is cleaner and seems to work. Adopted!

Thank you.
-- 
Matthias

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-01-24 12:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-15  5:21 dired: "!" How to see not just result, but !-cmd too? David Combs
2005-01-17 16:40 ` Kevin Rodgers
2005-01-20 13:23 ` Matthias
2005-01-20 16:28   ` Kevin Rodgers
2005-01-21 17:38   ` Kevin Rodgers
2005-01-24 12:49     ` Matthias

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.