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