-
Notifications
You must be signed in to change notification settings - Fork 4
/
helm-flymake.el
152 lines (130 loc) · 4.42 KB
/
helm-flymake.el
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
142
143
144
145
146
147
148
149
150
151
152
;;; helm-flymake.el --- helm sources for flymake -*- lexical-binding: t -*-
;; Copyright (C) 2012-2013 Akira Tamamori
;; Copyright (C) 2024 zbelial <[email protected]>
;; Author: Akira Tamamori <[email protected]>
;; Maintainer: zbelial <[email protected]>
;; URL: https://github.com/emacs-helm/helm-flymake
;; Version: 0.1.9
;; Package-Requires: ((helm "1.0"))
;; 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 2 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:
;;
;; `helm' interface for flymake.
;; When `flymake-mode' is t, M-x `helm-flymake' lists warning and error
;; messages in *helm flymake* buffer.
;; When Enter/<return> is pressed the "default" action is executed
;; moving point to the line of the selected diagnostic and closing
;; the `helm-flymake' mini-buffer.
;;; Installation:
;;
;; Add this file in your `load-path' and the following to your Emacs init file:
;;
;; Note: Not necessary if using ELPA package.
;; (autoload 'helm-flymake "helm-flymake" nil t)
;;; History:
;;
;; Revision 0.1.9
;; * Rewrite most of the code to make it work with latest flymake.
;;
;; Revision 0.1.8
;; * Added "goto line" feature
;; * Sorted warnings and errors by line number such that lowest line is first
;; * Fixed but that showed "nil" in the warning/errors window when there were
;; a different numbers of warnings compared to errors (and vise-versa).
;;
;; Revision 0.1.7
;; * convert prefix of helm-c-* into helm-*.
;;
;; Revision 0.1.6
;; * fix typo.
;;
;; Revision 0.1.5
;; * remove global variable `helm-c-flymake-err-list'.
;;
;; Revision 0.1.4
;; * revise documents.
;;
;; Revision 0.1.3
;; * add default input, line number at current point when `helm-flymake'
;; is invoked with prefix argument.
;;
;; Revision 0.1.2
;; * add magic comment `autoload' to `helm-flymake'.
;;
;; Revision 0.1.1
;; * add variable `helm-c-flymake-buffer'.
;;
;; Revision 0.1
;; * Initial revision
;;; Code:
(require 'flymake)
(require 'helm)
(defgroup helm-flymake nil
"Helm for flymake."
:group 'helm)
(defcustom helm-flymake-actions
'(("Goto flymake diagnostic" . helm-flymake-action-goto))
"Actions for helm-flymake."
:type '(alist :key-type string :value-type function))
(defun helm-flymake-action-goto (x)
"Goto where there is any diagnostic."
(goto-char (flymake-diagnostic-beg x))
(recenter))
(defvar helm-flymake-source-name "Helm Flymake"
"Source name of helm flymake.")
(defun helm-flymake--format-type (type)
(let (face
display-type
(type (symbol-name type)))
(cond
((string-suffix-p "note" type)
(setq display-type "note")
(setq face 'success))
((string-suffix-p "warning" type)
(setq display-type "warning")
(setq face 'warning))
((string-suffix-p "error" type)
(setq display-type "error")
(setq face 'error))
(t
(setq display-type "note")
(setq face 'warning)))
(propertize (format "%s" display-type) 'face face)))
(defun helm-flymake--transforme-to-candidate (diag)
(let* (msg
(beg (flymake-diagnostic-beg diag))
(type (flymake-diagnostic-type diag))
(text (flymake-diagnostic-text diag))
(line (line-number-at-pos beg)))
(setq msg (format "%-8d %-12s %s"
line (helm-flymake--format-type type) text))
(cons msg diag)))
;;;###autoload
(defun helm-flymake ()
"Helm interface for flymake."
(interactive)
(helm :sources (helm-build-sync-source helm-flymake-source-name
:candidates (mapcar #'helm-flymake--transforme-to-candidate
(flymake-diagnostics))
:multiline t
:action
'helm-flymake-actions)
:quit-if-no-candidate
(lambda ()
(message "No flymake diagnostics in this buffer"))
:buffer "*helm flymake*"))
(provide 'helm-flymake)
;; Local Variables:
;; coding: utf-8
;; indent-tabs-mode: nil
;; End:
;;; helm-flymake.el ends here