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