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