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