ch11ng / exwm

Emacs X Window Manager
2.86k stars 137 forks source link

Auto-hiding minibuffer does not work even if exwm-workspace-display-echo-area-timeout is not nil #926

Closed zhenhua-wang closed 9 months ago

zhenhua-wang commented 9 months ago

I believe that this is because exwm-workspace--on-echo-area-clear is only called when there is no current message.

(defun exwm-workspace--echo-area-maybe-clear ()
  "Eventually clear the echo area container."
  (exwm--log)
  (if (not (current-message))
      (exwm-workspace--on-echo-area-clear)
    ;; Reschedule.
    (cancel-timer exwm-workspace--display-echo-area-timer)
    (setq exwm-workspace--display-echo-area-timer
          (run-with-timer exwm-workspace-display-echo-area-timeout nil
                          #'exwm-workspace--echo-area-maybe-clear))))

I think that we should change the if condition from (not (current-message)) to (current-message), since we want to clear the echo area when the current message exists.

Actually, I can't figure out the purpose of rescheduling this timer. The timer seems to be scheduled whenever a new message arrives, as in exwm-workspace--on-echo-area-dirty. If that's the case, we probably don't need exwm-workspace--echo-area-maybe-clear. Instead, we could set the timer directly to exwm-workspace--on-echo-area-clear.

medranocalvo commented 9 months ago

I think that we should change the if condition from (not (current-message)) to (current-message), since we want to clear the echo area when the current message exists.

The core of the issue is that there is Emacs functionality (think isearch or similar, I don't remember; perhaps eldoc...) that relies on the echo-area message being visible until cleared. Usually (always?) the echo-area is cleared once the next command is invoked (e.g. next key is pressed).

There might be more info in old issues (I quickly found https://github.com/ch11ng/exwm/issues/581) and commits.

Actually, I can't figure out the purpose of rescheduling this timer. The timer seems to be scheduled whenever a new message arrives, as in exwm-workspace--on-echo-area-dirty. If that's the case, we probably don't need exwm-workspace--echo-area-maybe-clear. Instead, we could set the timer directly to exwm-workspace--on-echo-area-clear.

I think that the idea is to show the echo area whenever it is written into. Then we check periodically and only if no message is displayed do we hide it. I don't know why echo-area-clear-hook is not enough.

[...]

I found 0dd909a11baf3d7d766c1672d726eb59b1474ef2 (my deed) and 5b9f4b0851d27e8132a930dfbfec0b94099a4c9f, dated 2018 and 2019 respectively. I think that the original code unconditionally hid the minibuffer after a timeout, and I changed it to prevent hiding it whenever a message was being displayed. Later @ch11ng hooked into echo-area-clear-hook. This might have rendered the prior mechanism obsolete. Could you try disabling exwm-workspace--display-echo-area-timer and seeing whether it continues working as now does?

If the behaviour you want is to unconditionally hide the minibuffer after a timeout we could potentially add a defcustom for this behaviour. (I don't think it is a good idea at the moment.)

Thank you for looking into this @zhenhua-wang.

zhenhua-wang commented 9 months ago

Thanks for the detailed explanation. It makes perfect sense now. Eldoc users certainly don't want to unconditionally hide the minibuffer.

If the behaviour you want is to unconditionally hide the minibuffer after a timeout we could potentially add a defcustom for this behaviour. (I don't think it is a good idea at the moment.)

Let's keep exwm as it is then. I was misinterpreting the meaning of that timeout variable, and I will try create advices if I ever need this feature.

Could you try disabling exwm-workspace--display-echo-area-timer and seeing whether it continues working as now does?

I just tried this and I do think that we need to keep this mechanism. While disabling exwm-workspace--display-echo-area-timer is fine in most cases, it fails to work when users or packages choose to clear their messages during idle time. For example, executing the following command would cause the minibuffer persisting when the echo area is empty. I don't know how common this situation is, but it's certainly an corner case that disabling exwm-workspace--display-echo-area-timer would fail.

(run-with-idle-timer 5 t (lambda () (message "")))