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