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