commit | author | age
|
5cb5f7
|
1 |
;;; flycheck-tip.el --- Show flycheck/flymake errors by tooltip -*- lexical-binding: t; -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2016 by Yuta Yamada |
|
4 |
|
|
5 |
;; Author: Yuta Yamada <cokesboy"at"gmail.com> |
|
6 |
;; URL: https://github.com/yuutayamada/flycheck-tip |
|
7 |
;; Version: 0.5.0 |
|
8 |
;; Package-Requires: ((flycheck "29") (emacs "24.1") (popup "0.5.0")) |
|
9 |
;; Keywords: flycheck |
|
10 |
|
|
11 |
;;; License: |
|
12 |
;; This program is free software: you can redistribute it and/or modify |
|
13 |
;; it under the terms of the GNU General Public License as published by |
|
14 |
;; the Free Software Foundation, either version 3 of the License, or |
|
15 |
;; (at your option) any later version. |
|
16 |
;; |
|
17 |
;; This program is distributed in the hope that it will be useful, |
|
18 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 |
;; GNU General Public License for more details. |
|
21 |
;; |
|
22 |
;; You should have received a copy of the GNU General Public License |
|
23 |
;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24 |
|
|
25 |
;;; Commentary: |
|
26 |
;; Usage: |
|
27 |
;; Basic setting |
|
28 |
;; |
|
29 |
;; (require 'flycheck-tip) |
|
30 |
;; (define-key your-prog-mode (kbd "C-c C-n") 'flycheck-tip-cycle) |
|
31 |
;; (setq flycheck-display-errors-function 'ignore) |
|
32 |
;; |
|
33 |
;; If you are still using flymake, you can use combined function that |
|
34 |
;; show error by popup in flymake-mode or flycheck-mode. |
|
35 |
;; |
|
36 |
;; (define-key global-map (kbd "C-0") 'error-tip-cycle-dwim) |
|
37 |
;; (define-key global-map (kbd "C-9") 'error-tip-cycle-dwim-reverse) |
|
38 |
;; |
|
39 |
;; If you build Emacs with D-Bus option, you may configure following setting. |
|
40 |
;; This keeps the errors on notification area. Please check |
|
41 |
;; ‘error-tip-notify-timeout’ to change limit of the timeout as well. |
|
42 |
;; |
|
43 |
;; (setq error-tip-notify-keep-messages t) |
|
44 |
;;; Code: |
|
45 |
|
|
46 |
(require 'cl-lib) |
|
47 |
(require 'flycheck) |
|
48 |
(require 'error-tip) |
|
49 |
|
|
50 |
(defvaralias 'flycheck-tip-timer-delay 'error-tip-timer-delay |
|
51 |
"Alias of `error-tip-timer-delay'.") |
|
52 |
|
|
53 |
;; memo flycheck-current-errors |
|
54 |
;; 0 : err name? |
|
55 |
;; 1 : buffer |
|
56 |
;; 2 : lang |
|
57 |
;; 3 : file |
|
58 |
;; 4 : line |
|
59 |
;; 5 : line? |
|
60 |
;; 6 : message |
|
61 |
;; 7 : err type? |
|
62 |
|
|
63 |
;;;###autoload |
|
64 |
(defun flycheck-tip-cycle (&optional reverse) |
|
65 |
"Move to next error if it's exists. |
|
66 |
If it wasn't exists then move to previous error. |
|
67 |
Move to previous error if REVERSE is non-nil." |
|
68 |
(interactive) |
|
69 |
(error-tip-cycle |
|
70 |
(error-tip-collect-current-file-errors flycheck-current-errors) reverse)) |
|
71 |
|
|
72 |
;;;###autoload |
|
73 |
(defun flycheck-tip-cycle-reverse () |
|
74 |
"Do `flycheck-tip-cycle by reverse order." |
|
75 |
(interactive) |
|
76 |
(flycheck-tip-cycle t)) |
|
77 |
|
|
78 |
(defun flycheck-tip-display-current-line-error-message (errors) |
|
79 |
"Show current line's ERRORS by popup. |
|
80 |
This function is used to replace ‘flycheck-display-errors-function’." |
|
81 |
(error-tip-delete-popup) |
|
82 |
(let ((current-line-errors (mapcar #'flycheck-error-message errors)) |
|
83 |
;; prevents frequently notification update |
|
84 |
(error-tip-notify-keep-messages nil)) |
|
85 |
(when current-line-errors |
|
86 |
(setq error-tip-current-errors current-line-errors) |
|
87 |
(error-tip-popup-error-message current-line-errors (point))))) |
|
88 |
|
|
89 |
;;;###autoload |
|
90 |
(defun flycheck-tip--get (element err) |
|
91 |
(cl-case element |
|
92 |
(file (flycheck-error-filename err)) |
|
93 |
(line (flycheck-error-line err)) |
|
94 |
(message (flycheck-error-message err)))) |
|
95 |
|
|
96 |
;;;;;;;;;;;;; |
|
97 |
;; Obsolete |
|
98 |
;; FIXME: what is the proper way to obsolete? |
|
99 |
|
|
100 |
(defcustom flycheck-tip-avoid-show-func t |
|
101 |
"Avoid `flycheck-show-error-at-point' function's behavior. |
|
102 |
This variable is true by default." |
|
103 |
:group 'flycheck-tip |
|
104 |
:type 'boolean) |
|
105 |
|
|
106 |
(make-obsolete-variable |
|
107 |
'flycheck-tip-avoid-show-func nil |
|
108 |
"2017/9/30: Please set ‘flycheck-display-errors-function’ to ‘ignore’ if |
|
109 |
you want to avoid echoing error message instead of this |
|
110 |
value. This variable will be deleted on the future release.") |
|
111 |
|
|
112 |
(defun flycheck-tip-use-timer (order) |
|
113 |
"You can set 'normal, 'verbose or nil to ORDER. |
|
114 |
The normal means, use error popup and using timer or not is configurable. |
|
115 |
The verbose means, use error popup and popup current-line error if it's exists |
|
116 |
after `error-tip-timer-delay' seconds. |
|
117 |
If you set nil, show popup error immediately after you invoke flycheck-tip-cycle |
|
118 |
or flycheck-tip-cycle-reverse." |
|
119 |
(cl-case order |
|
120 |
(normal |
|
121 |
(setq flycheck-display-errors-function 'ignore)) |
|
122 |
(verbose |
|
123 |
(setq flycheck-idle-change-delay error-tip-timer-delay |
|
124 |
flycheck-display-errors-function |
|
125 |
'flycheck-tip-display-current-line-error-message)) |
|
126 |
;; do not use timer |
|
127 |
(t (setq flycheck-display-errors-function 'ignore) |
|
128 |
(setq error-tip-timer-delay nil)))) |
|
129 |
|
|
130 |
(define-obsolete-function-alias 'flycheck-tip-use-timer nil |
|
131 |
"2017/9/30: This function become obsolete in favor of official flycheck-pos-tip package. |
|
132 |
Please use that instead if you want just to show error messages at point by popup.") |
|
133 |
|
|
134 |
(provide 'flycheck-tip) |
|
135 |
|
|
136 |
;; Local Variables: |
|
137 |
;; coding: utf-8 |
|
138 |
;; mode: emacs-lisp |
|
139 |
;; End: |
|
140 |
|
|
141 |
;;; flycheck-tip.el ends here |