6

In haskell-doc-mode we have a timer that shows useful tips in minibuffer when cursor is idle for a moment. In other part of Haskell Mode there is code asking questions using y-or-n-p or read-event. The problem is haskell-doc-mode does not know about this and overwrites echo area. Users are confused and think Emacs is hanging.

Is there a general mechanism to detect if read-event or y-or-n-p is running?

Link to the reported issue:

https://github.com/haskell/haskell-mode/issues/820

Drew
  • 75,699
  • 9
  • 109
  • 225
Gracjan Polak
  • 1,082
  • 6
  • 21

3 Answers3

6

Best method seems to be found in eldoc that also displays temporary info in minibuffer:

;; Decide whether now is a good time to display a message.
(defun eldoc-display-message-p ()
  (and (eldoc-display-message-no-interference-p)
       ;; If this-command is non-nil while running via an idle
       ;; timer, we're still in the middle of executing a command,
       ;; e.g. a query-replace where it would be annoying to
       ;; overwrite the echo area.
       (not this-command)
       (eldoc--message-command-p last-command)))

Specifically (not this-command) ensures that no user command is running and that solves the problem in question.

Gracjan Polak
  • 1,082
  • 6
  • 21
1

For y-or-n-p, you could check the value of input-method-use-echo-area. It is turned on by read-key-sequence, which is indirectly used by y-or-n-p – and quite likely by various other commands you'd like to treat the same way.

Detecting an active read-event seems to be harder. Perhaps it's preferable to call it via a wrapper which rebinds some variable to let you detect its use.

Harald Hanche-Olsen
  • 2,401
  • 12
  • 15
  • Gracjan's answer is so much better, perhaps I should delete this one. But as it not utterly wrong, just incomplete, it doesn't seem quite right to do so. It's like rewriting history. – Harald Hanche-Olsen Feb 08 '16 at 11:27
0

I believe you could check the return value of current-message.

IIRC you can use the haskell-doc.el by enabling eldoc-mode instead of haskell-doc-mode (at least that worked for me at some point), so maybe an alternative solution is to deprecate haskell-doc-mode and rely on eldoc-mode (which is enabled by default in Emacs-25) instead.

Stefan
  • 26,154
  • 3
  • 46
  • 84