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