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