emacs-devel
[Top][All Lists]
Advanced

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

Re: Intelligent stacking of messages in the echo area


From: Ihor Radchenko
Subject: Re: Intelligent stacking of messages in the echo area
Date: Mon, 23 Dec 2019 11:50:48 +0800

Hi,

FYI:
A slightly improved version of the code, which prevents stacking
potentially "spammy" messages (like from eldoc or
org-display-outline-path). The messages are detected by looking at
messages-log-max variable, which is typically set to nil by such
functions.

(defun set-stacked-message (message)
  (let ((last-message (car messages-stack)))
    (unless (and last-message (equal message (aref last-message 1)))
      (when (and last-message (aref last-message 2)) ;; the last message had 
`message-log-max' equal to nil. Potential clutter.
        (setq messages-stack (cdr messages-stack)))
      (when (and last-message (> (float-time) (+ (aref last-message 0)
                                                 messages-stack-timeout)))
        (setq messages-stack nil))
      (push (vector (float-time) message (not message-log-max)) messages-stack)
      ;; (push (vector (float-time) message) messages-stack)
      (when (> (length messages-stack) messages-stack-max)
        (setf (nthcdr messages-stack-max messages-stack) nil)))
    (mapconcat (lambda (m) (aref m 1))
               (reverse messages-stack)
               messages-stack-separator)))

Also, it would be great to avoid stacking the echo-keystrokes, but I
have no clue how to detect them.

Best,
Ihor


Juri Linkov <address@hidden> writes:

>> If two or more packages use the echo area for informational messages
>> then often they fight each other, overwriting each other's messages.
>>
>> For example, in lisp mode eldoc is automatically enabled in my emacs
>> 26.2 If I also turn on a paren mode which shows in the message area
>> the matching part of a paren outside of the screen then eldoc often
>> overwrites this message with its own documentation message.
>>
>> Maybe the echo area could be smarter and stack messages on top of each
>> other if they come from diferent sources and they are close to each
>> other in time.
>>
>> So in case of the above example, if a message comes from eldoc and
>> parens at the same time in quick succession then the echo area could
>> show both of them in two lines.
>>
>> And if the same source is sending multiple messsages or there is
>> enough delay between two messages from different sources (e.g. 1-2
>> seconds) then it would work as today using only a single line.
>
> Please try to eval the following code in the current master.
>
> It allows messages produced in quick succession to be stacked
> in the echo area.
>
> So for example when both show-paren-mode and eldoc want to show their
> messages at the same time, the echo area shows both of them in two lines,
> e.g.:
>
>   No matching parenthesis found
>   defun: (NAME ARGLIST &optional DOCSTRING DECL &rest BODY)
>
> Caveat: it works best only when resize-mini-windows is at its default value
> 'grow-only'.
>
>
> (defcustom messages-stack-timeout 2
>   "Number of seconds between messages before clearing the stack."
>   :type 'number
>   :group 'minibuffer
>   :version "27.1")
>
> (defcustom messages-stack-max 8
>   "Max size of the message stack."
>   :type 'number
>   :group 'minibuffer
>   :version "27.1")
>
> (defvar messages-stack-separator "\n")
>
> (defvar messages-stack nil)
>
> (defun set-stacked-message (message)
>   (let ((last-message (car messages-stack)))
>     (unless (and last-message (equal message (aref last-message 1)))
>       (when (and last-message (> (float-time) (+ (aref last-message 0)
>                                                  messages-stack-timeout)))
>         (setq messages-stack nil))
>       (push (vector (float-time) message) messages-stack)
>       (when (> (length messages-stack) messages-stack-max)
>         (setf (nthcdr messages-stack-max messages-stack) nil)))
>     (mapconcat (lambda (m) (aref m 1))
>                (reverse messages-stack)
>                messages-stack-separator)))
>
> (setq set-message-function 'set-stacked-message)

-- 
Ihor Radchenko,
PhD,
Center for Advancing Materials Performance from the Nanoscale (CAMP-nano)
State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong 
University, Xi'an, China
Email: address@hidden, address@hidden



reply via email to

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