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