emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: shell-command-on-region fooled by long lines


From: Juri Linkov
Subject: Re: shell-command-on-region fooled by long lines
Date: Thu, 09 Feb 2006 21:17:34 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

[followup to address@hidden from address@hidden
> shell-command-on-region on this:
>   perl -le 'for(1..6){print $_ x 111}'
> mistakenly thinks it is showing all the output in the minibuffer, so
> it doesn't create new a new buffer for the output, when in fact it
> gets fooled by the wrapped lines.

This bothered me for a long time too until I realized that the decision
whether to display the output in the echo area or in a separate window
has nothing to do with the amount of lines in the output.

Sometimes I need to display the output in a separate window
even with 1 line to switch to this window later and to do some operation
on it (e.g. save a part of the output to the kill ring).  In all
other cases displaying the output in the echo area is more preferable
to not change the current window configuration.

But with the current code it is not possible to do this without
modifying the function `shell-command-on-region'.  I propose the
following patch that changes this function to call `display-message-or-buffer'
conditionally depending on the value of a new variable
`shell-command-display-message'.  This is not a new feature, but rather is
a fix for a misfeature.

With this variable, users can either set it permanently to nil
to always display the output in a separate window, or let-bind
it depending on the key used to exit the command-reading minibuffer:

(defadvice shell-command (around my-shell-command act)
  (let* ((shell-command-display-message
          (unless (eq last-input-char 'S-return)
            shell-command-display-message)))
    ad-do-it))

This displays the output in the echo area when the minibuffer is exited
with RET, and displays the output in a separate window when the minibuffer
is exited with S-RET.

Index: lisp/simple.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/simple.el,v
retrieving revision 1.790
diff -c -r1.790 simple.el
*** lisp/simple.el      4 Feb 2006 21:48:20 -0000       1.790
--- lisp/simple.el      9 Feb 2006 19:16:09 -0000
***************
*** 1961,1966 ****
--- 1967,1976 ----
               (car (cdr (cdr (process-command process))))
               (substring signal 0 -1))))
  
+ (defvar shell-command-display-message t
+   "If nil, display the output in a pop-up buffer.
+ If non-nil, display the output in the echo area if the output
+ is not too long.  See `display-message-or-buffer'".)
+ 
  (defun shell-command-on-region (start end command
                                      &optional output-buffer replace
                                      error-buffer display-error-buffer)
***************
*** 1987,1993 ****
  \(determined by the variable `max-mini-window-height' if
  `resize-mini-windows' is non-nil), it is shown there.  Otherwise
  it is displayed in the buffer `*Shell Command Output*'.  The output
! is available in that buffer in both cases.
  
  If there is output and an error, a message about the error
  appears at the end of the output.
--- 1997,2005 ----
  \(determined by the variable `max-mini-window-height' if
  `resize-mini-windows' is non-nil), it is shown there.  Otherwise
  it is displayed in the buffer `*Shell Command Output*'.  The output
! is available in that buffer in both cases.  If the variable
! `shell-command-display-message' is nil, it displays the output
! in a pop-up buffer.
  
  If there is output and an error, a message about the error
  appears at the end of the output.
***************
*** 2104,2110 ****
                         (format " - Exit [%d]" exit-status)))))
          (if (with-current-buffer buffer (> (point-max) (point-min)))
              ;; There's some output, display it
!             (display-message-or-buffer buffer)
            ;; No output; error?
            (let ((output
                   (if (and error-file
--- 2116,2126 ----
                         (format " - Exit [%d]" exit-status)))))
          (if (with-current-buffer buffer (> (point-max) (point-min)))
              ;; There's some output, display it
!             (if shell-command-display-message
!                 (display-message-or-buffer buffer)
!               (with-current-buffer buffer
!                 (goto-char (point-min))
!                 (display-buffer (current-buffer))))
            ;; No output; error?
            (let ((output
                   (if (and error-file

-- 
Juri Linkov
http://www.jurta.org/emacs/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]