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