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