display-message-or-buffer?

Raymond Toy toy.raymond at gmail.com
Fri Jun 22 12:49:48 EDT 2012


On Fri, Jun 22, 2012 at 9:24 AM, Raymond Toy <toy.raymond at gmail.com> wrote:

>
> Ray
>
> P.S. The function isn't very big.  It's 67 lines including docstring.
>
>
This seems to work.  I just changed the original to use xemacs
resize-minibuffer-* variables.

Ray

(defun display-message-or-buffer (message
                  &optional buffer-name not-this-window frame)
  (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
     ;; General case
     (with-current-buffer
         (if (bufferp message)
         message
           (get-buffer-create (or buffer-name "*Message*")))

       (unless (bufferp message)
         (erase-buffer)
         (insert message))

       (let ((lines
          (if (= (buffer-size) 0)
              0
            (count-screen-lines nil nil nil (minibuffer-window)))))
         (cond ((= lines 0))
           ((and (or (<= lines 1)
                 (<= lines
                 (if resize-minibuffer-frame
                     (cond ((integerp resize-minibuffer-window-max-height)
                        resize-minibuffer-window-max-height)
                       (t
                        1))
                   1)))
             ;; Don't use the echo area if the output buffer is
             ;; already dispayed in the selected frame.
             (not (get-buffer-window (current-buffer))))
            ;; Echo area
            (goto-char (point-max))
            (when (bolp)
              (backward-char 1))
            (message "%s" (buffer-substring (point-min) (point))))
           (t
            ;; Buffer
            (goto-char (point-min))
            (display-buffer (current-buffer)
                    not-this-window frame))))))))


More information about the XEmacs-Beta mailing list