Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca
[bpt/emacs.git] / lisp / progmodes / flymake.el
CommitLineData
4bcbcb9d
EZ
1;;; flymake.el -- a universal on-the-fly syntax checker
2
ab422c4d 3;; Copyright (C) 2003-2013 Free Software Foundation, Inc.
4bcbcb9d 4
1d9a4930
EZ
5;; Author: Pavel Kobyakov <pk_at_work@yahoo.com>
6;; Maintainer: Pavel Kobyakov <pk_at_work@yahoo.com>
4bcbcb9d
EZ
7;; Version: 0.3
8;; Keywords: c languages tools
9
10;; This file is part of GNU Emacs.
11
b1fc2b50 12;; GNU Emacs is free software: you can redistribute it and/or modify
4bcbcb9d 13;; it under the terms of the GNU General Public License as published by
b1fc2b50
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
4bcbcb9d
EZ
16
17;; GNU Emacs 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
b1fc2b50 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
4bcbcb9d
EZ
24
25;;; Commentary:
26;;
27;; Flymake is a minor Emacs mode performing on-the-fly syntax
28;; checks using the external syntax check tool (for C/C++ this
29;; is usually the compiler)
30
9f812d23
SM
31;;; Bugs/todo:
32
33;; - Only uses "Makefile", not "makefile" or "GNUmakefile"
34;; (from http://bugs.debian.org/337339).
35
4bcbcb9d
EZ
36;;; Code:
37
a464a6c7 38(eval-when-compile (require 'cl-lib))
6fee12e6
SM
39(if (featurep 'xemacs) (require 'overlay))
40
43ed65ac
SM
41(defvar flymake-is-running nil
42 "If t, flymake syntax check process is running for the current buffer.")
43(make-variable-buffer-local 'flymake-is-running)
c92d6023 44
43ed65ac
SM
45(defvar flymake-timer nil
46 "Timer for starting syntax check.")
47(make-variable-buffer-local 'flymake-timer)
c92d6023 48
43ed65ac
SM
49(defvar flymake-last-change-time nil
50 "Time of last buffer change.")
51(make-variable-buffer-local 'flymake-last-change-time)
52
53(defvar flymake-check-start-time nil
54 "Time at which syntax check was started.")
55(make-variable-buffer-local 'flymake-check-start-time)
56
57(defvar flymake-check-was-interrupted nil
58 "Non-nil if syntax check was killed by `flymake-compile'.")
59(make-variable-buffer-local 'flymake-check-was-interrupted)
60
61(defvar flymake-err-info nil
62 "Sorted list of line numbers and lists of err info in the form (file, err-text).")
63(make-variable-buffer-local 'flymake-err-info)
64
65(defvar flymake-new-err-info nil
66 "Same as `flymake-err-info', effective when a syntax check is in progress.")
67(make-variable-buffer-local 'flymake-new-err-info)
c92d6023 68
4bcbcb9d 69;;;; [[ cross-emacs compatibility routines
ce721de4
KS
70(defsubst flymake-makehash (&optional test)
71 (if (fboundp 'make-hash-table)
72 (if test (make-hash-table :test test) (make-hash-table))
adf8a02e
RS
73 (with-no-warnings
74 (makehash test))))
5323b4b0 75
cd2325cd
SM
76(defalias 'flymake-float-time
77 (if (fboundp 'float-time)
78 'float-time
7ea8834e
RS
79 (if (featurep 'xemacs)
80 (lambda ()
b3f5a846 81 (multiple-value-bind (s0 s1 s2) (values-list (current-time))
7ea8834e 82 (+ (* (float (ash 1 16)) s0) (float s1) (* 0.0000001 s2)))))))
ce721de4 83
43ed65ac
SM
84(defalias 'flymake-replace-regexp-in-string
85 (if (eval-when-compile (fboundp 'replace-regexp-in-string))
86 'replace-regexp-in-string
87 (lambda (regexp rep str)
88 (replace-in-string str regexp rep))))
89
90(defalias 'flymake-split-string
91 (if (condition-case nil (equal (split-string " bc " " " t) '("bc"))
92 (error nil))
93 (lambda (str pattern) (split-string str pattern t))
94 (lambda (str pattern)
95 "Split STR into a list of substrings bounded by PATTERN.
53ec26ed 96Zero-length substrings at the beginning and end of the list are omitted."
43ed65ac 97 (let ((split (split-string str pattern)))
587d108e
SM
98 (while (equal (car split) "") (setq split (cdr split)))
99 (setq split (nreverse split))
100 (while (equal (car split) "") (setq split (cdr split)))
101 (nreverse split)))))
43ed65ac
SM
102
103(defalias 'flymake-get-temp-dir
cd2325cd 104 (if (fboundp 'temp-directory)
43ed65ac
SM
105 'temp-directory
106 (lambda () temporary-file-directory)))
4bcbcb9d 107
1d9a4930
EZ
108(defun flymake-posn-at-point-as-event (&optional position window dx dy)
109 "Return pixel position of top left corner of glyph at POSITION,
110relative to top left corner of WINDOW, as a mouse-1 click
111event (identical to the event that would be triggered by clicking
112mouse button 1 at the top left corner of the glyph).
113
114POSITION and WINDOW default to the position of point in the
115selected window.
116
117DX and DY specify optional offsets from the top left of the glyph."
118 (unless window (setq window (selected-window)))
119 (unless position (setq position (window-point window)))
120 (unless dx (setq dx 0))
121 (unless dy (setq dy 0))
122
123 (let* ((pos (posn-at-point position window))
124 (x-y (posn-x-y pos))
125 (edges (window-inside-pixel-edges window))
126 (win-x-y (window-pixel-edges window)))
127 ;; adjust for window edges
128 (setcar (nthcdr 2 pos)
129 (cons (+ (car x-y) (car edges) (- (car win-x-y)) dx)
130 (+ (cdr x-y) (cadr edges) (- (cadr win-x-y)) dy)))
131 (list 'mouse-1 pos)))
43ed65ac
SM
132
133(defun flymake-popup-menu (menu-data)
134 "Pop up the flymake menu at point, using the data MENU-DATA.
53ec26ed
RS
135POS is a list of the form ((X Y) WINDOW), where X and Y are
136pixels positions from the top left corner of WINDOW's frame.
137MENU-DATA is a list of error and warning messages returned by
138`flymake-make-err-menu-data'."
139 (if (featurep 'xemacs)
43ed65ac
SM
140 (let* ((pos (flymake-get-point-pixel-pos))
141 (x-pos (nth 0 pos))
142 (y-pos (nth 1 pos))
ce721de4
KS
143 (fake-event-props '(button 1 x 1 y 1)))
144 (setq fake-event-props (plist-put fake-event-props 'x x-pos))
145 (setq fake-event-props (plist-put fake-event-props 'y y-pos))
43ed65ac
SM
146 (popup-menu (flymake-make-xemacs-menu menu-data)
147 (make-event 'button-press fake-event-props)))
148 (x-popup-menu (if (eval-when-compile (fboundp 'posn-at-point))
1d9a4930 149 (flymake-posn-at-point-as-event)
43ed65ac
SM
150 (list (flymake-get-point-pixel-pos) (selected-window)))
151 (flymake-make-emacs-menu menu-data))))
4bcbcb9d 152
5323b4b0 153(defun flymake-make-emacs-menu (menu-data)
53ec26ed
RS
154 "Return a menu specifier using MENU-DATA.
155MENU-DATA is a list of error and warning messages returned by
156`flymake-make-err-menu-data'.
157See `x-popup-menu' for the menu specifier format."
5323b4b0
RS
158 (let* ((menu-title (nth 0 menu-data))
159 (menu-items (nth 1 menu-data))
43ed65ac
SM
160 (menu-commands (mapcar (lambda (foo)
161 (cons (nth 0 foo) (nth 1 foo)))
162 menu-items)))
5323b4b0 163 (list menu-title (cons "" menu-commands))))
4bcbcb9d 164
ce721de4
KS
165(if (featurep 'xemacs) (progn
166
cd2325cd
SM
167(defun flymake-nop ())
168
2aa13ec4 169(defun flymake-make-xemacs-menu (menu-data)
53ec26ed 170 "Return a menu specifier using MENU-DATA."
5323b4b0
RS
171 (let* ((menu-title (nth 0 menu-data))
172 (menu-items (nth 1 menu-data))
173 (menu-commands nil))
174 (setq menu-commands (mapcar (lambda (foo)
175 (vector (nth 0 foo) (or (nth 1 foo) '(flymake-nop)) t))
176 menu-items))
177 (cons menu-title menu-commands)))
178
ce721de4
KS
179)) ;; xemacs
180
43ed65ac
SM
181(unless (eval-when-compile (fboundp 'posn-at-point))
182
5323b4b0
RS
183(defun flymake-current-row ()
184 "Return current row number in current frame."
cd2325cd
SM
185 (if (fboundp 'window-edges)
186 (+ (car (cdr (window-edges))) (count-lines (window-start) (point)))
187 (count-lines (window-start) (point))))
5323b4b0
RS
188
189(defun flymake-selected-frame ()
cd2325cd
SM
190 (if (fboundp 'window-edges)
191 (selected-frame)
192 (selected-window)))
4bcbcb9d 193
43ed65ac
SM
194(defun flymake-get-point-pixel-pos ()
195 "Return point position in pixels: (x, y)."
196 (let ((mouse-pos (mouse-position))
197 (pixel-pos nil)
198 (ret nil))
199 (if (car (cdr mouse-pos))
200 (progn
201 (set-mouse-position (flymake-selected-frame) (current-column) (flymake-current-row))
202 (setq pixel-pos (mouse-pixel-position))
203 (set-mouse-position (car mouse-pos) (car (cdr mouse-pos)) (cdr (cdr mouse-pos)))
204 (setq ret (list (car (cdr pixel-pos)) (cdr (cdr pixel-pos)))))
205 (progn
206 (setq ret '(0 0))))
207 (flymake-log 3 "mouse pos is %s" ret)
208 ret))
209
210) ;; End of (unless (fboundp 'posn-at-point)
211
4bcbcb9d
EZ
212;;;; ]]
213
214(defcustom flymake-log-level -1
cd2325cd 215 "Logging level, only messages with level lower or equal will be logged.
4bcbcb9d 216-1 = NONE, 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG"
5323b4b0
RS
217 :group 'flymake
218 :type 'integer)
4bcbcb9d 219
2aa13ec4 220(defun flymake-log (level text &rest args)
53ec26ed
RS
221 "Log a message at level LEVEL.
222If LEVEL is higher than `flymake-log-level', the message is
223ignored. Otherwise, it is printed using `message'.
224TEXT is a format control string, and the remaining arguments ARGS
225are the string substitutions (see `format')."
5323b4b0
RS
226 (if (<= level flymake-log-level)
227 (let* ((msg (apply 'format text args)))
29a4e67d 228 (message "%s" msg)
5323b4b0
RS
229 ;;(with-temp-buffer
230 ;; (insert msg)
231 ;; (insert "\n")
6df19241 232 ;; (flymake-save-buffer-in-file "d:/flymake.log" t) ; make log file name customizable
5323b4b0 233 ;;)
2aa13ec4 234 )))
4bcbcb9d 235
2aa13ec4 236(defun flymake-ins-after (list pos val)
5323b4b0
RS
237 "Insert VAL into LIST after position POS."
238 (let ((tmp (copy-sequence list))) ; (???)
239 (setcdr (nthcdr pos tmp) (cons val (nthcdr (1+ pos) tmp)))
240 tmp))
4bcbcb9d 241
2aa13ec4 242(defun flymake-set-at (list pos val)
9a686ad2 243 "Set VAL at position POS in LIST."
5323b4b0
RS
244 (let ((tmp (copy-sequence list))) ; (???)
245 (setcar (nthcdr pos tmp) val)
246 tmp))
4bcbcb9d 247
43ed65ac
SM
248(defvar flymake-processes nil
249 "List of currently active flymake processes.")
4bcbcb9d 250
9a686ad2 251(defvar flymake-output-residual nil)
2aa13ec4 252
4bcbcb9d 253(make-variable-buffer-local 'flymake-output-residual)
2aa13ec4 254
57a97b44 255(defgroup flymake nil
cf20dee0 256 "Universal on-the-fly syntax checker."
57a97b44
MR
257 :version "23.1"
258 :group 'tools)
259
5323b4b0 260(defcustom flymake-allowed-file-name-masks
fd09a83f 261 '(("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'" flymake-simple-make-init)
c07fa030
SM
262 ("\\.xml\\'" flymake-xml-init)
263 ("\\.html?\\'" flymake-xml-init)
264 ("\\.cs\\'" flymake-simple-make-init)
eabd11d4
MH
265 ("\\.p[ml]\\'" flymake-perl-init)
266 ("\\.php[345]?\\'" flymake-php-init)
6df19241
SM
267 ("\\.h\\'" flymake-master-make-header-init flymake-master-cleanup)
268 ("\\.java\\'" flymake-simple-make-java-init flymake-simple-java-cleanup)
269 ("[0-9]+\\.tex\\'" flymake-master-tex-init flymake-master-cleanup)
c07fa030
SM
270 ("\\.tex\\'" flymake-simple-tex-init)
271 ("\\.idl\\'" flymake-simple-make-init)
6df19241
SM
272 ;; ("\\.cpp\\'" 1)
273 ;; ("\\.java\\'" 3)
274 ;; ("\\.h\\'" 2 ("\\.cpp\\'" "\\.c\\'")
9a686ad2 275 ;; ("[ \t]*#[ \t]*include[ \t]*\"\\([\w0-9/\\_\.]*[/\\]*\\)\\(%s\\)\"" 1 2))
6df19241
SM
276 ;; ("\\.idl\\'" 1)
277 ;; ("\\.odl\\'" 1)
278 ;; ("[0-9]+\\.tex\\'" 2 ("\\.tex\\'")
9a686ad2 279 ;; ("[ \t]*\\input[ \t]*{\\(.*\\)\\(%s\\)}" 1 2 ))
6df19241 280 ;; ("\\.tex\\'" 1)
5323b4b0 281 )
fd09a83f 282 "Files syntax checking is allowed for."
5323b4b0
RS
283 :group 'flymake
284 :type '(repeat (string symbol symbol symbol)))
4bcbcb9d 285
2aa13ec4 286(defun flymake-get-file-name-mode-and-masks (file-name)
9a686ad2 287 "Return the corresponding entry from `flymake-allowed-file-name-masks'."
5323b4b0
RS
288 (unless (stringp file-name)
289 (error "Invalid file-name"))
17404091 290 (let ((fnm flymake-allowed-file-name-masks)
5323b4b0 291 (mode-and-masks nil))
17404091
SM
292 (while (and (not mode-and-masks) fnm)
293 (if (string-match (car (car fnm)) file-name)
294 (setq mode-and-masks (cdr (car fnm))))
295 (setq fnm (cdr fnm)))
5323b4b0
RS
296 (flymake-log 3 "file %s, init=%s" file-name (car mode-and-masks))
297 mode-and-masks))
4bcbcb9d 298
2aa13ec4 299(defun flymake-can-syntax-check-file (file-name)
5323b4b0 300 "Determine whether we can syntax check FILE-NAME.
2aa13ec4 301Return nil if we cannot, non-nil if we can."
5323b4b0 302 (if (flymake-get-init-function file-name) t nil))
4bcbcb9d 303
2aa13ec4 304(defun flymake-get-init-function (file-name)
5323b4b0
RS
305 "Return init function to be used for the file."
306 (let* ((init-f (nth 0 (flymake-get-file-name-mode-and-masks file-name))))
9a686ad2
SM
307 ;;(flymake-log 0 "calling %s" init-f)
308 ;;(funcall init-f (current-buffer))
5323b4b0 309 init-f))
4bcbcb9d 310
2aa13ec4 311(defun flymake-get-cleanup-function (file-name)
5323b4b0 312 "Return cleanup function to be used for the file."
c07fa030
SM
313 (or (nth 1 (flymake-get-file-name-mode-and-masks file-name))
314 'flymake-simple-cleanup))
4bcbcb9d 315
2aa13ec4 316(defun flymake-get-real-file-name-function (file-name)
6df19241
SM
317 (or (nth 2 (flymake-get-file-name-mode-and-masks file-name))
318 'flymake-get-real-file-name))
4bcbcb9d 319
4bcbcb9d 320(defvar flymake-find-buildfile-cache (flymake-makehash 'equal))
4bcbcb9d 321
2aa13ec4 322(defun flymake-get-buildfile-from-cache (dir-name)
5323b4b0 323 (gethash dir-name flymake-find-buildfile-cache))
2aa13ec4
RS
324
325(defun flymake-add-buildfile-to-cache (dir-name buildfile)
5323b4b0 326 (puthash dir-name buildfile flymake-find-buildfile-cache))
2aa13ec4
RS
327
328(defun flymake-clear-buildfile-cache ()
5323b4b0 329 (clrhash flymake-find-buildfile-cache))
2aa13ec4 330
5f73367d 331(defun flymake-find-buildfile (buildfile-name source-dir-name)
5323b4b0 332 "Find buildfile starting from current directory.
2aa13ec4 333Buildfile includes Makefile, build.xml etc.
5323b4b0 334Return its file name if found, or nil if not found."
5f73367d 335 (or (flymake-get-buildfile-from-cache source-dir-name)
8cd56959 336 (let* ((file (locate-dominating-file source-dir-name buildfile-name)))
8ebbfc80 337 (if file
5f73367d 338 (progn
8ebbfc80 339 (flymake-log 3 "found buildfile at %s" file)
8ebbfc80
SM
340 (flymake-add-buildfile-to-cache source-dir-name file)
341 file)
5f73367d
SM
342 (progn
343 (flymake-log 3 "buildfile for %s not found" source-dir-name)
344 nil)))))
5323b4b0
RS
345
346(defun flymake-fix-file-name (name)
57d3a1f3 347 "Replace all occurrences of '\' with '/'."
5323b4b0 348 (when name
587d108e
SM
349 (setq name (expand-file-name name))
350 (setq name (abbreviate-file-name name))
351 (setq name (directory-file-name name))
352 name))
4bcbcb9d 353
2aa13ec4 354(defun flymake-same-files (file-name-one file-name-two)
5323b4b0 355 "Check if FILE-NAME-ONE and FILE-NAME-TWO point to same file.
2aa13ec4 356Return t if so, nil if not."
5323b4b0
RS
357 (equal (flymake-fix-file-name file-name-one)
358 (flymake-fix-file-name file-name-two)))
359
4bcbcb9d 360(defcustom flymake-master-file-dirs '("." "./src" "./UnitTest")
9a686ad2 361 "Dirs where to look for master files."
5323b4b0
RS
362 :group 'flymake
363 :type '(repeat (string)))
4bcbcb9d
EZ
364
365(defcustom flymake-master-file-count-limit 32
5323b4b0
RS
366 "Max number of master files to check."
367 :group 'flymake
368 :type 'integer)
2aa13ec4 369
ce721de4
KS
370;; This is bound dynamically to pass a parameter to a sort predicate below
371(defvar flymake-included-file-name)
4bcbcb9d 372
2aa13ec4 373(defun flymake-find-possible-master-files (file-name master-file-dirs masks)
9a686ad2 374 "Find (by name and location) all possible master files.
fd09a83f 375Master files include .cpp and .c for .h. Files are searched for
2aa13ec4 376starting from the .h directory and max max-level parent dirs.
4bcbcb9d 377File contents are not checked."
17404091 378 (let* ((dirs master-file-dirs)
5323b4b0 379 (files nil)
17404091
SM
380 (done nil))
381
382 (while (and (not done) dirs)
587d108e 383 (let* ((dir (expand-file-name (car dirs) (file-name-directory file-name)))
17404091
SM
384 (masks masks))
385 (while (and (file-exists-p dir) (not done) masks)
386 (let* ((mask (car masks))
387 (dir-files (directory-files dir t mask)))
388
389 (flymake-log 3 "dir %s, %d file(s) for mask %s"
390 dir (length dir-files) mask)
391 (while (and (not done) dir-files)
392 (when (not (file-directory-p (car dir-files)))
393 (setq files (cons (car dir-files) files))
5323b4b0
RS
394 (when (>= (length files) flymake-master-file-count-limit)
395 (flymake-log 3 "master file count limit (%d) reached" flymake-master-file-count-limit)
396 (setq done t)))
17404091
SM
397 (setq dir-files (cdr dir-files))))
398 (setq masks (cdr masks))))
399 (setq dirs (cdr dirs)))
5323b4b0 400 (when files
ce721de4
KS
401 (let ((flymake-included-file-name (file-name-nondirectory file-name)))
402 (setq files (sort files 'flymake-master-file-compare))))
5323b4b0
RS
403 (flymake-log 3 "found %d possible master file(s)" (length files))
404 files))
4bcbcb9d 405
2aa13ec4 406(defun flymake-master-file-compare (file-one file-two)
173569aa 407 "Compare two files specified by FILE-ONE and FILE-TWO.
2aa13ec4 408This function is used in sort to move most possible file names
173569aa 409to the beginning of the list (File.h -> File.cpp moved to top)."
5323b4b0 410 (and (equal (file-name-sans-extension flymake-included-file-name)
d2c32364 411 (file-name-base file-one))
5323b4b0 412 (not (equal file-one file-two))))
4bcbcb9d
EZ
413
414(defcustom flymake-check-file-limit 8192
bd77c2ef
GM
415 "Maximum number of chars to look at when checking possible master file.
416Nil means search the entire file."
5323b4b0 417 :group 'flymake
bd77c2ef
GM
418 :type '(choice (const :tag "No limit" nil)
419 (integer :tag "Characters")))
4bcbcb9d 420
587d108e
SM
421(defun flymake-check-patch-master-file-buffer
422 (master-file-temp-buffer
423 master-file-name patched-master-file-name
424 source-file-name patched-source-file-name
425 include-dirs regexp)
5323b4b0 426 "Check if MASTER-FILE-NAME is a master file for SOURCE-FILE-NAME.
2aa13ec4
RS
427If yes, patch a copy of MASTER-FILE-NAME to include PATCHED-SOURCE-FILE-NAME
428instead of SOURCE-FILE-NAME.
fd09a83f
CY
429
430For example, foo.cpp is a master file if it includes foo.h.
431
2aa13ec4
RS
432Whether a buffer for MATER-FILE-NAME exists, use it as a source
433instead of reading master file from disk."
587d108e 434 (let* ((source-file-nondir (file-name-nondirectory source-file-name))
bd77c2ef
GM
435 (source-file-extension (file-name-extension source-file-nondir))
436 (source-file-nonext (file-name-sans-extension source-file-nondir))
587d108e 437 (found nil)
5323b4b0
RS
438 (inc-name nil)
439 (search-limit flymake-check-file-limit))
587d108e
SM
440 (setq regexp
441 (format regexp ; "[ \t]*#[ \t]*include[ \t]*\"\\(.*%s\\)\""
bd77c2ef
GM
442 ;; Hack for tex files, where \include often excludes .tex.
443 ;; Maybe this is safe generally.
444 (if (and (> (length source-file-extension) 1)
445 (string-equal source-file-extension "tex"))
446 (format "%s\\(?:\\.%s\\)?"
447 (regexp-quote source-file-nonext)
448 (regexp-quote source-file-extension))
449 (regexp-quote source-file-nondir))))
587d108e
SM
450 (unwind-protect
451 (with-current-buffer master-file-temp-buffer
bd77c2ef
GM
452 (if (or (not search-limit)
453 (> search-limit (point-max)))
454 (setq search-limit (point-max)))
587d108e
SM
455 (flymake-log 3 "checking %s against regexp %s"
456 master-file-name regexp)
457 (goto-char (point-min))
458 (while (and (< (point) search-limit)
459 (re-search-forward regexp search-limit t))
460 (let ((match-beg (match-beginning 1))
461 (match-end (match-end 1)))
462
463 (flymake-log 3 "found possible match for %s" source-file-nondir)
464 (setq inc-name (match-string 1))
bd77c2ef
GM
465 (and (> (length source-file-extension) 1)
466 (string-equal source-file-extension "tex")
467 (not (string-match (format "\\.%s\\'" source-file-extension)
468 inc-name))
469 (setq inc-name (concat inc-name "." source-file-extension)))
587d108e
SM
470 (when (eq t (compare-strings
471 source-file-nondir nil nil
472 inc-name (- (length inc-name)
473 (length source-file-nondir)) nil))
474 (flymake-log 3 "inc-name=%s" inc-name)
475 (when (flymake-check-include source-file-name inc-name
476 include-dirs)
477 (setq found t)
478 ;; replace-match is not used here as it fails in
479 ;; XEmacs with 'last match not a buffer' error as
480 ;; check-includes calls replace-in-string
481 (flymake-replace-region
482 match-beg match-end
483 (file-name-nondirectory patched-source-file-name))))
484 (forward-line 1)))
485 (when found
486 (flymake-save-buffer-in-file patched-master-file-name)))
487 ;;+(flymake-log 3 "killing buffer %s"
488 ;; (buffer-name master-file-temp-buffer))
489 (kill-buffer master-file-temp-buffer))
9a686ad2 490 ;;+(flymake-log 3 "check-patch master file %s: %s" master-file-name found)
5323b4b0
RS
491 (when found
492 (flymake-log 2 "found master file %s" master-file-name))
493 found))
4bcbcb9d 494
4bd0a5d0 495(defun flymake-replace-region (beg end rep)
5323b4b0
RS
496 "Replace text in BUFFER in region (BEG END) with REP."
497 (save-excursion
4bd0a5d0
SM
498 (goto-char end)
499 ;; Insert before deleting, so as to better preserve markers's positions.
500 (insert rep)
501 (delete-region beg end)))
4bcbcb9d 502
2aa13ec4 503(defun flymake-read-file-to-temp-buffer (file-name)
5323b4b0
RS
504 "Insert contents of FILE-NAME into newly created temp buffer."
505 (let* ((temp-buffer (get-buffer-create (generate-new-buffer-name (concat "flymake:" (file-name-nondirectory file-name))))))
cd2325cd 506 (with-current-buffer temp-buffer
5323b4b0
RS
507 (insert-file-contents file-name))
508 temp-buffer))
4bcbcb9d 509
2aa13ec4 510(defun flymake-copy-buffer-to-temp-buffer (buffer)
5323b4b0 511 "Copy contents of BUFFER into newly created temp buffer."
4dd68f44
SM
512 (with-current-buffer
513 (get-buffer-create (generate-new-buffer-name
514 (concat "flymake:" (buffer-name buffer))))
515 (insert-buffer-substring buffer)
516 (current-buffer)))
4bcbcb9d 517
587d108e 518(defun flymake-check-include (source-file-name inc-name include-dirs)
5323b4b0 519 "Check if SOURCE-FILE-NAME can be found in include path.
587d108e
SM
520Return t if it can be found via include path using INC-NAME."
521 (if (file-name-absolute-p inc-name)
522 (flymake-same-files source-file-name inc-name)
523 (while (and include-dirs
524 (not (flymake-same-files
525 source-file-name
526 (concat (file-name-directory source-file-name)
527 "/" (car include-dirs)
528 "/" inc-name))))
529 (setq include-dirs (cdr include-dirs)))
530 include-dirs))
4bcbcb9d 531
2aa13ec4 532(defun flymake-find-buffer-for-file (file-name)
5323b4b0 533 "Check if there exists a buffer visiting FILE-NAME.
2aa13ec4 534Return t if so, nil if not."
5323b4b0
RS
535 (let ((buffer-name (get-file-buffer file-name)))
536 (if buffer-name
537 (get-buffer buffer-name))))
4bcbcb9d 538
587d108e 539(defun flymake-create-master-file (source-file-name patched-source-file-name get-incl-dirs-f create-temp-f masks include-regexp)
5323b4b0 540 "Save SOURCE-FILE-NAME with a different name.
2aa13ec4 541Find master file, patch and save it."
5323b4b0
RS
542 (let* ((possible-master-files (flymake-find-possible-master-files source-file-name flymake-master-file-dirs masks))
543 (master-file-count (length possible-master-files))
544 (idx 0)
545 (temp-buffer nil)
546 (master-file-name nil)
547 (patched-master-file-name nil)
548 (found nil))
549
550 (while (and (not found) (< idx master-file-count))
551 (setq master-file-name (nth idx possible-master-files))
552 (setq patched-master-file-name (funcall create-temp-f master-file-name "flymake_master"))
553 (if (flymake-find-buffer-for-file master-file-name)
554 (setq temp-buffer (flymake-copy-buffer-to-temp-buffer (flymake-find-buffer-for-file master-file-name)))
555 (setq temp-buffer (flymake-read-file-to-temp-buffer master-file-name)))
556 (setq found
557 (flymake-check-patch-master-file-buffer
558 temp-buffer
559 master-file-name
560 patched-master-file-name
561 source-file-name
562 patched-source-file-name
563 (funcall get-incl-dirs-f (file-name-directory master-file-name))
587d108e 564 include-regexp))
5323b4b0
RS
565 (setq idx (1+ idx)))
566 (if found
567 (list master-file-name patched-master-file-name)
568 (progn
569 (flymake-log 3 "none of %d master file(s) checked includes %s" master-file-count
570 (file-name-nondirectory source-file-name))
571 nil))))
4bcbcb9d 572
6df19241 573(defun flymake-save-buffer-in-file (file-name)
ab1d3835
SM
574 (make-directory (file-name-directory file-name) 1)
575 (write-region nil nil file-name nil 566)
6df19241 576 (flymake-log 3 "saved buffer %s in file %s" (buffer-name) file-name))
4bcbcb9d 577
2aa13ec4 578(defun flymake-save-string-to-file (file-name data)
5323b4b0
RS
579 "Save string DATA to file FILE-NAME."
580 (write-region data nil file-name nil 566))
4bcbcb9d 581
2aa13ec4 582(defun flymake-read-file-to-string (file-name)
5323b4b0
RS
583 "Read contents of file FILE-NAME and return as a string."
584 (with-temp-buffer
585 (insert-file-contents file-name)
586 (buffer-substring (point-min) (point-max))))
4bcbcb9d 587
2aa13ec4 588(defun flymake-process-filter (process output)
5323b4b0 589 "Parse OUTPUT and highlight error lines.
2aa13ec4 590It's flymake process filter."
43ed65ac 591 (let ((source-buffer (process-buffer process)))
4bcbcb9d 592
43ed65ac
SM
593 (flymake-log 3 "received %d byte(s) of output from process %d"
594 (length output) (process-id process))
466a09b5 595 (when (buffer-live-p source-buffer)
4dd68f44
SM
596 (with-current-buffer source-buffer
597 (flymake-parse-output-and-residual output)))))
4bcbcb9d 598
e02f48d7 599(defun flymake-process-sentinel (process _event)
5323b4b0 600 "Sentinel for syntax check buffers."
c07fa030
SM
601 (when (memq (process-status process) '(signal exit))
602 (let* ((exit-status (process-exit-status process))
603 (command (process-command process))
604 (source-buffer (process-buffer process))
605 (cleanup-f (flymake-get-cleanup-function (buffer-file-name source-buffer))))
606
607 (flymake-log 2 "process %d exited with code %d"
608 (process-id process) exit-status)
609 (condition-case err
610 (progn
611 (flymake-log 3 "cleaning up using %s" cleanup-f)
612 (when (buffer-live-p source-buffer)
613 (with-current-buffer source-buffer
614 (funcall cleanup-f)))
615
616 (delete-process process)
617 (setq flymake-processes (delq process flymake-processes))
618
619 (when (buffer-live-p source-buffer)
620 (with-current-buffer source-buffer
621
622 (flymake-parse-residual)
623 (flymake-post-syntax-check exit-status command)
624 (setq flymake-is-running nil))))
625 (error
626 (let ((err-str (format "Error in process sentinel for buffer %s: %s"
627 source-buffer (error-message-string err))))
628 (flymake-log 0 err-str)
629 (with-current-buffer source-buffer
630 (setq flymake-is-running nil))))))))
4bcbcb9d 631
4dd68f44
SM
632(defun flymake-post-syntax-check (exit-status command)
633 (setq flymake-err-info flymake-new-err-info)
634 (setq flymake-new-err-info nil)
635 (setq flymake-err-info
636 (flymake-fix-line-numbers
637 flymake-err-info 1 (flymake-count-lines)))
638 (flymake-delete-own-overlays)
639 (flymake-highlight-err-lines flymake-err-info)
53ec26ed 640 (let (err-count warn-count)
4dd68f44
SM
641 (setq err-count (flymake-get-err-count flymake-err-info "e"))
642 (setq warn-count (flymake-get-err-count flymake-err-info "w"))
643 (flymake-log 2 "%s: %d error(s), %d warning(s) in %.2f second(s)"
644 (buffer-name) err-count warn-count
53ec26ed 645 (- (flymake-float-time) flymake-check-start-time))
4dd68f44 646 (setq flymake-check-start-time nil)
53ec26ed 647
5323b4b0
RS
648 (if (and (equal 0 err-count) (equal 0 warn-count))
649 (if (equal 0 exit-status)
4dd68f44
SM
650 (flymake-report-status "" "") ; PASSED
651 (if (not flymake-check-was-interrupted)
652 (flymake-report-fatal-status "CFGERR"
80cd4bb4 653 (format "Configuration error has occurred while running %s" command))
4dd68f44
SM
654 (flymake-report-status nil ""))) ; "STOPPED"
655 (flymake-report-status (format "%d/%d" err-count warn-count) ""))))
4bcbcb9d 656
4dd68f44 657(defun flymake-parse-output-and-residual (output)
5323b4b0 658 "Split OUTPUT into lines, merge in residual if necessary."
4dd68f44
SM
659 (let* ((buffer-residual flymake-output-residual)
660 (total-output (if buffer-residual (concat buffer-residual output) output))
661 (lines-and-residual (flymake-split-output total-output))
662 (lines (nth 0 lines-and-residual))
663 (new-residual (nth 1 lines-and-residual)))
664 (setq flymake-output-residual new-residual)
665 (setq flymake-new-err-info
666 (flymake-parse-err-lines
667 flymake-new-err-info lines))))
668
669(defun flymake-parse-residual ()
5323b4b0 670 "Parse residual if it's non empty."
4dd68f44
SM
671 (when flymake-output-residual
672 (setq flymake-new-err-info
673 (flymake-parse-err-lines
674 flymake-new-err-info
675 (list flymake-output-residual)))
676 (setq flymake-output-residual nil)))
4bcbcb9d 677
2aa13ec4 678(defun flymake-er-make-er (line-no line-err-info-list)
5323b4b0 679 (list line-no line-err-info-list))
2aa13ec4
RS
680
681(defun flymake-er-get-line (err-info)
5323b4b0 682 (nth 0 err-info))
2aa13ec4
RS
683
684(defun flymake-er-get-line-err-info-list (err-info)
5323b4b0 685 (nth 1 err-info))
4bcbcb9d 686
a464a6c7 687(cl-defstruct (flymake-ler
587d108e
SM
688 (:constructor nil)
689 (:constructor flymake-ler-make-ler (file line type text &optional full-file)))
690 file line type text full-file)
2aa13ec4
RS
691
692(defun flymake-ler-set-file (line-err-info file)
5323b4b0 693 (flymake-ler-make-ler file
587d108e
SM
694 (flymake-ler-line line-err-info)
695 (flymake-ler-type line-err-info)
696 (flymake-ler-text line-err-info)
697 (flymake-ler-full-file line-err-info)))
2aa13ec4
RS
698
699(defun flymake-ler-set-full-file (line-err-info full-file)
587d108e
SM
700 (flymake-ler-make-ler (flymake-ler-file line-err-info)
701 (flymake-ler-line line-err-info)
702 (flymake-ler-type line-err-info)
703 (flymake-ler-text line-err-info)
2aa13ec4
RS
704 full-file))
705
706(defun flymake-ler-set-line (line-err-info line)
587d108e 707 (flymake-ler-make-ler (flymake-ler-file line-err-info)
4bcbcb9d 708 line
587d108e
SM
709 (flymake-ler-type line-err-info)
710 (flymake-ler-text line-err-info)
711 (flymake-ler-full-file line-err-info)))
4bcbcb9d 712
2aa13ec4 713(defun flymake-get-line-err-count (line-err-info-list type)
5323b4b0 714 "Return number of errors of specified TYPE.
173569aa 715Value of TYPE is either \"e\" or \"w\"."
5323b4b0
RS
716 (let* ((idx 0)
717 (count (length line-err-info-list))
718 (err-count 0))
4bcbcb9d 719
5323b4b0 720 (while (< idx count)
587d108e 721 (when (equal type (flymake-ler-type (nth idx line-err-info-list)))
5323b4b0
RS
722 (setq err-count (1+ err-count)))
723 (setq idx (1+ idx)))
724 err-count))
4bcbcb9d 725
2aa13ec4 726(defun flymake-get-err-count (err-info-list type)
5323b4b0
RS
727 "Return number of errors of specified TYPE for ERR-INFO-LIST."
728 (let* ((idx 0)
729 (count (length err-info-list))
730 (err-count 0))
731 (while (< idx count)
732 (setq err-count (+ err-count (flymake-get-line-err-count (nth 1 (nth idx err-info-list)) type)))
733 (setq idx (1+ idx)))
734 err-count))
2aa13ec4
RS
735
736(defun flymake-fix-line-numbers (err-info-list min-line max-line)
5323b4b0 737 "Replace line numbers with fixed value.
2aa13ec4
RS
738If line-numbers is less than MIN-LINE, set line numbers to MIN-LINE.
739If line numbers is greater than MAX-LINE, set line numbers to MAX-LINE.
ce721de4 740The reason for this fix is because some compilers might report
2aa13ec4 741line number outside the file being compiled."
5323b4b0
RS
742 (let* ((count (length err-info-list))
743 (err-info nil)
744 (line 0))
745 (while (> count 0)
746 (setq err-info (nth (1- count) err-info-list))
747 (setq line (flymake-er-get-line err-info))
748 (when (or (< line min-line) (> line max-line))
749 (setq line (if (< line min-line) min-line max-line))
750 (setq err-info-list (flymake-set-at err-info-list (1- count)
751 (flymake-er-make-er line
752 (flymake-er-get-line-err-info-list err-info)))))
753 (setq count (1- count))))
754 err-info-list)
4bcbcb9d 755
4dd68f44 756(defun flymake-highlight-err-lines (err-info-list)
5323b4b0 757 "Highlight error lines in BUFFER using info from ERR-INFO-LIST."
4dd68f44
SM
758 (save-excursion
759 (dolist (err err-info-list)
760 (flymake-highlight-line (car err) (nth 1 err)))))
4bcbcb9d 761
2aa13ec4 762(defun flymake-overlay-p (ov)
5323b4b0
RS
763 "Determine whether overlay OV was created by flymake."
764 (and (overlayp ov) (overlay-get ov 'flymake-overlay)))
4bcbcb9d 765
28ca98ac 766(defcustom flymake-error-bitmap '(exclamation-mark error)
24c38527 767 "Bitmap (a symbol) used in the fringe for indicating errors.
28ca98ac 768The value may also be a list of two elements where the second
24c38527
GM
769element specifies the face for the bitmap. For possible bitmap
770symbols, see `fringe-bitmaps'. See also `flymake-warning-bitmap'.
771
772The option `flymake-fringe-indicator-position' controls how and where
773this is used."
28ca98ac 774 :group 'flymake
d1a1c7e6 775 :version "24.3"
24c38527
GM
776 :type '(choice (symbol :tag "Bitmap")
777 (list :tag "Bitmap and face"
778 (symbol :tag "Bitmap")
779 (face :tag "Face"))))
28ca98ac
LL
780
781(defcustom flymake-warning-bitmap 'question-mark
24c38527 782 "Bitmap (a symbol) used in the fringe for indicating warnings.
28ca98ac 783The value may also be a list of two elements where the second
24c38527
GM
784element specifies the face for the bitmap. For possible bitmap
785symbols, see `fringe-bitmaps'. See also `flymake-error-bitmap'.
786
787The option `flymake-fringe-indicator-position' controls how and where
788this is used."
28ca98ac 789 :group 'flymake
d1a1c7e6 790 :version "24.3"
24c38527
GM
791 :type '(choice (symbol :tag "Bitmap")
792 (list :tag "Bitmap and face"
793 (symbol :tag "Bitmap")
794 (face :tag "Face"))))
28ca98ac
LL
795
796(defcustom flymake-fringe-indicator-position 'left-fringe
797 "The position to put flymake fringe indicator.
24c38527
GM
798The value can be nil (do not use indicators), `left-fringe' or `right-fringe'.
799See `flymake-error-bitmap' and `flymake-warning-bitmap'."
28ca98ac 800 :group 'flymake
d1a1c7e6 801 :version "24.3"
28ca98ac
LL
802 :type '(choice (const left-fringe)
803 (const right-fringe)
804 (const :tag "No fringe indicators" nil)))
805
806(defun flymake-make-overlay (beg end tooltip-text face bitmap mouse-face)
5323b4b0
RS
807 "Allocate a flymake overlay in range BEG and END."
808 (when (not (flymake-region-has-flymake-overlays beg end))
28ca98ac
LL
809 (let ((ov (make-overlay beg end nil t t))
810 (fringe (and flymake-fringe-indicator-position
811 (propertize "!" 'display
812 (cons flymake-fringe-indicator-position
813 (if (listp bitmap)
814 bitmap
815 (list bitmap)))))))
5323b4b0
RS
816 (overlay-put ov 'face face)
817 (overlay-put ov 'mouse-face mouse-face)
818 (overlay-put ov 'help-echo tooltip-text)
819 (overlay-put ov 'flymake-overlay t)
820 (overlay-put ov 'priority 100)
28ca98ac
LL
821 (overlay-put ov 'evaporate t)
822 (overlay-put ov 'before-string fringe)
9a686ad2 823 ;;+(flymake-log 3 "created overlay %s" ov)
5323b4b0
RS
824 ov)
825 (flymake-log 3 "created an overlay at (%d-%d)" beg end)))
4bcbcb9d 826
4dd68f44 827(defun flymake-delete-own-overlays ()
5323b4b0 828 "Delete all flymake overlays in BUFFER."
4dd68f44
SM
829 (dolist (ol (overlays-in (point-min) (point-max)))
830 (when (flymake-overlay-p ol)
831 (delete-overlay ol)
832 ;;+(flymake-log 3 "deleted overlay %s" ol)
833 )))
4bcbcb9d 834
2aa13ec4 835(defun flymake-region-has-flymake-overlays (beg end)
5323b4b0 836 "Check if region specified by BEG and END has overlay.
2aa13ec4 837Return t if it has at least one flymake overlay, nil if no overlay."
5323b4b0
RS
838 (let ((ov (overlays-in beg end))
839 (has-flymake-overlays nil))
840 (while (consp ov)
841 (when (flymake-overlay-p (car ov))
842 (setq has-flymake-overlays t))
cd2325cd
SM
843 (setq ov (cdr ov)))
844 has-flymake-overlays))
4bcbcb9d 845
ded09abd 846(defface flymake-errline
4b56d0fe 847 '((t :inherit error))
5323b4b0
RS
848 "Face used for marking error lines."
849 :group 'flymake)
4bcbcb9d 850
ded09abd 851(defface flymake-warnline
4b56d0fe 852 '((t :inherit warning))
5323b4b0
RS
853 "Face used for marking warning lines."
854 :group 'flymake)
4bcbcb9d 855
2aa13ec4 856(defun flymake-highlight-line (line-no line-err-info-list)
5323b4b0 857 "Highlight line LINE-NO in current buffer.
173569aa 858Perhaps use text from LINE-ERR-INFO-LIST to enhance highlighting."
5f68c1b7
GM
859 (goto-char (point-min))
860 (forward-line (1- line-no))
3ba6b2ee 861 (let* ((line-beg (point-at-bol))
81aa0dab 862 (line-end (point-at-eol))
5323b4b0
RS
863 (beg line-beg)
864 (end line-end)
587d108e 865 (tooltip-text (flymake-ler-text (nth 0 line-err-info-list)))
28ca98ac
LL
866 (face nil)
867 (bitmap nil))
5323b4b0
RS
868
869 (goto-char line-beg)
870 (while (looking-at "[ \t]")
871 (forward-char))
4bcbcb9d 872
5323b4b0 873 (setq beg (point))
4bcbcb9d 874
5323b4b0
RS
875 (goto-char line-end)
876 (while (and (looking-at "[ \t\r\n]") (> (point) 1))
877 (backward-char))
4bcbcb9d 878
5323b4b0 879 (setq end (1+ (point)))
4bcbcb9d 880
5323b4b0
RS
881 (when (<= end beg)
882 (setq beg line-beg)
883 (setq end line-end))
2aa13ec4 884
5323b4b0
RS
885 (when (= end beg)
886 (goto-char end)
887 (forward-line)
888 (setq end (point)))
2aa13ec4 889
5323b4b0 890 (if (> (flymake-get-line-err-count line-err-info-list "e") 0)
28ca98ac
LL
891 (setq face 'flymake-errline
892 bitmap flymake-error-bitmap)
893 (setq face 'flymake-warnline
894 bitmap flymake-warning-bitmap))
2aa13ec4 895
28ca98ac 896 (flymake-make-overlay beg end tooltip-text face bitmap nil)))
4bcbcb9d 897
4dd68f44 898(defun flymake-parse-err-lines (err-info-list lines)
5323b4b0
RS
899 "Parse err LINES, store info in ERR-INFO-LIST."
900 (let* ((count (length lines))
901 (idx 0)
902 (line-err-info nil)
903 (real-file-name nil)
4dd68f44 904 (source-file-name buffer-file-name)
5323b4b0
RS
905 (get-real-file-name-f (flymake-get-real-file-name-function source-file-name)))
906
907 (while (< idx count)
908 (setq line-err-info (flymake-parse-line (nth idx lines)))
909 (when line-err-info
c07fa030 910 (setq real-file-name (funcall get-real-file-name-f
587d108e 911 (flymake-ler-file line-err-info)))
5323b4b0
RS
912 (setq line-err-info (flymake-ler-set-full-file line-err-info real-file-name))
913
b89b385c
CY
914 (when (flymake-same-files real-file-name source-file-name)
915 (setq line-err-info (flymake-ler-set-file line-err-info nil))
916 (setq err-info-list (flymake-add-err-info err-info-list line-err-info))))
5323b4b0
RS
917 (flymake-log 3 "parsed '%s', %s line-err-info" (nth idx lines) (if line-err-info "got" "no"))
918 (setq idx (1+ idx)))
919 err-info-list))
4bcbcb9d 920
2aa13ec4 921(defun flymake-split-output (output)
5323b4b0 922 "Split OUTPUT into lines.
9a686ad2
SM
923Return last one as residual if it does not end with newline char.
924Returns ((LINES) RESIDUAL)."
5323b4b0
RS
925 (when (and output (> (length output) 0))
926 (let* ((lines (flymake-split-string output "[\n\r]+"))
927 (complete (equal "\n" (char-to-string (aref output (1- (length output))))))
928 (residual nil))
929 (when (not complete)
930 (setq residual (car (last lines)))
931 (setq lines (butlast lines)))
932 (list lines residual))))
4bcbcb9d 933
2aa13ec4 934(defun flymake-reformat-err-line-patterns-from-compile-el (original-list)
5323b4b0 935 "Grab error line patterns from ORIGINAL-LIST in compile.el format.
2aa13ec4 936Convert it to flymake internal format."
5323b4b0 937 (let* ((converted-list '()))
cd2325cd
SM
938 (dolist (item original-list)
939 (setq item (cdr item))
940 (let ((regexp (nth 0 item))
941 (file (nth 1 item))
942 (line (nth 2 item))
943 (col (nth 3 item)))
944 (if (consp file) (setq file (car file)))
945 (if (consp line) (setq line (car line)))
946 (if (consp col) (setq col (car col)))
d799c278 947
cd2325cd
SM
948 (when (not (functionp line))
949 (setq converted-list (cons (list regexp file line col) converted-list)))))
5323b4b0 950 converted-list))
2aa13ec4 951
c3b8339f 952(require 'compile)
5323b4b0
RS
953
954(defvar flymake-err-line-patterns ; regexp file-idx line-idx col-idx (optional) text-idx(optional), match-end to end of string is error text
955 (append
956 '(
9a686ad2 957 ;; MS Visual C++ 6.0
5323b4b0
RS
958 ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \: \\(\\(error\\|warning\\|fatal error\\) \\(C[0-9]+\\):[ \t\n]*\\(.+\\)\\)"
959 1 3 nil 4)
9a686ad2 960 ;; jikes
5323b4b0
RS
961 ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)\:\\([0-9]+\\)\:[0-9]+\:[0-9]+\:[0-9]+\: \\(\\(Error\\|Warning\\|Caution\\|Semantic Error\\):[ \t\n]*\\(.+\\)\\)"
962 1 3 nil 4)
9a686ad2 963 ;; MS midl
5323b4b0
RS
964 ("midl[ ]*:[ ]*\\(command line error .*\\)"
965 nil nil nil 1)
9a686ad2 966 ;; MS C#
5323b4b0
RS
967 ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\),[0-9]+)\: \\(\\(error\\|warning\\|fatal error\\) \\(CS[0-9]+\\):[ \t\n]*\\(.+\\)\\)"
968 1 3 nil 4)
9a686ad2 969 ;; perl
5323b4b0 970 ("\\(.*\\) at \\([^ \n]+\\) line \\([0-9]+\\)[,.\n]" 2 3 nil 1)
eabd11d4
MH
971 ;; PHP
972 ("\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)" 2 3 nil 1)
9a686ad2 973 ;; LaTeX warnings (fileless) ("\\(LaTeX \\(Warning\\|Error\\): .*\\) on input line \\([0-9]+\\)" 20 3 nil 1)
819a6054
GM
974 ;; ant/javac. Note this also matches gcc warnings!
975 (" *\\(\\[javac\\] *\\)?\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)\:\\([0-9]+\\)\\(?:\:[0-9]+\\)?\:[ \t\n]*\\(.+\\)"
5323b4b0
RS
976 2 4 nil 5))
977 ;; compilation-error-regexp-alist)
ce721de4 978 (flymake-reformat-err-line-patterns-from-compile-el compilation-error-regexp-alist-alist))
8c01db22
EZ
979 "Patterns for matching error/warning lines. Each pattern has the form
980\(REGEXP FILE-IDX LINE-IDX COL-IDX ERR-TEXT-IDX).
9a686ad2
SM
981Use `flymake-reformat-err-line-patterns-from-compile-el' to add patterns
982from compile.el")
983
984;;(defcustom flymake-err-line-patterns
985;; '(
986;; ; MS Visual C++ 6.0
987;; ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \: \\(\\(error\\|warning\\|fatal error\\) \\(C[0-9]+\\):[ \t\n]*\\(.+\\)\\)"
988;; 1 3 4)
989;; ; jikes
990;; ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)\:\\([0-9]+\\)\:[0-9]+\:[0-9]+\:[0-9]+\: \\(\\(Error\\|Warning\\|Caution\\):[ \t\n]*\\(.+\\)\\)"
991;; 1 3 4))
992;; "patterns for matching error/warning lines, (regexp file-idx line-idx err-text-idx)"
993;; :group 'flymake
994;; :type '(repeat (string number number number))
995;;)
4bcbcb9d 996
3aca1291
LL
997(defvar flymake-warning-re "^[wW]arning"
998 "Regexp matching against err-text to detect a warning.")
999
2aa13ec4 1000(defun flymake-parse-line (line)
173569aa
JB
1001 "Parse LINE to see if it is an error or warning.
1002Return its components if so, nil otherwise."
5323b4b0
RS
1003 (let ((raw-file-name nil)
1004 (line-no 0)
1005 (err-type "e")
1006 (err-text nil)
17404091 1007 (patterns flymake-err-line-patterns)
5323b4b0 1008 (matched nil))
17404091
SM
1009 (while (and patterns (not matched))
1010 (when (string-match (car (car patterns)) line)
1011 (let* ((file-idx (nth 1 (car patterns)))
1012 (line-idx (nth 2 (car patterns))))
5323b4b0
RS
1013
1014 (setq raw-file-name (if file-idx (match-string file-idx line) nil))
027a4b6b 1015 (setq line-no (if line-idx (string-to-number (match-string line-idx line)) 0))
17404091
SM
1016 (setq err-text (if (> (length (car patterns)) 4)
1017 (match-string (nth 4 (car patterns)) line)
5323b4b0
RS
1018 (flymake-patch-err-text (substring line (match-end 0)))))
1019 (or err-text (setq err-text "<no error text>"))
3aca1291 1020 (if (and err-text (string-match flymake-warning-re err-text))
5323b4b0
RS
1021 (setq err-type "w")
1022 )
1023 (flymake-log 3 "parse line: file-idx=%s line-idx=%s file=%s line=%s text=%s" file-idx line-idx
1024 raw-file-name line-no err-text)
1025 (setq matched t)))
17404091 1026 (setq patterns (cdr patterns)))
5323b4b0
RS
1027 (if matched
1028 (flymake-ler-make-ler raw-file-name line-no err-type err-text)
1029 ())))
4bcbcb9d 1030
2aa13ec4 1031(defun flymake-find-err-info (err-info-list line-no)
5323b4b0
RS
1032 "Find (line-err-info-list pos) for specified LINE-NO."
1033 (if err-info-list
1034 (let* ((line-err-info-list nil)
1035 (pos 0)
1036 (count (length err-info-list)))
1037
1038 (while (and (< pos count) (< (car (nth pos err-info-list)) line-no))
1039 (setq pos (1+ pos)))
1040 (when (and (< pos count) (equal (car (nth pos err-info-list)) line-no))
1041 (setq line-err-info-list (flymake-er-get-line-err-info-list (nth pos err-info-list))))
1042 (list line-err-info-list pos))
1043 '(nil 0)))
4bcbcb9d 1044
2aa13ec4 1045(defun flymake-line-err-info-is-less-or-equal (line-one line-two)
587d108e
SM
1046 (or (string< (flymake-ler-type line-one) (flymake-ler-type line-two))
1047 (and (string= (flymake-ler-type line-one) (flymake-ler-type line-two))
1048 (not (flymake-ler-file line-one)) (flymake-ler-file line-two))
1049 (and (string= (flymake-ler-type line-one) (flymake-ler-type line-two))
1050 (or (and (flymake-ler-file line-one) (flymake-ler-file line-two))
1051 (and (not (flymake-ler-file line-one)) (not (flymake-ler-file line-two)))))))
4bcbcb9d 1052
2aa13ec4 1053(defun flymake-add-line-err-info (line-err-info-list line-err-info)
53ec26ed
RS
1054 "Update LINE-ERR-INFO-LIST with the error LINE-ERR-INFO.
1055For the format of LINE-ERR-INFO, see `flymake-ler-make-ler'.
1056The new element is inserted in the proper position, according to
1057the predicate `flymake-line-err-info-is-less-or-equal'.
1058The updated value of LINE-ERR-INFO-LIST is returned."
5323b4b0
RS
1059 (if (not line-err-info-list)
1060 (list line-err-info)
1061 (let* ((count (length line-err-info-list))
1062 (idx 0))
1063 (while (and (< idx count) (flymake-line-err-info-is-less-or-equal (nth idx line-err-info-list) line-err-info))
1064 (setq idx (1+ idx)))
1065 (cond ((equal 0 idx) (setq line-err-info-list (cons line-err-info line-err-info-list)))
1066 (t (setq line-err-info-list (flymake-ins-after line-err-info-list (1- idx) line-err-info))))
1067 line-err-info-list)))
4bcbcb9d 1068
2aa13ec4 1069(defun flymake-add-err-info (err-info-list line-err-info)
53ec26ed
RS
1070 "Update ERR-INFO-LIST with the error LINE-ERR-INFO, preserving sort order.
1071Returns the updated value of ERR-INFO-LIST.
1072For the format of ERR-INFO-LIST, see `flymake-err-info'.
1073For the format of LINE-ERR-INFO, see `flymake-ler-make-ler'."
587d108e 1074 (let* ((line-no (if (flymake-ler-file line-err-info) 1 (flymake-ler-line line-err-info)))
5323b4b0
RS
1075 (info-and-pos (flymake-find-err-info err-info-list line-no))
1076 (exists (car info-and-pos))
1077 (pos (nth 1 info-and-pos))
1078 (line-err-info-list nil)
1079 (err-info nil))
1080
1081 (if exists
1082 (setq line-err-info-list (flymake-er-get-line-err-info-list (car (nthcdr pos err-info-list)))))
1083 (setq line-err-info-list (flymake-add-line-err-info line-err-info-list line-err-info))
1084
1085 (setq err-info (flymake-er-make-er line-no line-err-info-list))
1086 (cond (exists (setq err-info-list (flymake-set-at err-info-list pos err-info)))
1087 ((equal 0 pos) (setq err-info-list (cons err-info err-info-list)))
1088 (t (setq err-info-list (flymake-ins-after err-info-list (1- pos) err-info))))
1089 err-info-list))
4bcbcb9d 1090
2aa13ec4 1091(defun flymake-get-project-include-dirs-imp (basedir)
5323b4b0
RS
1092 "Include dirs for the project current file belongs to."
1093 (if (flymake-get-project-include-dirs-from-cache basedir)
1094 (progn
1095 (flymake-get-project-include-dirs-from-cache basedir))
9a686ad2 1096 ;;else
ff4e2883
KS
1097 (let* ((command-line (concat "make -C "
1098 (shell-quote-argument basedir)
1099 " DUMPVARS=INCLUDE_DIRS dumpvars"))
5323b4b0
RS
1100 (output (shell-command-to-string command-line))
1101 (lines (flymake-split-string output "\n"))
1102 (count (length lines))
1103 (idx 0)
1104 (inc-dirs nil))
1105 (while (and (< idx count) (not (string-match "^INCLUDE_DIRS=.*" (nth idx lines))))
1106 (setq idx (1+ idx)))
1107 (when (< idx count)
1108 (let* ((inc-lines (flymake-split-string (nth idx lines) " *-I"))
1109 (inc-count (length inc-lines)))
1110 (while (> inc-count 0)
1111 (when (not (string-match "^INCLUDE_DIRS=.*" (nth (1- inc-count) inc-lines)))
587d108e 1112 (push (flymake-replace-regexp-in-string "\"" "" (nth (1- inc-count) inc-lines)) inc-dirs))
5323b4b0
RS
1113 (setq inc-count (1- inc-count)))))
1114 (flymake-add-project-include-dirs-to-cache basedir inc-dirs)
1115 inc-dirs)))
4bcbcb9d
EZ
1116
1117(defcustom flymake-get-project-include-dirs-function 'flymake-get-project-include-dirs-imp
173569aa 1118 "Function used to get project include dirs, one parameter: basedir name."
5323b4b0
RS
1119 :group 'flymake
1120 :type 'function)
4bcbcb9d 1121
2aa13ec4 1122(defun flymake-get-project-include-dirs (basedir)
5323b4b0 1123 (funcall flymake-get-project-include-dirs-function basedir))
4bcbcb9d 1124
2aa13ec4 1125(defun flymake-get-system-include-dirs ()
5323b4b0
RS
1126 "System include dirs - from the 'INCLUDE' env setting."
1127 (let* ((includes (getenv "INCLUDE")))
1128 (if includes (flymake-split-string includes path-separator) nil)))
4bcbcb9d
EZ
1129
1130(defvar flymake-project-include-dirs-cache (flymake-makehash 'equal))
4bcbcb9d 1131
2aa13ec4 1132(defun flymake-get-project-include-dirs-from-cache (base-dir)
5323b4b0 1133 (gethash base-dir flymake-project-include-dirs-cache))
2aa13ec4
RS
1134
1135(defun flymake-add-project-include-dirs-to-cache (base-dir include-dirs)
5323b4b0 1136 (puthash base-dir include-dirs flymake-project-include-dirs-cache))
2aa13ec4
RS
1137
1138(defun flymake-clear-project-include-dirs-cache ()
5323b4b0 1139 (clrhash flymake-project-include-dirs-cache))
2aa13ec4
RS
1140
1141(defun flymake-get-include-dirs (base-dir)
5323b4b0
RS
1142 "Get dirs to use when resolving local file names."
1143 (let* ((include-dirs (append '(".") (flymake-get-project-include-dirs base-dir) (flymake-get-system-include-dirs))))
1144 include-dirs))
4bcbcb9d 1145
4dd68f44
SM
1146;; (defun flymake-restore-formatting ()
1147;; "Remove any formatting made by flymake."
1148;; )
4bcbcb9d 1149
c07fa030
SM
1150;; (defun flymake-get-program-dir (buffer)
1151;; "Get dir to start program in."
1152;; (unless (bufferp buffer)
1153;; (error "Invalid buffer"))
1154;; (with-current-buffer buffer
1155;; default-directory))
4bcbcb9d 1156
2aa13ec4 1157(defun flymake-safe-delete-file (file-name)
5323b4b0
RS
1158 (when (and file-name (file-exists-p file-name))
1159 (delete-file file-name)
1160 (flymake-log 1 "deleted file %s" file-name)))
4bcbcb9d 1161
2aa13ec4 1162(defun flymake-safe-delete-directory (dir-name)
e02f48d7 1163 (condition-case nil
5323b4b0
RS
1164 (progn
1165 (delete-directory dir-name)
1166 (flymake-log 1 "deleted dir %s" dir-name))
1167 (error
1168 (flymake-log 1 "Failed to delete dir %s, error ignored" dir-name))))
4bcbcb9d 1169
ce721de4 1170(defcustom flymake-compilation-prevents-syntax-check t
2c587104 1171 "If non-nil, don't start syntax check if compilation is running."
5323b4b0
RS
1172 :group 'flymake
1173 :type 'boolean)
4bcbcb9d 1174
4dd68f44
SM
1175(defun flymake-start-syntax-check ()
1176 "Start syntax checking for current buffer."
1177 (interactive)
1178 (flymake-log 3 "flymake is running: %s" flymake-is-running)
1179 (when (and (not flymake-is-running)
1180 (flymake-can-syntax-check-file buffer-file-name))
1181 (when (or (not flymake-compilation-prevents-syntax-check)
1182 (not (flymake-compilation-is-running))) ;+ (flymake-rep-ort-status buffer "COMP")
1183 (flymake-clear-buildfile-cache)
1184 (flymake-clear-project-include-dirs-cache)
1185
1186 (setq flymake-check-was-interrupted nil)
4dd68f44
SM
1187
1188 (let* ((source-file-name buffer-file-name)
1189 (init-f (flymake-get-init-function source-file-name))
1190 (cleanup-f (flymake-get-cleanup-function source-file-name))
6df19241 1191 (cmd-and-args (funcall init-f))
4dd68f44
SM
1192 (cmd (nth 0 cmd-and-args))
1193 (args (nth 1 cmd-and-args))
1194 (dir (nth 2 cmd-and-args)))
1195 (if (not cmd-and-args)
1196 (progn
1197 (flymake-log 0 "init function %s for %s failed, cleaning up" init-f source-file-name)
c07fa030 1198 (funcall cleanup-f))
4dd68f44
SM
1199 (progn
1200 (setq flymake-last-change-time nil)
1201 (flymake-start-syntax-check-process cmd args dir)))))))
1202
1203(defun flymake-start-syntax-check-process (cmd args dir)
5323b4b0 1204 "Start syntax check process."
c79a6f38
SM
1205 (condition-case err
1206 (let* ((process
1207 (let ((default-directory (or dir default-directory)))
1208 (when dir
1209 (flymake-log 3 "starting process on dir %s" dir))
1210 (apply 'start-file-process
1211 "flymake-proc" (current-buffer) cmd args))))
1212 (set-process-sentinel process 'flymake-process-sentinel)
1213 (set-process-filter process 'flymake-process-filter)
1214 (push process flymake-processes)
1215
1216 (setq flymake-is-running t)
1217 (setq flymake-last-change-time nil)
1218 (setq flymake-check-start-time (flymake-float-time))
1219
1220 (flymake-report-status nil "*")
1221 (flymake-log 2 "started process %d, command=%s, dir=%s"
1222 (process-id process) (process-command process)
1223 default-directory)
1224 process)
1225 (error
1226 (let* ((err-str (format "Failed to launch syntax check process '%s' with args %s: %s"
1227 cmd args (error-message-string err)))
1228 (source-file-name buffer-file-name)
1229 (cleanup-f (flymake-get-cleanup-function source-file-name)))
1230 (flymake-log 0 err-str)
1231 (funcall cleanup-f)
1232 (flymake-report-fatal-status "PROCERR" err-str)))))
4bcbcb9d 1233
43ed65ac
SM
1234(defun flymake-kill-process (proc)
1235 "Kill process PROC."
1236 (kill-process proc)
1237 (let* ((buf (process-buffer proc)))
1238 (when (buffer-live-p buf)
1239 (with-current-buffer buf
53ec26ed 1240 (setq flymake-check-was-interrupted t))))
43ed65ac 1241 (flymake-log 1 "killed process %d" (process-id proc)))
4bcbcb9d 1242
2aa13ec4 1243(defun flymake-stop-all-syntax-checks ()
5323b4b0
RS
1244 "Kill all syntax check processes."
1245 (interactive)
43ed65ac
SM
1246 (while flymake-processes
1247 (flymake-kill-process (pop flymake-processes))))
4bcbcb9d 1248
2aa13ec4 1249(defun flymake-compilation-is-running ()
5323b4b0
RS
1250 (and (boundp 'compilation-in-progress)
1251 compilation-in-progress))
4bcbcb9d 1252
2aa13ec4 1253(defun flymake-compile ()
5323b4b0
RS
1254 "Kill all flymake syntax checks, start compilation."
1255 (interactive)
1256 (flymake-stop-all-syntax-checks)
1257 (call-interactively 'compile))
4bcbcb9d 1258
4bcbcb9d 1259(defcustom flymake-no-changes-timeout 0.5
5323b4b0
RS
1260 "Time to wait after last change before starting compilation."
1261 :group 'flymake
1262 :type 'number)
4bcbcb9d 1263
2aa13ec4 1264(defun flymake-on-timer-event (buffer)
5323b4b0 1265 "Start a syntax check for buffer BUFFER if necessary."
587d108e 1266 (when (buffer-live-p buffer)
cd2325cd 1267 (with-current-buffer buffer
53ec26ed
RS
1268 (when (and (not flymake-is-running)
1269 flymake-last-change-time
587d108e
SM
1270 (> (- (flymake-float-time) flymake-last-change-time)
1271 flymake-no-changes-timeout))
53ec26ed
RS
1272
1273 (setq flymake-last-change-time nil)
5323b4b0 1274 (flymake-log 3 "starting syntax check as more than 1 second passed since last change")
4dd68f44 1275 (flymake-start-syntax-check)))))
4bcbcb9d 1276
2aa13ec4 1277(defun flymake-current-line-no ()
5323b4b0 1278 "Return number of current line in current buffer."
587d108e 1279 (count-lines (point-min) (if (eobp) (point) (1+ (point)))))
4bcbcb9d 1280
4dd68f44 1281(defun flymake-count-lines ()
5323b4b0 1282 "Return number of lines in buffer BUFFER."
4dd68f44 1283 (count-lines (point-min) (point-max)))
4bcbcb9d 1284
2aa13ec4 1285(defun flymake-display-err-menu-for-current-line ()
5323b4b0
RS
1286 "Display a menu with errors/warnings for current line if it has errors and/or warnings."
1287 (interactive)
1288 (let* ((line-no (flymake-current-line-no))
53ec26ed 1289 (line-err-info-list (nth 0 (flymake-find-err-info flymake-err-info line-no)))
5323b4b0 1290 (menu-data (flymake-make-err-menu-data line-no line-err-info-list))
43ed65ac 1291 (choice nil))
5323b4b0
RS
1292 (if menu-data
1293 (progn
43ed65ac 1294 (setq choice (flymake-popup-menu menu-data))
5323b4b0
RS
1295 (flymake-log 3 "choice=%s" choice)
1296 (when choice
1297 (eval choice)))
1298 (flymake-log 1 "no errors for line %d" line-no))))
4bcbcb9d 1299
2aa13ec4 1300(defun flymake-make-err-menu-data (line-no line-err-info-list)
173569aa 1301 "Make a (menu-title (item-title item-action)*) list with errors/warnings from LINE-ERR-INFO-LIST."
5323b4b0
RS
1302 (let* ((menu-items nil))
1303 (when line-err-info-list
1304 (let* ((count (length line-err-info-list))
1305 (menu-item-text nil))
1306 (while (> count 0)
587d108e
SM
1307 (setq menu-item-text (flymake-ler-text (nth (1- count) line-err-info-list)))
1308 (let* ((file (flymake-ler-file (nth (1- count) line-err-info-list)))
1309 (full-file (flymake-ler-full-file (nth (1- count) line-err-info-list)))
1310 (line (flymake-ler-line (nth (1- count) line-err-info-list))))
5323b4b0
RS
1311 (if file
1312 (setq menu-item-text (concat menu-item-text " - " file "(" (format "%d" line) ")")))
1313 (setq menu-items (cons (list menu-item-text
1314 (if file (list 'flymake-goto-file-and-line full-file line) nil))
1315 menu-items)))
1316 (setq count (1- count)))
1317 (flymake-log 3 "created menu-items with %d item(s)" (length menu-items))))
1318 (if menu-items
1319 (let* ((menu-title (format "Line %d: %d error(s), %d warning(s)" line-no
1320 (flymake-get-line-err-count line-err-info-list "e")
1321 (flymake-get-line-err-count line-err-info-list "w"))))
1322 (list menu-title menu-items))
1323 nil)))
4bcbcb9d 1324
2aa13ec4 1325(defun flymake-goto-file-and-line (file line)
9a686ad2 1326 "Try to get buffer for FILE and goto line LINE in it."
5323b4b0 1327 (if (not (file-exists-p file))
caf790b6
MR
1328 (flymake-log 1 "File %s does not exist" file)
1329 (find-file file)
5f68c1b7
GM
1330 (goto-char (point-min))
1331 (forward-line (1- line))))
4bcbcb9d 1332
2aa13ec4 1333;; flymake minor mode declarations
4bd0a5d0 1334(defvar flymake-mode-line nil)
2aa13ec4 1335
4bcbcb9d 1336(make-variable-buffer-local 'flymake-mode-line)
2aa13ec4 1337
4bcbcb9d 1338(defvar flymake-mode-line-e-w nil)
2aa13ec4 1339
4bcbcb9d 1340(make-variable-buffer-local 'flymake-mode-line-e-w)
2aa13ec4 1341
4bcbcb9d 1342(defvar flymake-mode-line-status nil)
2aa13ec4 1343
4bcbcb9d 1344(make-variable-buffer-local 'flymake-mode-line-status)
4bcbcb9d 1345
4dd68f44 1346(defun flymake-report-status (e-w &optional status)
5323b4b0 1347 "Show status in mode line."
4dd68f44
SM
1348 (when e-w
1349 (setq flymake-mode-line-e-w e-w))
1350 (when status
1351 (setq flymake-mode-line-status status))
1352 (let* ((mode-line " Flymake"))
1353 (when (> (length flymake-mode-line-e-w) 0)
1354 (setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
1355 (setq mode-line (concat mode-line flymake-mode-line-status))
1356 (setq flymake-mode-line mode-line)
1357 (force-mode-line-update)))
4bcbcb9d 1358
2aa13ec4 1359(defun flymake-display-warning (warning)
5323b4b0
RS
1360 "Display a warning to user."
1361 (message-box warning))
4bcbcb9d
EZ
1362
1363(defcustom flymake-gui-warnings-enabled t
173569aa 1364 "Enables/disables GUI warnings."
5323b4b0
RS
1365 :group 'flymake
1366 :type 'boolean)
4bcbcb9d 1367
4dd68f44 1368(defun flymake-report-fatal-status (status warning)
5323b4b0
RS
1369 "Display a warning and switch flymake mode off."
1370 (when flymake-gui-warnings-enabled
1371 (flymake-display-warning (format "Flymake: %s. Flymake will be switched OFF" warning))
1372 )
4dd68f44
SM
1373 (flymake-mode 0)
1374 (flymake-log 0 "switched OFF Flymake mode for buffer %s due to fatal status %s, warning %s"
1375 (buffer-name) status warning))
4bcbcb9d 1376
d57f6b5e
SM
1377(defcustom flymake-start-syntax-check-on-find-file t
1378 "Start syntax check on find file."
1379 :group 'flymake
1380 :type 'boolean)
1381
5ffc943b 1382;;;###autoload
4bd0a5d0 1383(define-minor-mode flymake-mode
e1ac4066
GM
1384 "Toggle on-the-fly syntax checking.
1385With a prefix argument ARG, enable the mode if ARG is positive,
1386and disable it otherwise. If called from Lisp, enable the mode
1387if ARG is omitted or nil."
d799c278 1388 :group 'flymake :lighter flymake-mode-line
d57f6b5e
SM
1389 (cond
1390
1391 ;; Turning the mode ON.
1392 (flymake-mode
83319045
LMI
1393 (cond
1394 ((not buffer-file-name)
1395 (message "Flymake unable to run without a buffer file name"))
1396 ((not (flymake-can-syntax-check-file buffer-file-name))
1397 (flymake-log 2 "flymake cannot check syntax in buffer %s" (buffer-name)))
1398 (t
d57f6b5e
SM
1399 (add-hook 'after-change-functions 'flymake-after-change-function nil t)
1400 (add-hook 'after-save-hook 'flymake-after-save-hook nil t)
1401 (add-hook 'kill-buffer-hook 'flymake-kill-buffer-hook nil t)
1402 ;;+(add-hook 'find-file-hook 'flymake-find-file-hook)
1403
4dd68f44 1404 (flymake-report-status "" "")
c92d6023 1405
d57f6b5e
SM
1406 (setq flymake-timer
1407 (run-at-time nil 1 'flymake-on-timer-event (current-buffer)))
1408
0221e323
SM
1409 (when (and flymake-start-syntax-check-on-find-file
1410 ;; Since we write temp files in current dir, there's no point
1411 ;; trying if the directory is read-only (bug#8954).
1412 (file-writable-p (file-name-directory buffer-file-name)))
1413 (with-demoted-errors
1414 (flymake-start-syntax-check))))))
d57f6b5e
SM
1415
1416 ;; Turning the mode OFF.
1417 (t
1418 (remove-hook 'after-change-functions 'flymake-after-change-function t)
1419 (remove-hook 'after-save-hook 'flymake-after-save-hook t)
1420 (remove-hook 'kill-buffer-hook 'flymake-kill-buffer-hook t)
1421 ;;+(remove-hook 'find-file-hook (function flymake-find-file-hook) t)
2aa13ec4 1422
4dd68f44 1423 (flymake-delete-own-overlays)
d57f6b5e
SM
1424
1425 (when flymake-timer
1426 (cancel-timer flymake-timer)
1427 (setq flymake-timer nil))
1428
bd6a83d5 1429 (setq flymake-is-running nil))))
4bcbcb9d 1430
4bcbcb9d 1431;;;###autoload
2aa13ec4 1432(defun flymake-mode-on ()
5323b4b0 1433 "Turn flymake mode on."
d57f6b5e
SM
1434 (flymake-mode 1)
1435 (flymake-log 1 "flymake mode turned ON for buffer %s" (buffer-name)))
4bcbcb9d
EZ
1436
1437;;;###autoload
2aa13ec4 1438(defun flymake-mode-off ()
5323b4b0 1439 "Turn flymake mode off."
d57f6b5e 1440 (flymake-mode 0)
bd6a83d5 1441 (flymake-log 1 "flymake mode turned OFF for buffer %s" (buffer-name)))
4bcbcb9d
EZ
1442
1443(defcustom flymake-start-syntax-check-on-newline t
5323b4b0
RS
1444 "Start syntax check if newline char was added/removed from the buffer."
1445 :group 'flymake
1446 :type 'boolean)
4bcbcb9d 1447
e02f48d7 1448(defun flymake-after-change-function (start stop _len)
9a686ad2
SM
1449 "Start syntax check for current buffer if it isn't already running."
1450 ;;+(flymake-log 0 "setting change time to %s" (flymake-float-time))
5323b4b0
RS
1451 (let((new-text (buffer-substring start stop)))
1452 (when (and flymake-start-syntax-check-on-newline (equal new-text "\n"))
1453 (flymake-log 3 "starting syntax check as new-line has been seen")
4dd68f44 1454 (flymake-start-syntax-check))
53ec26ed 1455 (setq flymake-last-change-time (flymake-float-time))))
4bcbcb9d 1456
2aa13ec4 1457(defun flymake-after-save-hook ()
5323b4b0
RS
1458 (if (local-variable-p 'flymake-mode (current-buffer)) ; (???) other way to determine whether flymake is active in buffer being saved?
1459 (progn
1460 (flymake-log 3 "starting syntax check as buffer was saved")
4dd68f44 1461 (flymake-start-syntax-check)))) ; no more mode 3. cannot start check if mode 3 (to temp copies) is active - (???)
4bcbcb9d 1462
2aa13ec4 1463(defun flymake-kill-buffer-hook ()
53ec26ed
RS
1464 (when flymake-timer
1465 (cancel-timer flymake-timer)
1466 (setq flymake-timer nil)))
4bcbcb9d 1467
5bd35902 1468;;;###autoload
2aa13ec4 1469(defun flymake-find-file-hook ()
9a686ad2
SM
1470 ;;+(when flymake-start-syntax-check-on-find-file
1471 ;;+ (flymake-log 3 "starting syntax check on file open")
4dd68f44 1472 ;;+ (flymake-start-syntax-check)
9a686ad2 1473 ;;+)
5323b4b0 1474 (when (and (not (local-variable-p 'flymake-mode (current-buffer)))
d57f6b5e 1475 (flymake-can-syntax-check-file buffer-file-name))
5323b4b0
RS
1476 (flymake-mode)
1477 (flymake-log 3 "automatically turned ON flymake mode")))
4bcbcb9d 1478
2aa13ec4 1479(defun flymake-get-first-err-line-no (err-info-list)
5323b4b0
RS
1480 "Return first line with error."
1481 (when err-info-list
1482 (flymake-er-get-line (car err-info-list))))
4bcbcb9d 1483
2aa13ec4 1484(defun flymake-get-last-err-line-no (err-info-list)
5323b4b0
RS
1485 "Return last line with error."
1486 (when err-info-list
1487 (flymake-er-get-line (nth (1- (length err-info-list)) err-info-list))))
4bcbcb9d 1488
2aa13ec4 1489(defun flymake-get-next-err-line-no (err-info-list line-no)
5323b4b0
RS
1490 "Return next line with error."
1491 (when err-info-list
1492 (let* ((count (length err-info-list))
1493 (idx 0))
1494 (while (and (< idx count) (>= line-no (flymake-er-get-line (nth idx err-info-list))))
1495 (setq idx (1+ idx)))
1496 (if (< idx count)
1497 (flymake-er-get-line (nth idx err-info-list))))))
4bcbcb9d 1498
2aa13ec4 1499(defun flymake-get-prev-err-line-no (err-info-list line-no)
173569aa 1500 "Return previous line with error."
5323b4b0
RS
1501 (when err-info-list
1502 (let* ((count (length err-info-list)))
1503 (while (and (> count 0) (<= line-no (flymake-er-get-line (nth (1- count) err-info-list))))
1504 (setq count (1- count)))
1505 (if (> count 0)
1506 (flymake-er-get-line (nth (1- count) err-info-list))))))
4bcbcb9d 1507
2aa13ec4 1508(defun flymake-skip-whitespace ()
5323b4b0
RS
1509 "Move forward until non-whitespace is reached."
1510 (while (looking-at "[ \t]")
1511 (forward-char)))
4bcbcb9d 1512
2aa13ec4 1513(defun flymake-goto-line (line-no)
9a686ad2 1514 "Go to line LINE-NO, then skip whitespace."
5f68c1b7
GM
1515 (goto-char (point-min))
1516 (forward-line (1- line-no))
5323b4b0 1517 (flymake-skip-whitespace))
4bcbcb9d 1518
2aa13ec4 1519(defun flymake-goto-next-error ()
9a686ad2 1520 "Go to next error in err ring."
5323b4b0 1521 (interactive)
53ec26ed 1522 (let ((line-no (flymake-get-next-err-line-no flymake-err-info (flymake-current-line-no))))
5323b4b0 1523 (when (not line-no)
53ec26ed 1524 (setq line-no (flymake-get-first-err-line-no flymake-err-info))
5323b4b0
RS
1525 (flymake-log 1 "passed end of file"))
1526 (if line-no
1527 (flymake-goto-line line-no)
1528 (flymake-log 1 "no errors in current buffer"))))
4bcbcb9d 1529
2aa13ec4 1530(defun flymake-goto-prev-error ()
173569aa 1531 "Go to previous error in err ring."
5323b4b0 1532 (interactive)
53ec26ed 1533 (let ((line-no (flymake-get-prev-err-line-no flymake-err-info (flymake-current-line-no))))
5323b4b0 1534 (when (not line-no)
53ec26ed 1535 (setq line-no (flymake-get-last-err-line-no flymake-err-info))
5323b4b0
RS
1536 (flymake-log 1 "passed beginning of file"))
1537 (if line-no
1538 (flymake-goto-line line-no)
1539 (flymake-log 1 "no errors in current buffer"))))
4bcbcb9d 1540
2aa13ec4 1541(defun flymake-patch-err-text (string)
5323b4b0
RS
1542 (if (string-match "^[\n\t :0-9]*\\(.*\\)$" string)
1543 (match-string 1 string)
1544 string))
4bcbcb9d
EZ
1545
1546;;;; general init-cleanup and helper routines
2aa13ec4 1547(defun flymake-create-temp-inplace (file-name prefix)
5323b4b0
RS
1548 (unless (stringp file-name)
1549 (error "Invalid file-name"))
1550 (or prefix
1551 (setq prefix "flymake"))
79e1997a
AJ
1552 (let* ((ext (file-name-extension file-name))
1553 (temp-name (file-truename
1554 (concat (file-name-sans-extension file-name)
1555 "_" prefix
1556 (and ext (concat "." ext))))))
5323b4b0
RS
1557 (flymake-log 3 "create-temp-inplace: file=%s temp=%s" file-name temp-name)
1558 temp-name))
4bcbcb9d 1559
e02f48d7 1560(defun flymake-create-temp-with-folder-structure (file-name _prefix)
5323b4b0
RS
1561 (unless (stringp file-name)
1562 (error "Invalid file-name"))
4bcbcb9d 1563
5323b4b0 1564 (let* ((dir (file-name-directory file-name))
6df19241
SM
1565 ;; Not sure what this slash-pos is all about, but I guess it's just
1566 ;; trying to remove the leading / of absolute file names.
5323b4b0 1567 (slash-pos (string-match "/" dir))
6df19241
SM
1568 (temp-dir (expand-file-name (substring dir (1+ slash-pos))
1569 (flymake-get-temp-dir))))
4bcbcb9d 1570
6df19241
SM
1571 (file-truename (expand-file-name (file-name-nondirectory file-name)
1572 temp-dir))))
4bcbcb9d 1573
2aa13ec4 1574(defun flymake-delete-temp-directory (dir-name)
9a686ad2 1575 "Attempt to delete temp dir created by `flymake-create-temp-with-folder-structure', do not fail on error."
5323b4b0 1576 (let* ((temp-dir (flymake-get-temp-dir))
587d108e 1577 (suffix (substring dir-name (1+ (length temp-dir)))))
5323b4b0
RS
1578
1579 (while (> (length suffix) 0)
6df19241 1580 (setq suffix (directory-file-name suffix))
9a686ad2 1581 ;;+(flymake-log 0 "suffix=%s" suffix)
6df19241
SM
1582 (flymake-safe-delete-directory
1583 (file-truename (expand-file-name suffix temp-dir)))
1584 (setq suffix (file-name-directory suffix)))))
4bcbcb9d 1585
5bcef417
SM
1586(defvar flymake-temp-source-file-name nil)
1587(make-variable-buffer-local 'flymake-temp-source-file-name)
1588
1589(defvar flymake-master-file-name nil)
1590(make-variable-buffer-local 'flymake-master-file-name)
1591
1592(defvar flymake-temp-master-file-name nil)
1593(make-variable-buffer-local 'flymake-temp-master-file-name)
1594
1595(defvar flymake-base-dir nil)
1596(make-variable-buffer-local 'flymake-base-dir)
1597
6df19241 1598(defun flymake-init-create-temp-buffer-copy (create-temp-f)
5323b4b0 1599 "Make a temporary copy of the current buffer, save its name in buffer data and return the name."
6df19241 1600 (let* ((source-file-name buffer-file-name)
5323b4b0 1601 (temp-source-file-name (funcall create-temp-f source-file-name "flymake")))
4bcbcb9d 1602
6df19241
SM
1603 (flymake-save-buffer-in-file temp-source-file-name)
1604 (setq flymake-temp-source-file-name temp-source-file-name)
5323b4b0 1605 temp-source-file-name))
4bcbcb9d 1606
c07fa030 1607(defun flymake-simple-cleanup ()
69df8d97 1608 "Do cleanup after `flymake-init-create-temp-buffer-copy'.
2aa13ec4 1609Delete temp file."
c07fa030
SM
1610 (flymake-safe-delete-file flymake-temp-source-file-name)
1611 (setq flymake-last-change-time nil))
4bcbcb9d 1612
c07fa030 1613(defun flymake-get-real-file-name (file-name-from-err-msg)
9a686ad2
SM
1614 "Translate file name from error message to \"real\" file name.
1615Return full-name. Names are real, not patched."
c07fa030
SM
1616 (let* ((real-name nil)
1617 (source-file-name buffer-file-name)
1618 (master-file-name flymake-master-file-name)
1619 (temp-source-file-name flymake-temp-source-file-name)
1620 (temp-master-file-name flymake-temp-master-file-name)
5bcef417 1621 (base-dirs
c07fa030 1622 (list flymake-base-dir
5bcef417
SM
1623 (file-name-directory source-file-name)
1624 (if master-file-name (file-name-directory master-file-name))))
c07fa030
SM
1625 (files (list (list source-file-name source-file-name)
1626 (list temp-source-file-name source-file-name)
1627 (list master-file-name master-file-name)
1628 (list temp-master-file-name master-file-name))))
5323b4b0
RS
1629
1630 (when (equal 0 (length file-name-from-err-msg))
1631 (setq file-name-from-err-msg source-file-name))
1632
1633 (setq real-name (flymake-get-full-patched-file-name file-name-from-err-msg base-dirs files))
9a686ad2 1634 ;; if real-name is nil, than file name from err msg is none of the files we've patched
5323b4b0
RS
1635 (if (not real-name)
1636 (setq real-name (flymake-get-full-nonpatched-file-name file-name-from-err-msg base-dirs)))
1637 (if (not real-name)
1638 (setq real-name file-name-from-err-msg))
1639 (setq real-name (flymake-fix-file-name real-name))
1640 (flymake-log 3 "get-real-file-name: file-name=%s real-name=%s" file-name-from-err-msg real-name)
1641 real-name))
4bcbcb9d 1642
2aa13ec4 1643(defun flymake-get-full-patched-file-name (file-name-from-err-msg base-dirs files)
5323b4b0
RS
1644 (let* ((base-dirs-count (length base-dirs))
1645 (file-count (length files))
1646 (real-name nil))
1647
1648 (while (and (not real-name) (> base-dirs-count 0))
1649 (setq file-count (length files))
1650 (while (and (not real-name) (> file-count 0))
1651 (let* ((this-dir (nth (1- base-dirs-count) base-dirs))
1652 (this-file (nth 0 (nth (1- file-count) files)))
1653 (this-real-name (nth 1 (nth (1- file-count) files))))
9a686ad2 1654 ;;+(flymake-log 0 "this-dir=%s this-file=%s this-real=%s msg-file=%s" this-dir this-file this-real-name file-name-from-err-msg)
5323b4b0 1655 (when (and this-dir this-file (flymake-same-files
b8471a02 1656 (expand-file-name file-name-from-err-msg this-dir)
5323b4b0
RS
1657 this-file))
1658 (setq real-name this-real-name)))
1659 (setq file-count (1- file-count)))
1660 (setq base-dirs-count (1- base-dirs-count)))
1661 real-name))
4bcbcb9d 1662
2aa13ec4 1663(defun flymake-get-full-nonpatched-file-name (file-name-from-err-msg base-dirs)
5323b4b0
RS
1664 (let* ((real-name nil))
1665 (if (file-name-absolute-p file-name-from-err-msg)
1666 (setq real-name file-name-from-err-msg)
1667 (let* ((base-dirs-count (length base-dirs)))
1668 (while (and (not real-name) (> base-dirs-count 0))
b8471a02
SM
1669 (let* ((full-name (expand-file-name file-name-from-err-msg
1670 (nth (1- base-dirs-count) base-dirs))))
5323b4b0
RS
1671 (if (file-exists-p full-name)
1672 (setq real-name full-name))
1673 (setq base-dirs-count (1- base-dirs-count))))))
1674 real-name))
4bcbcb9d 1675
6df19241 1676(defun flymake-init-find-buildfile-dir (source-file-name buildfile-name)
5323b4b0 1677 "Find buildfile, store its dir in buffer data and return its dir, if found."
5bcef417
SM
1678 (let* ((buildfile-dir
1679 (flymake-find-buildfile buildfile-name
5f73367d 1680 (file-name-directory source-file-name))))
5bcef417 1681 (if buildfile-dir
6df19241 1682 (setq flymake-base-dir buildfile-dir)
5bcef417 1683 (flymake-log 1 "no buildfile (%s) for %s" buildfile-name source-file-name)
6df19241
SM
1684 (flymake-report-fatal-status
1685 "NOMK" (format "No buildfile (%s) found for %s"
1686 buildfile-name source-file-name)))))
4bcbcb9d 1687
587d108e 1688(defun flymake-init-create-temp-source-and-master-buffer-copy (get-incl-dirs-f create-temp-f master-file-masks include-regexp)
84bb5a0c 1689 "Find master file (or buffer), create its copy along with a copy of the source file."
c07fa030 1690 (let* ((source-file-name buffer-file-name)
6df19241 1691 (temp-source-file-name (flymake-init-create-temp-buffer-copy create-temp-f))
5323b4b0
RS
1692 (master-and-temp-master (flymake-create-master-file
1693 source-file-name temp-source-file-name
1694 get-incl-dirs-f create-temp-f
587d108e 1695 master-file-masks include-regexp)))
5323b4b0
RS
1696
1697 (if (not master-and-temp-master)
1698 (progn
1699 (flymake-log 1 "cannot find master file for %s" source-file-name)
6df19241 1700 (flymake-report-status "!" "") ; NOMASTER
5bcef417 1701 nil)
6df19241
SM
1702 (setq flymake-master-file-name (nth 0 master-and-temp-master))
1703 (setq flymake-temp-master-file-name (nth 1 master-and-temp-master)))))
4bcbcb9d 1704
c07fa030
SM
1705(defun flymake-master-cleanup ()
1706 (flymake-simple-cleanup)
1707 (flymake-safe-delete-file flymake-temp-master-file-name))
4bcbcb9d
EZ
1708
1709;;;; make-specific init-cleanup routines
2aa13ec4 1710(defun flymake-get-syntax-check-program-args (source-file-name base-dir use-relative-base-dir use-relative-source get-cmd-line-f)
5323b4b0 1711 "Create a command line for syntax check using GET-CMD-LINE-F."
6fee12e6
SM
1712 (funcall get-cmd-line-f
1713 (if use-relative-source
1714 (file-relative-name source-file-name base-dir)
1715 source-file-name)
1716 (if use-relative-base-dir
1717 (file-relative-name base-dir
1718 (file-name-directory source-file-name))
1719 base-dir)))
4bcbcb9d 1720
2aa13ec4 1721(defun flymake-get-make-cmdline (source base-dir)
5323b4b0
RS
1722 (list "make"
1723 (list "-s"
1724 "-C"
1725 base-dir
1726 (concat "CHK_SOURCES=" source)
1727 "SYNTAX_CHECK_MODE=1"
1728 "check-syntax")))
4bcbcb9d 1729
2aa13ec4 1730(defun flymake-get-ant-cmdline (source base-dir)
5323b4b0
RS
1731 (list "ant"
1732 (list "-buildfile"
1733 (concat base-dir "/" "build.xml")
1734 (concat "-DCHK_SOURCES=" source)
1735 "check-syntax")))
4bcbcb9d 1736
6df19241 1737(defun flymake-simple-make-init-impl (create-temp-f use-relative-base-dir use-relative-source build-file-name get-cmdline-f)
5323b4b0 1738 "Create syntax check command line for a directly checked source file.
2aa13ec4 1739Use CREATE-TEMP-F for creating temp copy."
5323b4b0 1740 (let* ((args nil)
6df19241
SM
1741 (source-file-name buffer-file-name)
1742 (buildfile-dir (flymake-init-find-buildfile-dir source-file-name build-file-name)))
5323b4b0 1743 (if buildfile-dir
6df19241 1744 (let* ((temp-source-file-name (flymake-init-create-temp-buffer-copy create-temp-f)))
5323b4b0
RS
1745 (setq args (flymake-get-syntax-check-program-args temp-source-file-name buildfile-dir
1746 use-relative-base-dir use-relative-source
1747 get-cmdline-f))))
1748 args))
4bcbcb9d 1749
6df19241
SM
1750(defun flymake-simple-make-init ()
1751 (flymake-simple-make-init-impl 'flymake-create-temp-inplace t t "Makefile" 'flymake-get-make-cmdline))
4bcbcb9d 1752
587d108e 1753(defun flymake-master-make-init (get-incl-dirs-f master-file-masks include-regexp)
9a686ad2 1754 "Create make command line for a source file checked via master file compilation."
5323b4b0
RS
1755 (let* ((make-args nil)
1756 (temp-master-file-name (flymake-init-create-temp-source-and-master-buffer-copy
6df19241 1757 get-incl-dirs-f 'flymake-create-temp-inplace
587d108e 1758 master-file-masks include-regexp)))
5323b4b0 1759 (when temp-master-file-name
6df19241 1760 (let* ((buildfile-dir (flymake-init-find-buildfile-dir temp-master-file-name "Makefile")))
5323b4b0
RS
1761 (if buildfile-dir
1762 (setq make-args (flymake-get-syntax-check-program-args
1763 temp-master-file-name buildfile-dir nil nil 'flymake-get-make-cmdline)))))
1764 make-args))
4bcbcb9d 1765
2aa13ec4 1766(defun flymake-find-make-buildfile (source-dir)
5f73367d 1767 (flymake-find-buildfile "Makefile" source-dir))
4bcbcb9d
EZ
1768
1769;;;; .h/make specific
6df19241 1770(defun flymake-master-make-header-init ()
fd09a83f
CY
1771 (flymake-master-make-init
1772 'flymake-get-include-dirs
1773 '("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'")
1774 "[ \t]*#[ \t]*include[ \t]*\"\\([[:word:]0-9/\\_.]*%s\\)\""))
4bcbcb9d
EZ
1775
1776;;;; .java/make specific
6df19241
SM
1777(defun flymake-simple-make-java-init ()
1778 (flymake-simple-make-init-impl 'flymake-create-temp-with-folder-structure nil nil "Makefile" 'flymake-get-make-cmdline))
4bcbcb9d 1779
6df19241
SM
1780(defun flymake-simple-ant-java-init ()
1781 (flymake-simple-make-init-impl 'flymake-create-temp-with-folder-structure nil nil "build.xml" 'flymake-get-ant-cmdline))
4bcbcb9d 1782
c07fa030 1783(defun flymake-simple-java-cleanup ()
9a686ad2 1784 "Cleanup after `flymake-simple-make-java-init' -- delete temp file and dirs."
c07fa030
SM
1785 (flymake-safe-delete-file flymake-temp-source-file-name)
1786 (when flymake-temp-source-file-name
1787 (flymake-delete-temp-directory
1788 (file-name-directory flymake-temp-source-file-name))))
4bcbcb9d
EZ
1789
1790;;;; perl-specific init-cleanup routines
6df19241 1791(defun flymake-perl-init ()
4bd0a5d0 1792 (let* ((temp-file (flymake-init-create-temp-buffer-copy
6df19241 1793 'flymake-create-temp-inplace))
6fee12e6
SM
1794 (local-file (file-relative-name
1795 temp-file
1796 (file-name-directory buffer-file-name))))
5323b4b0 1797 (list "perl" (list "-wc " local-file))))
eabd11d4
MH
1798
1799;;;; php-specific init-cleanup routines
1800(defun flymake-php-init ()
1801 (let* ((temp-file (flymake-init-create-temp-buffer-copy
1802 'flymake-create-temp-inplace))
1803 (local-file (file-relative-name
1804 temp-file
1805 (file-name-directory buffer-file-name))))
1806 (list "php" (list "-f" local-file "-l"))))
4bcbcb9d
EZ
1807
1808;;;; tex-specific init-cleanup routines
2aa13ec4 1809(defun flymake-get-tex-args (file-name)
9a686ad2 1810 ;;(list "latex" (list "-c-style-errors" file-name))
5323b4b0 1811 (list "texify" (list "--pdf" "--tex-option=-c-style-errors" file-name)))
4bcbcb9d 1812
6df19241
SM
1813(defun flymake-simple-tex-init ()
1814 (flymake-get-tex-args (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)))
4bcbcb9d 1815
bd77c2ef
GM
1816;; Perhaps there should be a buffer-local variable flymake-master-file
1817;; that people can set to override this stuff. Could inherit from
1818;; the similar AUCTeX variable.
6df19241 1819(defun flymake-master-tex-init ()
5323b4b0 1820 (let* ((temp-master-file-name (flymake-init-create-temp-source-and-master-buffer-copy
6df19241
SM
1821 'flymake-get-include-dirs-dot 'flymake-create-temp-inplace
1822 '("\\.tex\\'")
bd77c2ef 1823 "[ \t]*\\in\\(?:put\\|clude\\)[ \t]*{\\(.*%s\\)}")))
5323b4b0
RS
1824 (when temp-master-file-name
1825 (flymake-get-tex-args temp-master-file-name))))
4bcbcb9d 1826
e02f48d7 1827(defun flymake-get-include-dirs-dot (_base-dir)
5323b4b0 1828 '("."))
4bcbcb9d
EZ
1829
1830;;;; xml-specific init-cleanup routines
6df19241
SM
1831(defun flymake-xml-init ()
1832 (list "xml" (list "val" (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace))))
2aa13ec4
RS
1833
1834(provide 'flymake)
4bcbcb9d
EZ
1835
1836;;; flymake.el ends here