Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions flycheck-pos-tip.el
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ messages on TTY frames if `flycheck-pos-tip-mode' is active."
(setq flycheck-pos-tip--last-pos
(list (current-buffer) (buffer-modified-tick) (point)))))

(defconst flycheck-pos-tip--hide-hooks '(post-command-hook focus-out-hook)
"List of hooks used to hide tooltips.")

(defun flycheck-pos-tip-error-messages (errors)
"Display ERRORS, using a graphical tooltip on GUI frames."
(when errors
Expand All @@ -93,11 +96,15 @@ messages on TTY frames if `flycheck-pos-tip-mode' is active."
;; pos-tip computes the offset from the top of the line
;; apparently.
nil (and line-height (+ line-height 5))))
(funcall flycheck-pos-tip-display-errors-tty-function errors))))
(funcall flycheck-pos-tip-display-errors-tty-function errors))
(dolist (hook flycheck-pos-tip--hide-hooks)
(add-hook hook #'flycheck-pos-tip-hide-messages))))

(defun flycheck-pos-tip-hide-messages ()
"Hide messages currently being shown if any."
(unless (flycheck-pos-tip--check-pos)
(dolist (hook flycheck-pos-tip--hide-hooks)
(remove-hook hook #'flycheck-pos-tip-hide-messages))
Comment on lines +106 to +107
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be out of the unless block?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that doesn't quite work. flycheck-pos-tip-hide-messages is called in post-command-hook so invoking any command that doesn't happen to move point would cause the hook to be removed if it was outside of the unless block.

Consider the following example operations:

  1. Move point onto a highlighted error. Wait a bit, then the tooltip will be displayed.
  2. Press C-h . (or even just C-g, etc.) which is a command that does not change current-buffer, buffer-modified-tick, or point
  3. Move point off of the error. This should hide the tooltip

With the suggested snippet moved outside of the unless block, (3) does not hide the error as it should.

(Sorry for the delay, I had a lot of personal stuff going on recently.)

(if (display-graphic-p)
(pos-tip-hide)
(flycheck-hide-error-buffer))))
Expand All @@ -123,29 +130,23 @@ GUI tooltip. Falls back to `flycheck-display-error-messages' on
TTY frames."
:global t
:group 'flycheck
(let ((hooks '(post-command-hook focus-out-hook)))
(cond
;; Use our display function and remember the old one but only if we haven't
;; yet configured it, to avoid activating twice.
((and flycheck-pos-tip-mode
(not (eq flycheck-display-errors-function
#'flycheck-pos-tip-error-messages)))
(setq flycheck-pos-tip-old-display-function
flycheck-display-errors-function
flycheck-display-errors-function
#'flycheck-pos-tip-error-messages)
(dolist (hook hooks)
(add-hook hook #'flycheck-pos-tip-hide-messages)))
;; Reset the display function and remove ourselves from all hooks but only
;; if the mode is still active.
((and (not flycheck-pos-tip-mode)
(eq flycheck-display-errors-function
#'flycheck-pos-tip-error-messages))
(setq flycheck-display-errors-function
flycheck-pos-tip-old-display-function
flycheck-pos-tip-old-display-function nil)
(dolist (hook hooks)
(remove-hook hook 'flycheck-pos-tip-hide-messages))))))
(cond
;; Use our display function and remember the old one but only if we haven't
;; yet configured it, to avoid activating twice.
((and flycheck-pos-tip-mode
(not (eq flycheck-display-errors-function
#'flycheck-pos-tip-error-messages)))
(setq flycheck-pos-tip-old-display-function
flycheck-display-errors-function
flycheck-display-errors-function
#'flycheck-pos-tip-error-messages))
;; Reset the display function, but only if the mode is still active.
((and (not flycheck-pos-tip-mode)
(eq flycheck-display-errors-function
#'flycheck-pos-tip-error-messages))
(setq flycheck-display-errors-function
flycheck-pos-tip-old-display-function
flycheck-pos-tip-old-display-function nil))))

(provide 'flycheck-pos-tip)

Expand Down