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

2
  • At the linked issue, is was claimed an hour ago that the issue has been fixed. Jan 30, 2016 at 21:09
  • The fix there is suboptimal. We are looking for a better solution. Jan 30, 2016 at 23:13

3 Answers 3

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.

1
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.

1
  • 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. Feb 8, 2016 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.