1 ;;; compile.el --- run compiler as inferior of Emacs, parse error messages
3 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 ;; Free Software Foundation, Inc.
7 ;; Authors: Roland McGrath <roland@gnu.org>,
8 ;; Daniel Pfeiffer <occitan@esperanto.org>
10 ;; Keywords: tools, processes
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;; This package provides the compile facilities documented in the Emacs user's
32 ;; This mode uses some complex data-structures:
34 ;; LOC (or location) is a list of (COLUMN LINE FILE-STRUCTURE)
36 ;; COLUMN and LINE are numbers parsed from an error message. COLUMN and maybe
37 ;; LINE will be nil for a message that doesn't contain them. Then the
38 ;; location refers to a indented beginning of line or beginning of file.
39 ;; Once any location in some file has been jumped to, the list is extended to
40 ;; (COLUMN LINE FILE-STRUCTURE MARKER TIMESTAMP . VISITED)
41 ;; for all LOCs pertaining to that file.
42 ;; MARKER initially points to LINE and COLUMN in a buffer visiting that file.
43 ;; Being a marker it sticks to some text, when the buffer grows or shrinks
44 ;; before that point. VISITED is t if we have jumped there, else nil.
45 ;; TIMESTAMP is necessary because of "incremental compilation": `omake -P'
46 ;; polls filesystem for changes and recompiles when a file is modified
47 ;; using the same *compilation* buffer. this necessitates re-parsing markers.
49 ;; FILE-STRUCTURE is a list of
50 ;; ((FILENAME DIRECTORY) FORMATS (LINE LOC ...) ...)
52 ;; FILENAME is a string parsed from an error message. DIRECTORY is a string
53 ;; obtained by following directory change messages. DIRECTORY will be nil for
54 ;; an absolute filename. FORMATS is a list of formats to apply to FILENAME if
55 ;; a file of that name can't be found.
56 ;; The rest of the list is an alist of elements with LINE as key. The keys
57 ;; are either nil or line numbers. If present, nil comes first, followed by
58 ;; the numbers in decreasing order. The LOCs for each line are again an alist
59 ;; ordered the same way. Note that the whole file structure is referenced in
62 ;; MESSAGE is a list of (LOC TYPE END-LOC)
64 ;; TYPE is 0 for info or 1 for warning if the message matcher identified it as
65 ;; such, 2 otherwise (for a real error). END-LOC is a LOC pointing to the
66 ;; other end, if the parsed message contained a range. If the end of the
67 ;; range didn't specify a COLUMN, it defaults to -1, meaning end of line.
68 ;; These are the value of the `message' text-properties in the compilation
73 (eval-when-compile (require 'cl
))
77 (defvar font-lock-extra-managed-props
)
78 (defvar font-lock-keywords
)
79 (defvar font-lock-maximum-size
)
80 (defvar font-lock-support-mode
)
83 (defgroup compilation nil
84 "Run compiler as inferior of Emacs, parse error messages."
90 (defcustom compilation-mode-hook nil
91 "List of hook functions run by `compilation-mode' (see `run-mode-hooks')."
96 (defcustom compilation-start-hook nil
97 "List of hook functions run by `compilation-start' on the compilation process.
98 \(See `run-hook-with-args').
99 If you use \"omake -P\" and do not want \\[save-buffers-kill-terminal] to ask whether you want
100 the compilation to be killed, you can use this hook:
101 (add-hook 'compilation-start-hook
102 (lambda (process) (set-process-query-on-exit-flag process nil)) nil t)"
107 (defcustom compilation-window-height nil
108 "Number of lines in a compilation window. If nil, use Emacs default."
109 :type
'(choice (const :tag
"Default" nil
)
113 (defvar compilation-first-column
1
114 "*This is how compilers number the first column, usually 1 or 0.")
116 (defvar compilation-parse-errors-filename-function nil
117 "Function to call to post-process filenames while parsing error messages.
118 It takes one arg FILENAME which is the name of a file as found
119 in the compilation output, and should return a transformed file name.")
122 (defvar compilation-process-setup-function nil
123 "*Function to call to customize the compilation process.
124 This function is called immediately before the compilation process is
125 started. It can be used to set any variables or functions that are used
126 while processing the output of the compilation process. The function
127 is called with variables `compilation-buffer' and `compilation-window'
128 bound to the compilation buffer and window, respectively.")
131 (defvar compilation-buffer-name-function nil
132 "Function to compute the name of a compilation buffer.
133 The function receives one argument, the name of the major mode of the
134 compilation buffer. It should return a string.
135 If nil, compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
138 (defvar compilation-finish-function nil
139 "Function to call when a compilation process finishes.
140 It is called with two arguments: the compilation buffer, and a string
141 describing how the process finished.")
143 (make-obsolete-variable 'compilation-finish-function
144 "use `compilation-finish-functions', but it works a little differently."
148 (defvar compilation-finish-functions nil
149 "Functions to call when a compilation process finishes.
150 Each function is called with two arguments: the compilation buffer,
151 and a string describing how the process finished.")
153 (defvar compilation-in-progress nil
154 "List of compilation processes now running.")
155 (or (assq 'compilation-in-progress minor-mode-alist
)
156 (setq minor-mode-alist
(cons '(compilation-in-progress " Compiling")
159 (defvar compilation-error
"error"
160 "Stem of message to print when no matches are found.")
162 (defvar compilation-arguments nil
163 "Arguments that were given to `compilation-start'.")
165 (defvar compilation-num-errors-found
)
167 (defconst compilation-error-regexp-alist-alist
169 "^\\(?:[Ee]rror on \\|[Ww]arning on\\( \\)\\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
170 of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil
(1))
173 "\\(warning: .*\\)? at \\([^ \n]+\\):\\([0-9]+\\)$" 2 3 nil
(1))
176 " in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
179 "^[ \t]*\\[[^] \n]+\\][ \t]*\\([^: \n]+\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):[0-9]+:[0-9]+:\\)?\
180 \\( warning\\)?" 1 2 3 (4))
183 "^\\([^: \n\t]+\\): line \\([0-9]+\\):" 1 2)
186 "^\\(?:Error\\|Warnin\\(g\\)\\) \\(?:[FEW][0-9]+ \\)?\
187 \\([a-zA-Z]?:?[^:( \t\n]+\\)\
188 \\([0-9]+\\)\\(?:[) \t]\\|:[^0-9\n]\\)" 2 3 nil
(1))
191 "^ *File \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1, lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
192 \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:\\)?\\([ \n]Warning:\\)?\\)"
193 2 (3 .
4) (5 .
6) (7))
196 "^\"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)\
197 \\(?:[(. pos]+\\([0-9]+\\))?\\)?[:.,; (-]\\( warning:\\|[-0-9 ]*(W)\\)?" 1 2 3 (4))
200 "\\(?:^cucumber\\(?: -p [^[:space:]]+\\)?\\|#\\)\
201 \\(?: \\)\\([^\(].*\\):\\([1-9][0-9]*\\)" 1 2)
204 "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
207 "at line \\([0-9]+\\) of \"\\([^ \n]+\\)\"$"
211 "^Error [0-9]+ at (\\([0-9]+\\):\\([^)\n]+\\))" 2 1)
214 "\\(^Warning .*\\)? line[ \n]\\([0-9]+\\)[ \n]\\(?:col \\([0-9]+\\)[ \n]\\)?file \\([^ :;\n]+\\)"
218 "^\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(?:Error\\|Warnin\\(g\\)\\)\\[[0-9]+\\]:"
222 "^\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) :\
223 \\(?:warnin\\(g\\)\\|informationa\\(l\\)\\)?" 1 2 3 (4 .
5))
225 ;; fixme: should be `mips'
227 "^[-[:alnum:]_/ ]+: \\(?:\\(?:[sS]evere\\|[eE]rror\\|[wW]arnin\\(g\\)\\|[iI]nf\\(o\\)\\)[0-9 ]*: \\)?\
228 \\([^,\" \n\t]+\\)\\(?:, line\\|:\\) \\([0-9]+\\):" 3 4 nil
(1 .
2))
231 "^\\(?:[ \t]+at \\|==[0-9]+== +\\(?:at\\|b\\(y\\)\\)\\).+(\\([^()\n]+\\):\\([0-9]+\\))$" 2 3 nil
(1))
234 "^\\(?:Found\\|Issued\\) .* compiling \"\\(.+\\)\":$" 1 nil nil
0)
236 "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)"
238 (2 (compilation-face '(3))))
241 "^\\(?:In file included \\| \\|\t\\)from \
242 \\(.+\\):\\([0-9]+\\)\\(?:\\(:\\)\\|\\(,\\|$\\)\\)?" 1 2 nil
(3 .
4))
245 ;; The first line matches the program name for
247 ;; PROGRAM:SOURCE-FILE-NAME:LINENO: MESSAGE
249 ;; format, which is used for non-interactive programs other than
250 ;; compilers (e.g. the "jade:" entry in compilation.txt).
252 ;; This first line makes things ambiguous with output such as
253 ;; "foo:344:50:blabla" since the "foo" part can match this first
254 ;; line (in which case the file name as "344"). To avoid this,
255 ;; the second line disallows filenames exclusively composed of
258 ;; Similarly, we get lots of false positives with messages including
259 ;; times of the form "HH:MM:SS" where MM is taken as a line number, so
260 ;; the last line tries to rule out message where the info after the
261 ;; line number starts with "SS". --Stef
263 ;; The core of the regexp is the one with *?. It says that a file name
264 ;; can be composed of any non-newline char, but it also rules out some
265 ;; valid but unlikely cases, such as a trailing space or a space
267 "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\|[ \t]+\\(?:in \\|from \\)\\)?\
268 \\([0-9]*[^0-9\n]\\(?:[^\n ]\\| [^-/\n]\\)*?\\): ?\
269 \\([0-9]+\\)\\(?:\\([.:]\\)\\([0-9]+\\)\\)?\
270 \\(?:-\\([0-9]+\\)?\\(?:\\.\\([0-9]+\\)\\)?\\)?:\
271 \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\
272 *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\|[Nn]ote\\)\\|\
273 \[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)"
274 1 (2 .
5) (4 .
6) (7 .
8))
277 "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)"
281 "^makepp\\(?:\\(?:: warning\\(:\\).*?\\|\\(: Scanning\\|: [LR]e?l?oading makefile\\|: Imported\\|log:.*?\\) \\|: .*?\\)\
282 `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)"
284 ("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]" nil nil
285 (2 compilation-info-face
)
286 (3 compilation-line-face nil t
)
287 (1 (compilation-error-properties 2 3 nil nil nil
0 nil
)
290 ;; This regexp is pathologically slow on long lines (Bug#3441).
292 ;; ;; Maven is a popular build tool for Java. Maven is Free Software.
293 ;; "\\(.*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\]" 1 2 3)
295 ;; Should be lint-1, lint-2 (SysV lint)
297 " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
299 " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2)
302 ;; The message may be a "warning", "error", or "fatal error" with
303 ;; an error code, or "see declaration of" without an error code.
304 "^ *\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
305 : \\(?:see declaration\\|\\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:\\)"
309 ;; "omake -P" reports "file foo changed"
310 ;; (useful if you do "cvs up" and want to see what has changed)
311 "omake: file \\(.*\\) changed" 1)
314 "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
315 \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
316 \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
319 ;; "during global destruction": This comes out under "use
320 ;; warnings" in recent perl when breaking circular references
321 ;; during program or thread exit.
323 " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \
324 during global destruction\\.$\\)" 1 2)
327 "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
331 "[\t ]*\\[\\([^\(].*\\):\\([1-9][0-9]*\\)\\(\\]\\)?:$" 1 2)
334 "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
335 \\([0-9]+\\) of file://\\(.+\\)"
339 "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
340 [12][09][0-9][0-9] +\\(.*\\):$"
343 "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
344 nil
3 nil
(2) nil
(1 (compilation-face '(2))))
345 (sparc-pascal-example
346 "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
347 nil
1 nil
(3) nil
(2 (compilation-face '(3))))
350 ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
351 File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
355 "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
358 "^[ \t]*\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)): ?\
359 \\(?:\\(Error! E[0-9]+\\)\\|\\(Warning! W[0-9]+\\)\\):"
363 "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
364 \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil
(3))
367 "^ *-: *\\(0\\):Source:\\(.+\\)$"
369 (1 compilation-line-face prepend
) (2 compilation-info-face prepend
))
371 "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
373 (1 compilation-line-face prepend
))
374 ;; Underlines over all lines of gcov output are too uncomfortable to read.
375 ;; However, hyperlinks embedded in the lines are useful.
376 ;; So I put default face on the lines; and then put
377 ;; compilation-*-face by manually to eliminate the underlines.
378 ;; The hyperlinks are still effective.
380 "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
383 (1 compilation-line-face prepend
))
385 "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
388 (1 compilation-info-face prepend
) (2 compilation-line-face prepend
))
390 "^ *\\(#####\\): *\\([0-9]+\\):.*$"
393 (1 compilation-error-face prepend
) (2 compilation-line-face prepend
))
396 ;; podchecker error messages, per Pod::Checker.
397 ;; The style is from the Pod::Checker::poderror() function, eg.
398 ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm
400 ;; Plus end_pod() can give "at line EOF" instead of a
401 ;; number, so for that match "on line N" which is the
402 ;; originating spot, eg.
403 ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm
405 ;; Plus command() can give both "on line N" and "at line N";
406 ;; the latter is desired and is matched because the .* is
408 ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod
410 "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \
411 \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)"
414 ;; perl Test module error messages.
415 ;; Style per the ok() function "$context", eg.
416 ;; # Failed test 1 in foo.t at line 6
418 "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
421 ;; Or when comparing got/want values,
422 ;; # Test 2 got: "xx" (t-compilation-perl-2.t at line 10)
424 ;; And under Test::Harness they're preceded by progress stuff with
426 ;; ... NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
428 "^\\(.*NOK.*\\)?# Test [0-9]+ got:.* (\\([^ \t\r\n]+\\) at line \
432 ;; perl Test::Harness output, eg.
433 ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
435 ;; Test::Harness is slightly designed for tty output, since
436 ;; it prints CRs to overwrite progress messages, but if you
437 ;; run it in with M-x compile this pattern can at least step
438 ;; through the failures.
440 "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
443 ;; The style comes from HTML::Lint::Error::as_string(), eg.
444 ;; index.html (13:1) Unknown element <fdjsk>
446 ;; The pattern only matches filenames without spaces, since that
447 ;; should be usual and should help reduce the chance of a false
448 ;; match of a message from some unrelated program.
450 ;; This message style is quite close to the "ibm" entry which is
451 ;; for IBM C, though that ibm bit doesn't put a space after the
454 "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) "
457 "Alist of values for `compilation-error-regexp-alist'.")
459 (defcustom compilation-error-regexp-alist
460 (mapcar 'car compilation-error-regexp-alist-alist
)
461 "Alist that specifies how to match errors in compiler output.
462 On GNU and Unix, any string is a valid filename, so these
463 matchers must make some common sense assumptions, which catch
464 normal cases. A shorter list will be lighter on resource usage.
466 Instead of an alist element, you can use a symbol, which is
467 looked up in `compilation-error-regexp-alist-alist'. You can see
468 the predefined symbols and their effects in the file
469 `etc/compilation.txt' (linked below if you are customizing this).
471 Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
472 HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
473 gives the file name, and the LINE'th subexpression gives the line
474 number. The COLUMN'th subexpression gives the column number on
477 If FILE, LINE or COLUMN are nil or that index didn't match, that
478 information is not present on the matched line. In that case the
479 file name is assumed to be the same as the previous one in the
480 buffer, line number defaults to 1 and column defaults to
481 beginning of line's indentation.
483 FILE can also have the form (FILE FORMAT...), where the FORMATs
484 \(e.g. \"%s.c\") will be applied in turn to the recognized file
485 name, until a file of that name is found. Or FILE can also be a
486 function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
487 In the former case, FILENAME may be relative or absolute.
489 LINE can also be of the form (LINE . END-LINE) meaning a range
490 of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
491 meaning a range of columns starting on LINE and ending on
492 END-LINE, if that matched.
494 TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
495 TYPE can also be of the form (WARNING . INFO). In that case this
496 will be equivalent to 1 if the WARNING'th subexpression matched
497 or else equivalent to 0 if the INFO'th subexpression matched.
498 See `compilation-error-face', `compilation-warning-face',
499 `compilation-info-face' and `compilation-skip-threshold'.
501 What matched the HYPERLINK'th subexpression has `mouse-face' and
502 `compilation-message-face' applied. If this is nil, the text
503 matched by the whole REGEXP becomes the hyperlink.
505 Additional HIGHLIGHTs as described under `font-lock-keywords' can
507 :type
`(set :menu-tag
"Pick"
508 ,@(mapcar (lambda (elt)
509 (list 'const
(car elt
)))
510 compilation-error-regexp-alist-alist
))
511 :link
`(file-link :tag
"example file"
512 ,(expand-file-name "compilation.txt" data-directory
))
515 ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp)
516 (defvar compilation-directory nil
517 "Directory to restore to when doing `recompile'.")
519 (defvar compilation-directory-matcher
520 '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 .
1))
521 "A list for tracking when directories are entered or left.
522 If nil, do not track directories, e.g. if all file names are absolute. The
523 first element is the REGEXP matching these messages. It can match any number
524 of variants, e.g. different languages. The remaining elements are all of the
525 form (DIR . LEAVE). If for any one of these the DIR'th subexpression
526 matches, that is a directory name. If LEAVE is nil or the corresponding
527 LEAVE'th subexpression doesn't match, this message is about going into another
528 directory. If it does match anything, this message is about going back to the
529 directory we were in before the last entering message. If you change this,
530 you may also want to change `compilation-page-delimiter'.")
532 (defvar compilation-page-delimiter
533 "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
534 "Value of `page-delimiter' in Compilation mode.")
536 (defvar compilation-mode-font-lock-keywords
537 '(;; configure output lines.
538 ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
539 (1 font-lock-variable-name-face
)
540 (2 (compilation-face '(4 .
3))))
541 ;; Command output lines. Recognize `make[n]:' lines too.
542 ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
543 (1 font-lock-function-name-face
) (3 compilation-line-face nil t
))
544 (" --?o\\(?:utfile\\|utput\\)?[= ]?\\(\\S +\\)" .
1)
545 ("^Compilation \\(finished\\).*"
546 (0 '(face nil message nil help-echo nil mouse-face nil
) t
)
547 (1 compilation-info-face
))
548 ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
549 (0 '(face nil message nil help-echo nil mouse-face nil
) t
)
550 (1 compilation-error-face
)
551 (2 compilation-error-face nil t
)))
552 "Additional things to highlight in Compilation mode.
553 This gets tacked on the end of the generated expressions.")
555 (defvar compilation-highlight-regexp t
556 "Regexp matching part of visited source lines to highlight temporarily.
557 Highlight entire line if t; don't highlight source lines if nil.")
559 (defvar compilation-highlight-overlay nil
560 "Overlay used to temporarily highlight compilation matches.")
562 (defcustom compilation-error-screen-columns t
563 "If non-nil, column numbers in error messages are screen columns.
564 Otherwise they are interpreted as character positions, with
565 each character occupying one column.
566 The default is to use screen columns, which requires that the compilation
567 program and Emacs agree about the display width of the characters,
568 especially the TAB character."
573 (defcustom compilation-read-command t
574 "Non-nil means \\[compile] reads the compilation command to use.
575 Otherwise, \\[compile] just uses the value of `compile-command'.
577 Note that changing this to nil may be a security risk, because a
578 file might define a malicious `compile-command' as a file local
579 variable, and you might not notice. Therefore, `compile-command'
580 is considered unsafe if this variable is nil."
585 (defcustom compilation-ask-about-save t
586 "Non-nil means \\[compile] asks which buffers to save before compiling.
587 Otherwise, it saves all modified buffers without asking."
591 (defcustom compilation-save-buffers-predicate nil
592 "The second argument (PRED) passed to `save-some-buffers' before compiling.
593 E.g., one can set this to
595 (string-prefix-p my-compilation-root (file-truename (buffer-file-name))))
596 to limit saving to files located under `my-compilation-root'.
597 Note, that, in general, `compilation-directory' cannot be used instead
598 of `my-compilation-root' here."
600 (const :tag
"Default (save all file-visiting buffers)" nil
)
601 (const :tag
"Save all buffers" t
)
607 (defcustom compilation-search-path
'(nil)
608 "List of directories to search for source files named in error messages.
609 Elements should be directory names, not file names of directories.
610 The value nil as an element means to try the default directory."
611 :type
'(repeat (choice (const :tag
"Default" nil
)
612 (string :tag
"Directory")))
616 (defcustom compile-command
(purecopy "make -k ")
617 "Last shell command used to do a compilation; default for next compilation.
619 Sometimes it is useful for files to supply local values for this variable.
620 You might also use mode hooks to specify it in certain modes, like this:
622 (add-hook 'c-mode-hook
624 (unless (or (file-exists-p \"makefile\")
625 (file-exists-p \"Makefile\"))
626 (set (make-local-variable 'compile-command)
628 (file-name-sans-extension buffer-file-name))))))"
631 ;;;###autoload(put 'compile-command 'safe-local-variable (lambda (a) (and (stringp a) (or (not (boundp 'compilation-read-command)) compilation-read-command))))
634 (defcustom compilation-disable-input nil
635 "If non-nil, send end-of-file as compilation process input.
636 This only affects platforms that support asynchronous processes (see
637 `start-process'); synchronous compilation processes never accept input."
642 ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
643 ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
644 ;; key. This holds the tree seen from root, for storing new nodes.
645 (defvar compilation-locs
())
647 (defvar compilation-debug nil
648 "*Set this to t before creating a *compilation* buffer.
649 Then every error line will have a debug text property with the matcher that
650 fit this line and the match data. Use `describe-text-properties'.")
652 (defvar compilation-exit-message-function nil
"\
653 If non-nil, called when a compilation process dies to return a status message.
654 This should be a function of three arguments: process status, exit status,
655 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
656 write into the compilation buffer, and to put in its mode line.")
658 (defvar compilation-environment nil
659 "*List of environment variables for compilation to inherit.
660 Each element should be a string of the form ENVVARNAME=VALUE.
661 This list is temporarily prepended to `process-environment' prior to
662 starting the compilation process.")
664 ;; History of compile commands.
665 (defvar compile-history nil
)
667 (defface compilation-error
668 '((t :inherit font-lock-warning-face
))
669 "Face used to highlight compiler errors."
673 (defface compilation-warning
674 '((((class color
) (min-colors 16)) (:foreground
"Orange" :weight bold
))
675 (((class color
)) (:foreground
"cyan" :weight bold
))
677 "Face used to highlight compiler warnings."
681 (defface compilation-info
682 '((((class color
) (min-colors 16) (background light
))
683 (:foreground
"Green3" :weight bold
))
684 (((class color
) (min-colors 88) (background dark
))
685 (:foreground
"Green1" :weight bold
))
686 (((class color
) (min-colors 16) (background dark
))
687 (:foreground
"Green" :weight bold
))
688 (((class color
)) (:foreground
"green" :weight bold
))
690 "Face used to highlight compiler information."
694 (defface compilation-line-number
695 '((t :inherit font-lock-variable-name-face
))
696 "Face for displaying line numbers in compiler messages."
700 (defface compilation-column-number
701 '((t :inherit font-lock-type-face
))
702 "Face for displaying column numbers in compiler messages."
706 (defcustom compilation-message-face
'underline
707 "Face name to use for whole messages.
708 Faces `compilation-error-face', `compilation-warning-face',
709 `compilation-info-face', `compilation-line-face' and
710 `compilation-column-face' get prepended to this, when applicable."
715 (defvar compilation-error-face
'compilation-error
716 "Face name to use for file name in error messages.")
718 (defvar compilation-warning-face
'compilation-warning
719 "Face name to use for file name in warning messages.")
721 (defvar compilation-info-face
'compilation-info
722 "Face name to use for file name in informational messages.")
724 (defvar compilation-line-face
'compilation-line-number
725 "Face name to use for line numbers in compiler messages.")
727 (defvar compilation-column-face
'compilation-column-number
728 "Face name to use for column numbers in compiler messages.")
730 ;; same faces as dired uses
731 (defvar compilation-enter-directory-face
'font-lock-function-name-face
732 "Face name to use for entering directory messages.")
734 (defvar compilation-leave-directory-face
'font-lock-type-face
735 "Face name to use for leaving directory messages.")
739 ;; Used for compatibility with the old compile.el.
740 (defvaralias 'compilation-last-buffer
'next-error-last-buffer
)
741 (defvar compilation-parsing-end
(make-marker))
742 (defvar compilation-parse-errors-function nil
)
743 (defvar compilation-error-list nil
)
744 (defvar compilation-old-error-list nil
)
746 (defcustom compilation-auto-jump-to-first-error nil
747 "If non-nil, automatically jump to the first error during compilation."
752 (defvar compilation-auto-jump-to-next nil
753 "If non-nil, automatically jump to the next error encountered.")
754 (make-variable-buffer-local 'compilation-auto-jump-to-next
)
756 (defvar compilation-buffer-modtime nil
757 "The buffer modification time, for buffers not associated with files.")
758 (make-variable-buffer-local 'compilation-buffer-modtime
)
760 (defvar compilation-skip-to-next-location t
761 "*If non-nil, skip multiple error messages for the same source location.")
763 (defcustom compilation-skip-threshold
1
764 "Compilation motion commands skip less important messages.
765 The value can be either 2 -- skip anything less than error, 1 --
766 skip anything less than warning or 0 -- don't skip any messages.
767 Note that all messages not positively identified as warning or
768 info, are considered errors."
769 :type
'(choice (const :tag
"Warnings and info" 2)
770 (const :tag
"Info" 1)
771 (const :tag
"None" 0))
775 (defcustom compilation-skip-visited nil
776 "Compilation motion commands skip visited messages if this is t.
777 Visited messages are ones for which the file, line and column have been jumped
778 to from the current content in the current compilation buffer, even if it was
779 from a different message."
784 (defun compilation-face (type)
785 (or (and (car type
) (match-end (car type
)) compilation-warning-face
)
786 (and (cdr type
) (match-end (cdr type
)) compilation-info-face
)
787 compilation-error-face
))
789 ;; Internal function for calculating the text properties of a directory
790 ;; change message. The directory property is important, because it is
791 ;; the stack of nested enter-messages. Relative filenames on the following
792 ;; lines are relative to the top of the stack.
793 (defun compilation-directory-properties (idx leave
)
794 (if leave
(setq leave
(match-end leave
)))
795 ;; find previous stack, and push onto it, or if `leave' pop it
796 (let ((dir (previous-single-property-change (point) 'directory
)))
797 (setq dir
(if dir
(or (get-text-property (1- dir
) 'directory
)
798 (get-text-property dir
'directory
))))
800 compilation-leave-directory-face
801 compilation-enter-directory-face
)
804 '(nil)) ; nil only isn't a property-change
805 (cons (match-string-no-properties idx
) dir
))
807 keymap compilation-button-map
808 help-echo
"mouse-2: visit destination directory")))
810 ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
811 ;; KEY element from the ALIST, creating it in the right position if not already
812 ;; present. ALIST structure is
813 ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
814 ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
815 ;; may be nil. The other KEYs are ordered backwards so that growing line
816 ;; numbers can be inserted in front and searching can abort after half the
818 (eval-when-compile ;Don't keep it at runtime if not needed.
819 (defmacro compilation-assq
(key alist
)
822 (car (if (if (null ,key
)
823 (if l2
(null (caar l2
)))
824 (while (if l2
(if (caar l2
) (< ,key
(caar l2
)) t
))
827 (if l2
(eq ,key
(caar l2
))))
829 (setcdr l1
(cons (list ,key
) l2
)))))))
831 (defun compilation-auto-jump (buffer pos
)
832 (with-current-buffer buffer
834 (let ((win (get-buffer-window buffer
0)))
835 (if win
(set-window-point win pos
)))
836 (if compilation-auto-jump-to-first-error
837 (compile-goto-error))))
839 ;; This function is the central driver, called when font-locking to gather
840 ;; all information needed to later jump to corresponding source code.
841 ;; Return a property list with all meta information on this error location.
843 (defun compilation-error-properties (file line end-line col end-col type fmt
)
844 (unless (< (next-single-property-change (match-beginning 0)
845 'directory nil
(point))
849 (setq file
(funcall file
))
851 (setq file
(match-string-no-properties file
))
852 (unless (file-name-absolute-p file
)
853 (setq dir
(previous-single-property-change (point) 'directory
)
854 dir
(if dir
(or (get-text-property (1- dir
) 'directory
)
855 (get-text-property dir
'directory
)))))
856 (setq file
(cons file
(car dir
)))))
857 ;; This message didn't mention one, get it from previous
859 ;; Find the previous message.
860 (previous-single-property-change (point) 'message
)))
862 ;; Get the file structure that belongs to it.
864 (or (get-text-property (1- prev-pos
) 'message
)
865 (get-text-property prev-pos
'message
)))
867 (car (nth 2 (car prev
)))))
868 ;; Construct FILE . DIR from that.
870 (setq file
(cons (car prev-struct
)
871 (cadr prev-struct
))))))
873 (setq file
'("*unknown*")))))
874 ;; All of these fields are optional, get them only if we have an index, and
875 ;; it matched some part of the message.
877 (setq line
(match-string-no-properties line
))
878 (setq line
(string-to-number line
)))
880 (setq end-line
(match-string-no-properties end-line
))
881 (setq end-line
(string-to-number end-line
)))
884 (setq col
(funcall col
))
886 (setq col
(match-string-no-properties col
))
887 (setq col
(- (string-to-number col
) compilation-first-column
)))))
888 (if (and end-col
(functionp end-col
))
889 (setq end-col
(funcall end-col
))
890 (if (and end-col
(setq end-col
(match-string-no-properties end-col
)))
891 (setq end-col
(- (string-to-number end-col
) compilation-first-column -
1))
892 (if end-line
(setq end-col -
1))))
893 (if (consp type
) ; not a static type, check what it is.
894 (setq type
(or (and (car type
) (match-end (car type
)) 1)
895 (and (cdr type
) (match-end (cdr type
)) 0)
898 (when (and compilation-auto-jump-to-next
899 (>= type compilation-skip-threshold
))
900 (kill-local-variable 'compilation-auto-jump-to-next
)
901 (run-with-timer 0 nil
'compilation-auto-jump
902 (current-buffer) (match-beginning 0)))
904 (compilation-internal-error-properties file line end-line col end-col type fmt
)))
906 (defun compilation-move-to-column (col screen
)
907 "Go to column COL on the current line.
908 If SCREEN is non-nil, columns are screen columns, otherwise, they are
911 (move-to-column (max col
0))
912 (goto-char (min (+ (line-beginning-position) col
) (line-end-position)))))
914 (defun compilation-internal-error-properties (file line end-line col end-col type fmts
)
915 "Get the meta-info that will be added as text-properties.
916 LINE, END-LINE, COL, END-COL are integers or nil.
917 TYPE can be 0, 1, or 2, meaning error, warning, or just info.
918 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
919 FMTS is a list of format specs for transforming the file name.
920 (See `compilation-error-regexp-alist'.)"
921 (unless file
(setq file
'("*unknown*")))
922 (let* ((file-struct (compilation-get-file-structure file fmts
))
923 ;; Get first already existing marker (if any has one, all have one).
924 ;; Do this first, as the compilation-assq`s may create new nodes.
925 (marker-line (car (cddr file-struct
))) ; a line structure
926 (marker (nth 3 (cadr marker-line
))) ; its marker
927 (compilation-error-screen-columns compilation-error-screen-columns
)
928 end-marker loc end-loc
)
929 (if (not (and marker
(marker-buffer marker
)))
930 (setq marker nil
) ; no valid marker for this file
931 (setq loc
(or line
1)) ; normalize no linenumber to line 1
932 (catch 'marker
; find nearest loc, at least one exists
933 (dolist (x (nthcdr 3 file-struct
)) ; loop over remaining lines
934 (if (> (car x
) loc
) ; still bigger
936 (if (> (- (or (car marker-line
) 1) loc
)
937 (- loc
(car x
))) ; current line is nearer
938 (setq marker-line x
))
940 (setq marker
(nth 3 (cadr marker-line
))
941 marker-line
(or (car marker-line
) 1))
942 (with-current-buffer (marker-buffer marker
)
946 (goto-char (marker-position marker
))
947 (when (or end-col end-line
)
948 (beginning-of-line (- (or end-line line
) marker-line -
1))
949 (if (or (null end-col
) (< end-col
0))
951 (compilation-move-to-column
952 end-col compilation-error-screen-columns
))
953 (setq end-marker
(list (point-marker))))
954 (beginning-of-line (if end-line
956 (- loc marker-line -
1)))
958 (compilation-move-to-column
959 col compilation-error-screen-columns
)
960 (forward-to-indentation 0))
961 (setq marker
(list (point-marker)))))))
963 (setq loc
(compilation-assq line
(cdr file-struct
)))
965 (setq end-loc
(compilation-assq end-line
(cdr file-struct
))
966 end-loc
(compilation-assq end-col end-loc
))
967 (if end-col
; use same line element
968 (setq end-loc
(compilation-assq end-col loc
))))
969 (setq loc
(compilation-assq col loc
))
970 ;; If they are new, make the loc(s) reference the file they point to.
971 (or (cdr loc
) (setcdr loc
`(,line
,file-struct
,@marker
)))
974 (setcdr end-loc
`(,(or end-line line
) ,file-struct
,@end-marker
))))
976 ;; Must start with face
977 `(face ,compilation-message-face
978 message
(,loc
,type
,end-loc
)
979 ,@(if compilation-debug
980 `(debug (,(assoc (with-no-warnings matcher
) font-lock-keywords
)
983 "mouse-2: visit this file, line and column"
985 "mouse-2: visit this file and line"
986 "mouse-2: visit this file"))
987 keymap compilation-button-map
988 mouse-face highlight
)))
990 (defun compilation-mode-font-lock-keywords ()
991 "Return expressions to highlight in Compilation mode."
992 (if compilation-parse-errors-function
993 ;; An old package! Try the compatibility code.
994 '((compilation-compat-parse-errors))
996 ;; make directory tracking
997 (if compilation-directory-matcher
998 `((,(car compilation-directory-matcher
)
999 ,@(mapcar (lambda (elt)
1001 (compilation-directory-properties
1002 ,(car elt
) ,(cdr elt
))
1004 (cdr compilation-directory-matcher
)))))
1006 ;; Compiler warning/error lines.
1010 (setq item
(cdr (assq item
1011 compilation-error-regexp-alist-alist
))))
1012 (let ((file (nth 1 item
))
1017 end-line end-col fmt
)
1018 ;; omake reports some error indented, so skip the indentation.
1019 ;; another solution is to modify (some?) regexps in
1020 ;; `compilation-error-regexp-alist'.
1021 ;; note that omake usage is not limited to ocaml and C (for stubs).
1022 (when (and (= ?^
(aref pat
0)) ; anchored: starts with "^"
1023 ;; but does not allow an arbitrary number of leading spaces
1024 (not (and (= ?
(aref pat
1)) (= ?
* (aref pat
2)))))
1025 (setq pat
(concat "^ *" (substring pat
1))))
1026 (if (consp file
) (setq fmt
(cdr file
) file
(car file
)))
1027 (if (consp line
) (setq end-line
(cdr line
) line
(car line
)))
1028 (if (consp col
) (setq end-col
(cdr col
) col
(car col
)))
1030 (if (functionp line
)
1031 ;; The old compile.el had here an undocumented hook that
1032 ;; allowed `line' to be a function that computed the actual
1033 ;; error location. Let's do our best.
1036 (compilation-compat-error-properties
1037 (funcall ',line
(cons (match-string ,file
)
1038 (cons default-directory
1040 ,(if col
`(match-string ,col
))))))
1041 (,file compilation-error-face t
))
1043 (unless (or (null (nth 5 item
)) (integerp (nth 5 item
)))
1044 (error "HYPERLINK should be an integer: %s" (nth 5 item
)))
1048 ,@(when (integerp file
)
1049 `((,file
,(if (consp type
)
1050 `(compilation-face ',type
)
1051 (aref [compilation-info-face
1052 compilation-warning-face
1053 compilation-error-face
]
1057 `((,line compilation-line-face nil t
)))
1059 `((,end-line compilation-line-face nil t
)))
1061 ,@(when (integerp col
)
1062 `((,col compilation-column-face nil t
)))
1063 ,@(when (integerp end-col
)
1064 `((,end-col compilation-column-face nil t
)))
1067 (,(or (nth 5 item
) 0)
1068 (compilation-error-properties ',file
,line
,end-line
1069 ,col
,end-col
',(or type
2)
1071 append
))))) ; for compilation-message-face
1072 compilation-error-regexp-alist
)
1074 compilation-mode-font-lock-keywords
)))
1076 (defun compilation-read-command (command)
1077 (read-shell-command "Compile command: " command
1078 (if (equal (car compile-history
) command
)
1079 '(compile-history .
1)
1084 (defun compile (command &optional comint
)
1085 "Compile the program including the current buffer. Default: run `make'.
1086 Runs COMMAND, a shell command, in a separate process asynchronously
1087 with output going to the buffer `*compilation*'.
1089 You can then use the command \\[next-error] to find the next error message
1090 and move to the source code that caused it.
1092 If optional second arg COMINT is t the buffer will be in Comint mode with
1093 `compilation-shell-minor-mode'.
1095 Interactively, prompts for the command if `compilation-read-command' is
1096 non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
1097 Additionally, with universal prefix arg, compilation buffer will be in
1098 comint mode, i.e. interactive.
1100 To run more than one compilation at once, start one then rename
1101 the \`*compilation*' buffer to some other name with
1102 \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
1103 It will create a new \`*compilation*' buffer.
1105 On most systems, termination of the main compilation process
1106 kills its subprocesses.
1108 The name used for the buffer is actually whatever is returned by
1109 the function in `compilation-buffer-name-function', so you can set that
1110 to a function that generates a unique name."
1113 (let ((command (eval compile-command
)))
1114 (if (or compilation-read-command current-prefix-arg
)
1115 (compilation-read-command command
)
1117 (consp current-prefix-arg
)))
1118 (unless (equal command
(eval compile-command
))
1119 (setq compile-command command
))
1120 (save-some-buffers (not compilation-ask-about-save
)
1121 compilation-save-buffers-predicate
)
1122 (setq-default compilation-directory default-directory
)
1123 (compilation-start command comint
))
1125 ;; run compile with the default command line
1126 (defun recompile (&optional edit-command
)
1127 "Re-compile the program including the current buffer.
1128 If this is run in a Compilation mode buffer, re-use the arguments from the
1129 original use. Otherwise, recompile using `compile-command'.
1130 If the optional argument `edit-command' is non-nil, the command can be edited."
1132 (save-some-buffers (not compilation-ask-about-save
)
1133 compilation-save-buffers-predicate
)
1134 (let ((default-directory (or compilation-directory default-directory
)))
1136 (setcar compilation-arguments
1137 (compilation-read-command (car compilation-arguments
))))
1138 (apply 'compilation-start
(or compilation-arguments
1139 `(,(eval compile-command
))))))
1141 (defcustom compilation-scroll-output nil
1142 "Non-nil to scroll the *compilation* buffer window as output appears.
1144 Setting it causes the Compilation mode commands to put point at the
1145 end of their output window so that the end of the output is always
1146 visible rather than the beginning.
1148 The value `first-error' stops scrolling at the first error, and leaves
1149 point on its location in the *compilation* buffer."
1150 :type
'(choice (const :tag
"No scrolling" nil
)
1151 (const :tag
"Scroll compilation output" t
)
1152 (const :tag
"Stop scrolling at the first error" first-error
))
1154 :group
'compilation
)
1157 (defun compilation-buffer-name (mode-name mode-command name-function
)
1158 "Return the name of a compilation buffer to use.
1159 If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
1160 to determine the buffer name.
1161 Likewise if `compilation-buffer-name-function' is non-nil.
1162 If current buffer has the major mode MODE-COMMAND,
1163 return the name of the current buffer, so that it gets reused.
1164 Otherwise, construct a buffer name from MODE-NAME."
1165 (cond (name-function
1166 (funcall name-function mode-name
))
1167 (compilation-buffer-name-function
1168 (funcall compilation-buffer-name-function mode-name
))
1169 ((eq mode-command major-mode
)
1172 (concat "*" (downcase mode-name
) "*"))))
1174 ;; This is a rough emulation of the old hack, until the transition to new
1175 ;; compile is complete.
1176 (defun compile-internal (command error-message
1177 &optional name-of-mode parser
1178 error-regexp-alist name-function
1179 enter-regexp-alist leave-regexp-alist
1180 file-regexp-alist nomessage-regexp-alist
1181 no-async highlight-regexp local-map
)
1183 (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
1184 (let ((compilation-error-regexp-alist
1185 (append file-regexp-alist
(or error-regexp-alist
1186 compilation-error-regexp-alist
)))
1187 (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
1188 "\\1" error-message
)))
1189 (compilation-start command nil name-function highlight-regexp
)))
1190 (make-obsolete 'compile-internal
'compilation-start
"22.1")
1193 (defun compilation-start (command &optional mode name-function highlight-regexp
)
1194 "Run compilation command COMMAND (low level interface).
1195 If COMMAND starts with a cd command, that becomes the `default-directory'.
1196 The rest of the arguments are optional; for them, nil means use the default.
1198 MODE is the major mode to set in the compilation buffer. Mode
1199 may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
1201 If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
1202 to determine the buffer name. Otherwise, the default is to
1203 reuses the current buffer if it has the proper major mode,
1204 else use or create a buffer with name based on the major mode.
1206 If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
1207 the matching section of the visited source line; the default is to use the
1208 global value of `compilation-highlight-regexp'.
1210 Returns the compilation buffer created."
1211 (or mode
(setq mode
'compilation-mode
))
1212 (let* ((name-of-mode
1215 (replace-regexp-in-string "-mode$" "" (symbol-name mode
))))
1216 (thisdir default-directory
)
1218 (with-current-buffer
1221 (compilation-buffer-name name-of-mode mode name-function
)))
1222 (let ((comp-proc (get-buffer-process (current-buffer))))
1224 (if (or (not (eq (process-status comp-proc
) 'run
))
1226 (format "A %s process is running; kill it? "
1230 (interrupt-process comp-proc
)
1232 (delete-process comp-proc
))
1234 (error "Cannot have two processes in `%s' at once"
1236 ;; first transfer directory from where M-x compile was called
1237 (setq default-directory thisdir
)
1238 ;; Make compilation buffer read-only. The filter can still write it.
1239 ;; Clear out the compilation buffer.
1240 (let ((inhibit-read-only t
)
1241 (default-directory thisdir
))
1242 ;; Then evaluate a cd command if any, but don't perform it yet, else
1243 ;; start-command would do it again through the shell: (cd "..") AND
1244 ;; sh -c "cd ..; make"
1245 (cd (if (string-match "\\`\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]"
1248 (substitute-env-vars (match-string 1 command
))
1252 ;; Select the desired mode.
1253 (if (not (eq mode t
))
1255 (buffer-disable-undo)
1257 (setq buffer-read-only nil
)
1258 (with-no-warnings (comint-mode))
1259 (compilation-shell-minor-mode))
1260 ;; Remember the original dir, so we can use it when we recompile.
1261 ;; default-directory' can't be used reliably for that because it may be
1262 ;; affected by the special handling of "cd ...;".
1263 ;; NB: must be fone after (funcall mode) as that resets local variables
1264 (set (make-local-variable 'compilation-directory
) thisdir
)
1265 (if highlight-regexp
1266 (set (make-local-variable 'compilation-highlight-regexp
)
1268 (if (or compilation-auto-jump-to-first-error
1269 (eq compilation-scroll-output
'first-error
))
1270 (set (make-local-variable 'compilation-auto-jump-to-next
) t
))
1271 ;; Output a mode setter, for saving and later reloading this buffer.
1272 (insert "-*- mode: " name-of-mode
1273 "; default-directory: "
1274 (prin1-to-string (abbreviate-file-name default-directory
))
1276 (format "%s started at %s\n\n"
1278 (substring (current-time-string) 0 19))
1280 (setq thisdir default-directory
))
1281 (set-buffer-modified-p nil
))
1282 ;; Pop up the compilation buffer.
1283 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html
1284 (setq outwin
(display-buffer outbuf
))
1285 (with-current-buffer outbuf
1286 (let ((process-environment
1288 compilation-environment
1289 (if (if (boundp 'system-uses-terminfo
) ; `if' for compiler warning
1290 system-uses-terminfo
)
1291 (list "TERM=dumb" "TERMCAP="
1292 (format "COLUMNS=%d" (window-width)))
1294 (format "TERMCAP=emacs:co#%d:tc=unknown:"
1296 ;; Set the EMACS variable, but
1297 ;; don't override users' setting of $EMACS.
1298 (unless (getenv "EMACS")
1300 (list "INSIDE_EMACS=t")
1301 (copy-sequence process-environment
))))
1302 (set (make-local-variable 'compilation-arguments
)
1303 (list command mode name-function highlight-regexp
))
1304 (set (make-local-variable 'revert-buffer-function
)
1305 'compilation-revert-buffer
)
1306 (set-window-start outwin
(point-min))
1308 ;; Position point as the user will see it.
1309 (let ((desired-visible-point
1310 ;; Put it at the end if `compilation-scroll-output' is set.
1311 (if compilation-scroll-output
1313 ;; Normally put it at the top.
1315 (if (eq outwin
(selected-window))
1316 (goto-char desired-visible-point
)
1317 (set-window-point outwin desired-visible-point
)))
1319 ;; The setup function is called before compilation-set-window-height
1320 ;; so it can set the compilation-window-height buffer locally.
1321 (if compilation-process-setup-function
1322 (funcall compilation-process-setup-function
))
1323 (compilation-set-window-height outwin
)
1324 ;; Start the compilation.
1325 (if (fboundp 'start-process
)
1328 ;; comint uses `start-file-process'.
1332 outbuf
(downcase mode-name
)
1333 (if (file-remote-p default-directory
)
1336 nil
`("-c" ,command
))))
1337 (start-file-process-shell-command (downcase mode-name
)
1339 ;; Make the buffer's mode line show process state.
1340 (setq mode-line-process
1341 (list (propertize ":%s" 'face
'compilation-warning
)))
1342 (set-process-sentinel proc
'compilation-sentinel
)
1344 ;; Keep the comint filter, since it's needed for proper handling
1346 (set-process-filter proc
'compilation-filter
))
1347 ;; Use (point-max) here so that output comes in
1348 ;; after the initial text,
1349 ;; regardless of where the user sees point.
1350 (set-marker (process-mark proc
) (point-max) outbuf
)
1351 (when compilation-disable-input
1353 (process-send-eof proc
)
1354 ;; The process may have exited already.
1356 (run-hook-with-args 'compilation-start-hook proc
)
1357 (setq compilation-in-progress
1358 (cons proc compilation-in-progress
)))
1359 ;; No asynchronous processes available.
1360 (message "Executing `%s'..." command
)
1361 ;; Fake modeline display as if `start-process' were run.
1362 (setq mode-line-process
1363 (list (propertize ":run" 'face
'compilation-warning
)))
1364 (force-mode-line-update)
1365 (sit-for 0) ; Force redisplay
1367 ;; Insert the output at the end, after the initial text,
1368 ;; regardless of where the user sees point.
1369 (goto-char (point-max))
1370 (let* ((buffer-read-only nil
) ; call-process needs to modify outbuf
1371 (status (call-process shell-file-name nil outbuf nil
"-c"
1373 (cond ((numberp status
)
1374 (compilation-handle-exit
1378 (format "exited abnormally with code %d\n" status
))))
1380 (compilation-handle-exit 'signal status
1381 (concat status
"\n")))
1383 (compilation-handle-exit 'bizarre status status
)))))
1384 ;; Without async subprocesses, the buffer is not yet
1385 ;; fontified, so fontify it now.
1386 (let ((font-lock-verbose nil
)) ; shut up font-lock messages
1387 (font-lock-fontify-buffer))
1388 (set-buffer-modified-p nil
)
1389 (message "Executing `%s'...done" command
)))
1390 ;; Now finally cd to where the shell started make/grep/...
1391 (setq default-directory thisdir
)
1392 ;; The following form selected outwin ever since revision 1.183,
1393 ;; so possibly messing up point in some other window (bug#1073).
1394 ;; Moved into the scope of with-current-buffer, though still with
1395 ;; complete disregard for the case when compilation-scroll-output
1396 ;; equals 'first-error (martin 2008-10-04).
1397 (when compilation-scroll-output
1398 (goto-char (point-max))))
1400 ;; Make it so the next C-x ` will use this buffer.
1401 (setq next-error-last-buffer outbuf
)))
1403 (defun compilation-set-window-height (window)
1404 "Set the height of WINDOW according to `compilation-window-height'."
1405 (let ((height (buffer-local-value 'compilation-window-height
(window-buffer window
))))
1407 (window-full-width-p window
)
1408 ;; If window is alone in its frame, aside from a minibuffer,
1409 ;; don't change its height.
1410 (not (eq window
(frame-root-window (window-frame window
))))
1411 ;; Stef said that doing the saves in this order is safer:
1413 (save-selected-window
1414 (select-window window
)
1415 (enlarge-window (- height
(window-height))))))))
1417 (defvar compilation-menu-map
1418 (let ((map (make-sparse-keymap "Errors"))
1419 (opt-map (make-sparse-keymap "Skip")))
1420 (define-key map
[stop-subjob
]
1421 '(menu-item "Stop Compilation" kill-compilation
1422 :help
"Kill the process made by the M-x compile or M-x grep commands"))
1423 (define-key map
[compilation-mode-separator3
]
1425 (define-key map
[compilation-next-error-follow-minor-mode
]
1427 "Auto Error Display" next-error-follow-minor-mode
1428 :help
"Display the error under cursor when moving the cursor"
1429 :button
(:toggle . next-error-follow-minor-mode
)))
1430 (define-key map
[compilation-skip
]
1431 (cons "Skip Less Important Messages" opt-map
))
1432 (define-key opt-map
[compilation-skip-none
]
1433 '(menu-item "Don't Skip Any Messages"
1436 (customize-set-variable 'compilation-skip-threshold
0))
1437 :help
"Do not skip any type of messages"
1438 :button
(:radio .
(eq compilation-skip-threshold
0))))
1439 (define-key opt-map
[compilation-skip-info
]
1440 '(menu-item "Skip Info"
1443 (customize-set-variable 'compilation-skip-threshold
1))
1444 :help
"Skip anything less than warning"
1445 :button
(:radio .
(eq compilation-skip-threshold
1))))
1446 (define-key opt-map
[compilation-skip-warning-and-info
]
1447 '(menu-item "Skip Warnings and Info"
1450 (customize-set-variable 'compilation-skip-threshold
2))
1451 :help
"Skip over Warnings and Info, stop for errors"
1452 :button
(:radio .
(eq compilation-skip-threshold
2))))
1453 (define-key map
[compilation-mode-separator2
]
1455 (define-key map
[compilation-first-error
]
1456 '(menu-item "First Error" first-error
1457 :help
"Restart at the first error, visit corresponding source code"))
1458 (define-key map
[compilation-previous-error
]
1459 '(menu-item "Previous Error" previous-error
1460 :help
"Visit previous `next-error' message and corresponding source code"))
1461 (define-key map
[compilation-next-error
]
1462 '(menu-item "Next Error" next-error
1463 :help
"Visit next `next-error' message and corresponding source code"))
1466 (defvar compilation-minor-mode-map
1467 (let ((map (make-sparse-keymap)))
1468 (define-key map
[mouse-2
] 'compile-goto-error
)
1469 (define-key map
[follow-link
] 'mouse-face
)
1470 (define-key map
"\C-c\C-c" 'compile-goto-error
)
1471 (define-key map
"\C-m" 'compile-goto-error
)
1472 (define-key map
"\C-c\C-k" 'kill-compilation
)
1473 (define-key map
"\M-n" 'compilation-next-error
)
1474 (define-key map
"\M-p" 'compilation-previous-error
)
1475 (define-key map
"\M-{" 'compilation-previous-file
)
1476 (define-key map
"\M-}" 'compilation-next-file
)
1477 (define-key map
"g" 'recompile
) ; revert
1478 (define-key map
"q" 'quit-window
)
1479 ;; Set up the menu-bar
1480 (define-key map
[menu-bar compilation
]
1481 (cons "Errors" compilation-menu-map
))
1483 "Keymap for `compilation-minor-mode'.")
1485 (defvar compilation-shell-minor-mode-map
1486 (let ((map (make-sparse-keymap)))
1487 (define-key map
"\M-\C-m" 'compile-goto-error
)
1488 (define-key map
"\M-\C-n" 'compilation-next-error
)
1489 (define-key map
"\M-\C-p" 'compilation-previous-error
)
1490 (define-key map
"\M-{" 'compilation-previous-file
)
1491 (define-key map
"\M-}" 'compilation-next-file
)
1492 ;; Set up the menu-bar
1493 (define-key map
[menu-bar compilation
]
1494 (cons "Errors" compilation-menu-map
))
1496 "Keymap for `compilation-shell-minor-mode'.")
1498 (defvar compilation-button-map
1499 (let ((map (make-sparse-keymap)))
1500 (define-key map
[mouse-2
] 'compile-goto-error
)
1501 (define-key map
[follow-link
] 'mouse-face
)
1502 (define-key map
"\C-m" 'compile-goto-error
)
1504 "Keymap for compilation-message buttons.")
1505 (fset 'compilation-button-map compilation-button-map
)
1507 (defvar compilation-mode-map
1508 (let ((map (make-sparse-keymap)))
1509 ;; Don't inherit from compilation-minor-mode-map,
1510 ;; because that introduces a menu bar item we don't want.
1511 ;; That confuses C-down-mouse-3.
1512 (define-key map
[mouse-2
] 'compile-goto-error
)
1513 (define-key map
[follow-link
] 'mouse-face
)
1514 (define-key map
"\C-c\C-c" 'compile-goto-error
)
1515 (define-key map
"\C-m" 'compile-goto-error
)
1516 (define-key map
"\C-c\C-k" 'kill-compilation
)
1517 (define-key map
"\M-n" 'compilation-next-error
)
1518 (define-key map
"\M-p" 'compilation-previous-error
)
1519 (define-key map
"\M-{" 'compilation-previous-file
)
1520 (define-key map
"\M-}" 'compilation-next-file
)
1521 (define-key map
"\t" 'compilation-next-error
)
1522 (define-key map
[backtab] 'compilation-previous-error)
1523 (define-key map "g" 'recompile) ; revert
1524 (define-key map "q" 'quit-window)
1526 (define-key map " " 'scroll-up)
1527 (define-key map "\^?" 'scroll-down)
1528 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
1530 ;; Set up the menu-bar
1531 (let ((submap (make-sparse-keymap "Compile")))
1532 (define-key map [menu-bar compilation]
1533 (cons "Compile" submap))
1534 (set-keymap-parent submap compilation-menu-map))
1535 (define-key map [menu-bar compilation compilation-separator2]
1537 (define-key map [menu-bar compilation compilation-grep]
1538 '(menu-item "Search Files (grep)..." grep
1539 :help "Run grep, with user-specified args, and collect output in a buffer"))
1540 (define-key map [menu-bar compilation compilation-recompile]
1541 '(menu-item "Recompile" recompile
1542 :help "Re-compile the program including the current buffer"))
1543 (define-key map [menu-bar compilation compilation-compile]
1544 '(menu-item "Compile..." compile
1545 :help "Compile the program including the current buffer. Default: run `make'"))
1547 "Keymap for compilation log buffers.
1548 `compilation-minor-mode-map' is a parent of this.")
1550 (defvar compilation-mode-tool-bar-map
1551 ;; When bootstrapping, tool-bar-map is not properly initialized yet,
1552 ;; so don't do anything.
1553 (when (keymapp (butlast tool-bar-map))
1554 (let ((map (butlast (copy-keymap tool-bar-map)))
1555 (help (last tool-bar-map))) ;; Keep Help last in tool bar
1556 (tool-bar-local-item
1557 "left-arrow" 'previous-error-no-select 'previous-error-no-select map
1559 :help "Goto previous error")
1560 (tool-bar-local-item
1561 "right-arrow" 'next-error-no-select 'next-error-no-select map
1563 :help "Goto next error")
1564 (tool-bar-local-item
1565 "cancel" 'kill-compilation 'kill-compilation map
1566 :enable '(let ((buffer (compilation-find-buffer)))
1567 (get-buffer-process buffer))
1568 :help "Stop compilation")
1569 (tool-bar-local-item
1570 "refresh" 'recompile 'recompile map
1571 :help "Restart compilation")
1572 (append map help))))
1574 (put 'compilation-mode 'mode-class 'special)
1577 (defun compilation-mode (&optional name-of-mode)
1578 "Major mode for compilation log buffers.
1579 \\<compilation-mode-map>To visit the source for a line-numbered error,
1580 move point to the error message line and type \\[compile-goto-error].
1581 To kill the compilation, type \\[kill-compilation].
1583 Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
1585 \\{compilation-mode-map}"
1587 (kill-all-local-variables)
1588 (use-local-map compilation-mode-map)
1589 ;; Let windows scroll along with the output.
1590 (set (make-local-variable 'window-point-insertion-type) t)
1591 (set (make-local-variable 'tool-bar-map) compilation-mode-tool-bar-map)
1592 (setq major-mode 'compilation-mode
1593 mode-name (or name-of-mode "Compilation"))
1594 (set (make-local-variable 'page-delimiter)
1595 compilation-page-delimiter)
1596 (set (make-local-variable 'compilation-buffer-modtime) nil)
1598 (setq buffer-read-only t)
1599 (run-mode-hooks 'compilation-mode-hook))
1601 (defmacro define-compilation-mode (mode name doc &rest body)
1602 "This is like `define-derived-mode' without the PARENT argument.
1603 The parent is always `compilation-mode' and the customizable `compilation-...'
1604 variables are also set from the name of the mode you have chosen,
1605 by replacing the first word, e.g `compilation-scroll-output' from
1606 `grep-scroll-output' if that variable exists."
1607 (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
1608 `(define-derived-mode ,mode compilation-mode ,name
1610 ,@(mapcar (lambda (v)
1612 (intern-soft (replace-regexp-in-string
1613 "^compilation" mode-name
1616 (or (boundp (cdr v))
1617 (if (boundp 'byte-compile-bound-variables)
1618 (memq (cdr v) byte-compile-bound-variables)))
1619 `(set (make-local-variable ',(car v)) ,(cdr v))))
1620 '(compilation-buffer-name-function
1621 compilation-directory-matcher
1623 compilation-error-regexp-alist
1624 compilation-error-regexp-alist-alist
1625 compilation-error-screen-columns
1626 compilation-finish-function
1627 compilation-finish-functions
1628 compilation-first-column
1629 compilation-mode-font-lock-keywords
1630 compilation-page-delimiter
1631 compilation-parse-errors-filename-function
1632 compilation-process-setup-function
1633 compilation-scroll-output
1634 compilation-search-path
1635 compilation-skip-threshold
1636 compilation-window-height))
1639 (defun compilation-revert-buffer (ignore-auto noconfirm)
1640 (if buffer-file-name
1641 (let (revert-buffer-function)
1642 (revert-buffer ignore-auto noconfirm))
1643 (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
1644 (apply 'compilation-start compilation-arguments))))
1646 (defvar compilation-current-error nil
1647 "Marker to the location from where the next error will be found.
1648 The global commands next/previous/first-error/goto-error use this.")
1650 (defvar compilation-messages-start nil
1651 "Buffer position of the beginning of the compilation messages.
1652 If nil, use the beginning of buffer.")
1654 ;; A function name can't be a hook, must be something with a value.
1655 (defconst compilation-turn-on-font-lock 'turn-on-font-lock)
1657 (defun compilation-setup (&optional minor)
1658 "Prepare the buffer for the compilation parsing commands to work.
1659 Optional argument MINOR indicates this is called from
1660 `compilation-minor-mode'."
1661 (make-local-variable 'compilation-current-error)
1662 (make-local-variable 'compilation-messages-start)
1663 (make-local-variable 'compilation-error-screen-columns)
1664 (make-local-variable 'overlay-arrow-position)
1665 (set (make-local-variable 'overlay-arrow-string) "")
1666 (setq next-error-overlay-arrow-position nil)
1667 (add-hook 'kill-buffer-hook
1668 (lambda () (setq next-error-overlay-arrow-position nil)) nil t)
1669 ;; Note that compilation-next-error-function is for interfacing
1670 ;; with the next-error function in simple.el, and it's only
1671 ;; coincidentally named similarly to compilation-next-error.
1672 (setq next-error-function 'compilation-next-error-function)
1673 (set (make-local-variable 'comint-file-name-prefix)
1674 (or (file-remote-p default-directory) ""))
1675 (set (make-local-variable 'font-lock-extra-managed-props)
1676 '(directory message help-echo mouse-face debug))
1677 (set (make-local-variable 'compilation-locs)
1678 (make-hash-table :test 'equal :weakness 'value))
1679 ;; lazy-lock would never find the message unless it's scrolled to.
1680 ;; jit-lock might fontify some things too late.
1681 (set (make-local-variable 'font-lock-support-mode) nil)
1682 (set (make-local-variable 'font-lock-maximum-size) nil)
1684 (let ((fld font-lock-defaults))
1685 (font-lock-add-keywords nil (compilation-mode-font-lock-keywords))
1688 (font-lock-fontify-buffer)
1689 (font-lock-change-mode)
1690 (turn-on-font-lock))
1691 (turn-on-font-lock)))
1692 (setq font-lock-defaults '(compilation-mode-font-lock-keywords t))
1693 ;; maybe defer font-lock till after derived mode is set up
1694 (run-mode-hooks 'compilation-turn-on-font-lock)))
1697 (define-minor-mode compilation-shell-minor-mode
1698 "Toggle compilation shell minor mode.
1699 With arg, turn compilation mode on if and only if arg is positive.
1700 In this minor mode, all the error-parsing commands of the
1701 Compilation major mode are available but bound to keys that don't
1702 collide with Shell mode. See `compilation-mode'.
1703 Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
1704 nil " Shell-Compile"
1706 (if compilation-shell-minor-mode
1707 (compilation-setup t)
1708 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1709 (font-lock-fontify-buffer)))
1712 (define-minor-mode compilation-minor-mode
1713 "Toggle compilation minor mode.
1714 With arg, turn compilation mode on if and only if arg is positive.
1715 In this minor mode, all the error-parsing commands of the
1716 Compilation major mode are available. See `compilation-mode'.
1717 Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
1720 (if compilation-minor-mode
1721 (compilation-setup t)
1722 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1723 (font-lock-fontify-buffer)))
1725 (defun compilation-handle-exit (process-status exit-status msg)
1726 "Write MSG in the current buffer and hack its `mode-line-process'."
1727 (let ((inhibit-read-only t)
1728 (status (if compilation-exit-message-function
1729 (funcall compilation-exit-message-function
1730 process-status exit-status msg)
1731 (cons msg exit-status)))
1734 (cur-buffer (current-buffer)))
1735 ;; Record where we put the message, so we can ignore it later on.
1737 (insert ?\n mode-name " " (car status))
1738 (if (and (numberp compilation-window-height)
1739 (zerop compilation-window-height))
1740 (message "%s" (cdr status)))
1743 (insert " at " (substring (current-time-string) 0 19))
1744 (goto-char (point-max))
1745 ;; Prevent that message from being recognized as a compilation error.
1746 (add-text-properties omax (point)
1747 (append '(compilation-handle-exit t) nil))
1748 (setq mode-line-process
1749 (let ((out-string (format ":%s [%s]" process-status (cdr status)))
1750 (msg (format "%s %s" mode-name
1751 (replace-regexp-in-string "\n?$" "" (car status)))))
1753 (propertize out-string
1754 'help-echo msg 'face (if (> exit-status 0)
1756 'compilation-info))))
1757 ;; Force mode line redisplay soon.
1758 (force-mode-line-update)
1759 (if (and opoint (< opoint omax))
1762 (if compilation-finish-function
1763 (funcall compilation-finish-function cur-buffer msg)))
1764 (run-hook-with-args 'compilation-finish-functions cur-buffer msg)))
1766 ;; Called when compilation process changes state.
1767 (defun compilation-sentinel (proc msg)
1768 "Sentinel for compilation buffers."
1769 (if (memq (process-status proc) '(exit signal))
1770 (let ((buffer (process-buffer proc)))
1771 (if (null (buffer-name buffer))
1773 (set-process-buffer proc nil)
1774 (with-current-buffer buffer
1775 ;; Write something in the compilation buffer
1776 ;; and hack its mode line.
1777 (compilation-handle-exit (process-status proc)
1778 (process-exit-status proc)
1780 ;; Since the buffer and mode line will show that the
1781 ;; process is dead, we can delete it now. Otherwise it
1782 ;; will stay around until M-x list-processes.
1783 (delete-process proc)))
1784 (setq compilation-in-progress (delq proc compilation-in-progress)))))
1786 (defun compilation-filter (proc string)
1787 "Process filter for compilation buffers.
1788 Just inserts the text,
1789 handles carriage motion (see `comint-inhibit-carriage-motion'),
1790 and runs `compilation-filter-hook'."
1791 (when (buffer-live-p (process-buffer proc))
1792 (with-current-buffer (process-buffer proc)
1793 (let ((inhibit-read-only t)
1794 ;; `save-excursion' doesn't use the right insertion-type for us.
1795 (pos (copy-marker (point) t))
1796 (min (point-min-marker))
1797 (max (point-max-marker)))
1800 ;; If we are inserting at the end of the accessible part
1801 ;; of the buffer, keep the inserted text visible.
1802 (set-marker-insertion-type max t)
1804 (goto-char (process-mark proc))
1805 ;; We used to use `insert-before-markers', so that windows with
1806 ;; point at `process-mark' scroll along with the output, but we
1807 ;; now use window-point-insertion-type instead.
1809 (unless comint-inhibit-carriage-motion
1810 (comint-carriage-motion (process-mark proc) (point)))
1811 (set-marker (process-mark proc) (point))
1812 (set (make-local-variable 'compilation-buffer-modtime) (current-time))
1813 (run-hooks 'compilation-filter-hook))
1815 (narrow-to-region min max)
1816 (set-marker min nil)
1817 (set-marker max nil))))))
1819 ;;; test if a buffer is a compilation buffer, assuming we're in the buffer
1820 (defsubst compilation-buffer-internal-p ()
1821 "Test if inside a compilation buffer."
1822 (local-variable-p 'compilation-locs))
1824 ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p
1825 (defsubst compilation-buffer-p (buffer)
1826 "Test if BUFFER is a compilation buffer."
1827 (with-current-buffer buffer
1828 (compilation-buffer-internal-p)))
1830 (defmacro compilation-loop (< property-change 1+ error limit)
1834 (or (setq pt (,property-change pt 'message))
1835 ;; Handle the case where where the first error message is
1836 ;; at the start of the buffer, and n < 0.
1837 (if (or (eq (get-text-property ,limit 'message)
1838 (get-text-property opt 'message))
1840 (error ,error compilation-error)
1842 ;; prop 'message usually has 2 changes, on and off, so
1844 (or (setq msg (get-text-property pt 'message))
1845 (if (setq pt (,property-change pt 'message nil ,limit))
1846 (setq msg (get-text-property pt 'message)))
1847 (error ,error compilation-error))
1848 (or (< (cadr msg) compilation-skip-threshold)
1850 (eq (prog1 last (setq last (nth 2 (car msg))))
1852 (if compilation-skip-visited
1853 (nthcdr 5 (car msg)))
1854 (if compilation-skip-to-next-location
1856 ;; count this message only if none of the above are true
1857 (setq n (,1+ n))))))
1859 (defun compilation-next-error (n &optional different-file pt)
1860 "Move point to the next error in the compilation buffer.
1861 This function does NOT find the source line like \\[next-error].
1862 Prefix arg N says how many error messages to move forwards (or
1863 backwards, if negative).
1864 Optional arg DIFFERENT-FILE, if non-nil, means find next error for a
1865 file that is different from the current one.
1866 Optional arg PT, if non-nil, specifies the value of point to start
1867 looking for the next message."
1869 (or (compilation-buffer-p (current-buffer))
1870 (error "Not in a compilation buffer"))
1871 (or pt (setq pt (point)))
1872 (let* ((msg (get-text-property pt 'message))
1873 ;; `loc' is used by the compilation-loop macro.
1877 (unless (or msg ; find message near here
1878 (setq msg (get-text-property (max (1- pt) (point-min))
1880 (setq pt (previous-single-property-change pt 'message nil
1881 (line-beginning-position)))
1882 (unless (setq msg (get-text-property (max (1- pt) (point-min)) 'message))
1883 (setq pt (next-single-property-change pt 'message nil
1884 (line-end-position)))
1885 (or (setq msg (get-text-property pt 'message))
1886 (setq pt (point)))))
1887 (setq last (nth 2 (car msg)))
1889 (compilation-loop > next-single-property-change 1-
1890 (if (get-buffer-process (current-buffer))
1892 "Moved past last %s")
1894 ;; Don't move "back" to message at or before point.
1895 ;; Pass an explicit (point-min) to make sure pt is non-nil.
1896 (setq pt (previous-single-property-change pt 'message nil (point-min)))
1897 (compilation-loop < previous-single-property-change 1+
1898 "Moved back before first %s" (point-min))))
1901 (error "No %s here" compilation-error))))
1903 (defun compilation-previous-error (n)
1904 "Move point to the previous error in the compilation buffer.
1905 Prefix arg N says how many error messages to move backwards (or
1906 forwards, if negative).
1907 Does NOT find the source line like \\[previous-error]."
1909 (compilation-next-error (- n)))
1911 (defun compilation-next-file (n)
1912 "Move point to the next error for a different file than the current one.
1913 Prefix arg N says how many files to move forwards (or backwards, if negative)."
1915 (compilation-next-error n t))
1917 (defun compilation-previous-file (n)
1918 "Move point to the previous error for a different file than the current one.
1919 Prefix arg N says how many files to move backwards (or forwards, if negative)."
1921 (compilation-next-file (- n)))
1923 (defun kill-compilation ()
1924 "Kill the process made by the \\[compile] or \\[grep] commands."
1926 (let ((buffer (compilation-find-buffer)))
1927 (if (get-buffer-process buffer)
1928 (interrupt-process (get-buffer-process buffer))
1929 (error "The %s process is not running" (downcase mode-name)))))
1931 (defalias 'compile-mouse-goto-error 'compile-goto-error)
1933 (defun compile-goto-error (&optional event)
1934 "Visit the source for the error message at point.
1935 Use this command in a compilation log buffer. Sets the mark at point there."
1936 (interactive (list last-input-event))
1937 (if event (posn-set-point (event-end event)))
1938 (or (compilation-buffer-p (current-buffer))
1939 (error "Not in a compilation buffer"))
1940 (if (get-text-property (point) 'directory)
1941 (dired-other-window (car (get-text-property (point) 'directory)))
1943 (setq compilation-current-error (point))
1944 (next-error-internal)))
1946 (defun compilation-find-buffer (&optional avoid-current)
1947 "Return a compilation buffer.
1948 If AVOID-CURRENT is nil, and the current buffer is a compilation buffer,
1949 return it. If AVOID-CURRENT is non-nil, return the current buffer only
1951 (if (and (compilation-buffer-internal-p) (not avoid-current))
1953 (next-error-find-buffer avoid-current 'compilation-buffer-internal-p)))
1956 (defun compilation-next-error-function (n &optional reset)
1957 "Advance to the next error message and visit the file where the error was.
1958 This is the value of `next-error-function' in Compilation buffers."
1961 (setq compilation-current-error nil))
1962 (let* ((columns compilation-error-screen-columns) ; buffer's local value
1964 (loc (compilation-next-error (or n 1) nil
1965 (or compilation-current-error
1966 compilation-messages-start
1968 (end-loc (nth 2 loc))
1969 (marker (point-marker)))
1970 (setq compilation-current-error (point-marker)
1971 overlay-arrow-position
1973 compilation-current-error
1974 (copy-marker (line-beginning-position)))
1976 ;; If loc contains no marker, no error in that file has been visited.
1977 ;; If the marker is invalid the buffer has been killed.
1978 ;; If the file is newer than the timestamp, it has been modified
1979 ;; (`omake -P' polls filesystem for changes and recompiles when needed
1980 ;; in the same process and buffer).
1981 ;; So, recalculate all markers for that file.
1982 (unless (and (nth 3 loc) (marker-buffer (nth 3 loc)) (nthcdr 4 loc)
1983 ;; There may be no timestamp info if the loc is a `fake-loc',
1984 ;; but we just checked that the file has been visited before!
1986 (setq timestamp compilation-buffer-modtime)))
1987 (with-current-buffer (compilation-find-file marker (caar (nth 2 loc))
1988 (cadr (car (nth 2 loc))))
1991 (goto-char (point-min))
1992 ;; Treat file's found lines in forward order, 1 by 1.
1993 (dolist (line (reverse (cddr (nth 2 loc))))
1994 (when (car line) ; else this is a filename w/o a line#
1995 (beginning-of-line (- (car line) last -1))
1996 (setq last (car line)))
1997 ;; Treat line's found columns and store/update a marker for each.
1998 (dolist (col (cdr line))
2000 (if (eq (car col) -1) ; special case for range end
2002 (compilation-move-to-column (car col) columns))
2004 (skip-chars-forward " \t"))
2006 (set-marker (nth 3 col) (point))
2007 (setcdr (nthcdr 2 col) `(,(point-marker)))))))))
2008 (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc))
2009 (setcdr (nthcdr 3 loc) (list timestamp))
2010 (setcdr (nthcdr 4 loc) t))) ; Set this one as visited.
2012 (defvar compilation-gcpro nil
2013 "Internal variable used to keep some values from being GC'd.")
2014 (make-variable-buffer-local 'compilation-gcpro)
2016 (defun compilation-fake-loc (marker file &optional line col)
2017 "Preassociate MARKER with FILE.
2018 FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
2019 This is useful when you compile temporary files, but want
2020 automatic translation of the messages to the real buffer from
2021 which the temporary file came. This only works if done before a
2022 message about FILE appears!
2024 Optional args LINE and COL default to 1 and beginning of
2025 indentation respectively. The marker is expected to reflect
2026 this. In the simplest case the marker points to the first line
2027 of the region that was saved to the temp file.
2029 If you concatenate several regions into the temp file (e.g. a
2030 header with variable assignments and a code region), you must
2031 call this several times, once each for the last line of one
2032 region and the first line of the next region."
2033 (or (consp file) (setq file (list file)))
2034 (setq file (compilation-get-file-structure file))
2035 ;; Between the current call to compilation-fake-loc and the first occurrence
2036 ;; of an error message referring to `file', the data is only kept in the
2037 ;; weak hash-table compilation-locs, so we need to prevent this entry
2038 ;; in compilation-locs from being GC'd away. --Stef
2039 (push file compilation-gcpro)
2040 (let ((loc (compilation-assq (or line 1) (cdr file))))
2041 (setq loc (compilation-assq col loc))
2043 (setcdr (cddr loc) (list marker))
2044 (setcdr loc (list line file marker)))
2047 (defcustom compilation-context-lines nil
2048 "Display this many lines of leading context before the current message.
2049 If nil and the left fringe is displayed, don't scroll the
2050 compilation output window; an arrow in the left fringe points to
2051 the current message. If nil and there is no left fringe, the message
2052 displays at the top of the window; there is no arrow."
2053 :type '(choice integer (const :tag "No window scrolling" nil))
2057 (defsubst compilation-set-window (w mk)
2058 "Align the compilation output window W with marker MK near top."
2059 (if (integerp compilation-context-lines)
2060 (set-window-start w (save-excursion
2063 (- 1 compilation-context-lines))
2065 ;; If there is no left fringe.
2066 (if (equal (car (window-fringes)) 0)
2067 (set-window-start w (save-excursion
2069 (beginning-of-line 1)
2071 (set-window-point w mk))
2073 (defvar next-error-highlight-timer)
2075 (defun compilation-goto-locus (msg mk end-mk)
2076 "Jump to an error corresponding to MSG at MK.
2077 All arguments are markers. If END-MK is non-nil, mark is set there
2078 and overlay is highlighted between MK and END-MK."
2079 ;; Show compilation buffer in other window, scrolled to this error.
2080 (let* ((from-compilation-buffer (eq (window-buffer (selected-window))
2081 (marker-buffer msg)))
2082 ;; Use an existing window if it is in a visible frame.
2083 (pre-existing (get-buffer-window (marker-buffer msg) 0))
2084 (w (if (and from-compilation-buffer pre-existing)
2085 ;; Calling display-buffer here may end up (partly) hiding
2086 ;; the error location if the two buffers are in two
2087 ;; different frames. So don't do it if it's not necessary.
2089 (let ((display-buffer-reuse-frames t)
2092 (display-buffer (marker-buffer msg)))))
2093 (highlight-regexp (with-current-buffer (marker-buffer msg)
2094 ;; also do this while we change buffer
2095 (compilation-set-window w msg)
2096 compilation-highlight-regexp)))
2097 ;; Ideally, the window-size should be passed to `display-buffer' (via
2098 ;; something like special-display-buffer) so it's only used when
2099 ;; creating a new window.
2100 (unless pre-existing (compilation-set-window-height w))
2102 (if from-compilation-buffer
2103 ;; If the compilation buffer window was selected,
2104 ;; keep the compilation buffer in this window;
2105 ;; display the source in another window.
2106 (let ((pop-up-windows t))
2107 (pop-to-buffer (marker-buffer mk) 'other-window))
2108 (if (window-dedicated-p (selected-window))
2109 (pop-to-buffer (marker-buffer mk))
2110 (switch-to-buffer (marker-buffer mk))))
2111 (unless (eq (goto-char mk) (point))
2112 ;; If narrowing gets in the way of going to the right place, widen.
2114 (if next-error-move-function
2115 (funcall next-error-move-function msg mk)
2118 (push-mark end-mk t)
2119 (if mark-active (setq mark-active)))
2120 ;; If hideshow got in the way of
2121 ;; seeing the right place, open permanently.
2122 (dolist (ov (overlays-at (point)))
2123 (when (eq 'hs (overlay-get ov 'invisible))
2127 (when highlight-regexp
2128 (if (timerp next-error-highlight-timer)
2129 (cancel-timer next-error-highlight-timer))
2130 (unless compilation-highlight-overlay
2131 (setq compilation-highlight-overlay
2132 (make-overlay (point-min) (point-min)))
2133 (overlay-put compilation-highlight-overlay 'face 'next-error))
2134 (with-current-buffer (marker-buffer mk)
2136 (if end-mk (goto-char end-mk) (end-of-line))
2137 (let ((end (point)))
2138 (if mk (goto-char mk) (beginning-of-line))
2139 (if (and (stringp highlight-regexp)
2140 (re-search-forward highlight-regexp end t))
2142 (goto-char (match-beginning 0))
2143 (move-overlay compilation-highlight-overlay
2144 (match-beginning 0) (match-end 0)
2146 (move-overlay compilation-highlight-overlay
2147 (point) end (current-buffer)))
2148 (if (or (eq next-error-highlight t)
2149 (numberp next-error-highlight))
2150 ;; We want highlighting: delete overlay on next input.
2151 (add-hook 'pre-command-hook
2152 'compilation-goto-locus-delete-o)
2153 ;; We don't want highlighting: delete overlay now.
2154 (delete-overlay compilation-highlight-overlay))
2155 ;; We want highlighting for a limited time:
2156 ;; set up a timer to delete it.
2157 (when (numberp next-error-highlight)
2158 (setq next-error-highlight-timer
2159 (run-at-time next-error-highlight nil
2160 'compilation-goto-locus-delete-o)))))))
2161 (when (and (eq next-error-highlight 'fringe-arrow))
2162 ;; We want a fringe arrow (instead of highlighting).
2163 (setq next-error-overlay-arrow-position
2164 (copy-marker (line-beginning-position))))))
2166 (defun compilation-goto-locus-delete-o ()
2167 (delete-overlay compilation-highlight-overlay)
2168 ;; Get rid of timer and hook that would try to do this again.
2169 (if (timerp next-error-highlight-timer)
2170 (cancel-timer next-error-highlight-timer))
2171 (remove-hook 'pre-command-hook
2172 'compilation-goto-locus-delete-o))
2174 (defun compilation-find-file (marker filename directory &rest formats)
2175 "Find a buffer for file FILENAME.
2176 If FILENAME is not found at all, ask the user where to find it.
2177 Pop up the buffer containing MARKER and scroll to MARKER if we ask
2178 the user where to find the file.
2179 Search the directories in `compilation-search-path'.
2180 A nil in `compilation-search-path' means to try the
2181 \"current\" directory, which is passed in DIRECTORY.
2182 If DIRECTORY is relative, it is combined with `default-directory'.
2183 If DIRECTORY is nil, that means use `default-directory'.
2184 FORMATS, if given, is a list of formats to reformat FILENAME when
2185 looking for it: for each element FMT in FORMATS, this function
2186 attempts to find a file whose name is produced by (format FMT FILENAME)."
2187 (or formats (setq formats '("%s")))
2188 (let ((dirs compilation-search-path)
2189 (spec-dir (if directory
2190 (expand-file-name directory)
2192 buffer thisdir fmts name)
2193 (if (file-name-absolute-p filename)
2194 ;; The file name is absolute. Use its explicit directory as
2195 ;; the first in the search path, and strip it from FILENAME.
2196 (setq filename (abbreviate-file-name (expand-file-name filename))
2197 dirs (cons (file-name-directory filename) dirs)
2198 filename (file-name-nondirectory filename)))
2199 ;; Now search the path.
2200 (while (and dirs (null buffer))
2201 (setq thisdir (or (car dirs) spec-dir)
2203 ;; For each directory, try each format string.
2204 (while (and fmts (null buffer))
2205 (setq name (expand-file-name (format (car fmts) filename) thisdir)
2206 buffer (and (file-exists-p name)
2207 (find-file-noselect name))
2209 (setq dirs (cdr dirs)))
2210 (while (null buffer) ;Repeat until the user selects an existing file.
2211 ;; The file doesn't exist. Ask the user where to find it.
2212 (save-excursion ;This save-excursion is probably not right.
2213 (let ((pop-up-windows t))
2214 (compilation-set-window (display-buffer (marker-buffer marker))
2216 (let* ((name (read-file-name
2217 (format "Find this %s in (default %s): "
2218 compilation-error filename)
2219 spec-dir filename t nil
2220 ;; The predicate below is fine when called from
2221 ;; minibuffer-complete-and-exit, but it's too
2222 ;; restrictive otherwise, since it also prevents the
2223 ;; user from completing "fo" to "foo/" when she
2224 ;; wants to enter "foo/bar".
2226 ;; Try to make sure the user can only select
2227 ;; a valid answer. This predicate may be ignored,
2228 ;; tho, so we still have to double-check afterwards.
2229 ;; TODO: We should probably fix read-file-name so
2230 ;; that it never ignores this predicate, even when
2231 ;; using popup dialog boxes.
2233 ;; (if (file-directory-p name)
2234 ;; (setq name (expand-file-name filename name)))
2235 ;; (file-exists-p name))
2239 ((not (file-exists-p name))
2240 (message "Cannot find file `%s'" name)
2242 ((and (file-directory-p name)
2244 (setq name (expand-file-name filename name)))))
2245 (message "No `%s' in directory %s" filename origname)
2248 (setq buffer (find-file-noselect name))))))))
2249 ;; Make intangible overlays tangible.
2250 ;; This is weird: it's not even clear which is the current buffer,
2251 ;; so the code below can't be expected to DTRT here. -- Stef
2252 (dolist (ov (overlays-in (point-min) (point-max)))
2253 (when (overlay-get ov 'intangible)
2254 (overlay-put ov 'intangible nil)))
2257 (defun compilation-get-file-structure (file &optional fmt)
2258 "Retrieve FILE's file-structure or create a new one.
2259 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
2260 In the former case, FILENAME may be relative or absolute.
2262 The file-structure looks like this:
2263 (list (list FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)"
2264 (or (gethash file compilation-locs)
2265 ;; File was not previously encountered, at least not in the form passed.
2266 ;; Let's normalize it and look again.
2267 (let ((filename (car file))
2268 ;; Get the specified directory from FILE.
2269 (spec-directory (if (cdr file)
2270 (file-truename (cdr file)))))
2272 ;; Check for a comint-file-name-prefix and prepend it if appropriate.
2273 ;; (This is very useful for compilation-minor-mode in an rlogin-mode
2275 (when (and (boundp 'comint-file-name-prefix)
2276 (not (equal comint-file-name-prefix "")))
2277 (if (file-name-absolute-p filename)
2279 (concat comint-file-name-prefix filename))
2281 (setq spec-directory
2283 (concat comint-file-name-prefix spec-directory))))))
2285 ;; If compilation-parse-errors-filename-function is
2286 ;; defined, use it to process the filename.
2287 (when compilation-parse-errors-filename-function
2289 (funcall compilation-parse-errors-filename-function
2292 ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
2293 ;; file names like "./bar//foo.c" for file "bar/foo.c";
2294 ;; expand-file-name will collapse these into "/foo.c" and fail to find
2295 ;; the appropriate file. So we look for doubled slashes in the file
2296 ;; name and fix them.
2297 (setq filename (command-line-normalize-file-name filename))
2299 ;; Store it for the possibly unnormalized name
2301 ;; Retrieve or create file-structure for normalized name
2302 ;; The gethash used to not use spec-directory, but
2303 ;; this leads to errors when files in different
2304 ;; directories have the same name:
2305 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00463.html
2306 (or (gethash (cons filename spec-directory) compilation-locs)
2307 (puthash (cons filename spec-directory)
2308 (list (list filename spec-directory) fmt)
2310 compilation-locs))))
2312 (add-to-list 'debug-ignored-errors "^No more [-a-z ]+s yet$")
2314 ;;; Compatibility with the old compile.el.
2316 (defun compile-buffer-substring (n) (if n (match-string n)))
2318 (defun compilation-compat-error-properties (err)
2319 "Map old-style error ERR to new-style message."
2320 ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
2321 ;; (MARKER . MARKER).
2322 (let ((dst (cdr err)))
2324 ;; Must start with a face, for font-lock.
2326 message ,(list (list nil nil nil dst) 2)
2327 help-echo "mouse-2: visit the source location"
2328 keymap compilation-button-map
2329 mouse-face highlight)
2330 ;; Too difficult to do it by hand: dispatch to the normal code.
2331 (let* ((file (pop dst))
2334 (filename (pop file))
2335 (dirname (pop file))
2337 (compilation-internal-error-properties
2338 (cons filename dirname) line nil col nil 2 fmt)))))
2340 (defun compilation-compat-parse-errors (limit)
2341 (when compilation-parse-errors-function
2342 ;; FIXME: We should remove the rest of the compilation keywords
2343 ;; but we can't do that from here because font-lock is using
2344 ;; the value right now. --stef
2346 (setq compilation-error-list nil)
2347 ;; Reset compilation-parsing-end each time because font-lock
2348 ;; might force us the re-parse many times (typically because
2349 ;; some code adds some text-property to the output that we
2350 ;; already parsed). You might say "why reparse", well:
2351 ;; because font-lock has just removed the `message' property so
2352 ;; have to do it all over again.
2353 (if compilation-parsing-end
2354 (set-marker compilation-parsing-end (point))
2355 (setq compilation-parsing-end (point-marker)))
2357 ;; Ignore any error: we're calling this function earlier than
2358 ;; in the old compile.el so things might not all be setup yet.
2359 (funcall compilation-parse-errors-function limit nil)
2361 (dolist (err (if (listp compilation-error-list) compilation-error-list))
2362 (let* ((src (car err))
2364 (loc (cond ((markerp dst) (list nil nil nil dst))
2366 (list (nth 2 dst) (nth 1 dst)
2367 (cons (cdar dst) (caar dst)))))))
2370 ;; (put-text-property src (line-end-position) 'font-lock-face 'font-lock-warning-face)
2371 (put-text-property src (line-end-position)
2372 'message (list loc 2)))))))
2376 ;; Beware: this is not only compatibility code. New code stil uses it. --Stef
2377 (defun compilation-forget-errors ()
2378 ;; In case we hit the same file/line specs, we want to recompute a new
2379 ;; marker for them, so flush our cache.
2380 (setq compilation-locs (make-hash-table :test 'equal :weakness 'value))
2381 (setq compilation-gcpro nil)
2382 ;; FIXME: the old code reset the directory-stack, so maybe we should
2383 ;; put a `directory change' marker of some sort, but where? -stef
2385 ;; FIXME: The old code moved compilation-current-error (which was
2386 ;; virtually represented by a mix of compilation-parsing-end and
2387 ;; compilation-error-list) to point-min, but that was only meaningful for
2388 ;; the internal uses of compilation-forget-errors: all calls from external
2389 ;; packages seem to be followed by a move of compilation-parsing-end to
2390 ;; something equivalent to point-max. So we heuristically move
2391 ;; compilation-current-error to point-max (since the external package
2392 ;; won't know that it should do it). --Stef
2393 (setq compilation-current-error nil)
2394 (let* ((proc (get-buffer-process (current-buffer)))
2395 (mark (if proc (process-mark proc)))
2396 (pos (or mark (point-max))))
2397 (setq compilation-messages-start
2398 ;; In the future, ignore the text already present in the buffer.
2399 ;; Since many process filter functions insert before markers,
2400 ;; we need to put ours just before the insertion point rather
2401 ;; than at the insertion point. If that's not possible, then
2402 ;; don't use a marker. --Stef
2403 (if (> pos (point-min)) (copy-marker (1- pos)) pos)))
2404 ;; Again, since this command is used in buffers that contain several
2405 ;; compilations, to set the beginning of "this compilation", it's a good
2406 ;; place to reset compilation-auto-jump-to-next.
2407 (set (make-local-variable 'compilation-auto-jump-to-next)
2408 (or compilation-auto-jump-to-first-error
2409 (eq compilation-scroll-output 'first-error))))
2412 (add-to-list 'auto-mode-alist (cons (purecopy "\\.gcov\\'") 'compilation-mode))
2416 ;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c
2417 ;;; compile.el ends here