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