]> code.delx.au - gnu-emacs/blob - lisp/progmodes/compile.el
* progmodes/compile.el (compilation-filter): If inserting at end
[gnu-emacs] / lisp / progmodes / compile.el
1 ;;; compile.el --- run compiler as inferior of Emacs, parse error messages
2
3 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 ;; Free Software Foundation, Inc.
6
7 ;; Authors: Roland McGrath <roland@gnu.org>,
8 ;; Daniel Pfeiffer <occitan@esperanto.org>
9 ;; Maintainer: FSF
10 ;; Keywords: tools, processes
11
12 ;; This file is part of GNU Emacs.
13
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
18
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26
27 ;;; Commentary:
28
29 ;; This package provides the compile facilities documented in the Emacs user's
30 ;; manual.
31
32 ;; This mode uses some complex data-structures:
33
34 ;; LOC (or location) is a list of (COLUMN LINE FILE-STRUCTURE)
35
36 ;; COLUMN and LINE are numbers parsed from an error message. COLUMN and maybe
37 ;; LINE will be nil for a message that doesn't contain them. Then the
38 ;; location refers to a indented beginning of line or beginning of file.
39 ;; Once any location in some file has been jumped to, the list is extended to
40 ;; (COLUMN LINE FILE-STRUCTURE MARKER TIMESTAMP . VISITED)
41 ;; for all LOCs pertaining to that file.
42 ;; MARKER initially points to LINE and COLUMN in a buffer visiting that file.
43 ;; Being a marker it sticks to some text, when the buffer grows or shrinks
44 ;; before that point. VISITED is t if we have jumped there, else nil.
45 ;; TIMESTAMP is necessary because of "incremental compilation": `omake -P'
46 ;; polls filesystem for changes and recompiles when a file is modified
47 ;; using the same *compilation* buffer. this necessitates re-parsing markers.
48
49 ;; FILE-STRUCTURE is a list of
50 ;; ((FILENAME . DIRECTORY) FORMATS (LINE LOC ...) ...)
51
52 ;; FILENAME is a string parsed from an error message. DIRECTORY is a string
53 ;; obtained by following directory change messages. DIRECTORY will be nil for
54 ;; an absolute filename. FORMATS is a list of formats to apply to FILENAME if
55 ;; a file of that name can't be found.
56 ;; The rest of the list is an alist of elements with LINE as key. The keys
57 ;; are either nil or line numbers. If present, nil comes first, followed by
58 ;; the numbers in decreasing order. The LOCs for each line are again an alist
59 ;; ordered the same way. Note that the whole file structure is referenced in
60 ;; every LOC.
61
62 ;; MESSAGE is a list of (LOC TYPE END-LOC)
63
64 ;; TYPE is 0 for info or 1 for warning if the message matcher identified it as
65 ;; such, 2 otherwise (for a real error). END-LOC is a LOC pointing to the
66 ;; other end, if the parsed message contained a range. If the end of the
67 ;; range didn't specify a COLUMN, it defaults to -1, meaning end of line.
68 ;; These are the value of the `message' text-properties in the compilation
69 ;; buffer.
70
71 ;;; Code:
72
73 (eval-when-compile (require 'cl))
74 (require 'tool-bar)
75 (require 'comint)
76
77 (defvar font-lock-extra-managed-props)
78 (defvar font-lock-keywords)
79 (defvar font-lock-maximum-size)
80 (defvar font-lock-support-mode)
81
82
83 (defgroup compilation nil
84 "Run compiler as inferior of Emacs, parse error messages."
85 :group 'tools
86 :group 'processes)
87
88
89 ;;;###autoload
90 (defcustom compilation-mode-hook nil
91 "List of hook functions run by `compilation-mode' (see `run-mode-hooks')."
92 :type 'hook
93 :group 'compilation)
94
95 ;;;###autoload
96 (defcustom compilation-start-hook nil
97 "List of hook functions run by `compilation-start' on the compilation process.
98 \(See `run-hook-with-args').
99 If you use \"omake -P\" and do not want \\[save-buffers-kill-terminal] to ask whether you want
100 the compilation to be killed, you can use this hook:
101 (add-hook 'compilation-start-hook
102 (lambda (process) (set-process-query-on-exit-flag process nil)) nil t)"
103 :type 'hook
104 :group 'compilation)
105
106 ;;;###autoload
107 (defcustom compilation-window-height nil
108 "Number of lines in a compilation window. If nil, use Emacs default."
109 :type '(choice (const :tag "Default" nil)
110 integer)
111 :group 'compilation)
112
113 (defvar compilation-first-column 1
114 "*This is how compilers number the first column, usually 1 or 0.")
115
116 (defvar compilation-parse-errors-filename-function nil
117 "Function to call to post-process filenames while parsing error messages.
118 It takes one arg FILENAME which is the name of a file as found
119 in the compilation output, and should return a transformed file name.")
120
121 ;;;###autoload
122 (defvar compilation-process-setup-function nil
123 "*Function to call to customize the compilation process.
124 This function is called immediately before the compilation process is
125 started. It can be used to set any variables or functions that are used
126 while processing the output of the compilation process. The function
127 is called with variables `compilation-buffer' and `compilation-window'
128 bound to the compilation buffer and window, respectively.")
129
130 ;;;###autoload
131 (defvar compilation-buffer-name-function nil
132 "Function to compute the name of a compilation buffer.
133 The function receives one argument, the name of the major mode of the
134 compilation buffer. It should return a string.
135 If nil, compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
136
137 ;;;###autoload
138 (defvar compilation-finish-function nil
139 "Function to call when a compilation process finishes.
140 It is called with two arguments: the compilation buffer, and a string
141 describing how the process finished.")
142
143 (make-obsolete-variable 'compilation-finish-function
144 "use `compilation-finish-functions', but it works a little differently."
145 "22.1")
146
147 ;;;###autoload
148 (defvar compilation-finish-functions nil
149 "Functions to call when a compilation process finishes.
150 Each function is called with two arguments: the compilation buffer,
151 and a string describing how the process finished.")
152
153 (defvar compilation-in-progress nil
154 "List of compilation processes now running.")
155 (or (assq 'compilation-in-progress minor-mode-alist)
156 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
157 minor-mode-alist)))
158
159 (defvar compilation-error "error"
160 "Stem of message to print when no matches are found.")
161
162 (defvar compilation-arguments nil
163 "Arguments that were given to `compilation-start'.")
164
165 (defvar compilation-num-errors-found)
166
167 (defconst compilation-error-regexp-alist-alist
168 '((absoft
169 "^\\(?:[Ee]rror on \\|[Ww]arning on\\( \\)\\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
170 of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil (1))
171
172 (ada
173 "\\(warning: .*\\)? at \\([^ \n]+\\):\\([0-9]+\\)$" 2 3 nil (1))
174
175 (aix
176 " in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
177
178 (ant
179 "^[ \t]*\\[[^] \n]+\\][ \t]*\\([^: \n]+\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):[0-9]+:[0-9]+:\\)?\
180 \\( warning\\)?" 1 2 3 (4))
181
182 (bash
183 "^\\([^: \n\t]+\\): line \\([0-9]+\\):" 1 2)
184
185 (borland
186 "^\\(?:Error\\|Warnin\\(g\\)\\) \\(?:[FEW][0-9]+ \\)?\
187 \\([a-zA-Z]?:?[^:( \t\n]+\\)\
188 \\([0-9]+\\)\\(?:[) \t]\\|:[^0-9\n]\\)" 2 3 nil (1))
189
190 (caml
191 "^ *File \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1, lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
192 \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:\\)?\\([ \n]Warning:\\)?\\)"
193 2 (3 . 4) (5 . 6) (7))
194
195 (comma
196 "^\"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)\
197 \\(?:[(. pos]+\\([0-9]+\\))?\\)?[:.,; (-]\\( warning:\\|[-0-9 ]*(W)\\)?" 1 2 3 (4))
198
199 (edg-1
200 "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
201 1 2 nil (3 . 4))
202 (edg-2
203 "at line \\([0-9]+\\) of \"\\([^ \n]+\\)\"$"
204 2 1 nil 0)
205
206 (epc
207 "^Error [0-9]+ at (\\([0-9]+\\):\\([^)\n]+\\))" 2 1)
208
209 (ftnchek
210 "\\(^Warning .*\\)? line[ \n]\\([0-9]+\\)[ \n]\\(?:col \\([0-9]+\\)[ \n]\\)?file \\([^ :;\n]+\\)"
211 4 2 3 (1))
212
213 (iar
214 "^\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(?:Error\\|Warnin\\(g\\)\\)\\[[0-9]+\\]:"
215 1 2 nil (3))
216
217 (ibm
218 "^\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) :\
219 \\(?:warnin\\(g\\)\\|informationa\\(l\\)\\)?" 1 2 3 (4 . 5))
220
221 ;; fixme: should be `mips'
222 (irix
223 "^[-[:alnum:]_/ ]+: \\(?:\\(?:[sS]evere\\|[eE]rror\\|[wW]arnin\\(g\\)\\|[iI]nf\\(o\\)\\)[0-9 ]*: \\)?\
224 \\([^,\" \n\t]+\\)\\(?:, line\\|:\\) \\([0-9]+\\):" 3 4 nil (1 . 2))
225
226 (java
227 "^\\(?:[ \t]+at \\|==[0-9]+== +\\(?:at\\|b\\(y\\)\\)\\).+(\\([^()\n]+\\):\\([0-9]+\\))$" 2 3 nil (1))
228
229 (jikes-file
230 "^\\(?:Found\\|Issued\\) .* compiling \"\\(.+\\)\":$" 1 nil nil 0)
231 (jikes-line
232 "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)"
233 nil 1 nil 2 0
234 (2 (compilation-face '(3))))
235
236 (gnu
237 ;; I have no idea what this first line is supposed to match, but it
238 ;; makes things ambiguous with output such as "foo:344:50:blabla" since
239 ;; the "foo" part can match this first line (in which case the file
240 ;; name as "344"). To avoid this, the second line disallows filenames
241 ;; exclusively composed of digits. --Stef
242 ;; Similarly, we get lots of false positives with messages including
243 ;; times of the form "HH:MM:SS" where MM is taken as a line number, so
244 ;; the last line tries to rule out message where the info after the
245 ;; line number starts with "SS". --Stef
246
247 ;; The core of the regexp is the one with *?. It says that a file name
248 ;; can be composed of any non-newline char, but it also rules out some
249 ;; valid but unlikely cases, such as a trailing space or a space
250 ;; followed by a -.
251 "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\)?\
252 \\([0-9]*[^0-9\n]\\(?:[^\n ]\\| [^-/\n]\\)*?\\): ?\
253 \\([0-9]+\\)\\(?:\\([.:]\\)\\([0-9]+\\)\\)?\
254 \\(?:-\\([0-9]+\\)?\\(?:\\.\\([0-9]+\\)\\)?\\)?:\
255 \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\
256 *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\|[Nn]ote\\)\\|\
257 \[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)"
258 1 (2 . 5) (4 . 6) (7 . 8))
259
260 ;; The `gnu' style above can incorrectly match gcc's "In file
261 ;; included from" message, so we process that first. -- cyd
262 (gcc-include
263 "^\\(?:In file included\\| \\) from \
264 \\(.+\\):\\([0-9]+\\)\\(?:\\(:\\)\\|\\(,\\)\\)?" 1 2 nil (3 . 4))
265
266 (lcc
267 "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)"
268 2 3 4 (1))
269
270 (makepp
271 "^makepp\\(?:\\(?:: warning\\(:\\).*?\\|\\(: Scanning\\|: [LR]e?l?oading makefile\\|: Imported\\|log:.*?\\) \\|: .*?\\)\
272 `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)"
273 4 5 nil (1 . 2) 3
274 ("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]" nil nil
275 (2 compilation-info-face)
276 (3 compilation-line-face nil t)
277 (1 (compilation-error-properties 2 3 nil nil nil 0 nil)
278 append)))
279
280 (maven
281 ;; Maven is a popular build tool for Java. Maven is Free Software.
282 "\\(.*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\]" 1 2 3)
283
284 ;; Should be lint-1, lint-2 (SysV lint)
285 (mips-1
286 " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
287 (mips-2
288 " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2)
289
290 (msft
291 ;; AFAWK, The message may be a "warning", "error", or "fatal error".
292 "^\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
293 : \\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:" 2 3 nil (4))
294
295 (omake
296 ;; "omake -P" reports "file foo changed"
297 ;; (useful if you do "cvs up" and want to see what has changed)
298 "omake: file \\(.*\\) changed" 1)
299
300 (oracle
301 "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
302 \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
303 \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
304 3 1 2)
305
306 ;; "during global destruction": This comes out under "use
307 ;; warnings" in recent perl when breaking circular references
308 ;; during program or thread exit.
309 (perl
310 " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \
311 during global destruction\\.$\\)" 1 2)
312
313 (php
314 "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
315 2 3 nil nil)
316
317 (rxp
318 "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
319 \\([0-9]+\\) of file://\\(.+\\)"
320 4 2 3 (1))
321
322 (sparc-pascal-file
323 "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
324 [12][09][0-9][0-9] +\\(.*\\):$"
325 1 nil nil 0)
326 (sparc-pascal-line
327 "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
328 nil 3 nil (2) nil (1 (compilation-face '(2))))
329 (sparc-pascal-example
330 "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
331 nil 1 nil (3) nil (2 (compilation-face '(3))))
332
333 (sun
334 ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
335 File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
336 3 4 5 (1 . 2))
337
338 (sun-ada
339 "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
340
341 (watcom
342 "\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)): ?\
343 \\(?:\\(Error! E[0-9]+\\)\\|\\(Warning! W[0-9]+\\)\\):"
344 1 2 nil (4))
345
346 (4bsd
347 "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
348 \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3))
349
350 (gcov-file
351 "^ *-: *\\(0\\):Source:\\(.+\\)$"
352 2 1 nil 0 nil
353 (1 compilation-line-face prepend) (2 compilation-info-face prepend))
354 (gcov-header
355 "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
356 nil 1 nil 0 nil
357 (1 compilation-line-face prepend))
358 ;; Underlines over all lines of gcov output are too uncomfortable to read.
359 ;; However, hyperlinks embedded in the lines are useful.
360 ;; So I put default face on the lines; and then put
361 ;; compilation-*-face by manually to eliminate the underlines.
362 ;; The hyperlinks are still effective.
363 (gcov-nomark
364 "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
365 nil 1 nil 0 nil
366 (0 'default t)
367 (1 compilation-line-face prepend))
368 (gcov-called-line
369 "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
370 nil 2 nil 0 nil
371 (0 'default t)
372 (1 compilation-info-face prepend) (2 compilation-line-face prepend))
373 (gcov-never-called
374 "^ *\\(#####\\): *\\([0-9]+\\):.*$"
375 nil 2 nil 2 nil
376 (0 'default t)
377 (1 compilation-error-face prepend) (2 compilation-line-face prepend))
378
379 (perl--Pod::Checker
380 ;; podchecker error messages, per Pod::Checker.
381 ;; The style is from the Pod::Checker::poderror() function, eg.
382 ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm
383 ;;
384 ;; Plus end_pod() can give "at line EOF" instead of a
385 ;; number, so for that match "on line N" which is the
386 ;; originating spot, eg.
387 ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm
388 ;;
389 ;; Plus command() can give both "on line N" and "at line N";
390 ;; the latter is desired and is matched because the .* is
391 ;; greedy.
392 ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod
393 ;;
394 "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \
395 \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)"
396 3 2 nil (1))
397 (perl--Test
398 ;; perl Test module error messages.
399 ;; Style per the ok() function "$context", eg.
400 ;; # Failed test 1 in foo.t at line 6
401 ;;
402 "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
403 1 2)
404 (perl--Test2
405 ;; Or when comparing got/want values,
406 ;; # Test 2 got: "xx" (t-compilation-perl-2.t at line 10)
407 ;;
408 ;; And under Test::Harness they're preceded by progress stuff with
409 ;; \r and "NOK",
410 ;; ... NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
411 ;;
412 "^\\(.*NOK.*\\)?# Test [0-9]+ got:.* (\\([^ \t\r\n]+\\) at line \
413 \\([0-9]+\\))"
414 2 3)
415 (perl--Test::Harness
416 ;; perl Test::Harness output, eg.
417 ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
418 ;;
419 ;; Test::Harness is slightly designed for tty output, since
420 ;; it prints CRs to overwrite progress messages, but if you
421 ;; run it in with M-x compile this pattern can at least step
422 ;; through the failures.
423 ;;
424 "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
425 1 2)
426 (weblint
427 ;; The style comes from HTML::Lint::Error::as_string(), eg.
428 ;; index.html (13:1) Unknown element <fdjsk>
429 ;;
430 ;; The pattern only matches filenames without spaces, since that
431 ;; should be usual and should help reduce the chance of a false
432 ;; match of a message from some unrelated program.
433 ;;
434 ;; This message style is quite close to the "ibm" entry which is
435 ;; for IBM C, though that ibm bit doesn't put a space after the
436 ;; filename.
437 ;;
438 "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) "
439 1 2 3)
440 )
441 "Alist of values for `compilation-error-regexp-alist'.")
442
443 (defcustom compilation-error-regexp-alist
444 (mapcar 'car compilation-error-regexp-alist-alist)
445 "Alist that specifies how to match errors in compiler output.
446 On GNU and Unix, any string is a valid filename, so these
447 matchers must make some common sense assumptions, which catch
448 normal cases. A shorter list will be lighter on resource usage.
449
450 Instead of an alist element, you can use a symbol, which is
451 looked up in `compilation-error-regexp-alist-alist'. You can see
452 the predefined symbols and their effects in the file
453 `etc/compilation.txt' (linked below if you are customizing this).
454
455 Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
456 HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
457 gives the file name, and the LINE'th subexpression gives the line
458 number. The COLUMN'th subexpression gives the column number on
459 that line.
460
461 If FILE, LINE or COLUMN are nil or that index didn't match, that
462 information is not present on the matched line. In that case the
463 file name is assumed to be the same as the previous one in the
464 buffer, line number defaults to 1 and column defaults to
465 beginning of line's indentation.
466
467 FILE can also have the form (FILE FORMAT...), where the FORMATs
468 \(e.g. \"%s.c\") will be applied in turn to the recognized file
469 name, until a file of that name is found. Or FILE can also be a
470 function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
471 In the former case, FILENAME may be relative or absolute.
472
473 LINE can also be of the form (LINE . END-LINE) meaning a range
474 of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
475 meaning a range of columns starting on LINE and ending on
476 END-LINE, if that matched.
477
478 TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
479 TYPE can also be of the form (WARNING . INFO). In that case this
480 will be equivalent to 1 if the WARNING'th subexpression matched
481 or else equivalent to 0 if the INFO'th subexpression matched.
482 See `compilation-error-face', `compilation-warning-face',
483 `compilation-info-face' and `compilation-skip-threshold'.
484
485 What matched the HYPERLINK'th subexpression has `mouse-face' and
486 `compilation-message-face' applied. If this is nil, the text
487 matched by the whole REGEXP becomes the hyperlink.
488
489 Additional HIGHLIGHTs as described under `font-lock-keywords' can
490 be added."
491 :type `(set :menu-tag "Pick"
492 ,@(mapcar (lambda (elt)
493 (list 'const (car elt)))
494 compilation-error-regexp-alist-alist))
495 :link `(file-link :tag "example file"
496 ,(expand-file-name "compilation.txt" data-directory))
497 :group 'compilation)
498
499 ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp)
500 (defvar compilation-directory nil
501 "Directory to restore to when doing `recompile'.")
502
503 (defvar compilation-directory-matcher
504 '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1))
505 "A list for tracking when directories are entered or left.
506 If nil, do not track directories, e.g. if all file names are absolute. The
507 first element is the REGEXP matching these messages. It can match any number
508 of variants, e.g. different languages. The remaining elements are all of the
509 form (DIR . LEAVE). If for any one of these the DIR'th subexpression
510 matches, that is a directory name. If LEAVE is nil or the corresponding
511 LEAVE'th subexpression doesn't match, this message is about going into another
512 directory. If it does match anything, this message is about going back to the
513 directory we were in before the last entering message. If you change this,
514 you may also want to change `compilation-page-delimiter'.")
515
516 (defvar compilation-page-delimiter
517 "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
518 "Value of `page-delimiter' in Compilation mode.")
519
520 (defvar compilation-mode-font-lock-keywords
521 '(;; configure output lines.
522 ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
523 (1 font-lock-variable-name-face)
524 (2 (compilation-face '(4 . 3))))
525 ;; Command output lines. Recognize `make[n]:' lines too.
526 ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
527 (1 font-lock-function-name-face) (3 compilation-line-face nil t))
528 (" --?o\\(?:utfile\\|utput\\)?[= ]?\\(\\S +\\)" . 1)
529 ("^Compilation \\(finished\\).*"
530 (0 '(face nil message nil help-echo nil mouse-face nil) t)
531 (1 compilation-info-face))
532 ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
533 (0 '(face nil message nil help-echo nil mouse-face nil) t)
534 (1 compilation-error-face)
535 (2 compilation-error-face nil t)))
536 "Additional things to highlight in Compilation mode.
537 This gets tacked on the end of the generated expressions.")
538
539 (defvar compilation-highlight-regexp t
540 "Regexp matching part of visited source lines to highlight temporarily.
541 Highlight entire line if t; don't highlight source lines if nil.")
542
543 (defvar compilation-highlight-overlay nil
544 "Overlay used to temporarily highlight compilation matches.")
545
546 (defcustom compilation-error-screen-columns t
547 "If non-nil, column numbers in error messages are screen columns.
548 Otherwise they are interpreted as character positions, with
549 each character occupying one column.
550 The default is to use screen columns, which requires that the compilation
551 program and Emacs agree about the display width of the characters,
552 especially the TAB character."
553 :type 'boolean
554 :group 'compilation
555 :version "20.4")
556
557 (defcustom compilation-read-command t
558 "Non-nil means \\[compile] reads the compilation command to use.
559 Otherwise, \\[compile] just uses the value of `compile-command'."
560 :type 'boolean
561 :group 'compilation)
562
563 ;;;###autoload
564 (defcustom compilation-ask-about-save t
565 "Non-nil means \\[compile] asks which buffers to save before compiling.
566 Otherwise, it saves all modified buffers without asking."
567 :type 'boolean
568 :group 'compilation)
569
570 ;;;###autoload
571 (defcustom compilation-search-path '(nil)
572 "List of directories to search for source files named in error messages.
573 Elements should be directory names, not file names of directories.
574 The value nil as an element means to try the default directory."
575 :type '(repeat (choice (const :tag "Default" nil)
576 (string :tag "Directory")))
577 :group 'compilation)
578
579 ;;;###autoload
580 (defcustom compile-command "make -k "
581 "Last shell command used to do a compilation; default for next compilation.
582
583 Sometimes it is useful for files to supply local values for this variable.
584 You might also use mode hooks to specify it in certain modes, like this:
585
586 (add-hook 'c-mode-hook
587 (lambda ()
588 (unless (or (file-exists-p \"makefile\")
589 (file-exists-p \"Makefile\"))
590 (set (make-local-variable 'compile-command)
591 (concat \"make -k \"
592 (file-name-sans-extension buffer-file-name))))))"
593 :type 'string
594 :group 'compilation)
595 ;;;###autoload(put 'compile-command 'safe-local-variable 'stringp)
596
597 ;;;###autoload
598 (defcustom compilation-disable-input nil
599 "If non-nil, send end-of-file as compilation process input.
600 This only affects platforms that support asynchronous processes (see
601 `start-process'); synchronous compilation processes never accept input."
602 :type 'boolean
603 :group 'compilation
604 :version "22.1")
605
606 ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
607 ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
608 ;; key. This holds the tree seen from root, for storing new nodes.
609 (defvar compilation-locs ())
610
611 (defvar compilation-debug nil
612 "*Set this to t before creating a *compilation* buffer.
613 Then every error line will have a debug text property with the matcher that
614 fit this line and the match data. Use `describe-text-properties'.")
615
616 (defvar compilation-exit-message-function nil "\
617 If non-nil, called when a compilation process dies to return a status message.
618 This should be a function of three arguments: process status, exit status,
619 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
620 write into the compilation buffer, and to put in its mode line.")
621
622 (defvar compilation-environment nil
623 "*List of environment variables for compilation to inherit.
624 Each element should be a string of the form ENVVARNAME=VALUE.
625 This list is temporarily prepended to `process-environment' prior to
626 starting the compilation process.")
627
628 ;; History of compile commands.
629 (defvar compile-history nil)
630
631 (defface compilation-error
632 '((t :inherit font-lock-warning-face))
633 "Face used to highlight compiler errors."
634 :group 'compilation
635 :version "22.1")
636
637 (defface compilation-warning
638 '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
639 (((class color)) (:foreground "cyan" :weight bold))
640 (t (:weight bold)))
641 "Face used to highlight compiler warnings."
642 :group 'compilation
643 :version "22.1")
644
645 (defface compilation-info
646 '((((class color) (min-colors 16) (background light))
647 (:foreground "Green3" :weight bold))
648 (((class color) (min-colors 88) (background dark))
649 (:foreground "Green1" :weight bold))
650 (((class color) (min-colors 16) (background dark))
651 (:foreground "Green" :weight bold))
652 (((class color)) (:foreground "green" :weight bold))
653 (t (:weight bold)))
654 "Face used to highlight compiler information."
655 :group 'compilation
656 :version "22.1")
657
658 (defface compilation-line-number
659 '((t :inherit font-lock-variable-name-face))
660 "Face for displaying line numbers in compiler messages."
661 :group 'compilation
662 :version "22.1")
663
664 (defface compilation-column-number
665 '((t :inherit font-lock-type-face))
666 "Face for displaying column numbers in compiler messages."
667 :group 'compilation
668 :version "22.1")
669
670 (defcustom compilation-message-face 'underline
671 "Face name to use for whole messages.
672 Faces `compilation-error-face', `compilation-warning-face',
673 `compilation-info-face', `compilation-line-face' and
674 `compilation-column-face' get prepended to this, when applicable."
675 :type 'face
676 :group 'compilation
677 :version "22.1")
678
679 (defvar compilation-error-face 'compilation-error
680 "Face name to use for file name in error messages.")
681
682 (defvar compilation-warning-face 'compilation-warning
683 "Face name to use for file name in warning messages.")
684
685 (defvar compilation-info-face 'compilation-info
686 "Face name to use for file name in informational messages.")
687
688 (defvar compilation-line-face 'compilation-line-number
689 "Face name to use for line numbers in compiler messages.")
690
691 (defvar compilation-column-face 'compilation-column-number
692 "Face name to use for column numbers in compiler messages.")
693
694 ;; same faces as dired uses
695 (defvar compilation-enter-directory-face 'font-lock-function-name-face
696 "Face name to use for entering directory messages.")
697
698 (defvar compilation-leave-directory-face 'font-lock-type-face
699 "Face name to use for leaving directory messages.")
700
701
702
703 ;; Used for compatibility with the old compile.el.
704 (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
705 (defvar compilation-parsing-end (make-marker))
706 (defvar compilation-parse-errors-function nil)
707 (defvar compilation-error-list nil)
708 (defvar compilation-old-error-list nil)
709
710 (defcustom compilation-auto-jump-to-first-error nil
711 "If non-nil, automatically jump to the first error during compilation."
712 :type 'boolean
713 :group 'compilation
714 :version "23.1")
715
716 (defvar compilation-auto-jump-to-next nil
717 "If non-nil, automatically jump to the next error encountered.")
718 (make-variable-buffer-local 'compilation-auto-jump-to-next)
719
720
721 (defvar compilation-skip-to-next-location t
722 "*If non-nil, skip multiple error messages for the same source location.")
723
724 (defcustom compilation-skip-threshold 1
725 "Compilation motion commands skip less important messages.
726 The value can be either 2 -- skip anything less than error, 1 --
727 skip anything less than warning or 0 -- don't skip any messages.
728 Note that all messages not positively identified as warning or
729 info, are considered errors."
730 :type '(choice (const :tag "Warnings and info" 2)
731 (const :tag "Info" 1)
732 (const :tag "None" 0))
733 :group 'compilation
734 :version "22.1")
735
736 (defcustom compilation-skip-visited nil
737 "Compilation motion commands skip visited messages if this is t.
738 Visited messages are ones for which the file, line and column have been jumped
739 to from the current content in the current compilation buffer, even if it was
740 from a different message."
741 :type 'boolean
742 :group 'compilation
743 :version "22.1")
744
745 (defun compilation-face (type)
746 (or (and (car type) (match-end (car type)) compilation-warning-face)
747 (and (cdr type) (match-end (cdr type)) compilation-info-face)
748 compilation-error-face))
749
750 ;; Internal function for calculating the text properties of a directory
751 ;; change message. The directory property is important, because it is
752 ;; the stack of nested enter-messages. Relative filenames on the following
753 ;; lines are relative to the top of the stack.
754 (defun compilation-directory-properties (idx leave)
755 (if leave (setq leave (match-end leave)))
756 ;; find previous stack, and push onto it, or if `leave' pop it
757 (let ((dir (previous-single-property-change (point) 'directory)))
758 (setq dir (if dir (or (get-text-property (1- dir) 'directory)
759 (get-text-property dir 'directory))))
760 `(face ,(if leave
761 compilation-leave-directory-face
762 compilation-enter-directory-face)
763 directory ,(if leave
764 (or (cdr dir)
765 '(nil)) ; nil only isn't a property-change
766 (cons (match-string-no-properties idx) dir))
767 mouse-face highlight
768 keymap compilation-button-map
769 help-echo "mouse-2: visit destination directory")))
770
771 ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
772 ;; KEY element from the ALIST, creating it in the right position if not already
773 ;; present. ALIST structure is
774 ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
775 ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
776 ;; may be nil. The other KEYs are ordered backwards so that growing line
777 ;; numbers can be inserted in front and searching can abort after half the
778 ;; list on average.
779 (eval-when-compile ;Don't keep it at runtime if not needed.
780 (defmacro compilation-assq (key alist)
781 `(let* ((l1 ,alist)
782 (l2 (cdr l1)))
783 (car (if (if (null ,key)
784 (if l2 (null (caar l2)))
785 (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
786 (setq l1 l2
787 l2 (cdr l1)))
788 (if l2 (eq ,key (caar l2))))
789 l2
790 (setcdr l1 (cons (list ,key) l2)))))))
791
792 (defun compilation-auto-jump (buffer pos)
793 (with-current-buffer buffer
794 (goto-char pos)
795 (let ((win (get-buffer-window buffer 0)))
796 (if win (set-window-point win pos)))
797 (if compilation-auto-jump-to-first-error
798 (compile-goto-error))))
799
800 ;; This function is the central driver, called when font-locking to gather
801 ;; all information needed to later jump to corresponding source code.
802 ;; Return a property list with all meta information on this error location.
803
804 (defun compilation-error-properties (file line end-line col end-col type fmt)
805 (unless (< (next-single-property-change (match-beginning 0)
806 'directory nil (point))
807 (point))
808 (if file
809 (if (functionp file)
810 (setq file (funcall file))
811 (let (dir)
812 (setq file (match-string-no-properties file))
813 (unless (file-name-absolute-p file)
814 (setq dir (previous-single-property-change (point) 'directory)
815 dir (if dir (or (get-text-property (1- dir) 'directory)
816 (get-text-property dir 'directory)))))
817 (setq file (cons file (car dir)))))
818 ;; This message didn't mention one, get it from previous
819 (let ((prev-pos
820 ;; Find the previous message.
821 (previous-single-property-change (point) 'message)))
822 (if prev-pos
823 ;; Get the file structure that belongs to it.
824 (let* ((prev
825 (or (get-text-property (1- prev-pos) 'message)
826 (get-text-property prev-pos 'message)))
827 (prev-struct
828 (car (nth 2 (car prev)))))
829 ;; Construct FILE . DIR from that.
830 (if prev-struct
831 (setq file (cons (car prev-struct)
832 (cadr prev-struct))))))
833 (unless file
834 (setq file '("*unknown*")))))
835 ;; All of these fields are optional, get them only if we have an index, and
836 ;; it matched some part of the message.
837 (and line
838 (setq line (match-string-no-properties line))
839 (setq line (string-to-number line)))
840 (and end-line
841 (setq end-line (match-string-no-properties end-line))
842 (setq end-line (string-to-number end-line)))
843 (if col
844 (if (functionp col)
845 (setq col (funcall col))
846 (and
847 (setq col (match-string-no-properties col))
848 (setq col (- (string-to-number col) compilation-first-column)))))
849 (if (and end-col (functionp end-col))
850 (setq end-col (funcall end-col))
851 (if (and end-col (setq end-col (match-string-no-properties end-col)))
852 (setq end-col (- (string-to-number end-col) compilation-first-column -1))
853 (if end-line (setq end-col -1))))
854 (if (consp type) ; not a static type, check what it is.
855 (setq type (or (and (car type) (match-end (car type)) 1)
856 (and (cdr type) (match-end (cdr type)) 0)
857 2)))
858
859 (when (and compilation-auto-jump-to-next
860 (>= type compilation-skip-threshold))
861 (kill-local-variable 'compilation-auto-jump-to-next)
862 (run-with-timer 0 nil 'compilation-auto-jump
863 (current-buffer) (match-beginning 0)))
864
865 (compilation-internal-error-properties file line end-line col end-col type fmt)))
866
867 (defun compilation-move-to-column (col screen)
868 "Go to column COL on the current line.
869 If SCREEN is non-nil, columns are screen columns, otherwise, they are
870 just char-counts."
871 (if screen
872 (move-to-column (max col 0))
873 (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
874
875 (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
876 "Get the meta-info that will be added as text-properties.
877 LINE, END-LINE, COL, END-COL are integers or nil.
878 TYPE can be 0, 1, or 2, meaning error, warning, or just info.
879 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
880 FMTS is a list of format specs for transforming the file name.
881 (See `compilation-error-regexp-alist'.)"
882 (unless file (setq file '("*unknown*")))
883 (let* ((file-struct (compilation-get-file-structure file fmts))
884 ;; Get first already existing marker (if any has one, all have one).
885 ;; Do this first, as the compilation-assq`s may create new nodes.
886 (marker-line (car (cddr file-struct))) ; a line structure
887 (marker (nth 3 (cadr marker-line))) ; its marker
888 (compilation-error-screen-columns compilation-error-screen-columns)
889 end-marker loc end-loc)
890 (if (not (and marker (marker-buffer marker)))
891 (setq marker nil) ; no valid marker for this file
892 (setq loc (or line 1)) ; normalize no linenumber to line 1
893 (catch 'marker ; find nearest loc, at least one exists
894 (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines
895 (if (> (car x) loc) ; still bigger
896 (setq marker-line x)
897 (if (> (- (or (car marker-line) 1) loc)
898 (- loc (car x))) ; current line is nearer
899 (setq marker-line x))
900 (throw 'marker t))))
901 (setq marker (nth 3 (cadr marker-line))
902 marker-line (or (car marker-line) 1))
903 (with-current-buffer (marker-buffer marker)
904 (save-excursion
905 (save-restriction
906 (widen)
907 (goto-char (marker-position marker))
908 (when (or end-col end-line)
909 (beginning-of-line (- (or end-line line) marker-line -1))
910 (if (or (null end-col) (< end-col 0))
911 (end-of-line)
912 (compilation-move-to-column
913 end-col compilation-error-screen-columns))
914 (setq end-marker (list (point-marker))))
915 (beginning-of-line (if end-line
916 (- line end-line -1)
917 (- loc marker-line -1)))
918 (if col
919 (compilation-move-to-column
920 col compilation-error-screen-columns)
921 (forward-to-indentation 0))
922 (setq marker (list (point-marker)))))))
923
924 (setq loc (compilation-assq line (cdr file-struct)))
925 (if end-line
926 (setq end-loc (compilation-assq end-line (cdr file-struct))
927 end-loc (compilation-assq end-col end-loc))
928 (if end-col ; use same line element
929 (setq end-loc (compilation-assq end-col loc))))
930 (setq loc (compilation-assq col loc))
931 ;; If they are new, make the loc(s) reference the file they point to.
932 (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker)))
933 (if end-loc
934 (or (cdr end-loc)
935 (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker))))
936
937 ;; Must start with face
938 `(face ,compilation-message-face
939 message (,loc ,type ,end-loc)
940 ,@(if compilation-debug
941 `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords)
942 ,@(match-data))))
943 help-echo ,(if col
944 "mouse-2: visit this file, line and column"
945 (if line
946 "mouse-2: visit this file and line"
947 "mouse-2: visit this file"))
948 keymap compilation-button-map
949 mouse-face highlight)))
950
951 (defun compilation-mode-font-lock-keywords ()
952 "Return expressions to highlight in Compilation mode."
953 (if compilation-parse-errors-function
954 ;; An old package! Try the compatibility code.
955 '((compilation-compat-parse-errors))
956 (append
957 ;; make directory tracking
958 (if compilation-directory-matcher
959 `((,(car compilation-directory-matcher)
960 ,@(mapcar (lambda (elt)
961 `(,(car elt)
962 (compilation-directory-properties
963 ,(car elt) ,(cdr elt))
964 t t))
965 (cdr compilation-directory-matcher)))))
966
967 ;; Compiler warning/error lines.
968 (mapcar
969 (lambda (item)
970 (if (symbolp item)
971 (setq item (cdr (assq item
972 compilation-error-regexp-alist-alist))))
973 (let ((file (nth 1 item))
974 (line (nth 2 item))
975 (col (nth 3 item))
976 (type (nth 4 item))
977 end-line end-col fmt)
978 (if (consp file) (setq fmt (cdr file) file (car file)))
979 (if (consp line) (setq end-line (cdr line) line (car line)))
980 (if (consp col) (setq end-col (cdr col) col (car col)))
981
982 (if (functionp line)
983 ;; The old compile.el had here an undocumented hook that
984 ;; allowed `line' to be a function that computed the actual
985 ;; error location. Let's do our best.
986 `(,(car item)
987 (0 (save-match-data
988 (compilation-compat-error-properties
989 (funcall ',line (cons (match-string ,file)
990 (cons default-directory
991 ',(nthcdr 4 item)))
992 ,(if col `(match-string ,col))))))
993 (,file compilation-error-face t))
994
995 (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
996 (error "HYPERLINK should be an integer: %s" (nth 5 item)))
997
998 `(,(nth 0 item)
999
1000 ,@(when (integerp file)
1001 `((,file ,(if (consp type)
1002 `(compilation-face ',type)
1003 (aref [compilation-info-face
1004 compilation-warning-face
1005 compilation-error-face]
1006 (or type 2))))))
1007
1008 ,@(when line
1009 `((,line compilation-line-face nil t)))
1010 ,@(when end-line
1011 `((,end-line compilation-line-face nil t)))
1012
1013 ,@(when (integerp col)
1014 `((,col compilation-column-face nil t)))
1015 ,@(when (integerp end-col)
1016 `((,end-col compilation-column-face nil t)))
1017
1018 ,@(nthcdr 6 item)
1019 (,(or (nth 5 item) 0)
1020 (compilation-error-properties ',file ,line ,end-line
1021 ,col ,end-col ',(or type 2)
1022 ',fmt)
1023 append))))) ; for compilation-message-face
1024 compilation-error-regexp-alist)
1025
1026 compilation-mode-font-lock-keywords)))
1027
1028 (defun compilation-read-command (command)
1029 (read-shell-command "Compile command: " command
1030 (if (equal (car compile-history) command)
1031 '(compile-history . 1)
1032 'compile-history)))
1033
1034 \f
1035 ;;;###autoload
1036 (defun compile (command &optional comint)
1037 "Compile the program including the current buffer. Default: run `make'.
1038 Runs COMMAND, a shell command, in a separate process asynchronously
1039 with output going to the buffer `*compilation*'.
1040
1041 You can then use the command \\[next-error] to find the next error message
1042 and move to the source code that caused it.
1043
1044 If optional second arg COMINT is t the buffer will be in Comint mode with
1045 `compilation-shell-minor-mode'.
1046
1047 Interactively, prompts for the command if `compilation-read-command' is
1048 non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
1049 Additionally, with universal prefix arg, compilation buffer will be in
1050 comint mode, i.e. interactive.
1051
1052 To run more than one compilation at once, start one then rename
1053 the \`*compilation*' buffer to some other name with
1054 \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
1055 It will create a new \`*compilation*' buffer.
1056
1057 On most systems, termination of the main compilation process
1058 kills its subprocesses.
1059
1060 The name used for the buffer is actually whatever is returned by
1061 the function in `compilation-buffer-name-function', so you can set that
1062 to a function that generates a unique name."
1063 (interactive
1064 (list
1065 (let ((command (eval compile-command)))
1066 (if (or compilation-read-command current-prefix-arg)
1067 (compilation-read-command command)
1068 command))
1069 (consp current-prefix-arg)))
1070 (unless (equal command (eval compile-command))
1071 (setq compile-command command))
1072 (save-some-buffers (not compilation-ask-about-save) nil)
1073 (setq-default compilation-directory default-directory)
1074 (compilation-start command comint))
1075
1076 ;; run compile with the default command line
1077 (defun recompile (&optional edit-command)
1078 "Re-compile the program including the current buffer.
1079 If this is run in a Compilation mode buffer, re-use the arguments from the
1080 original use. Otherwise, recompile using `compile-command'.
1081 If the optional argument `edit-command' is non-nil, the command can be edited."
1082 (interactive "P")
1083 (save-some-buffers (not compilation-ask-about-save) nil)
1084 (let ((default-directory (or compilation-directory default-directory)))
1085 (when edit-command
1086 (setcar compilation-arguments
1087 (compilation-read-command (car compilation-arguments))))
1088 (apply 'compilation-start (or compilation-arguments
1089 `(,(eval compile-command))))))
1090
1091 (defcustom compilation-scroll-output nil
1092 "Non-nil to scroll the *compilation* buffer window as output appears.
1093
1094 Setting it causes the Compilation mode commands to put point at the
1095 end of their output window so that the end of the output is always
1096 visible rather than the beginning.
1097
1098 The value `first-error' stops scrolling at the first error, and leaves
1099 point on its location in the *compilation* buffer."
1100 :type '(choice (const :tag "No scrolling" nil)
1101 (const :tag "Scroll compilation output" t)
1102 (const :tag "Stop scrolling at the first error" first-error))
1103 :version "20.3"
1104 :group 'compilation)
1105
1106
1107 (defun compilation-buffer-name (mode-name mode-command name-function)
1108 "Return the name of a compilation buffer to use.
1109 If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
1110 to determine the buffer name.
1111 Likewise if `compilation-buffer-name-function' is non-nil.
1112 If current buffer has the major mode MODE-COMMAND,
1113 return the name of the current buffer, so that it gets reused.
1114 Otherwise, construct a buffer name from MODE-NAME."
1115 (cond (name-function
1116 (funcall name-function mode-name))
1117 (compilation-buffer-name-function
1118 (funcall compilation-buffer-name-function mode-name))
1119 ((eq mode-command major-mode)
1120 (buffer-name))
1121 (t
1122 (concat "*" (downcase mode-name) "*"))))
1123
1124 ;; This is a rough emulation of the old hack, until the transition to new
1125 ;; compile is complete.
1126 (defun compile-internal (command error-message
1127 &optional name-of-mode parser
1128 error-regexp-alist name-function
1129 enter-regexp-alist leave-regexp-alist
1130 file-regexp-alist nomessage-regexp-alist
1131 no-async highlight-regexp local-map)
1132 (if parser
1133 (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
1134 (let ((compilation-error-regexp-alist
1135 (append file-regexp-alist (or error-regexp-alist
1136 compilation-error-regexp-alist)))
1137 (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
1138 "\\1" error-message)))
1139 (compilation-start command nil name-function highlight-regexp)))
1140 (make-obsolete 'compile-internal 'compilation-start "22.1")
1141
1142 ;;;###autoload
1143 (defun compilation-start (command &optional mode name-function highlight-regexp)
1144 "Run compilation command COMMAND (low level interface).
1145 If COMMAND starts with a cd command, that becomes the `default-directory'.
1146 The rest of the arguments are optional; for them, nil means use the default.
1147
1148 MODE is the major mode to set in the compilation buffer. Mode
1149 may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
1150
1151 If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
1152 to determine the buffer name. Otherwise, the default is to
1153 reuses the current buffer if it has the proper major mode,
1154 else use or create a buffer with name based on the major mode.
1155
1156 If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
1157 the matching section of the visited source line; the default is to use the
1158 global value of `compilation-highlight-regexp'.
1159
1160 Returns the compilation buffer created."
1161 (or mode (setq mode 'compilation-mode))
1162 (let* ((name-of-mode
1163 (if (eq mode t)
1164 "compilation"
1165 (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
1166 (thisdir default-directory)
1167 outwin outbuf)
1168 (with-current-buffer
1169 (setq outbuf
1170 (get-buffer-create
1171 (compilation-buffer-name name-of-mode mode name-function)))
1172 (let ((comp-proc (get-buffer-process (current-buffer))))
1173 (if comp-proc
1174 (if (or (not (eq (process-status comp-proc) 'run))
1175 (yes-or-no-p
1176 (format "A %s process is running; kill it? "
1177 name-of-mode)))
1178 (condition-case ()
1179 (progn
1180 (interrupt-process comp-proc)
1181 (sit-for 1)
1182 (delete-process comp-proc))
1183 (error nil))
1184 (error "Cannot have two processes in `%s' at once"
1185 (buffer-name)))))
1186 ;; first transfer directory from where M-x compile was called
1187 (setq default-directory thisdir)
1188 ;; Make compilation buffer read-only. The filter can still write it.
1189 ;; Clear out the compilation buffer.
1190 (let ((inhibit-read-only t)
1191 (default-directory thisdir))
1192 ;; Then evaluate a cd command if any, but don't perform it yet, else
1193 ;; start-command would do it again through the shell: (cd "..") AND
1194 ;; sh -c "cd ..; make"
1195 (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command)
1196 (if (match-end 1)
1197 (substitute-env-vars (match-string 1 command))
1198 "~")
1199 default-directory))
1200 (erase-buffer)
1201 ;; Select the desired mode.
1202 (if (not (eq mode t))
1203 (progn
1204 (buffer-disable-undo)
1205 (funcall mode))
1206 (setq buffer-read-only nil)
1207 (with-no-warnings (comint-mode))
1208 (compilation-shell-minor-mode))
1209 ;; Remember the original dir, so we can use it when we recompile.
1210 ;; default-directory' can't be used reliably for that because it may be
1211 ;; affected by the special handling of "cd ...;".
1212 ;; NB: must be fone after (funcall mode) as that resets local variables
1213 (set (make-local-variable 'compilation-directory) thisdir)
1214 (if highlight-regexp
1215 (set (make-local-variable 'compilation-highlight-regexp)
1216 highlight-regexp))
1217 (if (or compilation-auto-jump-to-first-error
1218 (eq compilation-scroll-output 'first-error))
1219 (set (make-local-variable 'compilation-auto-jump-to-next) t))
1220 ;; Output a mode setter, for saving and later reloading this buffer.
1221 (insert "-*- mode: " name-of-mode
1222 "; default-directory: " (prin1-to-string default-directory)
1223 " -*-\n"
1224 (format "%s started at %s\n\n"
1225 mode-name
1226 (substring (current-time-string) 0 19))
1227 command "\n")
1228 (setq thisdir default-directory))
1229 (set-buffer-modified-p nil))
1230 ;; Pop up the compilation buffer.
1231 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html
1232 (setq outwin (display-buffer outbuf))
1233 (with-current-buffer outbuf
1234 (let ((process-environment
1235 (append
1236 compilation-environment
1237 (if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning
1238 system-uses-terminfo)
1239 (list "TERM=dumb" "TERMCAP="
1240 (format "COLUMNS=%d" (window-width)))
1241 (list "TERM=emacs"
1242 (format "TERMCAP=emacs:co#%d:tc=unknown:"
1243 (window-width))))
1244 ;; Set the EMACS variable, but
1245 ;; don't override users' setting of $EMACS.
1246 (unless (getenv "EMACS")
1247 (list "EMACS=t"))
1248 (list "INSIDE_EMACS=t")
1249 (copy-sequence process-environment))))
1250 (set (make-local-variable 'compilation-arguments)
1251 (list command mode name-function highlight-regexp))
1252 (set (make-local-variable 'revert-buffer-function)
1253 'compilation-revert-buffer)
1254 (set-window-start outwin (point-min))
1255
1256 ;; Position point as the user will see it.
1257 (let ((desired-visible-point
1258 ;; Put it at the end if `compilation-scroll-output' is set.
1259 (if compilation-scroll-output
1260 (point-max)
1261 ;; Normally put it at the top.
1262 (point-min))))
1263 (if (eq outwin (selected-window))
1264 (goto-char desired-visible-point)
1265 (set-window-point outwin desired-visible-point)))
1266
1267 ;; The setup function is called before compilation-set-window-height
1268 ;; so it can set the compilation-window-height buffer locally.
1269 (if compilation-process-setup-function
1270 (funcall compilation-process-setup-function))
1271 (compilation-set-window-height outwin)
1272 ;; Start the compilation.
1273 (if (fboundp 'start-process)
1274 (let ((proc
1275 (if (eq mode t)
1276 ;; comint uses `start-file-process'.
1277 (get-buffer-process
1278 (with-no-warnings
1279 (comint-exec
1280 outbuf (downcase mode-name)
1281 (if (file-remote-p default-directory)
1282 "/bin/sh"
1283 shell-file-name)
1284 nil `("-c" ,command))))
1285 (start-file-process-shell-command (downcase mode-name)
1286 outbuf command))))
1287 ;; Make the buffer's mode line show process state.
1288 (setq mode-line-process
1289 (list (propertize ":%s" 'face 'compilation-warning)))
1290 (set-process-sentinel proc 'compilation-sentinel)
1291 (unless (eq mode t)
1292 ;; Keep the comint filter, since it's needed for proper handling
1293 ;; of the prompts.
1294 (set-process-filter proc 'compilation-filter))
1295 ;; Use (point-max) here so that output comes in
1296 ;; after the initial text,
1297 ;; regardless of where the user sees point.
1298 (set-marker (process-mark proc) (point-max) outbuf)
1299 (when compilation-disable-input
1300 (condition-case nil
1301 (process-send-eof proc)
1302 ;; The process may have exited already.
1303 (error nil)))
1304 (run-hook-with-args 'compilation-start-hook proc)
1305 (setq compilation-in-progress
1306 (cons proc compilation-in-progress)))
1307 ;; No asynchronous processes available.
1308 (message "Executing `%s'..." command)
1309 ;; Fake modeline display as if `start-process' were run.
1310 (setq mode-line-process
1311 (list (propertize ":run" 'face 'compilation-warning)))
1312 (force-mode-line-update)
1313 (sit-for 0) ; Force redisplay
1314 (save-excursion
1315 ;; Insert the output at the end, after the initial text,
1316 ;; regardless of where the user sees point.
1317 (goto-char (point-max))
1318 (let* ((buffer-read-only nil) ; call-process needs to modify outbuf
1319 (status (call-process shell-file-name nil outbuf nil "-c"
1320 command)))
1321 (cond ((numberp status)
1322 (compilation-handle-exit
1323 'exit status
1324 (if (zerop status)
1325 "finished\n"
1326 (format "exited abnormally with code %d\n" status))))
1327 ((stringp status)
1328 (compilation-handle-exit 'signal status
1329 (concat status "\n")))
1330 (t
1331 (compilation-handle-exit 'bizarre status status)))))
1332 ;; Without async subprocesses, the buffer is not yet
1333 ;; fontified, so fontify it now.
1334 (let ((font-lock-verbose nil)) ; shut up font-lock messages
1335 (font-lock-fontify-buffer))
1336 (set-buffer-modified-p nil)
1337 (message "Executing `%s'...done" command)))
1338 ;; Now finally cd to where the shell started make/grep/...
1339 (setq default-directory thisdir)
1340 ;; The following form selected outwin ever since revision 1.183,
1341 ;; so possibly messing up point in some other window (bug#1073).
1342 ;; Moved into the scope of with-current-buffer, though still with
1343 ;; complete disregard for the case when compilation-scroll-output
1344 ;; equals 'first-error (martin 2008-10-04).
1345 (when compilation-scroll-output
1346 (goto-char (point-max))))
1347
1348 ;; Make it so the next C-x ` will use this buffer.
1349 (setq next-error-last-buffer outbuf)))
1350
1351 (defun compilation-set-window-height (window)
1352 "Set the height of WINDOW according to `compilation-window-height'."
1353 (let ((height (buffer-local-value 'compilation-window-height (window-buffer window))))
1354 (and height
1355 (window-full-width-p window)
1356 ;; If window is alone in its frame, aside from a minibuffer,
1357 ;; don't change its height.
1358 (not (eq window (frame-root-window (window-frame window))))
1359 ;; Stef said that doing the saves in this order is safer:
1360 (save-excursion
1361 (save-selected-window
1362 (select-window window)
1363 (enlarge-window (- height (window-height))))))))
1364
1365 (defvar compilation-menu-map
1366 (let ((map (make-sparse-keymap "Errors"))
1367 (opt-map (make-sparse-keymap "Skip")))
1368 (define-key map [stop-subjob]
1369 '(menu-item "Stop Compilation" kill-compilation
1370 :help "Kill the process made by the M-x compile or M-x grep commands"))
1371 (define-key map [compilation-mode-separator3]
1372 '("----" . nil))
1373 (define-key map [compilation-next-error-follow-minor-mode]
1374 '(menu-item
1375 "Auto Error Display" next-error-follow-minor-mode
1376 :help "Display the error under cursor when moving the cursor"
1377 :button (:toggle . next-error-follow-minor-mode)))
1378 (define-key map [compilation-skip]
1379 (cons "Skip Less Important Messages" opt-map))
1380 (define-key opt-map [compilation-skip-none]
1381 '(menu-item "Don't Skip Any Messages"
1382 (lambda ()
1383 (interactive)
1384 (customize-set-variable 'compilation-skip-threshold 0))
1385 :help "Do not skip any type of messages"
1386 :button (:radio . (eq compilation-skip-threshold 0))))
1387 (define-key opt-map [compilation-skip-info]
1388 '(menu-item "Skip Info"
1389 (lambda ()
1390 (interactive)
1391 (customize-set-variable 'compilation-skip-threshold 1))
1392 :help "Skip anything less than warning"
1393 :button (:radio . (eq compilation-skip-threshold 1))))
1394 (define-key opt-map [compilation-skip-warning-and-info]
1395 '(menu-item "Skip Warnings and Info"
1396 (lambda ()
1397 (interactive)
1398 (customize-set-variable 'compilation-skip-threshold 2))
1399 :help "Skip over Warnings and Info, stop for errors"
1400 :button (:radio . (eq compilation-skip-threshold 2))))
1401 (define-key map [compilation-mode-separator2]
1402 '("----" . nil))
1403 (define-key map [compilation-first-error]
1404 '(menu-item "First Error" first-error
1405 :help "Restart at the first error, visit corresponding source code"))
1406 (define-key map [compilation-previous-error]
1407 '(menu-item "Previous Error" previous-error
1408 :help "Visit previous `next-error' message and corresponding source code"))
1409 (define-key map [compilation-next-error]
1410 '(menu-item "Next Error" next-error
1411 :help "Visit next `next-error' message and corresponding source code"))
1412 map))
1413
1414 (defvar compilation-minor-mode-map
1415 (let ((map (make-sparse-keymap)))
1416 (define-key map [mouse-2] 'compile-goto-error)
1417 (define-key map [follow-link] 'mouse-face)
1418 (define-key map "\C-c\C-c" 'compile-goto-error)
1419 (define-key map "\C-m" 'compile-goto-error)
1420 (define-key map "\C-c\C-k" 'kill-compilation)
1421 (define-key map "\M-n" 'compilation-next-error)
1422 (define-key map "\M-p" 'compilation-previous-error)
1423 (define-key map "\M-{" 'compilation-previous-file)
1424 (define-key map "\M-}" 'compilation-next-file)
1425 (define-key map "g" 'recompile) ; revert
1426 (define-key map "q" 'quit-window)
1427 ;; Set up the menu-bar
1428 (define-key map [menu-bar compilation]
1429 (cons "Errors" compilation-menu-map))
1430 map)
1431 "Keymap for `compilation-minor-mode'.")
1432
1433 (defvar compilation-shell-minor-mode-map
1434 (let ((map (make-sparse-keymap)))
1435 (define-key map "\M-\C-m" 'compile-goto-error)
1436 (define-key map "\M-\C-n" 'compilation-next-error)
1437 (define-key map "\M-\C-p" 'compilation-previous-error)
1438 (define-key map "\M-{" 'compilation-previous-file)
1439 (define-key map "\M-}" 'compilation-next-file)
1440 ;; Set up the menu-bar
1441 (define-key map [menu-bar compilation]
1442 (cons "Errors" compilation-menu-map))
1443 map)
1444 "Keymap for `compilation-shell-minor-mode'.")
1445
1446 (defvar compilation-button-map
1447 (let ((map (make-sparse-keymap)))
1448 (define-key map [mouse-2] 'compile-goto-error)
1449 (define-key map [follow-link] 'mouse-face)
1450 (define-key map "\C-m" 'compile-goto-error)
1451 map)
1452 "Keymap for compilation-message buttons.")
1453 (fset 'compilation-button-map compilation-button-map)
1454
1455 (defvar compilation-mode-map
1456 (let ((map (make-sparse-keymap)))
1457 ;; Don't inherit from compilation-minor-mode-map,
1458 ;; because that introduces a menu bar item we don't want.
1459 ;; That confuses C-down-mouse-3.
1460 (define-key map [mouse-2] 'compile-goto-error)
1461 (define-key map [follow-link] 'mouse-face)
1462 (define-key map "\C-c\C-c" 'compile-goto-error)
1463 (define-key map "\C-m" 'compile-goto-error)
1464 (define-key map "\C-c\C-k" 'kill-compilation)
1465 (define-key map "\M-n" 'compilation-next-error)
1466 (define-key map "\M-p" 'compilation-previous-error)
1467 (define-key map "\M-{" 'compilation-previous-file)
1468 (define-key map "\M-}" 'compilation-next-file)
1469 (define-key map "\t" 'compilation-next-error)
1470 (define-key map [backtab] 'compilation-previous-error)
1471 (define-key map "g" 'recompile) ; revert
1472 (define-key map "q" 'quit-window)
1473
1474 (define-key map " " 'scroll-up)
1475 (define-key map "\^?" 'scroll-down)
1476 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
1477
1478 ;; Set up the menu-bar
1479 (let ((submap (make-sparse-keymap "Compile")))
1480 (define-key map [menu-bar compilation]
1481 (cons "Compile" submap))
1482 (set-keymap-parent submap compilation-menu-map))
1483 (define-key map [menu-bar compilation compilation-separator2]
1484 '("----" . nil))
1485 (define-key map [menu-bar compilation compilation-grep]
1486 '(menu-item "Search Files (grep)..." grep
1487 :help "Run grep, with user-specified args, and collect output in a buffer"))
1488 (define-key map [menu-bar compilation compilation-recompile]
1489 '(menu-item "Recompile" recompile
1490 :help "Re-compile the program including the current buffer"))
1491 (define-key map [menu-bar compilation compilation-compile]
1492 '(menu-item "Compile..." compile
1493 :help "Compile the program including the current buffer. Default: run `make'"))
1494 map)
1495 "Keymap for compilation log buffers.
1496 `compilation-minor-mode-map' is a parent of this.")
1497
1498 (defvar compilation-mode-tool-bar-map
1499 ;; When bootstrapping, tool-bar-map is not properly initialized yet,
1500 ;; so don't do anything.
1501 (when (keymapp (butlast tool-bar-map))
1502 (let ((map (butlast (copy-keymap tool-bar-map)))
1503 (help (last tool-bar-map))) ;; Keep Help last in tool bar
1504 (tool-bar-local-item
1505 "left-arrow" 'previous-error-no-select 'previous-error-no-select map
1506 :rtl "right-arrow"
1507 :help "Goto previous error")
1508 (tool-bar-local-item
1509 "right-arrow" 'next-error-no-select 'next-error-no-select map
1510 :rtl "left-arrow"
1511 :help "Goto next error")
1512 (tool-bar-local-item
1513 "cancel" 'kill-compilation 'kill-compilation map
1514 :enable '(let ((buffer (compilation-find-buffer)))
1515 (get-buffer-process buffer))
1516 :help "Stop compilation")
1517 (tool-bar-local-item
1518 "refresh" 'recompile 'recompile map
1519 :help "Restart compilation")
1520 (append map help))))
1521
1522 (put 'compilation-mode 'mode-class 'special)
1523
1524 ;;;###autoload
1525 (defun compilation-mode (&optional name-of-mode)
1526 "Major mode for compilation log buffers.
1527 \\<compilation-mode-map>To visit the source for a line-numbered error,
1528 move point to the error message line and type \\[compile-goto-error].
1529 To kill the compilation, type \\[kill-compilation].
1530
1531 Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
1532
1533 \\{compilation-mode-map}"
1534 (interactive)
1535 (kill-all-local-variables)
1536 (use-local-map compilation-mode-map)
1537 ;; Let windows scroll along with the output.
1538 (set (make-local-variable 'window-point-insertion-type) t)
1539 (set (make-local-variable 'tool-bar-map) compilation-mode-tool-bar-map)
1540 (setq major-mode 'compilation-mode
1541 mode-name (or name-of-mode "Compilation"))
1542 (set (make-local-variable 'page-delimiter)
1543 compilation-page-delimiter)
1544 (compilation-setup)
1545 (setq buffer-read-only t)
1546 (run-mode-hooks 'compilation-mode-hook))
1547
1548 (defmacro define-compilation-mode (mode name doc &rest body)
1549 "This is like `define-derived-mode' without the PARENT argument.
1550 The parent is always `compilation-mode' and the customizable `compilation-...'
1551 variables are also set from the name of the mode you have chosen,
1552 by replacing the first word, e.g `compilation-scroll-output' from
1553 `grep-scroll-output' if that variable exists."
1554 (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
1555 `(define-derived-mode ,mode compilation-mode ,name
1556 ,doc
1557 ,@(mapcar (lambda (v)
1558 (setq v (cons v
1559 (intern-soft (replace-regexp-in-string
1560 "^compilation" mode-name
1561 (symbol-name v)))))
1562 (and (cdr v)
1563 (or (boundp (cdr v))
1564 (if (boundp 'byte-compile-bound-variables)
1565 (memq (cdr v) byte-compile-bound-variables)))
1566 `(set (make-local-variable ',(car v)) ,(cdr v))))
1567 '(compilation-buffer-name-function
1568 compilation-directory-matcher
1569 compilation-error
1570 compilation-error-regexp-alist
1571 compilation-error-regexp-alist-alist
1572 compilation-error-screen-columns
1573 compilation-finish-function
1574 compilation-finish-functions
1575 compilation-first-column
1576 compilation-mode-font-lock-keywords
1577 compilation-page-delimiter
1578 compilation-parse-errors-filename-function
1579 compilation-process-setup-function
1580 compilation-scroll-output
1581 compilation-search-path
1582 compilation-skip-threshold
1583 compilation-window-height))
1584 ,@body)))
1585
1586 (defun compilation-revert-buffer (ignore-auto noconfirm)
1587 (if buffer-file-name
1588 (let (revert-buffer-function)
1589 (revert-buffer ignore-auto noconfirm))
1590 (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
1591 (apply 'compilation-start compilation-arguments))))
1592
1593 (defvar compilation-current-error nil
1594 "Marker to the location from where the next error will be found.
1595 The global commands next/previous/first-error/goto-error use this.")
1596
1597 (defvar compilation-messages-start nil
1598 "Buffer position of the beginning of the compilation messages.
1599 If nil, use the beginning of buffer.")
1600
1601 ;; A function name can't be a hook, must be something with a value.
1602 (defconst compilation-turn-on-font-lock 'turn-on-font-lock)
1603
1604 (defun compilation-setup (&optional minor)
1605 "Prepare the buffer for the compilation parsing commands to work.
1606 Optional argument MINOR indicates this is called from
1607 `compilation-minor-mode'."
1608 (make-local-variable 'compilation-current-error)
1609 (make-local-variable 'compilation-messages-start)
1610 (make-local-variable 'compilation-error-screen-columns)
1611 (make-local-variable 'overlay-arrow-position)
1612 (set (make-local-variable 'overlay-arrow-string) "")
1613 (setq next-error-overlay-arrow-position nil)
1614 (add-hook 'kill-buffer-hook
1615 (lambda () (setq next-error-overlay-arrow-position nil)) nil t)
1616 ;; Note that compilation-next-error-function is for interfacing
1617 ;; with the next-error function in simple.el, and it's only
1618 ;; coincidentally named similarly to compilation-next-error.
1619 (setq next-error-function 'compilation-next-error-function)
1620 (set (make-local-variable 'comint-file-name-prefix)
1621 (or (file-remote-p default-directory) ""))
1622 (set (make-local-variable 'font-lock-extra-managed-props)
1623 '(directory message help-echo mouse-face debug))
1624 (set (make-local-variable 'compilation-locs)
1625 (make-hash-table :test 'equal :weakness 'value))
1626 ;; lazy-lock would never find the message unless it's scrolled to.
1627 ;; jit-lock might fontify some things too late.
1628 (set (make-local-variable 'font-lock-support-mode) nil)
1629 (set (make-local-variable 'font-lock-maximum-size) nil)
1630 (if minor
1631 (let ((fld font-lock-defaults))
1632 (font-lock-add-keywords nil (compilation-mode-font-lock-keywords))
1633 (if font-lock-mode
1634 (if fld
1635 (font-lock-fontify-buffer)
1636 (font-lock-change-mode)
1637 (turn-on-font-lock))
1638 (turn-on-font-lock)))
1639 (setq font-lock-defaults '(compilation-mode-font-lock-keywords t))
1640 ;; maybe defer font-lock till after derived mode is set up
1641 (run-mode-hooks 'compilation-turn-on-font-lock)))
1642
1643 ;;;###autoload
1644 (define-minor-mode compilation-shell-minor-mode
1645 "Toggle compilation shell minor mode.
1646 With arg, turn compilation mode on if and only if arg is positive.
1647 In this minor mode, all the error-parsing commands of the
1648 Compilation major mode are available but bound to keys that don't
1649 collide with Shell mode. See `compilation-mode'.
1650 Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
1651 nil " Shell-Compile"
1652 :group 'compilation
1653 (if compilation-shell-minor-mode
1654 (compilation-setup t)
1655 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1656 (font-lock-fontify-buffer)))
1657
1658 ;;;###autoload
1659 (define-minor-mode compilation-minor-mode
1660 "Toggle compilation minor mode.
1661 With arg, turn compilation mode on if and only if arg is positive.
1662 In this minor mode, all the error-parsing commands of the
1663 Compilation major mode are available. See `compilation-mode'.
1664 Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
1665 nil " Compilation"
1666 :group 'compilation
1667 (if compilation-minor-mode
1668 (compilation-setup t)
1669 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1670 (font-lock-fontify-buffer)))
1671
1672 (defun compilation-handle-exit (process-status exit-status msg)
1673 "Write MSG in the current buffer and hack its `mode-line-process'."
1674 (let ((inhibit-read-only t)
1675 (status (if compilation-exit-message-function
1676 (funcall compilation-exit-message-function
1677 process-status exit-status msg)
1678 (cons msg exit-status)))
1679 (omax (point-max))
1680 (opoint (point))
1681 (cur-buffer (current-buffer)))
1682 ;; Record where we put the message, so we can ignore it later on.
1683 (goto-char omax)
1684 (insert ?\n mode-name " " (car status))
1685 (if (and (numberp compilation-window-height)
1686 (zerop compilation-window-height))
1687 (message "%s" (cdr status)))
1688 (if (bolp)
1689 (forward-char -1))
1690 (insert " at " (substring (current-time-string) 0 19))
1691 (goto-char (point-max))
1692 ;; Prevent that message from being recognized as a compilation error.
1693 (add-text-properties omax (point)
1694 (append '(compilation-handle-exit t) nil))
1695 (setq mode-line-process
1696 (let ((out-string (format ":%s [%s]" process-status (cdr status)))
1697 (msg (format "%s %s" mode-name
1698 (replace-regexp-in-string "\n?$" "" (car status)))))
1699 (message "%s" msg)
1700 (propertize out-string
1701 'help-echo msg 'face (if (> exit-status 0)
1702 'compilation-error
1703 'compilation-info))))
1704 ;; Force mode line redisplay soon.
1705 (force-mode-line-update)
1706 (if (and opoint (< opoint omax))
1707 (goto-char opoint))
1708 (with-no-warnings
1709 (if compilation-finish-function
1710 (funcall compilation-finish-function cur-buffer msg)))
1711 (run-hook-with-args 'compilation-finish-functions cur-buffer msg)))
1712
1713 ;; Called when compilation process changes state.
1714 (defun compilation-sentinel (proc msg)
1715 "Sentinel for compilation buffers."
1716 (if (memq (process-status proc) '(exit signal))
1717 (let ((buffer (process-buffer proc)))
1718 (if (null (buffer-name buffer))
1719 ;; buffer killed
1720 (set-process-buffer proc nil)
1721 (with-current-buffer buffer
1722 ;; Write something in the compilation buffer
1723 ;; and hack its mode line.
1724 (compilation-handle-exit (process-status proc)
1725 (process-exit-status proc)
1726 msg)
1727 ;; Since the buffer and mode line will show that the
1728 ;; process is dead, we can delete it now. Otherwise it
1729 ;; will stay around until M-x list-processes.
1730 (delete-process proc)))
1731 (setq compilation-in-progress (delq proc compilation-in-progress)))))
1732
1733 (defun compilation-filter (proc string)
1734 "Process filter for compilation buffers.
1735 Just inserts the text,
1736 handles carriage motion (see `comint-inhibit-carriage-motion'),
1737 and runs `compilation-filter-hook'."
1738 (when (buffer-live-p (process-buffer proc))
1739 (with-current-buffer (process-buffer proc)
1740 (let ((inhibit-read-only t)
1741 ;; `save-excursion' doesn't use the right insertion-type for us.
1742 (pos (copy-marker (point) t))
1743 (min (point-min-marker))
1744 (max (point-max-marker)))
1745 (unwind-protect
1746 (progn
1747 ;; If we are inserting at the end of the accessible part
1748 ;; of the buffer, keep the inserted text visible.
1749 (set-marker-insertion-type max t)
1750 (widen)
1751 (goto-char (process-mark proc))
1752 ;; We used to use `insert-before-markers', so that windows with
1753 ;; point at `process-mark' scroll along with the output, but we
1754 ;; now use window-point-insertion-type instead.
1755 (insert string)
1756 (unless comint-inhibit-carriage-motion
1757 (comint-carriage-motion (process-mark proc) (point)))
1758 (set-marker (process-mark proc) (point))
1759 (run-hooks 'compilation-filter-hook))
1760 (goto-char pos)
1761 (narrow-to-region min max)
1762 (set-marker min nil)
1763 (set-marker max nil))))))
1764
1765 ;;; test if a buffer is a compilation buffer, assuming we're in the buffer
1766 (defsubst compilation-buffer-internal-p ()
1767 "Test if inside a compilation buffer."
1768 (local-variable-p 'compilation-locs))
1769
1770 ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p
1771 (defsubst compilation-buffer-p (buffer)
1772 "Test if BUFFER is a compilation buffer."
1773 (with-current-buffer buffer
1774 (compilation-buffer-internal-p)))
1775
1776 (defmacro compilation-loop (< property-change 1+ error limit)
1777 `(let (opt)
1778 (while (,< n 0)
1779 (setq opt pt)
1780 (or (setq pt (,property-change pt 'message))
1781 ;; Handle the case where where the first error message is
1782 ;; at the start of the buffer, and n < 0.
1783 (if (or (eq (get-text-property ,limit 'message)
1784 (get-text-property opt 'message))
1785 (eq pt opt))
1786 (error ,error compilation-error)
1787 (setq pt ,limit)))
1788 ;; prop 'message usually has 2 changes, on and off, so
1789 ;; re-search if off
1790 (or (setq msg (get-text-property pt 'message))
1791 (if (setq pt (,property-change pt 'message nil ,limit))
1792 (setq msg (get-text-property pt 'message)))
1793 (error ,error compilation-error))
1794 (or (< (cadr msg) compilation-skip-threshold)
1795 (if different-file
1796 (eq (prog1 last (setq last (nth 2 (car msg))))
1797 last))
1798 (if compilation-skip-visited
1799 (nthcdr 5 (car msg)))
1800 (if compilation-skip-to-next-location
1801 (eq (car msg) loc))
1802 ;; count this message only if none of the above are true
1803 (setq n (,1+ n))))))
1804
1805 (defun compilation-next-error (n &optional different-file pt)
1806 "Move point to the next error in the compilation buffer.
1807 This function does NOT find the source line like \\[next-error].
1808 Prefix arg N says how many error messages to move forwards (or
1809 backwards, if negative).
1810 Optional arg DIFFERENT-FILE, if non-nil, means find next error for a
1811 file that is different from the current one.
1812 Optional arg PT, if non-nil, specifies the value of point to start
1813 looking for the next message."
1814 (interactive "p")
1815 (or (compilation-buffer-p (current-buffer))
1816 (error "Not in a compilation buffer"))
1817 (or pt (setq pt (point)))
1818 (let* ((msg (get-text-property pt 'message))
1819 ;; `loc' is used by the compilation-loop macro.
1820 (loc (car msg))
1821 last)
1822 (if (zerop n)
1823 (unless (or msg ; find message near here
1824 (setq msg (get-text-property (max (1- pt) (point-min))
1825 'message)))
1826 (setq pt (previous-single-property-change pt 'message nil
1827 (line-beginning-position)))
1828 (unless (setq msg (get-text-property (max (1- pt) (point-min)) 'message))
1829 (setq pt (next-single-property-change pt 'message nil
1830 (line-end-position)))
1831 (or (setq msg (get-text-property pt 'message))
1832 (setq pt (point)))))
1833 (setq last (nth 2 (car msg)))
1834 (if (>= n 0)
1835 (compilation-loop > next-single-property-change 1-
1836 (if (get-buffer-process (current-buffer))
1837 "No more %ss yet"
1838 "Moved past last %s")
1839 (point-max))
1840 ;; Don't move "back" to message at or before point.
1841 ;; Pass an explicit (point-min) to make sure pt is non-nil.
1842 (setq pt (previous-single-property-change pt 'message nil (point-min)))
1843 (compilation-loop < previous-single-property-change 1+
1844 "Moved back before first %s" (point-min))))
1845 (goto-char pt)
1846 (or msg
1847 (error "No %s here" compilation-error))))
1848
1849 (defun compilation-previous-error (n)
1850 "Move point to the previous error in the compilation buffer.
1851 Prefix arg N says how many error messages to move backwards (or
1852 forwards, if negative).
1853 Does NOT find the source line like \\[previous-error]."
1854 (interactive "p")
1855 (compilation-next-error (- n)))
1856
1857 (defun compilation-next-file (n)
1858 "Move point to the next error for a different file than the current one.
1859 Prefix arg N says how many files to move forwards (or backwards, if negative)."
1860 (interactive "p")
1861 (compilation-next-error n t))
1862
1863 (defun compilation-previous-file (n)
1864 "Move point to the previous error for a different file than the current one.
1865 Prefix arg N says how many files to move backwards (or forwards, if negative)."
1866 (interactive "p")
1867 (compilation-next-file (- n)))
1868
1869 (defun kill-compilation ()
1870 "Kill the process made by the \\[compile] or \\[grep] commands."
1871 (interactive)
1872 (let ((buffer (compilation-find-buffer)))
1873 (if (get-buffer-process buffer)
1874 (interrupt-process (get-buffer-process buffer))
1875 (error "The %s process is not running" (downcase mode-name)))))
1876
1877 (defalias 'compile-mouse-goto-error 'compile-goto-error)
1878
1879 (defun compile-goto-error (&optional event)
1880 "Visit the source for the error message at point.
1881 Use this command in a compilation log buffer. Sets the mark at point there."
1882 (interactive (list last-input-event))
1883 (if event (posn-set-point (event-end event)))
1884 (or (compilation-buffer-p (current-buffer))
1885 (error "Not in a compilation buffer"))
1886 (if (get-text-property (point) 'directory)
1887 (dired-other-window (car (get-text-property (point) 'directory)))
1888 (push-mark)
1889 (setq compilation-current-error (point))
1890 (next-error-internal)))
1891
1892 (defun compilation-find-buffer (&optional avoid-current)
1893 "Return a compilation buffer.
1894 If AVOID-CURRENT is nil, and the current buffer is a compilation buffer,
1895 return it. If AVOID-CURRENT is non-nil, return the current buffer only
1896 as a last resort."
1897 (if (and (compilation-buffer-internal-p) (not avoid-current))
1898 (current-buffer)
1899 (next-error-find-buffer avoid-current 'compilation-buffer-internal-p)))
1900
1901 ;;;###autoload
1902 (defun compilation-next-error-function (n &optional reset)
1903 "Advance to the next error message and visit the file where the error was.
1904 This is the value of `next-error-function' in Compilation buffers."
1905 (interactive "p")
1906 (when reset
1907 (setq compilation-current-error nil))
1908 (let* ((columns compilation-error-screen-columns) ; buffer's local value
1909 (last 1) timestamp
1910 (loc (compilation-next-error (or n 1) nil
1911 (or compilation-current-error
1912 compilation-messages-start
1913 (point-min))))
1914 (end-loc (nth 2 loc))
1915 (marker (point-marker)))
1916 (setq compilation-current-error (point-marker)
1917 overlay-arrow-position
1918 (if (bolp)
1919 compilation-current-error
1920 (copy-marker (line-beginning-position)))
1921 loc (car loc))
1922 ;; If loc contains no marker, no error in that file has been visited.
1923 ;; If the marker is invalid the buffer has been killed.
1924 ;; If the file is newer than the timestamp, it has been modified
1925 ;; (`omake -P' polls filesystem for changes and recompiles when needed
1926 ;; in the same process and buffer).
1927 ;; So, recalculate all markers for that file.
1928 (unless (and (nth 3 loc) (marker-buffer (nth 3 loc))
1929 ;; There may be no timestamp info if the loc is a `fake-loc'.
1930 ;; So we skip the time-check here, although we should maybe
1931 ;; change `compilation-fake-loc' to add timestamp info.
1932 (or (null (nth 4 loc))
1933 (equal (nth 4 loc)
1934 (setq timestamp
1935 (with-current-buffer
1936 (marker-buffer (nth 3 loc))
1937 (visited-file-modtime))))))
1938 (with-current-buffer (compilation-find-file marker (caar (nth 2 loc))
1939 (cadr (car (nth 2 loc))))
1940 (save-restriction
1941 (widen)
1942 (goto-char (point-min))
1943 ;; Treat file's found lines in forward order, 1 by 1.
1944 (dolist (line (reverse (cddr (nth 2 loc))))
1945 (when (car line) ; else this is a filename w/o a line#
1946 (beginning-of-line (- (car line) last -1))
1947 (setq last (car line)))
1948 ;; Treat line's found columns and store/update a marker for each.
1949 (dolist (col (cdr line))
1950 (if (car col)
1951 (if (eq (car col) -1) ; special case for range end
1952 (end-of-line)
1953 (compilation-move-to-column (car col) columns))
1954 (beginning-of-line)
1955 (skip-chars-forward " \t"))
1956 (if (nth 3 col)
1957 (set-marker (nth 3 col) (point))
1958 (setcdr (nthcdr 2 col) `(,(point-marker)))))))))
1959 (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc))
1960 (setcdr (nthcdr 3 loc) (list timestamp))
1961 (setcdr (nthcdr 4 loc) t))) ; Set this one as visited.
1962
1963 (defvar compilation-gcpro nil
1964 "Internal variable used to keep some values from being GC'd.")
1965 (make-variable-buffer-local 'compilation-gcpro)
1966
1967 (defun compilation-fake-loc (marker file &optional line col)
1968 "Preassociate MARKER with FILE.
1969 FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
1970 This is useful when you compile temporary files, but want
1971 automatic translation of the messages to the real buffer from
1972 which the temporary file came. This only works if done before a
1973 message about FILE appears!
1974
1975 Optional args LINE and COL default to 1 and beginning of
1976 indentation respectively. The marker is expected to reflect
1977 this. In the simplest case the marker points to the first line
1978 of the region that was saved to the temp file.
1979
1980 If you concatenate several regions into the temp file (e.g. a
1981 header with variable assignments and a code region), you must
1982 call this several times, once each for the last line of one
1983 region and the first line of the next region."
1984 (or (consp file) (setq file (list file)))
1985 (setq file (compilation-get-file-structure file))
1986 ;; Between the current call to compilation-fake-loc and the first occurrence
1987 ;; of an error message referring to `file', the data is only kept in the
1988 ;; weak hash-table compilation-locs, so we need to prevent this entry
1989 ;; in compilation-locs from being GC'd away. --Stef
1990 (push file compilation-gcpro)
1991 (let ((loc (compilation-assq (or line 1) (cdr file))))
1992 (setq loc (compilation-assq col loc))
1993 (if (cdr loc)
1994 (setcdr (cddr loc) (list marker))
1995 (setcdr loc (list line file marker)))
1996 loc))
1997
1998 (defcustom compilation-context-lines nil
1999 "Display this many lines of leading context before the current message.
2000 If nil and the left fringe is displayed, don't scroll the
2001 compilation output window; an arrow in the left fringe points to
2002 the current message. If nil and there is no left fringe, the message
2003 displays at the top of the window; there is no arrow."
2004 :type '(choice integer (const :tag "No window scrolling" nil))
2005 :group 'compilation
2006 :version "22.1")
2007
2008 (defsubst compilation-set-window (w mk)
2009 "Align the compilation output window W with marker MK near top."
2010 (if (integerp compilation-context-lines)
2011 (set-window-start w (save-excursion
2012 (goto-char mk)
2013 (beginning-of-line
2014 (- 1 compilation-context-lines))
2015 (point)))
2016 ;; If there is no left fringe.
2017 (if (equal (car (window-fringes)) 0)
2018 (set-window-start w (save-excursion
2019 (goto-char mk)
2020 (beginning-of-line 1)
2021 (point)))))
2022 (set-window-point w mk))
2023
2024 (defvar next-error-highlight-timer)
2025
2026 (defun compilation-goto-locus (msg mk end-mk)
2027 "Jump to an error corresponding to MSG at MK.
2028 All arguments are markers. If END-MK is non-nil, mark is set there
2029 and overlay is highlighted between MK and END-MK."
2030 ;; Show compilation buffer in other window, scrolled to this error.
2031 (let* ((from-compilation-buffer (eq (window-buffer (selected-window))
2032 (marker-buffer msg)))
2033 ;; Use an existing window if it is in a visible frame.
2034 (pre-existing (get-buffer-window (marker-buffer msg) 0))
2035 (w (if (and from-compilation-buffer pre-existing)
2036 ;; Calling display-buffer here may end up (partly) hiding
2037 ;; the error location if the two buffers are in two
2038 ;; different frames. So don't do it if it's not necessary.
2039 pre-existing
2040 (let ((display-buffer-reuse-frames t)
2041 (pop-up-windows t))
2042 ;; Pop up a window.
2043 (display-buffer (marker-buffer msg)))))
2044 (highlight-regexp (with-current-buffer (marker-buffer msg)
2045 ;; also do this while we change buffer
2046 (compilation-set-window w msg)
2047 compilation-highlight-regexp)))
2048 ;; Ideally, the window-size should be passed to `display-buffer' (via
2049 ;; something like special-display-buffer) so it's only used when
2050 ;; creating a new window.
2051 (unless pre-existing (compilation-set-window-height w))
2052
2053 (if from-compilation-buffer
2054 ;; If the compilation buffer window was selected,
2055 ;; keep the compilation buffer in this window;
2056 ;; display the source in another window.
2057 (let ((pop-up-windows t))
2058 (pop-to-buffer (marker-buffer mk) 'other-window))
2059 (if (window-dedicated-p (selected-window))
2060 (pop-to-buffer (marker-buffer mk))
2061 (switch-to-buffer (marker-buffer mk))))
2062 ;; If narrowing gets in the way of going to the right place, widen.
2063 (unless (eq (goto-char mk) (point))
2064 (widen)
2065 (goto-char mk))
2066 (if end-mk
2067 (push-mark end-mk t)
2068 (if mark-active (setq mark-active)))
2069 ;; If hideshow got in the way of
2070 ;; seeing the right place, open permanently.
2071 (dolist (ov (overlays-at (point)))
2072 (when (eq 'hs (overlay-get ov 'invisible))
2073 (delete-overlay ov)
2074 (goto-char mk)))
2075
2076 (when highlight-regexp
2077 (if (timerp next-error-highlight-timer)
2078 (cancel-timer next-error-highlight-timer))
2079 (unless compilation-highlight-overlay
2080 (setq compilation-highlight-overlay
2081 (make-overlay (point-min) (point-min)))
2082 (overlay-put compilation-highlight-overlay 'face 'next-error))
2083 (with-current-buffer (marker-buffer mk)
2084 (save-excursion
2085 (if end-mk (goto-char end-mk) (end-of-line))
2086 (let ((end (point)))
2087 (if mk (goto-char mk) (beginning-of-line))
2088 (if (and (stringp highlight-regexp)
2089 (re-search-forward highlight-regexp end t))
2090 (progn
2091 (goto-char (match-beginning 0))
2092 (move-overlay compilation-highlight-overlay
2093 (match-beginning 0) (match-end 0)
2094 (current-buffer)))
2095 (move-overlay compilation-highlight-overlay
2096 (point) end (current-buffer)))
2097 (if (or (eq next-error-highlight t)
2098 (numberp next-error-highlight))
2099 ;; We want highlighting: delete overlay on next input.
2100 (add-hook 'pre-command-hook
2101 'compilation-goto-locus-delete-o)
2102 ;; We don't want highlighting: delete overlay now.
2103 (delete-overlay compilation-highlight-overlay))
2104 ;; We want highlighting for a limited time:
2105 ;; set up a timer to delete it.
2106 (when (numberp next-error-highlight)
2107 (setq next-error-highlight-timer
2108 (run-at-time next-error-highlight nil
2109 'compilation-goto-locus-delete-o)))))))
2110 (when (and (eq next-error-highlight 'fringe-arrow))
2111 ;; We want a fringe arrow (instead of highlighting).
2112 (setq next-error-overlay-arrow-position
2113 (copy-marker (line-beginning-position))))))
2114
2115 (defun compilation-goto-locus-delete-o ()
2116 (delete-overlay compilation-highlight-overlay)
2117 ;; Get rid of timer and hook that would try to do this again.
2118 (if (timerp next-error-highlight-timer)
2119 (cancel-timer next-error-highlight-timer))
2120 (remove-hook 'pre-command-hook
2121 'compilation-goto-locus-delete-o))
2122 \f
2123 (defun compilation-find-file (marker filename directory &rest formats)
2124 "Find a buffer for file FILENAME.
2125 If FILENAME is not found at all, ask the user where to find it.
2126 Pop up the buffer containing MARKER and scroll to MARKER if we ask
2127 the user where to find the file.
2128 Search the directories in `compilation-search-path'.
2129 A nil in `compilation-search-path' means to try the
2130 \"current\" directory, which is passed in DIRECTORY.
2131 If DIRECTORY is relative, it is combined with `default-directory'.
2132 If DIRECTORY is nil, that means use `default-directory'.
2133 FORMATS, if given, is a list of formats to reformat FILENAME when
2134 looking for it: for each element FMT in FORMATS, this function
2135 attempts to find a file whose name is produced by (format FMT FILENAME)."
2136 (or formats (setq formats '("%s")))
2137 (let ((dirs compilation-search-path)
2138 (spec-dir (if directory
2139 (expand-file-name directory)
2140 default-directory))
2141 buffer thisdir fmts name)
2142 (if (file-name-absolute-p filename)
2143 ;; The file name is absolute. Use its explicit directory as
2144 ;; the first in the search path, and strip it from FILENAME.
2145 (setq filename (abbreviate-file-name (expand-file-name filename))
2146 dirs (cons (file-name-directory filename) dirs)
2147 filename (file-name-nondirectory filename)))
2148 ;; Now search the path.
2149 (while (and dirs (null buffer))
2150 (setq thisdir (or (car dirs) spec-dir)
2151 fmts formats)
2152 ;; For each directory, try each format string.
2153 (while (and fmts (null buffer))
2154 (setq name (expand-file-name (format (car fmts) filename) thisdir)
2155 buffer (and (file-exists-p name)
2156 (find-file-noselect name))
2157 fmts (cdr fmts)))
2158 (setq dirs (cdr dirs)))
2159 (while (null buffer) ;Repeat until the user selects an existing file.
2160 ;; The file doesn't exist. Ask the user where to find it.
2161 (save-excursion ;This save-excursion is probably not right.
2162 (let ((pop-up-windows t))
2163 (compilation-set-window (display-buffer (marker-buffer marker))
2164 marker)
2165 (let* ((name (read-file-name
2166 (format "Find this %s in (default %s): "
2167 compilation-error filename)
2168 spec-dir filename t nil
2169 ;; The predicate below is fine when called from
2170 ;; minibuffer-complete-and-exit, but it's too
2171 ;; restrictive otherwise, since it also prevents the
2172 ;; user from completing "fo" to "foo/" when she
2173 ;; wants to enter "foo/bar".
2174 ;;
2175 ;; Try to make sure the user can only select
2176 ;; a valid answer. This predicate may be ignored,
2177 ;; tho, so we still have to double-check afterwards.
2178 ;; TODO: We should probably fix read-file-name so
2179 ;; that it never ignores this predicate, even when
2180 ;; using popup dialog boxes.
2181 ;; (lambda (name)
2182 ;; (if (file-directory-p name)
2183 ;; (setq name (expand-file-name filename name)))
2184 ;; (file-exists-p name))
2185 ))
2186 (origname name))
2187 (cond
2188 ((not (file-exists-p name))
2189 (message "Cannot find file `%s'" name)
2190 (ding) (sit-for 2))
2191 ((and (file-directory-p name)
2192 (not (file-exists-p
2193 (setq name (expand-file-name filename name)))))
2194 (message "No `%s' in directory %s" filename origname)
2195 (ding) (sit-for 2))
2196 (t
2197 (setq buffer (find-file-noselect name))))))))
2198 ;; Make intangible overlays tangible.
2199 ;; This is weird: it's not even clear which is the current buffer,
2200 ;; so the code below can't be expected to DTRT here. -- Stef
2201 (dolist (ov (overlays-in (point-min) (point-max)))
2202 (when (overlay-get ov 'intangible)
2203 (overlay-put ov 'intangible nil)))
2204 buffer))
2205
2206 (defun compilation-get-file-structure (file &optional fmt)
2207 "Retrieve FILE's file-structure or create a new one.
2208 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
2209 In the former case, FILENAME may be relative or absolute.
2210
2211 The file-structure looks like this:
2212 (list (list FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)"
2213 (or (gethash file compilation-locs)
2214 ;; File was not previously encountered, at least not in the form passed.
2215 ;; Let's normalize it and look again.
2216 (let ((filename (car file))
2217 ;; Get the specified directory from FILE.
2218 (spec-directory (if (cdr file)
2219 (file-truename (cdr file)))))
2220
2221 ;; Check for a comint-file-name-prefix and prepend it if appropriate.
2222 ;; (This is very useful for compilation-minor-mode in an rlogin-mode
2223 ;; buffer.)
2224 (when (and (boundp 'comint-file-name-prefix)
2225 (not (equal comint-file-name-prefix "")))
2226 (if (file-name-absolute-p filename)
2227 (setq filename
2228 (concat comint-file-name-prefix filename))
2229 (if spec-directory
2230 (setq spec-directory
2231 (file-truename
2232 (concat comint-file-name-prefix spec-directory))))))
2233
2234 ;; If compilation-parse-errors-filename-function is
2235 ;; defined, use it to process the filename.
2236 (when compilation-parse-errors-filename-function
2237 (setq filename
2238 (funcall compilation-parse-errors-filename-function
2239 filename)))
2240
2241 ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
2242 ;; file names like "./bar//foo.c" for file "bar/foo.c";
2243 ;; expand-file-name will collapse these into "/foo.c" and fail to find
2244 ;; the appropriate file. So we look for doubled slashes in the file
2245 ;; name and fix them.
2246 (setq filename (command-line-normalize-file-name filename))
2247
2248 ;; Store it for the possibly unnormalized name
2249 (puthash file
2250 ;; Retrieve or create file-structure for normalized name
2251 ;; The gethash used to not use spec-directory, but
2252 ;; this leads to errors when files in different
2253 ;; directories have the same name:
2254 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00463.html
2255 (or (gethash (cons filename spec-directory) compilation-locs)
2256 (puthash (cons filename spec-directory)
2257 (list (list filename spec-directory) fmt)
2258 compilation-locs))
2259 compilation-locs))))
2260
2261 (add-to-list 'debug-ignored-errors "^No more [-a-z ]+s yet$")
2262
2263 ;;; Compatibility with the old compile.el.
2264
2265 (defun compile-buffer-substring (n) (if n (match-string n)))
2266
2267 (defun compilation-compat-error-properties (err)
2268 "Map old-style error ERR to new-style message."
2269 ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
2270 ;; (MARKER . MARKER).
2271 (let ((dst (cdr err)))
2272 (if (markerp dst)
2273 ;; Must start with a face, for font-lock.
2274 `(face nil
2275 message ,(list (list nil nil nil dst) 2)
2276 help-echo "mouse-2: visit the source location"
2277 keymap compilation-button-map
2278 mouse-face highlight)
2279 ;; Too difficult to do it by hand: dispatch to the normal code.
2280 (let* ((file (pop dst))
2281 (line (pop dst))
2282 (col (pop dst))
2283 (filename (pop file))
2284 (dirname (pop file))
2285 (fmt (pop file)))
2286 (compilation-internal-error-properties
2287 (cons filename dirname) line nil col nil 2 fmt)))))
2288
2289 (defun compilation-compat-parse-errors (limit)
2290 (when compilation-parse-errors-function
2291 ;; FIXME: We should remove the rest of the compilation keywords
2292 ;; but we can't do that from here because font-lock is using
2293 ;; the value right now. --stef
2294 (save-excursion
2295 (setq compilation-error-list nil)
2296 ;; Reset compilation-parsing-end each time because font-lock
2297 ;; might force us the re-parse many times (typically because
2298 ;; some code adds some text-property to the output that we
2299 ;; already parsed). You might say "why reparse", well:
2300 ;; because font-lock has just removed the `message' property so
2301 ;; have to do it all over again.
2302 (if compilation-parsing-end
2303 (set-marker compilation-parsing-end (point))
2304 (setq compilation-parsing-end (point-marker)))
2305 (condition-case nil
2306 ;; Ignore any error: we're calling this function earlier than
2307 ;; in the old compile.el so things might not all be setup yet.
2308 (funcall compilation-parse-errors-function limit nil)
2309 (error nil))
2310 (dolist (err (if (listp compilation-error-list) compilation-error-list))
2311 (let* ((src (car err))
2312 (dst (cdr err))
2313 (loc (cond ((markerp dst) (list nil nil nil dst))
2314 ((consp dst)
2315 (list (nth 2 dst) (nth 1 dst)
2316 (cons (cdar dst) (caar dst)))))))
2317 (when loc
2318 (goto-char src)
2319 ;; (put-text-property src (line-end-position) 'font-lock-face 'font-lock-warning-face)
2320 (put-text-property src (line-end-position)
2321 'message (list loc 2)))))))
2322 (goto-char limit)
2323 nil)
2324
2325 ;; Beware: this is not only compatiblity code. New code stil uses it. --Stef
2326 (defun compilation-forget-errors ()
2327 ;; In case we hit the same file/line specs, we want to recompute a new
2328 ;; marker for them, so flush our cache.
2329 (setq compilation-locs (make-hash-table :test 'equal :weakness 'value))
2330 (setq compilation-gcpro nil)
2331 ;; FIXME: the old code reset the directory-stack, so maybe we should
2332 ;; put a `directory change' marker of some sort, but where? -stef
2333 ;;
2334 ;; FIXME: The old code moved compilation-current-error (which was
2335 ;; virtually represented by a mix of compilation-parsing-end and
2336 ;; compilation-error-list) to point-min, but that was only meaningful for
2337 ;; the internal uses of compilation-forget-errors: all calls from external
2338 ;; packages seem to be followed by a move of compilation-parsing-end to
2339 ;; something equivalent to point-max. So we heuristically move
2340 ;; compilation-current-error to point-max (since the external package
2341 ;; won't know that it should do it). --Stef
2342 (setq compilation-current-error nil)
2343 (let* ((proc (get-buffer-process (current-buffer)))
2344 (mark (if proc (process-mark proc)))
2345 (pos (or mark (point-max))))
2346 (setq compilation-messages-start
2347 ;; In the future, ignore the text already present in the buffer.
2348 ;; Since many process filter functions insert before markers,
2349 ;; we need to put ours just before the insertion point rather
2350 ;; than at the insertion point. If that's not possible, then
2351 ;; don't use a marker. --Stef
2352 (if (> pos (point-min)) (copy-marker (1- pos)) pos)))
2353 ;; Again, since this command is used in buffers that contain several
2354 ;; compilations, to set the beginning of "this compilation", it's a good
2355 ;; place to reset compilation-auto-jump-to-next.
2356 (set (make-local-variable 'compilation-auto-jump-to-next)
2357 (or compilation-auto-jump-to-first-error
2358 (eq compilation-scroll-output 'first-error))))
2359
2360 ;;;###autoload
2361 (add-to-list 'auto-mode-alist '("\\.gcov\\'" . compilation-mode))
2362
2363 (provide 'compile)
2364
2365 ;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c
2366 ;;; compile.el ends here