From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.bugs Subject: Re: shell-command-on-region fooled by long lines Date: Wed, 01 Feb 2006 10:07:13 -0700 Message-ID: References: <87mzhchqqf.fsf@jidanni.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1138832014 31190 80.91.229.2 (1 Feb 2006 22:13:34 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 1 Feb 2006 22:13:34 +0000 (UTC) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Feb 01 23:13:24 2006 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1F4Q9Y-0007FF-1w for geb-bug-gnu-emacs@m.gmane.org; Wed, 01 Feb 2006 23:08:41 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F4Q6S-00086d-Gp for geb-bug-gnu-emacs@m.gmane.org; Wed, 01 Feb 2006 17:05:28 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1F4OCe-0003NQ-Hs for bug-gnu-emacs@gnu.org; Wed, 01 Feb 2006 15:03:45 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1F4NuI-0006Ux-4C for bug-gnu-emacs@gnu.org; Wed, 01 Feb 2006 14:44:48 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F4LWb-0007V2-P2 for bug-gnu-emacs@gnu.org; Wed, 01 Feb 2006 12:12:11 -0500 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1F4LVH-00089F-HD for bug-gnu-emacs@gnu.org; Wed, 01 Feb 2006 12:10:48 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1F4LSj-0000pz-Qr for bug-gnu-emacs@gnu.org; Wed, 01 Feb 2006 18:08:10 +0100 Original-Received: from 207.167.42.60 ([207.167.42.60]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 01 Feb 2006 18:08:09 +0100 Original-Received: from ihs_4664 by 207.167.42.60 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 01 Feb 2006 18:08:09 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-To: bug-gnu-emacs@gnu.org Original-Lines: 98 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 207.167.42.60 User-Agent: Mozilla Thunderbird 0.9 (X11/20041105) X-Accept-Language: en-us, en In-Reply-To: <87mzhchqqf.fsf@jidanni.org> X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:14767 Archived-At: Dan Jacobson wrote: > 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. Adjust the 6 and 111 for your screen > if you don't see the effect. I was using Emacs.geometry: 81x35+-6+. > emacs-version"21.4.1" shell-command always captures the command's output in the *Shell Command Output* buffer. Whether the output is displayed in the echo area or in a pop-up buffer is determined by the resize-mini-windows and max-mini-window-height variables. You are right, though, that the length of the output lines is not considered, only the number of output lines. Here's an experimental version of display-message-or-buffer that counts display lines by comparing each line length to the frame width. It tries to do so efficiently for both empty messages and large messages, like the original: (defun display-message-or-buffer (message &optional buffer-name not-this-window frame) "Display MESSAGE in the echo area if possible, otherwise in a pop-up buffer. MESSAGE may be either a string or a buffer. A buffer is displayed using `display-buffer' if MESSAGE is too long for the maximum height of the echo area, as defined by `max-mini-window-height' if `resize-mini-windows' is non-nil. Returns either the string shown in the echo area, or when a pop-up buffer is used, the window used to display it. If MESSAGE is a string, then the optional argument BUFFER-NAME is the name of the buffer used to display it in the case where a pop-up buffer is used, defaulting to `*Message*'. In the case where MESSAGE is a string and it is displayed in the echo area, it is not specified whether the contents are inserted into the buffer anyway. Optional arguments NOT-THIS-WINDOW and FRAME are as for `display-buffer', and only used if a buffer is displayed." (cond ((and (stringp message) (not (string-match "\n" message)) (<= (length message) (frame-width))) ;; Trivial case where we can use the echo area (message "%s" message)) ((and (stringp message) (= (string-match "\n" message) (1- (length message))) (<= (1- (length message)) (frame-width))) ;; Trivial case where we can just remove single trailing newline (message "%s" (substring message 0 (1- (length message))))) (t ;; General case (with-current-buffer (if (bufferp message) message (get-buffer-create (or buffer-name "*Message*"))) (unless (bufferp message) (erase-buffer) (insert message)) (let* ((max-height (if resize-mini-windows (cond ((floatp max-mini-window-height) (* (frame-height) max-mini-window-height)) ((integerp max-mini-window-height) max-mini-window-height) (t 1)) 1)) (line 1) ; buffer position (height 1)) (unless (= (buffer-size) 0) (unless (> max-height (frame-height)) (save-excursion (goto-char (point-min)) (while (and (<= height max-height) (re-search-forward "\n" nil t)) (unless (eobp) (setq height (1+ height))) (when (> (- (point) line 1) (frame-width)) (setq height (1+ height))) (setq line (point))) (when (> (- (point) line) (frame-width)) (setq height (1+ height))))) (if (> height max-height) (progn ; buffer (goto-char (point-min)) (display-buffer (current-buffer) not-this-window frame)) (progn ; echo area (goto-char (point-max)) (when (bolp) (backward-char 1)) (message "%s" (buffer-substring (point-min) (point))))))))))) -- Kevin Rodgers