annotate lisp/progmodes/flymake.el @ 59865:87daa7a3dc1f

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