(calendar-other-dates): New function.
[emacs.git] / lisp / progmodes / compile.el
blob86db755b2341a563cc6ee92d6e4a5ee760475cc1
1 ;;; compile.el --- run compiler as inferior of Emacs, parse error messages
3 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
5 ;; Free Software Foundation, Inc.
7 ;; Authors: Roland McGrath <roland@gnu.org>,
8 ;; Daniel Pfeiffer <occitan@esperanto.org>
9 ;; Maintainer: FSF
10 ;; Keywords: tools, processes
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
29 ;;; Commentary:
31 ;; This package provides the compile facilities documented in the Emacs user's
32 ;; manual.
34 ;; This mode uses some complex data-structures:
36 ;; LOC (or location) is a list of (COLUMN LINE FILE-STRUCTURE)
38 ;; COLUMN and LINE are numbers parsed from an error message. COLUMN and maybe
39 ;; LINE will be nil for a message that doesn't contain them. Then the
40 ;; location refers to a indented beginning of line or beginning of file.
41 ;; Once any location in some file has been jumped to, the list is extended to
42 ;; (COLUMN LINE FILE-STRUCTURE MARKER TIMESTAMP . VISITED)
43 ;; for all LOCs pertaining to that file.
44 ;; MARKER initially points to LINE and COLUMN in a buffer visiting that file.
45 ;; Being a marker it sticks to some text, when the buffer grows or shrinks
46 ;; before that point. VISITED is t if we have jumped there, else nil.
47 ;; TIMESTAMP is necessary because of "incremental compilation": `omake -P'
48 ;; polls filesystem for changes and recompiles when a file is modified
49 ;; using the same *compilation* buffer. this necessitates re-parsing markers.
51 ;; FILE-STRUCTURE is a list of
52 ;; ((FILENAME . DIRECTORY) FORMATS (LINE LOC ...) ...)
54 ;; FILENAME is a string parsed from an error message. DIRECTORY is a string
55 ;; obtained by following directory change messages. DIRECTORY will be nil for
56 ;; an absolute filename. FORMATS is a list of formats to apply to FILENAME if
57 ;; a file of that name can't be found.
58 ;; The rest of the list is an alist of elements with LINE as key. The keys
59 ;; are either nil or line numbers. If present, nil comes first, followed by
60 ;; the numbers in decreasing order. The LOCs for each line are again an alist
61 ;; ordered the same way. Note that the whole file structure is referenced in
62 ;; every LOC.
64 ;; MESSAGE is a list of (LOC TYPE END-LOC)
66 ;; TYPE is 0 for info or 1 for warning if the message matcher identified it as
67 ;; such, 2 otherwise (for a real error). END-LOC is a LOC pointing to the
68 ;; other end, if the parsed message contained a range. If the end of the
69 ;; range didn't specify a COLUMN, it defaults to -1, meaning end of line.
70 ;; These are the value of the `message' text-properties in the compilation
71 ;; buffer.
73 ;;; Code:
75 (eval-when-compile (require 'cl))
76 (require 'tool-bar)
78 (defvar font-lock-extra-managed-props)
79 (defvar font-lock-keywords)
80 (defvar font-lock-maximum-size)
81 (defvar font-lock-support-mode)
84 (defgroup compilation nil
85 "Run compiler as inferior of Emacs, parse error messages."
86 :group 'tools
87 :group 'processes)
90 ;;;###autoload
91 (defcustom compilation-mode-hook nil
92 "List of hook functions run by `compilation-mode' (see `run-mode-hooks')."
93 :type 'hook
94 :group 'compilation)
96 ;;;###autoload
97 (defcustom compilation-window-height nil
98 "Number of lines in a compilation window. If nil, use Emacs default."
99 :type '(choice (const :tag "Default" nil)
100 integer)
101 :group 'compilation)
103 (defvar compilation-first-column 1
104 "*This is how compilers number the first column, usually 1 or 0.")
106 (defvar compilation-parse-errors-filename-function nil
107 "Function to call to post-process filenames while parsing error messages.
108 It takes one arg FILENAME which is the name of a file as found
109 in the compilation output, and should return a transformed file name.")
111 ;;;###autoload
112 (defvar compilation-process-setup-function nil
113 "*Function to call to customize the compilation process.
114 This function is called immediately before the compilation process is
115 started. It can be used to set any variables or functions that are used
116 while processing the output of the compilation process. The function
117 is called with variables `compilation-buffer' and `compilation-window'
118 bound to the compilation buffer and window, respectively.")
120 ;;;###autoload
121 (defvar compilation-buffer-name-function nil
122 "Function to compute the name of a compilation buffer.
123 The function receives one argument, the name of the major mode of the
124 compilation buffer. It should return a string.
125 If nil, compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
127 ;;;###autoload
128 (defvar compilation-finish-function nil
129 "Function to call when a compilation process finishes.
130 It is called with two arguments: the compilation buffer, and a string
131 describing how the process finished.")
133 (make-obsolete-variable 'compilation-finish-function
134 "use `compilation-finish-functions', but it works a little differently."
135 "22.1")
137 ;;;###autoload
138 (defvar compilation-finish-functions nil
139 "Functions to call when a compilation process finishes.
140 Each function is called with two arguments: the compilation buffer,
141 and a string describing how the process finished.")
143 (defvar compilation-in-progress nil
144 "List of compilation processes now running.")
145 (or (assq 'compilation-in-progress minor-mode-alist)
146 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
147 minor-mode-alist)))
149 (defvar compilation-error "error"
150 "Stem of message to print when no matches are found.")
152 (defvar compilation-arguments nil
153 "Arguments that were given to `compilation-start'.")
155 (defvar compilation-num-errors-found)
157 (defconst compilation-error-regexp-alist-alist
158 '((absoft
159 "^\\(?:[Ee]rror on \\|[Ww]arning on\\( \\)\\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
160 of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil (1))
162 (ada
163 "\\(warning: .*\\)? at \\([^ \n]+\\):\\([0-9]+\\)$" 2 3 nil (1))
165 (aix
166 " in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
168 (ant
169 "^[ \t]*\\[[^] \n]+\\][ \t]*\\([^: \n]+\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):[0-9]+:[0-9]+:\\)?\
170 \\( warning\\)?" 1 2 3 (4))
172 (maven
173 ;; Maven is a popular build tool for Java. Maven is Free Software.
174 "\\(.*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\]" 1 2 3)
176 (bash
177 "^\\([^: \n\t]+\\): line \\([0-9]+\\):" 1 2)
179 (borland
180 "^\\(?:Error\\|Warnin\\(g\\)\\) \\(?:[FEW][0-9]+ \\)?\
181 \\([a-zA-Z]?:?[^:( \t\n]+\\)\
182 \\([0-9]+\\)\\(?:[) \t]\\|:[^0-9\n]\\)" 2 3 nil (1))
184 (caml
185 "^ *File \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1, lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
186 \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:\\)?\\([ \n]Warning:\\)?\\)"
187 2 (3 . 4) (5 . 6) (7))
189 (comma
190 "^\"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)\
191 \\(?:[(. pos]+\\([0-9]+\\))?\\)?[:.,; (-]\\( warning:\\|[-0-9 ]*(W)\\)?" 1 2 3 (4))
193 (edg-1
194 "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
195 1 2 nil (3 . 4))
196 (edg-2
197 "at line \\([0-9]+\\) of \"\\([^ \n]+\\)\"$"
198 2 1 nil 0)
200 (epc
201 "^Error [0-9]+ at (\\([0-9]+\\):\\([^)\n]+\\))" 2 1)
203 (ftnchek
204 "\\(^Warning .*\\)? line[ \n]\\([0-9]+\\)[ \n]\\(?:col \\([0-9]+\\)[ \n]\\)?file \\([^ :;\n]+\\)"
205 4 2 3 (1))
207 (iar
208 "^\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(?:Error\\|Warnin\\(g\\)\\)\\[[0-9]+\\]:"
209 1 2 nil (3))
211 (ibm
212 "^\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) :\
213 \\(?:warnin\\(g\\)\\|informationa\\(l\\)\\)?" 1 2 3 (4 . 5))
215 ;; fixme: should be `mips'
216 (irix
217 "^[-[:alnum:]_/ ]+: \\(?:\\(?:[sS]evere\\|[eE]rror\\|[wW]arnin\\(g\\)\\|[iI]nf\\(o\\)\\)[0-9 ]*: \\)?\
218 \\([^,\" \n\t]+\\)\\(?:, line\\|:\\) \\([0-9]+\\):" 3 4 nil (1 . 2))
220 (java
221 "^\\(?:[ \t]+at \\|==[0-9]+== +\\(?:at\\|b\\(y\\)\\)\\).+(\\([^()\n]+\\):\\([0-9]+\\))$" 2 3 nil (1))
223 (jikes-file
224 "^\\(?:Found\\|Issued\\) .* compiling \"\\(.+\\)\":$" 1 nil nil 0)
225 (jikes-line
226 "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)"
227 nil 1 nil 2 0
228 (2 (compilation-face '(3))))
230 (gnu
231 ;; I have no idea what this first line is supposed to match, but it
232 ;; makes things ambiguous with output such as "foo:344:50:blabla" since
233 ;; the "foo" part can match this first line (in which case the file
234 ;; name as "344"). To avoid this, the second line disallows filenames
235 ;; exclusively composed of digits. --Stef
236 ;; Similarly, we get lots of false positives with messages including
237 ;; times of the form "HH:MM:SS" where MM is taken as a line number, so
238 ;; the last line tries to rule out message where the info after the
239 ;; line number starts with "SS". --Stef
240 "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\)?\
241 \\([0-9]*[^0-9\n]\\(?:[^\n ]\\| [^-\n]\\)*?\\): ?\
242 \\([0-9]+\\)\\(?:\\([.:]\\)\\([0-9]+\\)\\)?\
243 \\(?:-\\([0-9]+\\)?\\(?:\\3\\([0-9]+\\)\\)?\\)?:\
244 \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\
245 *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\|[Nn]ote\\)\\|\
246 \[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)"
247 1 (2 . 5) (4 . 6) (7 . 8))
249 ;; The `gnu' style above can incorrectly match gcc's "In file
250 ;; included from" message, so we process that first. -- cyd
251 (gcc-include
252 "^\\(?:In file included\\| \\) from \
253 \\(.+\\):\\([0-9]+\\)\\(?:\\(:\\)\\|\\(,\\)\\)?" 1 2 nil (3 . 4))
255 (lcc
256 "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)"
257 2 3 4 (1))
259 (makepp
260 "^makepp\\(?:\\(?:: warning\\(:\\).*?\\|\\(: Scanning\\|: [LR]e?l?oading makefile\\|: Imported\\|log:.*?\\) \\|: .*?\\)\
261 `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)"
262 4 5 nil (1 . 2) 3
263 ("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]" nil nil
264 (2 compilation-info-face)
265 (3 compilation-line-face nil t)
266 (1 (compilation-error-properties 2 3 nil nil nil 0 nil)
267 append)))
269 ;; Should be lint-1, lint-2 (SysV lint)
270 (mips-1
271 " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
272 (mips-2
273 " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2)
275 (msft
276 ;; AFAWK, The message may be a "warning", "error", or "fatal error".
277 "^\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
278 : \\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:" 2 3 nil (4))
280 (oracle
281 "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
282 \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
283 \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
284 3 1 2)
286 ;; "during global destruction": This comes out under "use
287 ;; warnings" in recent perl when breaking circular references
288 ;; during program or thread exit.
289 (perl
290 " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \
291 during global destruction\\.$\\)" 1 2)
293 (php
294 "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
295 2 3 nil nil)
297 (rxp
298 "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
299 \\([0-9]+\\) of file://\\(.+\\)"
300 4 2 3 (1))
302 (sparc-pascal-file
303 "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
304 [12][09][0-9][0-9] +\\(.*\\):$"
305 1 nil nil 0)
306 (sparc-pascal-line
307 "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
308 nil 3 nil (2) nil (1 (compilation-face '(2))))
309 (sparc-pascal-example
310 "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
311 nil 1 nil (3) nil (2 (compilation-face '(3))))
313 (sun
314 ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
315 File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
316 3 4 5 (1 . 2))
318 (sun-ada
319 "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
321 (4bsd
322 "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
323 \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3))
325 (gcov-file
326 "^ *-: *\\(0\\):Source:\\(.+\\)$"
327 2 1 nil 0 nil
328 (1 compilation-line-face prepend) (2 compilation-info-face prepend))
329 (gcov-header
330 "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
331 nil 1 nil 0 nil
332 (1 compilation-line-face prepend))
333 ;; Underlines over all lines of gcov output are too uncomfortable to read.
334 ;; However, hyperlinks embedded in the lines are useful.
335 ;; So I put default face on the lines; and then put
336 ;; compilation-*-face by manually to eliminate the underlines.
337 ;; The hyperlinks are still effective.
338 (gcov-nomark
339 "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
340 nil 1 nil 0 nil
341 (0 'default t)
342 (1 compilation-line-face prepend))
343 (gcov-called-line
344 "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
345 nil 2 nil 0 nil
346 (0 'default t)
347 (1 compilation-info-face prepend) (2 compilation-line-face prepend))
348 (gcov-never-called
349 "^ *\\(#####\\): *\\([0-9]+\\):.*$"
350 nil 2 nil 2 nil
351 (0 'default t)
352 (1 compilation-error-face prepend) (2 compilation-line-face prepend))
354 (perl--Pod::Checker
355 ;; podchecker error messages, per Pod::Checker.
356 ;; The style is from the Pod::Checker::poderror() function, eg.
357 ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm
359 ;; Plus end_pod() can give "at line EOF" instead of a
360 ;; number, so for that match "on line N" which is the
361 ;; originating spot, eg.
362 ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm
364 ;; Plus command() can give both "on line N" and "at line N";
365 ;; the latter is desired and is matched because the .* is
366 ;; greedy.
367 ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod
369 "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \
370 \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)"
371 3 2 nil (1))
372 (perl--Test
373 ;; perl Test module error messages.
374 ;; Style per the ok() function "$context", eg.
375 ;; # Failed test 1 in foo.t at line 6
377 "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
378 1 2)
379 (perl--Test2
380 ;; Or when comparing got/want values,
381 ;; # Test 2 got: "xx" (t-compilation-perl-2.t at line 10)
383 ;; And under Test::Harness they're preceded by progress stuff with
384 ;; \r and "NOK",
385 ;; ... NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
387 "^\\(.*NOK.*\\)?# Test [0-9]+ got:.* (\\([^ \t\r\n]+\\) at line \
388 \\([0-9]+\\))"
389 2 3)
390 (perl--Test::Harness
391 ;; perl Test::Harness output, eg.
392 ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
394 ;; Test::Harness is slightly designed for tty output, since
395 ;; it prints CRs to overwrite progress messages, but if you
396 ;; run it in with M-x compile this pattern can at least step
397 ;; through the failures.
399 "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
400 1 2)
401 (weblint
402 ;; The style comes from HTML::Lint::Error::as_string(), eg.
403 ;; index.html (13:1) Unknown element <fdjsk>
405 ;; The pattern only matches filenames without spaces, since that
406 ;; should be usual and should help reduce the chance of a false
407 ;; match of a message from some unrelated program.
409 ;; This message style is quite close to the "ibm" entry which is
410 ;; for IBM C, though that ibm bit doesn't put a space after the
411 ;; filename.
413 "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) "
414 1 2 3)
416 "Alist of values for `compilation-error-regexp-alist'.")
418 (defcustom compilation-error-regexp-alist
419 (mapcar 'car compilation-error-regexp-alist-alist)
420 "Alist that specifies how to match errors in compiler output.
421 On GNU and Unix, any string is a valid filename, so these
422 matchers must make some common sense assumptions, which catch
423 normal cases. A shorter list will be lighter on resource usage.
425 Instead of an alist element, you can use a symbol, which is
426 looked up in `compilation-error-regexp-alist-alist'. You can see
427 the predefined symbols and their effects in the file
428 `etc/compilation.txt' (linked below if you are customizing this).
430 Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
431 HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
432 gives the file name, and the LINE'th subexpression gives the line
433 number. The COLUMN'th subexpression gives the column number on
434 that line.
436 If FILE, LINE or COLUMN are nil or that index didn't match, that
437 information is not present on the matched line. In that case the
438 file name is assumed to be the same as the previous one in the
439 buffer, line number defaults to 1 and column defaults to
440 beginning of line's indentation.
442 FILE can also have the form (FILE FORMAT...), where the FORMATs
443 \(e.g. \"%s.c\") will be applied in turn to the recognized file
444 name, until a file of that name is found. Or FILE can also be a
445 function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
446 In the former case, FILENAME may be relative or absolute.
448 LINE can also be of the form (LINE . END-LINE) meaning a range
449 of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
450 meaning a range of columns starting on LINE and ending on
451 END-LINE, if that matched.
453 TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
454 TYPE can also be of the form (WARNING . INFO). In that case this
455 will be equivalent to 1 if the WARNING'th subexpression matched
456 or else equivalent to 0 if the INFO'th subexpression matched.
457 See `compilation-error-face', `compilation-warning-face',
458 `compilation-info-face' and `compilation-skip-threshold'.
460 What matched the HYPERLINK'th subexpression has `mouse-face' and
461 `compilation-message-face' applied. If this is nil, the text
462 matched by the whole REGEXP becomes the hyperlink.
464 Additional HIGHLIGHTs as described under `font-lock-keywords' can
465 be added."
466 :type `(set :menu-tag "Pick"
467 ,@(mapcar (lambda (elt)
468 (list 'const (car elt)))
469 compilation-error-regexp-alist-alist))
470 :link `(file-link :tag "example file"
471 ,(expand-file-name "compilation.txt" data-directory))
472 :group 'compilation)
474 ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp)
475 (defvar compilation-directory nil
476 "Directory to restore to when doing `recompile'.")
478 (defvar compilation-directory-matcher
479 '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1))
480 "A list for tracking when directories are entered or left.
481 If nil, do not track directories, e.g. if all file names are absolute. The
482 first element is the REGEXP matching these messages. It can match any number
483 of variants, e.g. different languages. The remaining elements are all of the
484 form (DIR . LEAVE). If for any one of these the DIR'th subexpression
485 matches, that is a directory name. If LEAVE is nil or the corresponding
486 LEAVE'th subexpression doesn't match, this message is about going into another
487 directory. If it does match anything, this message is about going back to the
488 directory we were in before the last entering message. If you change this,
489 you may also want to change `compilation-page-delimiter'.")
491 (defvar compilation-page-delimiter
492 "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
493 "Value of `page-delimiter' in Compilation mode.")
495 (defvar compilation-mode-font-lock-keywords
496 '(;; configure output lines.
497 ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
498 (1 font-lock-variable-name-face)
499 (2 (compilation-face '(4 . 3))))
500 ;; Command output lines. Recognize `make[n]:' lines too.
501 ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
502 (1 font-lock-function-name-face) (3 compilation-line-face nil t))
503 (" --?o\\(?:utfile\\|utput\\)?[= ]?\\(\\S +\\)" . 1)
504 ("^Compilation \\(finished\\).*"
505 (0 '(face nil message nil help-echo nil mouse-face nil) t)
506 (1 compilation-info-face))
507 ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
508 (0 '(face nil message nil help-echo nil mouse-face nil) t)
509 (1 compilation-error-face)
510 (2 compilation-error-face nil t)))
511 "Additional things to highlight in Compilation mode.
512 This gets tacked on the end of the generated expressions.")
514 (defvar compilation-highlight-regexp t
515 "Regexp matching part of visited source lines to highlight temporarily.
516 Highlight entire line if t; don't highlight source lines if nil.")
518 (defvar compilation-highlight-overlay nil
519 "Overlay used to temporarily highlight compilation matches.")
521 (defcustom compilation-error-screen-columns t
522 "If non-nil, column numbers in error messages are screen columns.
523 Otherwise they are interpreted as character positions, with
524 each character occupying one column.
525 The default is to use screen columns, which requires that the compilation
526 program and Emacs agree about the display width of the characters,
527 especially the TAB character."
528 :type 'boolean
529 :group 'compilation
530 :version "20.4")
532 (defcustom compilation-read-command t
533 "Non-nil means \\[compile] reads the compilation command to use.
534 Otherwise, \\[compile] just uses the value of `compile-command'."
535 :type 'boolean
536 :group 'compilation)
538 ;;;###autoload
539 (defcustom compilation-ask-about-save t
540 "Non-nil means \\[compile] asks which buffers to save before compiling.
541 Otherwise, it saves all modified buffers without asking."
542 :type 'boolean
543 :group 'compilation)
545 ;;;###autoload
546 (defcustom compilation-search-path '(nil)
547 "List of directories to search for source files named in error messages.
548 Elements should be directory names, not file names of directories.
549 The value nil as an element means to try the default directory."
550 :type '(repeat (choice (const :tag "Default" nil)
551 (string :tag "Directory")))
552 :group 'compilation)
554 ;;;###autoload
555 (defcustom compile-command "make -k "
556 "Last shell command used to do a compilation; default for next compilation.
558 Sometimes it is useful for files to supply local values for this variable.
559 You might also use mode hooks to specify it in certain modes, like this:
561 (add-hook 'c-mode-hook
562 (lambda ()
563 (unless (or (file-exists-p \"makefile\")
564 (file-exists-p \"Makefile\"))
565 (set (make-local-variable 'compile-command)
566 (concat \"make -k \"
567 (file-name-sans-extension buffer-file-name))))))"
568 :type 'string
569 :group 'compilation)
570 ;;;###autoload(put 'compile-command 'safe-local-variable 'stringp)
572 ;;;###autoload
573 (defcustom compilation-disable-input nil
574 "If non-nil, send end-of-file as compilation process input.
575 This only affects platforms that support asynchronous processes (see
576 `start-process'); synchronous compilation processes never accept input."
577 :type 'boolean
578 :group 'compilation
579 :version "22.1")
581 ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
582 ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
583 ;; key. This holds the tree seen from root, for storing new nodes.
584 (defvar compilation-locs ())
586 (defvar compilation-debug nil
587 "*Set this to t before creating a *compilation* buffer.
588 Then every error line will have a debug text property with the matcher that
589 fit this line and the match data. Use `describe-text-properties'.")
591 (defvar compilation-exit-message-function nil "\
592 If non-nil, called when a compilation process dies to return a status message.
593 This should be a function of three arguments: process status, exit status,
594 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
595 write into the compilation buffer, and to put in its mode line.")
597 (defvar compilation-environment nil
598 "*List of environment variables for compilation to inherit.
599 Each element should be a string of the form ENVVARNAME=VALUE.
600 This list is temporarily prepended to `process-environment' prior to
601 starting the compilation process.")
603 ;; History of compile commands.
604 (defvar compile-history nil)
606 (defface compilation-error
607 '((t :inherit font-lock-warning-face))
608 "Face used to highlight compiler errors."
609 :group 'compilation
610 :version "22.1")
612 (defface compilation-warning
613 '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
614 (((class color)) (:foreground "cyan" :weight bold))
615 (t (:weight bold)))
616 "Face used to highlight compiler warnings."
617 :group 'compilation
618 :version "22.1")
620 (defface compilation-info
621 '((((class color) (min-colors 16) (background light))
622 (:foreground "Green3" :weight bold))
623 (((class color) (min-colors 88) (background dark))
624 (:foreground "Green1" :weight bold))
625 (((class color) (min-colors 16) (background dark))
626 (:foreground "Green" :weight bold))
627 (((class color)) (:foreground "green" :weight bold))
628 (t (:weight bold)))
629 "Face used to highlight compiler information."
630 :group 'compilation
631 :version "22.1")
633 (defface compilation-line-number
634 '((t :inherit font-lock-variable-name-face))
635 "Face for displaying line numbers in compiler messages."
636 :group 'compilation
637 :version "22.1")
639 (defface compilation-column-number
640 '((t :inherit font-lock-type-face))
641 "Face for displaying column numbers in compiler messages."
642 :group 'compilation
643 :version "22.1")
645 (defcustom compilation-message-face 'underline
646 "Face name to use for whole messages.
647 Faces `compilation-error-face', `compilation-warning-face',
648 `compilation-info-face', `compilation-line-face' and
649 `compilation-column-face' get prepended to this, when applicable."
650 :type 'face
651 :group 'compilation
652 :version "22.1")
654 (defvar compilation-error-face 'compilation-error
655 "Face name to use for file name in error messages.")
657 (defvar compilation-warning-face 'compilation-warning
658 "Face name to use for file name in warning messages.")
660 (defvar compilation-info-face 'compilation-info
661 "Face name to use for file name in informational messages.")
663 (defvar compilation-line-face 'compilation-line-number
664 "Face name to use for line numbers in compiler messages.")
666 (defvar compilation-column-face 'compilation-column-number
667 "Face name to use for column numbers in compiler messages.")
669 ;; same faces as dired uses
670 (defvar compilation-enter-directory-face 'font-lock-function-name-face
671 "Face name to use for entering directory messages.")
673 (defvar compilation-leave-directory-face 'font-lock-type-face
674 "Face name to use for leaving directory messages.")
678 ;; Used for compatibility with the old compile.el.
679 (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
680 (defvar compilation-parsing-end (make-marker))
681 (defvar compilation-parse-errors-function nil)
682 (defvar compilation-error-list nil)
683 (defvar compilation-old-error-list nil)
685 (defcustom compilation-auto-jump-to-first-error nil
686 "If non-nil, automatically jump to the first error after `compile'."
687 :type 'boolean
688 :group 'compilation
689 :version "23.1")
691 (defvar compilation-auto-jump-to-next nil
692 "If non-nil, automatically jump to the next error encountered.")
693 (make-variable-buffer-local 'compilation-auto-jump-to-next)
696 (defvar compilation-skip-to-next-location t
697 "*If non-nil, skip multiple error messages for the same source location.")
699 (defcustom compilation-skip-threshold 1
700 "Compilation motion commands skip less important messages.
701 The value can be either 2 -- skip anything less than error, 1 --
702 skip anything less than warning or 0 -- don't skip any messages.
703 Note that all messages not positively identified as warning or
704 info, are considered errors."
705 :type '(choice (const :tag "Warnings and info" 2)
706 (const :tag "Info" 1)
707 (const :tag "None" 0))
708 :group 'compilation
709 :version "22.1")
711 (defcustom compilation-skip-visited nil
712 "Compilation motion commands skip visited messages if this is t.
713 Visited messages are ones for which the file, line and column have been jumped
714 to from the current content in the current compilation buffer, even if it was
715 from a different message."
716 :type 'boolean
717 :group 'compilation
718 :version "22.1")
720 (defun compilation-face (type)
721 (or (and (car type) (match-end (car type)) compilation-warning-face)
722 (and (cdr type) (match-end (cdr type)) compilation-info-face)
723 compilation-error-face))
725 ;; Internal function for calculating the text properties of a directory
726 ;; change message. The directory property is important, because it is
727 ;; the stack of nested enter-messages. Relative filenames on the following
728 ;; lines are relative to the top of the stack.
729 (defun compilation-directory-properties (idx leave)
730 (if leave (setq leave (match-end leave)))
731 ;; find previous stack, and push onto it, or if `leave' pop it
732 (let ((dir (previous-single-property-change (point) 'directory)))
733 (setq dir (if dir (or (get-text-property (1- dir) 'directory)
734 (get-text-property dir 'directory))))
735 `(face ,(if leave
736 compilation-leave-directory-face
737 compilation-enter-directory-face)
738 directory ,(if leave
739 (or (cdr dir)
740 '(nil)) ; nil only isn't a property-change
741 (cons (match-string-no-properties idx) dir))
742 mouse-face highlight
743 keymap compilation-button-map
744 help-echo "mouse-2: visit destination directory")))
746 ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
747 ;; KEY element from the ALIST, creating it in the right position if not already
748 ;; present. ALIST structure is
749 ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
750 ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
751 ;; may be nil. The other KEYs are ordered backwards so that growing line
752 ;; numbers can be inserted in front and searching can abort after half the
753 ;; list on average.
754 (eval-when-compile ;Don't keep it at runtime if not needed.
755 (defmacro compilation-assq (key alist)
756 `(let* ((l1 ,alist)
757 (l2 (cdr l1)))
758 (car (if (if (null ,key)
759 (if l2 (null (caar l2)))
760 (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
761 (setq l1 l2
762 l2 (cdr l1)))
763 (if l2 (eq ,key (caar l2))))
765 (setcdr l1 (cons (list ,key) l2)))))))
767 (defun compilation-auto-jump (buffer pos)
768 (with-current-buffer buffer
769 (goto-char pos)
770 (if compilation-auto-jump-to-first-error
771 (compile-goto-error))))
773 ;; This function is the central driver, called when font-locking to gather
774 ;; all information needed to later jump to corresponding source code.
775 ;; Return a property list with all meta information on this error location.
777 (defun compilation-error-properties (file line end-line col end-col type fmt)
778 (unless (< (next-single-property-change (match-beginning 0)
779 'directory nil (point))
780 (point))
781 (if file
782 (if (functionp file)
783 (setq file (funcall file))
784 (let (dir)
785 (setq file (match-string-no-properties file))
786 (unless (file-name-absolute-p file)
787 (setq dir (previous-single-property-change (point) 'directory)
788 dir (if dir (or (get-text-property (1- dir) 'directory)
789 (get-text-property dir 'directory)))))
790 (setq file (cons file (car dir)))))
791 ;; This message didn't mention one, get it from previous
792 (let ((prev-pos
793 ;; Find the previous message.
794 (previous-single-property-change (point) 'message)))
795 (if prev-pos
796 ;; Get the file structure that belongs to it.
797 (let* ((prev
798 (or (get-text-property (1- prev-pos) 'message)
799 (get-text-property prev-pos 'message)))
800 (prev-struct
801 (car (nth 2 (car prev)))))
802 ;; Construct FILE . DIR from that.
803 (if prev-struct
804 (setq file (cons (car prev-struct)
805 (cadr prev-struct))))))
806 (unless file
807 (setq file '("*unknown*")))))
808 ;; All of these fields are optional, get them only if we have an index, and
809 ;; it matched some part of the message.
810 (and line
811 (setq line (match-string-no-properties line))
812 (setq line (string-to-number line)))
813 (and end-line
814 (setq end-line (match-string-no-properties end-line))
815 (setq end-line (string-to-number end-line)))
816 (if col
817 (if (functionp col)
818 (setq col (funcall col))
819 (and
820 (setq col (match-string-no-properties col))
821 (setq col (- (string-to-number col) compilation-first-column)))))
822 (if (and end-col (functionp end-col))
823 (setq end-col (funcall end-col))
824 (if (and end-col (setq end-col (match-string-no-properties end-col)))
825 (setq end-col (- (string-to-number end-col) compilation-first-column -1))
826 (if end-line (setq end-col -1))))
827 (if (consp type) ; not a static type, check what it is.
828 (setq type (or (and (car type) (match-end (car type)) 1)
829 (and (cdr type) (match-end (cdr type)) 0)
830 2)))
832 (when (and compilation-auto-jump-to-next
833 (>= type compilation-skip-threshold))
834 (kill-local-variable 'compilation-auto-jump-to-next)
835 (run-with-timer 0 nil 'compilation-auto-jump
836 (current-buffer) (match-beginning 0)))
838 (compilation-internal-error-properties file line end-line col end-col type fmt)))
840 (defun compilation-move-to-column (col screen)
841 "Go to column COL on the current line.
842 If SCREEN is non-nil, columns are screen columns, otherwise, they are
843 just char-counts."
844 (if screen
845 (move-to-column col)
846 (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
848 (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
849 "Get the meta-info that will be added as text-properties.
850 LINE, END-LINE, COL, END-COL are integers or nil.
851 TYPE can be 0, 1, or 2, meaning error, warning, or just info.
852 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
853 FMTS is a list of format specs for transforming the file name.
854 (See `compilation-error-regexp-alist'.)"
855 (unless file (setq file '("*unknown*")))
856 (let* ((file-struct (compilation-get-file-structure file fmts))
857 ;; Get first already existing marker (if any has one, all have one).
858 ;; Do this first, as the compilation-assq`s may create new nodes.
859 (marker-line (car (cddr file-struct))) ; a line structure
860 (marker (nth 3 (cadr marker-line))) ; its marker
861 (compilation-error-screen-columns compilation-error-screen-columns)
862 end-marker loc end-loc)
863 (if (not (and marker (marker-buffer marker)))
864 (setq marker nil) ; no valid marker for this file
865 (setq loc (or line 1)) ; normalize no linenumber to line 1
866 (catch 'marker ; find nearest loc, at least one exists
867 (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines
868 (if (> (car x) loc) ; still bigger
869 (setq marker-line x)
870 (if (> (- (or (car marker-line) 1) loc)
871 (- loc (car x))) ; current line is nearer
872 (setq marker-line x))
873 (throw 'marker t))))
874 (setq marker (nth 3 (cadr marker-line))
875 marker-line (or (car marker-line) 1))
876 (with-current-buffer (marker-buffer marker)
877 (save-excursion
878 (save-restriction
879 (widen)
880 (goto-char (marker-position marker))
881 (when (or end-col end-line)
882 (beginning-of-line (- (or end-line line) marker-line -1))
883 (if (or (null end-col) (< end-col 0))
884 (end-of-line)
885 (compilation-move-to-column
886 end-col compilation-error-screen-columns))
887 (setq end-marker (list (point-marker))))
888 (beginning-of-line (if end-line
889 (- line end-line -1)
890 (- loc marker-line -1)))
891 (if col
892 (compilation-move-to-column
893 col compilation-error-screen-columns)
894 (forward-to-indentation 0))
895 (setq marker (list (point-marker)))))))
897 (setq loc (compilation-assq line (cdr file-struct)))
898 (if end-line
899 (setq end-loc (compilation-assq end-line (cdr file-struct))
900 end-loc (compilation-assq end-col end-loc))
901 (if end-col ; use same line element
902 (setq end-loc (compilation-assq end-col loc))))
903 (setq loc (compilation-assq col loc))
904 ;; If they are new, make the loc(s) reference the file they point to.
905 (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker)))
906 (if end-loc
907 (or (cdr end-loc)
908 (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker))))
910 ;; Must start with face
911 `(face ,compilation-message-face
912 message (,loc ,type ,end-loc)
913 ,@(if compilation-debug
914 `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords)
915 ,@(match-data))))
916 help-echo ,(if col
917 "mouse-2: visit this file, line and column"
918 (if line
919 "mouse-2: visit this file and line"
920 "mouse-2: visit this file"))
921 keymap compilation-button-map
922 mouse-face highlight)))
924 (defun compilation-mode-font-lock-keywords ()
925 "Return expressions to highlight in Compilation mode."
926 (if compilation-parse-errors-function
927 ;; An old package! Try the compatibility code.
928 '((compilation-compat-parse-errors))
929 (append
930 ;; make directory tracking
931 (if compilation-directory-matcher
932 `((,(car compilation-directory-matcher)
933 ,@(mapcar (lambda (elt)
934 `(,(car elt)
935 (compilation-directory-properties
936 ,(car elt) ,(cdr elt))
937 t t))
938 (cdr compilation-directory-matcher)))))
940 ;; Compiler warning/error lines.
941 (mapcar
942 (lambda (item)
943 (if (symbolp item)
944 (setq item (cdr (assq item
945 compilation-error-regexp-alist-alist))))
946 (let ((file (nth 1 item))
947 (line (nth 2 item))
948 (col (nth 3 item))
949 (type (nth 4 item))
950 end-line end-col fmt)
951 (if (consp file) (setq fmt (cdr file) file (car file)))
952 (if (consp line) (setq end-line (cdr line) line (car line)))
953 (if (consp col) (setq end-col (cdr col) col (car col)))
955 (if (functionp line)
956 ;; The old compile.el had here an undocumented hook that
957 ;; allowed `line' to be a function that computed the actual
958 ;; error location. Let's do our best.
959 `(,(car item)
960 (0 (save-match-data
961 (compilation-compat-error-properties
962 (funcall ',line (cons (match-string ,file)
963 (cons default-directory
964 ',(nthcdr 4 item)))
965 ,(if col `(match-string ,col))))))
966 (,file compilation-error-face t))
968 (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
969 (error "HYPERLINK should be an integer: %s" (nth 5 item)))
971 `(,(nth 0 item)
973 ,@(when (integerp file)
974 `((,file ,(if (consp type)
975 `(compilation-face ',type)
976 (aref [compilation-info-face
977 compilation-warning-face
978 compilation-error-face]
979 (or type 2))))))
981 ,@(when line
982 `((,line compilation-line-face nil t)))
983 ,@(when end-line
984 `((,end-line compilation-line-face nil t)))
986 ,@(when (integerp col)
987 `((,col compilation-column-face nil t)))
988 ,@(when (integerp end-col)
989 `((,end-col compilation-column-face nil t)))
991 ,@(nthcdr 6 item)
992 (,(or (nth 5 item) 0)
993 (compilation-error-properties ',file ,line ,end-line
994 ,col ,end-col ',(or type 2)
995 ',fmt)
996 append))))) ; for compilation-message-face
997 compilation-error-regexp-alist)
999 compilation-mode-font-lock-keywords)))
1002 ;;;###autoload
1003 (defun compile (command &optional comint)
1004 "Compile the program including the current buffer. Default: run `make'.
1005 Runs COMMAND, a shell command, in a separate process asynchronously
1006 with output going to the buffer `*compilation*'.
1008 You can then use the command \\[next-error] to find the next error message
1009 and move to the source code that caused it.
1011 If optional second arg COMINT is t the buffer will be in Comint mode with
1012 `compilation-shell-minor-mode'.
1014 Interactively, prompts for the command if `compilation-read-command' is
1015 non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
1016 Additionally, with universal prefix arg, compilation buffer will be in
1017 comint mode, i.e. interactive.
1019 To run more than one compilation at once, start one then rename
1020 the \`*compilation*' buffer to some other name with
1021 \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
1022 It will create a new \`*compilation*' buffer.
1024 On most systems, termination of the main compilation process
1025 kills its subprocesses.
1027 The name used for the buffer is actually whatever is returned by
1028 the function in `compilation-buffer-name-function', so you can set that
1029 to a function that generates a unique name."
1030 (interactive
1031 (list
1032 (let ((command (eval compile-command)))
1033 (if (or compilation-read-command current-prefix-arg)
1034 (read-from-minibuffer "Compile command: "
1035 command nil nil
1036 (if (equal (car compile-history) command)
1037 '(compile-history . 1)
1038 'compile-history))
1039 command))
1040 (consp current-prefix-arg)))
1041 (unless (equal command (eval compile-command))
1042 (setq compile-command command))
1043 (save-some-buffers (not compilation-ask-about-save) nil)
1044 (setq-default compilation-directory default-directory)
1045 (compilation-start command comint))
1047 ;; run compile with the default command line
1048 (defun recompile ()
1049 "Re-compile the program including the current buffer.
1050 If this is run in a Compilation mode buffer, re-use the arguments from the
1051 original use. Otherwise, recompile using `compile-command'."
1052 (interactive)
1053 (save-some-buffers (not compilation-ask-about-save) nil)
1054 (let ((default-directory (or compilation-directory default-directory)))
1055 (apply 'compilation-start (or compilation-arguments
1056 `(,(eval compile-command))))))
1058 (defcustom compilation-scroll-output nil
1059 "Non-nil to scroll the *compilation* buffer window as output appears.
1061 Setting it causes the Compilation mode commands to put point at the
1062 end of their output window so that the end of the output is always
1063 visible rather than the beginning.
1065 The value `first-error' stops scrolling at the first error, and leaves
1066 point on its location in the *compilation* buffer."
1067 :type '(choice (const :tag "No scrolling" nil)
1068 (const :tag "Scroll compilation output" t)
1069 (const :tag "Stop scrolling at the first error" first-error))
1070 :version "20.3"
1071 :group 'compilation)
1074 (defun compilation-buffer-name (mode-name mode-command name-function)
1075 "Return the name of a compilation buffer to use.
1076 If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
1077 to determine the buffer name.
1078 Likewise if `compilation-buffer-name-function' is non-nil.
1079 If current buffer has the major mode MODE-COMMAND,
1080 return the name of the current buffer, so that it gets reused.
1081 Otherwise, construct a buffer name from MODE-NAME."
1082 (cond (name-function
1083 (funcall name-function mode-name))
1084 (compilation-buffer-name-function
1085 (funcall compilation-buffer-name-function mode-name))
1086 ((eq mode-command major-mode)
1087 (buffer-name))
1089 (concat "*" (downcase mode-name) "*"))))
1091 ;; This is a rough emulation of the old hack, until the transition to new
1092 ;; compile is complete.
1093 (defun compile-internal (command error-message
1094 &optional name-of-mode parser
1095 error-regexp-alist name-function
1096 enter-regexp-alist leave-regexp-alist
1097 file-regexp-alist nomessage-regexp-alist
1098 no-async highlight-regexp local-map)
1099 (if parser
1100 (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
1101 (let ((compilation-error-regexp-alist
1102 (append file-regexp-alist (or error-regexp-alist
1103 compilation-error-regexp-alist)))
1104 (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
1105 "\\1" error-message)))
1106 (compilation-start command nil name-function highlight-regexp)))
1107 (make-obsolete 'compile-internal 'compilation-start)
1109 ;;;###autoload
1110 (defun compilation-start (command &optional mode name-function highlight-regexp)
1111 "Run compilation command COMMAND (low level interface).
1112 If COMMAND starts with a cd command, that becomes the `default-directory'.
1113 The rest of the arguments are optional; for them, nil means use the default.
1115 MODE is the major mode to set in the compilation buffer. Mode
1116 may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
1118 If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
1119 to determine the buffer name. Otherwise, the default is to
1120 reuses the current buffer if it has the proper major mode,
1121 else use or create a buffer with name based on the major mode.
1123 If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
1124 the matching section of the visited source line; the default is to use the
1125 global value of `compilation-highlight-regexp'.
1127 Returns the compilation buffer created."
1128 (or mode (setq mode 'compilation-mode))
1129 (let* ((name-of-mode
1130 (if (eq mode t)
1131 (prog1 "compilation" (require 'comint))
1132 (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
1133 (thisdir default-directory)
1134 outwin outbuf)
1135 (with-current-buffer
1136 (setq outbuf
1137 (get-buffer-create
1138 (compilation-buffer-name name-of-mode mode name-function)))
1139 (let ((comp-proc (get-buffer-process (current-buffer))))
1140 (if comp-proc
1141 (if (or (not (eq (process-status comp-proc) 'run))
1142 (yes-or-no-p
1143 (format "A %s process is running; kill it? "
1144 name-of-mode)))
1145 (condition-case ()
1146 (progn
1147 (interrupt-process comp-proc)
1148 (sit-for 1)
1149 (delete-process comp-proc))
1150 (error nil))
1151 (error "Cannot have two processes in `%s' at once"
1152 (buffer-name)))))
1153 (buffer-disable-undo (current-buffer))
1154 ;; first transfer directory from where M-x compile was called
1155 (setq default-directory thisdir)
1156 ;; Remember the original dir, so we can use it when we recompile.
1157 ;; default-directory' can't be used reliably for that because it may be
1158 ;; affected by the special handling of "cd ...;".
1159 (set (make-local-variable 'compilation-directory) thisdir)
1160 ;; Make compilation buffer read-only. The filter can still write it.
1161 ;; Clear out the compilation buffer.
1162 (let ((inhibit-read-only t)
1163 (default-directory thisdir))
1164 ;; Then evaluate a cd command if any, but don't perform it yet, else
1165 ;; start-command would do it again through the shell: (cd "..") AND
1166 ;; sh -c "cd ..; make"
1167 (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command)
1168 (if (match-end 1)
1169 (substitute-env-vars (match-string 1 command))
1170 "~")
1171 default-directory))
1172 (erase-buffer)
1173 ;; Select the desired mode.
1174 (if (not (eq mode t))
1175 (funcall mode)
1176 (setq buffer-read-only nil)
1177 (with-no-warnings (comint-mode))
1178 (compilation-shell-minor-mode))
1179 (if highlight-regexp
1180 (set (make-local-variable 'compilation-highlight-regexp)
1181 highlight-regexp))
1182 (if (or compilation-auto-jump-to-first-error
1183 (eq compilation-scroll-output 'first-error))
1184 (set (make-local-variable 'compilation-auto-jump-to-next) t))
1185 ;; Output a mode setter, for saving and later reloading this buffer.
1186 (insert "-*- mode: " name-of-mode
1187 "; default-directory: " (prin1-to-string default-directory)
1188 " -*-\n"
1189 (format "%s started at %s\n\n"
1190 mode-name
1191 (substring (current-time-string) 0 19))
1192 command "\n")
1193 (setq thisdir default-directory))
1194 (set-buffer-modified-p nil))
1195 ;; Pop up the compilation buffer.
1196 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html
1197 (setq outwin (display-buffer outbuf))
1198 (with-current-buffer outbuf
1199 (let ((process-environment
1200 (append
1201 compilation-environment
1202 (if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning
1203 system-uses-terminfo)
1204 (list "TERM=dumb" "TERMCAP="
1205 (format "COLUMNS=%d" (window-width)))
1206 (list "TERM=emacs"
1207 (format "TERMCAP=emacs:co#%d:tc=unknown:"
1208 (window-width))))
1209 ;; Set the EMACS variable, but
1210 ;; don't override users' setting of $EMACS.
1211 (unless (getenv "EMACS")
1212 (list "EMACS=t"))
1213 (list "INSIDE_EMACS=t")
1214 (copy-sequence process-environment))))
1215 (set (make-local-variable 'compilation-arguments)
1216 (list command mode name-function highlight-regexp))
1217 (set (make-local-variable 'revert-buffer-function)
1218 'compilation-revert-buffer)
1219 (set-window-start outwin (point-min))
1221 ;; Position point as the user will see it.
1222 (let ((desired-visible-point
1223 ;; Put it at the end if `compilation-scroll-output' is set.
1224 (if compilation-scroll-output
1225 (point-max)
1226 ;; Normally put it at the top.
1227 (point-min))))
1228 (if (eq outwin (selected-window))
1229 (goto-char desired-visible-point)
1230 (set-window-point outwin desired-visible-point)))
1232 ;; The setup function is called before compilation-set-window-height
1233 ;; so it can set the compilation-window-height buffer locally.
1234 (if compilation-process-setup-function
1235 (funcall compilation-process-setup-function))
1236 (compilation-set-window-height outwin)
1237 ;; Start the compilation.
1238 (let ((proc
1239 (if (eq mode t)
1240 ;; comint uses `start-file-process'.
1241 (get-buffer-process
1242 (with-no-warnings
1243 (comint-exec
1244 outbuf (downcase mode-name)
1245 (if (file-remote-p default-directory)
1246 "/bin/sh"
1247 shell-file-name)
1248 nil `("-c" ,command))))
1249 (start-file-process-shell-command (downcase mode-name)
1250 outbuf command))))
1251 ;; Make the buffer's mode line show process state.
1252 (setq mode-line-process
1253 (list (propertize ":%s" 'face 'compilation-warning)))
1254 (set-process-sentinel proc 'compilation-sentinel)
1255 (set-process-filter proc 'compilation-filter)
1256 ;; Use (point-max) here so that output comes in
1257 ;; after the initial text,
1258 ;; regardless of where the user sees point.
1259 (set-marker (process-mark proc) (point-max) outbuf)
1260 (when compilation-disable-input
1261 (condition-case nil
1262 (process-send-eof proc)
1263 ;; The process may have exited already.
1264 (error nil)))
1265 (setq compilation-in-progress
1266 (cons proc compilation-in-progress))))
1267 ;; Now finally cd to where the shell started make/grep/...
1268 (setq default-directory thisdir))
1269 (if (buffer-local-value 'compilation-scroll-output outbuf)
1270 (save-selected-window
1271 (select-window outwin)
1272 (goto-char (point-max))))
1273 ;; Make it so the next C-x ` will use this buffer.
1274 (setq next-error-last-buffer outbuf)))
1276 (defun compilation-set-window-height (window)
1277 "Set the height of WINDOW according to `compilation-window-height'."
1278 (let ((height (buffer-local-value 'compilation-window-height (window-buffer window))))
1279 (and height
1280 (window-full-width-p window)
1281 ;; If window is alone in its frame, aside from a minibuffer,
1282 ;; don't change its height.
1283 (not (eq window (frame-root-window (window-frame window))))
1284 ;; Stef said that doing the saves in this order is safer:
1285 (save-excursion
1286 (save-selected-window
1287 (select-window window)
1288 (enlarge-window (- height (window-height))))))))
1290 (defvar compilation-menu-map
1291 (let ((map (make-sparse-keymap "Errors"))
1292 (opt-map (make-sparse-keymap "Skip")))
1293 (define-key map [stop-subjob]
1294 '(menu-item "Stop Compilation" kill-compilation
1295 :help "Kill the process made by the M-x compile or M-x grep commands"))
1296 (define-key map [compilation-mode-separator3]
1297 '("----" . nil))
1298 (define-key map [compilation-next-error-follow-minor-mode]
1299 '(menu-item
1300 "Auto Error Display" next-error-follow-minor-mode
1301 :help "Display the error under cursor when moving the cursor"
1302 :button (:toggle . next-error-follow-minor-mode)))
1303 (define-key map [compilation-skip]
1304 (cons "Skip Less Important Messages" opt-map))
1305 (define-key opt-map [compilation-skip-none]
1306 '(menu-item "Don't Skip Any Messages"
1307 (lambda ()
1308 (interactive)
1309 (customize-set-variable 'compilation-skip-threshold 0))
1310 :help "Do not skip any type of messages"
1311 :button (:radio . (eq compilation-skip-threshold 0))))
1312 (define-key opt-map [compilation-skip-info]
1313 '(menu-item "Skip Info"
1314 (lambda ()
1315 (interactive)
1316 (customize-set-variable 'compilation-skip-threshold 1))
1317 :help "Skip anything less than warning"
1318 :button (:radio . (eq compilation-skip-threshold 1))))
1319 (define-key opt-map [compilation-skip-warning-and-info]
1320 '(menu-item "Skip Warnings and Info"
1321 (lambda ()
1322 (interactive)
1323 (customize-set-variable 'compilation-skip-threshold 2))
1324 :help "Skip over Warnings and Info, stop for errors"
1325 :button (:radio . (eq compilation-skip-threshold 2))))
1326 (define-key map [compilation-mode-separator2]
1327 '("----" . nil))
1328 (define-key map [compilation-first-error]
1329 '(menu-item "First Error" first-error
1330 :help "Restart at the first error, visit corresponding source code"))
1331 (define-key map [compilation-previous-error]
1332 '(menu-item "Previous Error" previous-error
1333 :help "Visit previous `next-error' message and corresponding source code"))
1334 (define-key map [compilation-next-error]
1335 '(menu-item "Next Error" next-error
1336 :help "Visit next `next-error' message and corresponding source code"))
1337 map))
1339 (defvar compilation-minor-mode-map
1340 (let ((map (make-sparse-keymap)))
1341 (define-key map [mouse-2] 'compile-goto-error)
1342 (define-key map [follow-link] 'mouse-face)
1343 (define-key map "\C-c\C-c" 'compile-goto-error)
1344 (define-key map "\C-m" 'compile-goto-error)
1345 (define-key map "\C-c\C-k" 'kill-compilation)
1346 (define-key map "\M-n" 'compilation-next-error)
1347 (define-key map "\M-p" 'compilation-previous-error)
1348 (define-key map "\M-{" 'compilation-previous-file)
1349 (define-key map "\M-}" 'compilation-next-file)
1350 ;; Set up the menu-bar
1351 (define-key map [menu-bar compilation]
1352 (cons "Errors" compilation-menu-map))
1353 map)
1354 "Keymap for `compilation-minor-mode'.")
1356 (defvar compilation-shell-minor-mode-map
1357 (let ((map (make-sparse-keymap)))
1358 (define-key map "\M-\C-m" 'compile-goto-error)
1359 (define-key map "\M-\C-n" 'compilation-next-error)
1360 (define-key map "\M-\C-p" 'compilation-previous-error)
1361 (define-key map "\M-{" 'compilation-previous-file)
1362 (define-key map "\M-}" 'compilation-next-file)
1363 ;; Set up the menu-bar
1364 (define-key map [menu-bar compilation]
1365 (cons "Errors" compilation-menu-map))
1366 map)
1367 "Keymap for `compilation-shell-minor-mode'.")
1369 (defvar compilation-button-map
1370 (let ((map (make-sparse-keymap)))
1371 (define-key map [mouse-2] 'compile-goto-error)
1372 (define-key map [follow-link] 'mouse-face)
1373 (define-key map "\C-m" 'compile-goto-error)
1374 map)
1375 "Keymap for compilation-message buttons.")
1376 (fset 'compilation-button-map compilation-button-map)
1378 (defvar compilation-mode-map
1379 (let ((map (make-sparse-keymap)))
1380 ;; Don't inherit from compilation-minor-mode-map,
1381 ;; because that introduces a menu bar item we don't want.
1382 ;; That confuses C-down-mouse-3.
1383 (define-key map [mouse-2] 'compile-goto-error)
1384 (define-key map [follow-link] 'mouse-face)
1385 (define-key map "\C-c\C-c" 'compile-goto-error)
1386 (define-key map "\C-m" 'compile-goto-error)
1387 (define-key map "\C-c\C-k" 'kill-compilation)
1388 (define-key map "\M-n" 'compilation-next-error)
1389 (define-key map "\M-p" 'compilation-previous-error)
1390 (define-key map "\M-{" 'compilation-previous-file)
1391 (define-key map "\M-}" 'compilation-next-file)
1392 (define-key map "\t" 'compilation-next-error)
1393 (define-key map [backtab] 'compilation-previous-error)
1395 (define-key map " " 'scroll-up)
1396 (define-key map "\^?" 'scroll-down)
1397 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
1399 ;; Set up the menu-bar
1400 (let ((submap (make-sparse-keymap "Compile")))
1401 (define-key map [menu-bar compilation]
1402 (cons "Compile" submap))
1403 (set-keymap-parent submap compilation-menu-map))
1404 (define-key map [menu-bar compilation compilation-separator2]
1405 '("----" . nil))
1406 (define-key map [menu-bar compilation compilation-grep]
1407 '(menu-item "Search Files (grep)..." grep
1408 :help "Run grep, with user-specified args, and collect output in a buffer"))
1409 (define-key map [menu-bar compilation compilation-recompile]
1410 '(menu-item "Recompile" recompile
1411 :help "Re-compile the program including the current buffer"))
1412 (define-key map [menu-bar compilation compilation-compile]
1413 '(menu-item "Compile..." compile
1414 :help "Compile the program including the current buffer. Default: run `make'"))
1415 map)
1416 "Keymap for compilation log buffers.
1417 `compilation-minor-mode-map' is a parent of this.")
1419 (defvar compilation-mode-tool-bar-map
1420 (if (display-graphic-p)
1421 (let ((map (butlast (copy-keymap tool-bar-map)))
1422 (help (last tool-bar-map))) ;; Keep Help last in tool bar
1423 (tool-bar-local-item
1424 "left-arrow" 'previous-error-no-select 'previous-error-no-select map
1425 :rtl "right-arrow"
1426 :help "Goto previous error")
1427 (tool-bar-local-item
1428 "right-arrow" 'next-error-no-select 'next-error-no-select map
1429 :rtl "left-arrow"
1430 :help "Goto next error")
1431 (tool-bar-local-item
1432 "cancel" 'kill-compilation 'kill-compilation map
1433 :help "Stop compilation")
1434 (tool-bar-local-item
1435 "refresh" 'recompile 'recompile map
1436 :help "Restart compilation")
1437 (append map help))))
1439 (put 'compilation-mode 'mode-class 'special)
1441 ;;;###autoload
1442 (defun compilation-mode (&optional name-of-mode)
1443 "Major mode for compilation log buffers.
1444 \\<compilation-mode-map>To visit the source for a line-numbered error,
1445 move point to the error message line and type \\[compile-goto-error].
1446 To kill the compilation, type \\[kill-compilation].
1448 Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
1450 \\{compilation-mode-map}"
1451 (interactive)
1452 (kill-all-local-variables)
1453 (use-local-map compilation-mode-map)
1454 (set (make-local-variable 'tool-bar-map) compilation-mode-tool-bar-map)
1455 (setq major-mode 'compilation-mode
1456 mode-name (or name-of-mode "Compilation"))
1457 (set (make-local-variable 'page-delimiter)
1458 compilation-page-delimiter)
1459 (compilation-setup)
1460 (setq buffer-read-only t)
1461 (run-mode-hooks 'compilation-mode-hook))
1463 (defmacro define-compilation-mode (mode name doc &rest body)
1464 "This is like `define-derived-mode' without the PARENT argument.
1465 The parent is always `compilation-mode' and the customizable `compilation-...'
1466 variables are also set from the name of the mode you have chosen,
1467 by replacing the first word, e.g `compilation-scroll-output' from
1468 `grep-scroll-output' if that variable exists."
1469 (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
1470 `(define-derived-mode ,mode compilation-mode ,name
1471 ,doc
1472 ,@(mapcar (lambda (v)
1473 (setq v (cons v
1474 (intern-soft (replace-regexp-in-string
1475 "^compilation" mode-name
1476 (symbol-name v)))))
1477 (and (cdr v)
1478 (or (boundp (cdr v))
1479 (if (boundp 'byte-compile-bound-variables)
1480 (memq (cdr v) byte-compile-bound-variables)))
1481 `(set (make-local-variable ',(car v)) ,(cdr v))))
1482 '(compilation-buffer-name-function
1483 compilation-directory-matcher
1484 compilation-error
1485 compilation-error-regexp-alist
1486 compilation-error-regexp-alist-alist
1487 compilation-error-screen-columns
1488 compilation-finish-function
1489 compilation-finish-functions
1490 compilation-first-column
1491 compilation-mode-font-lock-keywords
1492 compilation-page-delimiter
1493 compilation-parse-errors-filename-function
1494 compilation-process-setup-function
1495 compilation-scroll-output
1496 compilation-search-path
1497 compilation-skip-threshold
1498 compilation-window-height))
1499 ,@body)))
1501 (defun compilation-revert-buffer (ignore-auto noconfirm)
1502 (if buffer-file-name
1503 (let (revert-buffer-function)
1504 (revert-buffer ignore-auto noconfirm))
1505 (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
1506 (apply 'compilation-start compilation-arguments))))
1508 (defvar compilation-current-error nil
1509 "Marker to the location from where the next error will be found.
1510 The global commands next/previous/first-error/goto-error use this.")
1512 (defvar compilation-messages-start nil
1513 "Buffer position of the beginning of the compilation messages.
1514 If nil, use the beginning of buffer.")
1516 ;; A function name can't be a hook, must be something with a value.
1517 (defconst compilation-turn-on-font-lock 'turn-on-font-lock)
1519 (defun compilation-setup (&optional minor)
1520 "Prepare the buffer for the compilation parsing commands to work.
1521 Optional argument MINOR indicates this is called from
1522 `compilation-minor-mode'."
1523 (make-local-variable 'compilation-current-error)
1524 (make-local-variable 'compilation-messages-start)
1525 (make-local-variable 'compilation-error-screen-columns)
1526 (make-local-variable 'overlay-arrow-position)
1527 (set (make-local-variable 'overlay-arrow-string) "")
1528 (setq next-error-overlay-arrow-position nil)
1529 (add-hook 'kill-buffer-hook
1530 (lambda () (setq next-error-overlay-arrow-position nil)) nil t)
1531 ;; Note that compilation-next-error-function is for interfacing
1532 ;; with the next-error function in simple.el, and it's only
1533 ;; coincidentally named similarly to compilation-next-error.
1534 (setq next-error-function 'compilation-next-error-function)
1535 (set (make-local-variable 'comint-file-name-prefix)
1536 (or (file-remote-p default-directory) ""))
1537 (set (make-local-variable 'font-lock-extra-managed-props)
1538 '(directory message help-echo mouse-face debug))
1539 (set (make-local-variable 'compilation-locs)
1540 (make-hash-table :test 'equal :weakness 'value))
1541 ;; lazy-lock would never find the message unless it's scrolled to.
1542 ;; jit-lock might fontify some things too late.
1543 (set (make-local-variable 'font-lock-support-mode) nil)
1544 (set (make-local-variable 'font-lock-maximum-size) nil)
1545 (if minor
1546 (let ((fld font-lock-defaults))
1547 (font-lock-add-keywords nil (compilation-mode-font-lock-keywords))
1548 (if font-lock-mode
1549 (if fld
1550 (font-lock-fontify-buffer)
1551 (font-lock-change-mode)
1552 (turn-on-font-lock))
1553 (turn-on-font-lock)))
1554 (setq font-lock-defaults '(compilation-mode-font-lock-keywords t))
1555 ;; maybe defer font-lock till after derived mode is set up
1556 (run-mode-hooks 'compilation-turn-on-font-lock)))
1558 ;;;###autoload
1559 (define-minor-mode compilation-shell-minor-mode
1560 "Toggle compilation shell minor mode.
1561 With arg, turn compilation mode on if and only if arg is positive.
1562 In this minor mode, all the error-parsing commands of the
1563 Compilation major mode are available but bound to keys that don't
1564 collide with Shell mode. See `compilation-mode'.
1565 Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
1566 nil " Shell-Compile"
1567 :group 'compilation
1568 (if compilation-shell-minor-mode
1569 (compilation-setup t)
1570 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1571 (font-lock-fontify-buffer)))
1573 ;;;###autoload
1574 (define-minor-mode compilation-minor-mode
1575 "Toggle compilation minor mode.
1576 With arg, turn compilation mode on if and only if arg is positive.
1577 In this minor mode, all the error-parsing commands of the
1578 Compilation major mode are available. See `compilation-mode'.
1579 Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
1580 nil " Compilation"
1581 :group 'compilation
1582 (if compilation-minor-mode
1583 (compilation-setup t)
1584 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1585 (font-lock-fontify-buffer)))
1587 (defun compilation-handle-exit (process-status exit-status msg)
1588 "Write MSG in the current buffer and hack its `mode-line-process'."
1589 (let ((inhibit-read-only t)
1590 (status (if compilation-exit-message-function
1591 (funcall compilation-exit-message-function
1592 process-status exit-status msg)
1593 (cons msg exit-status)))
1594 (omax (point-max))
1595 (opoint (point))
1596 (cur-buffer (current-buffer)))
1597 ;; Record where we put the message, so we can ignore it later on.
1598 (goto-char omax)
1599 (insert ?\n mode-name " " (car status))
1600 (if (and (numberp compilation-window-height)
1601 (zerop compilation-window-height))
1602 (message "%s" (cdr status)))
1603 (if (bolp)
1604 (forward-char -1))
1605 (insert " at " (substring (current-time-string) 0 19))
1606 (goto-char (point-max))
1607 ;; Prevent that message from being recognized as a compilation error.
1608 (add-text-properties omax (point)
1609 (append '(compilation-handle-exit t) nil))
1610 (setq mode-line-process
1611 (let ((out-string (format ":%s [%s]" process-status (cdr status)))
1612 (msg (format "%s %s" mode-name
1613 (replace-regexp-in-string "\n?$" "" (car status)))))
1614 (message "%s" msg)
1615 (propertize out-string
1616 'help-echo msg 'face (if (> exit-status 0)
1617 'compilation-error
1618 'compilation-info))))
1619 ;; Force mode line redisplay soon.
1620 (force-mode-line-update)
1621 (if (and opoint (< opoint omax))
1622 (goto-char opoint))
1623 (with-no-warnings
1624 (if compilation-finish-function
1625 (funcall compilation-finish-function cur-buffer msg)))
1626 (run-hook-with-args 'compilation-finish-functions cur-buffer msg)))
1628 ;; Called when compilation process changes state.
1629 (defun compilation-sentinel (proc msg)
1630 "Sentinel for compilation buffers."
1631 (if (memq (process-status proc) '(exit signal))
1632 (let ((buffer (process-buffer proc)))
1633 (if (null (buffer-name buffer))
1634 ;; buffer killed
1635 (set-process-buffer proc nil)
1636 (with-current-buffer buffer
1637 ;; Write something in the compilation buffer
1638 ;; and hack its mode line.
1639 (compilation-handle-exit (process-status proc)
1640 (process-exit-status proc)
1641 msg)
1642 ;; Since the buffer and mode line will show that the
1643 ;; process is dead, we can delete it now. Otherwise it
1644 ;; will stay around until M-x list-processes.
1645 (delete-process proc)))
1646 (setq compilation-in-progress (delq proc compilation-in-progress)))))
1648 (defun compilation-filter (proc string)
1649 "Process filter for compilation buffers.
1650 Just inserts the text, but uses `insert-before-markers'."
1651 (if (buffer-name (process-buffer proc))
1652 (with-current-buffer (process-buffer proc)
1653 (let ((inhibit-read-only t))
1654 (save-excursion
1655 (goto-char (process-mark proc))
1656 (insert-before-markers string)
1657 (run-hooks 'compilation-filter-hook))))))
1659 ;;; test if a buffer is a compilation buffer, assuming we're in the buffer
1660 (defsubst compilation-buffer-internal-p ()
1661 "Test if inside a compilation buffer."
1662 (local-variable-p 'compilation-locs))
1664 ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p
1665 (defsubst compilation-buffer-p (buffer)
1666 "Test if BUFFER is a compilation buffer."
1667 (with-current-buffer buffer
1668 (compilation-buffer-internal-p)))
1670 (defmacro compilation-loop (< property-change 1+ error limit)
1671 `(let (opt)
1672 (while (,< n 0)
1673 (setq opt pt)
1674 (or (setq pt (,property-change pt 'message))
1675 ;; Handle the case where where the first error message is
1676 ;; at the start of the buffer, and n < 0.
1677 (if (or (eq (get-text-property ,limit 'message)
1678 (get-text-property opt 'message))
1679 (eq pt opt))
1680 (error ,error compilation-error)
1681 (setq pt ,limit)))
1682 ;; prop 'message usually has 2 changes, on and off, so
1683 ;; re-search if off
1684 (or (setq msg (get-text-property pt 'message))
1685 (if (setq pt (,property-change pt 'message nil ,limit))
1686 (setq msg (get-text-property pt 'message)))
1687 (error ,error compilation-error))
1688 (or (< (cadr msg) compilation-skip-threshold)
1689 (if different-file
1690 (eq (prog1 last (setq last (nth 2 (car msg))))
1691 last))
1692 (if compilation-skip-visited
1693 (nthcdr 5 (car msg)))
1694 (if compilation-skip-to-next-location
1695 (eq (car msg) loc))
1696 ;; count this message only if none of the above are true
1697 (setq n (,1+ n))))))
1699 (defun compilation-next-error (n &optional different-file pt)
1700 "Move point to the next error in the compilation buffer.
1701 This function does NOT find the source line like \\[next-error].
1702 Prefix arg N says how many error messages to move forwards (or
1703 backwards, if negative).
1704 Optional arg DIFFERENT-FILE, if non-nil, means find next error for a
1705 file that is different from the current one.
1706 Optional arg PT, if non-nil, specifies the value of point to start
1707 looking for the next message."
1708 (interactive "p")
1709 (or (compilation-buffer-p (current-buffer))
1710 (error "Not in a compilation buffer"))
1711 (or pt (setq pt (point)))
1712 (let* ((msg (get-text-property pt 'message))
1713 ;; `loc' is used by the compilation-loop macro.
1714 (loc (car msg))
1715 last)
1716 (if (zerop n)
1717 (unless (or msg ; find message near here
1718 (setq msg (get-text-property (max (1- pt) (point-min))
1719 'message)))
1720 (setq pt (previous-single-property-change pt 'message nil
1721 (line-beginning-position)))
1722 (unless (setq msg (get-text-property (max (1- pt) (point-min)) 'message))
1723 (setq pt (next-single-property-change pt 'message nil
1724 (line-end-position)))
1725 (or (setq msg (get-text-property pt 'message))
1726 (setq pt (point)))))
1727 (setq last (nth 2 (car msg)))
1728 (if (>= n 0)
1729 (compilation-loop > next-single-property-change 1-
1730 (if (get-buffer-process (current-buffer))
1731 "No more %ss yet"
1732 "Moved past last %s")
1733 (point-max))
1734 ;; Don't move "back" to message at or before point.
1735 ;; Pass an explicit (point-min) to make sure pt is non-nil.
1736 (setq pt (previous-single-property-change pt 'message nil (point-min)))
1737 (compilation-loop < previous-single-property-change 1+
1738 "Moved back before first %s" (point-min))))
1739 (goto-char pt)
1740 (or msg
1741 (error "No %s here" compilation-error))))
1743 (defun compilation-previous-error (n)
1744 "Move point to the previous error in the compilation buffer.
1745 Prefix arg N says how many error messages to move backwards (or
1746 forwards, if negative).
1747 Does NOT find the source line like \\[previous-error]."
1748 (interactive "p")
1749 (compilation-next-error (- n)))
1751 (defun compilation-next-file (n)
1752 "Move point to the next error for a different file than the current one.
1753 Prefix arg N says how many files to move forwards (or backwards, if negative)."
1754 (interactive "p")
1755 (compilation-next-error n t))
1757 (defun compilation-previous-file (n)
1758 "Move point to the previous error for a different file than the current one.
1759 Prefix arg N says how many files to move backwards (or forwards, if negative)."
1760 (interactive "p")
1761 (compilation-next-file (- n)))
1763 (defun kill-compilation ()
1764 "Kill the process made by the \\[compile] or \\[grep] commands."
1765 (interactive)
1766 (let ((buffer (compilation-find-buffer)))
1767 (if (get-buffer-process buffer)
1768 (interrupt-process (get-buffer-process buffer))
1769 (error "The %s process is not running" (downcase mode-name)))))
1771 (defalias 'compile-mouse-goto-error 'compile-goto-error)
1773 (defun compile-goto-error (&optional event)
1774 "Visit the source for the error message at point.
1775 Use this command in a compilation log buffer. Sets the mark at point there."
1776 (interactive (list last-input-event))
1777 (if event (posn-set-point (event-end event)))
1778 (or (compilation-buffer-p (current-buffer))
1779 (error "Not in a compilation buffer"))
1780 (if (get-text-property (point) 'directory)
1781 (dired-other-window (car (get-text-property (point) 'directory)))
1782 (push-mark)
1783 (setq compilation-current-error (point))
1784 (next-error-internal)))
1786 (defun compilation-find-buffer (&optional avoid-current)
1787 "Return a compilation buffer.
1788 If AVOID-CURRENT is nil, and the current buffer is a compilation buffer,
1789 return it. If AVOID-CURRENT is non-nil, return the current buffer only
1790 as a last resort."
1791 (if (and (compilation-buffer-internal-p) (not avoid-current))
1792 (current-buffer)
1793 (next-error-find-buffer avoid-current 'compilation-buffer-internal-p)))
1795 ;;;###autoload
1796 (defun compilation-next-error-function (n &optional reset)
1797 "Advance to the next error message and visit the file where the error was.
1798 This is the value of `next-error-function' in Compilation buffers."
1799 (interactive "p")
1800 (when reset
1801 (setq compilation-current-error nil))
1802 (let* ((columns compilation-error-screen-columns) ; buffer's local value
1803 (last 1) timestamp
1804 (loc (compilation-next-error (or n 1) nil
1805 (or compilation-current-error
1806 compilation-messages-start
1807 (point-min))))
1808 (end-loc (nth 2 loc))
1809 (marker (point-marker)))
1810 (setq compilation-current-error (point-marker)
1811 overlay-arrow-position
1812 (if (bolp)
1813 compilation-current-error
1814 (copy-marker (line-beginning-position)))
1815 loc (car loc))
1816 ;; If loc contains no marker, no error in that file has been visited.
1817 ;; If the marker is invalid the buffer has been killed.
1818 ;; If the file is newer than the timestamp, it has been modified
1819 ;; (`omake -P' polls filesystem for changes and recompiles when needed
1820 ;; in the same process and buffer).
1821 ;; So, recalculate all markers for that file.
1822 (unless (and (nth 3 loc) (marker-buffer (nth 3 loc))
1823 ;; There may be no timestamp info if the loc is a `fake-loc'.
1824 ;; So we skip the time-check here, although we should maybe
1825 ;; change `compilation-fake-loc' to add timestamp info.
1826 (or (null (nth 4 loc))
1827 (equal (nth 4 loc)
1828 (setq timestamp
1829 (with-current-buffer
1830 (marker-buffer (nth 3 loc))
1831 (visited-file-modtime))))))
1832 (with-current-buffer (compilation-find-file marker (caar (nth 2 loc))
1833 (cadr (car (nth 2 loc))))
1834 (save-restriction
1835 (widen)
1836 (goto-char (point-min))
1837 ;; Treat file's found lines in forward order, 1 by 1.
1838 (dolist (line (reverse (cddr (nth 2 loc))))
1839 (when (car line) ; else this is a filename w/o a line#
1840 (beginning-of-line (- (car line) last -1))
1841 (setq last (car line)))
1842 ;; Treat line's found columns and store/update a marker for each.
1843 (dolist (col (cdr line))
1844 (if (car col)
1845 (if (eq (car col) -1) ; special case for range end
1846 (end-of-line)
1847 (compilation-move-to-column (car col) columns))
1848 (beginning-of-line)
1849 (skip-chars-forward " \t"))
1850 (if (nth 3 col)
1851 (set-marker (nth 3 col) (point))
1852 (setcdr (nthcdr 2 col) `(,(point-marker)))))))))
1853 (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc))
1854 (setcdr (nthcdr 3 loc) (list timestamp))
1855 (setcdr (nthcdr 4 loc) t))) ; Set this one as visited.
1857 (defvar compilation-gcpro nil
1858 "Internal variable used to keep some values from being GC'd.")
1859 (make-variable-buffer-local 'compilation-gcpro)
1861 (defun compilation-fake-loc (marker file &optional line col)
1862 "Preassociate MARKER with FILE.
1863 FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
1864 This is useful when you compile temporary files, but want
1865 automatic translation of the messages to the real buffer from
1866 which the temporary file came. This only works if done before a
1867 message about FILE appears!
1869 Optional args LINE and COL default to 1 and beginning of
1870 indentation respectively. The marker is expected to reflect
1871 this. In the simplest case the marker points to the first line
1872 of the region that was saved to the temp file.
1874 If you concatenate several regions into the temp file (e.g. a
1875 header with variable assignments and a code region), you must
1876 call this several times, once each for the last line of one
1877 region and the first line of the next region."
1878 (or (consp file) (setq file (list file)))
1879 (setq file (compilation-get-file-structure file))
1880 ;; Between the current call to compilation-fake-loc and the first occurrence
1881 ;; of an error message referring to `file', the data is only kept in the
1882 ;; weak hash-table compilation-locs, so we need to prevent this entry
1883 ;; in compilation-locs from being GC'd away. --Stef
1884 (push file compilation-gcpro)
1885 (let ((loc (compilation-assq (or line 1) (cdr file))))
1886 (setq loc (compilation-assq col loc))
1887 (if (cdr loc)
1888 (setcdr (cddr loc) (list marker))
1889 (setcdr loc (list line file marker)))
1890 loc))
1892 (defcustom compilation-context-lines nil
1893 "Display this many lines of leading context before the current message.
1894 If nil and the left fringe is displayed, don't scroll the
1895 compilation output window; an arrow in the left fringe points to
1896 the current message. If nil and there is no left fringe, the message
1897 displays at the top of the window; there is no arrow."
1898 :type '(choice integer (const :tag "No window scrolling" nil))
1899 :group 'compilation
1900 :version "22.1")
1902 (defsubst compilation-set-window (w mk)
1903 "Align the compilation output window W with marker MK near top."
1904 (if (integerp compilation-context-lines)
1905 (set-window-start w (save-excursion
1906 (goto-char mk)
1907 (beginning-of-line
1908 (- 1 compilation-context-lines))
1909 (point)))
1910 ;; If there is no left fringe.
1911 (if (equal (car (window-fringes)) 0)
1912 (set-window-start w (save-excursion
1913 (goto-char mk)
1914 (beginning-of-line 1)
1915 (point)))))
1916 (set-window-point w mk))
1918 (defvar next-error-highlight-timer)
1920 (defun compilation-goto-locus (msg mk end-mk)
1921 "Jump to an error corresponding to MSG at MK.
1922 All arguments are markers. If END-MK is non-nil, mark is set there
1923 and overlay is highlighted between MK and END-MK."
1924 ;; Show compilation buffer in other window, scrolled to this error.
1925 (let* ((from-compilation-buffer (eq (window-buffer (selected-window))
1926 (marker-buffer msg)))
1927 ;; Use an existing window if it is in a visible frame.
1928 (pre-existing (get-buffer-window (marker-buffer msg) 0))
1929 (w (if (and from-compilation-buffer pre-existing)
1930 ;; Calling display-buffer here may end up (partly) hiding
1931 ;; the error location if the two buffers are in two
1932 ;; different frames. So don't do it if it's not necessary.
1933 pre-existing
1934 (let ((display-buffer-reuse-frames t)
1935 (pop-up-windows t))
1936 ;; Pop up a window.
1937 (display-buffer (marker-buffer msg)))))
1938 (highlight-regexp (with-current-buffer (marker-buffer msg)
1939 ;; also do this while we change buffer
1940 (compilation-set-window w msg)
1941 compilation-highlight-regexp)))
1942 ;; Ideally, the window-size should be passed to `display-buffer' (via
1943 ;; something like special-display-buffer) so it's only used when
1944 ;; creating a new window.
1945 (unless pre-existing (compilation-set-window-height w))
1947 (if from-compilation-buffer
1948 ;; If the compilation buffer window was selected,
1949 ;; keep the compilation buffer in this window;
1950 ;; display the source in another window.
1951 (let ((pop-up-windows t))
1952 (pop-to-buffer (marker-buffer mk) 'other-window))
1953 (if (window-dedicated-p (selected-window))
1954 (pop-to-buffer (marker-buffer mk))
1955 (switch-to-buffer (marker-buffer mk))))
1956 ;; If narrowing gets in the way of going to the right place, widen.
1957 (unless (eq (goto-char mk) (point))
1958 (widen)
1959 (goto-char mk))
1960 (if end-mk
1961 (push-mark end-mk t)
1962 (if mark-active (setq mark-active)))
1963 ;; If hideshow got in the way of
1964 ;; seeing the right place, open permanently.
1965 (dolist (ov (overlays-at (point)))
1966 (when (eq 'hs (overlay-get ov 'invisible))
1967 (delete-overlay ov)
1968 (goto-char mk)))
1970 (when highlight-regexp
1971 (if (timerp next-error-highlight-timer)
1972 (cancel-timer next-error-highlight-timer))
1973 (unless compilation-highlight-overlay
1974 (setq compilation-highlight-overlay
1975 (make-overlay (point-min) (point-min)))
1976 (overlay-put compilation-highlight-overlay 'face 'next-error))
1977 (with-current-buffer (marker-buffer mk)
1978 (save-excursion
1979 (if end-mk (goto-char end-mk) (end-of-line))
1980 (let ((end (point)))
1981 (if mk (goto-char mk) (beginning-of-line))
1982 (if (and (stringp highlight-regexp)
1983 (re-search-forward highlight-regexp end t))
1984 (progn
1985 (goto-char (match-beginning 0))
1986 (move-overlay compilation-highlight-overlay
1987 (match-beginning 0) (match-end 0)
1988 (current-buffer)))
1989 (move-overlay compilation-highlight-overlay
1990 (point) end (current-buffer)))
1991 (if (or (eq next-error-highlight t)
1992 (numberp next-error-highlight))
1993 ;; We want highlighting: delete overlay on next input.
1994 (add-hook 'pre-command-hook
1995 'compilation-goto-locus-delete-o)
1996 ;; We don't want highlighting: delete overlay now.
1997 (delete-overlay compilation-highlight-overlay))
1998 ;; We want highlighting for a limited time:
1999 ;; set up a timer to delete it.
2000 (when (numberp next-error-highlight)
2001 (setq next-error-highlight-timer
2002 (run-at-time next-error-highlight nil
2003 'compilation-goto-locus-delete-o)))))))
2004 (when (and (eq next-error-highlight 'fringe-arrow))
2005 ;; We want a fringe arrow (instead of highlighting).
2006 (setq next-error-overlay-arrow-position
2007 (copy-marker (line-beginning-position))))))
2009 (defun compilation-goto-locus-delete-o ()
2010 (delete-overlay compilation-highlight-overlay)
2011 ;; Get rid of timer and hook that would try to do this again.
2012 (if (timerp next-error-highlight-timer)
2013 (cancel-timer next-error-highlight-timer))
2014 (remove-hook 'pre-command-hook
2015 'compilation-goto-locus-delete-o))
2017 (defun compilation-find-file (marker filename directory &rest formats)
2018 "Find a buffer for file FILENAME.
2019 If FILENAME is not found at all, ask the user where to find it.
2020 Pop up the buffer containing MARKER and scroll to MARKER if we ask
2021 the user where to find the file.
2022 Search the directories in `compilation-search-path'.
2023 A nil in `compilation-search-path' means to try the
2024 \"current\" directory, which is passed in DIRECTORY.
2025 If DIRECTORY is relative, it is combined with `default-directory'.
2026 If DIRECTORY is nil, that means use `default-directory'.
2027 FORMATS, if given, is a list of formats to reformat FILENAME when
2028 looking for it: for each element FMT in FORMATS, this function
2029 attempts to find a file whose name is produced by (format FMT FILENAME)."
2030 (or formats (setq formats '("%s")))
2031 (let ((dirs compilation-search-path)
2032 (spec-dir (if directory
2033 (expand-file-name directory)
2034 default-directory))
2035 buffer thisdir fmts name)
2036 (if (file-name-absolute-p filename)
2037 ;; The file name is absolute. Use its explicit directory as
2038 ;; the first in the search path, and strip it from FILENAME.
2039 (setq filename (abbreviate-file-name (expand-file-name filename))
2040 dirs (cons (file-name-directory filename) dirs)
2041 filename (file-name-nondirectory filename)))
2042 ;; Now search the path.
2043 (while (and dirs (null buffer))
2044 (setq thisdir (or (car dirs) spec-dir)
2045 fmts formats)
2046 ;; For each directory, try each format string.
2047 (while (and fmts (null buffer))
2048 (setq name (expand-file-name (format (car fmts) filename) thisdir)
2049 buffer (and (file-exists-p name)
2050 (find-file-noselect name))
2051 fmts (cdr fmts)))
2052 (setq dirs (cdr dirs)))
2053 (while (null buffer) ;Repeat until the user selects an existing file.
2054 ;; The file doesn't exist. Ask the user where to find it.
2055 (save-excursion ;This save-excursion is probably not right.
2056 (let ((pop-up-windows t))
2057 (compilation-set-window (display-buffer (marker-buffer marker))
2058 marker)
2059 (let* ((name (read-file-name
2060 (format "Find this %s in (default %s): "
2061 compilation-error filename)
2062 spec-dir filename t nil
2063 ;; The predicate below is fine when called from
2064 ;; minibuffer-complete-and-exit, but it's too
2065 ;; restrictive otherwise, since it also prevents the
2066 ;; user from completing "fo" to "foo/" when she
2067 ;; wants to enter "foo/bar".
2069 ;; Try to make sure the user can only select
2070 ;; a valid answer. This predicate may be ignored,
2071 ;; tho, so we still have to double-check afterwards.
2072 ;; TODO: We should probably fix read-file-name so
2073 ;; that it never ignores this predicate, even when
2074 ;; using popup dialog boxes.
2075 ;; (lambda (name)
2076 ;; (if (file-directory-p name)
2077 ;; (setq name (expand-file-name filename name)))
2078 ;; (file-exists-p name))
2080 (origname name))
2081 (cond
2082 ((not (file-exists-p name))
2083 (message "Cannot find file `%s'" name)
2084 (ding) (sit-for 2))
2085 ((and (file-directory-p name)
2086 (not (file-exists-p
2087 (setq name (expand-file-name filename name)))))
2088 (message "No `%s' in directory %s" filename origname)
2089 (ding) (sit-for 2))
2091 (setq buffer (find-file-noselect name))))))))
2092 ;; Make intangible overlays tangible.
2093 ;; This is weird: it's not even clear which is the current buffer,
2094 ;; so the code below can't be expected to DTRT here. -- Stef
2095 (dolist (ov (overlays-in (point-min) (point-max)))
2096 (when (overlay-get ov 'intangible)
2097 (overlay-put ov 'intangible nil)))
2098 buffer))
2100 (defun compilation-get-file-structure (file &optional fmt)
2101 "Retrieve FILE's file-structure or create a new one.
2102 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
2103 In the former case, FILENAME may be relative or absolute.
2105 The file-structure looks like this:
2106 (list (list FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)"
2107 (or (gethash file compilation-locs)
2108 ;; File was not previously encountered, at least not in the form passed.
2109 ;; Let's normalize it and look again.
2110 (let ((filename (car file))
2111 ;; Get the specified directory from FILE.
2112 (spec-directory (if (cdr file)
2113 (file-truename (cdr file)))))
2115 ;; Check for a comint-file-name-prefix and prepend it if appropriate.
2116 ;; (This is very useful for compilation-minor-mode in an rlogin-mode
2117 ;; buffer.)
2118 (when (and (boundp 'comint-file-name-prefix)
2119 (not (equal comint-file-name-prefix "")))
2120 (if (file-name-absolute-p filename)
2121 (setq filename
2122 (concat comint-file-name-prefix filename))
2123 (if spec-directory
2124 (setq spec-directory
2125 (file-truename
2126 (concat comint-file-name-prefix spec-directory))))))
2128 ;; If compilation-parse-errors-filename-function is
2129 ;; defined, use it to process the filename.
2130 (when compilation-parse-errors-filename-function
2131 (setq filename
2132 (funcall compilation-parse-errors-filename-function
2133 filename)))
2135 ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
2136 ;; file names like "./bar//foo.c" for file "bar/foo.c";
2137 ;; expand-file-name will collapse these into "/foo.c" and fail to find
2138 ;; the appropriate file. So we look for doubled slashes in the file
2139 ;; name and fix them.
2140 (setq filename (command-line-normalize-file-name filename))
2142 ;; Store it for the possibly unnormalized name
2143 (puthash file
2144 ;; Retrieve or create file-structure for normalized name
2145 ;; The gethash used to not use spec-directory, but
2146 ;; this leads to errors when files in different
2147 ;; directories have the same name:
2148 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00463.html
2149 (or (gethash (cons filename spec-directory) compilation-locs)
2150 (puthash (cons filename spec-directory)
2151 (list (list filename spec-directory) fmt)
2152 compilation-locs))
2153 compilation-locs))))
2155 (add-to-list 'debug-ignored-errors "^No more [-a-z ]+s yet$")
2157 ;;; Compatibility with the old compile.el.
2159 (defun compile-buffer-substring (n) (if n (match-string n)))
2161 (defun compilation-compat-error-properties (err)
2162 "Map old-style error ERR to new-style message."
2163 ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
2164 ;; (MARKER . MARKER).
2165 (let ((dst (cdr err)))
2166 (if (markerp dst)
2167 ;; Must start with a face, for font-lock.
2168 `(face nil
2169 message ,(list (list nil nil nil dst) 2)
2170 help-echo "mouse-2: visit the source location"
2171 keymap compilation-button-map
2172 mouse-face highlight)
2173 ;; Too difficult to do it by hand: dispatch to the normal code.
2174 (let* ((file (pop dst))
2175 (line (pop dst))
2176 (col (pop dst))
2177 (filename (pop file))
2178 (dirname (pop file))
2179 (fmt (pop file)))
2180 (compilation-internal-error-properties
2181 (cons filename dirname) line nil col nil 2 fmt)))))
2183 (defun compilation-compat-parse-errors (limit)
2184 (when compilation-parse-errors-function
2185 ;; FIXME: We should remove the rest of the compilation keywords
2186 ;; but we can't do that from here because font-lock is using
2187 ;; the value right now. --stef
2188 (save-excursion
2189 (setq compilation-error-list nil)
2190 ;; Reset compilation-parsing-end each time because font-lock
2191 ;; might force us the re-parse many times (typically because
2192 ;; some code adds some text-property to the output that we
2193 ;; already parsed). You might say "why reparse", well:
2194 ;; because font-lock has just removed the `message' property so
2195 ;; have to do it all over again.
2196 (if compilation-parsing-end
2197 (set-marker compilation-parsing-end (point))
2198 (setq compilation-parsing-end (point-marker)))
2199 (condition-case nil
2200 ;; Ignore any error: we're calling this function earlier than
2201 ;; in the old compile.el so things might not all be setup yet.
2202 (funcall compilation-parse-errors-function limit nil)
2203 (error nil))
2204 (dolist (err (if (listp compilation-error-list) compilation-error-list))
2205 (let* ((src (car err))
2206 (dst (cdr err))
2207 (loc (cond ((markerp dst) (list nil nil nil dst))
2208 ((consp dst)
2209 (list (nth 2 dst) (nth 1 dst)
2210 (cons (cdar dst) (caar dst)))))))
2211 (when loc
2212 (goto-char src)
2213 ;; (put-text-property src (line-end-position) 'font-lock-face 'font-lock-warning-face)
2214 (put-text-property src (line-end-position)
2215 'message (list loc 2)))))))
2216 (goto-char limit)
2217 nil)
2219 ;; Beware: this is not only compatiblity code. New code stil uses it. --Stef
2220 (defun compilation-forget-errors ()
2221 ;; In case we hit the same file/line specs, we want to recompute a new
2222 ;; marker for them, so flush our cache.
2223 (setq compilation-locs (make-hash-table :test 'equal :weakness 'value))
2224 (setq compilation-gcpro nil)
2225 ;; FIXME: the old code reset the directory-stack, so maybe we should
2226 ;; put a `directory change' marker of some sort, but where? -stef
2228 ;; FIXME: The old code moved compilation-current-error (which was
2229 ;; virtually represented by a mix of compilation-parsing-end and
2230 ;; compilation-error-list) to point-min, but that was only meaningful for
2231 ;; the internal uses of compilation-forget-errors: all calls from external
2232 ;; packages seem to be followed by a move of compilation-parsing-end to
2233 ;; something equivalent to point-max. So we heuristically move
2234 ;; compilation-current-error to point-max (since the external package
2235 ;; won't know that it should do it). --Stef
2236 (setq compilation-current-error nil)
2237 (let* ((proc (get-buffer-process (current-buffer)))
2238 (mark (if proc (process-mark proc)))
2239 (pos (or mark (point-max))))
2240 (setq compilation-messages-start
2241 ;; In the future, ignore the text already present in the buffer.
2242 ;; Since many process filter functions insert before markers,
2243 ;; we need to put ours just before the insertion point rather
2244 ;; than at the insertion point. If that's not possible, then
2245 ;; don't use a marker. --Stef
2246 (if (> pos (point-min)) (copy-marker (1- pos)) pos)))
2247 ;; Again, since this command is used in buffers that contain several
2248 ;; compilations, to set the beginning of "this compilation", it's a good
2249 ;; place to reset compilation-auto-jump-to-next.
2250 (set (make-local-variable 'compilation-auto-jump-to-next)
2251 (or compilation-auto-jump-to-first-error
2252 (eq compilation-scroll-output 'first-error))))
2254 ;;;###autoload
2255 (add-to-list 'auto-mode-alist '("\\.gcov\\'" . compilation-mode))
2257 (provide 'compile)
2259 ;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c
2260 ;;; compile.el ends here