Skip to content

Commit

Permalink
Use echo area in nongraphical sessions
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
cpitclaudel committed Dec 14, 2015
1 parent 6209525 commit d210f0e
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions flycheck-pos-tip.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"A function to show messages in a popup.
The function shall take a single argument, a list of messages as
strings, and shall show theses messages in a graphical popup."
strings, and shall show theses messages in a graphical popup.
For TTY environments, see `flycheck-pos-tip-tty-show-function'."
:group 'flycheck-pos-tip
:type 'function)

Expand All @@ -65,6 +66,26 @@ The function should be a no-op in this case."
:type 'function
:package-version '(flycheck-pos-tip . "0.2"))

(defcustom flycheck-pos-tip-tty-show-function
#'flycheck-pos-tip-tty-show
"A function to show messages in TTY mode.
This function is call instead of `flycheck-pos-tip-show-function'
when no graphical environment is available."
:group 'flycheck-pos-tip
:type 'function
:package-version '(flycheck-pos-tip . "0.3"))

(defcustom flycheck-pos-tip-tty-hide-function
#'identity
"A function to hide messages in TTY mode.
This function is call instead of `flycheck-pos-tip-hide-function'
when no graphical environment is available."
:group 'flycheck-pos-tip
:type 'function
:package-version '(flycheck-pos-tip . "0.3"))

(defcustom flycheck-pos-tip-timeout 5
"Time in seconds to hide the tooltip after."
:group 'flycheck-pos-tip
Expand All @@ -82,16 +103,34 @@ Uses `pos-tip-show' under the hood."
"Hide the Flycheck tooltip."
(pos-tip-hide))

(defvar flycheck-pos-tip-tty-old-message nil
"The contents of the message buffer before showing errors.")

(defun flycheck-pos-tip-tty-show (messages)
"Show MESSAGES in the echo area."
(setq flycheck-pos-tip-tty-old-message (current-message))
(message "%s" (mapconcat #'identity messages "\n\n")))

(defun flycheck-pos-tip-tty-hide ()
"Restore old message in echo area."
(when flycheck-pos-tip-tty-old-message
(message flycheck-pos-tip-tty-old-message)))

;;;###autoload
(defun flycheck-pos-tip-error-messages (errors)
"Display ERRORS in a graphical tooltip."
"Display ERRORS in a graphical tooltip, if possible."
(when errors
(-when-let (messages (-keep #'flycheck-error-format-message-and-id errors))
(funcall flycheck-pos-tip-show-function messages))))
(funcall (if (display-graphic-p)
flycheck-pos-tip-show-function
flycheck-pos-tip-tty-show-function)
messages))))

(defun flycheck-pos-tip-hide-messages ()
"Hide messages currently being shown if any."
(funcall flycheck-pos-tip-hide-function))
(funcall (if (display-graphic-p)
flycheck-pos-tip-hide-function
flycheck-pos-tip-tty-hide-function)))

(defvar flycheck-pos-tip-old-display-function nil
"The former value of `flycheck-display-errors-function'.")
Expand All @@ -110,9 +149,9 @@ omitted, nil or positive. If ARG is `toggle', toggle
interactively.
In `flycheck-pos-tip-mode' show Flycheck's error messages in a
GUI tooltip. This does not work on TTY frames. You can provide
your own function to show and hide the popup via
`flycheck-pos-tip-show-function' and
GUI tooltip. Falls back to `flycheck-pos-tip-tty-show-function'
on TTY frames. You can provide your own functions to show and
hide the popup via `flycheck-pos-tip-show-function' and
`flycheck-pos-tip-hide-function' respectively. For instance you
may use the popular popup.el library (see URL
`https://github.com/auto-complete/popup-el')."
Expand Down

0 comments on commit d210f0e

Please sign in to comment.