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