1 ;;; flymake.el --- a universal on-the-fly syntax checker
3 ;; Copyright (C) 2003-2013 Free Software Foundation, Inc.
5 ;; Author: Pavel Kobyakov <pk_at_work@yahoo.com>
6 ;; Maintainer: Pavel Kobyakov <pk_at_work@yahoo.com>
8 ;; Keywords: c languages tools
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
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.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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)
33 ;; - Only uses "Makefile", not "makefile" or "GNUmakefile"
34 ;; (from http://bugs.debian.org/337339).
38 (eval-when-compile (require 'cl-lib
))
39 (if (featurep 'xemacs
) (require 'overlay
))
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
)
45 (defvar flymake-timer nil
46 "Timer for starting syntax check.")
47 (make-variable-buffer-local 'flymake-timer
)
49 (defvar flymake-last-change-time nil
50 "Time of last buffer change.")
51 (make-variable-buffer-local 'flymake-last-change-time
)
53 (defvar flymake-check-start-time nil
54 "Time at which syntax check was started.")
55 (make-variable-buffer-local 'flymake-check-start-time
)
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
)
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
)
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
)
69 ;;;; [[ cross-emacs compatibility routines
70 (defsubst flymake-makehash
(&optional test
)
71 "Create and return a new hash table using TEST to compare keys.
72 It uses the function `make-hash-table' to make a hash-table if
73 you use GNU Emacs, otherwise it uses `makehash'."
74 (if (fboundp 'make-hash-table
)
75 (if test
(make-hash-table :test test
) (make-hash-table))
79 (defalias 'flymake-float-time
80 (if (fboundp 'float-time
)
82 (if (featurep 'xemacs
)
84 (multiple-value-bind (s0 s1 s2
) (values-list (current-time))
85 (+ (* (float (ash 1 16)) s0
) (float s1
) (* 0.0000001 s2
)))))))
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
))))
93 (defalias 'flymake-split-string
94 (if (condition-case nil
(equal (split-string " bc " " " t
) '("bc"))
96 (lambda (str pattern
) (split-string str pattern t
))
98 "Split STR into a list of substrings bounded by PATTERN.
99 Zero-length substrings at the beginning and end of the list are omitted."
100 (let ((split (split-string str pattern
)))
101 (while (equal (car split
) "") (setq split
(cdr split
)))
102 (setq split
(nreverse split
))
103 (while (equal (car split
) "") (setq split
(cdr split
)))
106 (defalias 'flymake-get-temp-dir
107 (if (fboundp 'temp-directory
)
109 (lambda () temporary-file-directory
)))
111 (defun flymake-posn-at-point-as-event (&optional position window dx dy
)
112 "Return pixel position of top left corner of glyph at POSITION.
114 The position is relative to top left corner of WINDOW, as a
115 mouse-1 click event (identical to the event that would be
116 triggered by clicking mouse button 1 at the top left corner of
119 POSITION and WINDOW default to the position of point in the
122 DX 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))
128 (let* ((pos (posn-at-point position window
))
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
)))
138 (defun flymake-popup-menu (menu-data)
139 "Pop up the flymake menu at point, using the data MENU-DATA.
140 POS is a list of the form ((X Y) WINDOW), where X and Y are
141 pixels positions from the top left corner of WINDOW's frame.
142 MENU-DATA is a list of error and warning messages returned by
143 `flymake-make-err-menu-data'."
144 (if (featurep 'xemacs
)
145 (let* ((pos (flymake-get-point-pixel-pos))
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
))
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
))
154 (flymake-posn-at-point-as-event)
155 (list (flymake-get-point-pixel-pos) (selected-window)))
156 (flymake-make-emacs-menu menu-data
))))
158 (defun flymake-make-emacs-menu (menu-data)
159 "Return a menu specifier using MENU-DATA.
160 MENU-DATA is a list of error and warning messages returned by
161 `flymake-make-err-menu-data'.
162 See `x-popup-menu' for the menu specifier format."
163 (let* ((menu-title (nth 0 menu-data
))
164 (menu-items (nth 1 menu-data
))
165 (menu-commands (mapcar (lambda (foo)
166 (cons (nth 0 foo
) (nth 1 foo
)))
168 (list menu-title
(cons "" menu-commands
))))
170 (if (featurep 'xemacs
) (progn
172 (defun flymake-nop ()
176 (defun flymake-make-xemacs-menu (menu-data)
177 "Return a menu specifier using MENU-DATA."
178 (let* ((menu-title (nth 0 menu-data
))
179 (menu-items (nth 1 menu-data
))
181 (setq menu-commands
(mapcar (lambda (foo)
182 (vector (nth 0 foo
) (or (nth 1 foo
) '(flymake-nop)) t
))
184 (cons menu-title menu-commands
)))
188 (unless (eval-when-compile (fboundp 'posn-at-point
))
190 (defun flymake-current-row ()
191 "Return current row number in current frame."
192 (if (fboundp 'window-edges
)
193 (+ (car (cdr (window-edges))) (count-lines (window-start) (point)))
194 (count-lines (window-start) (point))))
196 (defun flymake-selected-frame ()
197 "Return the frame that is now selected."
198 (if (fboundp 'window-edges
)
202 (defun flymake-get-point-pixel-pos ()
203 "Return point position in pixels: (x, y)."
204 (let ((mouse-pos (mouse-position))
207 (if (car (cdr mouse-pos
))
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
)))))
215 (flymake-log 3 "mouse pos is %s" ret
)
218 ) ;; End of (unless (fboundp 'posn-at-point)
222 (defcustom flymake-log-level -
1
223 "Logging level, only messages with level lower or equal will be logged.
224 -1 = NONE, 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG"
229 ;; (defcustom flymake-log-file-name "~/flymake.log"
230 ;; "Where to put the flymake log if logging is enabled.
232 ;; See `flymake-log-level' if you want to control what is logged."
236 (defun flymake-log (level text
&rest args
)
237 "Log a message at level LEVEL.
238 If LEVEL is higher than `flymake-log-level', the message is
239 ignored. Otherwise, it is printed using `message'.
240 TEXT is a format control string, and the remaining arguments ARGS
241 are the string substitutions (see the function `format')."
242 (if (<= level flymake-log-level
)
243 (let* ((msg (apply 'format text args
)))
248 ;; (flymake-save-buffer-in-file "~/flymake.log") ; make log file name customizable
252 (defun flymake-ins-after (list pos val
)
253 "Insert VAL into LIST after position POS.
254 POS counts from zero."
255 (let ((tmp (copy-sequence list
)))
256 (setcdr (nthcdr pos tmp
) (cons val
(nthcdr (1+ pos
) tmp
)))
259 (defun flymake-set-at (list pos val
)
260 "Set VAL at position POS in LIST.
261 POS counts from zero."
262 (let ((tmp (copy-sequence list
)))
263 (setcar (nthcdr pos tmp
) val
)
266 (defvar flymake-processes nil
267 "List of currently active flymake processes.")
269 (defvar flymake-output-residual nil
)
270 (make-variable-buffer-local 'flymake-output-residual
)
272 (defgroup flymake nil
273 "Universal on-the-fly syntax checker."
277 (defcustom flymake-xml-program
278 (if (executable-find "xmlstarlet") "xmlstarlet" "xml")
279 "Program to use for XML validation."
284 (defcustom flymake-allowed-file-name-masks
285 '(("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'" flymake-simple-make-init
)
286 ("\\.xml\\'" flymake-xml-init
)
287 ("\\.html?\\'" flymake-xml-init
)
288 ("\\.cs\\'" flymake-simple-make-init
)
289 ("\\.p[ml]\\'" flymake-perl-init
)
290 ("\\.php[345]?\\'" flymake-php-init
)
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
)
294 ("\\.tex\\'" flymake-simple-tex-init
)
295 ("\\.idl\\'" flymake-simple-make-init
)
298 ;; ("\\.h\\'" 2 ("\\.cpp\\'" "\\.c\\'")
299 ;; ("[ \t]*#[ \t]*include[ \t]*\"\\([\w0-9/\\_\.]*[/\\]*\\)\\(%s\\)\"" 1 2))
302 ;; ("[0-9]+\\.tex\\'" 2 ("\\.tex\\'")
303 ;; ("[ \t]*\\input[ \t]*{\\(.*\\)\\(%s\\)}" 1 2 ))
306 "Files syntax checking is allowed for.
307 This is an alist with elements of the form:
308 REGEXP INIT [CLEANUP [NAME]]
309 REGEXP is a regular expression that matches a file name.
310 INIT is the init function to use.
311 CLEANUP is the cleanup function to use, default `flymake-simple-cleanup'.
312 NAME is the file name function to use, default `flymake-get-real-file-name'."
314 :type
'(alist :key-type
(regexp :tag
"File regexp")
316 (list :tag
"Handler functions"
317 (function :tag
"Init function")
318 (choice :tag
"Cleanup function"
319 (const :tag
"flymake-simple-cleanup" nil
)
321 (choice :tag
"Name function"
322 (const :tag
"flymake-get-real-file-name" nil
)
325 (defun flymake-get-file-name-mode-and-masks (file-name)
326 "Return the corresponding entry from `flymake-allowed-file-name-masks'."
327 (unless (stringp file-name
)
328 (error "Invalid file-name"))
329 (let ((fnm flymake-allowed-file-name-masks
)
330 (mode-and-masks nil
))
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
)))
335 (flymake-log 3 "file %s, init=%s" file-name
(car mode-and-masks
))
338 (defun flymake-can-syntax-check-file (file-name)
339 "Determine whether we can syntax check FILE-NAME.
340 Return nil if we cannot, non-nil if we can."
341 (if (flymake-get-init-function file-name
) t nil
))
343 (defun flymake-get-init-function (file-name)
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
))))
346 ;;(flymake-log 0 "calling %s" init-f)
347 ;;(funcall init-f (current-buffer))
350 (defun flymake-get-cleanup-function (file-name)
351 "Return cleanup function to be used for the file."
352 (or (nth 1 (flymake-get-file-name-mode-and-masks file-name
))
353 'flymake-simple-cleanup
))
355 (defun flymake-get-real-file-name-function (file-name)
356 (or (nth 4 (flymake-get-file-name-mode-and-masks file-name
))
357 'flymake-get-real-file-name
))
359 (defvar flymake-find-buildfile-cache
(flymake-makehash 'equal
))
361 (defun flymake-get-buildfile-from-cache (dir-name)
362 "Look up DIR-NAME in cache and return its associated value.
363 If DIR-NAME is not found, return nil."
364 (gethash dir-name flymake-find-buildfile-cache
))
366 (defun flymake-add-buildfile-to-cache (dir-name buildfile
)
367 "Associate DIR-NAME with BUILDFILE in the buildfile cache."
368 (puthash dir-name buildfile flymake-find-buildfile-cache
))
370 (defun flymake-clear-buildfile-cache ()
371 "Clear the buildfile cache."
372 (clrhash flymake-find-buildfile-cache
))
374 (defun flymake-find-buildfile (buildfile-name source-dir-name
)
375 "Find buildfile starting from current directory.
376 Buildfile includes Makefile, build.xml etc.
377 Return its file name if found, or nil if not found."
378 (or (flymake-get-buildfile-from-cache source-dir-name
)
379 (let* ((file (locate-dominating-file source-dir-name buildfile-name
)))
382 (flymake-log 3 "found buildfile at %s" file
)
383 (flymake-add-buildfile-to-cache source-dir-name file
)
386 (flymake-log 3 "buildfile for %s not found" source-dir-name
)
389 (defun flymake-fix-file-name (name)
390 "Replace all occurrences of '\' with '/'."
392 (setq name
(expand-file-name name
))
393 (setq name
(abbreviate-file-name name
))
394 (setq name
(directory-file-name name
))
397 (defun flymake-same-files (file-name-one file-name-two
)
398 "Check if FILE-NAME-ONE and FILE-NAME-TWO point to same file.
399 Return t if so, nil if not."
400 (equal (flymake-fix-file-name file-name-one
)
401 (flymake-fix-file-name file-name-two
)))
403 (defcustom flymake-master-file-dirs
'("." "./src" "./UnitTest")
404 "Dirs where to look for master files."
406 :type
'(repeat (string)))
408 (defcustom flymake-master-file-count-limit
32
409 "Max number of master files to check."
413 ;; This is bound dynamically to pass a parameter to a sort predicate below
414 (defvar flymake-included-file-name
)
416 (defun flymake-find-possible-master-files (file-name master-file-dirs masks
)
417 "Find (by name and location) all possible master files.
419 Name is specified by FILE-NAME and location is specified by
420 MASTER-FILE-DIRS. Master files include .cpp and .c for .h.
421 Files are searched for starting from the .h directory and max
422 max-level parent dirs. File contents are not checked."
423 (let* ((dirs master-file-dirs
)
427 (while (and (not done
) dirs
)
428 (let* ((dir (expand-file-name (car dirs
) (file-name-directory file-name
)))
430 (while (and (file-exists-p dir
) (not done
) masks
)
431 (let* ((mask (car masks
))
432 (dir-files (directory-files dir t mask
)))
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
))
439 (when (>= (length files
) flymake-master-file-count-limit
)
440 (flymake-log 3 "master file count limit (%d) reached" flymake-master-file-count-limit
)
442 (setq dir-files
(cdr dir-files
))))
443 (setq masks
(cdr masks
))))
444 (setq dirs
(cdr dirs
)))
446 (let ((flymake-included-file-name (file-name-nondirectory file-name
)))
447 (setq files
(sort files
'flymake-master-file-compare
))))
448 (flymake-log 3 "found %d possible master file(s)" (length files
))
451 (defun flymake-master-file-compare (file-one file-two
)
452 "Compare two files specified by FILE-ONE and FILE-TWO.
453 This function is used in sort to move most possible file names
454 to the beginning of the list (File.h -> File.cpp moved to top)."
455 (and (equal (file-name-sans-extension flymake-included-file-name
)
456 (file-name-base file-one
))
457 (not (equal file-one file-two
))))
459 (defcustom flymake-check-file-limit
8192
460 "Maximum number of chars to look at when checking possible master file.
461 Nil means search the entire file."
463 :type
'(choice (const :tag
"No limit" nil
)
464 (integer :tag
"Characters")))
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
471 "Check if MASTER-FILE-NAME is a master file for SOURCE-FILE-NAME.
472 If yes, patch a copy of MASTER-FILE-NAME to include PATCHED-SOURCE-FILE-NAME
473 instead of SOURCE-FILE-NAME.
475 For example, foo.cpp is a master file if it includes foo.h.
477 Whether a buffer for MATER-FILE-NAME exists, use it as a source
478 instead of reading master file from disk."
479 (let* ((source-file-nondir (file-name-nondirectory source-file-name
))
480 (source-file-extension (file-name-extension source-file-nondir
))
481 (source-file-nonext (file-name-sans-extension source-file-nondir
))
484 (search-limit flymake-check-file-limit
))
486 (format regexp
; "[ \t]*#[ \t]*include[ \t]*\"\\(.*%s\\)\""
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
))))
496 (with-current-buffer master-file-temp-buffer
497 (if (or (not search-limit
)
498 (> search-limit
(point-max)))
499 (setq search-limit
(point-max)))
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)))
508 (flymake-log 3 "found possible match for %s" source-file-nondir
)
509 (setq inc-name
(match-string 1))
510 (and (> (length source-file-extension
) 1)
511 (string-equal source-file-extension
"tex")
512 (not (string-match (format "\\.%s\\'" source-file-extension
)
514 (setq inc-name
(concat inc-name
"." source-file-extension
)))
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
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
528 (file-name-nondirectory patched-source-file-name
))))
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
))
535 ;;+(flymake-log 3 "check-patch master file %s: %s" master-file-name found)
537 (flymake-log 2 "found master file %s" master-file-name
))
540 (defun flymake-replace-region (beg end rep
)
541 "Replace text in BUFFER in region (BEG END) with REP."
544 ;; Insert before deleting, so as to better preserve markers's positions.
546 (delete-region beg end
)))
548 (defun flymake-read-file-to-temp-buffer (file-name)
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
))))))
551 (with-current-buffer temp-buffer
552 (insert-file-contents file-name
))
555 (defun flymake-copy-buffer-to-temp-buffer (buffer)
556 "Copy contents of BUFFER into newly created temp buffer."
558 (get-buffer-create (generate-new-buffer-name
559 (concat "flymake:" (buffer-name buffer
))))
560 (insert-buffer-substring buffer
)
563 (defun flymake-check-include (source-file-name inc-name include-dirs
)
564 "Check if SOURCE-FILE-NAME can be found in include path.
565 Return 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
571 (concat (file-name-directory source-file-name
)
572 "/" (car include-dirs
)
574 (setq include-dirs
(cdr include-dirs
)))
577 (defun flymake-find-buffer-for-file (file-name)
578 "Check if there exists a buffer visiting FILE-NAME.
579 Return t if so, nil if not."
580 (let ((buffer-name (get-file-buffer file-name
)))
582 (get-buffer buffer-name
))))
584 (defun flymake-create-master-file (source-file-name patched-source-file-name get-incl-dirs-f create-temp-f masks include-regexp
)
585 "Save SOURCE-FILE-NAME with a different name.
586 Find master file, patch and save it."
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
))
591 (master-file-name nil
)
592 (patched-master-file-name nil
)
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
)))
602 (flymake-check-patch-master-file-buffer
605 patched-master-file-name
607 patched-source-file-name
608 (funcall get-incl-dirs-f
(file-name-directory master-file-name
))
612 (list master-file-name patched-master-file-name
)
614 (flymake-log 3 "none of %d master file(s) checked includes %s" master-file-count
615 (file-name-nondirectory source-file-name
))
618 (defun flymake-save-buffer-in-file (file-name)
619 "Save the entire buffer contents into file FILE-NAME.
620 Create parent directories as needed."
621 (make-directory (file-name-directory file-name
) 1)
622 (write-region nil nil file-name nil
566)
623 (flymake-log 3 "saved buffer %s in file %s" (buffer-name) file-name
))
625 (defun flymake-save-string-to-file (file-name data
)
626 "Save string DATA to file FILE-NAME."
627 (write-region data nil file-name nil
566))
629 (defun flymake-read-file-to-string (file-name)
630 "Read contents of file FILE-NAME and return as a string."
632 (insert-file-contents file-name
)
633 (buffer-substring (point-min) (point-max))))
635 (defun flymake-process-filter (process output
)
636 "Parse OUTPUT and highlight error lines.
637 It's flymake process filter."
638 (let ((source-buffer (process-buffer process
)))
640 (flymake-log 3 "received %d byte(s) of output from process %d"
641 (length output
) (process-id process
))
642 (when (buffer-live-p source-buffer
)
643 (with-current-buffer source-buffer
644 (flymake-parse-output-and-residual output
)))))
646 (defun flymake-process-sentinel (process _event
)
647 "Sentinel for syntax check buffers."
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
))))
654 (flymake-log 2 "process %d exited with code %d"
655 (process-id process
) exit-status
)
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
)))
663 (delete-process process
)
664 (setq flymake-processes
(delq process flymake-processes
))
666 (when (buffer-live-p source-buffer
)
667 (with-current-buffer source-buffer
669 (flymake-parse-residual)
670 (flymake-post-syntax-check exit-status command
)
671 (setq flymake-is-running nil
))))
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
))))))))
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
)
687 (let (err-count warn-count
)
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
692 (- (flymake-float-time) flymake-check-start-time
))
693 (setq flymake-check-start-time nil
)
695 (if (and (equal 0 err-count
) (equal 0 warn-count
))
696 (if (equal 0 exit-status
)
697 (flymake-report-status "" "") ; PASSED
698 (if (not flymake-check-was-interrupted
)
699 (flymake-report-fatal-status "CFGERR"
700 (format "Configuration error has occurred while running %s" command
))
701 (flymake-report-status nil
""))) ; "STOPPED"
702 (flymake-report-status (format "%d/%d" err-count warn-count
) ""))))
704 (defun flymake-parse-output-and-residual (output)
705 "Split OUTPUT into lines, merge in residual if necessary."
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
))))
716 (defun flymake-parse-residual ()
717 "Parse residual if it's non empty."
718 (when flymake-output-residual
719 (setq flymake-new-err-info
720 (flymake-parse-err-lines
722 (list flymake-output-residual
)))
723 (setq flymake-output-residual nil
)))
725 (defun flymake-er-make-er (line-no line-err-info-list
)
726 (list line-no line-err-info-list
))
728 (defun flymake-er-get-line (err-info)
731 (defun flymake-er-get-line-err-info-list (err-info)
734 (cl-defstruct (flymake-ler
736 (:constructor flymake-ler-make-ler
(file line type text
&optional full-file
)))
737 file line type text full-file
)
739 (defun flymake-ler-set-file (line-err-info file
)
740 (flymake-ler-make-ler file
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
)))
746 (defun flymake-ler-set-full-file (line-err-info full-file
)
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
)
753 (defun flymake-ler-set-line (line-err-info line
)
754 (flymake-ler-make-ler (flymake-ler-file line-err-info
)
756 (flymake-ler-type line-err-info
)
757 (flymake-ler-text line-err-info
)
758 (flymake-ler-full-file line-err-info
)))
760 (defun flymake-get-line-err-count (line-err-info-list type
)
761 "Return number of errors of specified TYPE.
762 Value of TYPE is either \"e\" or \"w\"."
764 (count (length line-err-info-list
))
768 (when (equal type
(flymake-ler-type (nth idx line-err-info-list
)))
769 (setq err-count
(1+ err-count
)))
773 (defun flymake-get-err-count (err-info-list type
)
774 "Return number of errors of specified TYPE for ERR-INFO-LIST."
776 (count (length err-info-list
))
779 (setq err-count
(+ err-count
(flymake-get-line-err-count (nth 1 (nth idx err-info-list
)) type
)))
783 (defun flymake-fix-line-numbers (err-info-list min-line max-line
)
784 "Replace line numbers with fixed value.
785 If line-numbers is less than MIN-LINE, set line numbers to MIN-LINE.
786 If line numbers is greater than MAX-LINE, set line numbers to MAX-LINE.
787 The reason for this fix is because some compilers might report
788 line number outside the file being compiled."
789 (let* ((count (length err-info-list
))
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
))))
803 (defun flymake-highlight-err-lines (err-info-list)
804 "Highlight error lines in BUFFER using info from ERR-INFO-LIST."
806 (dolist (err err-info-list
)
807 (flymake-highlight-line (car err
) (nth 1 err
)))))
809 (defun flymake-overlay-p (ov)
810 "Determine whether overlay OV was created by flymake."
811 (and (overlayp ov
) (overlay-get ov
'flymake-overlay
)))
813 (defcustom flymake-error-bitmap
'(exclamation-mark error
)
814 "Bitmap (a symbol) used in the fringe for indicating errors.
815 The value may also be a list of two elements where the second
816 element specifies the face for the bitmap. For possible bitmap
817 symbols, see `fringe-bitmaps'. See also `flymake-warning-bitmap'.
819 The option `flymake-fringe-indicator-position' controls how and where
823 :type
'(choice (symbol :tag
"Bitmap")
824 (list :tag
"Bitmap and face"
825 (symbol :tag
"Bitmap")
826 (face :tag
"Face"))))
828 (defcustom flymake-warning-bitmap
'question-mark
829 "Bitmap (a symbol) used in the fringe for indicating warnings.
830 The value may also be a list of two elements where the second
831 element specifies the face for the bitmap. For possible bitmap
832 symbols, see `fringe-bitmaps'. See also `flymake-error-bitmap'.
834 The option `flymake-fringe-indicator-position' controls how and where
838 :type
'(choice (symbol :tag
"Bitmap")
839 (list :tag
"Bitmap and face"
840 (symbol :tag
"Bitmap")
841 (face :tag
"Face"))))
843 (defcustom flymake-fringe-indicator-position
'left-fringe
844 "The position to put flymake fringe indicator.
845 The value can be nil (do not use indicators), `left-fringe' or `right-fringe'.
846 See `flymake-error-bitmap' and `flymake-warning-bitmap'."
849 :type
'(choice (const left-fringe
)
851 (const :tag
"No fringe indicators" nil
)))
853 (defun flymake-make-overlay (beg end tooltip-text face bitmap mouse-face
)
854 "Allocate a flymake overlay in range BEG and END."
855 (when (not (flymake-region-has-flymake-overlays beg end
))
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
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)
868 (overlay-put ov
'evaporate t
)
869 (overlay-put ov
'before-string fringe
)
870 ;;+(flymake-log 3 "created overlay %s" ov)
872 (flymake-log 3 "created an overlay at (%d-%d)" beg end
)))
874 (defun flymake-delete-own-overlays ()
875 "Delete all flymake overlays in BUFFER."
876 (dolist (ol (overlays-in (point-min) (point-max)))
877 (when (flymake-overlay-p ol
)
879 ;;+(flymake-log 3 "deleted overlay %s" ol)
882 (defun flymake-region-has-flymake-overlays (beg end
)
883 "Check if region specified by BEG and END has overlay.
884 Return t if it has at least one flymake overlay, nil if no overlay."
885 (let ((ov (overlays-in beg end
))
886 (has-flymake-overlays nil
))
888 (when (flymake-overlay-p (car ov
))
889 (setq has-flymake-overlays t
))
891 has-flymake-overlays
))
893 (defface flymake-errline
894 '((((supports :underline
(:style wave
)))
895 :underline
(:style wave
:color
"Red1"))
898 "Face used for marking error lines."
902 (defface flymake-warnline
903 '((((supports :underline
(:style wave
)))
904 :underline
(:style wave
:color
"DarkOrange"))
907 "Face used for marking warning lines."
911 (defun flymake-highlight-line (line-no line-err-info-list
)
912 "Highlight line LINE-NO in current buffer.
913 Perhaps use text from LINE-ERR-INFO-LIST to enhance highlighting."
914 (goto-char (point-min))
915 (forward-line (1- line-no
))
916 (let* ((line-beg (point-at-bol))
917 (line-end (point-at-eol))
920 (tooltip-text (flymake-ler-text (nth 0 line-err-info-list
)))
925 (while (looking-at "[ \t]")
931 (while (and (looking-at "[ \t\r\n]") (> (point) 1))
934 (setq end
(1+ (point)))
945 (if (> (flymake-get-line-err-count line-err-info-list
"e") 0)
946 (setq face
'flymake-errline
947 bitmap flymake-error-bitmap
)
948 (setq face
'flymake-warnline
949 bitmap flymake-warning-bitmap
))
951 (flymake-make-overlay beg end tooltip-text face bitmap nil
)))
953 (defun flymake-parse-err-lines (err-info-list lines
)
954 "Parse err LINES, store info in ERR-INFO-LIST."
955 (let* ((count (length lines
))
959 (source-file-name buffer-file-name
)
960 (get-real-file-name-f (flymake-get-real-file-name-function source-file-name
)))
963 (setq line-err-info
(flymake-parse-line (nth idx lines
)))
965 (setq real-file-name
(funcall get-real-file-name-f
966 (flymake-ler-file line-err-info
)))
967 (setq line-err-info
(flymake-ler-set-full-file line-err-info real-file-name
))
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
))))
972 (flymake-log 3 "parsed '%s', %s line-err-info" (nth idx lines
) (if line-err-info
"got" "no"))
976 (defun flymake-split-output (output)
977 "Split OUTPUT into lines.
978 Return last one as residual if it does not end with newline char.
979 Returns ((LINES) RESIDUAL)."
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
))))))
985 (setq residual
(car (last lines
)))
986 (setq lines
(butlast lines
)))
987 (list lines residual
))))
989 (defun flymake-reformat-err-line-patterns-from-compile-el (original-list)
990 "Grab error line patterns from ORIGINAL-LIST in compile.el format.
991 Convert it to flymake internal format."
992 (let* ((converted-list '()))
993 (dolist (item original-list
)
994 (setq item
(cdr item
))
995 (let ((regexp (nth 0 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
)))
1003 (when (not (functionp line
))
1004 (setq converted-list
(cons (list regexp file line col
) converted-list
)))))
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
1012 ;; MS Visual C++ 6.0
1013 ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \: \\(\\(error\\|warning\\|fatal error\\) \\(C[0-9]+\\):[ \t\n]*\\(.+\\)\\)"
1016 ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)\:\\([0-9]+\\)\:[0-9]+\:[0-9]+\:[0-9]+\: \\(\\(Error\\|Warning\\|Caution\\|Semantic Error\\):[ \t\n]*\\(.+\\)\\)"
1019 ("midl[ ]*:[ ]*\\(command line error .*\\)"
1022 ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\),[0-9]+)\: \\(\\(error\\|warning\\|fatal error\\) \\(CS[0-9]+\\):[ \t\n]*\\(.+\\)\\)"
1025 ("\\(.*\\) at \\([^ \n]+\\) line \\([0-9]+\\)[,.\n]" 2 3 nil
1)
1027 ("\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)" 2 3 nil
1)
1028 ;; LaTeX warnings (fileless) ("\\(LaTeX \\(Warning\\|Error\\): .*\\) on input line \\([0-9]+\\)" 20 3 nil 1)
1029 ;; ant/javac. Note this also matches gcc warnings!
1030 (" *\\(\\[javac\\] *\\)?\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)\:\\([0-9]+\\)\\(?:\:[0-9]+\\)?\:[ \t\n]*\\(.+\\)"
1032 ;; compilation-error-regexp-alist)
1033 (flymake-reformat-err-line-patterns-from-compile-el compilation-error-regexp-alist-alist
))
1034 "Patterns for matching error/warning lines. Each pattern has the form
1035 \(REGEXP FILE-IDX LINE-IDX COL-IDX ERR-TEXT-IDX).
1036 Use `flymake-reformat-err-line-patterns-from-compile-el' to add patterns
1039 ;;(defcustom flymake-err-line-patterns
1041 ;; ; MS Visual C++ 6.0
1042 ;; ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \: \\(\\(error\\|warning\\|fatal error\\) \\(C[0-9]+\\):[ \t\n]*\\(.+\\)\\)"
1045 ;; ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)\:\\([0-9]+\\)\:[0-9]+\:[0-9]+\:[0-9]+\: \\(\\(Error\\|Warning\\|Caution\\):[ \t\n]*\\(.+\\)\\)"
1047 ;; "patterns for matching error/warning lines, (regexp file-idx line-idx err-text-idx)"
1049 ;; :type '(repeat (string number number number))
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.
1055 Takes a single argument, the error's text and should return non-nil
1057 Instead of a function, it can also be a regular expression.")
1059 (defun flymake-parse-line (line)
1060 "Parse LINE to see if it is an error or warning.
1061 Return its components if so, nil otherwise."
1062 (let ((raw-file-name nil
)
1066 (patterns flymake-err-line-patterns
)
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
))))
1073 (setq raw-file-name
(if file-idx
(match-string file-idx line
) nil
))
1074 (setq line-no
(if line-idx
(string-to-number
1075 (match-string line-idx line
)) 0))
1076 (setq err-text
(if (> (length (car patterns
)) 4)
1077 (match-string (nth 4 (car patterns
)) line
)
1078 (flymake-patch-err-text
1079 (substring line
(match-end 0)))))
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")))
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
)
1091 (setq patterns
(cdr patterns
)))
1093 (flymake-ler-make-ler raw-file-name line-no err-type err-text
)
1096 (defun flymake-find-err-info (err-info-list line-no
)
1097 "Find (line-err-info-list pos) for specified LINE-NO."
1099 (let* ((line-err-info-list nil
)
1101 (count (length err-info-list
)))
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
))
1110 (defun flymake-line-err-info-is-less-or-equal (line-one line-two
)
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
)))))))
1118 (defun flymake-add-line-err-info (line-err-info-list line-err-info
)
1119 "Update LINE-ERR-INFO-LIST with the error LINE-ERR-INFO.
1120 For the format of LINE-ERR-INFO, see `flymake-ler-make-ler'.
1121 The new element is inserted in the proper position, according to
1122 the predicate `flymake-line-err-info-is-less-or-equal'.
1123 The updated value of LINE-ERR-INFO-LIST is returned."
1124 (if (not line-err-info-list
)
1125 (list line-err-info
)
1126 (let* ((count (length line-err-info-list
))
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
)))
1134 (defun flymake-add-err-info (err-info-list line-err-info
)
1135 "Update ERR-INFO-LIST with the error LINE-ERR-INFO, preserving sort order.
1136 Returns the updated value of ERR-INFO-LIST.
1137 For the format of ERR-INFO-LIST, see `flymake-err-info'.
1138 For the format of LINE-ERR-INFO, see `flymake-ler-make-ler'."
1139 (let* ((line-no (if (flymake-ler-file line-err-info
) 1 (flymake-ler-line line-err-info
)))
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
)
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
))
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
))))
1156 (defun flymake-get-project-include-dirs-imp (basedir)
1157 "Include dirs for the project current file belongs to."
1158 (if (flymake-get-project-include-dirs-from-cache basedir
)
1160 (flymake-get-project-include-dirs-from-cache basedir
))
1162 (let* ((command-line (concat "make -C "
1163 (shell-quote-argument basedir
)
1164 " DUMPVARS=INCLUDE_DIRS dumpvars"))
1165 (output (shell-command-to-string command-line
))
1166 (lines (flymake-split-string output
"\n"))
1167 (count (length lines
))
1170 (while (and (< idx count
) (not (string-match "^INCLUDE_DIRS=.*" (nth idx lines
))))
1171 (setq idx
(1+ idx
)))
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
)))
1177 (push (flymake-replace-regexp-in-string "\"" "" (nth (1- inc-count
) inc-lines
)) inc-dirs
))
1178 (setq inc-count
(1- inc-count
)))))
1179 (flymake-add-project-include-dirs-to-cache basedir inc-dirs
)
1182 (defcustom flymake-get-project-include-dirs-function
'flymake-get-project-include-dirs-imp
1183 "Function used to get project include dirs, one parameter: basedir name."
1187 (defun flymake-get-project-include-dirs (basedir)
1188 (funcall flymake-get-project-include-dirs-function basedir
))
1190 (defun flymake-get-system-include-dirs ()
1191 "System include dirs - from the 'INCLUDE' env setting."
1192 (let* ((includes (getenv "INCLUDE")))
1193 (if includes
(flymake-split-string includes path-separator
) nil
)))
1195 (defvar flymake-project-include-dirs-cache
(flymake-makehash 'equal
))
1197 (defun flymake-get-project-include-dirs-from-cache (base-dir)
1198 (gethash base-dir flymake-project-include-dirs-cache
))
1200 (defun flymake-add-project-include-dirs-to-cache (base-dir include-dirs
)
1201 (puthash base-dir include-dirs flymake-project-include-dirs-cache
))
1203 (defun flymake-clear-project-include-dirs-cache ()
1204 (clrhash flymake-project-include-dirs-cache
))
1206 (defun flymake-get-include-dirs (base-dir)
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))))
1211 ;; (defun flymake-restore-formatting ()
1212 ;; "Remove any formatting made by flymake."
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))
1222 (defun flymake-safe-delete-file (file-name)
1223 (when (and file-name
(file-exists-p file-name
))
1224 (delete-file file-name
)
1225 (flymake-log 1 "deleted file %s" file-name
)))
1227 (defun flymake-safe-delete-directory (dir-name)
1230 (delete-directory dir-name
)
1231 (flymake-log 1 "deleted dir %s" dir-name
))
1233 (flymake-log 1 "Failed to delete dir %s, error ignored" dir-name
))))
1235 (defcustom flymake-compilation-prevents-syntax-check t
1236 "If non-nil, don't start syntax check if compilation is running."
1240 (defun flymake-start-syntax-check ()
1241 "Start syntax checking for current buffer."
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)
1251 (setq flymake-check-was-interrupted nil
)
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
))
1256 (cmd-and-args (funcall init-f
))
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
)
1262 (flymake-log 0 "init function %s for %s failed, cleaning up" init-f source-file-name
)
1263 (funcall cleanup-f
))
1265 (setq flymake-last-change-time nil
)
1266 (flymake-start-syntax-check-process cmd args dir
)))))))
1268 (defun flymake-start-syntax-check-process (cmd args dir
)
1269 "Start syntax check process."
1272 (let ((default-directory (or dir default-directory
)))
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
)
1281 (setq flymake-is-running t
)
1282 (setq flymake-last-change-time nil
)
1283 (setq flymake-check-start-time
(flymake-float-time))
1285 (flymake-report-status nil
"*")
1286 (flymake-log 2 "started process %d, command=%s, dir=%s"
1287 (process-id process
) (process-command process
)
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
)
1297 (flymake-report-fatal-status "PROCERR" err-str
)))))
1299 (defun flymake-kill-process (proc)
1300 "Kill process PROC."
1302 (let* ((buf (process-buffer proc
)))
1303 (when (buffer-live-p buf
)
1304 (with-current-buffer buf
1305 (setq flymake-check-was-interrupted t
))))
1306 (flymake-log 1 "killed process %d" (process-id proc
)))
1308 (defun flymake-stop-all-syntax-checks ()
1309 "Kill all syntax check processes."
1311 (while flymake-processes
1312 (flymake-kill-process (pop flymake-processes
))))
1314 (defun flymake-compilation-is-running ()
1315 (and (boundp 'compilation-in-progress
)
1316 compilation-in-progress
))
1318 (defun flymake-compile ()
1319 "Kill all flymake syntax checks, start compilation."
1321 (flymake-stop-all-syntax-checks)
1322 (call-interactively 'compile
))
1324 (defcustom flymake-no-changes-timeout
0.5
1325 "Time to wait after last change before starting compilation."
1329 (defun flymake-on-timer-event (buffer)
1330 "Start a syntax check for buffer BUFFER if necessary."
1331 (when (buffer-live-p buffer
)
1332 (with-current-buffer buffer
1333 (when (and (not flymake-is-running
)
1334 flymake-last-change-time
1335 (> (- (flymake-float-time) flymake-last-change-time
)
1336 flymake-no-changes-timeout
))
1338 (setq flymake-last-change-time nil
)
1339 (flymake-log 3 "starting syntax check as more than 1 second passed since last change")
1340 (flymake-start-syntax-check)))))
1342 (defun flymake-current-line-no ()
1343 "Return number of current line in current buffer."
1344 (count-lines (point-min) (if (eobp) (point) (1+ (point)))))
1346 (defun flymake-count-lines ()
1347 "Return number of lines in buffer BUFFER."
1348 (count-lines (point-min) (point-max)))
1350 (defun flymake-display-err-menu-for-current-line ()
1351 "Display a menu with errors/warnings for current line if it has errors and/or warnings."
1353 (let* ((line-no (flymake-current-line-no))
1354 (line-err-info-list (nth 0 (flymake-find-err-info flymake-err-info line-no
)))
1355 (menu-data (flymake-make-err-menu-data line-no line-err-info-list
))
1359 (setq choice
(flymake-popup-menu menu-data
))
1360 (flymake-log 3 "choice=%s" choice
)
1363 (flymake-log 1 "no errors for line %d" line-no
))))
1365 (defun flymake-make-err-menu-data (line-no line-err-info-list
)
1366 "Make a (menu-title (item-title item-action)*) list with errors/warnings from LINE-ERR-INFO-LIST."
1367 (let* ((menu-items nil
))
1368 (when line-err-info-list
1369 (let* ((count (length line-err-info-list
))
1370 (menu-item-text nil
))
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
))))
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
))
1381 (setq count
(1- count
)))
1382 (flymake-log 3 "created menu-items with %d item(s)" (length 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
))
1390 (defun flymake-goto-file-and-line (file line
)
1391 "Try to get buffer for FILE and goto line LINE in it."
1392 (if (not (file-exists-p file
))
1393 (flymake-log 1 "File %s does not exist" file
)
1395 (goto-char (point-min))
1396 (forward-line (1- line
))))
1398 ;; flymake minor mode declarations
1399 (defvar flymake-mode-line nil
)
1401 (make-variable-buffer-local 'flymake-mode-line
)
1403 (defvar flymake-mode-line-e-w nil
)
1405 (make-variable-buffer-local 'flymake-mode-line-e-w
)
1407 (defvar flymake-mode-line-status nil
)
1409 (make-variable-buffer-local 'flymake-mode-line-status
)
1411 (defun flymake-report-status (e-w &optional status
)
1412 "Show status in mode line."
1414 (setq flymake-mode-line-e-w e-w
))
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)))
1424 (defun flymake-display-warning (warning)
1425 "Display a warning to user."
1426 (message-box warning
))
1428 (defcustom flymake-gui-warnings-enabled t
1429 "Enables/disables GUI warnings."
1433 (defun flymake-report-fatal-status (status warning
)
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
))
1439 (flymake-log 0 "switched OFF Flymake mode for buffer %s due to fatal status %s, warning %s"
1440 (buffer-name) status warning
))
1442 (defcustom flymake-start-syntax-check-on-find-file t
1443 "Start syntax check on find file."
1448 (define-minor-mode flymake-mode
1449 "Toggle on-the-fly syntax checking.
1450 With a prefix argument ARG, enable the mode if ARG is positive,
1451 and disable it otherwise. If called from Lisp, enable the mode
1452 if ARG is omitted or nil."
1453 :group
'flymake
:lighter flymake-mode-line
1456 ;; Turning the mode ON.
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)))
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)
1469 (flymake-report-status "" "")
1472 (run-at-time nil
1 'flymake-on-timer-event
(current-buffer)))
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))))))
1481 ;; Turning the mode OFF.
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)
1488 (flymake-delete-own-overlays)
1491 (cancel-timer flymake-timer
)
1492 (setq flymake-timer nil
))
1494 (setq flymake-is-running nil
))))
1497 (defun flymake-mode-on ()
1498 "Turn flymake mode on."
1500 (flymake-log 1 "flymake mode turned ON for buffer %s" (buffer-name)))
1503 (defun flymake-mode-off ()
1504 "Turn flymake mode off."
1506 (flymake-log 1 "flymake mode turned OFF for buffer %s" (buffer-name)))
1508 (defcustom flymake-start-syntax-check-on-newline t
1509 "Start syntax check if newline char was added/removed from the buffer."
1513 (defun flymake-after-change-function (start stop _len
)
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))
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")
1519 (flymake-start-syntax-check))
1520 (setq flymake-last-change-time
(flymake-float-time))))
1522 (defun flymake-after-save-hook ()
1523 (if (local-variable-p 'flymake-mode
(current-buffer)) ; (???) other way to determine whether flymake is active in buffer being saved?
1525 (flymake-log 3 "starting syntax check as buffer was saved")
1526 (flymake-start-syntax-check)))) ; no more mode 3. cannot start check if mode 3 (to temp copies) is active - (???)
1528 (defun flymake-kill-buffer-hook ()
1530 (cancel-timer flymake-timer
)
1531 (setq flymake-timer nil
)))
1534 (defun flymake-find-file-hook ()
1535 ;;+(when flymake-start-syntax-check-on-find-file
1536 ;;+ (flymake-log 3 "starting syntax check on file open")
1537 ;;+ (flymake-start-syntax-check)
1539 (when (and (not (local-variable-p 'flymake-mode
(current-buffer)))
1540 (flymake-can-syntax-check-file buffer-file-name
))
1542 (flymake-log 3 "automatically turned ON flymake mode")))
1544 (defun flymake-get-first-err-line-no (err-info-list)
1545 "Return first line with error."
1547 (flymake-er-get-line (car err-info-list
))))
1549 (defun flymake-get-last-err-line-no (err-info-list)
1550 "Return last line with error."
1552 (flymake-er-get-line (nth (1- (length err-info-list
)) err-info-list
))))
1554 (defun flymake-get-next-err-line-no (err-info-list line-no
)
1555 "Return next line with error."
1557 (let* ((count (length err-info-list
))
1559 (while (and (< idx count
) (>= line-no
(flymake-er-get-line (nth idx err-info-list
))))
1560 (setq idx
(1+ idx
)))
1562 (flymake-er-get-line (nth idx err-info-list
))))))
1564 (defun flymake-get-prev-err-line-no (err-info-list line-no
)
1565 "Return previous line with error."
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
)))
1571 (flymake-er-get-line (nth (1- count
) err-info-list
))))))
1573 (defun flymake-skip-whitespace ()
1574 "Move forward until non-whitespace is reached."
1575 (while (looking-at "[ \t]")
1578 (defun flymake-goto-line (line-no)
1579 "Go to line LINE-NO, then skip whitespace."
1580 (goto-char (point-min))
1581 (forward-line (1- line-no
))
1582 (flymake-skip-whitespace))
1584 (defun flymake-goto-next-error ()
1585 "Go to next error in err ring."
1587 (let ((line-no (flymake-get-next-err-line-no flymake-err-info
(flymake-current-line-no))))
1589 (setq line-no
(flymake-get-first-err-line-no flymake-err-info
))
1590 (flymake-log 1 "passed end of file"))
1592 (flymake-goto-line line-no
)
1593 (flymake-log 1 "no errors in current buffer"))))
1595 (defun flymake-goto-prev-error ()
1596 "Go to previous error in err ring."
1598 (let ((line-no (flymake-get-prev-err-line-no flymake-err-info
(flymake-current-line-no))))
1600 (setq line-no
(flymake-get-last-err-line-no flymake-err-info
))
1601 (flymake-log 1 "passed beginning of file"))
1603 (flymake-goto-line line-no
)
1604 (flymake-log 1 "no errors in current buffer"))))
1606 (defun flymake-patch-err-text (string)
1607 (if (string-match "^[\n\t :0-9]*\\(.*\\)$" string
)
1608 (match-string 1 string
)
1611 ;;;; general init-cleanup and helper routines
1612 (defun flymake-create-temp-inplace (file-name prefix
)
1613 (unless (stringp file-name
)
1614 (error "Invalid file-name"))
1616 (setq prefix
"flymake"))
1617 (let* ((ext (file-name-extension file-name
))
1618 (temp-name (file-truename
1619 (concat (file-name-sans-extension file-name
)
1621 (and ext
(concat "." ext
))))))
1622 (flymake-log 3 "create-temp-inplace: file=%s temp=%s" file-name temp-name
)
1625 (defun flymake-create-temp-with-folder-structure (file-name _prefix
)
1626 (unless (stringp file-name
)
1627 (error "Invalid file-name"))
1629 (let* ((dir (file-name-directory file-name
))
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.
1632 (slash-pos (string-match "/" dir
))
1633 (temp-dir (expand-file-name (substring dir
(1+ slash-pos
))
1634 (flymake-get-temp-dir))))
1636 (file-truename (expand-file-name (file-name-nondirectory file-name
)
1639 (defun flymake-delete-temp-directory (dir-name)
1640 "Attempt to delete temp dir created by `flymake-create-temp-with-folder-structure', do not fail on error."
1641 (let* ((temp-dir (flymake-get-temp-dir))
1642 (suffix (substring dir-name
(1+ (length temp-dir
)))))
1644 (while (> (length suffix
) 0)
1645 (setq suffix
(directory-file-name suffix
))
1646 ;;+(flymake-log 0 "suffix=%s" suffix)
1647 (flymake-safe-delete-directory
1648 (file-truename (expand-file-name suffix temp-dir
)))
1649 (setq suffix
(file-name-directory suffix
)))))
1651 (defvar flymake-temp-source-file-name nil
)
1652 (make-variable-buffer-local 'flymake-temp-source-file-name
)
1654 (defvar flymake-master-file-name nil
)
1655 (make-variable-buffer-local 'flymake-master-file-name
)
1657 (defvar flymake-temp-master-file-name nil
)
1658 (make-variable-buffer-local 'flymake-temp-master-file-name
)
1660 (defvar flymake-base-dir nil
)
1661 (make-variable-buffer-local 'flymake-base-dir
)
1663 (defun flymake-init-create-temp-buffer-copy (create-temp-f)
1664 "Make a temporary copy of the current buffer, save its name in buffer data and return the name."
1665 (let* ((source-file-name buffer-file-name
)
1666 (temp-source-file-name (funcall create-temp-f source-file-name
"flymake")))
1668 (flymake-save-buffer-in-file temp-source-file-name
)
1669 (setq flymake-temp-source-file-name temp-source-file-name
)
1670 temp-source-file-name
))
1672 (defun flymake-simple-cleanup ()
1673 "Do cleanup after `flymake-init-create-temp-buffer-copy'.
1675 (flymake-safe-delete-file flymake-temp-source-file-name
)
1676 (setq flymake-last-change-time nil
))
1678 (defun flymake-get-real-file-name (file-name-from-err-msg)
1679 "Translate file name from error message to \"real\" file name.
1680 Return full-name. Names are real, not patched."
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
)
1687 (list flymake-base-dir
1688 (file-name-directory source-file-name
)
1689 (if master-file-name
(file-name-directory master-file-name
))))
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
))))
1695 (when (equal 0 (length file-name-from-err-msg
))
1696 (setq file-name-from-err-msg source-file-name
))
1698 (setq real-name
(flymake-get-full-patched-file-name file-name-from-err-msg base-dirs files
))
1699 ;; if real-name is nil, than file name from err msg is none of the files we've patched
1701 (setq real-name
(flymake-get-full-nonpatched-file-name file-name-from-err-msg base-dirs
)))
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
)
1708 (defun flymake-get-full-patched-file-name (file-name-from-err-msg base-dirs files
)
1709 (let* ((base-dirs-count (length base-dirs
))
1710 (file-count (length files
))
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
))))
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)
1720 (when (and this-dir this-file
(flymake-same-files
1721 (expand-file-name file-name-from-err-msg this-dir
)
1723 (setq real-name this-real-name
)))
1724 (setq file-count
(1- file-count
)))
1725 (setq base-dirs-count
(1- base-dirs-count
)))
1728 (defun flymake-get-full-nonpatched-file-name (file-name-from-err-msg base-dirs
)
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))
1734 (let* ((full-name (expand-file-name file-name-from-err-msg
1735 (nth (1- base-dirs-count
) base-dirs
))))
1736 (if (file-exists-p full-name
)
1737 (setq real-name full-name
))
1738 (setq base-dirs-count
(1- base-dirs-count
))))))
1741 (defun flymake-init-find-buildfile-dir (source-file-name buildfile-name
)
1742 "Find buildfile, store its dir in buffer data and return its dir, if found."
1743 (let* ((buildfile-dir
1744 (flymake-find-buildfile buildfile-name
1745 (file-name-directory source-file-name
))))
1747 (setq flymake-base-dir buildfile-dir
)
1748 (flymake-log 1 "no buildfile (%s) for %s" buildfile-name source-file-name
)
1749 (flymake-report-fatal-status
1750 "NOMK" (format "No buildfile (%s) found for %s"
1751 buildfile-name source-file-name
)))))
1753 (defun flymake-init-create-temp-source-and-master-buffer-copy (get-incl-dirs-f create-temp-f master-file-masks include-regexp
)
1754 "Find master file (or buffer), create its copy along with a copy of the source file."
1755 (let* ((source-file-name buffer-file-name
)
1756 (temp-source-file-name (flymake-init-create-temp-buffer-copy create-temp-f
))
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
1760 master-file-masks include-regexp
)))
1762 (if (not master-and-temp-master
)
1764 (flymake-log 1 "cannot find master file for %s" source-file-name
)
1765 (flymake-report-status "!" "") ; NOMASTER
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
)))))
1770 (defun flymake-master-cleanup ()
1771 (flymake-simple-cleanup)
1772 (flymake-safe-delete-file flymake-temp-master-file-name
))
1774 ;;;; make-specific init-cleanup routines
1775 (defun flymake-get-syntax-check-program-args (source-file-name base-dir use-relative-base-dir use-relative-source get-cmd-line-f
)
1776 "Create a command line for syntax check using GET-CMD-LINE-F."
1777 (funcall get-cmd-line-f
1778 (if use-relative-source
1779 (file-relative-name source-file-name base-dir
)
1781 (if use-relative-base-dir
1782 (file-relative-name base-dir
1783 (file-name-directory source-file-name
))
1786 (defun flymake-get-make-cmdline (source base-dir
)
1791 (concat "CHK_SOURCES=" source
)
1792 "SYNTAX_CHECK_MODE=1"
1795 (defun flymake-get-ant-cmdline (source base-dir
)
1798 (concat base-dir
"/" "build.xml")
1799 (concat "-DCHK_SOURCES=" source
)
1802 (defun flymake-simple-make-init-impl (create-temp-f use-relative-base-dir use-relative-source build-file-name get-cmdline-f
)
1803 "Create syntax check command line for a directly checked source file.
1804 Use CREATE-TEMP-F for creating temp copy."
1806 (source-file-name buffer-file-name
)
1807 (buildfile-dir (flymake-init-find-buildfile-dir source-file-name build-file-name
)))
1809 (let* ((temp-source-file-name (flymake-init-create-temp-buffer-copy create-temp-f
)))
1810 (setq args
(flymake-get-syntax-check-program-args temp-source-file-name buildfile-dir
1811 use-relative-base-dir use-relative-source
1815 (defun flymake-simple-make-init ()
1816 (flymake-simple-make-init-impl 'flymake-create-temp-inplace t t
"Makefile" 'flymake-get-make-cmdline
))
1818 (defun flymake-master-make-init (get-incl-dirs-f master-file-masks include-regexp
)
1819 "Create make command line for a source file checked via master file compilation."
1820 (let* ((make-args nil
)
1821 (temp-master-file-name (flymake-init-create-temp-source-and-master-buffer-copy
1822 get-incl-dirs-f
'flymake-create-temp-inplace
1823 master-file-masks include-regexp
)))
1824 (when temp-master-file-name
1825 (let* ((buildfile-dir (flymake-init-find-buildfile-dir temp-master-file-name
"Makefile")))
1827 (setq make-args
(flymake-get-syntax-check-program-args
1828 temp-master-file-name buildfile-dir nil nil
'flymake-get-make-cmdline
)))))
1831 (defun flymake-find-make-buildfile (source-dir)
1832 (flymake-find-buildfile "Makefile" source-dir
))
1834 ;;;; .h/make specific
1835 (defun flymake-master-make-header-init ()
1836 (flymake-master-make-init
1837 'flymake-get-include-dirs
1838 '("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'")
1839 "[ \t]*#[ \t]*include[ \t]*\"\\([[:word:]0-9/\\_.]*%s\\)\""))
1841 ;;;; .java/make specific
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
))
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
))
1848 (defun flymake-simple-java-cleanup ()
1849 "Cleanup after `flymake-simple-make-java-init' -- delete temp file and dirs."
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
))))
1855 ;;;; perl-specific init-cleanup routines
1856 (defun flymake-perl-init ()
1857 (let* ((temp-file (flymake-init-create-temp-buffer-copy
1858 'flymake-create-temp-inplace
))
1859 (local-file (file-relative-name
1861 (file-name-directory buffer-file-name
))))
1862 (list "perl" (list "-wc " local-file
))))
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
1870 (file-name-directory buffer-file-name
))))
1871 (list "php" (list "-f" local-file
"-l"))))
1873 ;;;; tex-specific init-cleanup routines
1874 (defun flymake-get-tex-args (file-name)
1875 ;;(list "latex" (list "-c-style-errors" file-name))
1876 (list "texify" (list "--pdf" "--tex-option=-c-style-errors" file-name
)))
1878 (defun flymake-simple-tex-init ()
1879 (flymake-get-tex-args (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace
)))
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.
1884 (defun flymake-master-tex-init ()
1885 (let* ((temp-master-file-name (flymake-init-create-temp-source-and-master-buffer-copy
1886 'flymake-get-include-dirs-dot
'flymake-create-temp-inplace
1888 "[ \t]*\\in\\(?:put\\|clude\\)[ \t]*{\\(.*%s\\)}")))
1889 (when temp-master-file-name
1890 (flymake-get-tex-args temp-master-file-name
))))
1892 (defun flymake-get-include-dirs-dot (_base-dir)
1895 ;;;; xml-specific init-cleanup routines
1896 (defun flymake-xml-init ()
1897 (list flymake-xml-program
1898 (list "val" (flymake-init-create-temp-buffer-copy
1899 'flymake-create-temp-inplace
))))
1903 ;;; flymake.el ends here