* shell-command-on-region fooled by long lines
@ 2006-02-01 0:23 Dan Jacobson
2006-02-01 17:07 ` Kevin Rodgers
0 siblings, 1 reply; 5+ messages in thread
From: Dan Jacobson @ 2006-02-01 0:23 UTC (permalink / raw)
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"
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: shell-command-on-region fooled by long lines
2006-02-01 0:23 shell-command-on-region fooled by long lines Dan Jacobson
@ 2006-02-01 17:07 ` Kevin Rodgers
2006-02-02 16:49 ` Kevin Rodgers
0 siblings, 1 reply; 5+ messages in thread
From: Kevin Rodgers @ 2006-02-01 17:07 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: shell-command-on-region fooled by long lines
2006-02-01 17:07 ` Kevin Rodgers
@ 2006-02-02 16:49 ` Kevin Rodgers
2006-02-02 19:54 ` Kevin Rodgers
0 siblings, 1 reply; 5+ messages in thread
From: Kevin Rodgers @ 2006-02-02 16:49 UTC (permalink / raw)
Kevin Rodgers wrote:
> 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:
Thanks to the clue posted by Sam Owre in a subsequent thread, this is
all that's needed:
2006-02-02 Kevin Rodgers <ihs_4664@yahoo.com>
* simple.el (display-message-or-buffer): Count screen lines
instead of buffer lines when determining whether the message
will fit in the echo area/minibuffer window.
*** simple.el~ Thu Feb 2 09:31:34 2006
--- simple.el Thu Feb 2 09:35:18 2006
***************
*** 1922,1928 ****
(let ((lines
(if (= (buffer-size) 0)
0
! (count-lines (point-min) (point-max)))))
(cond ((= lines 0))
((and (or (<= lines 1)
(<= lines
--- 1922,1928 ----
(let ((lines
(if (= (buffer-size) 0)
0
! (count-screen-lines nil nil t (minibuffer-window)))))
(cond ((= lines 0))
((and (or (<= lines 1)
(<= lines
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: shell-command-on-region fooled by long lines
2006-02-02 16:49 ` Kevin Rodgers
@ 2006-02-02 19:54 ` Kevin Rodgers
2006-02-03 16:31 ` Kevin Rodgers
0 siblings, 1 reply; 5+ messages in thread
From: Kevin Rodgers @ 2006-02-02 19:54 UTC (permalink / raw)
Kevin Rodgers wrote:
> Thanks to the clue posted by Sam Owre in a subsequent thread, this is
> all that's needed:
Oops. A final newline is ignored when displaying the message in the
echo area, so the call to count-screen-lines should specify nil for
the COUNT-FINAL-NEWLINE argument:
2006-02-02 Kevin Rodgers <ihs_4664@yahoo.com>
* simple.el (display-message-or-buffer): Count screen lines
instead of buffer lines when determining whether the message
will fit in the echo area/minibuffer window.
*** simple.el~ Thu Feb 2 09:31:34 2006
--- simple.el Thu Feb 2 09:35:18 2006
***************
*** 1922,1928 ****
(let ((lines
(if (= (buffer-size) 0)
0
! (count-lines (point-min) (point-max)))))
(cond ((= lines 0))
((and (or (<= lines 1)
(<= lines
--- 1922,1928 ----
(let ((lines
(if (= (buffer-size) 0)
0
! (count-screen-lines nil nil nil (minibuffer-window)))))
(cond ((= lines 0))
((and (or (<= lines 1)
(<= lines
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: shell-command-on-region fooled by long lines
2006-02-02 19:54 ` Kevin Rodgers
@ 2006-02-03 16:31 ` Kevin Rodgers
0 siblings, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2006-02-03 16:31 UTC (permalink / raw)
Kevin Rodgers wrote:
> Oops. A final newline is ignored when displaying the message in the
> echo area, so the call to count-screen-lines should specify nil for
> the COUNT-FINAL-NEWLINE argument:
Sorry, I forgot to handle the trivial 1-line string cases:
2006-02-03 Kevin Rodgers <ihs_4664@yahoo.com>
* simple.el (display-message-or-buffer): Compare the number of
characters to the frame width when determining whether a 1-line
message string will fit in the echo area. Count screen lines
instead of buffer lines when determining whether a multi-line
message will fit in the echo area/minibuffer window.
*** simple.el~ Thu Feb 2 09:31:34 2006
--- simple.el Fri Feb 3 09:30:19 2006
***************
*** 1901,1911 ****
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)))
;; Trivial case where we can use the echo area
(message "%s" message))
((and (stringp message)
! (= (string-match "\n" message) (1- (length message))))
;; Trivial case where we can just remove single trailing newline
(message "%s" (substring message 0 (1- (length message)))))
(t
--- 1901,1914 ----
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)
! (equal (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
***************
*** 1922,1928 ****
(let ((lines
(if (= (buffer-size) 0)
0
! (count-lines (point-min) (point-max)))))
(cond ((= lines 0))
((and (or (<= lines 1)
(<= lines
--- 1925,1931 ----
(let ((lines
(if (= (buffer-size) 0)
0
! (count-screen-lines nil nil nil (minibuffer-window)))))
(cond ((= lines 0))
((and (or (<= lines 1)
(<= lines
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-02-03 16:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-01 0:23 shell-command-on-region fooled by long lines Dan Jacobson
2006-02-01 17:07 ` Kevin Rodgers
2006-02-02 16:49 ` Kevin Rodgers
2006-02-02 19:54 ` Kevin Rodgers
2006-02-03 16:31 ` Kevin Rodgers
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.