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