-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflymake-extension.el
263 lines (219 loc) · 8.5 KB
/
flymake-extension.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
;;; flymake-extension.el --- Some extension for flymake
;; Author: Andy Stewart [email protected]
;; Maintainer: Andy Stewart [email protected]
;; Copyright (C) 2008, 2009, Andy Stewart, all rights reserved.
;; Created: 2008-10-11 23:05:38
;; Version: 0.3
;; Last-Updated: 2009-02-04 19:31:35
;; URL:
;; Keywords: flymake
;; Compatibility: GNU Emacs 23.0.60.1
;; This file is not part of GNU Emacs
;;; 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, 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; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;; Features that might be required by this library:
;;
;; `flymake' `fringe-helper'
;;
;;; Commentary:
;;
;; Some extensions for `flymake'
;;
;;; Installation:
;;
;; Put flymake-extension.el to your load-path.
;; The load-path is usually ~/elisp/.
;; It's set in your ~/.emacs like this:
;; (add-to-list 'load-path (expand-file-name "~/elisp"))
;;
;; And the following to your ~/.emacs startup file.
;;
;; (require 'flymake-extension)
;;
;; No need more
;;; Customize:
;;
;; You can setup option `flymake-extension-use-showtip' with `t',
;; if you want to show error or warning use `showtip',
;; And `showtip' just can use in X window system.
;;
;; You can setup option `flymake-extension-auto-show' with `t',
;; if you want to show error or waring automatically.
;;
;; And all above options can customize by:
;; M-x customize-group RET flymake-extension RET
;;
;;; Change log:
;;
;; 2009/02/04
;; Add new option `flymake-extension-use-showtip'.
;; Add new option `flymake-extension-auto-show'.
;;
;; 2008/10/11
;; First released.
;;
;;; Acknowledgements:
;;
;;
;;
;;; TODO
;;
;;
;;
;;; Require
(require 'flymake)
(require 'fringe-helper)
;;; Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgroup flymake-extension nil
"Some extension functions for flymake."
:group 'flymake)
(defcustom flymake-extension-use-showtip nil
"Display error or warning in showtip.
If nil flymake display error or warning in minibuffer.
Otherwise use `showtip' display.
If you use X window, you can try to enable this option.
Default is nil."
:type 'boolean
:group 'flymake-extension)
(defcustom flymake-extension-auto-show nil
"Whether show error or warning automatically.
Default is nil."
:type 'boolean
:set (lambda (symbol value)
(set symbol value)
(if value
(add-hook 'post-command-hook 'flymake-extension-show+)
(remove-hook 'post-command-hook 'flymake-extension-show+)))
:group 'flymake-extension)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar multiline-flymake-mode nil)
(defvar flymake-split-output-multiline nil)
(defvar flymake-fringe-overlays nil)
(make-variable-buffer-local 'flymake-fringe-overlays)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Show error ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun flymake-show-next-error (&optional reversed)
"Show next error of flymake."
(interactive)
(if reversed
(flymake-goto-prev-error)
(flymake-goto-next-error))
(flymake-extension-show))
(defun flymake-show-prev-error()
"Show previous error of flymake."
(interactive)
(flymake-show-next-error t))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun flymake-report-fatal-status (status warning)
"Display a warning and switch flymake mode off."
(flymake-extension-show (format "Flymake: %s. Flymake will be switched OFF" warning))
(flymake-mode -1))
(defun flymake-extension-show (&optional msg no-echo)
"Show error or warning.
If option `flymake-extension-use-showtip' is t, use `showtip' display.
If MSG nil, try to get current error or warning.
If NO-ECHO t, don't display message when no error or waring."
;; Just check when `flymake-mode' is enable.
(when flymake-mode
(or msg (setq msg (get-char-property (point) 'help-echo)))
(if msg
(progn
;; Remove blank lines form information.
(setq msg (replace-regexp-in-string "^[ \t]*\n" "" msg))
;; Show information.
(if flymake-extension-use-showtip
(progn
(require 'showtip)
(showtip msg))
(message msg)))
(unless no-echo
(message "No error or waring.")))))
(defun flymake-extension-show+ ()
"This function is similar with `flymake-extension-show'.
Always try to get error or waring around point.
Except don't display message when no error or waring."
(flymake-extension-show nil t))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Rules for `flymake' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Haskell mode.
(defun flymake-Haskell-init ()
(flymake-simple-make-init-impl
'flymake-create-temp-with-folder-structure nil nil
(file-name-nondirectory buffer-file-name)
'flymake-get-Haskell-cmdline))
(defun flymake-get-Haskell-cmdline (source base-dir)
(list "ghc"
(list "--make" "-fbyte-code"
(concat "-i" base-dir) ;; can be expanded for additional -i options as in the Perl script
source)))
(defadvice flymake-split-output
;; this needs to be advised as flymake-split-string is used in other places
;; and I don't know of a better way to get at the caller's details
(around flymake-split-output-multiline activate protect)
(if multiline-flymake-mode
(let ((flymake-split-output-multiline t))
ad-do-it)
ad-do-it))
(defadvice flymake-split-string
(before flymake-split-string-multiline activate)
(when flymake-split-output-multiline
(ad-set-arg 1 "^\\s *$")))
(add-hook
'haskell-mode-hook
'(lambda ()
;; use add-to-list rather than push to avoid growing the list for every Haskell file loaded
(add-to-list 'flymake-allowed-file-name-masks
'("\\.l?hs$" flymake-Haskell-init flymake-simple-java-cleanup))
(add-to-list 'flymake-err-line-patterns
'("^\\(.+\\.l?hs\\):\\([0-9]+\\):\\([0-9]+\\):\\(\\(?:.\\|\\W\\)+\\)"
1 2 3 4))
(set (make-local-variable 'multiline-flymake-mode) t)))
;; C mode.
(defun flymake-c-init ()
(flymake-simple-make-init-impl 'flymake-create-temp-inplace t t (file-name-nondirectory buffer-file-name) 'flymake-get-c-cmdline))
(defun flymake-get-c-cmdline (source base-dir)
(list "gcc" (list "-Wall" (concat base-dir source))))
(push '(".+\\.c$" flymake-c-init) flymake-allowed-file-name-masks)
(push '(".+\\.h$" flymake-c-init) flymake-allowed-file-name-masks)
;; C++ mode.
(defun flymake-c++-init ()
(flymake-simple-make-init-impl 'flymake-create-temp-inplace t t (file-name-nondirectory buffer-file-name) 'flymake-get-c++-cmdline))
(defun flymake-get-c++-cmdline (source base-dir)
(list "g++" (list "-Wall" (concat base-dir source))))
(push '(".+\\.cpp$" flymake-c++-init) flymake-allowed-file-name-masks)
;; Java mode.
(defun flymake-java-init ()
(flymake-simple-make-init-impl 'flymake-create-temp-inplace t t (file-name-nondirectory buffer-file-name) 'flymake-get-java-cmdline))
(defun flymake-get-java-cmdline (source base-dir)
(list "javac" (list "-g" (concat base-dir source))))
(push '(".+\\.java$" flymake-java-init) flymake-allowed-file-name-masks)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Fringe for `flymake' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defadvice flymake-make-overlay (after add-to-fringe first
(beg end tooltip-text face mouse-face)
activate compile)
(push (fringe-helper-insert-region
beg end
(fringe-lib-load fringe-lib-exclamation-mark)
'left-fringe
(if (eq face 'flymake-errline)
'font-lock-warning-face
'font-lock-function-name-face))
flymake-fringe-overlays))
(defadvice flymake-delete-own-overlays (after remove-from-fringe activate compile)
(mapc 'fringe-helper-remove flymake-fringe-overlays)
(setq flymake-fringe-overlays nil))
(provide 'flymake-extension)
;;; flymake-extension.el ends here
;;; LocalWords: flymake haskell impl inplace cmdline perl hg errline showtip
;;; LocalWords: multiline ghc fbyte hs msg