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