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