aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/progmodes/flymake-proc.el1088
-rw-r--r--lisp/progmodes/flymake-ui.el601
-rw-r--r--lisp/progmodes/flymake.el1626
3 files changed, 1698 insertions, 1617 deletions
diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el
new file mode 100644
index 00000000000..8a2fede2df5
--- /dev/null
+++ b/lisp/progmodes/flymake-proc.el
@@ -0,0 +1,1088 @@
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-can-syntax-check-file (file-name)
124 "Determine whether we can syntax check FILE-NAME.
125Return nil if we cannot, non-nil if we can."
126 (if (flymake-get-init-function file-name) t nil))
127
128(defun flymake-get-init-function (file-name)
129 "Return init function to be used for the file."
130 (let* ((init-f (nth 0 (flymake-get-file-name-mode-and-masks file-name))))
131 ;;(flymake-log 0 "calling %s" init-f)
132 ;;(funcall init-f (current-buffer))
133 init-f))
134
135(defun flymake-get-cleanup-function (file-name)
136 "Return cleanup function to be used for the file."
137 (or (nth 1 (flymake-get-file-name-mode-and-masks file-name))
138 'flymake-simple-cleanup))
139
140(defun flymake-get-real-file-name-function (file-name)
141 (or (nth 2 (flymake-get-file-name-mode-and-masks file-name))
142 'flymake-get-real-file-name))
143
144(defvar flymake-find-buildfile-cache (make-hash-table :test #'equal))
145
146(defun flymake-get-buildfile-from-cache (dir-name)
147 "Look up DIR-NAME in cache and return its associated value.
148If DIR-NAME is not found, return nil."
149 (gethash dir-name flymake-find-buildfile-cache))
150
151(defun flymake-add-buildfile-to-cache (dir-name buildfile)
152 "Associate DIR-NAME with BUILDFILE in the buildfile cache."
153 (puthash dir-name buildfile flymake-find-buildfile-cache))
154
155(defun flymake-clear-buildfile-cache ()
156 "Clear the buildfile cache."
157 (clrhash flymake-find-buildfile-cache))
158
159(defun flymake-find-buildfile (buildfile-name source-dir-name)
160 "Find buildfile starting from current directory.
161Buildfile includes Makefile, build.xml etc.
162Return its file name if found, or nil if not found."
163 (or (flymake-get-buildfile-from-cache source-dir-name)
164 (let* ((file (locate-dominating-file source-dir-name buildfile-name)))
165 (if file
166 (progn
167 (flymake-log 3 "found buildfile at %s" file)
168 (flymake-add-buildfile-to-cache source-dir-name file)
169 file)
170 (progn
171 (flymake-log 3 "buildfile for %s not found" source-dir-name)
172 nil)))))
173
174(defun flymake-fix-file-name (name)
175 "Replace all occurrences of `\\' with `/'."
176 (when name
177 (setq name (expand-file-name name))
178 (setq name (abbreviate-file-name name))
179 (setq name (directory-file-name name))
180 name))
181
182(defun flymake-same-files (file-name-one file-name-two)
183 "Check if FILE-NAME-ONE and FILE-NAME-TWO point to same file.
184Return t if so, nil if not."
185 (equal (flymake-fix-file-name file-name-one)
186 (flymake-fix-file-name file-name-two)))
187
188;; This is bound dynamically to pass a parameter to a sort predicate below
189(defvar flymake-included-file-name)
190
191(defun flymake-find-possible-master-files (file-name master-file-dirs masks)
192 "Find (by name and location) all possible master files.
193
194Name is specified by FILE-NAME and location is specified by
195MASTER-FILE-DIRS. Master files include .cpp and .c for .h.
196Files are searched for starting from the .h directory and max
197max-level parent dirs. File contents are not checked."
198 (let* ((dirs master-file-dirs)
199 (files nil)
200 (done nil))
201
202 (while (and (not done) dirs)
203 (let* ((dir (expand-file-name (car dirs) (file-name-directory file-name)))
204 (masks masks))
205 (while (and (file-exists-p dir) (not done) masks)
206 (let* ((mask (car masks))
207 (dir-files (directory-files dir t mask)))
208
209 (flymake-log 3 "dir %s, %d file(s) for mask %s"
210 dir (length dir-files) mask)
211 (while (and (not done) dir-files)
212 (when (not (file-directory-p (car dir-files)))
213 (setq files (cons (car dir-files) files))
214 (when (>= (length files) flymake-master-file-count-limit)
215 (flymake-log 3 "master file count limit (%d) reached" flymake-master-file-count-limit)
216 (setq done t)))
217 (setq dir-files (cdr dir-files))))
218 (setq masks (cdr masks))))
219 (setq dirs (cdr dirs)))
220 (when files
221 (let ((flymake-included-file-name (file-name-nondirectory file-name)))
222 (setq files (sort files 'flymake-master-file-compare))))
223 (flymake-log 3 "found %d possible master file(s)" (length files))
224 files))
225
226(defun flymake-master-file-compare (file-one file-two)
227 "Compare two files specified by FILE-ONE and FILE-TWO.
228This function is used in sort to move most possible file names
229to the beginning of the list (File.h -> File.cpp moved to top)."
230 (and (equal (file-name-sans-extension flymake-included-file-name)
231 (file-name-base file-one))
232 (not (equal file-one file-two))))
233
234(defvar flymake-check-file-limit 8192
235 "Maximum number of chars to look at when checking possible master file.
236Nil means search the entire file.")
237
238(defun flymake-check-patch-master-file-buffer
239 (master-file-temp-buffer
240 master-file-name patched-master-file-name
241 source-file-name patched-source-file-name
242 include-dirs regexp)
243 "Check if MASTER-FILE-NAME is a master file for SOURCE-FILE-NAME.
244If yes, patch a copy of MASTER-FILE-NAME to include PATCHED-SOURCE-FILE-NAME
245instead of SOURCE-FILE-NAME.
246
247For example, foo.cpp is a master file if it includes foo.h.
248
249When a buffer for MASTER-FILE-NAME exists, use it as a source
250instead of reading master file from disk."
251 (let* ((source-file-nondir (file-name-nondirectory source-file-name))
252 (source-file-extension (file-name-extension source-file-nondir))
253 (source-file-nonext (file-name-sans-extension source-file-nondir))
254 (found nil)
255 (inc-name nil)
256 (search-limit flymake-check-file-limit))
257 (setq regexp
258 (format regexp ; "[ \t]*#[ \t]*include[ \t]*\"\\(.*%s\\)\""
259 ;; Hack for tex files, where \include often excludes .tex.
260 ;; Maybe this is safe generally.
261 (if (and (> (length source-file-extension) 1)
262 (string-equal source-file-extension "tex"))
263 (format "%s\\(?:\\.%s\\)?"
264 (regexp-quote source-file-nonext)
265 (regexp-quote source-file-extension))
266 (regexp-quote source-file-nondir))))
267 (unwind-protect
268 (with-current-buffer master-file-temp-buffer
269 (if (or (not search-limit)
270 (> search-limit (point-max)))
271 (setq search-limit (point-max)))
272 (flymake-log 3 "checking %s against regexp %s"
273 master-file-name regexp)
274 (goto-char (point-min))
275 (while (and (< (point) search-limit)
276 (re-search-forward regexp search-limit t))
277 (let ((match-beg (match-beginning 1))
278 (match-end (match-end 1)))
279
280 (flymake-log 3 "found possible match for %s" source-file-nondir)
281 (setq inc-name (match-string 1))
282 (and (> (length source-file-extension) 1)
283 (string-equal source-file-extension "tex")
284 (not (string-match (format "\\.%s\\'" source-file-extension)
285 inc-name))
286 (setq inc-name (concat inc-name "." source-file-extension)))
287 (when (eq t (compare-strings
288 source-file-nondir nil nil
289 inc-name (- (length inc-name)
290 (length source-file-nondir)) nil))
291 (flymake-log 3 "inc-name=%s" inc-name)
292 (when (flymake-check-include source-file-name inc-name
293 include-dirs)
294 (setq found t)
295 ;; replace-match is not used here as it fails in
296 ;; XEmacs with 'last match not a buffer' error as
297 ;; check-includes calls replace-in-string
298 (flymake-replace-region
299 match-beg match-end
300 (file-name-nondirectory patched-source-file-name))))
301 (forward-line 1)))
302 (when found
303 (flymake-save-buffer-in-file patched-master-file-name)))
304 ;;+(flymake-log 3 "killing buffer %s"
305 ;; (buffer-name master-file-temp-buffer))
306 (kill-buffer master-file-temp-buffer))
307 ;;+(flymake-log 3 "check-patch master file %s: %s" master-file-name found)
308 (when found
309 (flymake-log 2 "found master file %s" master-file-name))
310 found))
311
312;;; XXX: remove
313(defun flymake-replace-region (beg end rep)
314 "Replace text in BUFFER in region (BEG END) with REP."
315 (save-excursion
316 (goto-char end)
317 ;; Insert before deleting, so as to better preserve markers's positions.
318 (insert rep)
319 (delete-region beg end)))
320
321(defun flymake-read-file-to-temp-buffer (file-name)
322 "Insert contents of FILE-NAME into newly created temp buffer."
323 (let* ((temp-buffer (get-buffer-create (generate-new-buffer-name (concat "flymake:" (file-name-nondirectory file-name))))))
324 (with-current-buffer temp-buffer
325 (insert-file-contents file-name))
326 temp-buffer))
327
328(defun flymake-copy-buffer-to-temp-buffer (buffer)
329 "Copy contents of BUFFER into newly created temp buffer."
330 (with-current-buffer
331 (get-buffer-create (generate-new-buffer-name
332 (concat "flymake:" (buffer-name buffer))))
333 (insert-buffer-substring buffer)
334 (current-buffer)))
335
336(defun flymake-check-include (source-file-name inc-name include-dirs)
337 "Check if SOURCE-FILE-NAME can be found in include path.
338Return t if it can be found via include path using INC-NAME."
339 (if (file-name-absolute-p inc-name)
340 (flymake-same-files source-file-name inc-name)
341 (while (and include-dirs
342 (not (flymake-same-files
343 source-file-name
344 (concat (file-name-directory source-file-name)
345 "/" (car include-dirs)
346 "/" inc-name))))
347 (setq include-dirs (cdr include-dirs)))
348 include-dirs))
349
350(defun flymake-find-buffer-for-file (file-name)
351 "Check if there exists a buffer visiting FILE-NAME.
352Return t if so, nil if not."
353 (let ((buffer-name (get-file-buffer file-name)))
354 (if buffer-name
355 (get-buffer buffer-name))))
356
357(defun flymake-create-master-file (source-file-name patched-source-file-name get-incl-dirs-f create-temp-f masks include-regexp)
358 "Save SOURCE-FILE-NAME with a different name.
359Find master file, patch and save it."
360 (let* ((possible-master-files (flymake-find-possible-master-files source-file-name flymake-master-file-dirs masks))
361 (master-file-count (length possible-master-files))
362 (idx 0)
363 (temp-buffer nil)
364 (master-file-name nil)
365 (patched-master-file-name nil)
366 (found nil))
367
368 (while (and (not found) (< idx master-file-count))
369 (setq master-file-name (nth idx possible-master-files))
370 (setq patched-master-file-name (funcall create-temp-f master-file-name "flymake_master"))
371 (if (flymake-find-buffer-for-file master-file-name)
372 (setq temp-buffer (flymake-copy-buffer-to-temp-buffer (flymake-find-buffer-for-file master-file-name)))
373 (setq temp-buffer (flymake-read-file-to-temp-buffer master-file-name)))
374 (setq found
375 (flymake-check-patch-master-file-buffer
376 temp-buffer
377 master-file-name
378 patched-master-file-name
379 source-file-name
380 patched-source-file-name
381 (funcall get-incl-dirs-f (file-name-directory master-file-name))
382 include-regexp))
383 (setq idx (1+ idx)))
384 (if found
385 (list master-file-name patched-master-file-name)
386 (progn
387 (flymake-log 3 "none of %d master file(s) checked includes %s" master-file-count
388 (file-name-nondirectory source-file-name))
389 nil))))
390
391(defun flymake-save-buffer-in-file (file-name)
392 "Save the entire buffer contents into file FILE-NAME.
393Create parent directories as needed."
394 (make-directory (file-name-directory file-name) 1)
395 (write-region nil nil file-name nil 566)
396 (flymake-log 3 "saved buffer %s in file %s" (buffer-name) file-name))
397
398(defun flymake-process-filter (process output)
399 "Parse OUTPUT and highlight error lines.
400It's flymake process filter."
401 (let ((source-buffer (process-buffer process)))
402
403 (flymake-log 3 "received %d byte(s) of output from process %d"
404 (length output) (process-id process))
405 (when (buffer-live-p source-buffer)
406 (with-current-buffer source-buffer
407 (flymake-parse-output-and-residual output)))))
408
409(defun flymake-process-sentinel (process _event)
410 "Sentinel for syntax check buffers."
411 (when (memq (process-status process) '(signal exit))
412 (let* ((exit-status (process-exit-status process))
413 (command (process-command process))
414 (source-buffer (process-buffer process))
415 (cleanup-f (flymake-get-cleanup-function (buffer-file-name source-buffer))))
416
417 (flymake-log 2 "process %d exited with code %d"
418 (process-id process) exit-status)
419 (condition-case err
420 (progn
421 (flymake-log 3 "cleaning up using %s" cleanup-f)
422 (when (buffer-live-p source-buffer)
423 (with-current-buffer source-buffer
424 (funcall cleanup-f)))
425
426 (delete-process process)
427 (setq flymake-processes (delq process flymake-processes))
428
429 (when (buffer-live-p source-buffer)
430 (with-current-buffer source-buffer
431
432 (flymake-parse-residual)
433 (flymake-post-syntax-check exit-status command)
434 (setq flymake-is-running nil))))
435 (error
436 (let ((err-str (format "Error in process sentinel for buffer %s: %s"
437 source-buffer (error-message-string err))))
438 (flymake-log 0 err-str)
439 (with-current-buffer source-buffer
440 (setq flymake-is-running nil))))))))
441
442(defun flymake-post-syntax-check (exit-status command)
443 (save-restriction
444 (widen)
445 (setq flymake-err-info flymake-new-err-info)
446 (setq flymake-new-err-info nil)
447 (setq flymake-err-info
448 (flymake-fix-line-numbers
449 flymake-err-info 1 (count-lines (point-min) (point-max))))
450 (flymake-delete-own-overlays)
451 (flymake-highlight-err-lines flymake-err-info)
452 (let (err-count warn-count)
453 (setq err-count (flymake-get-err-count flymake-err-info "e"))
454 (setq warn-count (flymake-get-err-count flymake-err-info "w"))
455 (flymake-log 2 "%s: %d error(s), %d warning(s) in %.2f second(s)"
456 (buffer-name) err-count warn-count
457 (- (float-time) flymake-check-start-time))
458 (setq flymake-check-start-time nil)
459
460 (if (and (equal 0 err-count) (equal 0 warn-count))
461 (if (equal 0 exit-status)
462 (flymake-report-status "" "") ; PASSED
463 (if (not flymake-check-was-interrupted)
464 (flymake-report-fatal-status "CFGERR"
465 (format "Configuration error has occurred while running %s" command))
466 (flymake-report-status nil ""))) ; "STOPPED"
467 (flymake-report-status (format "%d/%d" err-count warn-count) "")))))
468
469(defun flymake-parse-output-and-residual (output)
470 "Split OUTPUT into lines, merge in residual if necessary."
471 (let* ((buffer-residual flymake-output-residual)
472 (total-output (if buffer-residual (concat buffer-residual output) output))
473 (lines-and-residual (flymake-split-output total-output))
474 (lines (nth 0 lines-and-residual))
475 (new-residual (nth 1 lines-and-residual)))
476 (setq flymake-output-residual new-residual)
477 (setq flymake-new-err-info
478 (flymake-parse-err-lines
479 flymake-new-err-info lines))))
480
481(defun flymake-parse-residual ()
482 "Parse residual if it's non empty."
483 (when flymake-output-residual
484 (setq flymake-new-err-info
485 (flymake-parse-err-lines
486 flymake-new-err-info
487 (list flymake-output-residual)))
488 (setq flymake-output-residual nil)))
489
490(defun flymake-fix-line-numbers (err-info-list min-line max-line)
491 "Replace line numbers with fixed value.
492If line-numbers is less than MIN-LINE, set line numbers to MIN-LINE.
493If line numbers is greater than MAX-LINE, set line numbers to MAX-LINE.
494The reason for this fix is because some compilers might report
495line number outside the file being compiled."
496 (let* ((count (length err-info-list))
497 (err-info nil)
498 (line 0))
499 (while (> count 0)
500 (setq err-info (nth (1- count) err-info-list))
501 (setq line (flymake-er-get-line err-info))
502 (when (or (< line min-line) (> line max-line))
503 (setq line (if (< line min-line) min-line max-line))
504 (setq err-info-list (flymake-set-at err-info-list (1- count)
505 (flymake-er-make-er line
506 (flymake-er-get-line-err-info-list err-info)))))
507 (setq count (1- count))))
508 err-info-list)
509
510(defun flymake-parse-err-lines (err-info-list lines)
511 "Parse err LINES, store info in ERR-INFO-LIST."
512 (let* ((count (length lines))
513 (idx 0)
514 (line-err-info nil)
515 (real-file-name nil)
516 (source-file-name buffer-file-name)
517 (get-real-file-name-f (flymake-get-real-file-name-function source-file-name)))
518
519 (while (< idx count)
520 (setq line-err-info (flymake-parse-line (nth idx lines)))
521 (when line-err-info
522 (setq real-file-name (funcall get-real-file-name-f
523 (flymake-ler-file line-err-info)))
524 (setq line-err-info (flymake-ler-set-full-file line-err-info real-file-name))
525
526 (when (flymake-same-files real-file-name source-file-name)
527 (setq line-err-info (flymake-ler-set-file line-err-info nil))
528 (setq err-info-list (flymake-add-err-info err-info-list line-err-info))))
529 (flymake-log 3 "parsed `%s', %s line-err-info" (nth idx lines) (if line-err-info "got" "no"))
530 (setq idx (1+ idx)))
531 err-info-list))
532
533(defun flymake-split-output (output)
534 "Split OUTPUT into lines.
535Return last one as residual if it does not end with newline char.
536Returns ((LINES) RESIDUAL)."
537 (when (and output (> (length output) 0))
538 (let* ((lines (split-string output "[\n\r]+" t))
539 (complete (equal "\n" (char-to-string (aref output (1- (length output))))))
540 (residual nil))
541 (when (not complete)
542 (setq residual (car (last lines)))
543 (setq lines (butlast lines)))
544 (list lines residual))))
545
546(defun flymake-reformat-err-line-patterns-from-compile-el (original-list)
547 "Grab error line patterns from ORIGINAL-LIST in compile.el format.
548Convert it to flymake internal format."
549 (let* ((converted-list '()))
550 (dolist (item original-list)
551 (setq item (cdr item))
552 (let ((regexp (nth 0 item))
553 (file (nth 1 item))
554 (line (nth 2 item))
555 (col (nth 3 item)))
556 (if (consp file) (setq file (car file)))
557 (if (consp line) (setq line (car line)))
558 (if (consp col) (setq col (car col)))
559
560 (when (not (functionp line))
561 (setq converted-list (cons (list regexp file line col) converted-list)))))
562 converted-list))
563
564(require 'compile)
565
566(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
567 (append
568 '(
569 ;; MS Visual C++ 6.0
570 ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) : \\(\\(error\\|warning\\|fatal error\\) \\(C[0-9]+\\):[ \t\n]*\\(.+\\)\\)"
571 1 3 nil 4)
572 ;; jikes
573 ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:[0-9]+: \\(\\(Error\\|Warning\\|Caution\\|Semantic Error\\):[ \t\n]*\\(.+\\)\\)"
574 1 3 nil 4)
575 ;; MS midl
576 ("midl[ ]*:[ ]*\\(command line error .*\\)"
577 nil nil nil 1)
578 ;; MS C#
579 ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\),[0-9]+): \\(\\(error\\|warning\\|fatal error\\) \\(CS[0-9]+\\):[ \t\n]*\\(.+\\)\\)"
580 1 3 nil 4)
581 ;; perl
582 ("\\(.*\\) at \\([^ \n]+\\) line \\([0-9]+\\)[,.\n]" 2 3 nil 1)
583 ;; PHP
584 ("\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)" 2 3 nil 1)
585 ;; LaTeX warnings (fileless) ("\\(LaTeX \\(Warning\\|Error\\): .*\\) on input line \\([0-9]+\\)" 20 3 nil 1)
586 ;; ant/javac. Note this also matches gcc warnings!
587 (" *\\(\\[javac\\] *\\)?\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\):\\([0-9]+\\)\\(?::[0-9]+\\)?:[ \t\n]*\\(.+\\)"
588 2 4 nil 5))
589 ;; compilation-error-regexp-alist)
590 (flymake-reformat-err-line-patterns-from-compile-el compilation-error-regexp-alist-alist))
591 "Patterns for matching error/warning lines. Each pattern has the form
592\(REGEXP FILE-IDX LINE-IDX COL-IDX ERR-TEXT-IDX).
593Use `flymake-reformat-err-line-patterns-from-compile-el' to add patterns
594from compile.el")
595
596(define-obsolete-variable-alias 'flymake-warning-re 'flymake-warning-predicate "24.4")
597(defvar flymake-warning-predicate "^[wW]arning"
598 "Predicate matching against error text to detect a warning.
599Takes a single argument, the error's text and should return non-nil
600if it's a warning.
601Instead of a function, it can also be a regular expression.")
602
603(defun flymake-parse-line (line)
604 "Parse LINE to see if it is an error or warning.
605Return its components if so, nil otherwise."
606 (let ((raw-file-name nil)
607 (line-no 0)
608 (err-type "e")
609 (err-text nil)
610 (patterns flymake-err-line-patterns)
611 (matched nil))
612 (while (and patterns (not matched))
613 (when (string-match (car (car patterns)) line)
614 (let* ((file-idx (nth 1 (car patterns)))
615 (line-idx (nth 2 (car patterns))))
616
617 (setq raw-file-name (if file-idx (match-string file-idx line) nil))
618 (setq line-no (if line-idx (string-to-number
619 (match-string line-idx line)) 0))
620 (setq err-text (if (> (length (car patterns)) 4)
621 (match-string (nth 4 (car patterns)) line)
622 (flymake-patch-err-text
623 (substring line (match-end 0)))))
624 (if (null err-text)
625 (setq err-text "<no error text>")
626 (when (cond ((stringp flymake-warning-predicate)
627 (string-match flymake-warning-predicate err-text))
628 ((functionp flymake-warning-predicate)
629 (funcall flymake-warning-predicate err-text)))
630 (setq err-type "w")))
631 (flymake-log
632 3 "parse line: file-idx=%s line-idx=%s file=%s line=%s text=%s"
633 file-idx line-idx raw-file-name line-no err-text)
634 (setq matched t)))
635 (setq patterns (cdr patterns)))
636 (if matched
637 (flymake-ler-make-ler raw-file-name line-no err-type err-text)
638 ())))
639
640(defun flymake-get-project-include-dirs-imp (basedir)
641 "Include dirs for the project current file belongs to."
642 (if (flymake-get-project-include-dirs-from-cache basedir)
643 (progn
644 (flymake-get-project-include-dirs-from-cache basedir))
645 ;;else
646 (let* ((command-line (concat "make -C "
647 (shell-quote-argument basedir)
648 " DUMPVARS=INCLUDE_DIRS dumpvars"))
649 (output (shell-command-to-string command-line))
650 (lines (split-string output "\n" t))
651 (count (length lines))
652 (idx 0)
653 (inc-dirs nil))
654 (while (and (< idx count) (not (string-match "^INCLUDE_DIRS=.*" (nth idx lines))))
655 (setq idx (1+ idx)))
656 (when (< idx count)
657 (let* ((inc-lines (split-string (nth idx lines) " *-I" t))
658 (inc-count (length inc-lines)))
659 (while (> inc-count 0)
660 (when (not (string-match "^INCLUDE_DIRS=.*" (nth (1- inc-count) inc-lines)))
661 (push (replace-regexp-in-string "\"" "" (nth (1- inc-count) inc-lines)) inc-dirs))
662 (setq inc-count (1- inc-count)))))
663 (flymake-add-project-include-dirs-to-cache basedir inc-dirs)
664 inc-dirs)))
665
666(defvar flymake-get-project-include-dirs-function #'flymake-get-project-include-dirs-imp
667 "Function used to get project include dirs, one parameter: basedir name.")
668
669(defun flymake-get-project-include-dirs (basedir)
670 (funcall flymake-get-project-include-dirs-function basedir))
671
672(defun flymake-get-system-include-dirs ()
673 "System include dirs - from the `INCLUDE' env setting."
674 (let* ((includes (getenv "INCLUDE")))
675 (if includes (split-string includes path-separator t) nil)))
676
677(defvar flymake-project-include-dirs-cache (make-hash-table :test #'equal))
678
679(defun flymake-get-project-include-dirs-from-cache (base-dir)
680 (gethash base-dir flymake-project-include-dirs-cache))
681
682(defun flymake-add-project-include-dirs-to-cache (base-dir include-dirs)
683 (puthash base-dir include-dirs flymake-project-include-dirs-cache))
684
685(defun flymake-clear-project-include-dirs-cache ()
686 (clrhash flymake-project-include-dirs-cache))
687
688(defun flymake-get-include-dirs (base-dir)
689 "Get dirs to use when resolving local file names."
690 (let* ((include-dirs (append '(".") (flymake-get-project-include-dirs base-dir) (flymake-get-system-include-dirs))))
691 include-dirs))
692
693;; (defun flymake-restore-formatting ()
694;; "Remove any formatting made by flymake."
695;; )
696
697;; (defun flymake-get-program-dir (buffer)
698;; "Get dir to start program in."
699;; (unless (bufferp buffer)
700;; (error "Invalid buffer"))
701;; (with-current-buffer buffer
702;; default-directory))
703
704(defun flymake-safe-delete-file (file-name)
705 (when (and file-name (file-exists-p file-name))
706 (delete-file file-name)
707 (flymake-log 1 "deleted file %s" file-name)))
708
709(defun flymake-safe-delete-directory (dir-name)
710 (condition-case nil
711 (progn
712 (delete-directory dir-name)
713 (flymake-log 1 "deleted dir %s" dir-name))
714 (error
715 (flymake-log 1 "Failed to delete dir %s, error ignored" dir-name))))
716
717(defun flymake-start-syntax-check ()
718 "Start syntax checking for current buffer."
719 (interactive)
720 (flymake-log 3 "flymake is running: %s" flymake-is-running)
721 (when (and (not flymake-is-running)
722 (flymake-can-syntax-check-file buffer-file-name))
723 (when (or (not flymake-compilation-prevents-syntax-check)
724 (not (flymake-compilation-is-running))) ;+ (flymake-rep-ort-status buffer "COMP")
725 (flymake-clear-buildfile-cache)
726 (flymake-clear-project-include-dirs-cache)
727
728 (setq flymake-check-was-interrupted nil)
729
730 (let* ((source-file-name buffer-file-name)
731 (init-f (flymake-get-init-function source-file-name))
732 (cleanup-f (flymake-get-cleanup-function source-file-name))
733 (cmd-and-args (funcall init-f))
734 (cmd (nth 0 cmd-and-args))
735 (args (nth 1 cmd-and-args))
736 (dir (nth 2 cmd-and-args)))
737 (if (not cmd-and-args)
738 (progn
739 (flymake-log 0 "init function %s for %s failed, cleaning up" init-f source-file-name)
740 (funcall cleanup-f))
741 (progn
742 (setq flymake-last-change-time nil)
743 (flymake-start-syntax-check-process cmd args dir)))))))
744
745(defun flymake-start-syntax-check-process (cmd args dir)
746 "Start syntax check process."
747 (condition-case err
748 (let* ((process
749 (let ((default-directory (or dir default-directory)))
750 (when dir
751 (flymake-log 3 "starting process on dir %s" dir))
752 (apply 'start-file-process
753 "flymake-proc" (current-buffer) cmd args))))
754 (set-process-sentinel process 'flymake-process-sentinel)
755 (set-process-filter process 'flymake-process-filter)
756 (set-process-query-on-exit-flag process nil)
757 (push process flymake-processes)
758
759 (setq flymake-is-running t)
760 (setq flymake-last-change-time nil)
761 (setq flymake-check-start-time (float-time))
762
763 (flymake-report-status nil "*")
764 (flymake-log 2 "started process %d, command=%s, dir=%s"
765 (process-id process) (process-command process)
766 default-directory)
767 process)
768 (error
769 (let* ((err-str
770 (format-message
771 "Failed to launch syntax check process `%s' with args %s: %s"
772 cmd args (error-message-string err)))
773 (source-file-name buffer-file-name)
774 (cleanup-f (flymake-get-cleanup-function source-file-name)))
775 (flymake-log 0 err-str)
776 (funcall cleanup-f)
777 (flymake-report-fatal-status "PROCERR" err-str)))))
778
779(defun flymake-kill-process (proc)
780 "Kill process PROC."
781 (kill-process proc)
782 (let* ((buf (process-buffer proc)))
783 (when (buffer-live-p buf)
784 (with-current-buffer buf
785 (setq flymake-check-was-interrupted t))))
786 (flymake-log 1 "killed process %d" (process-id proc)))
787
788(defun flymake-stop-all-syntax-checks ()
789 "Kill all syntax check processes."
790 (interactive)
791 (while flymake-processes
792 (flymake-kill-process (pop flymake-processes))))
793
794(defun flymake-compilation-is-running ()
795 (and (boundp 'compilation-in-progress)
796 compilation-in-progress))
797
798(defun flymake-compile ()
799 "Kill all flymake syntax checks, start compilation."
800 (interactive)
801 (flymake-stop-all-syntax-checks)
802 (call-interactively 'compile))
803
804;;;; general init-cleanup and helper routines
805(defun flymake-create-temp-inplace (file-name prefix)
806 (unless (stringp file-name)
807 (error "Invalid file-name"))
808 (or prefix
809 (setq prefix "flymake"))
810 (let* ((ext (file-name-extension file-name))
811 (temp-name (file-truename
812 (concat (file-name-sans-extension file-name)
813 "_" prefix
814 (and ext (concat "." ext))))))
815 (flymake-log 3 "create-temp-inplace: file=%s temp=%s" file-name temp-name)
816 temp-name))
817
818(defun flymake-create-temp-with-folder-structure (file-name _prefix)
819 (unless (stringp file-name)
820 (error "Invalid file-name"))
821
822 (let* ((dir (file-name-directory file-name))
823 ;; Not sure what this slash-pos is all about, but I guess it's just
824 ;; trying to remove the leading / of absolute file names.
825 (slash-pos (string-match "/" dir))
826 (temp-dir (expand-file-name (substring dir (1+ slash-pos))
827 temporary-file-directory)))
828
829 (file-truename (expand-file-name (file-name-nondirectory file-name)
830 temp-dir))))
831
832(defun flymake-delete-temp-directory (dir-name)
833 "Attempt to delete temp dir created by `flymake-create-temp-with-folder-structure', do not fail on error."
834 (let* ((temp-dir temporary-file-directory)
835 (suffix (substring dir-name (1+ (length temp-dir)))))
836
837 (while (> (length suffix) 0)
838 (setq suffix (directory-file-name suffix))
839 ;;+(flymake-log 0 "suffix=%s" suffix)
840 (flymake-safe-delete-directory
841 (file-truename (expand-file-name suffix temp-dir)))
842 (setq suffix (file-name-directory suffix)))))
843
844(defvar-local flymake-temp-source-file-name nil)
845(defvar-local flymake-master-file-name nil)
846(defvar-local flymake-temp-master-file-name nil)
847(defvar-local flymake-base-dir nil)
848
849(defun flymake-init-create-temp-buffer-copy (create-temp-f)
850 "Make a temporary copy of the current buffer, save its name in buffer data and return the name."
851 (let* ((source-file-name buffer-file-name)
852 (temp-source-file-name (funcall create-temp-f source-file-name "flymake")))
853
854 (flymake-save-buffer-in-file temp-source-file-name)
855 (setq flymake-temp-source-file-name temp-source-file-name)
856 temp-source-file-name))
857
858(defun flymake-simple-cleanup ()
859 "Do cleanup after `flymake-init-create-temp-buffer-copy'.
860Delete temp file."
861 (flymake-safe-delete-file flymake-temp-source-file-name)
862 (setq flymake-last-change-time nil))
863
864(defun flymake-get-real-file-name (file-name-from-err-msg)
865 "Translate file name from error message to \"real\" file name.
866Return full-name. Names are real, not patched."
867 (let* ((real-name nil)
868 (source-file-name buffer-file-name)
869 (master-file-name flymake-master-file-name)
870 (temp-source-file-name flymake-temp-source-file-name)
871 (temp-master-file-name flymake-temp-master-file-name)
872 (base-dirs
873 (list flymake-base-dir
874 (file-name-directory source-file-name)
875 (if master-file-name (file-name-directory master-file-name))))
876 (files (list (list source-file-name source-file-name)
877 (list temp-source-file-name source-file-name)
878 (list master-file-name master-file-name)
879 (list temp-master-file-name master-file-name))))
880
881 (when (equal 0 (length file-name-from-err-msg))
882 (setq file-name-from-err-msg source-file-name))
883
884 (setq real-name (flymake-get-full-patched-file-name file-name-from-err-msg base-dirs files))
885 ;; if real-name is nil, than file name from err msg is none of the files we've patched
886 (if (not real-name)
887 (setq real-name (flymake-get-full-nonpatched-file-name file-name-from-err-msg base-dirs)))
888 (if (not real-name)
889 (setq real-name file-name-from-err-msg))
890 (setq real-name (flymake-fix-file-name real-name))
891 (flymake-log 3 "get-real-file-name: file-name=%s real-name=%s" file-name-from-err-msg real-name)
892 real-name))
893
894(defun flymake-get-full-patched-file-name (file-name-from-err-msg base-dirs files)
895 (let* ((base-dirs-count (length base-dirs))
896 (file-count (length files))
897 (real-name nil))
898
899 (while (and (not real-name) (> base-dirs-count 0))
900 (setq file-count (length files))
901 (while (and (not real-name) (> file-count 0))
902 (let* ((this-dir (nth (1- base-dirs-count) base-dirs))
903 (this-file (nth 0 (nth (1- file-count) files)))
904 (this-real-name (nth 1 (nth (1- file-count) files))))
905 ;;+(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)
906 (when (and this-dir this-file (flymake-same-files
907 (expand-file-name file-name-from-err-msg this-dir)
908 this-file))
909 (setq real-name this-real-name)))
910 (setq file-count (1- file-count)))
911 (setq base-dirs-count (1- base-dirs-count)))
912 real-name))
913
914(defun flymake-get-full-nonpatched-file-name (file-name-from-err-msg base-dirs)
915 (let* ((real-name nil))
916 (if (file-name-absolute-p file-name-from-err-msg)
917 (setq real-name file-name-from-err-msg)
918 (let* ((base-dirs-count (length base-dirs)))
919 (while (and (not real-name) (> base-dirs-count 0))
920 (let* ((full-name (expand-file-name file-name-from-err-msg
921 (nth (1- base-dirs-count) base-dirs))))
922 (if (file-exists-p full-name)
923 (setq real-name full-name))
924 (setq base-dirs-count (1- base-dirs-count))))))
925 real-name))
926
927(defun flymake-init-find-buildfile-dir (source-file-name buildfile-name)
928 "Find buildfile, store its dir in buffer data and return its dir, if found."
929 (let* ((buildfile-dir
930 (flymake-find-buildfile buildfile-name
931 (file-name-directory source-file-name))))
932 (if buildfile-dir
933 (setq flymake-base-dir buildfile-dir)
934 (flymake-log 1 "no buildfile (%s) for %s" buildfile-name source-file-name)
935 (flymake-report-fatal-status
936 "NOMK" (format "No buildfile (%s) found for %s"
937 buildfile-name source-file-name)))))
938
939(defun flymake-init-create-temp-source-and-master-buffer-copy (get-incl-dirs-f create-temp-f master-file-masks include-regexp)
940 "Find master file (or buffer), create its copy along with a copy of the source file."
941 (let* ((source-file-name buffer-file-name)
942 (temp-source-file-name (flymake-init-create-temp-buffer-copy create-temp-f))
943 (master-and-temp-master (flymake-create-master-file
944 source-file-name temp-source-file-name
945 get-incl-dirs-f create-temp-f
946 master-file-masks include-regexp)))
947
948 (if (not master-and-temp-master)
949 (progn
950 (flymake-log 1 "cannot find master file for %s" source-file-name)
951 (flymake-report-status "!" "") ; NOMASTER
952 nil)
953 (setq flymake-master-file-name (nth 0 master-and-temp-master))
954 (setq flymake-temp-master-file-name (nth 1 master-and-temp-master)))))
955
956(defun flymake-master-cleanup ()
957 (flymake-simple-cleanup)
958 (flymake-safe-delete-file flymake-temp-master-file-name))
959
960;;;; make-specific init-cleanup routines
961(defun flymake-get-syntax-check-program-args (source-file-name base-dir use-relative-base-dir use-relative-source get-cmd-line-f)
962 "Create a command line for syntax check using GET-CMD-LINE-F."
963 (funcall get-cmd-line-f
964 (if use-relative-source
965 (file-relative-name source-file-name base-dir)
966 source-file-name)
967 (if use-relative-base-dir
968 (file-relative-name base-dir
969 (file-name-directory source-file-name))
970 base-dir)))
971
972(defun flymake-get-make-cmdline (source base-dir)
973 (list "make"
974 (list "-s"
975 "-C"
976 base-dir
977 (concat "CHK_SOURCES=" source)
978 "SYNTAX_CHECK_MODE=1"
979 "check-syntax")))
980
981(defun flymake-get-ant-cmdline (source base-dir)
982 (list "ant"
983 (list "-buildfile"
984 (concat base-dir "/" "build.xml")
985 (concat "-DCHK_SOURCES=" source)
986 "check-syntax")))
987
988(defun flymake-simple-make-init-impl (create-temp-f use-relative-base-dir use-relative-source build-file-name get-cmdline-f)
989 "Create syntax check command line for a directly checked source file.
990Use CREATE-TEMP-F for creating temp copy."
991 (let* ((args nil)
992 (source-file-name buffer-file-name)
993 (buildfile-dir (flymake-init-find-buildfile-dir source-file-name build-file-name)))
994 (if buildfile-dir
995 (let* ((temp-source-file-name (flymake-init-create-temp-buffer-copy create-temp-f)))
996 (setq args (flymake-get-syntax-check-program-args temp-source-file-name buildfile-dir
997 use-relative-base-dir use-relative-source
998 get-cmdline-f))))
999 args))
1000
1001(defun flymake-simple-make-init ()
1002 (flymake-simple-make-init-impl 'flymake-create-temp-inplace t t "Makefile" 'flymake-get-make-cmdline))
1003
1004(defun flymake-master-make-init (get-incl-dirs-f master-file-masks include-regexp)
1005 "Create make command line for a source file checked via master file compilation."
1006 (let* ((make-args nil)
1007 (temp-master-file-name (flymake-init-create-temp-source-and-master-buffer-copy
1008 get-incl-dirs-f 'flymake-create-temp-inplace
1009 master-file-masks include-regexp)))
1010 (when temp-master-file-name
1011 (let* ((buildfile-dir (flymake-init-find-buildfile-dir temp-master-file-name "Makefile")))
1012 (if buildfile-dir
1013 (setq make-args (flymake-get-syntax-check-program-args
1014 temp-master-file-name buildfile-dir nil nil 'flymake-get-make-cmdline)))))
1015 make-args))
1016
1017(defun flymake-find-make-buildfile (source-dir)
1018 (flymake-find-buildfile "Makefile" source-dir))
1019
1020;;;; .h/make specific
1021(defun flymake-master-make-header-init ()
1022 (flymake-master-make-init
1023 'flymake-get-include-dirs
1024 '("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'")
1025 "[ \t]*#[ \t]*include[ \t]*\"\\([[:word:]0-9/\\_.]*%s\\)\""))
1026
1027;;;; .java/make specific
1028(defun flymake-simple-make-java-init ()
1029 (flymake-simple-make-init-impl 'flymake-create-temp-with-folder-structure nil nil "Makefile" 'flymake-get-make-cmdline))
1030
1031(defun flymake-simple-ant-java-init ()
1032 (flymake-simple-make-init-impl 'flymake-create-temp-with-folder-structure nil nil "build.xml" 'flymake-get-ant-cmdline))
1033
1034(defun flymake-simple-java-cleanup ()
1035 "Cleanup after `flymake-simple-make-java-init' -- delete temp file and dirs."
1036 (flymake-safe-delete-file flymake-temp-source-file-name)
1037 (when flymake-temp-source-file-name
1038 (flymake-delete-temp-directory
1039 (file-name-directory flymake-temp-source-file-name))))
1040
1041;;;; perl-specific init-cleanup routines
1042(defun flymake-perl-init ()
1043 (let* ((temp-file (flymake-init-create-temp-buffer-copy
1044 'flymake-create-temp-inplace))
1045 (local-file (file-relative-name
1046 temp-file
1047 (file-name-directory buffer-file-name))))
1048 (list "perl" (list "-wc " local-file))))
1049
1050;;;; php-specific init-cleanup routines
1051(defun flymake-php-init ()
1052 (let* ((temp-file (flymake-init-create-temp-buffer-copy
1053 'flymake-create-temp-inplace))
1054 (local-file (file-relative-name
1055 temp-file
1056 (file-name-directory buffer-file-name))))
1057 (list "php" (list "-f" local-file "-l"))))
1058
1059;;;; tex-specific init-cleanup routines
1060(defun flymake-get-tex-args (file-name)
1061 ;;(list "latex" (list "-c-style-errors" file-name))
1062 (list "texify" (list "--pdf" "--tex-option=-c-style-errors" file-name)))
1063
1064(defun flymake-simple-tex-init ()
1065 (flymake-get-tex-args (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)))
1066
1067;; Perhaps there should be a buffer-local variable flymake-master-file
1068;; that people can set to override this stuff. Could inherit from
1069;; the similar AUCTeX variable.
1070(defun flymake-master-tex-init ()
1071 (let* ((temp-master-file-name (flymake-init-create-temp-source-and-master-buffer-copy
1072 'flymake-get-include-dirs-dot 'flymake-create-temp-inplace
1073 '("\\.tex\\'")
1074 "[ \t]*\\in\\(?:put\\|clude\\)[ \t]*{\\(.*%s\\)}")))
1075 (when temp-master-file-name
1076 (flymake-get-tex-args temp-master-file-name))))
1077
1078(defun flymake-get-include-dirs-dot (_base-dir)
1079 '("."))
1080
1081;;;; xml-specific init-cleanup routines
1082(defun flymake-xml-init ()
1083 (list flymake-xml-program
1084 (list "val" (flymake-init-create-temp-buffer-copy
1085 'flymake-create-temp-inplace))))
1086
1087(provide 'flymake-proc)
1088;;; 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..c1dffb4e7ef
--- /dev/null
+++ b/lisp/progmodes/flymake-ui.el
@@ -0,0 +1,601 @@
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(defvar-local flymake-timer nil
112 "Timer for starting syntax check.")
113
114(defvar-local flymake-last-change-time nil
115 "Time of last buffer change.")
116
117(defvar-local flymake-check-start-time nil
118 "Time at which syntax check was started.")
119
120(defvar-local flymake-check-was-interrupted nil
121 "Non-nil if syntax check was killed by `flymake-compile'.")
122
123(defvar-local flymake-err-info nil
124 "Sorted list of line numbers and lists of err info in the form (file, err-text).")
125
126(defvar-local flymake-new-err-info nil
127 "Same as `flymake-err-info', effective when a syntax check is in progress.")
128
129(defun flymake-log (level text &rest args)
130 "Log a message at level LEVEL.
131If LEVEL is higher than `flymake-log-level', the message is
132ignored. Otherwise, it is printed using `message'.
133TEXT is a format control string, and the remaining arguments ARGS
134are the string substitutions (see the function `format')."
135 (if (<= level flymake-log-level)
136 (let* ((msg (apply #'format-message text args)))
137 (message "%s" msg))))
138
139(defun flymake-ins-after (list pos val)
140 "Insert VAL into LIST after position POS.
141POS counts from zero."
142 (let ((tmp (copy-sequence list)))
143 (setcdr (nthcdr pos tmp) (cons val (nthcdr (1+ pos) tmp)))
144 tmp))
145
146(defun flymake-set-at (list pos val)
147 "Set VAL at position POS in LIST.
148POS counts from zero."
149 (let ((tmp (copy-sequence list)))
150 (setcar (nthcdr pos tmp) val)
151 tmp))
152
153(defun flymake-er-make-er (line-no line-err-info-list)
154 (list line-no line-err-info-list))
155
156(defun flymake-er-get-line (err-info)
157 (nth 0 err-info))
158
159(defun flymake-er-get-line-err-info-list (err-info)
160 (nth 1 err-info))
161
162(cl-defstruct (flymake-ler
163 (:constructor nil)
164 (:constructor flymake-ler-make-ler (file line type text &optional full-file)))
165 file line type text full-file)
166
167(defun flymake-ler-set-file (line-err-info file)
168 (flymake-ler-make-ler file
169 (flymake-ler-line line-err-info)
170 (flymake-ler-type line-err-info)
171 (flymake-ler-text line-err-info)
172 (flymake-ler-full-file line-err-info)))
173
174(defun flymake-ler-set-full-file (line-err-info full-file)
175 (flymake-ler-make-ler (flymake-ler-file line-err-info)
176 (flymake-ler-line line-err-info)
177 (flymake-ler-type line-err-info)
178 (flymake-ler-text line-err-info)
179 full-file))
180
181(defun flymake-ler-set-line (line-err-info line)
182 (flymake-ler-make-ler (flymake-ler-file line-err-info)
183 line
184 (flymake-ler-type line-err-info)
185 (flymake-ler-text line-err-info)
186 (flymake-ler-full-file line-err-info)))
187
188(defun flymake-get-line-err-count (line-err-info-list type)
189 "Return number of errors of specified TYPE.
190Value of TYPE is either \"e\" or \"w\"."
191 (let* ((idx 0)
192 (count (length line-err-info-list))
193 (err-count 0))
194
195 (while (< idx count)
196 (when (equal type (flymake-ler-type (nth idx line-err-info-list)))
197 (setq err-count (1+ err-count)))
198 (setq idx (1+ idx)))
199 err-count))
200
201(defun flymake-get-err-count (err-info-list type)
202 "Return number of errors of specified TYPE for ERR-INFO-LIST."
203 (let* ((idx 0)
204 (count (length err-info-list))
205 (err-count 0))
206 (while (< idx count)
207 (setq err-count (+ err-count (flymake-get-line-err-count (nth 1 (nth idx err-info-list)) type)))
208 (setq idx (1+ idx)))
209 err-count))
210
211(defun flymake-highlight-err-lines (err-info-list)
212 "Highlight error lines in BUFFER using info from ERR-INFO-LIST."
213 (save-excursion
214 (dolist (err err-info-list)
215 (flymake-highlight-line (car err) (nth 1 err)))))
216
217(defun flymake-overlay-p (ov)
218 "Determine whether overlay OV was created by flymake."
219 (and (overlayp ov) (overlay-get ov 'flymake-overlay)))
220
221(defun flymake-make-overlay (beg end tooltip-text face bitmap)
222 "Allocate a flymake overlay in range BEG and END."
223 (when (not (flymake-region-has-flymake-overlays beg end))
224 (let ((ov (make-overlay beg end nil t))
225 (fringe (and flymake-fringe-indicator-position
226 (propertize "!" 'display
227 (cons flymake-fringe-indicator-position
228 (if (listp bitmap)
229 bitmap
230 (list bitmap)))))))
231 (overlay-put ov 'face face)
232 (overlay-put ov 'help-echo tooltip-text)
233 (overlay-put ov 'flymake-overlay t)
234 (overlay-put ov 'priority 100)
235 (overlay-put ov 'evaporate t)
236 (overlay-put ov 'before-string fringe)
237 ;;+(flymake-log 3 "created overlay %s" ov)
238 ov)
239 (flymake-log 3 "created an overlay at (%d-%d)" beg end)))
240
241(defun flymake-delete-own-overlays ()
242 "Delete all flymake overlays in BUFFER."
243 (dolist (ol (overlays-in (point-min) (point-max)))
244 (when (flymake-overlay-p ol)
245 (delete-overlay ol)
246 ;;+(flymake-log 3 "deleted overlay %s" ol)
247 )))
248
249(defun flymake-region-has-flymake-overlays (beg end)
250 "Check if region specified by BEG and END has overlay.
251Return t if it has at least one flymake overlay, nil if no overlay."
252 (let ((ov (overlays-in beg end))
253 (has-flymake-overlays nil))
254 (while (consp ov)
255 (when (flymake-overlay-p (car ov))
256 (setq has-flymake-overlays t))
257 (setq ov (cdr ov)))
258 has-flymake-overlays))
259
260(defface flymake-errline
261 '((((supports :underline (:style wave)))
262 :underline (:style wave :color "Red1"))
263 (t
264 :inherit error))
265 "Face used for marking error lines."
266 :version "24.4"
267 :group 'flymake)
268
269(defface flymake-warnline
270 '((((supports :underline (:style wave)))
271 :underline (:style wave :color "DarkOrange"))
272 (t
273 :inherit warning))
274 "Face used for marking warning lines."
275 :version "24.4"
276 :group 'flymake)
277
278(defun flymake-highlight-line (line-no line-err-info-list)
279 "Highlight line LINE-NO in current buffer.
280Perhaps use text from LINE-ERR-INFO-LIST to enhance highlighting."
281 (goto-char (point-min))
282 (forward-line (1- line-no))
283 (pcase-let* ((beg (progn (back-to-indentation) (point)))
284 (end (progn
285 (end-of-line)
286 (skip-chars-backward " \t\f\t\n" beg)
287 (if (eq (point) beg)
288 (line-beginning-position 2)
289 (point))))
290 (tooltip-text (mapconcat #'flymake-ler-text line-err-info-list "\n"))
291 (`(,face ,bitmap)
292 (if (> (flymake-get-line-err-count line-err-info-list "e") 0)
293 (list 'flymake-errline flymake-error-bitmap)
294 (list 'flymake-warnline flymake-warning-bitmap))))
295 (flymake-make-overlay beg end tooltip-text face bitmap)))
296
297(defun flymake-find-err-info (err-info-list line-no)
298 "Find (line-err-info-list pos) for specified LINE-NO."
299 (if err-info-list
300 (let* ((line-err-info-list nil)
301 (pos 0)
302 (count (length err-info-list)))
303
304 (while (and (< pos count) (< (car (nth pos err-info-list)) line-no))
305 (setq pos (1+ pos)))
306 (when (and (< pos count) (equal (car (nth pos err-info-list)) line-no))
307 (setq line-err-info-list (flymake-er-get-line-err-info-list (nth pos err-info-list))))
308 (list line-err-info-list pos))
309 '(nil 0)))
310
311(defun flymake-line-err-info-is-less-or-equal (line-one line-two)
312 (or (string< (flymake-ler-type line-one) (flymake-ler-type line-two))
313 (and (string= (flymake-ler-type line-one) (flymake-ler-type line-two))
314 (not (flymake-ler-file line-one)) (flymake-ler-file line-two))
315 (and (string= (flymake-ler-type line-one) (flymake-ler-type line-two))
316 (or (and (flymake-ler-file line-one) (flymake-ler-file line-two))
317 (and (not (flymake-ler-file line-one)) (not (flymake-ler-file line-two)))))))
318
319(defun flymake-add-line-err-info (line-err-info-list line-err-info)
320 "Update LINE-ERR-INFO-LIST with the error LINE-ERR-INFO.
321For the format of LINE-ERR-INFO, see `flymake-ler-make-ler'.
322The new element is inserted in the proper position, according to
323the predicate `flymake-line-err-info-is-less-or-equal'.
324The updated value of LINE-ERR-INFO-LIST is returned."
325 (if (not line-err-info-list)
326 (list line-err-info)
327 (let* ((count (length line-err-info-list))
328 (idx 0))
329 (while (and (< idx count) (flymake-line-err-info-is-less-or-equal (nth idx line-err-info-list) line-err-info))
330 (setq idx (1+ idx)))
331 (cond ((equal 0 idx) (setq line-err-info-list (cons line-err-info line-err-info-list)))
332 (t (setq line-err-info-list (flymake-ins-after line-err-info-list (1- idx) line-err-info))))
333 line-err-info-list)))
334
335(defun flymake-add-err-info (err-info-list line-err-info)
336 "Update ERR-INFO-LIST with the error LINE-ERR-INFO, preserving sort order.
337Returns the updated value of ERR-INFO-LIST.
338For the format of ERR-INFO-LIST, see `flymake-err-info'.
339For the format of LINE-ERR-INFO, see `flymake-ler-make-ler'."
340 (let* ((line-no (if (flymake-ler-file line-err-info) 1 (flymake-ler-line line-err-info)))
341 (info-and-pos (flymake-find-err-info err-info-list line-no))
342 (exists (car info-and-pos))
343 (pos (nth 1 info-and-pos))
344 (line-err-info-list nil)
345 (err-info nil))
346
347 (if exists
348 (setq line-err-info-list (flymake-er-get-line-err-info-list (car (nthcdr pos err-info-list)))))
349 (setq line-err-info-list (flymake-add-line-err-info line-err-info-list line-err-info))
350
351 (setq err-info (flymake-er-make-er line-no line-err-info-list))
352 (cond (exists (setq err-info-list (flymake-set-at err-info-list pos err-info)))
353 ((equal 0 pos) (setq err-info-list (cons err-info err-info-list)))
354 (t (setq err-info-list (flymake-ins-after err-info-list (1- pos) err-info))))
355 err-info-list))
356
357(defvar-local flymake-is-running nil
358 "If t, flymake syntax check process is running for the current buffer.")
359
360(defun flymake-on-timer-event (buffer)
361 "Start a syntax check for buffer BUFFER if necessary."
362 (when (buffer-live-p buffer)
363 (with-current-buffer buffer
364 (when (and (not flymake-is-running)
365 flymake-last-change-time
366 (> (- (float-time) flymake-last-change-time)
367 flymake-no-changes-timeout))
368
369 (setq flymake-last-change-time nil)
370 (flymake-log 3 "starting syntax check as more than 1 second passed since last change")
371 (flymake-start-syntax-check)))))
372
373(define-obsolete-function-alias 'flymake-display-err-menu-for-current-line
374 'flymake-popup-current-error-menu "24.4")
375
376(defun flymake-popup-current-error-menu (&optional event)
377 "Pop up a menu with errors/warnings for current line."
378 (interactive (list last-nonmenu-event))
379 (let* ((line-no (line-number-at-pos))
380 (errors (or (car (flymake-find-err-info flymake-err-info line-no))
381 (user-error "No errors for current line")))
382 (menu (mapcar (lambda (x)
383 (if (flymake-ler-file x)
384 (cons (format "%s - %s(%d)"
385 (flymake-ler-text x)
386 (flymake-ler-file x)
387 (flymake-ler-line x))
388 x)
389 (list (flymake-ler-text x))))
390 errors))
391 (event (if (mouse-event-p event)
392 event
393 (list 'mouse-1 (posn-at-point))))
394 (title (format "Line %d: %d error(s), %d warning(s)"
395 line-no
396 (flymake-get-line-err-count errors "e")
397 (flymake-get-line-err-count errors "w")))
398 (choice (x-popup-menu event (list title (cons "" menu)))))
399 (flymake-log 3 "choice=%s" choice)
400 (when choice
401 (flymake-goto-file-and-line (flymake-ler-full-file choice)
402 (flymake-ler-line choice)))))
403
404(defun flymake-goto-file-and-line (file line)
405 "Try to get buffer for FILE and goto line LINE in it."
406 (if (not (file-exists-p file))
407 (flymake-log 1 "File %s does not exist" file)
408 (find-file file)
409 (goto-char (point-min))
410 (forward-line (1- line))))
411
412;; flymake minor mode declarations
413(defvar-local flymake-mode-line nil)
414(defvar-local flymake-mode-line-e-w nil)
415(defvar-local flymake-mode-line-status nil)
416
417(defun flymake-report-status (e-w &optional status)
418 "Show status in mode line."
419 (when e-w
420 (setq flymake-mode-line-e-w e-w))
421 (when status
422 (setq flymake-mode-line-status status))
423 (let* ((mode-line " Flymake"))
424 (when (> (length flymake-mode-line-e-w) 0)
425 (setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
426 (setq mode-line (concat mode-line flymake-mode-line-status))
427 (setq flymake-mode-line mode-line)
428 (force-mode-line-update)))
429
430;; Nothing in flymake uses this at all any more, so this is just for
431;; third-party compatibility.
432(define-obsolete-function-alias 'flymake-display-warning 'message-box "26.1")
433
434(defun flymake-report-fatal-status (status warning)
435 "Display a warning and switch flymake mode off."
436 ;; This first message was always shown by default, and flymake-log
437 ;; does nothing by default, hence the use of message.
438 ;; Another option is display-warning.
439 (if (< flymake-log-level 0)
440 (message "Flymake: %s. Flymake will be switched OFF" warning))
441 (flymake-mode 0)
442 (flymake-log 0 "switched OFF Flymake mode for buffer %s due to fatal status %s, warning %s"
443 (buffer-name) status warning))
444
445;;;###autoload
446(define-minor-mode flymake-mode nil
447 :group 'flymake :lighter flymake-mode-line
448 (cond
449
450 ;; Turning the mode ON.
451 (flymake-mode
452 (cond
453 ((not buffer-file-name)
454 (message "Flymake unable to run without a buffer file name"))
455 ((not (flymake-can-syntax-check-file buffer-file-name))
456 (flymake-log 2 "flymake cannot check syntax in buffer %s" (buffer-name)))
457 (t
458 (add-hook 'after-change-functions 'flymake-after-change-function nil t)
459 (add-hook 'after-save-hook 'flymake-after-save-hook nil t)
460 (add-hook 'kill-buffer-hook 'flymake-kill-buffer-hook nil t)
461 ;;+(add-hook 'find-file-hook 'flymake-find-file-hook)
462
463 (flymake-report-status "" "")
464
465 (setq flymake-timer
466 (run-at-time nil 1 'flymake-on-timer-event (current-buffer)))
467
468 (when (and flymake-start-syntax-check-on-find-file
469 ;; Since we write temp files in current dir, there's no point
470 ;; trying if the directory is read-only (bug#8954).
471 (file-writable-p (file-name-directory buffer-file-name)))
472 (with-demoted-errors
473 (flymake-start-syntax-check))))))
474
475 ;; Turning the mode OFF.
476 (t
477 (remove-hook 'after-change-functions 'flymake-after-change-function t)
478 (remove-hook 'after-save-hook 'flymake-after-save-hook t)
479 (remove-hook 'kill-buffer-hook 'flymake-kill-buffer-hook t)
480 ;;+(remove-hook 'find-file-hook (function flymake-find-file-hook) t)
481
482 (flymake-delete-own-overlays)
483
484 (when flymake-timer
485 (cancel-timer flymake-timer)
486 (setq flymake-timer nil))
487
488 (setq flymake-is-running nil))))
489
490;;;###autoload
491(defun flymake-mode-on ()
492 "Turn flymake mode on."
493 (flymake-mode 1)
494 (flymake-log 1 "flymake mode turned ON for buffer %s" (buffer-name)))
495
496;;;###autoload
497(defun flymake-mode-off ()
498 "Turn flymake mode off."
499 (flymake-mode 0)
500 (flymake-log 1 "flymake mode turned OFF for buffer %s" (buffer-name)))
501
502(defun flymake-after-change-function (start stop _len)
503 "Start syntax check for current buffer if it isn't already running."
504 ;;+(flymake-log 0 "setting change time to %s" (float-time))
505 (let((new-text (buffer-substring start stop)))
506 (when (and flymake-start-syntax-check-on-newline (equal new-text "\n"))
507 (flymake-log 3 "starting syntax check as new-line has been seen")
508 (flymake-start-syntax-check))
509 (setq flymake-last-change-time (float-time))))
510
511(defun flymake-after-save-hook ()
512 (if (local-variable-p 'flymake-mode (current-buffer)) ; (???) other way to determine whether flymake is active in buffer being saved?
513 (progn
514 (flymake-log 3 "starting syntax check as buffer was saved")
515 (flymake-start-syntax-check)))) ; no more mode 3. cannot start check if mode 3 (to temp copies) is active - (???)
516
517(defun flymake-kill-buffer-hook ()
518 (when flymake-timer
519 (cancel-timer flymake-timer)
520 (setq flymake-timer nil)))
521
522;;;###autoload
523(defun flymake-find-file-hook ()
524 ;;+(when flymake-start-syntax-check-on-find-file
525 ;;+ (flymake-log 3 "starting syntax check on file open")
526 ;;+ (flymake-start-syntax-check)
527 ;;+)
528 (when (and (not (local-variable-p 'flymake-mode (current-buffer)))
529 (flymake-can-syntax-check-file buffer-file-name))
530 (flymake-mode)
531 (flymake-log 3 "automatically turned ON flymake mode")))
532
533(defun flymake-get-first-err-line-no (err-info-list)
534 "Return first line with error."
535 (when err-info-list
536 (flymake-er-get-line (car err-info-list))))
537
538(defun flymake-get-last-err-line-no (err-info-list)
539 "Return last line with error."
540 (when err-info-list
541 (flymake-er-get-line (nth (1- (length err-info-list)) err-info-list))))
542
543(defun flymake-get-next-err-line-no (err-info-list line-no)
544 "Return next line with error."
545 (when err-info-list
546 (let* ((count (length err-info-list))
547 (idx 0))
548 (while (and (< idx count) (>= line-no (flymake-er-get-line (nth idx err-info-list))))
549 (setq idx (1+ idx)))
550 (if (< idx count)
551 (flymake-er-get-line (nth idx err-info-list))))))
552
553(defun flymake-get-prev-err-line-no (err-info-list line-no)
554 "Return previous line with error."
555 (when err-info-list
556 (let* ((count (length err-info-list)))
557 (while (and (> count 0) (<= line-no (flymake-er-get-line (nth (1- count) err-info-list))))
558 (setq count (1- count)))
559 (if (> count 0)
560 (flymake-er-get-line (nth (1- count) err-info-list))))))
561
562(defun flymake-skip-whitespace ()
563 "Move forward until non-whitespace is reached."
564 (while (looking-at "[ \t]")
565 (forward-char)))
566
567(defun flymake-goto-line (line-no)
568 "Go to line LINE-NO, then skip whitespace."
569 (goto-char (point-min))
570 (forward-line (1- line-no))
571 (flymake-skip-whitespace))
572
573(defun flymake-goto-next-error ()
574 "Go to next error in err ring."
575 (interactive)
576 (let ((line-no (flymake-get-next-err-line-no flymake-err-info (line-number-at-pos))))
577 (when (not line-no)
578 (setq line-no (flymake-get-first-err-line-no flymake-err-info))
579 (flymake-log 1 "passed end of file"))
580 (if line-no
581 (flymake-goto-line line-no)
582 (flymake-log 1 "no errors in current buffer"))))
583
584(defun flymake-goto-prev-error ()
585 "Go to previous error in err ring."
586 (interactive)
587 (let ((line-no (flymake-get-prev-err-line-no flymake-err-info (line-number-at-pos))))
588 (when (not line-no)
589 (setq line-no (flymake-get-last-err-line-no flymake-err-info))
590 (flymake-log 1 "passed beginning of file"))
591 (if line-no
592 (flymake-goto-line line-no)
593 (flymake-log 1 "no errors in current buffer"))))
594
595(defun flymake-patch-err-text (string)
596 (if (string-match "^[\n\t :0-9]*\\(.*\\)$" string)
597 (match-string 1 string)
598 string))
599
600(provide 'flymake-ui)
601;;; 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