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