1 ;;; compile.el --- run compiler as inferior of Emacs, parse error messages
3 ;; Copyright (C) 1985-1987, 1993-1999, 2001-2013 Free Software
6 ;; Authors: Roland McGrath <roland@gnu.org>,
7 ;; Daniel Pfeiffer <occitan@esperanto.org>
9 ;; Keywords: tools, processes
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; This package provides the compile facilities documented in the Emacs user's
33 (eval-when-compile (require 'cl-lib
))
37 (defgroup compilation nil
38 "Run compiler as inferior of Emacs, parse error messages."
44 (defcustom compilation-mode-hook nil
45 "List of hook functions run by `compilation-mode' (see `run-mode-hooks')."
50 (defcustom compilation-start-hook nil
51 "List of hook functions run by `compilation-start' on the compilation process.
52 \(See `run-hook-with-args').
53 If you use \"omake -P\" and do not want \\[save-buffers-kill-terminal] to ask whether you want
54 the compilation to be killed, you can use this hook:
55 (add-hook 'compilation-start-hook
56 (lambda (process) (set-process-query-on-exit-flag process nil)) nil t)"
61 (defcustom compilation-window-height nil
62 "Number of lines in a compilation window. If nil, use Emacs default."
63 :type
'(choice (const :tag
"Default" nil
)
67 (defvar compilation-filter-hook nil
68 "Hook run after `compilation-filter' has inserted a string into the buffer.
69 It is called with the variable `compilation-filter-start' bound
70 to the position of the start of the inserted text, and point at
73 If Emacs lacks asynchronous process support, this hook is run
74 after `call-process' inserts the grep output into the buffer.")
76 (defvar compilation-filter-start nil
77 "Position of the start of the text inserted by `compilation-filter'.
78 This is bound before running `compilation-filter-hook'.")
80 (defvar compilation-first-column
1
81 "This is how compilers number the first column, usually 1 or 0.
82 If this is buffer-local in the destination buffer, Emacs obeys
83 that value, otherwise it uses the value in the *compilation*
84 buffer. This enables a major-mode to specify its own value.")
86 (defvar compilation-parse-errors-filename-function nil
87 "Function to call to post-process filenames while parsing error messages.
88 It takes one arg FILENAME which is the name of a file as found
89 in the compilation output, and should return a transformed file name.")
92 (defvar compilation-process-setup-function nil
93 "Function to call to customize the compilation process.
94 This function is called immediately before the compilation process is
95 started. It can be used to set any variables or functions that are used
96 while processing the output of the compilation process.")
99 (defvar compilation-buffer-name-function nil
100 "Function to compute the name of a compilation buffer.
101 The function receives one argument, the name of the major mode of the
102 compilation buffer. It should return a string.
103 If nil, compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
106 (defvar compilation-finish-function nil
107 "Function to call when a compilation process finishes.
108 It is called with two arguments: the compilation buffer, and a string
109 describing how the process finished.")
111 (make-obsolete-variable 'compilation-finish-function
112 "use `compilation-finish-functions', but it works a little differently."
116 (defvar compilation-finish-functions nil
117 "Functions to call when a compilation process finishes.
118 Each function is called with two arguments: the compilation buffer,
119 and a string describing how the process finished.")
121 (defvar compilation-in-progress nil
122 "List of compilation processes now running.")
123 (or (assq 'compilation-in-progress minor-mode-alist
)
124 (setq minor-mode-alist
(cons '(compilation-in-progress " Compiling")
127 (defvar compilation-error
"error"
128 "Stem of message to print when no matches are found.")
130 (defvar compilation-arguments nil
131 "Arguments that were given to `compilation-start'.")
133 (defvar compilation-num-errors-found
)
135 ;; If you make any changes to `compilation-error-regexp-alist-alist',
136 ;; be sure to run the ERT test in test/automated/compile-tests.el.
138 (defvar compilation-error-regexp-alist-alist
140 "^\\(?:[Ee]rror on \\|[Ww]arning on\\( \\)\\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
141 of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil
(1))
144 "\\(warning: .*\\)? at \\([^ \n]+\\):\\([0-9]+\\)$" 2 3 nil
(1))
147 " in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
150 "^[ \t]*\\[[^] \n]+\\][ \t]*\\([^: \n]+\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\):\\)?\
151 \\( warning\\)?" 1 (2 .
4) (3 .
5) (6))
154 "^\\([^: \n\t]+\\): line \\([0-9]+\\):" 1 2)
157 "^\\(?:Error\\|Warnin\\(g\\)\\) \\(?:[FEW][0-9]+ \\)?\
158 \\([a-zA-Z]?:?[^:( \t\n]+\\)\
159 \\([0-9]+\\)\\(?:[) \t]\\|:[^0-9\n]\\)" 2 3 nil
(1))
161 (python-tracebacks-and-caml
162 "^[ \t]*File \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1, lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
163 \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:\\)?\\([ \n]Warning\\(?: [0-9]+\\)?:\\)?\\)"
164 2 (3 .
4) (5 .
6) (7))
167 "^\"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)\
168 \\(?:[(. pos]+\\([0-9]+\\))?\\)?[:.,; (-]\\( warning:\\|[-0-9 ]*(W)\\)?" 1 2 3 (4))
171 "\\(?:^cucumber\\(?: -p [^[:space:]]+\\)?\\|#\\)\
172 \\(?: \\)\\([^\(].*\\):\\([1-9][0-9]*\\)" 1 2)
175 ;; Must be before edg-1, so that MSVC's longer messages are
176 ;; considered before EDG.
177 ;; The message may be a "warning", "error", or "fatal error" with
178 ;; an error code, or "see declaration of" without an error code.
179 "^ *\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) ?\
180 : \\(?:see declaration\\|\\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:\\)"
184 "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
187 "at line \\([0-9]+\\) of \"\\([^ \n]+\\)\"$"
191 "^Error [0-9]+ at (\\([0-9]+\\):\\([^)\n]+\\))" 2 1)
194 "\\(^Warning .*\\)? line[ \n]\\([0-9]+\\)[ \n]\\(?:col \\([0-9]+\\)[ \n]\\)?file \\([^ :;\n]+\\)"
198 "^\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(?:Error\\|Warnin\\(g\\)\\)\\[[0-9]+\\]:"
202 "^\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) :\
203 \\(?:warnin\\(g\\)\\|informationa\\(l\\)\\)?" 1 2 3 (4 .
5))
205 ;; fixme: should be `mips'
207 "^[-[:alnum:]_/ ]+: \\(?:\\(?:[sS]evere\\|[eE]rror\\|[wW]arnin\\(g\\)\\|[iI]nf\\(o\\)\\)[0-9 ]*: \\)?\
208 \\([^,\" \n\t]+\\)\\(?:, line\\|:\\) \\([0-9]+\\):" 3 4 nil
(1 .
2))
211 "^\\(?:[ \t]+at \\|==[0-9]+== +\\(?:at\\|b\\(y\\)\\)\\).+(\\([^()\n]+\\):\\([0-9]+\\))$" 2 3 nil
(1))
214 "^\\(?:Found\\|Issued\\) .* compiling \"\\(.+\\)\":$" 1 nil nil
0)
217 ;; This used to be pathologically slow on long lines (Bug#3441),
218 ;; due to matching filenames via \\(.*?\\). This might be faster.
220 ;; Maven is a popular free software build tool for Java.
221 "\\([^ \n]\\(?:[^\n :]\\| [^-/\n]\\|:[^ \n]\\)*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\] " 1 2 3)
224 "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)"
226 (2 (compilation-face '(3))))
229 "^\\(?:In file included \\| \\|\t\\)from \
230 \\([0-9]*[^0-9\n]\\(?:[^\n :]\\| [^-/\n]\\|:[^ \n]\\)*?\\):\
231 \\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?\\(?:\\(:\\)\\|\\(,\\|$\\)\\)?"
235 "^[\t ]*\\[\\([^\(].*\\):\\([1-9][0-9]*\\)\\(\\]\\)?:in " 1 2)
238 ;; The first line matches the program name for
240 ;; PROGRAM:SOURCE-FILE-NAME:LINENO: MESSAGE
242 ;; format, which is used for non-interactive programs other than
243 ;; compilers (e.g. the "jade:" entry in compilation.txt).
245 ;; This first line makes things ambiguous with output such as
246 ;; "foo:344:50:blabla" since the "foo" part can match this first
247 ;; line (in which case the file name as "344"). To avoid this,
248 ;; the second line disallows filenames exclusively composed of
251 ;; Similarly, we get lots of false positives with messages including
252 ;; times of the form "HH:MM:SS" where MM is taken as a line number, so
253 ;; the last line tries to rule out message where the info after the
254 ;; line number starts with "SS". --Stef
256 ;; The core of the regexp is the one with *?. It says that a file name
257 ;; can be composed of any non-newline char, but it also rules out some
258 ;; valid but unlikely cases, such as a trailing space or a space
259 ;; followed by a -, or a colon followed by a space.
261 ;; The "in \\|from " exception was added to handle messages from Ruby.
262 "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\|[ \t]+\\(?:in \\|from \\)\\)?\
263 \\([0-9]*[^0-9\n]\\(?:[^\n :]\\| [^-/\n]\\|:[^ \n]\\)*?\\): ?\
264 \\([0-9]+\\)\\(?:[.:]\\([0-9]+\\)\\)?\
265 \\(?:-\\([0-9]+\\)?\\(?:\\.\\([0-9]+\\)\\)?\\)?:\
266 \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\
267 *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\|[Nn]ote\\)\\|\
268 *[Ee]rror\\|\[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)"
269 1 (2 .
4) (3 .
5) (6 .
7))
272 "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)"
276 "^makepp\\(?:\\(?:: warning\\(:\\).*?\\|\\(: Scanning\\|: [LR]e?l?oading makefile\\|: Imported\\|log:.*?\\) \\|: .*?\\)\
277 `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)"
279 (0 (progn (save-match-data
280 (compilation-parse-errors
281 (match-end 0) (line-end-position)
282 `("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]"
284 ,(cond ((match-end 1) 1) ((match-end 2) 0) (t 2))
289 ;; Should be lint-1, lint-2 (SysV lint)
291 " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
293 " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2)
296 ;; The message may be a "warning", "error", or "fatal error" with
297 ;; an error code, or "see declaration of" without an error code.
298 "^ *\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
299 : \\(?:see declaration\\|\\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:\\)"
303 ;; "omake -P" reports "file foo changed"
304 ;; (useful if you do "cvs up" and want to see what has changed)
305 "omake: file \\(.*\\) changed" 1 nil nil nil nil
306 ;; FIXME-omake: This tries to prevent reusing pre-existing markers
307 ;; for subsequent messages, since those messages's line numbers
308 ;; are about another version of the file.
309 (0 (progn (compilation--flush-file-structure (match-string 1))
313 "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
314 \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
315 \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
318 ;; "during global destruction": This comes out under "use
319 ;; warnings" in recent perl when breaking circular references
320 ;; during program or thread exit.
322 " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \
323 during global destruction\\.$\\)" 1 2)
326 "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
330 "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
331 \\([0-9]+\\) of file://\\(.+\\)"
335 "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
336 [12][09][0-9][0-9] +\\(.*\\):$"
339 "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
340 nil
3 nil
(2) nil
(1 (compilation-face '(2))))
341 (sparc-pascal-example
342 "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
343 nil
1 nil
(3) nil
(2 (compilation-face '(3))))
346 ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
347 File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
351 "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
354 "^[ \t]*\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)): ?\
355 \\(?:\\(Error! E[0-9]+\\)\\|\\(Warning! W[0-9]+\\)\\):"
359 "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
360 \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil
(3))
363 "^ *-: *\\(0\\):Source:\\(.+\\)$"
366 "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
368 ;; Underlines over all lines of gcov output are too uncomfortable to read.
369 ;; However, hyperlinks embedded in the lines are useful.
370 ;; So I put default face on the lines; and then put
371 ;; compilation-*-face by manually to eliminate the underlines.
372 ;; The hyperlinks are still effective.
374 "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
377 (1 compilation-line-face
))
379 "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
382 (1 compilation-info-face
) (2 compilation-line-face
))
384 "^ *\\(#####\\): *\\([0-9]+\\):.*$"
387 (1 compilation-error-face
) (2 compilation-line-face
))
390 ;; podchecker error messages, per Pod::Checker.
391 ;; The style is from the Pod::Checker::poderror() function, eg.
392 ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm
394 ;; Plus end_pod() can give "at line EOF" instead of a
395 ;; number, so for that match "on line N" which is the
396 ;; originating spot, eg.
397 ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm
399 ;; Plus command() can give both "on line N" and "at line N";
400 ;; the latter is desired and is matched because the .* is
402 ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod
404 "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \
405 \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)"
408 ;; perl Test module error messages.
409 ;; Style per the ok() function "$context", eg.
410 ;; # Failed test 1 in foo.t at line 6
412 "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
415 ;; Or when comparing got/want values, with a "fail #n" if repeated
416 ;; # Test 2 got: "xx" (t-compilation-perl-2.t at line 10)
417 ;; # Test 3 got: "xx" (t-compilation-perl-2.t at line 10 fail #2)
419 ;; And under Test::Harness they're preceded by progress stuff with
421 ;; ... NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
423 "^\\(.*NOK.*\\)?# Test [0-9]+ got:.* (\\([^ \t\r\n]+\\) at line \
424 \\([0-9]+\\)\\( fail #[0-9]+\\)?)"
427 ;; perl Test::Harness output, eg.
428 ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
430 ;; Test::Harness is slightly designed for tty output, since
431 ;; it prints CRs to overwrite progress messages, but if you
432 ;; run it in with M-x compile this pattern can at least step
433 ;; through the failures.
435 "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
438 ;; The style comes from HTML::Lint::Error::as_string(), eg.
439 ;; index.html (13:1) Unknown element <fdjsk>
441 ;; The pattern only matches filenames without spaces, since that
442 ;; should be usual and should help reduce the chance of a false
443 ;; match of a message from some unrelated program.
445 ;; This message style is quite close to the "ibm" entry which is
446 ;; for IBM C, though that ibm bit doesn't put a space after the
449 "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) "
452 "Alist of values for `compilation-error-regexp-alist'.")
454 (defcustom compilation-error-regexp-alist
455 (mapcar 'car compilation-error-regexp-alist-alist
)
456 "Alist that specifies how to match errors in compiler output.
457 On GNU and Unix, any string is a valid filename, so these
458 matchers must make some common sense assumptions, which catch
459 normal cases. A shorter list will be lighter on resource usage.
461 Instead of an alist element, you can use a symbol, which is
462 looked up in `compilation-error-regexp-alist-alist'. You can see
463 the predefined symbols and their effects in the file
464 `etc/compilation.txt' (linked below if you are customizing this).
466 Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
467 HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
468 gives the file name, and the LINE'th subexpression gives the line
469 number. The COLUMN'th subexpression gives the column number on
472 If FILE, LINE or COLUMN are nil or that index didn't match, that
473 information is not present on the matched line. In that case the
474 file name is assumed to be the same as the previous one in the
475 buffer, line number defaults to 1 and column defaults to
476 beginning of line's indentation.
478 FILE can also have the form (FILE FORMAT...), where the FORMATs
479 \(e.g. \"%s.c\") will be applied in turn to the recognized file
480 name, until a file of that name is found. Or FILE can also be a
481 function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
482 In the former case, FILENAME may be relative or absolute.
484 LINE can also be of the form (LINE . END-LINE) meaning a range
485 of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
486 meaning a range of columns starting on LINE and ending on
487 END-LINE, if that matched.
489 TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
490 TYPE can also be of the form (WARNING . INFO). In that case this
491 will be equivalent to 1 if the WARNING'th subexpression matched
492 or else equivalent to 0 if the INFO'th subexpression matched.
493 See `compilation-error-face', `compilation-warning-face',
494 `compilation-info-face' and `compilation-skip-threshold'.
496 What matched the HYPERLINK'th subexpression has `mouse-face' and
497 `compilation-message-face' applied. If this is nil, the text
498 matched by the whole REGEXP becomes the hyperlink.
500 Additional HIGHLIGHTs take the shape (SUBMATCH FACE), where
501 SUBMATCH is the number of a submatch and FACE is an expression
502 which evaluates to a face name (a symbol or string).
503 Alternatively, FACE can evaluate to a property list of the
504 form (face FACE PROP1 VAL1 PROP2 VAL2 ...), in which case all the
505 listed text properties PROP# are given values VAL# as well."
506 :type
'(repeat (choice (symbol :tag
"Predefined symbol")
507 (sexp :tag
"Error specification")))
508 :link
`(file-link :tag
"example file"
509 ,(expand-file-name "compilation.txt" data-directory
))
512 ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp)
513 (defvar compilation-directory nil
514 "Directory to restore to when doing `recompile'.")
516 (defvar compilation-directory-matcher
517 '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 .
1))
518 "A list for tracking when directories are entered or left.
519 If nil, do not track directories, e.g. if all file names are absolute. The
520 first element is the REGEXP matching these messages. It can match any number
521 of variants, e.g. different languages. The remaining elements are all of the
522 form (DIR . LEAVE). If for any one of these the DIR'th subexpression
523 matches, that is a directory name. If LEAVE is nil or the corresponding
524 LEAVE'th subexpression doesn't match, this message is about going into another
525 directory. If it does match anything, this message is about going back to the
526 directory we were in before the last entering message. If you change this,
527 you may also want to change `compilation-page-delimiter'.")
529 (defvar compilation-page-delimiter
530 "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
531 "Value of `page-delimiter' in Compilation mode.")
533 (defvar compilation-mode-font-lock-keywords
534 '(;; configure output lines.
535 ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
536 (1 font-lock-variable-name-face
)
537 (2 (compilation-face '(4 .
3))))
538 ;; Command output lines. Recognize `make[n]:' lines too.
539 ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
540 (1 font-lock-function-name-face
) (3 compilation-line-face nil t
))
541 (" --?o\\(?:utfile\\|utput\\)?[= ]\\(\\S +\\)" .
1)
542 ("^Compilation \\(finished\\).*"
543 (0 '(face nil compilation-message nil help-echo nil mouse-face nil
) t
)
544 (1 compilation-info-face
))
545 ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
546 (0 '(face nil compilation-message nil help-echo nil mouse-face nil
) t
)
547 (1 compilation-error-face
)
548 (2 compilation-error-face nil t
)))
549 "Additional things to highlight in Compilation mode.
550 This gets tacked on the end of the generated expressions.")
552 (defvar compilation-highlight-regexp t
553 "Regexp matching part of visited source lines to highlight temporarily.
554 Highlight entire line if t; don't highlight source lines if nil.")
556 (defvar compilation-highlight-overlay nil
557 "Overlay used to temporarily highlight compilation matches.")
559 (defcustom compilation-error-screen-columns t
560 "If non-nil, column numbers in error messages are screen columns.
561 Otherwise they are interpreted as character positions, with
562 each character occupying one column.
563 The default is to use screen columns, which requires that the compilation
564 program and Emacs agree about the display width of the characters,
565 especially the TAB character.
566 If this is buffer-local in the destination buffer, Emacs obeys
567 that value, otherwise it uses the value in the *compilation*
568 buffer. This enables a major-mode to specify its own value."
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 (defcustom compilation-environment nil
659 "List of environment variables for compilation to inherit.
660 Each element should be a string of the form ENVVARNAME=VALUE.
661 This list is temporarily prepended to `process-environment' prior to
662 starting the compilation process."
663 :type
'(repeat (string :tag
"ENVVARNAME=VALUE"))
664 :options
'(("LANG=C"))
668 ;; History of compile commands.
669 (defvar compile-history nil
)
671 (defface compilation-error
672 '((t :inherit error
))
673 "Face used to highlight compiler errors."
677 (defface compilation-warning
678 '((t :inherit warning
))
679 "Face used to highlight compiler warnings."
683 (defface compilation-info
684 '((t :inherit success
))
685 "Face used to highlight compiler information."
689 ;; The next three faces must be able to stand out against the
690 ;; `mode-line' and `mode-line-inactive' faces.
692 (defface compilation-mode-line-fail
693 '((default :inherit compilation-error
)
694 (((class color
) (min-colors 16)) (:foreground
"Red1" :weight bold
))
695 (((class color
) (min-colors 8)) (:foreground
"red"))
696 (t (:inverse-video t
:weight bold
)))
697 "Face for Compilation mode's \"error\" mode line indicator."
701 (defface compilation-mode-line-run
702 '((t :inherit compilation-warning
))
703 "Face for Compilation mode's \"running\" mode line indicator."
707 (defface compilation-mode-line-exit
708 '((default :inherit compilation-info
)
709 (((class color
) (min-colors 16))
710 (:foreground
"ForestGreen" :weight bold
))
711 (((class color
)) (:foreground
"green" :weight bold
))
713 "Face for Compilation mode's \"exit\" mode line indicator."
717 (defface compilation-line-number
718 '((t :inherit font-lock-keyword-face
))
719 "Face for displaying line numbers in compiler messages."
723 (defface compilation-column-number
724 '((t :inherit font-lock-doc-face
))
725 "Face for displaying column numbers in compiler messages."
729 (defcustom compilation-message-face
'underline
730 "Face name to use for whole messages.
731 Faces `compilation-error-face', `compilation-warning-face',
732 `compilation-info-face', `compilation-line-face' and
733 `compilation-column-face' get prepended to this, when applicable."
738 (defvar compilation-error-face
'compilation-error
739 "Face name to use for file name in error messages.")
741 (defvar compilation-warning-face
'compilation-warning
742 "Face name to use for file name in warning messages.")
744 (defvar compilation-info-face
'compilation-info
745 "Face name to use for file name in informational messages.")
747 (defvar compilation-line-face
'compilation-line-number
748 "Face name to use for line numbers in compiler messages.")
750 (defvar compilation-column-face
'compilation-column-number
751 "Face name to use for column numbers in compiler messages.")
753 ;; same faces as dired uses
754 (defvar compilation-enter-directory-face
'font-lock-function-name-face
755 "Face name to use for entering directory messages.")
757 (defvar compilation-leave-directory-face
'font-lock-builtin-face
758 "Face name to use for leaving directory messages.")
760 ;; Used for compatibility with the old compile.el.
761 (defvar compilation-parse-errors-function nil
)
762 (make-obsolete-variable 'compilation-parse-errors-function
763 'compilation-error-regexp-alist
"24.1")
765 (defcustom compilation-auto-jump-to-first-error nil
766 "If non-nil, automatically jump to the first error during compilation."
771 (defvar compilation-auto-jump-to-next nil
772 "If non-nil, automatically jump to the next error encountered.")
773 (make-variable-buffer-local 'compilation-auto-jump-to-next
)
775 ;; (defvar compilation-buffer-modtime nil
776 ;; "The buffer modification time, for buffers not associated with files.")
777 ;; (make-variable-buffer-local 'compilation-buffer-modtime)
779 (defvar compilation-skip-to-next-location t
780 "If non-nil, skip multiple error messages for the same source location.")
782 (defcustom compilation-skip-threshold
1
783 "Compilation motion commands skip less important messages.
784 The value can be either 2 -- skip anything less than error, 1 --
785 skip anything less than warning or 0 -- don't skip any messages.
786 Note that all messages not positively identified as warning or
787 info, are considered errors."
788 :type
'(choice (const :tag
"Skip warnings and info" 2)
789 (const :tag
"Skip info" 1)
790 (const :tag
"No skip" 0))
794 (defun compilation-set-skip-threshold (level)
795 "Switch the `compilation-skip-threshold' level."
798 (mod (if current-prefix-arg
799 (prefix-numeric-value current-prefix-arg
)
800 (1+ compilation-skip-threshold
))
802 (setq compilation-skip-threshold level
)
803 (message "Skipping %s"
804 (pcase compilation-skip-threshold
807 (2 "Warnings and info"))))
809 (defcustom compilation-skip-visited nil
810 "Compilation motion commands skip visited messages if this is t.
811 Visited messages are ones for which the file, line and column have been jumped
812 to from the current content in the current compilation buffer, even if it was
813 from a different message."
818 (defun compilation-face (type)
819 (or (and (car type
) (match-end (car type
)) compilation-warning-face
)
820 (and (cdr type
) (match-end (cdr type
)) compilation-info-face
)
821 compilation-error-face
))
823 ;; LOC (or location) is a list of (COLUMN LINE FILE-STRUCTURE nil nil)
825 ;; COLUMN and LINE are numbers parsed from an error message. COLUMN and maybe
826 ;; LINE will be nil for a message that doesn't contain them. Then the
827 ;; location refers to a indented beginning of line or beginning of file.
828 ;; Once any location in some file has been jumped to, the list is extended to
829 ;; (COLUMN LINE FILE-STRUCTURE MARKER TIMESTAMP . VISITED)
830 ;; for all LOCs pertaining to that file.
831 ;; MARKER initially points to LINE and COLUMN in a buffer visiting that file.
832 ;; Being a marker it sticks to some text, when the buffer grows or shrinks
833 ;; before that point. VISITED is t if we have jumped there, else nil.
834 ;; FIXME-omake: TIMESTAMP was used to try and handle "incremental compilation":
835 ;; `omake -P' polls filesystem for changes and recompiles when a file is
836 ;; modified using the same *compilation* buffer. this necessitates
837 ;; re-parsing markers.
839 ;; (cl-defstruct (compilation--loc
840 ;; (:constructor nil)
842 ;; (:constructor compilation--make-loc
843 ;; (file-struct line col marker))
844 ;; (:conc-name compilation--loc->))
845 ;; col line file-struct marker timestamp visited)
847 ;; FIXME: We don't use a defstruct because of compilation-assq which looks up
848 ;; and creates part of the LOC (only the first cons cell containing the COL).
850 (defmacro compilation--make-cdrloc
(line file-struct marker
)
851 `(list ,line
,file-struct
,marker nil
))
852 (defmacro compilation--loc-
>col
(loc) `(car ,loc
))
853 (defmacro compilation--loc-
>line
(loc) `(cadr ,loc
))
854 (defmacro compilation--loc-
>file-struct
(loc) `(nth 2 ,loc
))
855 (defmacro compilation--loc-
>marker
(loc) `(nth 3 ,loc
))
856 ;; (defmacro compilation--loc->timestamp (loc) `(nth 4 ,loc))
857 (defmacro compilation--loc-
>visited
(loc) `(nthcdr 5 ,loc
))
859 ;; FILE-STRUCTURE is a list of
860 ;; ((FILENAME DIRECTORY) FORMATS (LINE LOC ...) ...)
862 ;; FILENAME is a string parsed from an error message. DIRECTORY is a string
863 ;; obtained by following directory change messages. DIRECTORY will be nil for
864 ;; an absolute filename. FORMATS is a list of formats to apply to FILENAME if
865 ;; a file of that name can't be found.
866 ;; The rest of the list is an alist of elements with LINE as key. The keys
867 ;; are either nil or line numbers. If present, nil comes first, followed by
868 ;; the numbers in decreasing order. The LOCs for each line are again an alist
869 ;; ordered the same way. Note that the whole file structure is referenced in
872 (defmacro compilation--make-file-struct
(file-spec formats
&optional loc-tree
)
873 `(cons ,file-spec
(cons ,formats
,loc-tree
)))
874 (defmacro compilation--file-struct-
>file-spec
(fs) `(car ,fs
))
875 (defmacro compilation--file-struct-
>formats
(fs) `(cadr ,fs
))
876 ;; The FORMATS field plays the role of ANCHOR in the loc-tree.
877 (defmacro compilation--file-struct-
>loc-tree
(fs) `(cdr ,fs
))
879 ;; MESSAGE is a list of (LOC TYPE END-LOC)
881 ;; TYPE is 0 for info or 1 for warning if the message matcher identified it as
882 ;; such, 2 otherwise (for a real error). END-LOC is a LOC pointing to the
883 ;; other end, if the parsed message contained a range. If the end of the
884 ;; range didn't specify a COLUMN, it defaults to -1, meaning end of line.
885 ;; These are the value of the `compilation-message' text-properties in the
886 ;; compilation buffer.
888 (cl-defstruct (compilation--message
891 ;; (:type list) ;Old representation.
892 (:constructor compilation--make-message
(loc type end-loc
))
893 (:conc-name compilation--message-
>))
896 (defvar compilation--previous-directory-cache nil
897 "A pair (POS . RES) caching the result of previous directory search.
898 Basically, this pair says that calling
899 (previous-single-property-change POS 'compilation-directory)
900 returned RES, i.e. there is no change of `compilation-directory' between
902 (make-variable-buffer-local 'compilation--previous-directory-cache
)
904 (defun compilation--flush-directory-cache (start _end
)
906 ((or (not compilation--previous-directory-cache
)
907 (<= (car compilation--previous-directory-cache
) start
)))
908 ((or (not (cdr compilation--previous-directory-cache
))
909 (null (marker-buffer (cdr compilation--previous-directory-cache
)))
910 (<= (cdr compilation--previous-directory-cache
) start
))
911 (set-marker (car compilation--previous-directory-cache
) start
))
912 (t (setq compilation--previous-directory-cache nil
))))
914 (defun compilation--previous-directory (pos)
915 "Like (previous-single-property-change POS 'compilation-directory), but faster."
916 ;; This avoids an N² behavior when there's no/few compilation-directory
917 ;; entries, in which case each call to previous-single-property-change
918 ;; ends up having to walk very far back to find the last change.
919 (if (and compilation--previous-directory-cache
920 (< pos
(car compilation--previous-directory-cache
))
921 (or (null (cdr compilation--previous-directory-cache
))
922 (< (cdr compilation--previous-directory-cache
) pos
)))
923 ;; No need to call previous-single-property-change.
924 (cdr compilation--previous-directory-cache
)
926 (let* ((cache (and compilation--previous-directory-cache
927 (<= (car compilation--previous-directory-cache
) pos
)
928 (car compilation--previous-directory-cache
)))
930 (previous-single-property-change
931 pos
'compilation-directory nil cache
))
935 (setq compilation--previous-directory-cache
936 (cons (copy-marker pos
) (if prev
(copy-marker prev
))))
938 ((and prev
(= prev cache
))
940 (set-marker (car compilation--previous-directory-cache
) pos
)
941 (setq compilation--previous-directory-cache
942 (cons (copy-marker pos
) nil
)))
943 (cdr compilation--previous-directory-cache
))
947 (set-marker cache pos
)
948 (setcdr compilation--previous-directory-cache
950 (setq compilation--previous-directory-cache
951 (cons (copy-marker pos
) (if prev
(copy-marker prev
)))))
953 (if (markerp res
) (marker-position res
) res
))))
955 ;; Internal function for calculating the text properties of a directory
956 ;; change message. The compilation-directory property is important, because it
957 ;; is the stack of nested enter-messages. Relative filenames on the following
958 ;; lines are relative to the top of the stack.
959 (defun compilation-directory-properties (idx leave
)
960 (if leave
(setq leave
(match-end leave
)))
961 ;; find previous stack, and push onto it, or if `leave' pop it
962 (let ((dir (compilation--previous-directory (match-beginning 0))))
963 (setq dir
(if dir
(or (get-text-property (1- dir
) 'compilation-directory
)
964 (get-text-property dir
'compilation-directory
))))
965 `(font-lock-face ,(if leave
966 compilation-leave-directory-face
967 compilation-enter-directory-face
)
968 compilation-directory
,(if leave
970 '(nil)) ; nil only isn't a property-change
971 (cons (match-string-no-properties idx
) dir
))
972 ;; Place a `compilation-message' everywhere we change text-properties
973 ;; so compilation--remove-properties can know what to remove.
974 compilation-message
,(compilation--make-message nil
0 nil
)
976 keymap compilation-button-map
977 help-echo
"mouse-2: visit destination directory")))
979 ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
980 ;; KEY element from the ALIST, creating it in the right position if not already
981 ;; present. ALIST structure is
982 ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
983 ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
984 ;; may be nil. The other KEYs are ordered backwards so that growing line
985 ;; numbers can be inserted in front and searching can abort after half the
987 (eval-when-compile ;Don't keep it at runtime if not needed.
988 (defmacro compilation-assq
(key alist
)
991 (car (if (if (null ,key
)
992 (if l2
(null (caar l2
)))
993 (while (if l2
(if (caar l2
) (< ,key
(caar l2
)) t
))
996 (if l2
(eq ,key
(caar l2
))))
998 (setcdr l1
(cons (list ,key
) l2
)))))))
1000 (defun compilation-auto-jump (buffer pos
)
1001 (with-current-buffer buffer
1003 (let ((win (get-buffer-window buffer
0)))
1004 (if win
(set-window-point win pos
)))
1005 (if compilation-auto-jump-to-first-error
1006 (compile-goto-error))))
1008 ;; This function is the central driver, called when font-locking to gather
1009 ;; all information needed to later jump to corresponding source code.
1010 ;; Return a property list with all meta information on this error location.
1012 (defun compilation-error-properties (file line end-line col end-col type fmt
)
1013 (unless (text-property-not-all (match-beginning 0) (point)
1014 'compilation-message nil
)
1017 (setq file
(if (functionp file
) (funcall file
)
1018 (match-string-no-properties file
))))
1020 (unless (file-name-absolute-p file
)
1021 (let ((pos (compilation--previous-directory
1022 (match-beginning 0))))
1024 (or (get-text-property (1- pos
) 'compilation-directory
)
1025 (get-text-property pos
'compilation-directory
)))))))
1026 (setq file
(cons file
(car dir
)))))
1027 ;; This message didn't mention one, get it from previous
1029 ;; Find the previous message.
1030 (previous-single-property-change (point) 'compilation-message
)))
1032 ;; Get the file structure that belongs to it.
1034 (or (get-text-property (1- prev-pos
) 'compilation-message
)
1035 (get-text-property prev-pos
'compilation-message
)))
1038 (compilation--loc->file-struct
1039 (compilation--message->loc prev
)))))
1041 ;; Construct FILE . DIR from that.
1042 (if prev-file-struct
1043 (setq file
(cons (caar prev-file-struct
)
1044 (cadr (car prev-file-struct
)))))))
1046 (setq file
'("*unknown*")))))
1047 ;; All of these fields are optional, get them only if we have an index, and
1048 ;; it matched some part of the message.
1050 (setq line
(match-string-no-properties line
))
1051 (setq line
(string-to-number line
)))
1053 (setq end-line
(match-string-no-properties end-line
))
1054 (setq end-line
(string-to-number end-line
)))
1057 (setq col
(funcall col
))
1059 (setq col
(match-string-no-properties col
))
1060 (setq col
(string-to-number col
)))))
1061 (if (and end-col
(functionp end-col
))
1062 (setq end-col
(funcall end-col
))
1063 (if (and end-col
(setq end-col
(match-string-no-properties end-col
)))
1064 (setq end-col
(- (string-to-number end-col
) -
1))
1065 (if end-line
(setq end-col -
1))))
1066 (if (consp type
) ; not a static type, check what it is.
1067 (setq type
(or (and (car type
) (match-end (car type
)) 1)
1068 (and (cdr type
) (match-end (cdr type
)) 0)
1071 (when (and compilation-auto-jump-to-next
1072 (>= type compilation-skip-threshold
))
1073 (kill-local-variable 'compilation-auto-jump-to-next
)
1074 (run-with-timer 0 nil
'compilation-auto-jump
1075 (current-buffer) (match-beginning 0)))
1077 (compilation-internal-error-properties
1078 file line end-line col end-col type fmt
)))
1080 (defun compilation-move-to-column (col screen
)
1081 "Go to column COL on the current line.
1082 If SCREEN is non-nil, columns are screen columns, otherwise, they are
1084 (setq col
(- col compilation-first-column
))
1086 (move-to-column (max col
0))
1087 (goto-char (min (+ (line-beginning-position) col
) (line-end-position)))))
1089 (defun compilation-internal-error-properties (file line end-line col end-col type fmts
)
1090 "Get the meta-info that will be added as text-properties.
1091 LINE, END-LINE, COL, END-COL are integers or nil.
1092 TYPE can be 0, 1, or 2, meaning error, warning, or just info.
1093 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
1094 FMTS is a list of format specs for transforming the file name.
1095 (See `compilation-error-regexp-alist'.)"
1096 (unless file
(setq file
'("*unknown*")))
1097 (let* ((file-struct (compilation-get-file-structure file fmts
))
1098 ;; Get first already existing marker (if any has one, all have one).
1099 ;; Do this first, as the compilation-assq`s may create new nodes.
1100 (marker-line ; a line structure
1101 (cadr (compilation--file-struct->loc-tree file-struct
)))
1103 (if marker-line
(compilation--loc->marker
(cadr marker-line
))))
1104 (screen-columns compilation-error-screen-columns
)
1105 (first-column compilation-first-column
)
1106 end-marker loc end-loc
)
1107 (if (not (and marker
(marker-buffer marker
)))
1108 (setq marker nil
) ; no valid marker for this file
1109 (unless line
(setq line
1)) ; normalize no linenumber to line 1
1110 (catch 'marker
; find nearest loc, at least one exists
1111 (dolist (x (cddr (compilation--file-struct->loc-tree
1112 file-struct
))) ; Loop over remaining lines.
1113 (if (> (car x
) line
) ; Still bigger.
1114 (setq marker-line x
)
1115 (if (> (- (or (car marker-line
) 1) line
)
1116 (- line
(car x
))) ; Current line is nearer.
1117 (setq marker-line x
))
1118 (throw 'marker t
))))
1119 (setq marker
(compilation--loc->marker
(cadr marker-line
))
1120 marker-line
(or (car marker-line
) 1))
1121 (with-current-buffer (marker-buffer marker
)
1122 (let ((screen-columns
1123 ;; Obey the compilation-error-screen-columns of the target
1124 ;; buffer if its major mode set it buffer-locally.
1125 (if (local-variable-p 'compilation-error-screen-columns
)
1126 compilation-error-screen-columns screen-columns
))
1127 (compilation-first-column
1128 (if (local-variable-p 'compilation-first-column
)
1129 compilation-first-column first-column
)))
1133 (goto-char (marker-position marker
))
1134 ;; Set end-marker if appropriate and go to line.
1135 (if (not (or end-col end-line
))
1136 (beginning-of-line (- line marker-line -
1))
1137 (beginning-of-line (- (or end-line line
) marker-line -
1))
1138 (if (or (null end-col
) (< end-col
0))
1140 (compilation-move-to-column end-col screen-columns
))
1141 (setq end-marker
(point-marker))
1142 (when end-line
(beginning-of-line (- line end-line -
1))))
1144 (compilation-move-to-column col screen-columns
)
1145 (forward-to-indentation 0))
1146 (setq marker
(point-marker)))))))
1148 (setq loc
(compilation-assq line
(compilation--file-struct->loc-tree
1153 end-col
(compilation-assq
1154 end-line
(compilation--file-struct->loc-tree
1156 (if end-col
; use same line element
1157 (compilation-assq end-col loc
))))
1158 (setq loc
(compilation-assq col loc
))
1159 ;; If they are new, make the loc(s) reference the file they point to.
1160 ;; FIXME-omake: there's a problem with timestamps here: the markers
1161 ;; relative to which we computed the current `marker' have a timestamp
1162 ;; almost guaranteed to be different from compilation-buffer-modtime, so if
1163 ;; we use their timestamp, we'll never use `loc' since the timestamp won't
1164 ;; match compilation-buffer-modtime, and if we use
1165 ;; compilation-buffer-modtime then we have different timestamps for
1166 ;; locations that were computed together, which doesn't make sense either.
1167 ;; I think this points to a fundamental problem in our approach to the
1168 ;; "omake -P" problem. --Stef
1170 (setcdr loc
(compilation--make-cdrloc line file-struct marker
)))
1174 (compilation--make-cdrloc (or end-line line
) file-struct
1177 ;; Must start with face
1178 `(font-lock-face ,compilation-message-face
1179 compilation-message
,(compilation--make-message loc type end-loc
)
1181 "mouse-2: visit this file, line and column"
1183 "mouse-2: visit this file and line"
1184 "mouse-2: visit this file"))
1185 keymap compilation-button-map
1186 mouse-face highlight
)))
1188 (defun compilation--put-prop (matchnum prop val
)
1189 (when (and (integerp matchnum
) (match-beginning matchnum
))
1191 (match-beginning matchnum
) (match-end matchnum
)
1194 (defun compilation--remove-properties (&optional start end
)
1195 (with-silent-modifications
1196 ;; When compile.el used font-lock directly, we could just remove all
1197 ;; our text-properties in one go, but now that we manually place
1198 ;; font-lock-face, we have to be careful to only remove the font-lock-face
1200 ;; (remove-list-of-text-properties
1201 ;; (or start (point-min)) (or end (point-max))
1202 ;; '(compilation-debug compilation-directory compilation-message
1203 ;; font-lock-face help-echo mouse-face))
1205 (unless start
(setq start
(point-min)))
1206 (unless end
(setq end
(point-max)))
1207 (compilation--flush-directory-cache start end
)
1210 (setq next
(or (next-single-property-change
1211 start
'compilation-message nil end
)
1213 (when (get-text-property start
'compilation-message
)
1214 (remove-list-of-text-properties
1216 '(compilation-debug compilation-directory compilation-message
1217 font-lock-face help-echo mouse-face
)))
1219 (setq start next
)))))
1221 (defun compilation--parse-region (start end
)
1224 ;; We generally don't like to parse partial lines.
1226 (when (let ((proc (get-buffer-process (current-buffer))))
1227 (and proc
(memq (process-status proc
) '(run open
))))
1228 (setq end
(line-beginning-position))))
1229 (compilation--remove-properties start end
)
1230 (if compilation-parse-errors-function
1231 ;; An old package! Try the compatibility code.
1234 (compilation--compat-parse-errors end
))
1236 ;; compilation-directory-matcher is the only part that really needs to be
1237 ;; parsed sequentially. So we could split it out, handle directories
1238 ;; like syntax-propertize, and the rest as font-lock-keywords. But since
1239 ;; we want to have it work even when font-lock is off, we'd then need to
1240 ;; use our own compilation-parsed text-property to keep track of the parts
1241 ;; that have already been parsed.
1243 (while (re-search-forward (car compilation-directory-matcher
)
1245 (compilation--flush-directory-cache (match-beginning 0) (match-end 0))
1246 (when compilation-debug
1247 (font-lock-append-text-property
1248 (match-beginning 0) (match-end 0)
1250 (vector 'directory compilation-directory-matcher
)))
1251 (dolist (elt (cdr compilation-directory-matcher
))
1252 (add-text-properties (match-beginning (car elt
))
1253 (match-end (car elt
))
1254 (compilation-directory-properties
1255 (car elt
) (cdr elt
)))))
1257 (compilation-parse-errors start end
)))
1259 (defun compilation-parse-errors (start end
&rest rules
)
1260 "Parse errors between START and END.
1261 The errors recognized are the ones specified in RULES which default
1262 to `compilation-error-regexp-alist' if RULES is nil."
1263 (dolist (item (or rules compilation-error-regexp-alist
))
1265 (setq item
(cdr (assq item
1266 compilation-error-regexp-alist-alist
))))
1267 (let ((file (nth 1 item
))
1272 end-line end-col fmt
1275 ;; omake reports some error indented, so skip the indentation.
1276 ;; another solution is to modify (some?) regexps in
1277 ;; `compilation-error-regexp-alist'.
1278 ;; note that omake usage is not limited to ocaml and C (for stubs).
1279 ;; FIXME-omake: Doing it here seems wrong, at least it should depend on
1280 ;; whether or not omake's own error messages are recognized.
1282 ((not (memq 'omake compilation-error-regexp-alist
)) nil
)
1283 ((string-match "\\`\\([^^]\\|\\^\\( \\*\\|\\[\\)\\)" pat
)
1284 nil
) ;; Not anchored or anchored but already allows empty spaces.
1285 (t (setq pat
(concat "^ *" (substring pat
1)))))
1287 (if (consp file
) (setq fmt
(cdr file
) file
(car file
)))
1288 (if (consp line
) (setq end-line
(cdr line
) line
(car line
)))
1289 (if (consp col
) (setq end-col
(cdr col
) col
(car col
)))
1291 (if (functionp line
)
1292 ;; The old compile.el had here an undocumented hook that
1293 ;; allowed `line' to be a function that computed the actual
1294 ;; error location. Let's do our best.
1297 (while (re-search-forward pat end t
)
1299 (when compilation-debug
1300 (font-lock-append-text-property
1301 (match-beginning 0) (match-end 0)
1302 'compilation-debug
(vector 'functionp item
)))
1303 (add-text-properties
1304 (match-beginning 0) (match-end 0)
1305 (compilation--compat-error-properties
1306 (funcall line
(cons (match-string file
)
1307 (cons default-directory
1309 (if col
(match-string col
))))))
1310 (compilation--put-prop
1311 file
'font-lock-face compilation-error-face
)))
1313 (unless (or (null (nth 5 item
)) (integerp (nth 5 item
)))
1314 (error "HYPERLINK should be an integer: %s" (nth 5 item
)))
1317 (while (re-search-forward pat end t
)
1318 (when (setq props
(compilation-error-properties
1319 file line end-line col end-col
(or type
2) fmt
))
1321 (when (integerp file
)
1322 (compilation--put-prop
1323 file
'font-lock-face
1325 (compilation-face type
)
1326 (symbol-value (aref [compilation-info-face
1327 compilation-warning-face
1328 compilation-error-face
]
1331 (compilation--put-prop
1332 line
'font-lock-face compilation-line-face
)
1333 (compilation--put-prop
1334 end-line
'font-lock-face compilation-line-face
)
1336 (compilation--put-prop
1337 col
'font-lock-face compilation-column-face
)
1338 (compilation--put-prop
1339 end-col
'font-lock-face compilation-column-face
)
1342 (dolist (extra-item (nthcdr 6 item
))
1343 (let ((mn (pop extra-item
)))
1344 (when (match-beginning mn
)
1345 (let ((face (eval (car extra-item
))))
1348 ((or (symbolp face
) (stringp face
))
1350 (match-beginning mn
) (match-end mn
)
1351 'font-lock-face face
))
1353 (eq (car face
) 'face
)
1354 (or (symbolp (cadr face
))
1355 (stringp (cadr face
))))
1357 (match-beginning mn
) (match-end mn
)
1358 'font-lock-face
(cadr face
))
1359 (add-text-properties
1360 (match-beginning mn
) (match-end mn
)
1363 (error "Don't know how to handle face %S"
1365 (let ((mn (or (nth 5 item
) 0)))
1366 (when compilation-debug
1367 (font-lock-append-text-property
1368 (match-beginning 0) (match-end 0)
1369 'compilation-debug
(vector 'std item props
)))
1370 (add-text-properties
1371 (match-beginning mn
) (match-end mn
)
1373 (font-lock-append-text-property
1374 (match-beginning mn
) (match-end mn
)
1375 'font-lock-face
(cadr props
)))))))))
1377 (defvar compilation--parsed -
1)
1378 (make-variable-buffer-local 'compilation--parsed
)
1380 (defun compilation--ensure-parse (limit)
1381 "Make sure the text has been parsed up to LIMIT."
1384 (setq limit
(line-beginning-position 2))
1385 (unless (markerp compilation--parsed
)
1386 ;; We use a marker for compilation--parsed so that users (such as
1387 ;; grep.el) don't need to flush-parse when they modify the buffer
1388 ;; in a way that impacts buffer positions but does not require
1390 (setq compilation--parsed
(point-min-marker)))
1391 (when (< compilation--parsed limit
)
1392 (let ((start (max compilation--parsed
(point-min))))
1393 (move-marker compilation--parsed limit
)
1395 (forward-line 0) ;Not line-beginning-position: ignore (comint) fields.
1396 (with-silent-modifications
1397 (compilation--parse-region (point) compilation--parsed
)))))
1400 (defun compilation--flush-parse (start _end
)
1401 "Mark the region between START and END for re-parsing."
1402 (if (markerp compilation--parsed
)
1403 (move-marker compilation--parsed
(min start compilation--parsed
))))
1405 (defun compilation-mode-font-lock-keywords ()
1406 "Return expressions to highlight in Compilation mode."
1408 '((compilation--ensure-parse))
1409 compilation-mode-font-lock-keywords
))
1411 (defun compilation-read-command (command)
1412 (read-shell-command "Compile command: " command
1413 (if (equal (car compile-history
) command
)
1414 '(compile-history .
1)
1419 (defun compile (command &optional comint
)
1420 "Compile the program including the current buffer. Default: run `make'.
1421 Runs COMMAND, a shell command, in a separate process asynchronously
1422 with output going to the buffer `*compilation*'.
1424 You can then use the command \\[next-error] to find the next error message
1425 and move to the source code that caused it.
1427 If optional second arg COMINT is t the buffer will be in Comint mode with
1428 `compilation-shell-minor-mode'.
1430 Interactively, prompts for the command if the variable
1431 `compilation-read-command' is non-nil; otherwise uses`compile-command'.
1432 With prefix arg, always prompts.
1433 Additionally, with universal prefix arg, compilation buffer will be in
1434 comint mode, i.e. interactive.
1436 To run more than one compilation at once, start one then rename
1437 the \`*compilation*' buffer to some other name with
1438 \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
1439 It will create a new \`*compilation*' buffer.
1441 On most systems, termination of the main compilation process
1442 kills its subprocesses.
1444 The name used for the buffer is actually whatever is returned by
1445 the function in `compilation-buffer-name-function', so you can set that
1446 to a function that generates a unique name."
1449 (let ((command (eval compile-command
)))
1450 (if (or compilation-read-command current-prefix-arg
)
1451 (compilation-read-command command
)
1453 (consp current-prefix-arg
)))
1454 (unless (equal command
(eval compile-command
))
1455 (setq compile-command command
))
1456 (save-some-buffers (not compilation-ask-about-save
)
1457 compilation-save-buffers-predicate
)
1458 (setq-default compilation-directory default-directory
)
1459 (compilation-start command comint
))
1461 ;; run compile with the default command line
1462 (defun recompile (&optional edit-command
)
1463 "Re-compile the program including the current buffer.
1464 If this is run in a Compilation mode buffer, re-use the arguments from the
1465 original use. Otherwise, recompile using `compile-command'.
1466 If the optional argument `edit-command' is non-nil, the command can be edited."
1468 (save-some-buffers (not compilation-ask-about-save
)
1469 compilation-save-buffers-predicate
)
1470 (let ((default-directory (or compilation-directory default-directory
)))
1472 (setcar compilation-arguments
1473 (compilation-read-command (car compilation-arguments
))))
1474 (apply 'compilation-start
(or compilation-arguments
1475 `(,(eval compile-command
))))))
1477 (defcustom compilation-scroll-output nil
1478 "Non-nil to scroll the *compilation* buffer window as output appears.
1480 Setting it causes the Compilation mode commands to put point at the
1481 end of their output window so that the end of the output is always
1482 visible rather than the beginning.
1484 The value `first-error' stops scrolling at the first error, and leaves
1485 point on its location in the *compilation* buffer."
1486 :type
'(choice (const :tag
"No scrolling" nil
)
1487 (const :tag
"Scroll compilation output" t
)
1488 (const :tag
"Stop scrolling at the first error" first-error
))
1490 :group
'compilation
)
1493 (defun compilation-buffer-name (name-of-mode mode-command name-function
)
1494 "Return the name of a compilation buffer to use.
1495 If NAME-FUNCTION is non-nil, call it with one argument NAME-OF-MODE
1496 to determine the buffer name.
1497 Likewise if `compilation-buffer-name-function' is non-nil.
1498 If current buffer has the major mode MODE-COMMAND,
1499 return the name of the current buffer, so that it gets reused.
1500 Otherwise, construct a buffer name from NAME-OF-MODE."
1501 (cond (name-function
1502 (funcall name-function name-of-mode
))
1503 (compilation-buffer-name-function
1504 (funcall compilation-buffer-name-function name-of-mode
))
1505 ((eq mode-command major-mode
)
1508 (concat "*" (downcase name-of-mode
) "*"))))
1510 (defcustom compilation-always-kill nil
1511 "If t, always kill a running compilation process before starting a new one.
1512 If nil, ask to kill it."
1515 :group
'compilation
)
1518 (defun compilation-start (command &optional mode name-function highlight-regexp
)
1519 "Run compilation command COMMAND (low level interface).
1520 If COMMAND starts with a cd command, that becomes the `default-directory'.
1521 The rest of the arguments are optional; for them, nil means use the default.
1523 MODE is the major mode to set in the compilation buffer. Mode
1524 may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
1526 If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
1527 to determine the buffer name. Otherwise, the default is to
1528 reuses the current buffer if it has the proper major mode,
1529 else use or create a buffer with name based on the major mode.
1531 If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
1532 the matching section of the visited source line; the default is to use the
1533 global value of `compilation-highlight-regexp'.
1535 Returns the compilation buffer created."
1536 (or mode
(setq mode
'compilation-mode
))
1537 (let* ((name-of-mode
1540 (replace-regexp-in-string "-mode\\'" "" (symbol-name mode
))))
1541 (thisdir default-directory
)
1542 (thisenv compilation-environment
)
1544 (with-current-buffer
1547 (compilation-buffer-name name-of-mode mode name-function
)))
1548 (let ((comp-proc (get-buffer-process (current-buffer))))
1550 (if (or (not (eq (process-status comp-proc
) 'run
))
1551 (eq (process-query-on-exit-flag comp-proc
) nil
)
1553 (format "A %s process is running; kill it? "
1557 (interrupt-process comp-proc
)
1559 (delete-process comp-proc
))
1561 (error "Cannot have two processes in `%s' at once"
1563 ;; first transfer directory from where M-x compile was called
1564 (setq default-directory thisdir
)
1565 ;; Make compilation buffer read-only. The filter can still write it.
1566 ;; Clear out the compilation buffer.
1567 (let ((inhibit-read-only t
)
1568 (default-directory thisdir
))
1569 ;; Then evaluate a cd command if any, but don't perform it yet, else
1570 ;; start-command would do it again through the shell: (cd "..") AND
1571 ;; sh -c "cd ..; make"
1573 ((not (string-match "\\`\\s *cd\\(?:\\s +\\(\\S +?\\|'[^']*'\\|\"\\(?:[^\"`$\\]\\|\\\\.\\)*\"\\)\\)?\\s *[;&\n]"
1576 ((not (match-end 1)) "~")
1577 ((eq (aref command
(match-beginning 1)) ?
\')
1578 (substring command
(1+ (match-beginning 1))
1579 (1- (match-end 1))))
1580 ((eq (aref command
(match-beginning 1)) ?
\")
1581 (replace-regexp-in-string
1583 (substring command
(1+ (match-beginning 1))
1584 (1- (match-end 1)))))
1585 (t (substitute-env-vars (match-string 1 command
)))))
1587 ;; Select the desired mode.
1588 (if (not (eq mode t
))
1590 (buffer-disable-undo)
1592 (setq buffer-read-only nil
)
1593 (with-no-warnings (comint-mode))
1594 (compilation-shell-minor-mode))
1595 ;; Remember the original dir, so we can use it when we recompile.
1596 ;; default-directory' can't be used reliably for that because it may be
1597 ;; affected by the special handling of "cd ...;".
1598 ;; NB: must be done after (funcall mode) as that resets local variables
1599 (set (make-local-variable 'compilation-directory
) thisdir
)
1600 (set (make-local-variable 'compilation-environment
) thisenv
)
1601 (if highlight-regexp
1602 (set (make-local-variable 'compilation-highlight-regexp
)
1604 (if (or compilation-auto-jump-to-first-error
1605 (eq compilation-scroll-output
'first-error
))
1606 (set (make-local-variable 'compilation-auto-jump-to-next
) t
))
1607 ;; Output a mode setter, for saving and later reloading this buffer.
1608 (insert "-*- mode: " name-of-mode
1609 "; default-directory: "
1610 (prin1-to-string (abbreviate-file-name default-directory
))
1612 (format "%s started at %s\n\n"
1614 (substring (current-time-string) 0 19))
1615 ;; The command could be split into several lines, see
1616 ;; `rgrep' for example. We want to display it as one
1618 (apply 'concat
(split-string command
(regexp-quote "\\\n") t
))
1620 (setq thisdir default-directory
))
1621 (set-buffer-modified-p nil
))
1622 ;; Pop up the compilation buffer.
1623 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html
1624 (setq outwin
(display-buffer outbuf
))
1625 (with-current-buffer outbuf
1626 (let ((process-environment
1628 compilation-environment
1629 (if (if (boundp 'system-uses-terminfo
);`If' for compiler warning.
1630 system-uses-terminfo
)
1631 (list "TERM=dumb" "TERMCAP="
1632 (format "COLUMNS=%d" (window-width)))
1634 (format "TERMCAP=emacs:co#%d:tc=unknown:"
1636 ;; Set the EMACS variable, but
1637 ;; don't override users' setting of $EMACS.
1638 (unless (getenv "EMACS")
1640 (list "INSIDE_EMACS=t")
1641 (copy-sequence process-environment
))))
1642 (set (make-local-variable 'compilation-arguments
)
1643 (list command mode name-function highlight-regexp
))
1644 (set (make-local-variable 'revert-buffer-function
)
1645 'compilation-revert-buffer
)
1646 (set-window-start outwin
(point-min))
1648 ;; Position point as the user will see it.
1649 (let ((desired-visible-point
1650 ;; Put it at the end if `compilation-scroll-output' is set.
1651 (if compilation-scroll-output
1653 ;; Normally put it at the top.
1655 (if (eq outwin
(selected-window))
1656 (goto-char desired-visible-point
)
1657 (set-window-point outwin desired-visible-point
)))
1659 ;; The setup function is called before compilation-set-window-height
1660 ;; so it can set the compilation-window-height buffer locally.
1661 (if compilation-process-setup-function
1662 (funcall compilation-process-setup-function
))
1663 (compilation-set-window-height outwin
)
1664 ;; Start the compilation.
1665 (if (fboundp 'start-process
)
1668 ;; comint uses `start-file-process'.
1672 outbuf
(downcase mode-name
)
1673 (if (file-remote-p default-directory
)
1676 nil
`("-c" ,command
))))
1677 (start-file-process-shell-command (downcase mode-name
)
1679 ;; Make the buffer's mode line show process state.
1680 (setq mode-line-process
1681 '(:propertize
":%s" face compilation-mode-line-run
))
1683 ;; Set the process as killable without query by default.
1684 ;; This allows us to start a new compilation without
1685 ;; getting prompted.
1686 (when compilation-always-kill
1687 (set-process-query-on-exit-flag proc nil
))
1689 (set-process-sentinel proc
'compilation-sentinel
)
1691 ;; Keep the comint filter, since it's needed for proper
1692 ;; handling of the prompts.
1693 (set-process-filter proc
'compilation-filter
))
1694 ;; Use (point-max) here so that output comes in
1695 ;; after the initial text,
1696 ;; regardless of where the user sees point.
1697 (set-marker (process-mark proc
) (point-max) outbuf
)
1698 (when compilation-disable-input
1700 (process-send-eof proc
)
1701 ;; The process may have exited already.
1703 (run-hook-with-args 'compilation-start-hook proc
)
1704 (setq compilation-in-progress
1705 (cons proc compilation-in-progress
)))
1706 ;; No asynchronous processes available.
1707 (message "Executing `%s'..." command
)
1708 ;; Fake mode line display as if `start-process' were run.
1709 (setq mode-line-process
1710 '(:propertize
":run" face compilation-mode-line-run
))
1711 (force-mode-line-update)
1712 (sit-for 0) ; Force redisplay
1714 ;; Insert the output at the end, after the initial text,
1715 ;; regardless of where the user sees point.
1716 (goto-char (point-max))
1717 (let* ((inhibit-read-only t
) ; call-process needs to modify outbuf
1718 (compilation-filter-start (point))
1719 (status (call-process shell-file-name nil outbuf nil
"-c"
1721 (run-hooks 'compilation-filter-hook
)
1722 (cond ((numberp status
)
1723 (compilation-handle-exit
1727 (format "exited abnormally with code %d\n" status
))))
1729 (compilation-handle-exit 'signal status
1730 (concat status
"\n")))
1732 (compilation-handle-exit 'bizarre status status
)))))
1733 (set-buffer-modified-p nil
)
1734 (message "Executing `%s'...done" command
)))
1735 ;; Now finally cd to where the shell started make/grep/...
1736 (setq default-directory thisdir
)
1737 ;; The following form selected outwin ever since revision 1.183,
1738 ;; so possibly messing up point in some other window (bug#1073).
1739 ;; Moved into the scope of with-current-buffer, though still with
1740 ;; complete disregard for the case when compilation-scroll-output
1741 ;; equals 'first-error (martin 2008-10-04).
1742 (when compilation-scroll-output
1743 (goto-char (point-max))))
1745 ;; Make it so the next C-x ` will use this buffer.
1746 (setq next-error-last-buffer outbuf
)))
1748 (defun compilation-set-window-height (window)
1749 "Set the height of WINDOW according to `compilation-window-height'."
1750 (let ((height (buffer-local-value 'compilation-window-height
(window-buffer window
))))
1752 (window-full-width-p window
)
1753 ;; If window is alone in its frame, aside from a minibuffer,
1754 ;; don't change its height.
1755 (not (eq window
(frame-root-window (window-frame window
))))
1756 ;; Stef said that doing the saves in this order is safer:
1758 (save-selected-window
1759 (select-window window
)
1760 (enlarge-window (- height
(window-height))))))))
1762 (defvar compilation-menu-map
1763 (let ((map (make-sparse-keymap "Errors"))
1764 (opt-map (make-sparse-keymap "Skip")))
1765 (define-key map
[stop-subjob
]
1766 '(menu-item "Stop Compilation" kill-compilation
1767 :help
"Kill the process made by the M-x compile or M-x grep commands"))
1768 (define-key map
[compilation-mode-separator3
]
1770 (define-key map
[compilation-next-error-follow-minor-mode
]
1772 "Auto Error Display" next-error-follow-minor-mode
1773 :help
"Display the error under cursor when moving the cursor"
1774 :button
(:toggle . next-error-follow-minor-mode
)))
1775 (define-key map
[compilation-skip
]
1776 (cons "Skip Less Important Messages" opt-map
))
1777 (define-key opt-map
[compilation-skip-none
]
1778 '(menu-item "Don't Skip Any Messages"
1781 (customize-set-variable 'compilation-skip-threshold
0))
1782 :help
"Do not skip any type of messages"
1783 :button
(:radio .
(eq compilation-skip-threshold
0))))
1784 (define-key opt-map
[compilation-skip-info
]
1785 '(menu-item "Skip Info"
1788 (customize-set-variable 'compilation-skip-threshold
1))
1789 :help
"Skip anything less than warning"
1790 :button
(:radio .
(eq compilation-skip-threshold
1))))
1791 (define-key opt-map
[compilation-skip-warning-and-info
]
1792 '(menu-item "Skip Warnings and Info"
1795 (customize-set-variable 'compilation-skip-threshold
2))
1796 :help
"Skip over Warnings and Info, stop for errors"
1797 :button
(:radio .
(eq compilation-skip-threshold
2))))
1798 (define-key map
[compilation-mode-separator2
]
1800 (define-key map
[compilation-first-error
]
1801 '(menu-item "First Error" first-error
1802 :help
"Restart at the first error, visit corresponding source code"))
1803 (define-key map
[compilation-previous-error
]
1804 '(menu-item "Previous Error" previous-error
1805 :help
"Visit previous `next-error' message and corresponding source code"))
1806 (define-key map
[compilation-next-error
]
1807 '(menu-item "Next Error" next-error
1808 :help
"Visit next `next-error' message and corresponding source code"))
1811 (defvar compilation-minor-mode-map
1812 (let ((map (make-sparse-keymap)))
1813 (set-keymap-parent map special-mode-map
)
1814 (define-key map
[mouse-2
] 'compile-goto-error
)
1815 (define-key map
[follow-link
] 'mouse-face
)
1816 (define-key map
"\C-c\C-c" 'compile-goto-error
)
1817 (define-key map
"\C-m" 'compile-goto-error
)
1818 (define-key map
"\C-c\C-k" 'kill-compilation
)
1819 (define-key map
"\M-n" 'compilation-next-error
)
1820 (define-key map
"\M-p" 'compilation-previous-error
)
1821 (define-key map
"\M-{" 'compilation-previous-file
)
1822 (define-key map
"\M-}" 'compilation-next-file
)
1823 (define-key map
"g" 'recompile
) ; revert
1824 ;; Set up the menu-bar
1825 (define-key map
[menu-bar compilation
]
1826 (cons "Errors" compilation-menu-map
))
1828 "Keymap for `compilation-minor-mode'.")
1830 (defvar compilation-shell-minor-mode-map
1831 (let ((map (make-sparse-keymap)))
1832 (define-key map
"\M-\C-m" 'compile-goto-error
)
1833 (define-key map
"\M-\C-n" 'compilation-next-error
)
1834 (define-key map
"\M-\C-p" 'compilation-previous-error
)
1835 (define-key map
"\M-{" 'compilation-previous-file
)
1836 (define-key map
"\M-}" 'compilation-next-file
)
1837 ;; Set up the menu-bar
1838 (define-key map
[menu-bar compilation
]
1839 (cons "Errors" compilation-menu-map
))
1841 "Keymap for `compilation-shell-minor-mode'.")
1843 (defvar compilation-button-map
1844 (let ((map (make-sparse-keymap)))
1845 (define-key map
[mouse-2
] 'compile-goto-error
)
1846 (define-key map
[follow-link
] 'mouse-face
)
1847 (define-key map
"\C-m" 'compile-goto-error
)
1849 "Keymap for compilation-message buttons.")
1850 (fset 'compilation-button-map compilation-button-map
)
1852 (defvar compilation-mode-map
1853 (let ((map (make-sparse-keymap)))
1854 ;; Don't inherit from compilation-minor-mode-map,
1855 ;; because that introduces a menu bar item we don't want.
1856 ;; That confuses C-down-mouse-3.
1857 (set-keymap-parent map special-mode-map
)
1858 (define-key map
[mouse-2
] 'compile-goto-error
)
1859 (define-key map
[follow-link
] 'mouse-face
)
1860 (define-key map
"\C-c\C-c" 'compile-goto-error
)
1861 (define-key map
"\C-m" 'compile-goto-error
)
1862 (define-key map
"\C-c\C-k" 'kill-compilation
)
1863 (define-key map
"\M-n" 'compilation-next-error
)
1864 (define-key map
"\M-p" 'compilation-previous-error
)
1865 (define-key map
"\M-{" 'compilation-previous-file
)
1866 (define-key map
"\M-}" 'compilation-next-file
)
1867 (define-key map
"\t" 'compilation-next-error
)
1868 (define-key map
[backtab] 'compilation-previous-error)
1869 (define-key map "g" 'recompile) ; revert
1871 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
1873 ;; Set up the menu-bar
1874 (let ((submap (make-sparse-keymap "Compile")))
1875 (define-key map [menu-bar compilation]
1876 (cons "Compile" submap))
1877 (set-keymap-parent submap compilation-menu-map))
1878 (define-key map [menu-bar compilation compilation-separator2]
1880 (define-key map [menu-bar compilation compilation-grep]
1881 '(menu-item "Search Files (grep)..." grep
1882 :help "Run grep, with user-specified args, and collect output in a buffer"))
1883 (define-key map [menu-bar compilation compilation-recompile]
1884 '(menu-item "Recompile" recompile
1885 :help "Re-compile the program including the current buffer"))
1886 (define-key map [menu-bar compilation compilation-compile]
1887 '(menu-item "Compile..." compile
1888 :help "Compile the program including the current buffer. Default: run `make'"))
1890 "Keymap for compilation log buffers.
1891 `compilation-minor-mode-map' is a parent of this.")
1893 (defvar compilation-mode-tool-bar-map
1894 ;; When bootstrapping, tool-bar-map is not properly initialized yet,
1895 ;; so don't do anything.
1896 (when (keymapp tool-bar-map)
1897 (let ((map (copy-keymap tool-bar-map)))
1898 (define-key map [undo] nil)
1899 (define-key map [separator-2] nil)
1900 (define-key-after map [separator-compile] menu-bar-separator)
1901 (tool-bar-local-item
1902 "left-arrow" 'previous-error-no-select 'previous-error-no-select map
1904 :help "Goto previous error")
1905 (tool-bar-local-item
1906 "right-arrow" 'next-error-no-select 'next-error-no-select map
1908 :help "Goto next error")
1909 (tool-bar-local-item
1910 "cancel" 'kill-compilation 'kill-compilation map
1911 :enable '(let ((buffer (compilation-find-buffer)))
1912 (get-buffer-process buffer))
1913 :help "Stop compilation")
1914 (tool-bar-local-item
1915 "refresh" 'recompile 'recompile map
1916 :help "Restart compilation")
1919 (put 'compilation-mode 'mode-class 'special)
1922 (defun compilation-mode (&optional name-of-mode)
1923 "Major mode for compilation log buffers.
1924 \\<compilation-mode-map>To visit the source for a line-numbered error,
1925 move point to the error message line and type \\[compile-goto-error].
1926 To kill the compilation, type \\[kill-compilation].
1928 Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
1930 \\{compilation-mode-map}"
1932 (kill-all-local-variables)
1933 (use-local-map compilation-mode-map)
1934 ;; Let windows scroll along with the output.
1935 (set (make-local-variable 'window-point-insertion-type) t)
1936 (set (make-local-variable 'tool-bar-map) compilation-mode-tool-bar-map)
1937 (setq major-mode 'compilation-mode ; FIXME: Use define-derived-mode.
1938 mode-name (or name-of-mode "Compilation"))
1939 (set (make-local-variable 'page-delimiter)
1940 compilation-page-delimiter)
1941 ;; (set (make-local-variable 'compilation-buffer-modtime) nil)
1943 (setq buffer-read-only t)
1944 (run-mode-hooks 'compilation-mode-hook))
1947 (put 'define-compilation-mode 'doc-string-elt 3)
1949 (defmacro define-compilation-mode (mode name doc &rest body)
1950 "This is like `define-derived-mode' without the PARENT argument.
1951 The parent is always `compilation-mode' and the customizable `compilation-...'
1952 variables are also set from the name of the mode you have chosen,
1953 by replacing the first word, e.g `compilation-scroll-output' from
1954 `grep-scroll-output' if that variable exists."
1955 (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
1956 `(define-derived-mode ,mode compilation-mode ,name
1958 ,@(mapcar (lambda (v)
1960 (intern-soft (replace-regexp-in-string
1961 "^compilation" mode-name
1964 (or (boundp (cdr v))
1965 ;; FIXME: This is hackish, using undocumented info.
1966 (if (boundp 'byte-compile-bound-variables)
1967 (memq (cdr v) byte-compile-bound-variables)))
1968 `(set (make-local-variable ',(car v)) ,(cdr v))))
1969 '(compilation-buffer-name-function
1970 compilation-directory-matcher
1972 compilation-error-regexp-alist
1973 compilation-error-regexp-alist-alist
1974 compilation-error-screen-columns
1975 compilation-finish-function
1976 compilation-finish-functions
1977 compilation-first-column
1978 compilation-mode-font-lock-keywords
1979 compilation-page-delimiter
1980 compilation-parse-errors-filename-function
1981 compilation-process-setup-function
1982 compilation-scroll-output
1983 compilation-search-path
1984 compilation-skip-threshold
1985 compilation-window-height))
1988 (defun compilation-revert-buffer (ignore-auto noconfirm)
1989 (if buffer-file-name
1990 (let (revert-buffer-function)
1991 (revert-buffer ignore-auto noconfirm))
1992 (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
1993 (apply 'compilation-start compilation-arguments))))
1995 (defvar compilation-current-error nil
1996 "Marker to the location from where the next error will be found.
1997 The global commands next/previous/first-error/goto-error use this.")
1999 (defvar compilation-messages-start nil
2000 "Buffer position of the beginning of the compilation messages.
2001 If nil, use the beginning of buffer.")
2003 (defun compilation-setup (&optional minor)
2004 "Prepare the buffer for the compilation parsing commands to work.
2005 Optional argument MINOR indicates this is called from
2006 `compilation-minor-mode'."
2007 (make-local-variable 'compilation-current-error)
2008 (make-local-variable 'compilation-messages-start)
2009 (make-local-variable 'compilation-error-screen-columns)
2010 (make-local-variable 'overlay-arrow-position)
2011 (set (make-local-variable 'overlay-arrow-string) "")
2012 (setq next-error-overlay-arrow-position nil)
2013 (add-hook 'kill-buffer-hook
2014 (lambda () (setq next-error-overlay-arrow-position nil)) nil t)
2015 ;; Note that compilation-next-error-function is for interfacing
2016 ;; with the next-error function in simple.el, and it's only
2017 ;; coincidentally named similarly to compilation-next-error.
2018 (setq next-error-function 'compilation-next-error-function)
2019 (set (make-local-variable 'comint-file-name-prefix)
2020 (or (file-remote-p default-directory) ""))
2021 (set (make-local-variable 'compilation-locs)
2022 (make-hash-table :test 'equal :weakness 'value))
2023 ;; It's generally preferable to use after-change-functions since they
2024 ;; can be subject to combine-after-change-calls, but if we do that, we risk
2025 ;; running our hook after font-lock, resulting in incorrect refontification.
2026 (add-hook 'before-change-functions 'compilation--flush-parse nil t)
2027 ;; Also for minor mode, since it's not permanent-local.
2028 (add-hook 'change-major-mode-hook #'compilation--remove-properties nil t)
2031 (font-lock-add-keywords nil (compilation-mode-font-lock-keywords))
2033 (font-lock-fontify-buffer)))
2034 (setq font-lock-defaults '(compilation-mode-font-lock-keywords t))))
2036 (defun compilation--unsetup ()
2037 ;; Only for minor mode.
2038 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
2039 (remove-hook 'before-change-functions 'compilation--flush-parse t)
2040 (kill-local-variable 'compilation--parsed)
2041 (compilation--remove-properties)
2043 (font-lock-fontify-buffer)))
2046 (define-minor-mode compilation-shell-minor-mode
2047 "Toggle Compilation Shell minor mode.
2048 With a prefix argument ARG, enable Compilation Shell minor mode
2049 if ARG is positive, and disable it otherwise. If called from
2050 Lisp, enable the mode if ARG is omitted or nil.
2052 When Compilation Shell minor mode is enabled, all the
2053 error-parsing commands of the Compilation major mode are
2054 available but bound to keys that don't collide with Shell mode.
2055 See `compilation-mode'."
2056 nil " Shell-Compile"
2058 (if compilation-shell-minor-mode
2059 (compilation-setup t)
2060 (compilation--unsetup)))
2063 (define-minor-mode compilation-minor-mode
2064 "Toggle Compilation minor mode.
2065 With a prefix argument ARG, enable Compilation minor mode if ARG
2066 is positive, and disable it otherwise. If called from Lisp,
2067 enable the mode if ARG is omitted or nil.
2069 When Compilation minor mode is enabled, all the error-parsing
2070 commands of Compilation major mode are available. See
2071 `compilation-mode'."
2074 (if compilation-minor-mode
2075 (compilation-setup t)
2076 (compilation--unsetup)))
2078 (defun compilation-handle-exit (process-status exit-status msg)
2079 "Write MSG in the current buffer and hack its `mode-line-process'."
2080 (let ((inhibit-read-only t)
2081 (status (if compilation-exit-message-function
2082 (funcall compilation-exit-message-function
2083 process-status exit-status msg)
2084 (cons msg exit-status)))
2087 (cur-buffer (current-buffer)))
2088 ;; Record where we put the message, so we can ignore it later on.
2090 (insert ?\n mode-name " " (car status))
2091 (if (and (numberp compilation-window-height)
2092 (zerop compilation-window-height))
2093 (message "%s" (cdr status)))
2096 (insert " at " (substring (current-time-string) 0 19))
2097 (goto-char (point-max))
2098 ;; Prevent that message from being recognized as a compilation error.
2099 (add-text-properties omax (point)
2100 (append '(compilation-handle-exit t) nil))
2101 (setq mode-line-process
2102 (let ((out-string (format ":%s [%s]" process-status (cdr status)))
2103 (msg (format "%s %s" mode-name
2104 (replace-regexp-in-string "\n?$" ""
2107 (propertize out-string
2109 'face (if (> exit-status 0)
2110 'compilation-mode-line-fail
2111 'compilation-mode-line-exit))))
2112 ;; Force mode line redisplay soon.
2113 (force-mode-line-update)
2114 (if (and opoint (< opoint omax))
2117 (if compilation-finish-function
2118 (funcall compilation-finish-function cur-buffer msg)))
2119 (run-hook-with-args 'compilation-finish-functions cur-buffer msg)))
2121 ;; Called when compilation process changes state.
2122 (defun compilation-sentinel (proc msg)
2123 "Sentinel for compilation buffers."
2124 (if (memq (process-status proc) '(exit signal))
2125 (let ((buffer (process-buffer proc)))
2126 (if (null (buffer-name buffer))
2128 (set-process-buffer proc nil)
2129 (with-current-buffer buffer
2130 ;; Write something in the compilation buffer
2131 ;; and hack its mode line.
2132 (compilation-handle-exit (process-status proc)
2133 (process-exit-status proc)
2135 ;; Since the buffer and mode line will show that the
2136 ;; process is dead, we can delete it now. Otherwise it
2137 ;; will stay around until M-x list-processes.
2138 (delete-process proc)))
2139 (setq compilation-in-progress (delq proc compilation-in-progress)))))
2141 (defun compilation-filter (proc string)
2142 "Process filter for compilation buffers.
2143 Just inserts the text,
2144 handles carriage motion (see `comint-inhibit-carriage-motion'),
2145 and runs `compilation-filter-hook'."
2146 (when (buffer-live-p (process-buffer proc))
2147 (with-current-buffer (process-buffer proc)
2148 (let ((inhibit-read-only t)
2149 ;; `save-excursion' doesn't use the right insertion-type for us.
2150 (pos (copy-marker (point) t))
2151 ;; `save-restriction' doesn't use the right insertion type either:
2152 ;; If we are inserting at the end of the accessible part of the
2153 ;; buffer, keep the inserted text visible.
2154 (min (point-min-marker))
2155 (max (copy-marker (point-max) t))
2156 (compilation-filter-start (marker-position (process-mark proc))))
2160 (goto-char compilation-filter-start)
2161 ;; We used to use `insert-before-markers', so that windows with
2162 ;; point at `process-mark' scroll along with the output, but we
2163 ;; now use window-point-insertion-type instead.
2165 (unless comint-inhibit-carriage-motion
2166 (comint-carriage-motion (process-mark proc) (point)))
2167 (set-marker (process-mark proc) (point))
2168 ;; (set (make-local-variable 'compilation-buffer-modtime)
2170 (run-hooks 'compilation-filter-hook))
2172 (narrow-to-region min max)
2173 (set-marker pos nil)
2174 (set-marker min nil)
2175 (set-marker max nil))))))
2177 ;;; test if a buffer is a compilation buffer, assuming we're in the buffer
2178 (defsubst compilation-buffer-internal-p ()
2179 "Test if inside a compilation buffer."
2180 (local-variable-p 'compilation-locs))
2182 ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p
2183 (defsubst compilation-buffer-p (buffer)
2184 "Test if BUFFER is a compilation buffer."
2185 (with-current-buffer buffer
2186 (compilation-buffer-internal-p)))
2188 (defmacro compilation-loop (< property-change 1+ error limit)
2192 (or (setq pt (,property-change pt 'compilation-message))
2193 ;; Handle the case where where the first error message is
2194 ;; at the start of the buffer, and n < 0.
2195 (if (or (eq (get-text-property ,limit 'compilation-message)
2196 (get-text-property opt 'compilation-message))
2198 (user-error ,error compilation-error)
2200 ;; prop 'compilation-message usually has 2 changes, on and off, so
2202 (or (setq msg (get-text-property pt 'compilation-message))
2203 (if (setq pt (,property-change pt 'compilation-message nil ,limit))
2204 (setq msg (get-text-property pt 'compilation-message)))
2205 (user-error ,error compilation-error))
2206 (or (< (compilation--message->type msg) compilation-skip-threshold)
2209 (setq last (compilation--loc->file-struct
2210 (compilation--message->loc msg))))
2212 (if compilation-skip-visited
2213 (compilation--loc->visited (compilation--message->loc msg)))
2214 (if compilation-skip-to-next-location
2215 (eq (compilation--message->loc msg) loc))
2216 ;; count this message only if none of the above are true
2217 (setq n (,1+ n))))))
2219 (defun compilation-next-single-property-change (position prop
2220 &optional object limit)
2223 ;; We parse the buffer here "on-demand" by chunks of 500 chars.
2224 ;; But we could also just parse the whole buffer.
2225 (compilation--ensure-parse
2226 (setq parsed (max compilation--parsed
2227 (min (+ position 500)
2228 (or limit (point-max))))))
2229 (and (or (not (setq res (next-single-property-change
2230 position prop object limit)))
2232 (< position (or limit (point-max)))))
2233 (setq position parsed))
2236 (defun compilation-next-error (n &optional different-file pt)
2237 "Move point to the next error in the compilation buffer.
2238 This function does NOT find the source line like \\[next-error].
2239 Prefix arg N says how many error messages to move forwards (or
2240 backwards, if negative).
2241 Optional arg DIFFERENT-FILE, if non-nil, means find next error for a
2242 file that is different from the current one.
2243 Optional arg PT, if non-nil, specifies the value of point to start
2244 looking for the next message."
2246 (or (compilation-buffer-p (current-buffer))
2247 (error "Not in a compilation buffer"))
2248 (or pt (setq pt (point)))
2249 (let* ((msg (get-text-property pt 'compilation-message))
2250 ;; `loc', `msg', and `last' are used by the compilation-loop macro.
2251 (loc (and msg (compilation--message->loc msg)))
2254 (unless (or msg ; find message near here
2255 (setq msg (get-text-property (max (1- pt) (point-min))
2256 'compilation-message)))
2257 (setq pt (previous-single-property-change pt 'compilation-message nil
2258 (line-beginning-position)))
2259 (unless (setq msg (get-text-property (max (1- pt) (point-min))
2260 'compilation-message))
2261 (setq pt (next-single-property-change pt 'compilation-message nil
2262 (line-end-position)))
2263 (or (setq msg (get-text-property pt 'compilation-message))
2264 (setq pt (point)))))
2265 (setq last (compilation--loc->file-struct loc))
2267 (compilation-loop > compilation-next-single-property-change 1-
2268 (if (get-buffer-process (current-buffer))
2270 "Moved past last %s")
2272 (compilation--ensure-parse pt)
2273 ;; Don't move "back" to message at or before point.
2274 ;; Pass an explicit (point-min) to make sure pt is non-nil.
2275 (setq pt (previous-single-property-change
2276 pt 'compilation-message nil (point-min)))
2277 (compilation-loop < previous-single-property-change 1+
2278 "Moved back before first %s" (point-min))))
2281 (error "No %s here" compilation-error))))
2283 (defun compilation-previous-error (n)
2284 "Move point to the previous error in the compilation buffer.
2285 Prefix arg N says how many error messages to move backwards (or
2286 forwards, if negative).
2287 Does NOT find the source line like \\[previous-error]."
2289 (compilation-next-error (- n)))
2291 (defun compilation-next-file (n)
2292 "Move point to the next error for a different file than the current one.
2293 Prefix arg N says how many files to move forwards (or backwards, if negative)."
2295 (compilation-next-error n t))
2297 (defun compilation-previous-file (n)
2298 "Move point to the previous error for a different file than the current one.
2299 Prefix arg N says how many files to move backwards (or forwards, if negative)."
2301 (compilation-next-file (- n)))
2303 (defun kill-compilation ()
2304 "Kill the process made by the \\[compile] or \\[grep] commands."
2306 (let ((buffer (compilation-find-buffer)))
2307 (if (get-buffer-process buffer)
2308 (interrupt-process (get-buffer-process buffer))
2309 (error "The %s process is not running" (downcase mode-name)))))
2311 (defalias 'compile-mouse-goto-error 'compile-goto-error)
2313 (defun compile-goto-error (&optional event)
2314 "Visit the source for the error message at point.
2315 Use this command in a compilation log buffer. Sets the mark at point there."
2316 (interactive (list last-input-event))
2317 (if event (posn-set-point (event-end event)))
2318 (or (compilation-buffer-p (current-buffer))
2319 (error "Not in a compilation buffer"))
2320 (compilation--ensure-parse (point))
2321 (if (get-text-property (point) 'compilation-directory)
2323 (car (get-text-property (point) 'compilation-directory)))
2325 (setq compilation-current-error (point))
2326 (next-error-internal)))
2328 ;; This is mostly unused, but we keep it for the sake of some external
2329 ;; packages which seem to make use of it.
2330 (defun compilation-find-buffer (&optional avoid-current)
2331 "Return a compilation buffer.
2332 If AVOID-CURRENT is nil, and the current buffer is a compilation buffer,
2333 return it. If AVOID-CURRENT is non-nil, return the current buffer only
2335 (if (and (compilation-buffer-internal-p) (not avoid-current))
2337 (next-error-find-buffer avoid-current 'compilation-buffer-internal-p)))
2340 (defun compilation-next-error-function (n &optional reset)
2341 "Advance to the next error message and visit the file where the error was.
2342 This is the value of `next-error-function' in Compilation buffers."
2345 (setq compilation-current-error nil))
2346 (let* ((screen-columns compilation-error-screen-columns)
2347 (first-column compilation-first-column)
2349 (msg (compilation-next-error (or n 1) nil
2350 (or compilation-current-error
2351 compilation-messages-start
2353 (loc (compilation--message->loc msg))
2354 (end-loc (compilation--message->end-loc msg))
2355 (marker (point-marker)))
2356 (setq compilation-current-error (point-marker)
2357 overlay-arrow-position
2359 compilation-current-error
2360 (copy-marker (line-beginning-position))))
2361 ;; If loc contains no marker, no error in that file has been visited.
2362 ;; If the marker is invalid the buffer has been killed.
2363 ;; So, recalculate all markers for that file.
2364 (unless (and (compilation--loc->marker loc)
2365 (marker-buffer (compilation--loc->marker loc))
2366 ;; FIXME-omake: For "omake -P", which automatically recompiles
2367 ;; when the file is modified, the line numbers of new output
2368 ;; may not be related to line numbers from earlier output
2369 ;; (earlier markers), so we used to try to detect it here and
2370 ;; force a reparse. But that caused more problems elsewhere,
2371 ;; so instead we now flush the file-structure when we see
2372 ;; omake's message telling it's about to recompile a file.
2373 ;; (or (null (compilation--loc->timestamp loc)) ;A fake-loc
2374 ;; (equal (compilation--loc->timestamp loc)
2375 ;; (setq timestamp compilation-buffer-modtime)))
2377 (with-current-buffer
2378 (compilation-find-file
2380 (caar (compilation--loc->file-struct loc))
2381 (cadr (car (compilation--loc->file-struct loc))))
2382 (let ((screen-columns
2383 ;; Obey the compilation-error-screen-columns of the target
2384 ;; buffer if its major mode set it buffer-locally.
2385 (if (local-variable-p 'compilation-error-screen-columns)
2386 compilation-error-screen-columns screen-columns))
2387 (compilation-first-column
2388 (if (local-variable-p 'compilation-first-column)
2389 compilation-first-column first-column)))
2392 (goto-char (point-min))
2393 ;; Treat file's found lines in forward order, 1 by 1.
2394 (dolist (line (reverse (cddr (compilation--loc->file-struct loc))))
2395 (when (car line) ; else this is a filename w/o a line#
2396 (beginning-of-line (- (car line) last -1))
2397 (setq last (car line)))
2398 ;; Treat line's found columns and store/update a marker for each.
2399 (dolist (col (cdr line))
2400 (if (compilation--loc->col col)
2401 (if (eq (compilation--loc->col col) -1)
2402 ;; Special case for range end.
2404 (compilation-move-to-column (compilation--loc->col col)
2407 (skip-chars-forward " \t"))
2408 (if (compilation--loc->marker col)
2409 (set-marker (compilation--loc->marker col) (point))
2410 (setf (compilation--loc->marker col) (point-marker)))
2411 ;; (setf (compilation--loc->timestamp col) timestamp)
2413 (compilation-goto-locus marker (compilation--loc->marker loc)
2414 (compilation--loc->marker end-loc))
2415 (setf (compilation--loc->visited loc) t)))
2417 (defvar compilation-gcpro nil
2418 "Internal variable used to keep some values from being GC'd.")
2419 (make-variable-buffer-local 'compilation-gcpro)
2421 (defun compilation-fake-loc (marker file &optional line col)
2422 "Preassociate MARKER with FILE.
2423 FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
2424 This is useful when you compile temporary files, but want
2425 automatic translation of the messages to the real buffer from
2426 which the temporary file came. This may also affect previous messages
2429 Optional args LINE and COL default to 1 and beginning of
2430 indentation respectively. The marker is expected to reflect
2431 this. In the simplest case the marker points to the first line
2432 of the region that was saved to the temp file.
2434 If you concatenate several regions into the temp file (e.g. a
2435 header with variable assignments and a code region), you must
2436 call this several times, once each for the last line of one
2437 region and the first line of the next region."
2438 (or (consp file) (setq file (list file)))
2439 (compilation--flush-file-structure file)
2440 (let ((fs (compilation-get-file-structure file)))
2441 ;; Between the current call to compilation-fake-loc and the first
2442 ;; occurrence of an error message referring to `file', the data is
2443 ;; only kept in the weak hash-table compilation-locs, so we need
2444 ;; to prevent this entry in compilation-locs from being GC'd
2446 (push fs compilation-gcpro)
2447 (let ((loc (compilation-assq (or line 1) (cdr fs))))
2448 (setq loc (compilation-assq col loc))
2449 (cl-assert (null (cdr loc)))
2450 (setcdr loc (compilation--make-cdrloc line fs marker))
2453 (defcustom compilation-context-lines nil
2454 "Display this many lines of leading context before the current message.
2455 If nil and the left fringe is displayed, don't scroll the
2456 compilation output window; an arrow in the left fringe points to
2457 the current message. If nil and there is no left fringe, the message
2458 displays at the top of the window; there is no arrow."
2459 :type '(choice integer (const :tag "No window scrolling" nil))
2463 (defsubst compilation-set-window (w mk)
2464 "Align the compilation output window W with marker MK near top."
2465 (if (integerp compilation-context-lines)
2466 (set-window-start w (save-excursion
2469 (- 1 compilation-context-lines))
2471 ;; If there is no left fringe.
2472 (if (equal (car (window-fringes)) 0)
2473 (set-window-start w (save-excursion
2475 (beginning-of-line 1)
2477 (set-window-point w mk))
2479 (defvar next-error-highlight-timer)
2481 (defun compilation-goto-locus (msg mk end-mk)
2482 "Jump to an error corresponding to MSG at MK.
2483 All arguments are markers. If END-MK is non-nil, mark is set there
2484 and overlay is highlighted between MK and END-MK."
2485 ;; Show compilation buffer in other window, scrolled to this error.
2486 (let* ((from-compilation-buffer (eq (window-buffer (selected-window))
2487 (marker-buffer msg)))
2488 ;; Use an existing window if it is in a visible frame.
2489 (pre-existing (get-buffer-window (marker-buffer msg) 0))
2490 (w (if (and from-compilation-buffer pre-existing)
2491 ;; Calling display-buffer here may end up (partly) hiding
2492 ;; the error location if the two buffers are in two
2493 ;; different frames. So don't do it if it's not necessary.
2495 (display-buffer (marker-buffer msg))))
2496 (highlight-regexp (with-current-buffer (marker-buffer msg)
2497 ;; also do this while we change buffer
2498 (compilation-set-window w msg)
2499 compilation-highlight-regexp)))
2500 ;; Ideally, the window-size should be passed to `display-buffer'
2501 ;; so it's only used when creating a new window.
2502 (unless pre-existing (compilation-set-window-height w))
2504 (if from-compilation-buffer
2505 ;; If the compilation buffer window was selected,
2506 ;; keep the compilation buffer in this window;
2507 ;; display the source in another window.
2508 (let ((pop-up-windows t))
2509 (pop-to-buffer (marker-buffer mk) 'other-window))
2510 (switch-to-buffer (marker-buffer mk)))
2511 (unless (eq (goto-char mk) (point))
2512 ;; If narrowing gets in the way of going to the right place, widen.
2514 (if next-error-move-function
2515 (funcall next-error-move-function msg mk)
2518 (push-mark end-mk t)
2519 (if mark-active (setq mark-active)))
2520 ;; If hideshow got in the way of
2521 ;; seeing the right place, open permanently.
2522 (dolist (ov (overlays-at (point)))
2523 (when (eq 'hs (overlay-get ov 'invisible))
2527 (when highlight-regexp
2528 (if (timerp next-error-highlight-timer)
2529 (cancel-timer next-error-highlight-timer))
2530 (unless compilation-highlight-overlay
2531 (setq compilation-highlight-overlay
2532 (make-overlay (point-min) (point-min)))
2533 (overlay-put compilation-highlight-overlay 'face 'next-error))
2534 (with-current-buffer (marker-buffer mk)
2536 (if end-mk (goto-char end-mk) (end-of-line))
2537 (let ((end (point)))
2538 (if mk (goto-char mk) (beginning-of-line))
2539 (if (and (stringp highlight-regexp)
2540 (re-search-forward highlight-regexp end t))
2542 (goto-char (match-beginning 0))
2543 (move-overlay compilation-highlight-overlay
2544 (match-beginning 0) (match-end 0)
2546 (move-overlay compilation-highlight-overlay
2547 (point) end (current-buffer)))
2548 (if (or (eq next-error-highlight t)
2549 (numberp next-error-highlight))
2550 ;; We want highlighting: delete overlay on next input.
2551 (add-hook 'pre-command-hook
2552 'compilation-goto-locus-delete-o)
2553 ;; We don't want highlighting: delete overlay now.
2554 (delete-overlay compilation-highlight-overlay))
2555 ;; We want highlighting for a limited time:
2556 ;; set up a timer to delete it.
2557 (when (numberp next-error-highlight)
2558 (setq next-error-highlight-timer
2559 (run-at-time next-error-highlight nil
2560 'compilation-goto-locus-delete-o)))))))
2561 (when (and (eq next-error-highlight 'fringe-arrow))
2562 ;; We want a fringe arrow (instead of highlighting).
2563 (setq next-error-overlay-arrow-position
2564 (copy-marker (line-beginning-position))))))
2566 (defun compilation-goto-locus-delete-o ()
2567 (delete-overlay compilation-highlight-overlay)
2568 ;; Get rid of timer and hook that would try to do this again.
2569 (if (timerp next-error-highlight-timer)
2570 (cancel-timer next-error-highlight-timer))
2571 (remove-hook 'pre-command-hook
2572 'compilation-goto-locus-delete-o))
2574 (defun compilation-find-file (marker filename directory &rest formats)
2575 "Find a buffer for file FILENAME.
2576 If FILENAME is not found at all, ask the user where to find it.
2577 Pop up the buffer containing MARKER and scroll to MARKER if we ask
2578 the user where to find the file.
2579 Search the directories in `compilation-search-path'.
2580 A nil in `compilation-search-path' means to try the
2581 \"current\" directory, which is passed in DIRECTORY.
2582 If DIRECTORY is relative, it is combined with `default-directory'.
2583 If DIRECTORY is nil, that means use `default-directory'.
2584 FORMATS, if given, is a list of formats to reformat FILENAME when
2585 looking for it: for each element FMT in FORMATS, this function
2586 attempts to find a file whose name is produced by (format FMT FILENAME)."
2587 (or formats (setq formats '("%s")))
2588 (let ((dirs compilation-search-path)
2589 (spec-dir (if directory
2590 (expand-file-name directory)
2592 buffer thisdir fmts name)
2593 (if (file-name-absolute-p filename)
2594 ;; The file name is absolute. Use its explicit directory as
2595 ;; the first in the search path, and strip it from FILENAME.
2596 (setq filename (abbreviate-file-name (expand-file-name filename))
2597 dirs (cons (file-name-directory filename) dirs)
2598 filename (file-name-nondirectory filename)))
2599 ;; Now search the path.
2600 (while (and dirs (null buffer))
2601 (setq thisdir (or (car dirs) spec-dir)
2603 ;; For each directory, try each format string.
2604 (while (and fmts (null buffer))
2605 (setq name (expand-file-name (format (car fmts) filename) thisdir)
2606 buffer (and (file-exists-p name)
2607 (find-file-noselect name))
2609 (setq dirs (cdr dirs)))
2610 (while (null buffer) ;Repeat until the user selects an existing file.
2611 ;; The file doesn't exist. Ask the user where to find it.
2612 (save-excursion ;This save-excursion is probably not right.
2613 (let ((pop-up-windows t))
2614 (compilation-set-window (display-buffer (marker-buffer marker))
2616 (let* ((name (read-file-name
2617 (format "Find this %s in (default %s): "
2618 compilation-error filename)
2619 spec-dir filename t nil
2620 ;; The predicate below is fine when called from
2621 ;; minibuffer-complete-and-exit, but it's too
2622 ;; restrictive otherwise, since it also prevents the
2623 ;; user from completing "fo" to "foo/" when she
2624 ;; wants to enter "foo/bar".
2626 ;; Try to make sure the user can only select
2627 ;; a valid answer. This predicate may be ignored,
2628 ;; tho, so we still have to double-check afterwards.
2629 ;; TODO: We should probably fix read-file-name so
2630 ;; that it never ignores this predicate, even when
2631 ;; using popup dialog boxes.
2633 ;; (if (file-directory-p name)
2634 ;; (setq name (expand-file-name filename name)))
2635 ;; (file-exists-p name))
2639 ((not (file-exists-p name))
2640 (message "Cannot find file `%s'" name)
2642 ((and (file-directory-p name)
2644 (setq name (expand-file-name filename name)))))
2645 (message "No `%s' in directory %s" filename origname)
2648 (setq buffer (find-file-noselect name))))))))
2649 ;; Make intangible overlays tangible.
2650 ;; This is weird: it's not even clear which is the current buffer,
2651 ;; so the code below can't be expected to DTRT here. -- Stef
2652 (dolist (ov (overlays-in (point-min) (point-max)))
2653 (when (overlay-get ov 'intangible)
2654 (overlay-put ov 'intangible nil)))
2657 (defun compilation-get-file-structure (file &optional fmt)
2658 "Retrieve FILE's file-structure or create a new one.
2659 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
2660 In the former case, FILENAME may be relative or absolute.
2662 The file-structure looks like this:
2663 ((FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)"
2664 (or (gethash file compilation-locs)
2665 ;; File was not previously encountered, at least not in the form passed.
2666 ;; Let's normalize it and look again.
2667 (let ((filename (car file))
2668 ;; Get the specified directory from FILE.
2669 (spec-directory (if (cdr file)
2670 (file-truename (cdr file)))))
2672 ;; Check for a comint-file-name-prefix and prepend it if appropriate.
2673 ;; (This is very useful for compilation-minor-mode in an rlogin-mode
2675 (when (and (boundp 'comint-file-name-prefix)
2676 (not (equal comint-file-name-prefix "")))
2677 (if (file-name-absolute-p filename)
2679 (concat comint-file-name-prefix filename))
2681 (setq spec-directory
2683 (concat comint-file-name-prefix spec-directory))))))
2685 ;; If compilation-parse-errors-filename-function is
2686 ;; defined, use it to process the filename.
2687 (when compilation-parse-errors-filename-function
2689 (funcall compilation-parse-errors-filename-function
2692 ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
2693 ;; file names like "./bar//foo.c" for file "bar/foo.c";
2694 ;; expand-file-name will collapse these into "/foo.c" and fail to find
2695 ;; the appropriate file. So we look for doubled slashes in the file
2696 ;; name and fix them.
2697 (setq filename (command-line-normalize-file-name filename))
2699 ;; Store it for the possibly unnormalized name
2701 ;; Retrieve or create file-structure for normalized name
2702 ;; The gethash used to not use spec-directory, but
2703 ;; this leads to errors when files in different
2704 ;; directories have the same name:
2705 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00463.html
2706 (or (gethash (cons filename spec-directory) compilation-locs)
2707 (puthash (cons filename spec-directory)
2708 (compilation--make-file-struct
2709 (list filename spec-directory) fmt)
2711 compilation-locs))))
2713 (defun compilation--flush-file-structure (file)
2714 (or (consp file) (setq file (list file)))
2715 (let ((fs (compilation-get-file-structure file)))
2716 (cl-assert (eq fs (gethash file compilation-locs)))
2717 (cl-assert (eq fs (gethash (cons (caar fs) (cadr (car fs)))
2719 (maphash (lambda (k v)
2720 (if (eq v fs) (remhash k compilation-locs)))
2723 ;;; Compatibility with the old compile.el.
2725 (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
2726 (defvar compilation-parsing-end (make-marker))
2727 (defvar compilation-error-list nil)
2728 (defvar compilation-old-error-list nil)
2730 (defun compilation--compat-error-properties (err)
2731 "Map old-style error ERR to new-style message."
2732 ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
2733 ;; (MARKER . MARKER).
2734 (let ((dst (cdr err)))
2736 `(compilation-message ,(compilation--make-message
2737 (cons nil (compilation--make-cdrloc
2740 help-echo "mouse-2: visit the source location"
2741 keymap compilation-button-map
2742 mouse-face highlight)
2743 ;; Too difficult to do it by hand: dispatch to the normal code.
2744 (let* ((file (pop dst))
2747 (filename (pop file))
2748 (dirname (pop file))
2750 (compilation-internal-error-properties
2751 (cons filename dirname) line nil col nil 2 fmt)))))
2753 (defun compilation--compat-parse-errors (limit)
2754 (when compilation-parse-errors-function
2755 ;; FIXME: We should remove the rest of the compilation keywords
2756 ;; but we can't do that from here because font-lock is using
2757 ;; the value right now. --Stef
2759 (setq compilation-error-list nil)
2760 ;; Reset compilation-parsing-end each time because font-lock
2761 ;; might force us the re-parse many times (typically because
2762 ;; some code adds some text-property to the output that we
2763 ;; already parsed). You might say "why reparse", well:
2764 ;; because font-lock has just removed the `compilation-message' property
2765 ;; so have to do it all over again.
2766 (if compilation-parsing-end
2767 (set-marker compilation-parsing-end (point))
2768 (setq compilation-parsing-end (point-marker)))
2770 ;; Ignore any error: we're calling this function earlier than
2771 ;; in the old compile.el so things might not all be setup yet.
2772 (funcall compilation-parse-errors-function limit nil)
2774 (dolist (err (if (listp compilation-error-list) compilation-error-list))
2775 (let* ((src (car err))
2777 (loc (cond ((markerp dst)
2779 (compilation--make-cdrloc nil nil dst)))
2782 (compilation--make-cdrloc
2784 (cons (cdar dst) (caar dst))
2788 ;; (put-text-property src (line-end-position)
2789 ;; 'font-lock-face 'font-lock-warning-face)
2790 (put-text-property src (line-end-position)
2791 'compilation-message
2792 (compilation--make-message loc 2 nil)))))))
2796 ;; Beware! this is not only compatibility code. New code also uses it. --Stef
2797 (defun compilation-forget-errors ()
2798 ;; In case we hit the same file/line specs, we want to recompute a new
2799 ;; marker for them, so flush our cache.
2800 (clrhash compilation-locs)
2801 (setq compilation-gcpro nil)
2802 ;; FIXME: the old code reset the directory-stack, so maybe we should
2803 ;; put a `directory change' marker of some sort, but where? -stef
2805 ;; FIXME: The old code moved compilation-current-error (which was
2806 ;; virtually represented by a mix of compilation-parsing-end and
2807 ;; compilation-error-list) to point-min, but that was only meaningful for
2808 ;; the internal uses of compilation-forget-errors: all calls from external
2809 ;; packages seem to be followed by a move of compilation-parsing-end to
2810 ;; something equivalent to point-max. So we heuristically move
2811 ;; compilation-current-error to point-max (since the external package
2812 ;; won't know that it should do it). --Stef
2813 (setq compilation-current-error nil)
2814 (let* ((proc (get-buffer-process (current-buffer)))
2815 (mark (if proc (process-mark proc)))
2816 (pos (or mark (point-max))))
2817 (setq compilation-messages-start
2818 ;; In the future, ignore the text already present in the buffer.
2819 ;; Since many process filter functions insert before markers,
2820 ;; we need to put ours just before the insertion point rather
2821 ;; than at the insertion point. If that's not possible, then
2822 ;; don't use a marker. --Stef
2823 (if (> pos (point-min)) (copy-marker (1- pos)) pos)))
2824 ;; Again, since this command is used in buffers that contain several
2825 ;; compilations, to set the beginning of "this compilation", it's a good
2826 ;; place to reset compilation-auto-jump-to-next.
2827 (set (make-local-variable 'compilation-auto-jump-to-next)
2828 (or compilation-auto-jump-to-first-error
2829 (eq compilation-scroll-output 'first-error))))
2833 ;;; compile.el ends here