0
|
1 ;;; compile.el --- run compiler as inferior of Emacs, parse error messages.
|
|
2
|
2
|
3 ;; Copyright (C) 1985, 86, 87, 93, 94, 1995, 1996 Free Software Foundation, Inc.
|
0
|
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
|
5
|
|
6 ;; Author: Roland McGrath <roland@prep.ai.mit.edu>
|
|
7 ;; Maintainer: FSF
|
|
8 ;; Keywords: tools, processes
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
2
|
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
25 ;; 02111-1307, USA.
|
0
|
26
|
2
|
27 ;;; Synched up with: FSF 19.34, with a lot of divergence.
|
0
|
28
|
|
29 ;;; Commentary:
|
|
30
|
|
31 ;; This package provides the compile and grep facilities documented in
|
|
32 ;; the Emacs user's manual.
|
|
33
|
|
34 ;;; Code:
|
|
35
|
|
36 ;;;###autoload
|
|
37 (defvar compilation-mode-hook nil
|
|
38 "*List of hook functions run by `compilation-mode' (see `run-hooks').")
|
|
39
|
|
40 ;;;###autoload
|
|
41 (defvar compilation-window-height nil
|
|
42 "*Number of lines in a compilation window. If nil, use Emacs default.")
|
|
43
|
2
|
44 ;; XEmacs change
|
0
|
45 (defvar compilation-error-list 'invalid ; only valid buffer-local
|
|
46 "List of error message descriptors for visiting erring functions.
|
|
47 Each error descriptor is a cons (or nil). Its car is a marker pointing to
|
|
48 an error message. If its cdr is a marker, it points to the text of the
|
|
49 line the message is about. If its cdr is a cons, it is a list
|
|
50 \(\(DIRECTORY . FILE\) LINE [COLUMN]\). Or its cdr may be nil if that
|
|
51 error is not interesting.
|
|
52
|
|
53 The value may be t instead of a list; this means that the buffer of
|
|
54 error messages should be reparsed the next time the list of errors is wanted.
|
|
55
|
|
56 Some other commands (like `diff') use this list to control the error
|
2
|
57 message tracking facilities; if you change its structure, you should make
|
0
|
58 sure you also change those packages. Perhaps it is better not to change
|
|
59 it at all.")
|
|
60
|
|
61 (defvar compilation-old-error-list nil
|
|
62 "Value of `compilation-error-list' after errors were parsed.")
|
|
63
|
|
64 (defvar compilation-parse-errors-function 'compilation-parse-errors
|
|
65 "Function to call to parse error messages from a compilation.
|
|
66 It takes args LIMIT-SEARCH and FIND-AT-LEAST.
|
|
67 If LIMIT-SEARCH is non-nil, don't bother parsing past that location.
|
|
68 If FIND-AT-LEAST is non-nil, don't bother parsing after finding that
|
|
69 many new errors.
|
|
70 It should read in the source files which have errors and set
|
|
71 `compilation-error-list' to a list with an element for each error message
|
|
72 found. See that variable for more info.")
|
|
73
|
|
74 ;;;###autoload
|
|
75 (defvar compilation-buffer-name-function nil
|
|
76 "Function to compute the name of a compilation buffer.
|
|
77 The function receives one argument, the name of the major mode of the
|
|
78 compilation buffer. It should return a string.
|
|
79 nil means compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
|
|
80
|
|
81 ;;;###autoload
|
|
82 (defvar compilation-finish-function nil
|
|
83 "*Function to call when a compilation process finishes.
|
|
84 It is called with two arguments: the compilation buffer, and a string
|
|
85 describing how the process finished.")
|
|
86
|
|
87 (defvar compilation-last-buffer nil
|
|
88 "The most recent compilation buffer.
|
|
89 A buffer becomes most recent when its compilation is started
|
|
90 or when it is used with \\[next-error] or \\[compile-goto-error].")
|
|
91
|
|
92 (defvar compilation-in-progress nil
|
|
93 "List of compilation processes now running.")
|
|
94 (or (assq 'compilation-in-progress minor-mode-alist)
|
|
95 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
|
|
96 minor-mode-alist)))
|
|
97
|
2
|
98 ;; XEmacs change
|
0
|
99 (defvar compilation-always-signal-completion nil
|
|
100 "Always give an audible signal upon compilation completion.
|
|
101 By default that signal is only given if the bottom of the compilation
|
|
102 buffer is not visible in its window.")
|
|
103
|
|
104 (defvar compilation-parsing-end nil
|
|
105 "Position of end of buffer when last error messages were parsed.")
|
|
106
|
|
107 (defvar compilation-error-message "No more errors"
|
|
108 "Message to print when no more matches are found.")
|
|
109
|
|
110 (defvar compilation-num-errors-found)
|
|
111
|
|
112 (defvar compilation-error-regexp-alist
|
|
113 '(
|
|
114 ;; NOTE! See also grep-regexp-alist, below.
|
|
115
|
|
116 ;; 4.3BSD grep, cc, lint pass 1:
|
|
117 ;; /usr/src/foo/foo.c(8): warning: w may be used before set
|
|
118 ;; or GNU utilities:
|
|
119 ;; foo.c:8: error message
|
|
120 ;; or HP-UX 7.0 fc:
|
|
121 ;; foo.f :16 some horrible error message
|
|
122 ;; or GNU utilities with column (GNAT 1.82):
|
|
123 ;; foo.adb:2:1: Unit name does not match file name
|
|
124 ;;
|
|
125 ;; We'll insist that the number be followed by a colon or closing
|
|
126 ;; paren, because otherwise this matches just about anything
|
|
127 ;; containing a number with spaces around it.
|
88
|
128 ("\
|
2
|
129 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
|
0
|
130 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
|
|
131
|
2
|
132 ;; Microsoft C/C++:
|
|
133 ;; keyboard.c(537) : warning C4005: 'min' : macro redefinition
|
|
134 ;; d:\tmp\test.c(23) : error C2143: syntax error : missing ';' before 'if'
|
88
|
135 ("\\(\\([a-zA-Z]:\\)?[^:( \t\n-]+\\)[:(][ \t]*\\([0-9]+\\)[:) \t]" 1 3)
|
2
|
136
|
0
|
137 ;; Borland C++:
|
|
138 ;; Error ping.c 15: Unable to open include file 'sys/types.h'
|
|
139 ;; Warning ping.c 68: Call to function 'func' with no prototype
|
88
|
140 ("\\(Error\\|Warning\\) \\([a-zA-Z]?:?[^:( \t\n]+\\)\
|
0
|
141 \\([0-9]+\\)\\([) \t]\\|:[^0-9\n]\\)" 2 3)
|
|
142
|
|
143 ;; 4.3BSD lint pass 2
|
|
144 ;; strcmp: variable # of args. llib-lc(359) :: /usr/src/foo/foo.c(8)
|
88
|
145 ("[^\n]*[ \t:]\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(](+[ \t]*\\([0-9]+\\))[:) \t]*$"
|
2
|
146 1 2)
|
0
|
147
|
|
148 ;; 4.3BSD lint pass 3
|
|
149 ;; bloofle defined( /users/wolfgang/foo.c(4) ), but never used
|
|
150 ;; This used to be
|
2
|
151 ;; ("[ \t(]+\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]+" 1 2)
|
0
|
152 ;; which is regexp Impressionism - it matches almost anything!
|
88
|
153 ("[^\n]*([ \t]*\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\))" 1 2)
|
2
|
154
|
|
155 ;; MIPS lint pass<n>; looks good for SunPro lint also
|
|
156 ;; TrimMask (255) in solomon.c may be indistinguishable from TrimMasks (93) in solomon.c due to truncation
|
88
|
157 ("[^ \n]+ (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
|
2
|
158 ;; name defined but never used: LinInt in cmap_calc.c(199)
|
88
|
159 ("[^\n]*in \\([^(\n]+\\)(\\([0-9]+\\))$" 1 2)
|
0
|
160
|
|
161 ;; Ultrix 3.0 f77:
|
|
162 ;; fort: Severe: addstf.f, line 82: Missing operator or delimiter symbol
|
|
163 ;; Some SGI cc version:
|
|
164 ;; cfe: Warning 835: foo.c, line 2: something
|
88
|
165 ("\\(cfe\\|fort\\): [^:\n]*: \\([^ \n]*\\), line \\([0-9]+\\):" 2 3)
|
0
|
166 ;; Error on line 3 of t.f: Execution error unclassifiable statement
|
|
167 ;; Unknown who does this:
|
2
|
168 ;; Line 45 of "foo.c": bloofle undefined
|
0
|
169 ;; Absoft FORTRAN 77 Compiler 3.1.3
|
|
170 ;; error on line 19 of fplot.f: spelling error?
|
|
171 ;; warning on line 17 of fplot.f: data type is undefined for variable d
|
88
|
172 ("\\(\\|[^\n]* on \\)[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
|
2
|
173 of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2)
|
0
|
174
|
|
175 ;; Apollo cc, 4.3BSD fc:
|
|
176 ;; "foo.f", line 3: Error: syntax error near end of statement
|
|
177 ;; IBM RS6000:
|
|
178 ;; "vvouch.c", line 19.5: 1506-046 (S) Syntax error.
|
|
179 ;; Unknown compiler:
|
|
180 ;; File "foobar.ml", lines 5-8, characters 20-155: blah blah
|
|
181 ;; Microtec mcc68k:
|
|
182 ;; "foo.c", line 32 pos 1; (E) syntax error; unexpected symbol: "lossage"
|
|
183 ;; GNAT (as of July 94):
|
|
184 ;; "foo.adb", line 2(11): warning: file name does not match ...
|
2
|
185 ;; IBM AIX xlc compiler:
|
|
186 ;; "src/swapping.c", line 30.34: 1506-342 (W) "/*" detected in comment.
|
88
|
187 ("[^\n]*\"\\([^,\" \n\t]+\\)\", lines? \
|
2
|
188 \\([0-9]+\\)\\([\(.]\\([0-9]+\\)\)?\\)?[:., (-]" 1 2 4)
|
0
|
189
|
|
190 ;; MIPS RISC CC - the one distributed with Ultrix:
|
|
191 ;; ccom: Error: foo.c, line 2: syntax error
|
|
192 ;; DEC AXP OSF/1 cc
|
|
193 ;; /usr/lib/cmplrs/cc/cfe: Error: foo.c: 1: blah blah
|
88
|
194 ("[^\n]*rror: \\([^,\" \n\t]+\\)[,:] \\(line \\)?\\([0-9]+\\):" 1 3)
|
0
|
195
|
|
196 ;; IBM AIX PS/2 C version 1.1:
|
|
197 ;; ****** Error number 140 in line 8 of file errors.c ******
|
88
|
198 ("[^\n]*in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
|
0
|
199 ;; IBM AIX lint is too painful to do right this way. File name
|
|
200 ;; prefixes entire sections rather than being on each line.
|
|
201
|
|
202 ;; Lucid Compiler, lcc 3.x
|
|
203 ;; E, file.cc(35,52) Illegal operation on pointers
|
88
|
204 ("[EW], \\([^(\n]*\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)" 1 2 3)
|
0
|
205
|
|
206 ;; GNU messages with program name and optional column number.
|
88
|
207 ("[a-zA-Z]?:?[^0-9 \n\t:]+:[ \t]*\\([^ \n\t:]+\\):\
|
0
|
208 \\([0-9]+\\):\\(\\([0-9]+\\)[: \t]\\)?" 1 2 4)
|
|
209
|
88
|
210 ;; GNU messages with program name and optional column number
|
|
211 ;; and a severity letter after that. nsgmls makes them.
|
|
212 ("[^0-9 \n\t:]+:[ \t]*\\([^ \n\t:]+\\):\
|
|
213 \\([0-9]+\\):\\(\\([0-9]+\\):\\)?[A-Za-z]:" 1 2 4)
|
|
214
|
0
|
215 ;; jwz:
|
|
216 ;; IRIX 5.2
|
|
217 ;; cfe: Warning 712: foo.c, line 2: illegal combination of pointer and ...
|
88
|
218 ("[^\n]* \\([^ \n,\"]+\\), line \\([0-9]+\\):" 1 2)
|
0
|
219 ;; IRIX 5.2
|
|
220 ;; cfe: Warning 600: xfe.c: 170: Not in a conditional directive while ...
|
88
|
221 ("[^\n]*: \\([^ \n,\"]+\\): \\([0-9]+\\):" 1 2)
|
0
|
222
|
|
223 ;; Cray C compiler error messages
|
88
|
224 ("\\(cc\\| cft\\)-[0-9]+ c\\(c\\|f77\\): ERROR \\([^,\n]+, \\)* File = \\([^,\n]+\\), Line = \\([0-9]+\\)" 4 5)
|
0
|
225
|
|
226 ;; IBM C/C++ Tools 2.01:
|
|
227 ;; foo.c(2:0) : informational EDC0804: Function foo is not referenced.
|
|
228 ;; foo.c(3:8) : warning EDC0833: Implicit return statement encountered.
|
|
229 ;; foo.c(5:5) : error EDC0350: Syntax error.
|
88
|
230 ("\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) : " 1 2 3)
|
0
|
231
|
|
232 ;; Sun ada (VADS, Solaris):
|
|
233 ;; /home3/xdhar/rcds_rc/main.a, line 361, char 6:syntax error: "," inserted
|
88
|
234 ("\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
|
0
|
235 )
|
88
|
236 "Alist that specifies how to match errors in compiler output.
|
0
|
237 Each elt has the form (REGEXP FILE-IDX LINE-IDX [COLUMN-IDX FILE-FORMAT...])
|
88
|
238 If REGEXP matches constrained to the beginning of the line, the
|
|
239 FILE-IDX'th subexpression gives the file name, and the LINE-IDX'th
|
|
240 subexpression gives the line number. If COLUMN-IDX is given, the
|
|
241 COLUMN-IDX'th subexpression gives the column number on that line. If
|
|
242 any FILE-FORMAT is given, each is a format string to produce a file name
|
|
243 to try; %s in the string is replaced by the text matching the
|
|
244 FILE-IDX'th subexpression. Note previously REGEXP was not constrained
|
|
245 to the beginning of the line, so old patterns without leading `^' or `\\n'
|
|
246 may now require a leading `.*'.")
|
0
|
247
|
|
248 (defvar compilation-read-command t
|
|
249 "If not nil, M-x compile reads the compilation command to use.
|
|
250 Otherwise, M-x compile just uses the value of `compile-command'.")
|
|
251
|
|
252 (defvar compilation-ask-about-save t
|
|
253 "If not nil, M-x compile asks which buffers to save before compiling.
|
|
254 Otherwise, it saves all modified buffers without asking.")
|
|
255
|
|
256 (defvar grep-regexp-alist
|
2
|
257 '(("^\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2))
|
0
|
258 "Regexp used to match grep hits. See `compilation-error-regexp-alist'.")
|
|
259
|
|
260 (defvar grep-command "grep -n "
|
|
261 "Last grep command used in \\[grep]; default for next grep.")
|
|
262
|
|
263 ;;;###autoload
|
|
264 (defvar compilation-search-path '(nil)
|
|
265 "*List of directories to search for source files named in error messages.
|
|
266 Elements should be directory names, not file names of directories.
|
|
267 nil as an element means to try the default directory.")
|
|
268
|
|
269 (defvar compile-command "make -k "
|
|
270 "Last shell command used to do a compilation; default for next compilation.
|
|
271
|
|
272 Sometimes it is useful for files to supply local values for this variable.
|
|
273 You might also use mode hooks to specify it in certain modes, like this:
|
|
274
|
|
275 (setq c-mode-hook
|
|
276 '(lambda () (or (file-exists-p \"makefile\") (file-exists-p \"Makefile\")
|
|
277 (progn (make-local-variable 'compile-command)
|
|
278 (setq compile-command
|
|
279 (concat \"make -k \"
|
|
280 buffer-file-name))))))")
|
|
281
|
|
282 (defvar compilation-enter-directory-regexp
|
88
|
283 "[^\n]*: Entering directory `\\([^\n]*\\)'$"
|
0
|
284 "Regular expression matching lines that indicate a new current directory.
|
|
285 This must contain one \\(, \\) pair around the directory name.
|
|
286
|
|
287 The default value matches lines printed by the `-w' option of GNU Make.")
|
|
288
|
|
289 (defvar compilation-leave-directory-regexp
|
88
|
290 "[^\n]*: Leaving directory `\\([^\n]*\\)'$"
|
0
|
291 "Regular expression matching lines that indicate restoring current directory.
|
|
292 This may contain one \\(, \\) pair around the name of the directory
|
|
293 being moved from. If it does not, the last directory entered \(by a
|
|
294 line matching `compilation-enter-directory-regexp'\) is assumed.
|
|
295
|
|
296 The default value matches lines printed by the `-w' option of GNU Make.")
|
|
297
|
|
298 (defvar compilation-directory-stack nil
|
|
299 "Stack of previous directories for `compilation-leave-directory-regexp'.
|
|
300 The head element is the directory the compilation was started in.")
|
|
301
|
|
302 (defvar compilation-exit-message-function nil "\
|
|
303 If non-nil, called when a compilation process dies to return a status message.
|
2
|
304 This should be a function of three arguments: process status, exit status,
|
|
305 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
|
|
306 write into the compilation buffer, and to put in its mode line.")
|
0
|
307
|
|
308 ;; History of compile commands.
|
|
309 (defvar compile-history nil)
|
|
310 ;; History of grep commands.
|
|
311 (defvar grep-history nil)
|
|
312
|
2
|
313 ;; XEmacs
|
74
|
314 (defvar compilation-font-lock-keywords (purecopy
|
0
|
315 (list
|
|
316 '("^[-_.\"A-Za-z0-9/+]+\\(:\\|, line \\)[0-9]+: \\([wW]arning:\\).*$" .
|
|
317 font-lock-keyword-face)
|
|
318 '("^[-_.\"A-Za-z0-9/+]+\\(: *\\|, line \\)[0-9]+:.*$" . font-lock-function-name-face)
|
|
319 '("^[^:\n]+-[a-zA-Z][^:\n]+$" . font-lock-doc-string-face)
|
|
320 '("\\(^[-_.\"A-Za-z0-9/+]+\\)\\(: *\\|, line \\)[0-9]+" 1 font-lock-string-face t)
|
|
321 '("^[-_.\"A-Za-z0-9/+]+\\(: *[0-9]+\\|, line [0-9]+\\)" 1 bold t)
|
|
322 ))
|
|
323 "Additional expressions to highlight in Compilation mode.")
|
|
324
|
|
325 ;FSF's version. Ours looks better.
|
2
|
326 ;(defvar compilation-mode-font-lock-keywords
|
0
|
327 ; ;; This regexp needs a bit of rewriting. What is the third grouping for?
|
2
|
328 ; '(("^\\([a-zA-Z]?:?[^ \n:]*:\\([0-9]+:\\)+\\)\\(.*\\)$"
|
|
329 ; 1 font-lock-function-name-face))
|
|
330 ;;; ("^\\([^\n:]*:\\([0-9]+:\\)+\\)\\(.*\\)$" 0 font-lock-keyword-face keep)
|
|
331
|
|
332 ;; XEmacs change
|
0
|
333 (put 'compilation-mode 'font-lock-defaults
|
|
334 '(compilation-font-lock-keywords t))
|
|
335
|
|
336
|
|
337 ;;;###autoload
|
|
338 (defun compile (command)
|
|
339 "Compile the program including the current buffer. Default: run `make'.
|
|
340 Runs COMMAND, a shell command, in a separate process asynchronously
|
|
341 with output going to the buffer `*compilation*'.
|
|
342
|
|
343 You can then use the command \\[next-error] to find the next error message
|
|
344 and move to the source code that caused it.
|
|
345
|
|
346 Interactively, prompts for the command if `compilation-read-command' is
|
|
347 non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
|
|
348
|
|
349 To run more than one compilation at once, start one and rename the
|
|
350 \`*compilation*' buffer to some other name with \\[rename-buffer].
|
|
351 Then start the next one.
|
|
352
|
|
353 The name used for the buffer is actually whatever is returned by
|
|
354 the function in `compilation-buffer-name-function', so you can set that
|
|
355 to a function that generates a unique name."
|
|
356 (interactive
|
|
357 (if (or compilation-read-command current-prefix-arg)
|
2
|
358 ;; XEmacs change
|
0
|
359 (list (read-shell-command "Compile command: "
|
|
360 compile-command
|
|
361 ;; #### minibuffer code should do this
|
|
362 (if (equal (car compile-history)
|
|
363 compile-command)
|
|
364 '(compile-history . 1)
|
|
365 'compile-history)))
|
|
366 (list compile-command)))
|
|
367 (setq compile-command command)
|
|
368 (save-some-buffers (not compilation-ask-about-save) nil)
|
|
369 (compile-internal compile-command "No more errors"))
|
|
370
|
|
371 ;;; run compile with the default command line
|
|
372 (defun recompile ()
|
|
373 "Re-compile the program including the current buffer."
|
|
374 (interactive)
|
|
375 (save-some-buffers (not compilation-ask-about-save) nil)
|
|
376 (compile-internal compile-command "No more errors"))
|
|
377
|
|
378 ;; The system null device. (Should reference NULL_DEVICE from C.)
|
|
379 (defvar grep-null-device "/dev/null" "The system null device.")
|
|
380
|
|
381 ;;;###autoload
|
|
382 (defun grep (command-args)
|
|
383 "Run grep, with user-specified args, and collect output in a buffer.
|
|
384 While grep runs asynchronously, you can use the \\[next-error] command
|
|
385 to find the text that grep hits refer to.
|
|
386
|
|
387 This command uses a special history list for its arguments, so you can
|
|
388 easily repeat a grep command."
|
|
389 (interactive
|
2
|
390 ;; XEmacs change
|
0
|
391 (list (read-shell-command "Run grep (like this): "
|
|
392 grep-command 'grep-history)))
|
|
393 (let ((buf (compile-internal (concat command-args " " grep-null-device)
|
|
394 "No more grep hits" "grep"
|
|
395 ;; Give it a simpler regexp to match.
|
|
396 nil grep-regexp-alist)))
|
|
397 (save-excursion
|
|
398 (set-buffer buf)
|
|
399 (set (make-local-variable 'compilation-exit-message-function)
|
2
|
400 ;; XEmacs change
|
0
|
401 (lambda (proc msg)
|
|
402 (let ((code (process-exit-status proc)))
|
|
403 (if (eq (process-status proc) 'exit)
|
|
404 (cond ((zerop code)
|
|
405 '("finished (matches found)\n" . "matched"))
|
|
406 ((= code 1)
|
|
407 '("finished with no matches found\n" . "no match"))
|
|
408 (t
|
|
409 (cons msg code)))
|
|
410 (cons msg code))))))))
|
|
411
|
|
412 (defun compile-internal (command error-message
|
|
413 &optional name-of-mode parser regexp-alist
|
|
414 name-function)
|
|
415 "Run compilation command COMMAND (low level interface).
|
|
416 ERROR-MESSAGE is a string to print if the user asks to see another error
|
|
417 and there are no more errors. Third argument NAME-OF-MODE is the name
|
|
418 to display as the major mode in the compilation buffer.
|
|
419
|
|
420 Fourth arg PARSER is the error parser function (nil means the default). Fifth
|
|
421 arg REGEXP-ALIST is the error message regexp alist to use (nil means the
|
|
422 default). Sixth arg NAME-FUNCTION is a function called to name the buffer (nil
|
|
423 means the default). The defaults for these variables are the global values of
|
|
424 \`compilation-parse-errors-function', `compilation-error-regexp-alist', and
|
|
425 \`compilation-buffer-name-function', respectively.
|
|
426
|
|
427 Returns the compilation buffer created."
|
|
428 (let (outbuf)
|
|
429 (save-excursion
|
|
430 (or name-of-mode
|
|
431 (setq name-of-mode "Compilation"))
|
|
432 (setq outbuf
|
|
433 (get-buffer-create
|
|
434 (funcall (or name-function compilation-buffer-name-function
|
|
435 (function (lambda (mode)
|
|
436 (concat "*" (downcase mode) "*"))))
|
|
437 name-of-mode)))
|
|
438 (set-buffer outbuf)
|
|
439 (let ((comp-proc (get-buffer-process (current-buffer))))
|
|
440 (if comp-proc
|
|
441 (if (or (not (eq (process-status comp-proc) 'run))
|
|
442 (yes-or-no-p
|
|
443 (format "A %s process is running; kill it? "
|
|
444 name-of-mode)))
|
|
445 (condition-case ()
|
|
446 (progn
|
|
447 (interrupt-process comp-proc)
|
|
448 (sit-for 1)
|
|
449 (delete-process comp-proc))
|
|
450 (error nil))
|
|
451 (error "Cannot have two processes in `%s' at once"
|
|
452 (buffer-name))
|
|
453 )))
|
|
454 ;; In case the compilation buffer is current, make sure we get the global
|
|
455 ;; values of compilation-error-regexp-alist, etc.
|
|
456 (kill-all-local-variables))
|
|
457 (let ((regexp-alist (or regexp-alist compilation-error-regexp-alist))
|
|
458 (parser (or parser compilation-parse-errors-function))
|
|
459 (thisdir default-directory)
|
2
|
460 ;; XEmacs change
|
0
|
461 (buffer-save (current-buffer))
|
|
462 outwin)
|
2
|
463
|
|
464 ;; XEmacs change
|
0
|
465 ;; Pop up the compilation buffer.
|
|
466 (setq outwin (display-buffer outbuf))
|
|
467
|
|
468 (unwind-protect
|
|
469 (progn
|
|
470 ;; Clear out the compilation buffer and make it writable.
|
|
471 ;; Change its default-directory to the directory where the compilation
|
|
472 ;; will happen, and insert a `cd' command to indicate this.
|
|
473 (set-buffer outbuf)
|
2
|
474
|
0
|
475 (setq buffer-read-only nil)
|
|
476 (buffer-disable-undo (current-buffer))
|
|
477 (erase-buffer)
|
|
478 (buffer-enable-undo (current-buffer))
|
|
479 (setq default-directory thisdir)
|
|
480 (insert "cd " thisdir "\n" command "\n")
|
|
481 (set-buffer-modified-p nil)
|
|
482
|
2
|
483 ;; XEmacs change
|
0
|
484 ;; set it so the window will scroll to show compile output
|
|
485 (save-window-excursion
|
|
486 (select-window outwin)
|
|
487 (goto-char (point-max)))
|
|
488
|
2
|
489 ;; XEmacs change
|
0
|
490 (compilation-mode name-of-mode)
|
|
491 ;; (setq buffer-read-only t) ;;; Non-ergonomic.
|
2
|
492 ;; XEmacs change
|
0
|
493 (set (make-local-variable 'compile-command) command)
|
|
494 (set (make-local-variable 'compilation-parse-errors-function) parser)
|
|
495 (set (make-local-variable 'compilation-error-message) error-message)
|
|
496 (set (make-local-variable 'compilation-error-regexp-alist) regexp-alist)
|
|
497 (setq default-directory thisdir
|
|
498 compilation-directory-stack (list default-directory))
|
|
499 (set-window-start outwin (point-min))
|
|
500 (setq mode-name name-of-mode)
|
2
|
501 ;; XEmacs change
|
0
|
502 ; (or (eq outwin (selected-window))
|
|
503 ; (set-window-point outwin (point-min)))
|
|
504 (compilation-set-window-height outwin)
|
|
505 ;; Start the compilation.
|
|
506 (if (fboundp 'start-process)
|
|
507 (let* ((process-environment (cons "EMACS=t" process-environment))
|
|
508 (proc (start-process-shell-command (downcase mode-name)
|
|
509 outbuf
|
|
510 command)))
|
|
511 (set-process-sentinel proc 'compilation-sentinel)
|
|
512 (set-process-filter proc 'compilation-filter)
|
|
513 (set-marker (process-mark proc) (point) outbuf)
|
|
514 (setq compilation-in-progress
|
|
515 (cons proc compilation-in-progress)))
|
2
|
516 ;; No asynchronous processes available.
|
|
517 (message "Executing `%s'..." command)
|
|
518 ; FSF
|
|
519 ; (setq mode-line-process ":run")
|
|
520 ; (force-mode-line-update)
|
|
521 (sit-for 0) ;; Force redisplay
|
0
|
522 (let ((status (call-process shell-file-name nil outbuf nil "-c"
|
|
523 command))))
|
2
|
524 (message "Executing `%s'...done" command)))
|
0
|
525 (set-buffer buffer-save)))
|
|
526
|
|
527 ;; Make it so the next C-x ` will use this buffer.
|
|
528 (setq compilation-last-buffer outbuf)))
|
|
529
|
|
530 ;; Set the height of WINDOW according to compilation-window-height.
|
|
531 (defun compilation-set-window-height (window)
|
|
532 (and compilation-window-height
|
|
533 (= (window-width window) (frame-width (window-frame window)))
|
|
534 ;; If window is alone in its frame, aside from a minibuffer,
|
|
535 ;; don't change its height.
|
|
536 (not (eq window (frame-root-window (window-frame window))))
|
|
537 ;; This save-excursion prevents us from changing the current buffer,
|
|
538 ;; which might not be the same as the selected window's buffer.
|
|
539 (save-excursion
|
|
540 (let ((w (selected-window)))
|
|
541 (unwind-protect
|
|
542 (progn
|
|
543 (select-window window)
|
|
544 (enlarge-window (- compilation-window-height
|
|
545 (window-height))))
|
|
546 (select-window w))))))
|
|
547
|
|
548 (defvar compilation-minor-mode-map
|
|
549 (let ((map (make-sparse-keymap)))
|
|
550 (set-keymap-name map 'compilation-minor-mode-map)
|
|
551 (define-key map "\C-c\C-c" 'compile-goto-error)
|
|
552 (define-key map "\C-m" 'compile-goto-error)
|
|
553 (define-key map "\C-c\C-k" 'kill-compilation)
|
|
554 (define-key map "\M-n" 'compilation-next-error)
|
|
555 (define-key map "\M-p" 'compilation-previous-error)
|
|
556 (define-key map "\M-{" 'compilation-previous-file)
|
|
557 (define-key map "\M-}" 'compilation-next-file)
|
|
558 map)
|
|
559 "Keymap for `compilation-minor-mode'.")
|
|
560
|
|
561 (defvar compilation-mode-map
|
|
562 (let ((map (make-sparse-keymap)))
|
|
563 (set-keymap-parents map (list compilation-minor-mode-map))
|
|
564 (set-keymap-name map 'compilation-mode-map)
|
|
565 (define-key map " " 'scroll-up)
|
|
566 (define-key map "\^?" 'scroll-down)
|
|
567 (define-key map 'button2 'compile-mouse-goto-error)
|
|
568 map)
|
|
569 "Keymap for compilation log buffers.
|
|
570 `compilation-minor-mode-map' is a parent of this.")
|
|
571
|
|
572 ;;; XEmacs menus
|
|
573
|
|
574 (defun compilation-errors-exist-p (&optional buffer)
|
|
575 "Whether we are in a state where the `next-error' command will work,
|
|
576 that is, whether there exist (or may exist) error targets in the *compile*
|
|
577 or *grep* buffers."
|
|
578 (or buffer
|
|
579 (setq buffer (condition-case nil
|
|
580 (compilation-find-buffer)
|
|
581 (error nil))))
|
|
582 (and buffer
|
|
583 (compilation-buffer-p buffer)
|
|
584 (save-excursion
|
|
585 (set-buffer buffer)
|
|
586 ;; Has errors on the list, or needs to be parsed.
|
|
587 ;; But don't parse it now!
|
|
588 (or (not (null compilation-error-list))
|
|
589 (< compilation-parsing-end (point-max))))))
|
|
590
|
|
591 (defvar Compilation-mode-popup-menu
|
|
592 '("Compilation Mode Commands"
|
|
593 :filter compile-menu-filter
|
|
594 ["Compile..." compile t]
|
|
595 ["Recompile" recompile t]
|
|
596 ["Kill Compilation" kill-compilation (get-buffer-process (current-buffer))]
|
|
597 "---"
|
|
598 ["Goto Error" compile-goto-error (compilation-errors-exist-p)]
|
|
599 ["Next Error" next-error (compilation-errors-exist-p)]
|
|
600 ["Previous Error" previous-error (compilation-errors-exist-p)]
|
|
601 ["First Error" first-error (compilation-errors-exist-p)]
|
|
602 ))
|
|
603
|
|
604 (defvar Compilation-mode-menubar-menu
|
|
605 (cons "Compile" (cdr Compilation-mode-popup-menu)))
|
|
606
|
|
607 (defvar grep-mode-popup-menu
|
|
608 '("Grep Mode Commands"
|
|
609 :filter grep-menu-filter
|
|
610 ["Grep..." grep t]
|
|
611 ["Repeat Grep" recompile t]
|
|
612 ["Kill Grep" kill-compilation (get-buffer-process (current-buffer))]
|
|
613 "---"
|
|
614 ["Goto Match" compile-goto-error (default-value 'compilation-error-list)]
|
|
615 ["Next Match" next-error (default-value 'compilation-error-list)]
|
|
616 ["Previous Match" previous-error (default-value 'compilation-error-list)]
|
|
617 ["First Match" first-error (default-value 'compilation-error-list)]
|
|
618 ))
|
|
619
|
|
620 (defvar grep-mode-menubar-menu
|
|
621 (cons "Grep" (cdr grep-mode-popup-menu)))
|
|
622
|
|
623 (defun compile-menu-filter-1 (menu history-list item-name command-name)
|
|
624 (let ((submenu (mapcar #'(lambda (string)
|
|
625 (vector string
|
|
626 (list command-name string)
|
|
627 t))
|
|
628 history-list))
|
|
629 (existing (assoc item-name menu)))
|
|
630 (if existing
|
|
631 (progn
|
|
632 (setcdr existing submenu)
|
|
633 menu)
|
|
634 (nconc menu (list (cons item-name submenu))))))
|
|
635
|
|
636 (defun compile-menu-filter (menu)
|
|
637 (compile-menu-filter-1 menu compile-history "Compile History" 'compile))
|
|
638
|
|
639 (defun grep-menu-filter (menu)
|
|
640 (compile-menu-filter-1 menu grep-history "Grep History" 'grep))
|
|
641
|
|
642 (defun compilation-mode (&optional name-of-mode)
|
|
643 "Major mode for compilation log buffers.
|
|
644 \\<compilation-mode-map>To visit the source for a line-numbered error,
|
|
645 move point to the error message line and type \\[compile-goto-error],
|
|
646 or click on the line with \\[compile-mouse-goto-error].
|
|
647 There is a menu of commands on \\[compile-popup-menu].
|
|
648 To kill the compilation, type \\[kill-compilation].
|
|
649
|
|
650 Runs `compilation-mode-hook' with `run-hooks' (which see)."
|
|
651 (interactive)
|
|
652 (kill-all-local-variables)
|
|
653 (use-local-map compilation-mode-map)
|
|
654 (setq major-mode 'compilation-mode
|
|
655 mode-name "Compilation")
|
|
656 (compilation-setup)
|
|
657 (font-lock-set-defaults)
|
|
658 (if (not name-of-mode) nil
|
|
659 (let ((sym (intern (concat name-of-mode "-mode-popup-menu"))))
|
|
660 (if (boundp sym)
|
|
661 (setq mode-popup-menu (symbol-value sym))))
|
|
662 (if (featurep 'menubar)
|
|
663 (progn
|
|
664 ;; make a local copy of the menubar, so our modes don't
|
|
665 ;; change the global menubar
|
|
666 (set-buffer-menubar current-menubar)
|
|
667 (let ((sym (intern (concat name-of-mode "-mode-menubar-menu"))))
|
|
668 (if (boundp sym)
|
|
669 (add-submenu nil (symbol-value sym)))))))
|
|
670 (run-hooks 'compilation-mode-hook))
|
|
671
|
|
672 ;; XEmacs addition, hacked by Mly
|
|
673 (defun compilation-mode-motion-hook (event)
|
|
674 (mode-motion-highlight-internal
|
|
675 event
|
|
676 #'beginning-of-line
|
|
677 #'(lambda ()
|
|
678 (let* ((p (point))
|
|
679 (e (progn (end-of-line) (point)))
|
|
680 (l (progn
|
|
681 (if (or (eq compilation-error-list 't)
|
|
682 (>= p compilation-parsing-end))
|
|
683 ;; #### Does it suck too badly to have mouse-movement
|
|
684 ;; #### over a buffer parse errors in that buffer??
|
|
685 (save-window-excursion
|
|
686 (compile-reinitialize-errors nil p)))
|
|
687 (if (and compilation-error-list
|
|
688 (<= (car (car compilation-error-list)) p))
|
|
689 ;; Perhaps save time by only searching tail
|
|
690 compilation-error-list
|
|
691 compilation-old-error-list))))
|
|
692 (if (catch 'found
|
|
693 (while l
|
|
694 (let ((x (marker-position (car (car l)))))
|
|
695 (cond ((< x p)
|
|
696 (setq l (cdr l)))
|
|
697 ((<= x e)
|
|
698 (throw 'found t))
|
|
699 (t
|
|
700 (throw 'found nil)))))
|
|
701 nil)
|
|
702 (goto-char e)
|
|
703 (goto-char p))))))
|
|
704
|
|
705 ;; Prepare the buffer for the compilation parsing commands to work.
|
|
706 (defun compilation-setup ()
|
|
707 ;; Make the buffer's mode line show process state.
|
|
708 (setq mode-line-process '(":%s"))
|
|
709 (set (make-local-variable 'compilation-error-list) nil)
|
|
710 (set (make-local-variable 'compilation-old-error-list) nil)
|
|
711 (set (make-local-variable 'compilation-parsing-end) 1)
|
|
712 (set (make-local-variable 'compilation-directory-stack) nil)
|
|
713 (setq compilation-last-buffer (current-buffer))
|
|
714 ;; XEmacs change: highlight lines, install menubar.
|
|
715 (require 'mode-motion)
|
|
716 (setq mode-motion-hook 'compilation-mode-motion-hook)
|
|
717 (make-local-variable 'mouse-track-click-hook)
|
|
718 (add-hook 'mouse-track-click-hook 'compile-mouse-maybe-goto-error)
|
|
719 )
|
|
720
|
|
721 (defvar compilation-minor-mode nil
|
|
722 "Non-nil when in compilation-minor-mode.
|
|
723 In this minor mode, all the error-parsing commands of the
|
|
724 Compilation major mode are available.")
|
|
725 (make-variable-buffer-local 'compilation-minor-mode)
|
|
726
|
|
727 (or (assq 'compilation-minor-mode minor-mode-alist)
|
|
728 (setq minor-mode-alist (cons '(compilation-minor-mode " Compilation")
|
|
729 minor-mode-alist)))
|
|
730 (or (assq 'compilation-minor-mode minor-mode-map-alist)
|
|
731 (setq minor-mode-map-alist (cons (cons 'compilation-minor-mode
|
|
732 compilation-minor-mode-map)
|
|
733 minor-mode-map-alist)))
|
|
734
|
|
735 ;;;###autoload
|
|
736 (defun compilation-minor-mode (&optional arg)
|
|
737 "Toggle compilation minor mode.
|
|
738 With arg, turn compilation mode on if and only if arg is positive.
|
|
739 See `compilation-mode'.
|
|
740 ! \\{compilation-mode-map}"
|
|
741 (interactive "P")
|
|
742 (if (setq compilation-minor-mode (if (null arg)
|
|
743 (null compilation-minor-mode)
|
|
744 (> (prefix-numeric-value arg) 0)))
|
2
|
745 (progn
|
|
746 (compilation-setup)
|
|
747 (run-hooks 'compilation-minor-mode-hook))))
|
|
748
|
|
749 ;; Write msg in the current buffer and hack its mode-line-process.
|
|
750 (defun compilation-handle-exit (process-status exit-status msg)
|
|
751 (let ((buffer-read-only nil)
|
|
752 (status (if compilation-exit-message-function
|
|
753 (funcall compilation-exit-message-function
|
|
754 process-status exit-status msg)
|
|
755 (cons msg exit-status)))
|
|
756 (omax (point-max))
|
|
757 (opoint (point)))
|
|
758 ;; Record where we put the message, so we can ignore it
|
|
759 ;; later on.
|
|
760 (goto-char omax)
|
|
761 (insert ?\n mode-name " " (car status))
|
|
762 (forward-char -1)
|
|
763 (insert " at " (substring (current-time-string) 0 19))
|
|
764 (forward-char 1)
|
|
765 (setq mode-line-process (format ":%s [%s]" process-status (cdr status)))
|
|
766 ;; Force mode line redisplay soon.
|
|
767 (force-mode-line-update)
|
|
768 (if (and opoint (< opoint omax))
|
|
769 (goto-char opoint))
|
|
770 (if compilation-finish-function
|
|
771 (funcall compilation-finish-function (current-buffer) msg))))
|
0
|
772
|
|
773 ;; Called when compilation process changes state.
|
|
774 (defun compilation-sentinel (proc msg)
|
|
775 "Sentinel for compilation buffers."
|
2
|
776 ;; XEmacs change
|
0
|
777 (let* ((buffer (process-buffer proc))
|
|
778 (window (get-buffer-window buffer)))
|
|
779 (if (memq (process-status proc) '(signal exit))
|
|
780 (progn
|
|
781 (if (null (buffer-name buffer))
|
|
782 ;; buffer killed
|
|
783 (set-process-buffer proc nil)
|
|
784 (let ((obuf (current-buffer))
|
|
785 omax opoint estatus)
|
|
786 ;; save-excursion isn't the right thing if
|
|
787 ;; process-buffer is current-buffer
|
|
788 (unwind-protect
|
|
789 (progn
|
|
790 ;; Write something in the compilation buffer
|
|
791 ;; and hack its mode line.
|
|
792 (set-buffer buffer)
|
|
793 (let ((buffer-read-only nil)
|
|
794 (status (if compilation-exit-message-function
|
|
795 (funcall compilation-exit-message-function
|
|
796 proc msg)
|
|
797 (cons msg (process-exit-status proc)))))
|
|
798 (setq omax (point-max)
|
|
799 opoint (point))
|
|
800 (goto-char omax)
|
|
801 ;; Record where we put the message, so we can ignore it
|
|
802 ;; later on.
|
|
803 (insert ?\n mode-name " " (car status))
|
|
804 (forward-char -1)
|
|
805 (insert " at " (substring (current-time-string) 0 19))
|
|
806 (forward-char 1)
|
|
807 (setq mode-line-process
|
|
808 (concat ":"
|
|
809 (symbol-name (process-status proc))
|
|
810 (if (zerop (process-exit-status proc))
|
|
811 " OK"
|
|
812 (setq estatus
|
|
813 (format " [exit-status %d]"
|
|
814 (process-exit-status proc))))
|
|
815 ))
|
|
816 ;; XEmacs - tedium should let you know when it's ended...
|
|
817 (if (and (not compilation-always-signal-completion)
|
|
818 window
|
|
819 (pos-visible-in-window-p (point-max) window))
|
|
820 nil ; assume that the user will see it...
|
|
821 (ding t 'ready)
|
|
822 (message "Compilation process completed%s."
|
|
823 (or estatus " successfully")
|
|
824 ))
|
|
825 ;; Since the buffer and mode line will show that the
|
|
826 ;; process is dead, we can delete it now. Otherwise it
|
|
827 ;; will stay around until M-x list-processes.
|
|
828 (delete-process proc)
|
|
829 ;; Force mode line redisplay soon.
|
|
830 (redraw-modeline))
|
|
831 (if (and opoint (< opoint omax))
|
|
832 (goto-char opoint))
|
|
833 (if compilation-finish-function
|
|
834 (funcall compilation-finish-function buffer msg)))
|
|
835 (set-buffer obuf))))
|
|
836 (setq compilation-in-progress (delq proc compilation-in-progress))
|
|
837 ))))
|
|
838
|
|
839 (defun compilation-filter (proc string)
|
|
840 "Process filter for compilation buffers.
|
|
841 Just inserts the text, but uses `insert-before-markers'."
|
|
842 (if (buffer-name (process-buffer proc))
|
|
843 (save-excursion
|
|
844 (set-buffer (process-buffer proc))
|
|
845 (let ((buffer-read-only nil))
|
|
846 (save-excursion
|
|
847 (goto-char (process-mark proc))
|
|
848 (insert-before-markers string)
|
2
|
849 (run-hooks 'compilation-filter-hook)
|
0
|
850 (set-marker (process-mark proc) (point)))))))
|
|
851
|
|
852 ;; Return the cdr of compilation-old-error-list for the error containing point.
|
|
853 (defun compile-error-at-point ()
|
|
854 (compile-reinitialize-errors nil (point))
|
|
855 (let ((errors compilation-old-error-list))
|
|
856 (while (and errors
|
|
857 (> (point) (car (car errors))))
|
|
858 (setq errors (cdr errors)))
|
|
859 errors))
|
|
860
|
2
|
861 (defsubst compilation-buffer-p (buffer)
|
0
|
862 (save-excursion
|
|
863 (set-buffer buffer)
|
|
864 (or compilation-minor-mode (eq major-mode 'compilation-mode))))
|
|
865
|
|
866 (defun compilation-next-error (n)
|
|
867 "Move point to the next error in the compilation buffer.
|
|
868 Does NOT find the source line like \\[next-error]."
|
|
869 (interactive "p")
|
|
870 (or (compilation-buffer-p (current-buffer))
|
|
871 (error "Not in a compilation buffer."))
|
|
872 (setq compilation-last-buffer (current-buffer))
|
|
873
|
|
874 (let ((errors (compile-error-at-point)))
|
|
875
|
|
876 ;; Move to the error after the one containing point.
|
|
877 (goto-char (car (if (< n 0)
|
|
878 (let ((i 0)
|
|
879 (e compilation-old-error-list))
|
|
880 ;; See how many cdrs away ERRORS is from the start.
|
|
881 (while (not (eq e errors))
|
|
882 (setq i (1+ i)
|
|
883 e (cdr e)))
|
|
884 (if (> (- n) i)
|
|
885 (error "Moved back past first error")
|
|
886 (nth (+ i n) compilation-old-error-list)))
|
|
887 (let ((compilation-error-list (cdr errors)))
|
|
888 (compile-reinitialize-errors nil nil n)
|
|
889 (if compilation-error-list
|
|
890 (nth (1- n) compilation-error-list)
|
|
891 (error "Moved past last error"))))))))
|
|
892
|
|
893 (defun compilation-previous-error (n)
|
|
894 "Move point to the previous error in the compilation buffer.
|
|
895 Does NOT find the source line like \\[next-error]."
|
|
896 (interactive "p")
|
|
897 (compilation-next-error (- n)))
|
|
898
|
|
899
|
|
900 ;; Given an elt of `compilation-error-list', return an object representing
|
|
901 ;; the referenced file which is equal to (but not necessarily eq to) what
|
|
902 ;; this function would return for another error in the same file.
|
|
903 (defsubst compilation-error-filedata (data)
|
|
904 (setq data (cdr data))
|
|
905 (if (markerp data)
|
|
906 (marker-buffer data)
|
|
907 (car data)))
|
|
908
|
|
909 ;; Return a string describing a value from compilation-error-filedata.
|
|
910 ;; This value is not necessarily useful as a file name, but should be
|
|
911 ;; indicative to the user of what file's errors are being referred to.
|
|
912 (defsubst compilation-error-filedata-file-name (filedata)
|
|
913 (if (bufferp filedata)
|
|
914 (buffer-file-name filedata)
|
|
915 (car filedata)))
|
|
916
|
|
917 (defun compilation-next-file (n)
|
|
918 "Move point to the next error for a different file than the current one."
|
|
919 (interactive "p")
|
|
920 (or (compilation-buffer-p (current-buffer))
|
|
921 (error "Not in a compilation buffer."))
|
|
922 (setq compilation-last-buffer (current-buffer))
|
|
923
|
|
924 (let ((reversed (< n 0))
|
|
925 errors filedata)
|
|
926
|
|
927 (if (not reversed)
|
|
928 (setq errors (or (compile-error-at-point)
|
|
929 (error "Moved past last error")))
|
|
930
|
|
931 ;; Get a reversed list of the errors up through the one containing point.
|
|
932 (compile-reinitialize-errors nil (point))
|
|
933 (setq errors (reverse compilation-old-error-list)
|
|
934 n (- n))
|
|
935
|
|
936 ;; Ignore errors after point. (car ERRORS) will be the error
|
|
937 ;; containing point, (cadr ERRORS) the one before it.
|
|
938 (while (and errors
|
|
939 (< (point) (car (car errors))))
|
|
940 (setq errors (cdr errors))))
|
|
941
|
|
942 (while (> n 0)
|
|
943 (setq filedata (compilation-error-filedata (car errors)))
|
|
944
|
|
945 ;; Skip past the following errors for this file.
|
|
946 (while (equal filedata
|
|
947 (compilation-error-filedata
|
|
948 (car (or errors
|
|
949 (if reversed
|
|
950 (error "%s the first erring file"
|
|
951 (compilation-error-filedata-file-name
|
|
952 filedata))
|
|
953 (let ((compilation-error-list nil))
|
|
954 ;; Parse some more.
|
|
955 (compile-reinitialize-errors nil nil 2)
|
|
956 (setq errors compilation-error-list)))
|
|
957 (error "%s is the last erring file"
|
|
958 (compilation-error-filedata-file-name
|
|
959 filedata))))))
|
|
960 (setq errors (cdr errors)))
|
|
961
|
|
962 (setq n (1- n)))
|
|
963
|
|
964 ;; Move to the following error.
|
|
965 (goto-char (car (car (or errors
|
|
966 (if reversed
|
|
967 (error "This is the first erring file")
|
|
968 (let ((compilation-error-list nil))
|
|
969 ;; Parse the last one.
|
|
970 (compile-reinitialize-errors nil nil 1)
|
|
971 compilation-error-list))))))))
|
|
972
|
|
973 (defun compilation-previous-file (n)
|
|
974 "Move point to the previous error for a different file than the current one."
|
|
975 (interactive "p")
|
|
976 (compilation-next-file (- n)))
|
|
977
|
|
978
|
|
979 (defun kill-compilation ()
|
|
980 "Kill the process made by the \\[compile] command."
|
|
981 (interactive)
|
|
982 (let ((buffer (compilation-find-buffer)))
|
|
983 (if (get-buffer-process buffer)
|
|
984 (interrupt-process (get-buffer-process buffer))
|
|
985 (error "The compilation process is not running."))))
|
|
986
|
|
987
|
|
988 ;; Parse any new errors in the compilation buffer,
|
|
989 ;; or reparse from the beginning if the user has asked for that.
|
|
990 (defun compile-reinitialize-errors (reparse
|
|
991 &optional limit-search find-at-least)
|
|
992 (save-excursion
|
|
993 ;; XEmacs change: Below we made a change to possibly change the
|
|
994 ;; selected window. If we don't save and restore the old window
|
|
995 ;; then if we get an error such as 'no more errors' we'll end up
|
|
996 ;; in the compilation buffer.
|
|
997 (save-window-excursion
|
|
998 (set-buffer compilation-last-buffer)
|
|
999 ;; If we are out of errors, or if user says "reparse",
|
|
1000 ;; discard the info we have, to force reparsing.
|
|
1001 (if (or (eq compilation-error-list t)
|
|
1002 reparse)
|
|
1003 (compilation-forget-errors))
|
|
1004 (if (and compilation-error-list
|
|
1005 (or (not limit-search)
|
|
1006 (> compilation-parsing-end limit-search))
|
|
1007 (or (not find-at-least)
|
|
1008 (>= (length compilation-error-list) find-at-least)))
|
|
1009 ;; Since compilation-error-list is non-nil, it points to a specific
|
|
1010 ;; error the user wanted. So don't move it around.
|
|
1011 nil
|
|
1012
|
|
1013 ;; XEmacs change: if the compilation buffer is already visible
|
|
1014 ;; in a window, use that instead of thrashing the display.
|
|
1015 (let ((w (get-buffer-window compilation-last-buffer)))
|
|
1016 (if w
|
|
1017 (select-window w)
|
|
1018 (switch-to-buffer compilation-last-buffer)))
|
|
1019
|
2
|
1020 ;; This was here for a long time (before my rewrite); why? --roland
|
|
1021 ;;(switch-to-buffer compilation-last-buffer)
|
0
|
1022 (set-buffer-modified-p nil)
|
|
1023 (if (< compilation-parsing-end (point-max))
|
|
1024 ;; compilation-error-list might be non-nil if we have a non-nil
|
|
1025 ;; LIMIT-SEARCH or FIND-AT-LEAST arg. In that case its value
|
|
1026 ;; records the current position in the error list, and we must
|
|
1027 ;; preserve that after reparsing.
|
|
1028 (let ((error-list-pos compilation-error-list))
|
|
1029 (funcall compilation-parse-errors-function
|
|
1030 limit-search
|
|
1031 (and find-at-least
|
|
1032 ;; We only need enough new parsed errors to reach
|
|
1033 ;; FIND-AT-LEAST errors past the current
|
|
1034 ;; position.
|
|
1035 (- find-at-least (length compilation-error-list))))
|
|
1036 ;; Remember the entire list for compilation-forget-errors. If
|
|
1037 ;; this is an incremental parse, append to previous list. If
|
|
1038 ;; we are parsing anew, compilation-forget-errors cleared
|
|
1039 ;; compilation-old-error-list above.
|
|
1040 (setq compilation-old-error-list
|
|
1041 (nconc compilation-old-error-list compilation-error-list))
|
|
1042 (if error-list-pos
|
|
1043 ;; We started in the middle of an existing list of parsed
|
|
1044 ;; errors before parsing more; restore that position.
|
|
1045 (setq compilation-error-list error-list-pos))
|
|
1046 ))))))
|
|
1047
|
2
|
1048 ;; XEmacs addition
|
|
1049 ;; FSF has added this by 19.34, but it is highly complex, why? -sb
|
|
1050 (defun compile-mouse-goto-error (event)
|
|
1051 "Visit the source for the error under the mouse.
|
|
1052 Use this command in a compilation log buffer."
|
|
1053 (interactive "e")
|
|
1054 (mouse-set-point event)
|
|
1055 (beginning-of-line)
|
|
1056 (compile-goto-error))
|
|
1057
|
0
|
1058 (defun compile-goto-error (&optional argp)
|
|
1059 "Visit the source for the error message point is on.
|
|
1060 Use this command in a compilation log buffer. Sets the mark at point there.
|
|
1061 \\[universal-argument] as a prefix arg means to reparse the buffer's error messages first;
|
|
1062 other kinds of prefix arguments are ignored."
|
|
1063 (interactive "P")
|
|
1064 (or (compilation-buffer-p (current-buffer))
|
|
1065 (error "Not in a compilation buffer."))
|
|
1066 (setq compilation-last-buffer (current-buffer))
|
|
1067 (compile-reinitialize-errors (consp argp) (point))
|
|
1068
|
|
1069 ;; Move to bol; the marker for the error on this line will point there.
|
|
1070 (beginning-of-line)
|
|
1071
|
|
1072 ;; Move compilation-error-list to the elt of compilation-old-error-list
|
|
1073 ;; we want.
|
|
1074 (setq compilation-error-list compilation-old-error-list)
|
|
1075 (while (and compilation-error-list
|
|
1076 (> (point) (car (car compilation-error-list))))
|
|
1077 (setq compilation-error-list (cdr compilation-error-list)))
|
|
1078
|
|
1079 ;; Move to another window, so that next-error's window changes
|
|
1080 ;; result in the desired setup.
|
|
1081 (or (one-window-p)
|
|
1082 (progn
|
|
1083 (other-window -1)
|
|
1084 ;; other-window changed the selected buffer,
|
|
1085 ;; but we didn't want to do that.
|
|
1086 (set-buffer compilation-last-buffer)))
|
|
1087
|
|
1088 (push-mark)
|
|
1089 (next-error 1))
|
|
1090
|
|
1091 ;; XEmacs addition
|
|
1092 (defun compile-mouse-maybe-goto-error (event &optional click-count)
|
|
1093 (interactive "e")
|
|
1094 (if (equal (event-button event) 2)
|
|
1095 (let ((buffer (current-buffer))
|
|
1096 (point (point))
|
|
1097 (config (current-window-configuration)))
|
|
1098 (condition-case nil
|
|
1099 (progn
|
|
1100 (compile-mouse-goto-error event)
|
|
1101 t)
|
|
1102 (error
|
|
1103 (set-window-configuration config)
|
|
1104 (set-buffer buffer)
|
|
1105 (goto-char point)
|
|
1106 nil)))))
|
|
1107
|
|
1108 ;; Return a compilation buffer.
|
|
1109 ;; If the current buffer is a compilation buffer, return it.
|
|
1110 ;; If compilation-last-buffer is set to a live buffer, use that.
|
|
1111 ;; Otherwise, look for a compilation buffer and signal an error
|
|
1112 ;; if there are none.
|
|
1113 (defun compilation-find-buffer (&optional other-buffer)
|
|
1114 (if (and (not other-buffer)
|
|
1115 (compilation-buffer-p (current-buffer)))
|
|
1116 ;; The current buffer is a compilation buffer.
|
|
1117 (current-buffer)
|
|
1118 (if (and compilation-last-buffer (buffer-name compilation-last-buffer)
|
2
|
1119 (compilation-buffer-p compilation-last-buffer)
|
0
|
1120 (or (not other-buffer) (not (eq compilation-last-buffer
|
|
1121 (current-buffer)))))
|
|
1122 compilation-last-buffer
|
|
1123 (let ((buffers (buffer-list)))
|
|
1124 (while (and buffers (or (not (compilation-buffer-p (car buffers)))
|
|
1125 (and other-buffer
|
|
1126 (eq (car buffers) (current-buffer)))))
|
|
1127 (setq buffers (cdr buffers)))
|
|
1128 (if buffers
|
|
1129 (car buffers)
|
|
1130 (or (and other-buffer
|
|
1131 (compilation-buffer-p (current-buffer))
|
|
1132 ;; The current buffer is a compilation buffer.
|
|
1133 (progn
|
|
1134 (if other-buffer
|
|
1135 (message "This is the only compilation buffer."))
|
|
1136 (current-buffer)))
|
|
1137 (error "No compilation started!")))))))
|
|
1138
|
|
1139 ;;;###autoload
|
|
1140 (defun next-error (&optional argp)
|
|
1141 "Visit next compilation error message and corresponding source code.
|
|
1142 This operates on the output from the \\[compile] command.
|
|
1143 If all preparsed error messages have been processed,
|
|
1144 the error message buffer is checked for new ones.
|
|
1145
|
|
1146 A prefix arg specifies how many error messages to move;
|
|
1147 negative means move back to previous error messages.
|
|
1148 Just C-u as a prefix means reparse the error message buffer
|
|
1149 and start at the first error.
|
|
1150
|
|
1151 \\[next-error] normally applies to the most recent compilation started,
|
|
1152 but as long as you are in the middle of parsing errors from one compilation
|
|
1153 output buffer, you stay with that compilation output buffer.
|
|
1154
|
|
1155 Use \\[next-error] in a compilation output buffer to switch to
|
|
1156 processing errors from that compilation.
|
|
1157
|
|
1158 See variables `compilation-parse-errors-function' and
|
|
1159 \`compilation-error-regexp-alist' for customization ideas."
|
|
1160 (interactive "P")
|
|
1161 (setq compilation-last-buffer (compilation-find-buffer))
|
|
1162 (compilation-goto-locus (compilation-next-error-locus
|
|
1163 ;; We want to pass a number here only if
|
|
1164 ;; we got a numeric prefix arg, not just C-u.
|
|
1165 (and (not (consp argp))
|
|
1166 (prefix-numeric-value argp))
|
|
1167 (consp argp))))
|
2
|
1168 ;;;###autoload (define-key ctl-x-map "`" 'next-error)
|
0
|
1169
|
|
1170 ;; XEmacs change
|
|
1171 ;;;###autoload
|
|
1172 (defun previous-error (&optional argp)
|
|
1173 "Visit previous compilation error message and corresponding source code.
|
|
1174 This operates on the output from the \\[compile] command."
|
|
1175 (interactive "P")
|
|
1176 (next-error (cond ((null argp) -1)
|
|
1177 ((numberp argp) (- argp))
|
|
1178 (t argp))))
|
|
1179
|
|
1180 ;;;###autoload
|
|
1181 (defun first-error ()
|
|
1182 "Reparse the error message buffer and start at the first error
|
|
1183 Visit corresponding source code.
|
|
1184 This operates on the output from the \\[compile] command."
|
|
1185 (interactive)
|
|
1186 (next-error '(4)))
|
|
1187
|
|
1188 (defun compilation-next-error-locus (&optional move reparse silent)
|
|
1189 "Visit next compilation error and return locus in corresponding source code.
|
|
1190 This operates on the output from the \\[compile] command.
|
|
1191 If all preparsed error messages have been processed,
|
|
1192 the error message buffer is checked for new ones.
|
|
1193
|
|
1194 Returns a cons (ERROR . SOURCE) of two markers: ERROR is a marker at the
|
|
1195 location of the error message in the compilation buffer, and SOURCE is a
|
|
1196 marker at the location in the source code indicated by the error message.
|
|
1197
|
|
1198 Optional first arg MOVE says how many error messages to move forwards (or
|
|
1199 backwards, if negative); default is 1. Optional second arg REPARSE, if
|
|
1200 non-nil, says to reparse the error message buffer and reset to the first
|
|
1201 error (plus MOVE - 1). If optional third argument SILENT is non-nil, return
|
|
1202 nil instead of raising an error if there are no more errors.
|
|
1203
|
|
1204 The current buffer should be the desired compilation output buffer."
|
|
1205 (or move (setq move 1))
|
|
1206 (compile-reinitialize-errors reparse nil (and (not reparse)
|
|
1207 (if (< move 1) 0 (1- move))))
|
|
1208 (let (next-errors next-error)
|
|
1209 (catch 'no-next-error
|
|
1210 (save-excursion
|
|
1211 (set-buffer compilation-last-buffer)
|
|
1212 ;; compilation-error-list points to the "current" error.
|
|
1213 (setq next-errors
|
|
1214 (if (> move 0)
|
|
1215 (nthcdr (1- move)
|
|
1216 compilation-error-list)
|
|
1217 ;; Zero or negative arg; we need to move back in the list.
|
|
1218 (let ((n (1- move))
|
|
1219 (i 0)
|
|
1220 (e compilation-old-error-list))
|
|
1221 ;; See how many cdrs away the current error is from the start.
|
|
1222 (while (not (eq e compilation-error-list))
|
|
1223 (setq i (1+ i)
|
|
1224 e (cdr e)))
|
|
1225 (if (> (- n) i)
|
|
1226 (error "Moved back past first error")
|
|
1227 (nthcdr (+ i n) compilation-old-error-list))))
|
|
1228 next-error (car next-errors))
|
|
1229 (while
|
|
1230 (if (null next-error)
|
|
1231 (progn
|
|
1232 (and move (/= move 1)
|
|
1233 (error (if (> move 0)
|
|
1234 "Moved past last error"
|
|
1235 "Moved back past first error")))
|
|
1236 ;; Forget existing error messages if compilation has finished.
|
|
1237 ;;; XEmacs change by Barry Warsaw.
|
|
1238 ;;; Without this, if you get a "no more errors" error, then you can't do
|
|
1239 ;;; previous-error or goto-error until you kill the buffer.
|
|
1240 ; (if (not (and (get-buffer-process (current-buffer))
|
|
1241 ; (eq (process-status
|
|
1242 ; (get-buffer-process
|
|
1243 ; (current-buffer)))
|
|
1244 ; 'run)))
|
|
1245 ; (compilation-forget-errors))
|
|
1246 (if silent
|
|
1247 (throw 'no-next-error nil)
|
|
1248 (error (concat compilation-error-message
|
|
1249 (and (get-buffer-process (current-buffer))
|
2
|
1250 (eq (process-status
|
|
1251 (get-buffer-process
|
0
|
1252 (current-buffer)))
|
|
1253 'run)
|
|
1254 " yet")))))
|
|
1255 (setq compilation-error-list (cdr next-errors))
|
|
1256 (if (null (cdr next-error))
|
|
1257 ;; This error is boring. Go to the next.
|
|
1258 t
|
|
1259 (or (markerp (cdr next-error))
|
|
1260 ;; This error has a filename/lineno pair.
|
|
1261 ;; Find the file and turn it into a marker.
|
|
1262 (let* ((fileinfo (car (cdr next-error)))
|
|
1263 (cbuf (current-buffer)) ;XEmacs addition
|
|
1264 (buffer (apply 'compilation-find-file
|
|
1265 (car next-error) fileinfo)))
|
|
1266 (if (null buffer)
|
|
1267 ;; We can't find this error's file.
|
|
1268 ;; Remove all errors in the same file.
|
|
1269 (progn
|
|
1270 (setq next-errors compilation-old-error-list)
|
|
1271 (while next-errors
|
|
1272 (and (consp (cdr (car next-errors)))
|
|
1273 (equal (car (cdr (car next-errors)))
|
|
1274 fileinfo)
|
|
1275 (progn
|
|
1276 (set-marker (car (car next-errors)) nil)
|
|
1277 (setcdr (car next-errors) nil)))
|
|
1278 (setq next-errors (cdr next-errors)))
|
|
1279 ;; Look for the next error.
|
|
1280 t)
|
|
1281 ;; We found the file. Get a marker for this error.
|
|
1282 ;; compilation-old-error-list is a buffer-local
|
|
1283 ;; variable, so we must be careful to extract its value
|
|
1284 ;; before switching to the source file buffer.
|
|
1285 (let ((errors compilation-old-error-list)
|
|
1286 (last-line (nth 1 (cdr next-error)))
|
|
1287 (column (nth 2 (cdr next-error))))
|
|
1288 (set-buffer buffer)
|
|
1289 (save-excursion
|
|
1290 (save-restriction
|
|
1291 (widen)
|
|
1292 (goto-line last-line)
|
|
1293 (if (and column (> column 0))
|
|
1294 ;; Columns in error msgs are 1-origin.
|
|
1295 (move-to-column (1- column))
|
|
1296 (beginning-of-line))
|
|
1297 (setcdr next-error (point-marker))
|
|
1298 ;; Make all the other error messages referring
|
|
1299 ;; to the same file have markers into the buffer.
|
|
1300 (while errors
|
|
1301 (and (consp (cdr (car errors)))
|
|
1302 (equal (car (cdr (car errors))) fileinfo)
|
|
1303 (let* ((this (nth 1 (cdr (car errors))))
|
|
1304 (column (nth 2 (cdr (car errors))))
|
|
1305 (lines (- this last-line)))
|
|
1306 (if (eq selective-display t)
|
|
1307 ;; When selective-display is t,
|
|
1308 ;; each C-m is a line boundary,
|
|
1309 ;; as well as each newline.
|
|
1310 (if (< lines 0)
|
|
1311 (re-search-backward "[\n\C-m]"
|
|
1312 nil 'end
|
|
1313 (- lines))
|
|
1314 (re-search-forward "[\n\C-m]"
|
|
1315 nil 'end
|
|
1316 lines))
|
|
1317 (forward-line lines))
|
|
1318 (if (and column (> column 1))
|
|
1319 (move-to-column (1- column))
|
|
1320 (beginning-of-line))
|
|
1321 (setq last-line this)
|
|
1322 (setcdr (car errors) (point-marker))))
|
|
1323 (setq errors (cdr errors)))))
|
|
1324 ;; XEmacs addition
|
|
1325 (set-buffer cbuf)))))
|
|
1326 ;; If we didn't get a marker for this error, or this
|
|
1327 ;; marker's buffer was killed, go on to the next one.
|
|
1328 (or (not (markerp (cdr next-error)))
|
|
1329 (not (marker-buffer (cdr next-error))))))
|
|
1330 (setq next-errors compilation-error-list
|
|
1331 next-error (car next-errors)))
|
|
1332
|
|
1333 ;; XEmacs -- move this inside save-excursion
|
|
1334 ;; Skip over multiple error messages for the same source location,
|
|
1335 ;; so the next C-x ` won't go to an error in the same place.
|
|
1336 (while (and compilation-error-list
|
|
1337 (equal (cdr (car compilation-error-list))
|
|
1338 (cdr next-error)))
|
|
1339 (setq compilation-error-list (cdr compilation-error-list)))
|
|
1340 ))
|
|
1341
|
|
1342 ;; XEmacs change: If a new window has to be displayed, select the other
|
|
1343 ;; window to avoid swapping the position of the compilation error buffer.
|
|
1344 (and next-error (get-buffer-window (marker-buffer (car next-error)))
|
|
1345 (progn
|
|
1346 (select-window (get-buffer-window (marker-buffer (car next-error))))
|
|
1347 (other-window -1)))
|
|
1348
|
|
1349 ;; We now have a marker for the position of the error source code.
|
|
1350 ;; NEXT-ERROR is a cons (ERROR . SOURCE) of two markers.
|
|
1351 next-error))
|
|
1352
|
|
1353 (defun compilation-goto-locus (next-error)
|
|
1354 "Jump to an error locus returned by `compilation-next-error-locus'.
|
|
1355 Takes one argument, a cons (ERROR . SOURCE) of two markers.
|
|
1356 Selects a window with point at SOURCE, with another window displaying ERROR."
|
|
1357 ;; XEmacs: this code is horrendous, and makes windows do all sorts of
|
|
1358 ;; weird things when you're using separate frames for the compilation
|
|
1359 ;; and source buffer.
|
|
1360 ; (if (and (window-dedicated-p (selected-window))
|
|
1361 ; (eq (selected-window) (frame-root-window)))
|
|
1362 ; (switch-to-buffer-other-frame (marker-buffer (cdr next-error)))
|
|
1363 ; (switch-to-buffer (marker-buffer (cdr next-error))))
|
|
1364 ; (goto-char (cdr next-error))
|
|
1365 ; ;; If narrowing got in the way of
|
|
1366 ; ;; going to the right place, widen.
|
|
1367 ; (or (= (point) (marker-position (cdr next-error)))
|
|
1368 ; (progn
|
|
1369 ; (widen)
|
|
1370 ; (goto-char (cdr next-error))))
|
|
1371 ;
|
|
1372 ; ;; Show compilation buffer in other window, scrolled to this error.
|
|
1373 ; (let* ((pop-up-windows t)
|
|
1374 ; (w (or (get-buffer-window (marker-buffer (car next-error)) 'visible)
|
|
1375 ; (display-buffer (marker-buffer (car next-error))))))
|
|
1376 ; (set-window-point w (car next-error))
|
|
1377 ; (set-window-start w (car next-error))
|
|
1378 ; (compilation-set-window-height w)))
|
|
1379
|
|
1380 (let* ((pop-up-windows t)
|
|
1381 (compilation-buffer (marker-buffer (car next-error)))
|
|
1382 (source-buffer (marker-buffer (cdr next-error)))
|
|
1383 ;; make sure compilation buffer is visible ...
|
|
1384 (compilation-window
|
|
1385 ;; Use an existing window if it is in a visible frame.
|
|
1386 (or (get-buffer-window compilation-buffer 'visible)
|
|
1387 ;; Pop up a window.
|
|
1388 (display-buffer compilation-buffer))))
|
|
1389
|
|
1390 ;; now, make the compilation buffer **STAY WHERE IT IS** and
|
|
1391 ;; make sure the source buffer is visible
|
|
1392
|
|
1393 (select-window compilation-window)
|
|
1394 (pop-to-buffer source-buffer)
|
|
1395
|
|
1396 ;; now put things aright in the compilation window.
|
|
1397 (set-window-point compilation-window (car next-error))
|
|
1398 (set-window-start compilation-window (car next-error))
|
|
1399 (compilation-set-window-height compilation-window)
|
|
1400
|
|
1401 ;; now put things aright in the source window.
|
|
1402
|
|
1403 (set-buffer source-buffer)
|
|
1404 (goto-char (cdr next-error))
|
|
1405 ;; If narrowing got in the way of
|
|
1406 ;; going to the right place, widen.
|
|
1407 (or (= (point) (marker-position (cdr next-error)))
|
|
1408 (progn
|
|
1409 (widen)
|
|
1410 (goto-char (cdr next-error))))))
|
2
|
1411
|
0
|
1412
|
|
1413 ;; Find a buffer for file FILENAME.
|
|
1414 ;; Search the directories in compilation-search-path.
|
|
1415 ;; A nil in compilation-search-path means to try the
|
|
1416 ;; current directory, which is passed in DIR.
|
|
1417 ;; If FILENAME is not found at all, ask the user where to find it.
|
|
1418 ;; Pop up the buffer containing MARKER and scroll to MARKER if we ask the user.
|
|
1419 (defun compilation-find-file (marker filename dir &rest formats)
|
|
1420 (or formats (setq formats '("%s")))
|
|
1421 (let ((dirs compilation-search-path)
|
|
1422 buffer thisdir fmts name)
|
|
1423 (if (file-name-absolute-p filename)
|
|
1424 ;; The file name is absolute. Use its explicit directory as
|
|
1425 ;; the first in the search path, and strip it from FILENAME.
|
|
1426 (setq filename (abbreviate-file-name (expand-file-name filename))
|
|
1427 dirs (cons (file-name-directory filename) dirs)
|
|
1428 filename (file-name-nondirectory filename)))
|
|
1429 ;; Now search the path.
|
|
1430 (while (and dirs (null buffer))
|
|
1431 (setq thisdir (or (car dirs) dir)
|
|
1432 fmts formats)
|
|
1433 ;; For each directory, try each format string.
|
|
1434 (while (and fmts (null buffer))
|
|
1435 (setq name (expand-file-name (format (car fmts) filename) thisdir)
|
|
1436 buffer (and (file-exists-p name)
|
|
1437 (find-file-noselect name))
|
|
1438 fmts (cdr fmts)))
|
|
1439 (setq dirs (cdr dirs)))
|
|
1440 (or buffer
|
|
1441 ;; The file doesn't exist.
|
|
1442 ;; Ask the user where to find it.
|
|
1443 ;; If he hits C-g, then the next time he does
|
|
1444 ;; next-error, he'll skip past it.
|
|
1445 (let* ((pop-up-windows t)
|
|
1446 (w (display-buffer (marker-buffer marker))))
|
|
1447 (set-window-point w marker)
|
|
1448 (set-window-start w marker)
|
|
1449 (let ((name (expand-file-name
|
|
1450 (read-file-name
|
|
1451 (format "Find this error in: (default %s) "
|
|
1452 filename)
|
|
1453 dir filename t))))
|
|
1454 (if (file-directory-p name)
|
|
1455 (setq name (expand-file-name filename name)))
|
|
1456 (and (file-exists-p name)
|
|
1457 (find-file-noselect name)))))))
|
|
1458
|
|
1459 ;; Set compilation-error-list to nil, and unchain the markers that point to the
|
|
1460 ;; error messages and their text, so that they no longer slow down gap motion.
|
|
1461 ;; This would happen anyway at the next garbage collection, but it is better to
|
|
1462 ;; do it right away.
|
|
1463 (defun compilation-forget-errors ()
|
|
1464 (while compilation-old-error-list
|
|
1465 (let ((next-error (car compilation-old-error-list)))
|
|
1466 (set-marker (car next-error) nil)
|
|
1467 (if (markerp (cdr next-error))
|
|
1468 (set-marker (cdr next-error) nil)))
|
|
1469 (setq compilation-old-error-list (cdr compilation-old-error-list)))
|
|
1470 (setq compilation-error-list nil
|
|
1471 compilation-directory-stack nil
|
|
1472 compilation-parsing-end 1))
|
|
1473
|
|
1474
|
|
1475 (defun count-regexp-groupings (regexp)
|
|
1476 "Return the number of \\( ... \\) groupings in REGEXP (a string)."
|
|
1477 (let ((groupings 0)
|
|
1478 (len (length regexp))
|
|
1479 (i 0)
|
|
1480 c)
|
|
1481 (while (< i len)
|
|
1482 (setq c (aref regexp i)
|
|
1483 i (1+ i))
|
|
1484 (cond ((= c ?\[)
|
|
1485 ;; Find the end of this [...].
|
|
1486 (while (and (< i len)
|
|
1487 (not (= (aref regexp i) ?\])))
|
|
1488 (setq i (1+ i))))
|
|
1489 ((= c ?\\)
|
|
1490 (if (< i len)
|
|
1491 (progn
|
|
1492 (setq c (aref regexp i)
|
|
1493 i (1+ i))
|
|
1494 (if (= c ?\))
|
|
1495 ;; We found the end of a grouping,
|
|
1496 ;; so bump our counter.
|
|
1497 (setq groupings (1+ groupings))))))))
|
|
1498 groupings))
|
|
1499
|
|
1500 (defun compilation-parse-errors (limit-search find-at-least)
|
|
1501 "Parse the current buffer as grep, cc or lint error messages.
|
|
1502 See variable `compilation-parse-errors-function' for the interface it uses."
|
|
1503 (setq compilation-error-list nil)
|
|
1504 (message "Parsing error messages...")
|
|
1505 (let (;;text-buffer -- unused
|
|
1506 orig orig-expanded parent-expanded
|
|
1507 regexp enter-group leave-group error-group
|
|
1508 alist subexpr error-regexp-groups
|
|
1509 (found-desired nil)
|
|
1510 (compilation-num-errors-found 0))
|
|
1511
|
|
1512 ;; Don't reparse messages already seen at last parse.
|
|
1513 (goto-char compilation-parsing-end)
|
|
1514 ;; Don't parse the first two lines as error messages.
|
|
1515 ;; This matters for grep.
|
|
1516 (if (bobp)
|
|
1517 (progn
|
|
1518 (forward-line 2)
|
|
1519 ;; Move back so point is before the newline.
|
|
1520 ;; This matters because some error regexps use \n instead of ^
|
|
1521 ;; to be faster.
|
|
1522 (forward-char -1)))
|
|
1523
|
|
1524 ;; Compile all the regexps we want to search for into one.
|
|
1525 (setq regexp (concat "\\(" compilation-enter-directory-regexp "\\)\\|"
|
|
1526 "\\(" compilation-leave-directory-regexp "\\)\\|"
|
|
1527 "\\(" (mapconcat (function
|
|
1528 (lambda (elt)
|
|
1529 (concat "\\(" (car elt) "\\)")))
|
|
1530 compilation-error-regexp-alist
|
|
1531 "\\|") "\\)"))
|
|
1532
|
|
1533 ;; Find out how many \(...\) groupings are in each of the regexps, and set
|
|
1534 ;; *-GROUP to the grouping containing each constituent regexp (whose
|
|
1535 ;; subgroups will come immediately thereafter) of the big regexp we have
|
|
1536 ;; just constructed.
|
|
1537 (setq enter-group 1
|
|
1538 leave-group (+ enter-group
|
|
1539 (count-regexp-groupings
|
|
1540 compilation-enter-directory-regexp)
|
|
1541 1)
|
|
1542 error-group (+ leave-group
|
|
1543 (count-regexp-groupings
|
|
1544 compilation-leave-directory-regexp)
|
|
1545 1))
|
|
1546
|
|
1547 ;; Compile an alist (IDX FILE LINE [COL]), where IDX is the number of
|
|
1548 ;; the subexpression for an entire error-regexp, and FILE and LINE (and
|
|
1549 ;; possibly COL) are the numbers for the subexpressions giving the file
|
|
1550 ;; name and line number (and possibly column number).
|
|
1551 (setq alist (or compilation-error-regexp-alist
|
|
1552 (error "compilation-error-regexp-alist is empty!"))
|
|
1553 subexpr (1+ error-group))
|
|
1554 (while alist
|
2
|
1555 (setq error-regexp-groups
|
|
1556 (cons (list subexpr
|
|
1557 (+ subexpr (nth 1 (car alist)))
|
|
1558 (+ subexpr (nth 2 (car alist)))
|
|
1559 ;;#### This is buggy in FSFmacs
|
|
1560 (let ((col (nth 3 (car alist))))
|
|
1561 (and col
|
|
1562 (+ subexpr col))))
|
|
1563 error-regexp-groups))
|
0
|
1564 (setq subexpr (+ subexpr 1 (count-regexp-groupings (car (car alist)))))
|
|
1565 (setq alist (cdr alist)))
|
|
1566
|
|
1567 ;; Set up now the expanded, abbreviated directory variables
|
|
1568 ;; that compile-abbreviate-directory will need, so we can
|
|
1569 ;; compute them just once here.
|
|
1570 (setq orig (abbreviate-file-name default-directory)
|
|
1571 orig-expanded (abbreviate-file-name
|
|
1572 (file-truename default-directory))
|
|
1573 parent-expanded (abbreviate-file-name
|
|
1574 (expand-file-name "../" orig-expanded)))
|
|
1575
|
|
1576 (while (and (not found-desired)
|
|
1577 ;; We don't just pass LIMIT-SEARCH to re-search-forward
|
|
1578 ;; because we want to find matches containing LIMIT-SEARCH
|
|
1579 ;; but which extend past it.
|
88
|
1580 ;; Instead of using re-search-forward,
|
|
1581 ;; we use this loop which tries only at each line.
|
|
1582 (progn
|
|
1583 (while (and (not (eobp))
|
|
1584 (not (looking-at regexp)))
|
|
1585 (forward-line 1))
|
|
1586 (not (eobp))))
|
|
1587
|
|
1588 ;; Move to the end of the match we just found.
|
|
1589 (goto-char (match-end 0))
|
0
|
1590
|
|
1591 ;; Figure out which constituent regexp matched.
|
|
1592 (cond ((match-beginning enter-group)
|
|
1593 ;; The match was the enter-directory regexp.
|
|
1594 (let ((dir
|
|
1595 (file-name-as-directory
|
|
1596 (expand-file-name
|
|
1597 (buffer-substring (match-beginning (+ enter-group 1))
|
|
1598 (match-end (+ enter-group 1)))))))
|
|
1599 ;; The directory name in the "entering" message
|
|
1600 ;; is a truename. Try to convert it to a form
|
|
1601 ;; like what the user typed in.
|
|
1602 (setq dir
|
|
1603 (compile-abbreviate-directory dir orig orig-expanded
|
|
1604 parent-expanded))
|
|
1605 (setq compilation-directory-stack
|
|
1606 (cons dir compilation-directory-stack))
|
|
1607 (and (file-directory-p dir)
|
|
1608 (setq default-directory dir)))
|
|
1609
|
|
1610 (and limit-search (>= (point) limit-search)
|
|
1611 ;; The user wanted a specific error, and we're past it.
|
|
1612 ;; We do this check here (and in the leave-group case)
|
|
1613 ;; rather than at the end of the loop because if the last
|
|
1614 ;; thing seen is an error message, we must carefully
|
|
1615 ;; discard the last error when it is the first in a new
|
|
1616 ;; file (see below in the error-group case).
|
|
1617 (setq found-desired t)))
|
|
1618
|
|
1619 ((match-beginning leave-group)
|
|
1620 ;; The match was the leave-directory regexp.
|
|
1621 (let ((beg (match-beginning (+ leave-group 1)))
|
|
1622 (stack compilation-directory-stack))
|
|
1623 (if beg
|
|
1624 (let ((dir
|
|
1625 (file-name-as-directory
|
|
1626 (expand-file-name
|
|
1627 (buffer-substring beg
|
|
1628 (match-end (+ leave-group
|
|
1629 1)))))))
|
|
1630 ;; The directory name in the "leaving" message
|
|
1631 ;; is a truename. Try to convert it to a form
|
|
1632 ;; like what the user typed in.
|
|
1633 (setq dir
|
|
1634 (compile-abbreviate-directory dir orig orig-expanded
|
|
1635 parent-expanded))
|
|
1636 (while (and stack
|
|
1637 (not (string-equal (car stack) dir)))
|
|
1638 (setq stack (cdr stack)))))
|
|
1639 (setq compilation-directory-stack (cdr stack))
|
|
1640 (setq stack (car compilation-directory-stack))
|
|
1641 (if stack
|
|
1642 (setq default-directory stack))
|
|
1643 )
|
|
1644
|
|
1645 (and limit-search (>= (point) limit-search)
|
|
1646 ;; The user wanted a specific error, and we're past it.
|
|
1647 ;; We do this check here (and in the enter-group case)
|
|
1648 ;; rather than at the end of the loop because if the last
|
|
1649 ;; thing seen is an error message, we must carefully
|
|
1650 ;; discard the last error when it is the first in a new
|
|
1651 ;; file (see below in the error-group case).
|
|
1652 (setq found-desired t)))
|
|
1653
|
|
1654 ((match-beginning error-group)
|
|
1655 ;; The match was the composite error regexp.
|
|
1656 ;; Find out which individual regexp matched.
|
|
1657 (setq alist error-regexp-groups)
|
|
1658 (while (and alist
|
|
1659 (null (match-beginning (car (car alist)))))
|
|
1660 (setq alist (cdr alist)))
|
|
1661 (if alist
|
|
1662 (setq alist (car alist))
|
|
1663 (error "compilation-parse-errors: impossible regexp match!"))
|
|
1664
|
|
1665 ;; Extract the file name and line number from the error message.
|
|
1666 (let ((beginning-of-match (match-beginning 0)) ;looking-at nukes
|
|
1667 (filename (buffer-substring (match-beginning (nth 1 alist))
|
|
1668 (match-end (nth 1 alist))))
|
|
1669 (linenum (string-to-int
|
|
1670 (buffer-substring
|
|
1671 (match-beginning (nth 2 alist))
|
|
1672 (match-end (nth 2 alist)))))
|
|
1673 (column (and (nth 3 alist)
|
|
1674 (match-beginning (nth 3 alist))
|
|
1675 (string-to-int
|
|
1676 (buffer-substring
|
|
1677 (match-beginning (nth 3 alist))
|
|
1678 (match-end (nth 3 alist)))))))
|
|
1679
|
|
1680 ;; Check for a comint-file-name-prefix and prepend it if
|
|
1681 ;; appropriate. (This is very useful for
|
|
1682 ;; compilation-minor-mode in an rlogin-mode buffer.)
|
|
1683 (and (boundp 'comint-file-name-prefix)
|
|
1684 ;; If the file name is relative, default-directory will
|
|
1685 ;; already contain the comint-file-name-prefix (done by
|
|
1686 ;; compile-abbreviate-directory).
|
|
1687 (file-name-absolute-p filename)
|
|
1688 (setq filename (concat comint-file-name-prefix filename)))
|
2
|
1689
|
|
1690 ;; Some compilers (e.g. Sun's java compiler, reportedly)
|
|
1691 ;; produce bogus file names like "./bar//foo.c" for the file
|
|
1692 ;; "bar/foo.c"; expand-file-name will collapse these into
|
|
1693 ;; "/foo.c" and fail to find the appropriate file. So we look
|
|
1694 ;; for doubled slashes in the file name and fix them up in the
|
|
1695 ;; buffer.
|
|
1696 (when (fboundp 'command-line-normalize-file-name)
|
|
1697 (setq filename (command-line-normalize-file-name filename)))
|
0
|
1698 (setq filename (cons filename (cons default-directory
|
|
1699 (nthcdr 4 alist))))
|
|
1700
|
|
1701
|
|
1702 ;; Locate the erring file and line.
|
|
1703 ;; Cons a new elt onto compilation-error-list,
|
|
1704 ;; giving a marker for the current compilation buffer
|
|
1705 ;; location, and the file and line number of the error.
|
|
1706 (save-excursion
|
|
1707 ;; Save as the start of the error the beginning of the
|
|
1708 ;; line containing the match unless the match starts at a
|
|
1709 ;; newline, in which case the beginning of the next line.
|
|
1710 (goto-char beginning-of-match)
|
|
1711 (forward-line (if (eolp) 1 0))
|
|
1712 (let ((this (cons (point-marker)
|
|
1713 (list filename linenum column))))
|
|
1714 ;; Don't add the same source line more than once.
|
|
1715 (if (equal (cdr this) (cdr (car compilation-error-list)))
|
|
1716 nil
|
|
1717 (setq compilation-error-list
|
|
1718 (cons this
|
|
1719 compilation-error-list))
|
|
1720 (setq compilation-num-errors-found
|
|
1721 (1+ compilation-num-errors-found)))))
|
|
1722 (and (or (and find-at-least (> compilation-num-errors-found
|
|
1723 find-at-least))
|
|
1724 (and limit-search (>= (point) limit-search)))
|
|
1725 ;; We have found as many new errors as the user wants,
|
|
1726 ;; or past the buffer position he indicated. We
|
|
1727 ;; continue to parse until we have seen all the
|
|
1728 ;; consecutive errors in the same file, so the error
|
|
1729 ;; positions will be recorded as markers in this buffer
|
|
1730 ;; that might change.
|
|
1731 (cdr compilation-error-list) ; Must check at least two.
|
|
1732 (not (equal (car (cdr (nth 0 compilation-error-list)))
|
|
1733 (car (cdr (nth 1 compilation-error-list)))))
|
|
1734 (progn
|
|
1735 ;; Discard the error just parsed, so that the next
|
|
1736 ;; parsing run can get it and the following errors in
|
|
1737 ;; the same file all at once. If we didn't do this, we
|
|
1738 ;; would have the same problem we are trying to avoid
|
|
1739 ;; with the test above, just delayed until the next run!
|
|
1740 (setq compilation-error-list
|
|
1741 (cdr compilation-error-list))
|
|
1742 (goto-char beginning-of-match)
|
|
1743 (setq found-desired t)))
|
|
1744 )
|
|
1745 )
|
|
1746 (t
|
|
1747 (error "compilation-parse-errors: known groups didn't match!")))
|
|
1748
|
2
|
1749 (message "Parsing error messages...%d (%.0f%% of buffer)"
|
0
|
1750 compilation-num-errors-found
|
2
|
1751 ;; Use floating-point because (* 100 (point)) frequently
|
|
1752 ;; exceeds the range of Emacs Lisp integers.
|
|
1753 (/ (* 100.0 (point)) (point-max)))
|
0
|
1754
|
|
1755 (and limit-search (>= (point) limit-search)
|
|
1756 ;; The user wanted a specific error, and we're past it.
|
|
1757 (setq found-desired t)))
|
|
1758 (setq compilation-parsing-end (if found-desired
|
|
1759 (point)
|
|
1760 ;; We have searched the whole buffer.
|
|
1761 (point-max))))
|
|
1762 (setq compilation-error-list (nreverse compilation-error-list))
|
|
1763 (message "Parsing error messages...done"))
|
|
1764
|
|
1765 ;; If directory DIR is a subdir of ORIG or of ORIG's parent,
|
|
1766 ;; return a relative name for it starting from ORIG or its parent.
|
|
1767 ;; ORIG-EXPANDED is an expanded version of ORIG.
|
|
1768 ;; PARENT-EXPANDED is an expanded version of ORIG's parent.
|
|
1769 ;; Those two args could be computed here, but we run faster by
|
|
1770 ;; having the caller compute them just once.
|
|
1771 (defun compile-abbreviate-directory (dir orig orig-expanded parent-expanded)
|
|
1772 ;; Apply canonical abbreviations to DIR first thing.
|
|
1773 ;; Those abbreviations are already done in the other arguments passed.
|
|
1774 (setq dir (abbreviate-file-name dir))
|
|
1775
|
|
1776 ;; Check for a comint-file-name-prefix and prepend it if appropriate.
|
|
1777 ;; (This is very useful for compilation-minor-mode in an rlogin-mode
|
|
1778 ;; buffer.)
|
|
1779 (if (boundp 'comint-file-name-prefix)
|
|
1780 (setq dir (concat comint-file-name-prefix dir)))
|
|
1781
|
|
1782 (if (and (> (length dir) (length orig-expanded))
|
|
1783 (string= orig-expanded
|
|
1784 (substring dir 0 (length orig-expanded))))
|
|
1785 (setq dir
|
|
1786 (concat orig
|
|
1787 (substring dir (length orig-expanded)))))
|
|
1788 (if (and (> (length dir) (length parent-expanded))
|
|
1789 (string= parent-expanded
|
|
1790 (substring dir 0 (length parent-expanded))))
|
|
1791 (setq dir
|
|
1792 (concat (file-name-directory
|
|
1793 (directory-file-name orig))
|
|
1794 (substring dir (length parent-expanded)))))
|
|
1795 dir)
|
|
1796
|
|
1797 (provide 'compile)
|
|
1798
|
|
1799 ;;; compile.el ends here
|