1 ;;; compile.el --- run compiler as inferior of Emacs, parse error messages
3 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
5 ;; Free Software Foundation, Inc.
7 ;; Authors: Roland McGrath <roland@gnu.org>,
8 ;; Daniel Pfeiffer <occitan@esperanto.org>
10 ;; Keywords: tools, processes
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 3, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
31 ;; This package provides the compile facilities documented in the Emacs user's
34 ;; This mode uses some complex data-structures:
36 ;; LOC (or location) is a list of (COLUMN LINE FILE-STRUCTURE)
38 ;; COLUMN and LINE are numbers parsed from an error message. COLUMN and maybe
39 ;; LINE will be nil for a message that doesn't contain them. Then the
40 ;; location refers to a indented beginning of line or beginning of file.
41 ;; Once any location in some file has been jumped to, the list is extended to
42 ;; (COLUMN LINE FILE-STRUCTURE MARKER TIMESTAMP . VISITED)
43 ;; for all LOCs pertaining to that file.
44 ;; MARKER initially points to LINE and COLUMN in a buffer visiting that file.
45 ;; Being a marker it sticks to some text, when the buffer grows or shrinks
46 ;; before that point. VISITED is t if we have jumped there, else nil.
47 ;; TIMESTAMP is necessary because of "incremental compilation": `omake -P'
48 ;; polls filesystem for changes and recompiles when a file is modified
49 ;; using the same *compilation* buffer. this necessitates re-parsing markers.
51 ;; FILE-STRUCTURE is a list of
52 ;; ((FILENAME . DIRECTORY) FORMATS (LINE LOC ...) ...)
54 ;; FILENAME is a string parsed from an error message. DIRECTORY is a string
55 ;; obtained by following directory change messages. DIRECTORY will be nil for
56 ;; an absolute filename. FORMATS is a list of formats to apply to FILENAME if
57 ;; a file of that name can't be found.
58 ;; The rest of the list is an alist of elements with LINE as key. The keys
59 ;; are either nil or line numbers. If present, nil comes first, followed by
60 ;; the numbers in decreasing order. The LOCs for each line are again an alist
61 ;; ordered the same way. Note that the whole file structure is referenced in
64 ;; MESSAGE is a list of (LOC TYPE END-LOC)
66 ;; TYPE is 0 for info or 1 for warning if the message matcher identified it as
67 ;; such, 2 otherwise (for a real error). END-LOC is a LOC pointing to the
68 ;; other end, if the parsed message contained a range. If the end of the
69 ;; range didn't specify a COLUMN, it defaults to -1, meaning end of line.
70 ;; These are the value of the `message' text-properties in the compilation
75 (eval-when-compile (require 'cl))
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."
90 (defcustom compilation-mode-hook nil
91 "List of hook functions run by `compilation-mode' (see `run-mode-hooks')."
96 (defcustom compilation-window-height nil
97 "Number of lines in a compilation window. If nil, use Emacs default."
98 :type '(choice (const :tag "Default" nil)
102 (defvar compilation-first-column 1
103 "*This is how compilers number the first column, usually 1 or 0.")
105 (defvar compilation-parse-errors-filename-function nil
106 "Function to call to post-process filenames while parsing error messages.
107 It takes one arg FILENAME which is the name of a file as found
108 in the compilation output, and should return a transformed file name.")
111 (defvar compilation-process-setup-function nil
112 "*Function to call to customize the compilation process.
113 This function is called immediately before the compilation process is
114 started. It can be used to set any variables or functions that are used
115 while processing the output of the compilation process. The function
116 is called with variables `compilation-buffer' and `compilation-window'
117 bound to the compilation buffer and window, respectively.")
120 (defvar compilation-buffer-name-function nil
121 "Function to compute the name of a compilation buffer.
122 The function receives one argument, the name of the major mode of the
123 compilation buffer. It should return a string.
124 If nil, compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
127 (defvar compilation-finish-function nil
128 "Function to call when a compilation process finishes.
129 It is called with two arguments: the compilation buffer, and a string
130 describing how the process finished.")
132 (make-obsolete-variable 'compilation-finish-function
133 "use `compilation-finish-functions', but it works a little differently."
137 (defvar compilation-finish-functions nil
138 "Functions to call when a compilation process finishes.
139 Each function is called with two arguments: the compilation buffer,
140 and a string describing how the process finished.")
142 (defvar compilation-in-progress nil
143 "List of compilation processes now running.")
144 (or (assq 'compilation-in-progress minor-mode-alist)
145 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
148 (defvar compilation-error "error"
149 "Stem of message to print when no matches are found.")
151 (defvar compilation-arguments nil
152 "Arguments that were given to `compilation-start'.")
154 (defvar compilation-num-errors-found)
156 (defconst compilation-error-regexp-alist-alist
158 "^\\(?:[Ee]rror on \\|[Ww]arning on\\( \\)\\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
159 of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil (1))
162 "\\(warning: .*\\)? at \\([^ \n]+\\):\\([0-9]+\\)$" 2 3 nil (1))
165 " in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
168 "^[ \t]*\\[[^] \n]+\\][ \t]*\\([^: \n]+\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):[0-9]+:[0-9]+:\\)?\
169 \\( warning\\)?" 1 2 3 (4))
172 ;; Maven is a popular build tool for Java. Maven is Free Software.
173 "\\(.*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\]" 1 2 3)
176 "^\\([^: \n\t]+\\): line \\([0-9]+\\):" 1 2)
179 "^\\(?:Error\\|Warnin\\(g\\)\\) \\(?:[FEW][0-9]+ \\)?\
180 \\([a-zA-Z]?:?[^:( \t\n]+\\)\
181 \\([0-9]+\\)\\(?:[) \t]\\|:[^0-9\n]\\)" 2 3 nil (1))
184 "^ *File \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1, lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
185 \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:\\)?\\([ \n]Warning:\\)?\\)"
186 2 (3 . 4) (5 . 6) (7))
189 "^\"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)\
190 \\(?:[(. pos]+\\([0-9]+\\))?\\)?[:.,; (-]\\( warning:\\|[-0-9 ]*(W)\\)?" 1 2 3 (4))
193 "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
196 "at line \\([0-9]+\\) of \"\\([^ \n]+\\)\"$"
200 "^Error [0-9]+ at (\\([0-9]+\\):\\([^)\n]+\\))" 2 1)
203 "\\(^Warning .*\\)? line[ \n]\\([0-9]+\\)[ \n]\\(?:col \\([0-9]+\\)[ \n]\\)?file \\([^ :;\n]+\\)"
207 "^\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(?:Error\\|Warnin\\(g\\)\\)\\[[0-9]+\\]:"
211 "^\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) :\
212 \\(?:warnin\\(g\\)\\|informationa\\(l\\)\\)?" 1 2 3 (4 . 5))
214 ;; fixme: should be `mips'
216 "^[-[:alnum:]_/ ]+: \\(?:\\(?:[sS]evere\\|[eE]rror\\|[wW]arnin\\(g\\)\\|[iI]nf\\(o\\)\\)[0-9 ]*: \\)?\
217 \\([^,\" \n\t]+\\)\\(?:, line\\|:\\) \\([0-9]+\\):" 3 4 nil (1 . 2))
220 "^\\(?:[ \t]+at \\|==[0-9]+== +\\(?:at\\|b\\(y\\)\\)\\).+(\\([^()\n]+\\):\\([0-9]+\\))$" 2 3 nil (1))
223 "^\\(?:Found\\|Issued\\) .* compiling \"\\(.+\\)\":$" 1 nil nil 0)
225 "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)"
227 (2 (compilation-face '(3))))
230 ;; I have no idea what this first line is supposed to match, but it
231 ;; makes things ambiguous with output such as "foo:344:50:blabla" since
232 ;; the "foo" part can match this first line (in which case the file
233 ;; name as "344"). To avoid this, the second line disallows filenames
234 ;; exclusively composed of digits. --Stef
235 ;; Similarly, we get lots of false positives with messages including
236 ;; times of the form "HH:MM:SS" where MM is taken as a line number, so
237 ;; the last line tries to rule out message where the info after the
238 ;; line number starts with "SS". --Stef
239 "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\)?\
240 \\([0-9]*[^0-9\n]\\(?:[^\n ]\\| [^-\n]\\)*?\\): ?\
241 \\([0-9]+\\)\\(?:\\([.:]\\)\\([0-9]+\\)\\)?\
242 \\(?:-\\([0-9]+\\)?\\(?:\\3\\([0-9]+\\)\\)?\\)?:\
243 \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\
244 *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\|[Nn]ote\\)\\|\
245 \[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)"
246 1 (2 . 5) (4 . 6) (7 . 8))
248 ;; The `gnu' style above can incorrectly match gcc's "In file
249 ;; included from" message, so we process that first. -- cyd
251 "^\\(?:In file included\\| \\) from \
252 \\(.+\\):\\([0-9]+\\)\\(?:\\(:\\)\\|\\(,\\)\\)?" 1 2 nil (3 . 4))
255 "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)"
259 "^makepp\\(?:\\(?:: warning\\(:\\).*?\\|\\(: Scanning\\|: [LR]e?l?oading makefile\\|: Imported\\|log:.*?\\) \\|: .*?\\)\
260 `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)"
262 ("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]" nil nil
263 (2 compilation-info-face)
264 (3 compilation-line-face nil t)
265 (1 (compilation-error-properties 2 3 nil nil nil 0 nil)
268 ;; Should be lint-1, lint-2 (SysV lint)
270 " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
272 " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2)
275 ;; AFAWK, The message may be a "warning", "error", or "fatal error".
276 "^\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
277 : \\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:" 2 3 nil (4))
280 "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
281 \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
282 \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
285 ;; "during global destruction": This comes out under "use
286 ;; warnings" in recent perl when breaking circular references
287 ;; during program or thread exit.
289 " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \
290 during global destruction\\.$\\)" 1 2)
293 "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
294 \\([0-9]+\\) of file://\\(.+\\)"
298 "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
299 [12][09][0-9][0-9] +\\(.*\\):$"
302 "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
303 nil 3 nil (2) nil (1 (compilation-face '(2))))
304 (sparc-pascal-example
305 "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
306 nil 1 nil (3) nil (2 (compilation-face '(3))))
309 ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
310 File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
314 "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
317 "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
318 \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3))
321 "^ *-: *\\(0\\):Source:\\(.+\\)$"
323 (1 compilation-line-face prepend) (2 compilation-info-face prepend))
325 "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
327 (1 compilation-line-face prepend))
328 ;; Underlines over all lines of gcov output are too uncomfortable to read.
329 ;; However, hyperlinks embedded in the lines are useful.
330 ;; So I put default face on the lines; and then put
331 ;; compilation-*-face by manually to eliminate the underlines.
332 ;; The hyperlinks are still effective.
334 "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
337 (1 compilation-line-face prepend))
339 "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
342 (1 compilation-info-face prepend) (2 compilation-line-face prepend))
344 "^ *\\(#####\\): *\\([0-9]+\\):.*$"
347 (1 compilation-error-face prepend) (2 compilation-line-face prepend))
349 (compilation-perl--Pod::Checker
350 ;; podchecker error messages, per Pod::Checker.
351 ;; The style is from the Pod::Checker::poderror() function, eg.
352 ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm
354 ;; Plus end_pod() can give "at line EOF" instead of a
355 ;; number, so for that match "on line N" which is the
356 ;; originating spot, eg.
357 ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm
359 ;; Plus command() can give both "on line N" and "at line N";
360 ;; the latter is desired and is matched because the .* is
362 ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod
364 "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \
365 \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)"
367 (compilation-perl--Test
368 ;; perl Test module error messages.
369 ;; Style per the ok() function "$context", eg.
370 ;; # Failed test 1 in foo.t at line 6
372 "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
374 (compilation-perl--Test2
375 ;; Or when comparing got/want values,
376 ;; # Test 2 got: "xx" (t-compilation-perl-2.t at line 10)
378 ;; And under Test::Harness they're preceded by progress stuff with
380 ;; ... NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
382 "^\\(.*NOK.*\\)?# Test [0-9]+ got:.* (\\([^ \t\r\n]+\\) at line \
385 (compilation-perl--Test::Harness
386 ;; perl Test::Harness output, eg.
387 ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
389 ;; Test::Harness is slightly designed for tty output, since
390 ;; it prints CRs to overwrite progress messages, but if you
391 ;; run it in with M-x compile this pattern can at least step
392 ;; through the failures.
394 "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
397 ;; The style comes from HTML::Lint::Error::as_string(), eg.
398 ;; index.html (13:1) Unknown element <fdjsk>
400 ;; The pattern only matches filenames without spaces, since that
401 ;; should be usual and should help reduce the chance of a false
402 ;; match of a message from some unrelated program.
404 ;; This message style is quite close to the "ibm" entry which is
405 ;; for IBM C, though that ibm bit doesn't put a space after the
408 "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) "
411 "Alist of values for `compilation-error-regexp-alist'.")
413 (defcustom compilation-error-regexp-alist
414 (mapcar 'car compilation-error-regexp-alist-alist)
415 "Alist that specifies how to match errors in compiler output.
416 On GNU and Unix, any string is a valid filename, so these
417 matchers must make some common sense assumptions, which catch
418 normal cases. A shorter list will be lighter on resource usage.
420 Instead of an alist element, you can use a symbol, which is
421 looked up in `compilation-error-regexp-alist-alist'. You can see
422 the predefined symbols and their effects in the file
423 `etc/compilation.txt' (linked below if you are customizing this).
425 Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
426 HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
427 gives the file name, and the LINE'th subexpression gives the line
428 number. The COLUMN'th subexpression gives the column number on
431 If FILE, LINE or COLUMN are nil or that index didn't match, that
432 information is not present on the matched line. In that case the
433 file name is assumed to be the same as the previous one in the
434 buffer, line number defaults to 1 and column defaults to
435 beginning of line's indentation.
437 FILE can also have the form (FILE FORMAT...), where the FORMATs
438 \(e.g. \"%s.c\") will be applied in turn to the recognized file
439 name, until a file of that name is found. Or FILE can also be a
440 function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
441 In the former case, FILENAME may be relative or absolute.
443 LINE can also be of the form (LINE . END-LINE) meaning a range
444 of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
445 meaning a range of columns starting on LINE and ending on
446 END-LINE, if that matched.
448 TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
449 TYPE can also be of the form (WARNING . INFO). In that case this
450 will be equivalent to 1 if the WARNING'th subexpression matched
451 or else equivalent to 0 if the INFO'th subexpression matched.
452 See `compilation-error-face', `compilation-warning-face',
453 `compilation-info-face' and `compilation-skip-threshold'.
455 What matched the HYPERLINK'th subexpression has `mouse-face' and
456 `compilation-message-face' applied. If this is nil, the text
457 matched by the whole REGEXP becomes the hyperlink.
459 Additional HIGHLIGHTs as described under `font-lock-keywords' can
461 :type `(set :menu-tag "Pick"
462 ,@(mapcar (lambda (elt)
463 (list 'const (car elt)))
464 compilation-error-regexp-alist-alist))
465 :link `(file-link :tag "example file"
466 ,(expand-file-name "compilation.txt" data-directory))
469 ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp)
470 (defvar compilation-directory nil
471 "Directory to restore to when doing `recompile'.")
473 (defvar compilation-directory-matcher
474 '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1))
475 "A list for tracking when directories are entered or left.
476 If nil, do not track directories, e.g. if all file names are absolute. The
477 first element is the REGEXP matching these messages. It can match any number
478 of variants, e.g. different languages. The remaining elements are all of the
479 form (DIR . LEAVE). If for any one of these the DIR'th subexpression
480 matches, that is a directory name. If LEAVE is nil or the corresponding
481 LEAVE'th subexpression doesn't match, this message is about going into another
482 directory. If it does match anything, this message is about going back to the
483 directory we were in before the last entering message. If you change this,
484 you may also want to change `compilation-page-delimiter'.")
486 (defvar compilation-page-delimiter
487 "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
488 "Value of `page-delimiter' in Compilation mode.")
490 (defvar compilation-mode-font-lock-keywords
491 '(;; configure output lines.
492 ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
493 (1 font-lock-variable-name-face)
494 (2 (compilation-face '(4 . 3))))
495 ;; Command output lines. Recognize `make[n]:' lines too.
496 ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
497 (1 font-lock-function-name-face) (3 compilation-line-face nil t))
498 (" --?o\\(?:utfile\\|utput\\)?[= ]?\\(\\S +\\)" . 1)
499 ("^Compilation \\(finished\\).*"
500 (0 '(face nil message nil help-echo nil mouse-face nil) t)
501 (1 compilation-info-face))
502 ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
503 (0 '(face nil message nil help-echo nil mouse-face nil) t)
504 (1 compilation-error-face)
505 (2 compilation-error-face nil t)))
506 "Additional things to highlight in Compilation mode.
507 This gets tacked on the end of the generated expressions.")
509 (defvar compilation-highlight-regexp t
510 "Regexp matching part of visited source lines to highlight temporarily.
511 Highlight entire line if t; don't highlight source lines if nil.")
513 (defvar compilation-highlight-overlay nil
514 "Overlay used to temporarily highlight compilation matches.")
516 (defcustom compilation-error-screen-columns t
517 "If non-nil, column numbers in error messages are screen columns.
518 Otherwise they are interpreted as character positions, with
519 each character occupying one column.
520 The default is to use screen columns, which requires that the compilation
521 program and Emacs agree about the display width of the characters,
522 especially the TAB character."
527 (defcustom compilation-read-command t
528 "Non-nil means \\[compile] reads the compilation command to use.
529 Otherwise, \\[compile] just uses the value of `compile-command'."
534 (defcustom compilation-ask-about-save t
535 "Non-nil means \\[compile] asks which buffers to save before compiling.
536 Otherwise, it saves all modified buffers without asking."
541 (defcustom compilation-search-path '(nil)
542 "List of directories to search for source files named in error messages.
543 Elements should be directory names, not file names of directories.
544 The value nil as an element means to try the default directory."
545 :type '(repeat (choice (const :tag "Default" nil)
546 (string :tag "Directory")))
550 (defcustom compile-command "make -k "
551 "Last shell command used to do a compilation; default for next compilation.
553 Sometimes it is useful for files to supply local values for this variable.
554 You might also use mode hooks to specify it in certain modes, like this:
556 (add-hook 'c-mode-hook
558 (unless (or (file-exists-p \"makefile\")
559 (file-exists-p \"Makefile\"))
560 (set (make-local-variable 'compile-command)
562 (file-name-sans-extension buffer-file-name))))))"
565 ;;;###autoload(put 'compile-command 'safe-local-variable 'stringp)
568 (defcustom compilation-disable-input nil
569 "If non-nil, send end-of-file as compilation process input.
570 This only affects platforms that support asynchronous processes (see
571 `start-process'); synchronous compilation processes never accept input."
576 ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
577 ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
578 ;; key. This holds the tree seen from root, for storing new nodes.
579 (defvar compilation-locs ())
581 (defvar compilation-debug nil
582 "*Set this to t before creating a *compilation* buffer.
583 Then every error line will have a debug text property with the matcher that
584 fit this line and the match data. Use `describe-text-properties'.")
586 (defvar compilation-exit-message-function nil "\
587 If non-nil, called when a compilation process dies to return a status message.
588 This should be a function of three arguments: process status, exit status,
589 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
590 write into the compilation buffer, and to put in its mode line.")
592 (defvar compilation-environment nil
593 "*List of environment variables for compilation to inherit.
594 Each element should be a string of the form ENVVARNAME=VALUE.
595 This list is temporarily prepended to `process-environment' prior to
596 starting the compilation process.")
598 ;; History of compile commands.
599 (defvar compile-history nil)
601 (defface compilation-error
602 '((t :inherit font-lock-warning-face))
603 "Face used to highlight compiler errors."
607 (defface compilation-warning
608 '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
609 (((class color)) (:foreground "cyan" :weight bold))
611 "Face used to highlight compiler warnings."
615 (defface compilation-info
616 '((((class color) (min-colors 16) (background light))
617 (:foreground "Green3" :weight bold))
618 (((class color) (min-colors 88) (background dark))
619 (:foreground "Green1" :weight bold))
620 (((class color) (min-colors 16) (background dark))
621 (:foreground "Green" :weight bold))
622 (((class color)) (:foreground "green" :weight bold))
624 "Face used to highlight compiler information."
628 (defface compilation-line-number
629 '((t :inherit font-lock-variable-name-face))
630 "Face for displaying line numbers in compiler messages."
634 (defface compilation-column-number
635 '((t :inherit font-lock-type-face))
636 "Face for displaying column numbers in compiler messages."
640 (defcustom compilation-message-face 'underline
641 "Face name to use for whole messages.
642 Faces `compilation-error-face', `compilation-warning-face',
643 `compilation-info-face', `compilation-line-face' and
644 `compilation-column-face' get prepended to this, when applicable."
649 (defvar compilation-error-face 'compilation-error
650 "Face name to use for file name in error messages.")
652 (defvar compilation-warning-face 'compilation-warning
653 "Face name to use for file name in warning messages.")
655 (defvar compilation-info-face 'compilation-info
656 "Face name to use for file name in informational messages.")
658 (defvar compilation-line-face 'compilation-line-number
659 "Face name to use for line numbers in compiler messages.")
661 (defvar compilation-column-face 'compilation-column-number
662 "Face name to use for column numbers in compiler messages.")
664 ;; same faces as dired uses
665 (defvar compilation-enter-directory-face 'font-lock-function-name-face
666 "Face name to use for entering directory messages.")
668 (defvar compilation-leave-directory-face 'font-lock-type-face
669 "Face name to use for leaving directory messages.")
673 ;; Used for compatibility with the old compile.el.
674 (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
675 (defvar compilation-parsing-end (make-marker))
676 (defvar compilation-parse-errors-function nil)
677 (defvar compilation-error-list nil)
678 (defvar compilation-old-error-list nil)
680 (defcustom compilation-auto-jump-to-first-error nil
681 "If non-nil, automatically jump to the first error after `compile'."
686 (defvar compilation-auto-jump-to-next nil
687 "If non-nil, automatically jump to the next error encountered.")
688 (make-variable-buffer-local 'compilation-auto-jump-to-next)
691 (defvar compilation-skip-to-next-location t
692 "*If non-nil, skip multiple error messages for the same source location.")
694 (defcustom compilation-skip-threshold 1
695 "Compilation motion commands skip less important messages.
696 The value can be either 2 -- skip anything less than error, 1 --
697 skip anything less than warning or 0 -- don't skip any messages.
698 Note that all messages not positively identified as warning or
699 info, are considered errors."
700 :type '(choice (const :tag "Warnings and info" 2)
701 (const :tag "Info" 1)
702 (const :tag "None" 0))
706 (defcustom compilation-skip-visited nil
707 "Compilation motion commands skip visited messages if this is t.
708 Visited messages are ones for which the file, line and column have been jumped
709 to from the current content in the current compilation buffer, even if it was
710 from a different message."
715 (defun compilation-face (type)
716 (or (and (car type) (match-end (car type)) compilation-warning-face)
717 (and (cdr type) (match-end (cdr type)) compilation-info-face)
718 compilation-error-face))
720 ;; Internal function for calculating the text properties of a directory
721 ;; change message. The directory property is important, because it is
722 ;; the stack of nested enter-messages. Relative filenames on the following
723 ;; lines are relative to the top of the stack.
724 (defun compilation-directory-properties (idx leave)
725 (if leave (setq leave (match-end leave)))
726 ;; find previous stack, and push onto it, or if `leave' pop it
727 (let ((dir (previous-single-property-change (point) 'directory)))
728 (setq dir (if dir (or (get-text-property (1- dir) 'directory)
729 (get-text-property dir 'directory))))
731 compilation-leave-directory-face
732 compilation-enter-directory-face)
735 '(nil)) ; nil only isn't a property-change
736 (cons (match-string-no-properties idx) dir))
738 keymap compilation-button-map
739 help-echo "mouse-2: visit destination directory")))
741 ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
742 ;; KEY element from the ALIST, creating it in the right position if not already
743 ;; present. ALIST structure is
744 ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
745 ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
746 ;; may be nil. The other KEYs are ordered backwards so that growing line
747 ;; numbers can be inserted in front and searching can abort after half the
749 (eval-when-compile ;Don't keep it at runtime if not needed.
750 (defmacro compilation-assq (key alist)
753 (car (if (if (null ,key)
754 (if l2 (null (caar l2)))
755 (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
758 (if l2 (eq ,key (caar l2))))
760 (setcdr l1 (cons (list ,key) l2)))))))
762 (defun compilation-auto-jump (buffer pos)
763 (with-current-buffer buffer
765 (compile-goto-error)))
767 ;; This function is the central driver, called when font-locking to gather
768 ;; all information needed to later jump to corresponding source code.
769 ;; Return a property list with all meta information on this error location.
771 (defun compilation-error-properties (file line end-line col end-col type fmt)
772 (unless (< (next-single-property-change (match-beginning 0)
773 'directory nil (point))
777 (setq file (funcall file))
779 (setq file (match-string-no-properties file))
780 (unless (file-name-absolute-p file)
781 (setq dir (previous-single-property-change (point) 'directory)
782 dir (if dir (or (get-text-property (1- dir) 'directory)
783 (get-text-property dir 'directory)))))
784 (setq file (cons file (car dir)))))
785 ;; This message didn't mention one, get it from previous
787 ;; Find the previous message.
788 (previous-single-property-change (point) 'message)))
790 ;; Get the file structure that belongs to it.
792 (or (get-text-property (1- prev-pos) 'message)
793 (get-text-property prev-pos 'message)))
795 (car (nth 2 (car prev)))))
796 ;; Construct FILE . DIR from that.
798 (setq file (cons (car prev-struct)
799 (cadr prev-struct))))))
801 (setq file '("*unknown*")))))
802 ;; All of these fields are optional, get them only if we have an index, and
803 ;; it matched some part of the message.
805 (setq line (match-string-no-properties line))
806 (setq line (string-to-number line)))
808 (setq end-line (match-string-no-properties end-line))
809 (setq end-line (string-to-number end-line)))
812 (setq col (funcall col))
814 (setq col (match-string-no-properties col))
815 (setq col (- (string-to-number col) compilation-first-column)))))
816 (if (and end-col (functionp end-col))
817 (setq end-col (funcall end-col))
818 (if (and end-col (setq end-col (match-string-no-properties end-col)))
819 (setq end-col (- (string-to-number end-col) compilation-first-column -1))
820 (if end-line (setq end-col -1))))
821 (if (consp type) ; not a static type, check what it is.
822 (setq type (or (and (car type) (match-end (car type)) 1)
823 (and (cdr type) (match-end (cdr type)) 0)
826 (when (and compilation-auto-jump-to-next
827 (>= type compilation-skip-threshold))
828 (kill-local-variable 'compilation-auto-jump-to-next)
829 (run-with-timer 0 nil 'compilation-auto-jump
830 (current-buffer) (match-beginning 0)))
832 (compilation-internal-error-properties file line end-line col end-col type fmt)))
834 (defun compilation-move-to-column (col screen)
835 "Go to column COL on the current line.
836 If SCREEN is non-nil, columns are screen columns, otherwise, they are
840 (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
842 (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
843 "Get the meta-info that will be added as text-properties.
844 LINE, END-LINE, COL, END-COL are integers or nil.
845 TYPE can be 0, 1, or 2, meaning error, warning, or just info.
846 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
847 FMTS is a list of format specs for transforming the file name.
848 (See `compilation-error-regexp-alist'.)"
849 (unless file (setq file '("*unknown*")))
850 (let* ((file-struct (compilation-get-file-structure file fmts))
851 ;; Get first already existing marker (if any has one, all have one).
852 ;; Do this first, as the compilation-assq`s may create new nodes.
853 (marker-line (car (cddr file-struct))) ; a line structure
854 (marker (nth 3 (cadr marker-line))) ; its marker
855 (compilation-error-screen-columns compilation-error-screen-columns)
856 end-marker loc end-loc)
857 (if (not (and marker (marker-buffer marker)))
858 (setq marker nil) ; no valid marker for this file
859 (setq loc (or line 1)) ; normalize no linenumber to line 1
860 (catch 'marker ; find nearest loc, at least one exists
861 (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines
862 (if (> (car x) loc) ; still bigger
864 (if (> (- (or (car marker-line) 1) loc)
865 (- loc (car x))) ; current line is nearer
866 (setq marker-line x))
868 (setq marker (nth 3 (cadr marker-line))
869 marker-line (or (car marker-line) 1))
870 (with-current-buffer (marker-buffer marker)
874 (goto-char (marker-position marker))
875 (when (or end-col end-line)
876 (beginning-of-line (- (or end-line line) marker-line -1))
877 (if (or (null end-col) (< end-col 0))
879 (compilation-move-to-column
880 end-col compilation-error-screen-columns))
881 (setq end-marker (list (point-marker))))
882 (beginning-of-line (if end-line
884 (- loc marker-line -1)))
886 (compilation-move-to-column
887 col compilation-error-screen-columns)
888 (forward-to-indentation 0))
889 (setq marker (list (point-marker)))))))
891 (setq loc (compilation-assq line (cdr file-struct)))
893 (setq end-loc (compilation-assq end-line (cdr file-struct))
894 end-loc (compilation-assq end-col end-loc))
895 (if end-col ; use same line element
896 (setq end-loc (compilation-assq end-col loc))))
897 (setq loc (compilation-assq col loc))
898 ;; If they are new, make the loc(s) reference the file they point to.
899 (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker)))
902 (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker))))
904 ;; Must start with face
905 `(face ,compilation-message-face
906 message (,loc ,type ,end-loc)
907 ,@(if compilation-debug
908 `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords)
911 "mouse-2: visit this file, line and column"
913 "mouse-2: visit this file and line"
914 "mouse-2: visit this file"))
915 keymap compilation-button-map
916 mouse-face highlight)))
918 (defun compilation-mode-font-lock-keywords ()
919 "Return expressions to highlight in Compilation mode."
920 (if compilation-parse-errors-function
921 ;; An old package! Try the compatibility code.
922 '((compilation-compat-parse-errors))
924 ;; make directory tracking
925 (if compilation-directory-matcher
926 `((,(car compilation-directory-matcher)
927 ,@(mapcar (lambda (elt)
929 (compilation-directory-properties
930 ,(car elt) ,(cdr elt))
932 (cdr compilation-directory-matcher)))))
934 ;; Compiler warning/error lines.
938 (setq item (cdr (assq item
939 compilation-error-regexp-alist-alist))))
940 (let ((file (nth 1 item))
944 end-line end-col fmt)
945 (if (consp file) (setq fmt (cdr file) file (car file)))
946 (if (consp line) (setq end-line (cdr line) line (car line)))
947 (if (consp col) (setq end-col (cdr col) col (car col)))
950 ;; The old compile.el had here an undocumented hook that
951 ;; allowed `line' to be a function that computed the actual
952 ;; error location. Let's do our best.
955 (compilation-compat-error-properties
956 (funcall ',line (cons (match-string ,file)
957 (cons default-directory
959 ,(if col `(match-string ,col))))))
960 (,file compilation-error-face t))
962 (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
963 (error "HYPERLINK should be an integer: %s" (nth 5 item)))
967 ,@(when (integerp file)
968 `((,file ,(if (consp type)
969 `(compilation-face ',type)
970 (aref [compilation-info-face
971 compilation-warning-face
972 compilation-error-face]
976 `((,line compilation-line-face nil t)))
978 `((,end-line compilation-line-face nil t)))
980 ,@(when (integerp col)
981 `((,col compilation-column-face nil t)))
982 ,@(when (integerp end-col)
983 `((,end-col compilation-column-face nil t)))
986 (,(or (nth 5 item) 0)
987 (compilation-error-properties ',file ,line ,end-line
988 ,col ,end-col ',(or type 2)
990 append))))) ; for compilation-message-face
991 compilation-error-regexp-alist)
993 compilation-mode-font-lock-keywords)))
997 (defun compile (command &optional comint)
998 "Compile the program including the current buffer. Default: run `make'.
999 Runs COMMAND, a shell command, in a separate process asynchronously
1000 with output going to the buffer `*compilation*'.
1002 You can then use the command \\[next-error] to find the next error message
1003 and move to the source code that caused it.
1005 If optional second arg COMINT is t the buffer will be in Comint mode with
1006 `compilation-shell-minor-mode'.
1008 Interactively, prompts for the command if `compilation-read-command' is
1009 non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
1010 Additionally, with universal prefix arg, compilation buffer will be in
1011 comint mode, i.e. interactive.
1013 To run more than one compilation at once, start one then rename
1014 the \`*compilation*' buffer to some other name with
1015 \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
1016 It will create a new \`*compilation*' buffer.
1018 On most systems, termination of the main compilation process
1019 kills its subprocesses.
1021 The name used for the buffer is actually whatever is returned by
1022 the function in `compilation-buffer-name-function', so you can set that
1023 to a function that generates a unique name."
1026 (let ((command (eval compile-command)))
1027 (if (or compilation-read-command current-prefix-arg)
1028 (read-from-minibuffer "Compile command: "
1030 (if (equal (car compile-history) command)
1031 '(compile-history . 1)
1034 (consp current-prefix-arg)))
1035 (unless (equal command (eval compile-command))
1036 (setq compile-command command))
1037 (save-some-buffers (not compilation-ask-about-save) nil)
1038 (setq-default compilation-directory default-directory)
1039 (compilation-start command comint))
1041 ;; run compile with the default command line
1043 "Re-compile the program including the current buffer.
1044 If this is run in a Compilation mode buffer, re-use the arguments from the
1045 original use. Otherwise, recompile using `compile-command'."
1047 (save-some-buffers (not compilation-ask-about-save) nil)
1048 (let ((default-directory (or compilation-directory default-directory)))
1049 (apply 'compilation-start (or compilation-arguments
1050 `(,(eval compile-command))))))
1052 (defcustom compilation-scroll-output nil
1053 "Non-nil to scroll the *compilation* buffer window as output appears.
1055 Setting it causes the Compilation mode commands to put point at the
1056 end of their output window so that the end of the output is always
1057 visible rather than the beginning."
1060 :group 'compilation)
1063 (defun compilation-buffer-name (mode-name mode-command name-function)
1064 "Return the name of a compilation buffer to use.
1065 If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
1066 to determine the buffer name.
1067 Likewise if `compilation-buffer-name-function' is non-nil.
1068 If current buffer has the major mode MODE-COMMAND,
1069 return the name of the current buffer, so that it gets reused.
1070 Otherwise, construct a buffer name from MODE-NAME."
1071 (cond (name-function
1072 (funcall name-function mode-name))
1073 (compilation-buffer-name-function
1074 (funcall compilation-buffer-name-function mode-name))
1075 ((eq mode-command major-mode)
1078 (concat "*" (downcase mode-name) "*"))))
1080 ;; This is a rough emulation of the old hack, until the transition to new
1081 ;; compile is complete.
1082 (defun compile-internal (command error-message
1083 &optional name-of-mode parser
1084 error-regexp-alist name-function
1085 enter-regexp-alist leave-regexp-alist
1086 file-regexp-alist nomessage-regexp-alist
1087 no-async highlight-regexp local-map)
1089 (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
1090 (let ((compilation-error-regexp-alist
1091 (append file-regexp-alist (or error-regexp-alist
1092 compilation-error-regexp-alist)))
1093 (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
1094 "\\1" error-message)))
1095 (compilation-start command nil name-function highlight-regexp)))
1096 (make-obsolete 'compile-internal 'compilation-start)
1099 (defun compilation-start (command &optional mode name-function highlight-regexp)
1100 "Run compilation command COMMAND (low level interface).
1101 If COMMAND starts with a cd command, that becomes the `default-directory'.
1102 The rest of the arguments are optional; for them, nil means use the default.
1104 MODE is the major mode to set in the compilation buffer. Mode
1105 may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
1107 If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
1108 to determine the buffer name. Otherwise, the default is to
1109 reuses the current buffer if it has the proper major mode,
1110 else use or create a buffer with name based on the major mode.
1112 If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
1113 the matching section of the visited source line; the default is to use the
1114 global value of `compilation-highlight-regexp'.
1116 Returns the compilation buffer created."
1117 (or mode (setq mode 'compilation-mode))
1118 (let* ((name-of-mode
1120 (prog1 "compilation" (require 'comint))
1121 (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
1122 (thisdir default-directory)
1124 (with-current-buffer
1127 (compilation-buffer-name name-of-mode mode name-function)))
1128 (let ((comp-proc (get-buffer-process (current-buffer))))
1130 (if (or (not (eq (process-status comp-proc) 'run))
1132 (format "A %s process is running; kill it? "
1136 (interrupt-process comp-proc)
1138 (delete-process comp-proc))
1140 (error "Cannot have two processes in `%s' at once"
1142 (buffer-disable-undo (current-buffer))
1143 ;; first transfer directory from where M-x compile was called
1144 (setq default-directory thisdir)
1145 ;; Remember the original dir, so we can use it when we recompile.
1146 ;; default-directory' can't be used reliably for that because it may be
1147 ;; affected by the special handling of "cd ...;".
1148 (set (make-local-variable 'compilation-directory) thisdir)
1149 ;; Make compilation buffer read-only. The filter can still write it.
1150 ;; Clear out the compilation buffer.
1151 (let ((inhibit-read-only t)
1152 (default-directory thisdir))
1153 ;; Then evaluate a cd command if any, but don't perform it yet, else
1154 ;; start-command would do it again through the shell: (cd "..") AND
1155 ;; sh -c "cd ..; make"
1156 (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command)
1158 (substitute-env-vars (match-string 1 command))
1162 ;; Select the desired mode.
1163 (if (not (eq mode t))
1165 (setq buffer-read-only nil)
1166 (with-no-warnings (comint-mode))
1167 (compilation-shell-minor-mode))
1168 (if highlight-regexp
1169 (set (make-local-variable 'compilation-highlight-regexp)
1171 (if compilation-auto-jump-to-first-error
1172 (set (make-local-variable 'compilation-auto-jump-to-next) t))
1173 ;; Output a mode setter, for saving and later reloading this buffer.
1174 (insert "-*- mode: " name-of-mode
1175 "; default-directory: " (prin1-to-string default-directory)
1177 (format "%s started at %s\n\n"
1179 (substring (current-time-string) 0 19))
1181 (setq thisdir default-directory))
1182 (set-buffer-modified-p nil))
1183 ;; Pop up the compilation buffer.
1184 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html
1185 (setq outwin (display-buffer outbuf))
1186 (with-current-buffer outbuf
1187 (let ((process-environment
1189 compilation-environment
1190 (if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning
1191 system-uses-terminfo)
1192 (list "TERM=dumb" "TERMCAP="
1193 (format "COLUMNS=%d" (window-width)))
1195 (format "TERMCAP=emacs:co#%d:tc=unknown:"
1197 ;; Set the EMACS variable, but
1198 ;; don't override users' setting of $EMACS.
1199 (unless (getenv "EMACS")
1201 (list "INSIDE_EMACS=t")
1202 (copy-sequence process-environment))))
1203 (set (make-local-variable 'compilation-arguments)
1204 (list command mode name-function highlight-regexp))
1205 (set (make-local-variable 'revert-buffer-function)
1206 'compilation-revert-buffer)
1207 (set-window-start outwin (point-min))
1209 ;; Position point as the user will see it.
1210 (let ((desired-visible-point
1211 ;; Put it at the end if `compilation-scroll-output' is set.
1212 (if compilation-scroll-output
1214 ;; Normally put it at the top.
1216 (if (eq outwin (selected-window))
1217 (goto-char desired-visible-point)
1218 (set-window-point outwin desired-visible-point)))
1220 ;; The setup function is called before compilation-set-window-height
1221 ;; so it can set the compilation-window-height buffer locally.
1222 (if compilation-process-setup-function
1223 (funcall compilation-process-setup-function))
1224 (compilation-set-window-height outwin)
1225 ;; Start the compilation.
1228 ;; comint uses `start-file-process'.
1232 outbuf (downcase mode-name)
1233 (if (file-remote-p default-directory)
1236 nil `("-c" ,command))))
1237 (start-file-process-shell-command (downcase mode-name)
1239 ;; Make the buffer's mode line show process state.
1240 (setq mode-line-process '(":%s"))
1241 (set-process-sentinel proc 'compilation-sentinel)
1242 (set-process-filter proc 'compilation-filter)
1243 ;; Use (point-max) here so that output comes in
1244 ;; after the initial text,
1245 ;; regardless of where the user sees point.
1246 (set-marker (process-mark proc) (point-max) outbuf)
1247 (when compilation-disable-input
1249 (process-send-eof proc)
1250 ;; The process may have exited already.
1252 (setq compilation-in-progress
1253 (cons proc compilation-in-progress))))
1254 ;; Now finally cd to where the shell started make/grep/...
1255 (setq default-directory thisdir))
1256 (if (buffer-local-value 'compilation-scroll-output outbuf)
1257 (save-selected-window
1258 (select-window outwin)
1259 (goto-char (point-max))))
1260 ;; Make it so the next C-x ` will use this buffer.
1261 (setq next-error-last-buffer outbuf)))
1263 (defun compilation-set-window-height (window)
1264 "Set the height of WINDOW according to `compilation-window-height'."
1265 (let ((height (buffer-local-value 'compilation-window-height (window-buffer window))))
1267 (window-full-width-p window)
1268 ;; If window is alone in its frame, aside from a minibuffer,
1269 ;; don't change its height.
1270 (not (eq window (frame-root-window (window-frame window))))
1271 ;; Stef said that doing the saves in this order is safer:
1273 (save-selected-window
1274 (select-window window)
1275 (enlarge-window (- height (window-height))))))))
1277 (defvar compilation-menu-map
1278 (let ((map (make-sparse-keymap "Errors")))
1279 (define-key map [stop-subjob]
1280 '("Stop Compilation" . kill-compilation))
1281 (define-key map [compilation-mode-separator2]
1283 (define-key map [compilation-first-error]
1284 '("First Error" . first-error))
1285 (define-key map [compilation-previous-error]
1286 '("Previous Error" . previous-error))
1287 (define-key map [compilation-next-error]
1288 '("Next Error" . next-error))
1291 (defvar compilation-minor-mode-map
1292 (let ((map (make-sparse-keymap)))
1293 (define-key map [mouse-2] 'compile-goto-error)
1294 (define-key map [follow-link] 'mouse-face)
1295 (define-key map "\C-c\C-c" 'compile-goto-error)
1296 (define-key map "\C-m" 'compile-goto-error)
1297 (define-key map "\C-c\C-k" 'kill-compilation)
1298 (define-key map "\M-n" 'compilation-next-error)
1299 (define-key map "\M-p" 'compilation-previous-error)
1300 (define-key map "\M-{" 'compilation-previous-file)
1301 (define-key map "\M-}" 'compilation-next-file)
1302 ;; Set up the menu-bar
1303 (define-key map [menu-bar compilation]
1304 (cons "Errors" compilation-menu-map))
1306 "Keymap for `compilation-minor-mode'.")
1308 (defvar compilation-shell-minor-mode-map
1309 (let ((map (make-sparse-keymap)))
1310 (define-key map "\M-\C-m" 'compile-goto-error)
1311 (define-key map "\M-\C-n" 'compilation-next-error)
1312 (define-key map "\M-\C-p" 'compilation-previous-error)
1313 (define-key map "\M-{" 'compilation-previous-file)
1314 (define-key map "\M-}" 'compilation-next-file)
1315 ;; Set up the menu-bar
1316 (define-key map [menu-bar compilation]
1317 (cons "Errors" compilation-menu-map))
1319 "Keymap for `compilation-shell-minor-mode'.")
1321 (defvar compilation-button-map
1322 (let ((map (make-sparse-keymap)))
1323 (define-key map [mouse-2] 'compile-goto-error)
1324 (define-key map [follow-link] 'mouse-face)
1325 (define-key map "\C-m" 'compile-goto-error)
1327 "Keymap for compilation-message buttons.")
1328 (fset 'compilation-button-map compilation-button-map)
1330 (defvar compilation-mode-map
1331 (let ((map (make-sparse-keymap)))
1332 ;; Don't inherit from compilation-minor-mode-map,
1333 ;; because that introduces a menu bar item we don't want.
1334 ;; That confuses C-down-mouse-3.
1335 (define-key map [mouse-2] 'compile-goto-error)
1336 (define-key map [follow-link] 'mouse-face)
1337 (define-key map "\C-c\C-c" 'compile-goto-error)
1338 (define-key map "\C-m" 'compile-goto-error)
1339 (define-key map "\C-c\C-k" 'kill-compilation)
1340 (define-key map "\M-n" 'compilation-next-error)
1341 (define-key map "\M-p" 'compilation-previous-error)
1342 (define-key map "\M-{" 'compilation-previous-file)
1343 (define-key map "\M-}" 'compilation-next-file)
1344 (define-key map "\t" 'compilation-next-error)
1345 (define-key map [backtab] 'compilation-previous-error)
1347 (define-key map " " 'scroll-up)
1348 (define-key map "\^?" 'scroll-down)
1349 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
1351 ;; Set up the menu-bar
1352 (let ((submap (make-sparse-keymap "Compile")))
1353 (define-key map [menu-bar compilation]
1354 (cons "Compile" submap))
1355 (set-keymap-parent submap compilation-menu-map))
1356 (define-key map [menu-bar compilation compilation-separator2]
1358 (define-key map [menu-bar compilation compilation-grep]
1359 '("Search Files (grep)..." . grep))
1360 (define-key map [menu-bar compilation compilation-recompile]
1361 '("Recompile" . recompile))
1362 (define-key map [menu-bar compilation compilation-compile]
1363 '("Compile..." . compile))
1365 "Keymap for compilation log buffers.
1366 `compilation-minor-mode-map' is a parent of this.")
1368 (put 'compilation-mode 'mode-class 'special)
1371 (defun compilation-mode (&optional name-of-mode)
1372 "Major mode for compilation log buffers.
1373 \\<compilation-mode-map>To visit the source for a line-numbered error,
1374 move point to the error message line and type \\[compile-goto-error].
1375 To kill the compilation, type \\[kill-compilation].
1377 Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
1379 \\{compilation-mode-map}"
1381 (kill-all-local-variables)
1382 (use-local-map compilation-mode-map)
1383 (setq major-mode 'compilation-mode
1384 mode-name (or name-of-mode "Compilation"))
1385 (set (make-local-variable 'page-delimiter)
1386 compilation-page-delimiter)
1388 (setq buffer-read-only t)
1389 (run-mode-hooks 'compilation-mode-hook))
1391 (defmacro define-compilation-mode (mode name doc &rest body)
1392 "This is like `define-derived-mode' without the PARENT argument.
1393 The parent is always `compilation-mode' and the customizable `compilation-...'
1394 variables are also set from the name of the mode you have chosen,
1395 by replacing the first word, e.g `compilation-scroll-output' from
1396 `grep-scroll-output' if that variable exists."
1397 (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
1398 `(define-derived-mode ,mode compilation-mode ,name
1400 ,@(mapcar (lambda (v)
1402 (intern-soft (replace-regexp-in-string
1403 "^compilation" mode-name
1406 (or (boundp (cdr v))
1407 (if (boundp 'byte-compile-bound-variables)
1408 (memq (cdr v) byte-compile-bound-variables)))
1409 `(set (make-local-variable ',(car v)) ,(cdr v))))
1410 '(compilation-buffer-name-function
1411 compilation-directory-matcher
1413 compilation-error-regexp-alist
1414 compilation-error-regexp-alist-alist
1415 compilation-error-screen-columns
1416 compilation-finish-function
1417 compilation-finish-functions
1418 compilation-first-column
1419 compilation-mode-font-lock-keywords
1420 compilation-page-delimiter
1421 compilation-parse-errors-filename-function
1422 compilation-process-setup-function
1423 compilation-scroll-output
1424 compilation-search-path
1425 compilation-skip-threshold
1426 compilation-window-height))
1429 (defun compilation-revert-buffer (ignore-auto noconfirm)
1430 (if buffer-file-name
1431 (let (revert-buffer-function)
1432 (revert-buffer ignore-auto noconfirm))
1433 (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
1434 (apply 'compilation-start compilation-arguments))))
1436 (defvar compilation-current-error nil
1437 "Marker to the location from where the next error will be found.
1438 The global commands next/previous/first-error/goto-error use this.")
1440 (defvar compilation-messages-start nil
1441 "Buffer position of the beginning of the compilation messages.
1442 If nil, use the beginning of buffer.")
1444 ;; A function name can't be a hook, must be something with a value.
1445 (defconst compilation-turn-on-font-lock 'turn-on-font-lock)
1447 (defun compilation-setup (&optional minor)
1448 "Prepare the buffer for the compilation parsing commands to work.
1449 Optional argument MINOR indicates this is called from
1450 `compilation-minor-mode'."
1451 (make-local-variable 'compilation-current-error)
1452 (make-local-variable 'compilation-messages-start)
1453 (make-local-variable 'compilation-error-screen-columns)
1454 (make-local-variable 'overlay-arrow-position)
1455 (set (make-local-variable 'overlay-arrow-string) "")
1456 (setq next-error-overlay-arrow-position nil)
1457 (add-hook 'kill-buffer-hook
1458 (lambda () (setq next-error-overlay-arrow-position nil)) nil t)
1459 ;; Note that compilation-next-error-function is for interfacing
1460 ;; with the next-error function in simple.el, and it's only
1461 ;; coincidentally named similarly to compilation-next-error.
1462 (setq next-error-function 'compilation-next-error-function)
1463 (set (make-local-variable 'comint-file-name-prefix)
1464 (or (file-remote-p default-directory) ""))
1465 (set (make-local-variable 'font-lock-extra-managed-props)
1466 '(directory message help-echo mouse-face debug))
1467 (set (make-local-variable 'compilation-locs)
1468 (make-hash-table :test 'equal :weakness 'value))
1469 ;; lazy-lock would never find the message unless it's scrolled to.
1470 ;; jit-lock might fontify some things too late.
1471 (set (make-local-variable 'font-lock-support-mode) nil)
1472 (set (make-local-variable 'font-lock-maximum-size) nil)
1474 (let ((fld font-lock-defaults))
1475 (font-lock-add-keywords nil (compilation-mode-font-lock-keywords))
1478 (font-lock-fontify-buffer)
1479 (font-lock-change-mode)
1480 (turn-on-font-lock))
1481 (turn-on-font-lock)))
1482 (setq font-lock-defaults '(compilation-mode-font-lock-keywords t))
1483 ;; maybe defer font-lock till after derived mode is set up
1484 (run-mode-hooks 'compilation-turn-on-font-lock)))
1487 (define-minor-mode compilation-shell-minor-mode
1488 "Toggle compilation shell minor mode.
1489 With arg, turn compilation mode on if and only if arg is positive.
1490 In this minor mode, all the error-parsing commands of the
1491 Compilation major mode are available but bound to keys that don't
1492 collide with Shell mode. See `compilation-mode'.
1493 Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
1494 nil " Shell-Compile"
1496 (if compilation-shell-minor-mode
1497 (compilation-setup t)
1498 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1499 (font-lock-fontify-buffer)))
1502 (define-minor-mode compilation-minor-mode
1503 "Toggle compilation minor mode.
1504 With arg, turn compilation mode on if and only if arg is positive.
1505 In this minor mode, all the error-parsing commands of the
1506 Compilation major mode are available. See `compilation-mode'.
1507 Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
1510 (if compilation-minor-mode
1511 (compilation-setup t)
1512 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1513 (font-lock-fontify-buffer)))
1515 (defun compilation-handle-exit (process-status exit-status msg)
1516 "Write MSG in the current buffer and hack its `mode-line-process'."
1517 (let ((inhibit-read-only t)
1518 (status (if compilation-exit-message-function
1519 (funcall compilation-exit-message-function
1520 process-status exit-status msg)
1521 (cons msg exit-status)))
1524 (cur-buffer (current-buffer)))
1525 ;; Record where we put the message, so we can ignore it later on.
1527 (insert ?\n mode-name " " (car status))
1528 (if (and (numberp compilation-window-height)
1529 (zerop compilation-window-height))
1530 (message "%s" (cdr status)))
1533 (insert " at " (substring (current-time-string) 0 19))
1534 (goto-char (point-max))
1535 ;; Prevent that message from being recognized as a compilation error.
1536 (add-text-properties omax (point)
1537 (append '(compilation-handle-exit t) nil))
1538 (setq mode-line-process (format ":%s [%s]" process-status (cdr status)))
1539 ;; Force mode line redisplay soon.
1540 (force-mode-line-update)
1541 (if (and opoint (< opoint omax))
1544 (if compilation-finish-function
1545 (funcall compilation-finish-function cur-buffer msg)))
1546 (run-hook-with-args 'compilation-finish-functions cur-buffer msg)))
1548 ;; Called when compilation process changes state.
1549 (defun compilation-sentinel (proc msg)
1550 "Sentinel for compilation buffers."
1551 (if (memq (process-status proc) '(exit signal))
1552 (let ((buffer (process-buffer proc)))
1553 (if (null (buffer-name buffer))
1555 (set-process-buffer proc nil)
1556 (with-current-buffer buffer
1557 ;; Write something in the compilation buffer
1558 ;; and hack its mode line.
1559 (compilation-handle-exit (process-status proc)
1560 (process-exit-status proc)
1562 ;; Since the buffer and mode line will show that the
1563 ;; process is dead, we can delete it now. Otherwise it
1564 ;; will stay around until M-x list-processes.
1565 (delete-process proc)))
1566 (setq compilation-in-progress (delq proc compilation-in-progress)))))
1568 (defun compilation-filter (proc string)
1569 "Process filter for compilation buffers.
1570 Just inserts the text, but uses `insert-before-markers'."
1571 (if (buffer-name (process-buffer proc))
1572 (with-current-buffer (process-buffer proc)
1573 (let ((inhibit-read-only t))
1575 (goto-char (process-mark proc))
1576 (insert-before-markers string)
1577 (run-hooks 'compilation-filter-hook))))))
1579 ;;; test if a buffer is a compilation buffer, assuming we're in the buffer
1580 (defsubst compilation-buffer-internal-p ()
1581 "Test if inside a compilation buffer."
1582 (local-variable-p 'compilation-locs))
1584 ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p
1585 (defsubst compilation-buffer-p (buffer)
1586 "Test if BUFFER is a compilation buffer."
1587 (with-current-buffer buffer
1588 (compilation-buffer-internal-p)))
1590 (defmacro compilation-loop (< property-change 1+ error limit)
1594 (or (setq pt (,property-change pt 'message))
1595 ;; Handle the case where where the first error message is
1596 ;; at the start of the buffer, and n < 0.
1597 (if (or (eq (get-text-property ,limit 'message)
1598 (get-text-property opt 'message))
1600 (error ,error compilation-error)
1602 ;; prop 'message usually has 2 changes, on and off, so
1604 (or (setq msg (get-text-property pt 'message))
1605 (if (setq pt (,property-change pt 'message nil ,limit))
1606 (setq msg (get-text-property pt 'message)))
1607 (error ,error compilation-error))
1608 (or (< (cadr msg) compilation-skip-threshold)
1610 (eq (prog1 last (setq last (nth 2 (car msg))))
1612 (if compilation-skip-visited
1613 (nthcdr 5 (car msg)))
1614 (if compilation-skip-to-next-location
1616 ;; count this message only if none of the above are true
1617 (setq n (,1+ n))))))
1619 (defun compilation-next-error (n &optional different-file pt)
1620 "Move point to the next error in the compilation buffer.
1621 Prefix arg N says how many error messages to move forwards (or
1622 backwards, if negative).
1623 Does NOT find the source line like \\[next-error]."
1625 (or (compilation-buffer-p (current-buffer))
1626 (error "Not in a compilation buffer"))
1627 (or pt (setq pt (point)))
1628 (let* ((msg (get-text-property pt 'message))
1632 (unless (or msg ; find message near here
1633 (setq msg (get-text-property (max (1- pt) (point-min))
1635 (setq pt (previous-single-property-change pt 'message nil
1636 (line-beginning-position)))
1637 (unless (setq msg (get-text-property (max (1- pt) (point-min)) 'message))
1638 (setq pt (next-single-property-change pt 'message nil
1639 (line-end-position)))
1640 (or (setq msg (get-text-property pt 'message))
1641 (setq pt (point)))))
1642 (setq last (nth 2 (car msg)))
1644 (compilation-loop > next-single-property-change 1-
1645 (if (get-buffer-process (current-buffer))
1647 "Moved past last %s")
1649 ;; Don't move "back" to message at or before point.
1650 ;; Pass an explicit (point-min) to make sure pt is non-nil.
1651 (setq pt (previous-single-property-change pt 'message nil (point-min)))
1652 (compilation-loop < previous-single-property-change 1+
1653 "Moved back before first %s" (point-min))))
1656 (error "No %s here" compilation-error))))
1658 (defun compilation-previous-error (n)
1659 "Move point to the previous error in the compilation buffer.
1660 Prefix arg N says how many error messages to move backwards (or
1661 forwards, if negative).
1662 Does NOT find the source line like \\[previous-error]."
1664 (compilation-next-error (- n)))
1666 (defun compilation-next-file (n)
1667 "Move point to the next error for a different file than the current one.
1668 Prefix arg N says how many files to move forwards (or backwards, if negative)."
1670 (compilation-next-error n t))
1672 (defun compilation-previous-file (n)
1673 "Move point to the previous error for a different file than the current one.
1674 Prefix arg N says how many files to move backwards (or forwards, if negative)."
1676 (compilation-next-file (- n)))
1678 (defun kill-compilation ()
1679 "Kill the process made by the \\[compile] or \\[grep] commands."
1681 (let ((buffer (compilation-find-buffer)))
1682 (if (get-buffer-process buffer)
1683 (interrupt-process (get-buffer-process buffer))
1684 (error "The %s process is not running" (downcase mode-name)))))
1686 (defalias 'compile-mouse-goto-error 'compile-goto-error)
1688 (defun compile-goto-error (&optional event)
1689 "Visit the source for the error message at point.
1690 Use this command in a compilation log buffer. Sets the mark at point there."
1691 (interactive (list last-input-event))
1692 (if event (posn-set-point (event-end event)))
1693 (or (compilation-buffer-p (current-buffer))
1694 (error "Not in a compilation buffer"))
1695 (if (get-text-property (point) 'directory)
1696 (dired-other-window (car (get-text-property (point) 'directory)))
1698 (setq compilation-current-error (point))
1699 (next-error-internal)))
1701 (defun compilation-find-buffer (&optional avoid-current)
1702 "Return a compilation buffer.
1703 If AVOID-CURRENT is nil, and the current buffer is a compilation buffer,
1704 return it. If AVOID-CURRENT is non-nil, return the current buffer only
1706 (if (and (compilation-buffer-internal-p) (not avoid-current))
1708 (next-error-find-buffer avoid-current 'compilation-buffer-internal-p)))
1711 (defun compilation-next-error-function (n &optional reset)
1712 "Advance to the next error message and visit the file where the error was.
1713 This is the value of `next-error-function' in Compilation buffers."
1716 (setq compilation-current-error nil))
1717 (let* ((columns compilation-error-screen-columns) ; buffer's local value
1719 (loc (compilation-next-error (or n 1) nil
1720 (or compilation-current-error
1721 compilation-messages-start
1723 (end-loc (nth 2 loc))
1724 (marker (point-marker)))
1725 (setq compilation-current-error (point-marker)
1726 overlay-arrow-position
1728 compilation-current-error
1729 (copy-marker (line-beginning-position)))
1731 ;; If loc contains no marker, no error in that file has been visited.
1732 ;; If the marker is invalid the buffer has been killed.
1733 ;; If the file is newer than the timestamp, it has been modified
1734 ;; (`omake -P' polls filesystem for changes and recompiles when needed
1735 ;; in the same process and buffer).
1736 ;; So, recalculate all markers for that file.
1737 (unless (and (nth 3 loc) (marker-buffer (nth 3 loc))
1738 ;; There may be no timestamp info if the loc is a `fake-loc'.
1739 ;; So we skip the time-check here, although we should maybe
1740 ;; change `compilation-fake-loc' to add timestamp info.
1741 (or (null (nth 4 loc))
1744 (with-current-buffer
1745 (marker-buffer (nth 3 loc))
1746 (visited-file-modtime))))))
1747 (with-current-buffer (compilation-find-file marker (caar (nth 2 loc))
1748 (cadr (car (nth 2 loc))))
1751 (goto-char (point-min))
1752 ;; Treat file's found lines in forward order, 1 by 1.
1753 (dolist (line (reverse (cddr (nth 2 loc))))
1754 (when (car line) ; else this is a filename w/o a line#
1755 (beginning-of-line (- (car line) last -1))
1756 (setq last (car line)))
1757 ;; Treat line's found columns and store/update a marker for each.
1758 (dolist (col (cdr line))
1760 (if (eq (car col) -1) ; special case for range end
1762 (compilation-move-to-column (car col) columns))
1764 (skip-chars-forward " \t"))
1766 (set-marker (nth 3 col) (point))
1767 (setcdr (nthcdr 2 col) `(,(point-marker)))))))))
1768 (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc))
1769 (setcdr (nthcdr 3 loc) (list timestamp))
1770 (setcdr (nthcdr 4 loc) t))) ; Set this one as visited.
1772 (defvar compilation-gcpro nil
1773 "Internal variable used to keep some values from being GC'd.")
1774 (make-variable-buffer-local 'compilation-gcpro)
1776 (defun compilation-fake-loc (marker file &optional line col)
1777 "Preassociate MARKER with FILE.
1778 FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
1779 This is useful when you compile temporary files, but want
1780 automatic translation of the messages to the real buffer from
1781 which the temporary file came. This only works if done before a
1782 message about FILE appears!
1784 Optional args LINE and COL default to 1 and beginning of
1785 indentation respectively. The marker is expected to reflect
1786 this. In the simplest case the marker points to the first line
1787 of the region that was saved to the temp file.
1789 If you concatenate several regions into the temp file (e.g. a
1790 header with variable assignments and a code region), you must
1791 call this several times, once each for the last line of one
1792 region and the first line of the next region."
1793 (or (consp file) (setq file (list file)))
1794 (setq file (compilation-get-file-structure file))
1795 ;; Between the current call to compilation-fake-loc and the first occurrence
1796 ;; of an error message referring to `file', the data is only kept in the
1797 ;; weak hash-table compilation-locs, so we need to prevent this entry
1798 ;; in compilation-locs from being GC'd away. --Stef
1799 (push file compilation-gcpro)
1800 (let ((loc (compilation-assq (or line 1) (cdr file))))
1801 (setq loc (compilation-assq col loc))
1803 (setcdr (cddr loc) (list marker))
1804 (setcdr loc (list line file marker)))
1807 (defcustom compilation-context-lines nil
1808 "Display this many lines of leading context before the current message.
1809 If nil and the left fringe is displayed, don't scroll the
1810 compilation output window; an arrow in the left fringe points to
1811 the current message. If nil and there is no left fringe, the message
1812 displays at the top of the window; there is no arrow."
1813 :type '(choice integer (const :tag "No window scrolling" nil))
1817 (defsubst compilation-set-window (w mk)
1818 "Align the compilation output window W with marker MK near top."
1819 (if (integerp compilation-context-lines)
1820 (set-window-start w (save-excursion
1823 (- 1 compilation-context-lines))
1825 ;; If there is no left fringe.
1826 (if (equal (car (window-fringes)) 0)
1827 (set-window-start w (save-excursion
1829 (beginning-of-line 1)
1831 (set-window-point w mk))
1833 (defvar next-error-highlight-timer)
1835 (defun compilation-goto-locus (msg mk end-mk)
1836 "Jump to an error corresponding to MSG at MK.
1837 All arguments are markers. If END-MK is non-nil, mark is set there
1838 and overlay is highlighted between MK and END-MK."
1839 ;; Show compilation buffer in other window, scrolled to this error.
1840 (let* ((from-compilation-buffer (eq (window-buffer (selected-window))
1841 (marker-buffer msg)))
1842 ;; Use an existing window if it is in a visible frame.
1843 (pre-existing (get-buffer-window (marker-buffer msg) 0))
1844 (w (if (and from-compilation-buffer pre-existing)
1845 ;; Calling display-buffer here may end up (partly) hiding
1846 ;; the error location if the two buffers are in two
1847 ;; different frames. So don't do it if it's not necessary.
1849 (let ((display-buffer-reuse-frames t)
1852 (display-buffer (marker-buffer msg)))))
1853 (highlight-regexp (with-current-buffer (marker-buffer msg)
1854 ;; also do this while we change buffer
1855 (compilation-set-window w msg)
1856 compilation-highlight-regexp)))
1857 ;; Ideally, the window-size should be passed to `display-buffer' (via
1858 ;; something like special-display-buffer) so it's only used when
1859 ;; creating a new window.
1860 (unless pre-existing (compilation-set-window-height w))
1862 (if from-compilation-buffer
1863 ;; If the compilation buffer window was selected,
1864 ;; keep the compilation buffer in this window;
1865 ;; display the source in another window.
1866 (let ((pop-up-windows t))
1867 (pop-to-buffer (marker-buffer mk) 'other-window))
1868 (if (window-dedicated-p (selected-window))
1869 (pop-to-buffer (marker-buffer mk))
1870 (switch-to-buffer (marker-buffer mk))))
1871 ;; If narrowing gets in the way of going to the right place, widen.
1872 (unless (eq (goto-char mk) (point))
1876 (push-mark end-mk t)
1877 (if mark-active (setq mark-active)))
1878 ;; If hideshow got in the way of
1879 ;; seeing the right place, open permanently.
1880 (dolist (ov (overlays-at (point)))
1881 (when (eq 'hs (overlay-get ov 'invisible))
1885 (when highlight-regexp
1886 (if (timerp next-error-highlight-timer)
1887 (cancel-timer next-error-highlight-timer))
1888 (unless compilation-highlight-overlay
1889 (setq compilation-highlight-overlay
1890 (make-overlay (point-min) (point-min)))
1891 (overlay-put compilation-highlight-overlay 'face 'next-error))
1892 (with-current-buffer (marker-buffer mk)
1894 (if end-mk (goto-char end-mk) (end-of-line))
1895 (let ((end (point)))
1896 (if mk (goto-char mk) (beginning-of-line))
1897 (if (and (stringp highlight-regexp)
1898 (re-search-forward highlight-regexp end t))
1900 (goto-char (match-beginning 0))
1901 (move-overlay compilation-highlight-overlay
1902 (match-beginning 0) (match-end 0)
1904 (move-overlay compilation-highlight-overlay
1905 (point) end (current-buffer)))
1906 (if (or (eq next-error-highlight t)
1907 (numberp next-error-highlight))
1908 ;; We want highlighting: delete overlay on next input.
1909 (add-hook 'pre-command-hook
1910 'compilation-goto-locus-delete-o)
1911 ;; We don't want highlighting: delete overlay now.
1912 (delete-overlay compilation-highlight-overlay))
1913 ;; We want highlighting for a limited time:
1914 ;; set up a timer to delete it.
1915 (when (numberp next-error-highlight)
1916 (setq next-error-highlight-timer
1917 (run-at-time next-error-highlight nil
1918 'compilation-goto-locus-delete-o)))))))
1919 (when (and (eq next-error-highlight 'fringe-arrow))
1920 ;; We want a fringe arrow (instead of highlighting).
1921 (setq next-error-overlay-arrow-position
1922 (copy-marker (line-beginning-position))))))
1924 (defun compilation-goto-locus-delete-o ()
1925 (delete-overlay compilation-highlight-overlay)
1926 ;; Get rid of timer and hook that would try to do this again.
1927 (if (timerp next-error-highlight-timer)
1928 (cancel-timer next-error-highlight-timer))
1929 (remove-hook 'pre-command-hook
1930 'compilation-goto-locus-delete-o))
1932 (defun compilation-find-file (marker filename directory &rest formats)
1933 "Find a buffer for file FILENAME.
1934 Search the directories in `compilation-search-path'.
1935 A nil in `compilation-search-path' means to try the
1936 \"current\" directory, which is passed in DIRECTORY.
1937 If DIRECTORY is relative, it is combined with `default-directory'.
1938 If DIRECTORY is nil, that means use `default-directory'.
1939 If FILENAME is not found at all, ask the user where to find it.
1940 Pop up the buffer containing MARKER and scroll to MARKER if we ask the user."
1941 (or formats (setq formats '("%s")))
1942 (let ((dirs compilation-search-path)
1943 (spec-dir (if directory
1944 (expand-file-name directory)
1946 buffer thisdir fmts name)
1947 (if (file-name-absolute-p filename)
1948 ;; The file name is absolute. Use its explicit directory as
1949 ;; the first in the search path, and strip it from FILENAME.
1950 (setq filename (abbreviate-file-name (expand-file-name filename))
1951 dirs (cons (file-name-directory filename) dirs)
1952 filename (file-name-nondirectory filename)))
1953 ;; Now search the path.
1954 (while (and dirs (null buffer))
1955 (setq thisdir (or (car dirs) spec-dir)
1957 ;; For each directory, try each format string.
1958 (while (and fmts (null buffer))
1959 (setq name (expand-file-name (format (car fmts) filename) thisdir)
1960 buffer (and (file-exists-p name)
1961 (find-file-noselect name))
1963 (setq dirs (cdr dirs)))
1964 (while (null buffer) ;Repeat until the user selects an existing file.
1965 ;; The file doesn't exist. Ask the user where to find it.
1966 (save-excursion ;This save-excursion is probably not right.
1967 (let ((pop-up-windows t))
1968 (compilation-set-window (display-buffer (marker-buffer marker))
1970 (let* ((name (read-file-name
1971 (format "Find this %s in (default %s): "
1972 compilation-error filename)
1973 spec-dir filename t nil
1974 ;; The predicate below is fine when called from
1975 ;; minibuffer-complete-and-exit, but it's too
1976 ;; restrictive otherwise, since it also prevents the
1977 ;; user from completing "fo" to "foo/" when she
1978 ;; wants to enter "foo/bar".
1980 ;; Try to make sure the user can only select
1981 ;; a valid answer. This predicate may be ignored,
1982 ;; tho, so we still have to double-check afterwards.
1983 ;; TODO: We should probably fix read-file-name so
1984 ;; that it never ignores this predicate, even when
1985 ;; using popup dialog boxes.
1987 ;; (if (file-directory-p name)
1988 ;; (setq name (expand-file-name filename name)))
1989 ;; (file-exists-p name))
1993 ((not (file-exists-p name))
1994 (message "Cannot find file `%s'" name)
1996 ((and (file-directory-p name)
1998 (setq name (expand-file-name filename name)))))
1999 (message "No `%s' in directory %s" filename origname)
2002 (setq buffer (find-file-noselect name))))))))
2003 ;; Make intangible overlays tangible.
2004 ;; This is weird: it's not even clear which is the current buffer,
2005 ;; so the code below can't be expected to DTRT here. -- Stef
2006 (dolist (ov (overlays-in (point-min) (point-max)))
2007 (when (overlay-get ov 'intangible)
2008 (overlay-put ov 'intangible nil)))
2011 (defun compilation-get-file-structure (file &optional fmt)
2012 "Retrieve FILE's file-structure or create a new one.
2013 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
2014 In the former case, FILENAME may be relative or absolute.
2016 The file-structure looks like this:
2017 (list (list FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)"
2018 (or (gethash file compilation-locs)
2019 ;; File was not previously encountered, at least not in the form passed.
2020 ;; Let's normalize it and look again.
2021 (let ((filename (car file))
2022 ;; Get the specified directory from FILE.
2023 (spec-directory (if (cdr file)
2024 (file-truename (cdr file)))))
2026 ;; Check for a comint-file-name-prefix and prepend it if appropriate.
2027 ;; (This is very useful for compilation-minor-mode in an rlogin-mode
2029 (when (and (boundp 'comint-file-name-prefix)
2030 (not (equal comint-file-name-prefix "")))
2031 (if (file-name-absolute-p filename)
2033 (concat comint-file-name-prefix filename))
2035 (setq spec-directory
2037 (concat comint-file-name-prefix spec-directory))))))
2039 ;; If compilation-parse-errors-filename-function is
2040 ;; defined, use it to process the filename.
2041 (when compilation-parse-errors-filename-function
2043 (funcall compilation-parse-errors-filename-function
2046 ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
2047 ;; file names like "./bar//foo.c" for file "bar/foo.c";
2048 ;; expand-file-name will collapse these into "/foo.c" and fail to find
2049 ;; the appropriate file. So we look for doubled slashes in the file
2050 ;; name and fix them.
2051 (setq filename (command-line-normalize-file-name filename))
2053 ;; Store it for the possibly unnormalized name
2055 ;; Retrieve or create file-structure for normalized name
2056 ;; The gethash used to not use spec-directory, but
2057 ;; this leads to errors when files in different
2058 ;; directories have the same name:
2059 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00463.html
2060 (or (gethash (cons filename spec-directory) compilation-locs)
2061 (puthash (cons filename spec-directory)
2062 (list (list filename spec-directory) fmt)
2064 compilation-locs))))
2066 (add-to-list 'debug-ignored-errors "^No more [-a-z ]+s yet$")
2068 ;;; Compatibility with the old compile.el.
2070 (defun compile-buffer-substring (n) (if n (match-string n)))
2072 (defun compilation-compat-error-properties (err)
2073 "Map old-style error ERR to new-style message."
2074 ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
2075 ;; (MARKER . MARKER).
2076 (let ((dst (cdr err)))
2078 ;; Must start with a face, for font-lock.
2080 message ,(list (list nil nil nil dst) 2)
2081 help-echo "mouse-2: visit the source location"
2082 keymap compilation-button-map
2083 mouse-face highlight)
2084 ;; Too difficult to do it by hand: dispatch to the normal code.
2085 (let* ((file (pop dst))
2088 (filename (pop file))
2089 (dirname (pop file))
2091 (compilation-internal-error-properties
2092 (cons filename dirname) line nil col nil 2 fmt)))))
2094 (defun compilation-compat-parse-errors (limit)
2095 (when compilation-parse-errors-function
2096 ;; FIXME: We should remove the rest of the compilation keywords
2097 ;; but we can't do that from here because font-lock is using
2098 ;; the value right now. --stef
2100 (setq compilation-error-list nil)
2101 ;; Reset compilation-parsing-end each time because font-lock
2102 ;; might force us the re-parse many times (typically because
2103 ;; some code adds some text-property to the output that we
2104 ;; already parsed). You might say "why reparse", well:
2105 ;; because font-lock has just removed the `message' property so
2106 ;; have to do it all over again.
2107 (if compilation-parsing-end
2108 (set-marker compilation-parsing-end (point))
2109 (setq compilation-parsing-end (point-marker)))
2111 ;; Ignore any error: we're calling this function earlier than
2112 ;; in the old compile.el so things might not all be setup yet.
2113 (funcall compilation-parse-errors-function limit nil)
2115 (dolist (err (if (listp compilation-error-list) compilation-error-list))
2116 (let* ((src (car err))
2118 (loc (cond ((markerp dst) (list nil nil nil dst))
2120 (list (nth 2 dst) (nth 1 dst)
2121 (cons (cdar dst) (caar dst)))))))
2124 ;; (put-text-property src (line-end-position) 'font-lock-face 'font-lock-warning-face)
2125 (put-text-property src (line-end-position)
2126 'message (list loc 2)))))))
2130 ;; Beware: this is not only compatiblity code. New code stil uses it. --Stef
2131 (defun compilation-forget-errors ()
2132 ;; In case we hit the same file/line specs, we want to recompute a new
2133 ;; marker for them, so flush our cache.
2134 (setq compilation-locs (make-hash-table :test 'equal :weakness 'value))
2135 (setq compilation-gcpro nil)
2136 ;; FIXME: the old code reset the directory-stack, so maybe we should
2137 ;; put a `directory change' marker of some sort, but where? -stef
2139 ;; FIXME: The old code moved compilation-current-error (which was
2140 ;; virtually represented by a mix of compilation-parsing-end and
2141 ;; compilation-error-list) to point-min, but that was only meaningful for
2142 ;; the internal uses of compilation-forget-errors: all calls from external
2143 ;; packages seem to be followed by a move of compilation-parsing-end to
2144 ;; something equivalent to point-max. So we heuristically move
2145 ;; compilation-current-error to point-max (since the external package
2146 ;; won't know that it should do it). --Stef
2147 (setq compilation-current-error nil)
2148 (let* ((proc (get-buffer-process (current-buffer)))
2149 (mark (if proc (process-mark proc)))
2150 (pos (or mark (point-max))))
2151 (setq compilation-messages-start
2152 ;; In the future, ignore the text already present in the buffer.
2153 ;; Since many process filter functions insert before markers,
2154 ;; we need to put ours just before the insertion point rather
2155 ;; than at the insertion point. If that's not possible, then
2156 ;; don't use a marker. --Stef
2157 (if (> pos (point-min)) (copy-marker (1- pos)) pos)))
2158 ;; Again, since this command is used in buffers that contain several
2159 ;; compilations, to set the beginning of "this compilation", it's a good
2160 ;; place to reset compilation-auto-jump-to-next.
2161 (set (make-local-variable 'compilation-auto-jump-to-next)
2162 compilation-auto-jump-to-first-error))
2165 (add-to-list 'auto-mode-alist '("\\.gcov\\'" . compilation-mode))
2169 ;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c
2170 ;;; compile.el ends here