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