mirror of https://github.com/Chizi123/.emacs.d.git

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