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))
78 (defvar font-lock-extra-managed-props)
79 (defvar font-lock-keywords)
80 (defvar font-lock-maximum-size)
81 (defvar font-lock-support-mode)
84 (defgroup compilation nil
85 "Run compiler as inferior of Emacs, parse error messages."
91 (defcustom compilation-mode-hook nil
92 "List of hook functions run by `compilation-mode' (see `run-mode-hooks')."
97 (defcustom compilation-window-height nil
98 "Number of lines in a compilation window. If nil, use Emacs default."
99 :type '(choice (const :tag "Default" nil)
103 (defvar compilation-first-column 1
104 "*This is how compilers number the first column, usually 1 or 0.")
106 (defvar compilation-parse-errors-filename-function nil
107 "Function to call to post-process filenames while parsing error messages.
108 It takes one arg FILENAME which is the name of a file as found
109 in the compilation output, and should return a transformed file name.")
112 (defvar compilation-process-setup-function nil
113 "*Function to call to customize the compilation process.
114 This function is called immediately before the compilation process is
115 started. It can be used to set any variables or functions that are used
116 while processing the output of the compilation process. The function
117 is called with variables `compilation-buffer' and `compilation-window'
118 bound to the compilation buffer and window, respectively.")
121 (defvar compilation-buffer-name-function nil
122 "Function to compute the name of a compilation buffer.
123 The function receives one argument, the name of the major mode of the
124 compilation buffer. It should return a string.
125 If nil, compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
128 (defvar compilation-finish-function nil
129 "Function to call when a compilation process finishes.
130 It is called with two arguments: the compilation buffer, and a string
131 describing how the process finished.")
133 (make-obsolete-variable 'compilation-finish-function
134 "use `compilation-finish-functions', but it works a little differently."
138 (defvar compilation-finish-functions nil
139 "Functions to call when a compilation process finishes.
140 Each function is called with two arguments: the compilation buffer,
141 and a string describing how the process finished.")
143 (defvar compilation-in-progress nil
144 "List of compilation processes now running.")
145 (or (assq 'compilation-in-progress minor-mode-alist)
146 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
149 (defvar compilation-error "error"
150 "Stem of message to print when no matches are found.")
152 (defvar compilation-arguments nil
153 "Arguments that were given to `compilation-start'.")
155 (defvar compilation-num-errors-found)
157 (defconst compilation-error-regexp-alist-alist
159 "^\\(?:[Ee]rror on \\|[Ww]arning on\\( \\)\\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
160 of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil (1))
163 "\\(warning: .*\\)? at \\([^ \n]+\\):\\([0-9]+\\)$" 2 3 nil (1))
166 " in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
169 "^[ \t]*\\[[^] \n]+\\][ \t]*\\([^: \n]+\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):[0-9]+:[0-9]+:\\)?\
170 \\( warning\\)?" 1 2 3 (4))
173 ;; Maven is a popular build tool for Java. Maven is Free Software.
174 "\\(.*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\]" 1 2 3)
177 "^\\([^: \n\t]+\\): line \\([0-9]+\\):" 1 2)
180 "^\\(?:Error\\|Warnin\\(g\\)\\) \\(?:[FEW][0-9]+ \\)?\
181 \\([a-zA-Z]?:?[^:( \t\n]+\\)\
182 \\([0-9]+\\)\\(?:[) \t]\\|:[^0-9\n]\\)" 2 3 nil (1))
185 "^ *File \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1, lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
186 \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:\\)?\\([ \n]Warning:\\)?\\)"
187 2 (3 . 4) (5 . 6) (7))
190 "^\"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)\
191 \\(?:[(. pos]+\\([0-9]+\\))?\\)?[:.,; (-]\\( warning:\\|[-0-9 ]*(W)\\)?" 1 2 3 (4))
194 "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
197 "at line \\([0-9]+\\) of \"\\([^ \n]+\\)\"$"
201 "^Error [0-9]+ at (\\([0-9]+\\):\\([^)\n]+\\))" 2 1)
204 "\\(^Warning .*\\)? line[ \n]\\([0-9]+\\)[ \n]\\(?:col \\([0-9]+\\)[ \n]\\)?file \\([^ :;\n]+\\)"
208 "^\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(?:Error\\|Warnin\\(g\\)\\)\\[[0-9]+\\]:"
212 "^\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) :\
213 \\(?:warnin\\(g\\)\\|informationa\\(l\\)\\)?" 1 2 3 (4 . 5))
215 ;; fixme: should be `mips'
217 "^[-[:alnum:]_/ ]+: \\(?:\\(?:[sS]evere\\|[eE]rror\\|[wW]arnin\\(g\\)\\|[iI]nf\\(o\\)\\)[0-9 ]*: \\)?\
218 \\([^,\" \n\t]+\\)\\(?:, line\\|:\\) \\([0-9]+\\):" 3 4 nil (1 . 2))
221 "^\\(?:[ \t]+at \\|==[0-9]+== +\\(?:at\\|b\\(y\\)\\)\\).+(\\([^()\n]+\\):\\([0-9]+\\))$" 2 3 nil (1))
224 "^\\(?:Found\\|Issued\\) .* compiling \"\\(.+\\)\":$" 1 nil nil 0)
226 "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)"
228 (2 (compilation-face '(3))))
231 ;; I have no idea what this first line is supposed to match, but it
232 ;; makes things ambiguous with output such as "foo:344:50:blabla" since
233 ;; the "foo" part can match this first line (in which case the file
234 ;; name as "344"). To avoid this, the second line disallows filenames
235 ;; exclusively composed of digits. --Stef
236 ;; Similarly, we get lots of false positives with messages including
237 ;; times of the form "HH:MM:SS" where MM is taken as a line number, so
238 ;; the last line tries to rule out message where the info after the
239 ;; line number starts with "SS". --Stef
241 ;; The core of the regexp is the one with *?. It says that a file name
242 ;; can be composed of any non-newline char, but it also rules out some
243 ;; valid but unlikely cases, such as a trailing space or a space
245 "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\)?\
246 \\([0-9]*[^0-9\n]\\(?:[^\n ]\\| [^-/\n]\\)*?\\): ?\
247 \\([0-9]+\\)\\(?:\\([.:]\\)\\([0-9]+\\)\\)?\
248 \\(?:-\\([0-9]+\\)?\\(?:\\3\\([0-9]+\\)\\)?\\)?:\
249 \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\
250 *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\|[Nn]ote\\)\\|\
251 \[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)"
252 1 (2 . 5) (4 . 6) (7 . 8))
254 ;; The `gnu' style above can incorrectly match gcc's "In file
255 ;; included from" message, so we process that first. -- cyd
257 "^\\(?:In file included\\| \\) from \
258 \\(.+\\):\\([0-9]+\\)\\(?:\\(:\\)\\|\\(,\\)\\)?" 1 2 nil (3 . 4))
261 "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)"
265 "^makepp\\(?:\\(?:: warning\\(:\\).*?\\|\\(: Scanning\\|: [LR]e?l?oading makefile\\|: Imported\\|log:.*?\\) \\|: .*?\\)\
266 `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)"
268 ("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]" nil nil
269 (2 compilation-info-face)
270 (3 compilation-line-face nil t)
271 (1 (compilation-error-properties 2 3 nil nil nil 0 nil)
274 ;; Should be lint-1, lint-2 (SysV lint)
276 " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
278 " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2)
281 ;; AFAWK, The message may be a "warning", "error", or "fatal error".
282 "^\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
283 : \\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:" 2 3 nil (4))
286 "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
287 \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
288 \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
291 ;; "during global destruction": This comes out under "use
292 ;; warnings" in recent perl when breaking circular references
293 ;; during program or thread exit.
295 " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \
296 during global destruction\\.$\\)" 1 2)
299 "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
303 "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
304 \\([0-9]+\\) of file://\\(.+\\)"
308 "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
309 [12][09][0-9][0-9] +\\(.*\\):$"
312 "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
313 nil 3 nil (2) nil (1 (compilation-face '(2))))
314 (sparc-pascal-example
315 "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
316 nil 1 nil (3) nil (2 (compilation-face '(3))))
319 ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
320 File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
324 "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
327 "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
328 \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3))
331 "^ *-: *\\(0\\):Source:\\(.+\\)$"
333 (1 compilation-line-face prepend) (2 compilation-info-face prepend))
335 "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
337 (1 compilation-line-face prepend))
338 ;; Underlines over all lines of gcov output are too uncomfortable to read.
339 ;; However, hyperlinks embedded in the lines are useful.
340 ;; So I put default face on the lines; and then put
341 ;; compilation-*-face by manually to eliminate the underlines.
342 ;; The hyperlinks are still effective.
344 "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
347 (1 compilation-line-face prepend))
349 "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
352 (1 compilation-info-face prepend) (2 compilation-line-face prepend))
354 "^ *\\(#####\\): *\\([0-9]+\\):.*$"
357 (1 compilation-error-face prepend) (2 compilation-line-face prepend))
360 ;; podchecker error messages, per Pod::Checker.
361 ;; The style is from the Pod::Checker::poderror() function, eg.
362 ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm
364 ;; Plus end_pod() can give "at line EOF" instead of a
365 ;; number, so for that match "on line N" which is the
366 ;; originating spot, eg.
367 ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm
369 ;; Plus command() can give both "on line N" and "at line N";
370 ;; the latter is desired and is matched because the .* is
372 ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod
374 "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \
375 \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)"
378 ;; perl Test module error messages.
379 ;; Style per the ok() function "$context", eg.
380 ;; # Failed test 1 in foo.t at line 6
382 "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
385 ;; Or when comparing got/want values,
386 ;; # Test 2 got: "xx" (t-compilation-perl-2.t at line 10)
388 ;; And under Test::Harness they're preceded by progress stuff with
390 ;; ... NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
392 "^\\(.*NOK.*\\)?# Test [0-9]+ got:.* (\\([^ \t\r\n]+\\) at line \
396 ;; perl Test::Harness output, eg.
397 ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
399 ;; Test::Harness is slightly designed for tty output, since
400 ;; it prints CRs to overwrite progress messages, but if you
401 ;; run it in with M-x compile this pattern can at least step
402 ;; through the failures.
404 "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
407 ;; The style comes from HTML::Lint::Error::as_string(), eg.
408 ;; index.html (13:1) Unknown element <fdjsk>
410 ;; The pattern only matches filenames without spaces, since that
411 ;; should be usual and should help reduce the chance of a false
412 ;; match of a message from some unrelated program.
414 ;; This message style is quite close to the "ibm" entry which is
415 ;; for IBM C, though that ibm bit doesn't put a space after the
418 "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) "
421 "Alist of values for `compilation-error-regexp-alist'.")
423 (defcustom compilation-error-regexp-alist
424 (mapcar 'car compilation-error-regexp-alist-alist)
425 "Alist that specifies how to match errors in compiler output.
426 On GNU and Unix, any string is a valid filename, so these
427 matchers must make some common sense assumptions, which catch
428 normal cases. A shorter list will be lighter on resource usage.
430 Instead of an alist element, you can use a symbol, which is
431 looked up in `compilation-error-regexp-alist-alist'. You can see
432 the predefined symbols and their effects in the file
433 `etc/compilation.txt' (linked below if you are customizing this).
435 Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
436 HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
437 gives the file name, and the LINE'th subexpression gives the line
438 number. The COLUMN'th subexpression gives the column number on
441 If FILE, LINE or COLUMN are nil or that index didn't match, that
442 information is not present on the matched line. In that case the
443 file name is assumed to be the same as the previous one in the
444 buffer, line number defaults to 1 and column defaults to
445 beginning of line's indentation.
447 FILE can also have the form (FILE FORMAT...), where the FORMATs
448 \(e.g. \"%s.c\") will be applied in turn to the recognized file
449 name, until a file of that name is found. Or FILE can also be a
450 function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
451 In the former case, FILENAME may be relative or absolute.
453 LINE can also be of the form (LINE . END-LINE) meaning a range
454 of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
455 meaning a range of columns starting on LINE and ending on
456 END-LINE, if that matched.
458 TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
459 TYPE can also be of the form (WARNING . INFO). In that case this
460 will be equivalent to 1 if the WARNING'th subexpression matched
461 or else equivalent to 0 if the INFO'th subexpression matched.
462 See `compilation-error-face', `compilation-warning-face',
463 `compilation-info-face' and `compilation-skip-threshold'.
465 What matched the HYPERLINK'th subexpression has `mouse-face' and
466 `compilation-message-face' applied. If this is nil, the text
467 matched by the whole REGEXP becomes the hyperlink.
469 Additional HIGHLIGHTs as described under `font-lock-keywords' can
471 :type `(set :menu-tag "Pick"
472 ,@(mapcar (lambda (elt)
473 (list 'const (car elt)))
474 compilation-error-regexp-alist-alist))
475 :link `(file-link :tag "example file"
476 ,(expand-file-name "compilation.txt" data-directory))
479 ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp)
480 (defvar compilation-directory nil
481 "Directory to restore to when doing `recompile'.")
483 (defvar compilation-directory-matcher
484 '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1))
485 "A list for tracking when directories are entered or left.
486 If nil, do not track directories, e.g. if all file names are absolute. The
487 first element is the REGEXP matching these messages. It can match any number
488 of variants, e.g. different languages. The remaining elements are all of the
489 form (DIR . LEAVE). If for any one of these the DIR'th subexpression
490 matches, that is a directory name. If LEAVE is nil or the corresponding
491 LEAVE'th subexpression doesn't match, this message is about going into another
492 directory. If it does match anything, this message is about going back to the
493 directory we were in before the last entering message. If you change this,
494 you may also want to change `compilation-page-delimiter'.")
496 (defvar compilation-page-delimiter
497 "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
498 "Value of `page-delimiter' in Compilation mode.")
500 (defvar compilation-mode-font-lock-keywords
501 '(;; configure output lines.
502 ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
503 (1 font-lock-variable-name-face)
504 (2 (compilation-face '(4 . 3))))
505 ;; Command output lines. Recognize `make[n]:' lines too.
506 ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
507 (1 font-lock-function-name-face) (3 compilation-line-face nil t))
508 (" --?o\\(?:utfile\\|utput\\)?[= ]?\\(\\S +\\)" . 1)
509 ("^Compilation \\(finished\\).*"
510 (0 '(face nil message nil help-echo nil mouse-face nil) t)
511 (1 compilation-info-face))
512 ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
513 (0 '(face nil message nil help-echo nil mouse-face nil) t)
514 (1 compilation-error-face)
515 (2 compilation-error-face nil t)))
516 "Additional things to highlight in Compilation mode.
517 This gets tacked on the end of the generated expressions.")
519 (defvar compilation-highlight-regexp t
520 "Regexp matching part of visited source lines to highlight temporarily.
521 Highlight entire line if t; don't highlight source lines if nil.")
523 (defvar compilation-highlight-overlay nil
524 "Overlay used to temporarily highlight compilation matches.")
526 (defcustom compilation-error-screen-columns t
527 "If non-nil, column numbers in error messages are screen columns.
528 Otherwise they are interpreted as character positions, with
529 each character occupying one column.
530 The default is to use screen columns, which requires that the compilation
531 program and Emacs agree about the display width of the characters,
532 especially the TAB character."
537 (defcustom compilation-read-command t
538 "Non-nil means \\[compile] reads the compilation command to use.
539 Otherwise, \\[compile] just uses the value of `compile-command'."
544 (defcustom compilation-ask-about-save t
545 "Non-nil means \\[compile] asks which buffers to save before compiling.
546 Otherwise, it saves all modified buffers without asking."
551 (defcustom compilation-search-path '(nil)
552 "List of directories to search for source files named in error messages.
553 Elements should be directory names, not file names of directories.
554 The value nil as an element means to try the default directory."
555 :type '(repeat (choice (const :tag "Default" nil)
556 (string :tag "Directory")))
560 (defcustom compile-command "make -k "
561 "Last shell command used to do a compilation; default for next compilation.
563 Sometimes it is useful for files to supply local values for this variable.
564 You might also use mode hooks to specify it in certain modes, like this:
566 (add-hook 'c-mode-hook
568 (unless (or (file-exists-p \"makefile\")
569 (file-exists-p \"Makefile\"))
570 (set (make-local-variable 'compile-command)
572 (file-name-sans-extension buffer-file-name))))))"
575 ;;;###autoload(put 'compile-command 'safe-local-variable 'stringp)
578 (defcustom compilation-disable-input nil
579 "If non-nil, send end-of-file as compilation process input.
580 This only affects platforms that support asynchronous processes (see
581 `start-process'); synchronous compilation processes never accept input."
586 ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
587 ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
588 ;; key. This holds the tree seen from root, for storing new nodes.
589 (defvar compilation-locs ())
591 (defvar compilation-debug nil
592 "*Set this to t before creating a *compilation* buffer.
593 Then every error line will have a debug text property with the matcher that
594 fit this line and the match data. Use `describe-text-properties'.")
596 (defvar compilation-exit-message-function nil "\
597 If non-nil, called when a compilation process dies to return a status message.
598 This should be a function of three arguments: process status, exit status,
599 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
600 write into the compilation buffer, and to put in its mode line.")
602 (defvar compilation-environment nil
603 "*List of environment variables for compilation to inherit.
604 Each element should be a string of the form ENVVARNAME=VALUE.
605 This list is temporarily prepended to `process-environment' prior to
606 starting the compilation process.")
608 ;; History of compile commands.
609 (defvar compile-history nil)
611 (defface compilation-error
612 '((t :inherit font-lock-warning-face))
613 "Face used to highlight compiler errors."
617 (defface compilation-warning
618 '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
619 (((class color)) (:foreground "cyan" :weight bold))
621 "Face used to highlight compiler warnings."
625 (defface compilation-info
626 '((((class color) (min-colors 16) (background light))
627 (:foreground "Green3" :weight bold))
628 (((class color) (min-colors 88) (background dark))
629 (:foreground "Green1" :weight bold))
630 (((class color) (min-colors 16) (background dark))
631 (:foreground "Green" :weight bold))
632 (((class color)) (:foreground "green" :weight bold))
634 "Face used to highlight compiler information."
638 (defface compilation-line-number
639 '((t :inherit font-lock-variable-name-face))
640 "Face for displaying line numbers in compiler messages."
644 (defface compilation-column-number
645 '((t :inherit font-lock-type-face))
646 "Face for displaying column numbers in compiler messages."
650 (defcustom compilation-message-face 'underline
651 "Face name to use for whole messages.
652 Faces `compilation-error-face', `compilation-warning-face',
653 `compilation-info-face', `compilation-line-face' and
654 `compilation-column-face' get prepended to this, when applicable."
659 (defvar compilation-error-face 'compilation-error
660 "Face name to use for file name in error messages.")
662 (defvar compilation-warning-face 'compilation-warning
663 "Face name to use for file name in warning messages.")
665 (defvar compilation-info-face 'compilation-info
666 "Face name to use for file name in informational messages.")
668 (defvar compilation-line-face 'compilation-line-number
669 "Face name to use for line numbers in compiler messages.")
671 (defvar compilation-column-face 'compilation-column-number
672 "Face name to use for column numbers in compiler messages.")
674 ;; same faces as dired uses
675 (defvar compilation-enter-directory-face 'font-lock-function-name-face
676 "Face name to use for entering directory messages.")
678 (defvar compilation-leave-directory-face 'font-lock-type-face
679 "Face name to use for leaving directory messages.")
683 ;; Used for compatibility with the old compile.el.
684 (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
685 (defvar compilation-parsing-end (make-marker))
686 (defvar compilation-parse-errors-function nil)
687 (defvar compilation-error-list nil)
688 (defvar compilation-old-error-list nil)
690 (defcustom compilation-auto-jump-to-first-error nil
691 "If non-nil, automatically jump to the first error after `compile'."
696 (defvar compilation-auto-jump-to-next nil
697 "If non-nil, automatically jump to the next error encountered.")
698 (make-variable-buffer-local 'compilation-auto-jump-to-next)
701 (defvar compilation-skip-to-next-location t
702 "*If non-nil, skip multiple error messages for the same source location.")
704 (defcustom compilation-skip-threshold 1
705 "Compilation motion commands skip less important messages.
706 The value can be either 2 -- skip anything less than error, 1 --
707 skip anything less than warning or 0 -- don't skip any messages.
708 Note that all messages not positively identified as warning or
709 info, are considered errors."
710 :type '(choice (const :tag "Warnings and info" 2)
711 (const :tag "Info" 1)
712 (const :tag "None" 0))
716 (defcustom compilation-skip-visited nil
717 "Compilation motion commands skip visited messages if this is t.
718 Visited messages are ones for which the file, line and column have been jumped
719 to from the current content in the current compilation buffer, even if it was
720 from a different message."
725 (defun compilation-face (type)
726 (or (and (car type) (match-end (car type)) compilation-warning-face)
727 (and (cdr type) (match-end (cdr type)) compilation-info-face)
728 compilation-error-face))
730 ;; Internal function for calculating the text properties of a directory
731 ;; change message. The directory property is important, because it is
732 ;; the stack of nested enter-messages. Relative filenames on the following
733 ;; lines are relative to the top of the stack.
734 (defun compilation-directory-properties (idx leave)
735 (if leave (setq leave (match-end leave)))
736 ;; find previous stack, and push onto it, or if `leave' pop it
737 (let ((dir (previous-single-property-change (point) 'directory)))
738 (setq dir (if dir (or (get-text-property (1- dir) 'directory)
739 (get-text-property dir 'directory))))
741 compilation-leave-directory-face
742 compilation-enter-directory-face)
745 '(nil)) ; nil only isn't a property-change
746 (cons (match-string-no-properties idx) dir))
748 keymap compilation-button-map
749 help-echo "mouse-2: visit destination directory")))
751 ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
752 ;; KEY element from the ALIST, creating it in the right position if not already
753 ;; present. ALIST structure is
754 ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
755 ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
756 ;; may be nil. The other KEYs are ordered backwards so that growing line
757 ;; numbers can be inserted in front and searching can abort after half the
759 (eval-when-compile ;Don't keep it at runtime if not needed.
760 (defmacro compilation-assq (key alist)
763 (car (if (if (null ,key)
764 (if l2 (null (caar l2)))
765 (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
768 (if l2 (eq ,key (caar l2))))
770 (setcdr l1 (cons (list ,key) l2)))))))
772 (defun compilation-auto-jump (buffer pos)
773 (with-current-buffer buffer
775 (let ((win (get-buffer-window buffer 0)))
776 (if win (set-window-point win pos)))
777 (if compilation-auto-jump-to-first-error
778 (compile-goto-error))))
780 ;; This function is the central driver, called when font-locking to gather
781 ;; all information needed to later jump to corresponding source code.
782 ;; Return a property list with all meta information on this error location.
784 (defun compilation-error-properties (file line end-line col end-col type fmt)
785 (unless (< (next-single-property-change (match-beginning 0)
786 'directory nil (point))
790 (setq file (funcall file))
792 (setq file (match-string-no-properties file))
793 (unless (file-name-absolute-p file)
794 (setq dir (previous-single-property-change (point) 'directory)
795 dir (if dir (or (get-text-property (1- dir) 'directory)
796 (get-text-property dir 'directory)))))
797 (setq file (cons file (car dir)))))
798 ;; This message didn't mention one, get it from previous
800 ;; Find the previous message.
801 (previous-single-property-change (point) 'message)))
803 ;; Get the file structure that belongs to it.
805 (or (get-text-property (1- prev-pos) 'message)
806 (get-text-property prev-pos 'message)))
808 (car (nth 2 (car prev)))))
809 ;; Construct FILE . DIR from that.
811 (setq file (cons (car prev-struct)
812 (cadr prev-struct))))))
814 (setq file '("*unknown*")))))
815 ;; All of these fields are optional, get them only if we have an index, and
816 ;; it matched some part of the message.
818 (setq line (match-string-no-properties line))
819 (setq line (string-to-number line)))
821 (setq end-line (match-string-no-properties end-line))
822 (setq end-line (string-to-number end-line)))
825 (setq col (funcall col))
827 (setq col (match-string-no-properties col))
828 (setq col (- (string-to-number col) compilation-first-column)))))
829 (if (and end-col (functionp end-col))
830 (setq end-col (funcall end-col))
831 (if (and end-col (setq end-col (match-string-no-properties end-col)))
832 (setq end-col (- (string-to-number end-col) compilation-first-column -1))
833 (if end-line (setq end-col -1))))
834 (if (consp type) ; not a static type, check what it is.
835 (setq type (or (and (car type) (match-end (car type)) 1)
836 (and (cdr type) (match-end (cdr type)) 0)
839 (when (and compilation-auto-jump-to-next
840 (>= type compilation-skip-threshold))
841 (kill-local-variable 'compilation-auto-jump-to-next)
842 (run-with-timer 0 nil 'compilation-auto-jump
843 (current-buffer) (match-beginning 0)))
845 (compilation-internal-error-properties file line end-line col end-col type fmt)))
847 (defun compilation-move-to-column (col screen)
848 "Go to column COL on the current line.
849 If SCREEN is non-nil, columns are screen columns, otherwise, they are
853 (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
855 (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
856 "Get the meta-info that will be added as text-properties.
857 LINE, END-LINE, COL, END-COL are integers or nil.
858 TYPE can be 0, 1, or 2, meaning error, warning, or just info.
859 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
860 FMTS is a list of format specs for transforming the file name.
861 (See `compilation-error-regexp-alist'.)"
862 (unless file (setq file '("*unknown*")))
863 (let* ((file-struct (compilation-get-file-structure file fmts))
864 ;; Get first already existing marker (if any has one, all have one).
865 ;; Do this first, as the compilation-assq`s may create new nodes.
866 (marker-line (car (cddr file-struct))) ; a line structure
867 (marker (nth 3 (cadr marker-line))) ; its marker
868 (compilation-error-screen-columns compilation-error-screen-columns)
869 end-marker loc end-loc)
870 (if (not (and marker (marker-buffer marker)))
871 (setq marker nil) ; no valid marker for this file
872 (setq loc (or line 1)) ; normalize no linenumber to line 1
873 (catch 'marker ; find nearest loc, at least one exists
874 (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines
875 (if (> (car x) loc) ; still bigger
877 (if (> (- (or (car marker-line) 1) loc)
878 (- loc (car x))) ; current line is nearer
879 (setq marker-line x))
881 (setq marker (nth 3 (cadr marker-line))
882 marker-line (or (car marker-line) 1))
883 (with-current-buffer (marker-buffer marker)
887 (goto-char (marker-position marker))
888 (when (or end-col end-line)
889 (beginning-of-line (- (or end-line line) marker-line -1))
890 (if (or (null end-col) (< end-col 0))
892 (compilation-move-to-column
893 end-col compilation-error-screen-columns))
894 (setq end-marker (list (point-marker))))
895 (beginning-of-line (if end-line
897 (- loc marker-line -1)))
899 (compilation-move-to-column
900 col compilation-error-screen-columns)
901 (forward-to-indentation 0))
902 (setq marker (list (point-marker)))))))
904 (setq loc (compilation-assq line (cdr file-struct)))
906 (setq end-loc (compilation-assq end-line (cdr file-struct))
907 end-loc (compilation-assq end-col end-loc))
908 (if end-col ; use same line element
909 (setq end-loc (compilation-assq end-col loc))))
910 (setq loc (compilation-assq col loc))
911 ;; If they are new, make the loc(s) reference the file they point to.
912 (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker)))
915 (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker))))
917 ;; Must start with face
918 `(face ,compilation-message-face
919 message (,loc ,type ,end-loc)
920 ,@(if compilation-debug
921 `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords)
924 "mouse-2: visit this file, line and column"
926 "mouse-2: visit this file and line"
927 "mouse-2: visit this file"))
928 keymap compilation-button-map
929 mouse-face highlight)))
931 (defun compilation-mode-font-lock-keywords ()
932 "Return expressions to highlight in Compilation mode."
933 (if compilation-parse-errors-function
934 ;; An old package! Try the compatibility code.
935 '((compilation-compat-parse-errors))
937 ;; make directory tracking
938 (if compilation-directory-matcher
939 `((,(car compilation-directory-matcher)
940 ,@(mapcar (lambda (elt)
942 (compilation-directory-properties
943 ,(car elt) ,(cdr elt))
945 (cdr compilation-directory-matcher)))))
947 ;; Compiler warning/error lines.
951 (setq item (cdr (assq item
952 compilation-error-regexp-alist-alist))))
953 (let ((file (nth 1 item))
957 end-line end-col fmt)
958 (if (consp file) (setq fmt (cdr file) file (car file)))
959 (if (consp line) (setq end-line (cdr line) line (car line)))
960 (if (consp col) (setq end-col (cdr col) col (car col)))
963 ;; The old compile.el had here an undocumented hook that
964 ;; allowed `line' to be a function that computed the actual
965 ;; error location. Let's do our best.
968 (compilation-compat-error-properties
969 (funcall ',line (cons (match-string ,file)
970 (cons default-directory
972 ,(if col `(match-string ,col))))))
973 (,file compilation-error-face t))
975 (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
976 (error "HYPERLINK should be an integer: %s" (nth 5 item)))
980 ,@(when (integerp file)
981 `((,file ,(if (consp type)
982 `(compilation-face ',type)
983 (aref [compilation-info-face
984 compilation-warning-face
985 compilation-error-face]
989 `((,line compilation-line-face nil t)))
991 `((,end-line compilation-line-face nil t)))
993 ,@(when (integerp col)
994 `((,col compilation-column-face nil t)))
995 ,@(when (integerp end-col)
996 `((,end-col compilation-column-face nil t)))
999 (,(or (nth 5 item) 0)
1000 (compilation-error-properties ',file ,line ,end-line
1001 ,col ,end-col ',(or type 2)
1003 append))))) ; for compilation-message-face
1004 compilation-error-regexp-alist)
1006 compilation-mode-font-lock-keywords)))
1010 (defun compile (command &optional comint)
1011 "Compile the program including the current buffer. Default: run `make'.
1012 Runs COMMAND, a shell command, in a separate process asynchronously
1013 with output going to the buffer `*compilation*'.
1015 You can then use the command \\[next-error] to find the next error message
1016 and move to the source code that caused it.
1018 If optional second arg COMINT is t the buffer will be in Comint mode with
1019 `compilation-shell-minor-mode'.
1021 Interactively, prompts for the command if `compilation-read-command' is
1022 non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
1023 Additionally, with universal prefix arg, compilation buffer will be in
1024 comint mode, i.e. interactive.
1026 To run more than one compilation at once, start one then rename
1027 the \`*compilation*' buffer to some other name with
1028 \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
1029 It will create a new \`*compilation*' buffer.
1031 On most systems, termination of the main compilation process
1032 kills its subprocesses.
1034 The name used for the buffer is actually whatever is returned by
1035 the function in `compilation-buffer-name-function', so you can set that
1036 to a function that generates a unique name."
1039 (let ((command (eval compile-command)))
1040 (if (or compilation-read-command current-prefix-arg)
1041 (read-shell-command "Compile command: " command
1042 (if (equal (car compile-history) command)
1043 '(compile-history . 1)
1046 (consp current-prefix-arg)))
1047 (unless (equal command (eval compile-command))
1048 (setq compile-command command))
1049 (save-some-buffers (not compilation-ask-about-save) nil)
1050 (setq-default compilation-directory default-directory)
1051 (compilation-start command comint))
1053 ;; run compile with the default command line
1055 "Re-compile the program including the current buffer.
1056 If this is run in a Compilation mode buffer, re-use the arguments from the
1057 original use. Otherwise, recompile using `compile-command'."
1059 (save-some-buffers (not compilation-ask-about-save) nil)
1060 (let ((default-directory (or compilation-directory default-directory)))
1061 (apply 'compilation-start (or compilation-arguments
1062 `(,(eval compile-command))))))
1064 (defcustom compilation-scroll-output nil
1065 "Non-nil to scroll the *compilation* buffer window as output appears.
1067 Setting it causes the Compilation mode commands to put point at the
1068 end of their output window so that the end of the output is always
1069 visible rather than the beginning.
1071 The value `first-error' stops scrolling at the first error, and leaves
1072 point on its location in the *compilation* buffer."
1073 :type '(choice (const :tag "No scrolling" nil)
1074 (const :tag "Scroll compilation output" t)
1075 (const :tag "Stop scrolling at the first error" first-error))
1077 :group 'compilation)
1080 (defun compilation-buffer-name (mode-name mode-command name-function)
1081 "Return the name of a compilation buffer to use.
1082 If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
1083 to determine the buffer name.
1084 Likewise if `compilation-buffer-name-function' is non-nil.
1085 If current buffer has the major mode MODE-COMMAND,
1086 return the name of the current buffer, so that it gets reused.
1087 Otherwise, construct a buffer name from MODE-NAME."
1088 (cond (name-function
1089 (funcall name-function mode-name))
1090 (compilation-buffer-name-function
1091 (funcall compilation-buffer-name-function mode-name))
1092 ((eq mode-command major-mode)
1095 (concat "*" (downcase mode-name) "*"))))
1097 ;; This is a rough emulation of the old hack, until the transition to new
1098 ;; compile is complete.
1099 (defun compile-internal (command error-message
1100 &optional name-of-mode parser
1101 error-regexp-alist name-function
1102 enter-regexp-alist leave-regexp-alist
1103 file-regexp-alist nomessage-regexp-alist
1104 no-async highlight-regexp local-map)
1106 (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
1107 (let ((compilation-error-regexp-alist
1108 (append file-regexp-alist (or error-regexp-alist
1109 compilation-error-regexp-alist)))
1110 (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
1111 "\\1" error-message)))
1112 (compilation-start command nil name-function highlight-regexp)))
1113 (make-obsolete 'compile-internal 'compilation-start "22.1")
1116 (defun compilation-start (command &optional mode name-function highlight-regexp)
1117 "Run compilation command COMMAND (low level interface).
1118 If COMMAND starts with a cd command, that becomes the `default-directory'.
1119 The rest of the arguments are optional; for them, nil means use the default.
1121 MODE is the major mode to set in the compilation buffer. Mode
1122 may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
1124 If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
1125 to determine the buffer name. Otherwise, the default is to
1126 reuses the current buffer if it has the proper major mode,
1127 else use or create a buffer with name based on the major mode.
1129 If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
1130 the matching section of the visited source line; the default is to use the
1131 global value of `compilation-highlight-regexp'.
1133 Returns the compilation buffer created."
1134 (or mode (setq mode 'compilation-mode))
1135 (let* ((name-of-mode
1137 (prog1 "compilation" (require 'comint))
1138 (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
1139 (thisdir default-directory)
1141 (with-current-buffer
1144 (compilation-buffer-name name-of-mode mode name-function)))
1145 (let ((comp-proc (get-buffer-process (current-buffer))))
1147 (if (or (not (eq (process-status comp-proc) 'run))
1149 (format "A %s process is running; kill it? "
1153 (interrupt-process comp-proc)
1155 (delete-process comp-proc))
1157 (error "Cannot have two processes in `%s' at once"
1159 (buffer-disable-undo (current-buffer))
1160 ;; first transfer directory from where M-x compile was called
1161 (setq default-directory thisdir)
1162 ;; Remember the original dir, so we can use it when we recompile.
1163 ;; default-directory' can't be used reliably for that because it may be
1164 ;; affected by the special handling of "cd ...;".
1165 (set (make-local-variable 'compilation-directory) thisdir)
1166 ;; Make compilation buffer read-only. The filter can still write it.
1167 ;; Clear out the compilation buffer.
1168 (let ((inhibit-read-only t)
1169 (default-directory thisdir))
1170 ;; Then evaluate a cd command if any, but don't perform it yet, else
1171 ;; start-command would do it again through the shell: (cd "..") AND
1172 ;; sh -c "cd ..; make"
1173 (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command)
1175 (substitute-env-vars (match-string 1 command))
1179 ;; Select the desired mode.
1180 (if (not (eq mode t))
1182 (setq buffer-read-only nil)
1183 (with-no-warnings (comint-mode))
1184 (compilation-shell-minor-mode))
1185 (if highlight-regexp
1186 (set (make-local-variable 'compilation-highlight-regexp)
1188 (if (or compilation-auto-jump-to-first-error
1189 (eq compilation-scroll-output 'first-error))
1190 (set (make-local-variable 'compilation-auto-jump-to-next) t))
1191 ;; Output a mode setter, for saving and later reloading this buffer.
1192 (insert "-*- mode: " name-of-mode
1193 "; default-directory: " (prin1-to-string default-directory)
1195 (format "%s started at %s\n\n"
1197 (substring (current-time-string) 0 19))
1199 (setq thisdir default-directory))
1200 (set-buffer-modified-p nil))
1201 ;; Pop up the compilation buffer.
1202 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html
1203 (setq outwin (display-buffer outbuf))
1204 (with-current-buffer outbuf
1205 (let ((process-environment
1207 compilation-environment
1208 (if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning
1209 system-uses-terminfo)
1210 (list "TERM=dumb" "TERMCAP="
1211 (format "COLUMNS=%d" (window-width)))
1213 (format "TERMCAP=emacs:co#%d:tc=unknown:"
1215 ;; Set the EMACS variable, but
1216 ;; don't override users' setting of $EMACS.
1217 (unless (getenv "EMACS")
1219 (list "INSIDE_EMACS=t")
1220 (copy-sequence process-environment))))
1221 (set (make-local-variable 'compilation-arguments)
1222 (list command mode name-function highlight-regexp))
1223 (set (make-local-variable 'revert-buffer-function)
1224 'compilation-revert-buffer)
1225 (set-window-start outwin (point-min))
1227 ;; Position point as the user will see it.
1228 (let ((desired-visible-point
1229 ;; Put it at the end if `compilation-scroll-output' is set.
1230 (if compilation-scroll-output
1232 ;; Normally put it at the top.
1234 (if (eq outwin (selected-window))
1235 (goto-char desired-visible-point)
1236 (set-window-point outwin desired-visible-point)))
1238 ;; The setup function is called before compilation-set-window-height
1239 ;; so it can set the compilation-window-height buffer locally.
1240 (if compilation-process-setup-function
1241 (funcall compilation-process-setup-function))
1242 (compilation-set-window-height outwin)
1243 ;; Start the compilation.
1246 ;; comint uses `start-file-process'.
1250 outbuf (downcase mode-name)
1251 (if (file-remote-p default-directory)
1254 nil `("-c" ,command))))
1255 (start-file-process-shell-command (downcase mode-name)
1257 ;; Make the buffer's mode line show process state.
1258 (setq mode-line-process
1259 (list (propertize ":%s" 'face 'compilation-warning)))
1260 (set-process-sentinel proc 'compilation-sentinel)
1261 (set-process-filter proc 'compilation-filter)
1262 ;; Use (point-max) here so that output comes in
1263 ;; after the initial text,
1264 ;; regardless of where the user sees point.
1265 (set-marker (process-mark proc) (point-max) outbuf)
1266 (when compilation-disable-input
1268 (process-send-eof proc)
1269 ;; The process may have exited already.
1271 (setq compilation-in-progress
1272 (cons proc compilation-in-progress))))
1273 ;; Now finally cd to where the shell started make/grep/...
1274 (setq default-directory thisdir))
1275 (if (buffer-local-value 'compilation-scroll-output outbuf)
1276 (save-selected-window
1277 (select-window outwin)
1278 (goto-char (point-max))))
1279 ;; Make it so the next C-x ` will use this buffer.
1280 (setq next-error-last-buffer outbuf)))
1282 (defun compilation-set-window-height (window)
1283 "Set the height of WINDOW according to `compilation-window-height'."
1284 (let ((height (buffer-local-value 'compilation-window-height (window-buffer window))))
1286 (window-full-width-p window)
1287 ;; If window is alone in its frame, aside from a minibuffer,
1288 ;; don't change its height.
1289 (not (eq window (frame-root-window (window-frame window))))
1290 ;; Stef said that doing the saves in this order is safer:
1292 (save-selected-window
1293 (select-window window)
1294 (enlarge-window (- height (window-height))))))))
1296 (defvar compilation-menu-map
1297 (let ((map (make-sparse-keymap "Errors"))
1298 (opt-map (make-sparse-keymap "Skip")))
1299 (define-key map [stop-subjob]
1300 '(menu-item "Stop Compilation" kill-compilation
1301 :help "Kill the process made by the M-x compile or M-x grep commands"))
1302 (define-key map [compilation-mode-separator3]
1304 (define-key map [compilation-next-error-follow-minor-mode]
1306 "Auto Error Display" next-error-follow-minor-mode
1307 :help "Display the error under cursor when moving the cursor"
1308 :button (:toggle . next-error-follow-minor-mode)))
1309 (define-key map [compilation-skip]
1310 (cons "Skip Less Important Messages" opt-map))
1311 (define-key opt-map [compilation-skip-none]
1312 '(menu-item "Don't Skip Any Messages"
1315 (customize-set-variable 'compilation-skip-threshold 0))
1316 :help "Do not skip any type of messages"
1317 :button (:radio . (eq compilation-skip-threshold 0))))
1318 (define-key opt-map [compilation-skip-info]
1319 '(menu-item "Skip Info"
1322 (customize-set-variable 'compilation-skip-threshold 1))
1323 :help "Skip anything less than warning"
1324 :button (:radio . (eq compilation-skip-threshold 1))))
1325 (define-key opt-map [compilation-skip-warning-and-info]
1326 '(menu-item "Skip Warnings and Info"
1329 (customize-set-variable 'compilation-skip-threshold 2))
1330 :help "Skip over Warnings and Info, stop for errors"
1331 :button (:radio . (eq compilation-skip-threshold 2))))
1332 (define-key map [compilation-mode-separator2]
1334 (define-key map [compilation-first-error]
1335 '(menu-item "First Error" first-error
1336 :help "Restart at the first error, visit corresponding source code"))
1337 (define-key map [compilation-previous-error]
1338 '(menu-item "Previous Error" previous-error
1339 :help "Visit previous `next-error' message and corresponding source code"))
1340 (define-key map [compilation-next-error]
1341 '(menu-item "Next Error" next-error
1342 :help "Visit next `next-error' message and corresponding source code"))
1345 (defvar compilation-minor-mode-map
1346 (let ((map (make-sparse-keymap)))
1347 (define-key map [mouse-2] 'compile-goto-error)
1348 (define-key map [follow-link] 'mouse-face)
1349 (define-key map "\C-c\C-c" 'compile-goto-error)
1350 (define-key map "\C-m" 'compile-goto-error)
1351 (define-key map "\C-c\C-k" 'kill-compilation)
1352 (define-key map "\M-n" 'compilation-next-error)
1353 (define-key map "\M-p" 'compilation-previous-error)
1354 (define-key map "\M-{" 'compilation-previous-file)
1355 (define-key map "\M-}" 'compilation-next-file)
1356 ;; Set up the menu-bar
1357 (define-key map [menu-bar compilation]
1358 (cons "Errors" compilation-menu-map))
1360 "Keymap for `compilation-minor-mode'.")
1362 (defvar compilation-shell-minor-mode-map
1363 (let ((map (make-sparse-keymap)))
1364 (define-key map "\M-\C-m" 'compile-goto-error)
1365 (define-key map "\M-\C-n" 'compilation-next-error)
1366 (define-key map "\M-\C-p" 'compilation-previous-error)
1367 (define-key map "\M-{" 'compilation-previous-file)
1368 (define-key map "\M-}" 'compilation-next-file)
1369 ;; Set up the menu-bar
1370 (define-key map [menu-bar compilation]
1371 (cons "Errors" compilation-menu-map))
1373 "Keymap for `compilation-shell-minor-mode'.")
1375 (defvar compilation-button-map
1376 (let ((map (make-sparse-keymap)))
1377 (define-key map [mouse-2] 'compile-goto-error)
1378 (define-key map [follow-link] 'mouse-face)
1379 (define-key map "\C-m" 'compile-goto-error)
1381 "Keymap for compilation-message buttons.")
1382 (fset 'compilation-button-map compilation-button-map)
1384 (defvar compilation-mode-map
1385 (let ((map (make-sparse-keymap)))
1386 ;; Don't inherit from compilation-minor-mode-map,
1387 ;; because that introduces a menu bar item we don't want.
1388 ;; That confuses C-down-mouse-3.
1389 (define-key map [mouse-2] 'compile-goto-error)
1390 (define-key map [follow-link] 'mouse-face)
1391 (define-key map "\C-c\C-c" 'compile-goto-error)
1392 (define-key map "\C-m" 'compile-goto-error)
1393 (define-key map "\C-c\C-k" 'kill-compilation)
1394 (define-key map "\M-n" 'compilation-next-error)
1395 (define-key map "\M-p" 'compilation-previous-error)
1396 (define-key map "\M-{" 'compilation-previous-file)
1397 (define-key map "\M-}" 'compilation-next-file)
1398 (define-key map "\t" 'compilation-next-error)
1399 (define-key map [backtab] 'compilation-previous-error)
1401 (define-key map " " 'scroll-up)
1402 (define-key map "\^?" 'scroll-down)
1403 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
1405 ;; Set up the menu-bar
1406 (let ((submap (make-sparse-keymap "Compile")))
1407 (define-key map [menu-bar compilation]
1408 (cons "Compile" submap))
1409 (set-keymap-parent submap compilation-menu-map))
1410 (define-key map [menu-bar compilation compilation-separator2]
1412 (define-key map [menu-bar compilation compilation-grep]
1413 '(menu-item "Search Files (grep)..." grep
1414 :help "Run grep, with user-specified args, and collect output in a buffer"))
1415 (define-key map [menu-bar compilation compilation-recompile]
1416 '(menu-item "Recompile" recompile
1417 :help "Re-compile the program including the current buffer"))
1418 (define-key map [menu-bar compilation compilation-compile]
1419 '(menu-item "Compile..." compile
1420 :help "Compile the program including the current buffer. Default: run `make'"))
1422 "Keymap for compilation log buffers.
1423 `compilation-minor-mode-map' is a parent of this.")
1425 (defvar compilation-mode-tool-bar-map
1426 (if (display-graphic-p)
1427 (let ((map (butlast (copy-keymap tool-bar-map)))
1428 (help (last tool-bar-map))) ;; Keep Help last in tool bar
1429 (tool-bar-local-item
1430 "left-arrow" 'previous-error-no-select 'previous-error-no-select map
1432 :help "Goto previous error")
1433 (tool-bar-local-item
1434 "right-arrow" 'next-error-no-select 'next-error-no-select map
1436 :help "Goto next error")
1437 (tool-bar-local-item
1438 "cancel" 'kill-compilation 'kill-compilation map
1439 :enable '(let ((buffer (compilation-find-buffer)))
1440 (get-buffer-process buffer))
1441 :help "Stop compilation")
1442 (tool-bar-local-item
1443 "refresh" 'recompile 'recompile map
1444 :help "Restart compilation")
1445 (append map help))))
1447 (put 'compilation-mode 'mode-class 'special)
1450 (defun compilation-mode (&optional name-of-mode)
1451 "Major mode for compilation log buffers.
1452 \\<compilation-mode-map>To visit the source for a line-numbered error,
1453 move point to the error message line and type \\[compile-goto-error].
1454 To kill the compilation, type \\[kill-compilation].
1456 Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
1458 \\{compilation-mode-map}"
1460 (kill-all-local-variables)
1461 (use-local-map compilation-mode-map)
1462 (set (make-local-variable 'tool-bar-map) compilation-mode-tool-bar-map)
1463 (setq major-mode 'compilation-mode
1464 mode-name (or name-of-mode "Compilation"))
1465 (set (make-local-variable 'page-delimiter)
1466 compilation-page-delimiter)
1468 (setq buffer-read-only t)
1469 (run-mode-hooks 'compilation-mode-hook))
1471 (defmacro define-compilation-mode (mode name doc &rest body)
1472 "This is like `define-derived-mode' without the PARENT argument.
1473 The parent is always `compilation-mode' and the customizable `compilation-...'
1474 variables are also set from the name of the mode you have chosen,
1475 by replacing the first word, e.g `compilation-scroll-output' from
1476 `grep-scroll-output' if that variable exists."
1477 (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
1478 `(define-derived-mode ,mode compilation-mode ,name
1480 ,@(mapcar (lambda (v)
1482 (intern-soft (replace-regexp-in-string
1483 "^compilation" mode-name
1486 (or (boundp (cdr v))
1487 (if (boundp 'byte-compile-bound-variables)
1488 (memq (cdr v) byte-compile-bound-variables)))
1489 `(set (make-local-variable ',(car v)) ,(cdr v))))
1490 '(compilation-buffer-name-function
1491 compilation-directory-matcher
1493 compilation-error-regexp-alist
1494 compilation-error-regexp-alist-alist
1495 compilation-error-screen-columns
1496 compilation-finish-function
1497 compilation-finish-functions
1498 compilation-first-column
1499 compilation-mode-font-lock-keywords
1500 compilation-page-delimiter
1501 compilation-parse-errors-filename-function
1502 compilation-process-setup-function
1503 compilation-scroll-output
1504 compilation-search-path
1505 compilation-skip-threshold
1506 compilation-window-height))
1509 (defun compilation-revert-buffer (ignore-auto noconfirm)
1510 (if buffer-file-name
1511 (let (revert-buffer-function)
1512 (revert-buffer ignore-auto noconfirm))
1513 (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
1514 (apply 'compilation-start compilation-arguments))))
1516 (defvar compilation-current-error nil
1517 "Marker to the location from where the next error will be found.
1518 The global commands next/previous/first-error/goto-error use this.")
1520 (defvar compilation-messages-start nil
1521 "Buffer position of the beginning of the compilation messages.
1522 If nil, use the beginning of buffer.")
1524 ;; A function name can't be a hook, must be something with a value.
1525 (defconst compilation-turn-on-font-lock 'turn-on-font-lock)
1527 (defun compilation-setup (&optional minor)
1528 "Prepare the buffer for the compilation parsing commands to work.
1529 Optional argument MINOR indicates this is called from
1530 `compilation-minor-mode'."
1531 (make-local-variable 'compilation-current-error)
1532 (make-local-variable 'compilation-messages-start)
1533 (make-local-variable 'compilation-error-screen-columns)
1534 (make-local-variable 'overlay-arrow-position)
1535 (set (make-local-variable 'overlay-arrow-string) "")
1536 (setq next-error-overlay-arrow-position nil)
1537 (add-hook 'kill-buffer-hook
1538 (lambda () (setq next-error-overlay-arrow-position nil)) nil t)
1539 ;; Note that compilation-next-error-function is for interfacing
1540 ;; with the next-error function in simple.el, and it's only
1541 ;; coincidentally named similarly to compilation-next-error.
1542 (setq next-error-function 'compilation-next-error-function)
1543 (set (make-local-variable 'comint-file-name-prefix)
1544 (or (file-remote-p default-directory) ""))
1545 (set (make-local-variable 'font-lock-extra-managed-props)
1546 '(directory message help-echo mouse-face debug))
1547 (set (make-local-variable 'compilation-locs)
1548 (make-hash-table :test 'equal :weakness 'value))
1549 ;; lazy-lock would never find the message unless it's scrolled to.
1550 ;; jit-lock might fontify some things too late.
1551 (set (make-local-variable 'font-lock-support-mode) nil)
1552 (set (make-local-variable 'font-lock-maximum-size) nil)
1554 (let ((fld font-lock-defaults))
1555 (font-lock-add-keywords nil (compilation-mode-font-lock-keywords))
1558 (font-lock-fontify-buffer)
1559 (font-lock-change-mode)
1560 (turn-on-font-lock))
1561 (turn-on-font-lock)))
1562 (setq font-lock-defaults '(compilation-mode-font-lock-keywords t))
1563 ;; maybe defer font-lock till after derived mode is set up
1564 (run-mode-hooks 'compilation-turn-on-font-lock)))
1567 (define-minor-mode compilation-shell-minor-mode
1568 "Toggle compilation shell minor mode.
1569 With arg, turn compilation mode on if and only if arg is positive.
1570 In this minor mode, all the error-parsing commands of the
1571 Compilation major mode are available but bound to keys that don't
1572 collide with Shell mode. See `compilation-mode'.
1573 Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
1574 nil " Shell-Compile"
1576 (if compilation-shell-minor-mode
1577 (compilation-setup t)
1578 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1579 (font-lock-fontify-buffer)))
1582 (define-minor-mode compilation-minor-mode
1583 "Toggle compilation minor mode.
1584 With arg, turn compilation mode on if and only if arg is positive.
1585 In this minor mode, all the error-parsing commands of the
1586 Compilation major mode are available. See `compilation-mode'.
1587 Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
1590 (if compilation-minor-mode
1591 (compilation-setup t)
1592 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1593 (font-lock-fontify-buffer)))
1595 (defun compilation-handle-exit (process-status exit-status msg)
1596 "Write MSG in the current buffer and hack its `mode-line-process'."
1597 (let ((inhibit-read-only t)
1598 (status (if compilation-exit-message-function
1599 (funcall compilation-exit-message-function
1600 process-status exit-status msg)
1601 (cons msg exit-status)))
1604 (cur-buffer (current-buffer)))
1605 ;; Record where we put the message, so we can ignore it later on.
1607 (insert ?\n mode-name " " (car status))
1608 (if (and (numberp compilation-window-height)
1609 (zerop compilation-window-height))
1610 (message "%s" (cdr status)))
1613 (insert " at " (substring (current-time-string) 0 19))
1614 (goto-char (point-max))
1615 ;; Prevent that message from being recognized as a compilation error.
1616 (add-text-properties omax (point)
1617 (append '(compilation-handle-exit t) nil))
1618 (setq mode-line-process
1619 (let ((out-string (format ":%s [%s]" process-status (cdr status)))
1620 (msg (format "%s %s" mode-name
1621 (replace-regexp-in-string "\n?$" "" (car status)))))
1623 (propertize out-string
1624 'help-echo msg 'face (if (> exit-status 0)
1626 'compilation-info))))
1627 ;; Force mode line redisplay soon.
1628 (force-mode-line-update)
1629 (if (and opoint (< opoint omax))
1632 (if compilation-finish-function
1633 (funcall compilation-finish-function cur-buffer msg)))
1634 (run-hook-with-args 'compilation-finish-functions cur-buffer msg)))
1636 ;; Called when compilation process changes state.
1637 (defun compilation-sentinel (proc msg)
1638 "Sentinel for compilation buffers."
1639 (if (memq (process-status proc) '(exit signal))
1640 (let ((buffer (process-buffer proc)))
1641 (if (null (buffer-name buffer))
1643 (set-process-buffer proc nil)
1644 (with-current-buffer buffer
1645 ;; Write something in the compilation buffer
1646 ;; and hack its mode line.
1647 (compilation-handle-exit (process-status proc)
1648 (process-exit-status proc)
1650 ;; Since the buffer and mode line will show that the
1651 ;; process is dead, we can delete it now. Otherwise it
1652 ;; will stay around until M-x list-processes.
1653 (delete-process proc)))
1654 (setq compilation-in-progress (delq proc compilation-in-progress)))))
1656 (defun compilation-filter (proc string)
1657 "Process filter for compilation buffers.
1658 Just inserts the text, but uses `insert-before-markers'."
1659 (if (buffer-name (process-buffer proc))
1660 (with-current-buffer (process-buffer proc)
1661 (let ((inhibit-read-only t))
1663 (goto-char (process-mark proc))
1664 (insert-before-markers string)
1665 (run-hooks 'compilation-filter-hook))))))
1667 ;;; test if a buffer is a compilation buffer, assuming we're in the buffer
1668 (defsubst compilation-buffer-internal-p ()
1669 "Test if inside a compilation buffer."
1670 (local-variable-p 'compilation-locs))
1672 ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p
1673 (defsubst compilation-buffer-p (buffer)
1674 "Test if BUFFER is a compilation buffer."
1675 (with-current-buffer buffer
1676 (compilation-buffer-internal-p)))
1678 (defmacro compilation-loop (< property-change 1+ error limit)
1682 (or (setq pt (,property-change pt 'message))
1683 ;; Handle the case where where the first error message is
1684 ;; at the start of the buffer, and n < 0.
1685 (if (or (eq (get-text-property ,limit 'message)
1686 (get-text-property opt 'message))
1688 (error ,error compilation-error)
1690 ;; prop 'message usually has 2 changes, on and off, so
1692 (or (setq msg (get-text-property pt 'message))
1693 (if (setq pt (,property-change pt 'message nil ,limit))
1694 (setq msg (get-text-property pt 'message)))
1695 (error ,error compilation-error))
1696 (or (< (cadr msg) compilation-skip-threshold)
1698 (eq (prog1 last (setq last (nth 2 (car msg))))
1700 (if compilation-skip-visited
1701 (nthcdr 5 (car msg)))
1702 (if compilation-skip-to-next-location
1704 ;; count this message only if none of the above are true
1705 (setq n (,1+ n))))))
1707 (defun compilation-next-error (n &optional different-file pt)
1708 "Move point to the next error in the compilation buffer.
1709 This function does NOT find the source line like \\[next-error].
1710 Prefix arg N says how many error messages to move forwards (or
1711 backwards, if negative).
1712 Optional arg DIFFERENT-FILE, if non-nil, means find next error for a
1713 file that is different from the current one.
1714 Optional arg PT, if non-nil, specifies the value of point to start
1715 looking for the next message."
1717 (or (compilation-buffer-p (current-buffer))
1718 (error "Not in a compilation buffer"))
1719 (or pt (setq pt (point)))
1720 (let* ((msg (get-text-property pt 'message))
1721 ;; `loc' is used by the compilation-loop macro.
1725 (unless (or msg ; find message near here
1726 (setq msg (get-text-property (max (1- pt) (point-min))
1728 (setq pt (previous-single-property-change pt 'message nil
1729 (line-beginning-position)))
1730 (unless (setq msg (get-text-property (max (1- pt) (point-min)) 'message))
1731 (setq pt (next-single-property-change pt 'message nil
1732 (line-end-position)))
1733 (or (setq msg (get-text-property pt 'message))
1734 (setq pt (point)))))
1735 (setq last (nth 2 (car msg)))
1737 (compilation-loop > next-single-property-change 1-
1738 (if (get-buffer-process (current-buffer))
1740 "Moved past last %s")
1742 ;; Don't move "back" to message at or before point.
1743 ;; Pass an explicit (point-min) to make sure pt is non-nil.
1744 (setq pt (previous-single-property-change pt 'message nil (point-min)))
1745 (compilation-loop < previous-single-property-change 1+
1746 "Moved back before first %s" (point-min))))
1749 (error "No %s here" compilation-error))))
1751 (defun compilation-previous-error (n)
1752 "Move point to the previous error in the compilation buffer.
1753 Prefix arg N says how many error messages to move backwards (or
1754 forwards, if negative).
1755 Does NOT find the source line like \\[previous-error]."
1757 (compilation-next-error (- n)))
1759 (defun compilation-next-file (n)
1760 "Move point to the next error for a different file than the current one.
1761 Prefix arg N says how many files to move forwards (or backwards, if negative)."
1763 (compilation-next-error n t))
1765 (defun compilation-previous-file (n)
1766 "Move point to the previous error for a different file than the current one.
1767 Prefix arg N says how many files to move backwards (or forwards, if negative)."
1769 (compilation-next-file (- n)))
1771 (defun kill-compilation ()
1772 "Kill the process made by the \\[compile] or \\[grep] commands."
1774 (let ((buffer (compilation-find-buffer)))
1775 (if (get-buffer-process buffer)
1776 (interrupt-process (get-buffer-process buffer))
1777 (error "The %s process is not running" (downcase mode-name)))))
1779 (defalias 'compile-mouse-goto-error 'compile-goto-error)
1781 (defun compile-goto-error (&optional event)
1782 "Visit the source for the error message at point.
1783 Use this command in a compilation log buffer. Sets the mark at point there."
1784 (interactive (list last-input-event))
1785 (if event (posn-set-point (event-end event)))
1786 (or (compilation-buffer-p (current-buffer))
1787 (error "Not in a compilation buffer"))
1788 (if (get-text-property (point) 'directory)
1789 (dired-other-window (car (get-text-property (point) 'directory)))
1791 (setq compilation-current-error (point))
1792 (next-error-internal)))
1794 (defun compilation-find-buffer (&optional avoid-current)
1795 "Return a compilation buffer.
1796 If AVOID-CURRENT is nil, and the current buffer is a compilation buffer,
1797 return it. If AVOID-CURRENT is non-nil, return the current buffer only
1799 (if (and (compilation-buffer-internal-p) (not avoid-current))
1801 (next-error-find-buffer avoid-current 'compilation-buffer-internal-p)))
1804 (defun compilation-next-error-function (n &optional reset)
1805 "Advance to the next error message and visit the file where the error was.
1806 This is the value of `next-error-function' in Compilation buffers."
1809 (setq compilation-current-error nil))
1810 (let* ((columns compilation-error-screen-columns) ; buffer's local value
1812 (loc (compilation-next-error (or n 1) nil
1813 (or compilation-current-error
1814 compilation-messages-start
1816 (end-loc (nth 2 loc))
1817 (marker (point-marker)))
1818 (setq compilation-current-error (point-marker)
1819 overlay-arrow-position
1821 compilation-current-error
1822 (copy-marker (line-beginning-position)))
1824 ;; If loc contains no marker, no error in that file has been visited.
1825 ;; If the marker is invalid the buffer has been killed.
1826 ;; If the file is newer than the timestamp, it has been modified
1827 ;; (`omake -P' polls filesystem for changes and recompiles when needed
1828 ;; in the same process and buffer).
1829 ;; So, recalculate all markers for that file.
1830 (unless (and (nth 3 loc) (marker-buffer (nth 3 loc))
1831 ;; There may be no timestamp info if the loc is a `fake-loc'.
1832 ;; So we skip the time-check here, although we should maybe
1833 ;; change `compilation-fake-loc' to add timestamp info.
1834 (or (null (nth 4 loc))
1837 (with-current-buffer
1838 (marker-buffer (nth 3 loc))
1839 (visited-file-modtime))))))
1840 (with-current-buffer (compilation-find-file marker (caar (nth 2 loc))
1841 (cadr (car (nth 2 loc))))
1844 (goto-char (point-min))
1845 ;; Treat file's found lines in forward order, 1 by 1.
1846 (dolist (line (reverse (cddr (nth 2 loc))))
1847 (when (car line) ; else this is a filename w/o a line#
1848 (beginning-of-line (- (car line) last -1))
1849 (setq last (car line)))
1850 ;; Treat line's found columns and store/update a marker for each.
1851 (dolist (col (cdr line))
1853 (if (eq (car col) -1) ; special case for range end
1855 (compilation-move-to-column (car col) columns))
1857 (skip-chars-forward " \t"))
1859 (set-marker (nth 3 col) (point))
1860 (setcdr (nthcdr 2 col) `(,(point-marker)))))))))
1861 (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc))
1862 (setcdr (nthcdr 3 loc) (list timestamp))
1863 (setcdr (nthcdr 4 loc) t))) ; Set this one as visited.
1865 (defvar compilation-gcpro nil
1866 "Internal variable used to keep some values from being GC'd.")
1867 (make-variable-buffer-local 'compilation-gcpro)
1869 (defun compilation-fake-loc (marker file &optional line col)
1870 "Preassociate MARKER with FILE.
1871 FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
1872 This is useful when you compile temporary files, but want
1873 automatic translation of the messages to the real buffer from
1874 which the temporary file came. This only works if done before a
1875 message about FILE appears!
1877 Optional args LINE and COL default to 1 and beginning of
1878 indentation respectively. The marker is expected to reflect
1879 this. In the simplest case the marker points to the first line
1880 of the region that was saved to the temp file.
1882 If you concatenate several regions into the temp file (e.g. a
1883 header with variable assignments and a code region), you must
1884 call this several times, once each for the last line of one
1885 region and the first line of the next region."
1886 (or (consp file) (setq file (list file)))
1887 (setq file (compilation-get-file-structure file))
1888 ;; Between the current call to compilation-fake-loc and the first occurrence
1889 ;; of an error message referring to `file', the data is only kept in the
1890 ;; weak hash-table compilation-locs, so we need to prevent this entry
1891 ;; in compilation-locs from being GC'd away. --Stef
1892 (push file compilation-gcpro)
1893 (let ((loc (compilation-assq (or line 1) (cdr file))))
1894 (setq loc (compilation-assq col loc))
1896 (setcdr (cddr loc) (list marker))
1897 (setcdr loc (list line file marker)))
1900 (defcustom compilation-context-lines nil
1901 "Display this many lines of leading context before the current message.
1902 If nil and the left fringe is displayed, don't scroll the
1903 compilation output window; an arrow in the left fringe points to
1904 the current message. If nil and there is no left fringe, the message
1905 displays at the top of the window; there is no arrow."
1906 :type '(choice integer (const :tag "No window scrolling" nil))
1910 (defsubst compilation-set-window (w mk)
1911 "Align the compilation output window W with marker MK near top."
1912 (if (integerp compilation-context-lines)
1913 (set-window-start w (save-excursion
1916 (- 1 compilation-context-lines))
1918 ;; If there is no left fringe.
1919 (if (equal (car (window-fringes)) 0)
1920 (set-window-start w (save-excursion
1922 (beginning-of-line 1)
1924 (set-window-point w mk))
1926 (defvar next-error-highlight-timer)
1928 (defun compilation-goto-locus (msg mk end-mk)
1929 "Jump to an error corresponding to MSG at MK.
1930 All arguments are markers. If END-MK is non-nil, mark is set there
1931 and overlay is highlighted between MK and END-MK."
1932 ;; Show compilation buffer in other window, scrolled to this error.
1933 (let* ((from-compilation-buffer (eq (window-buffer (selected-window))
1934 (marker-buffer msg)))
1935 ;; Use an existing window if it is in a visible frame.
1936 (pre-existing (get-buffer-window (marker-buffer msg) 0))
1937 (w (if (and from-compilation-buffer pre-existing)
1938 ;; Calling display-buffer here may end up (partly) hiding
1939 ;; the error location if the two buffers are in two
1940 ;; different frames. So don't do it if it's not necessary.
1942 (let ((display-buffer-reuse-frames t)
1945 (display-buffer (marker-buffer msg)))))
1946 (highlight-regexp (with-current-buffer (marker-buffer msg)
1947 ;; also do this while we change buffer
1948 (compilation-set-window w msg)
1949 compilation-highlight-regexp)))
1950 ;; Ideally, the window-size should be passed to `display-buffer' (via
1951 ;; something like special-display-buffer) so it's only used when
1952 ;; creating a new window.
1953 (unless pre-existing (compilation-set-window-height w))
1955 (if from-compilation-buffer
1956 ;; If the compilation buffer window was selected,
1957 ;; keep the compilation buffer in this window;
1958 ;; display the source in another window.
1959 (let ((pop-up-windows t))
1960 (pop-to-buffer (marker-buffer mk) 'other-window))
1961 (if (window-dedicated-p (selected-window))
1962 (pop-to-buffer (marker-buffer mk))
1963 (switch-to-buffer (marker-buffer mk))))
1964 ;; If narrowing gets in the way of going to the right place, widen.
1965 (unless (eq (goto-char mk) (point))
1969 (push-mark end-mk t)
1970 (if mark-active (setq mark-active)))
1971 ;; If hideshow got in the way of
1972 ;; seeing the right place, open permanently.
1973 (dolist (ov (overlays-at (point)))
1974 (when (eq 'hs (overlay-get ov 'invisible))
1978 (when highlight-regexp
1979 (if (timerp next-error-highlight-timer)
1980 (cancel-timer next-error-highlight-timer))
1981 (unless compilation-highlight-overlay
1982 (setq compilation-highlight-overlay
1983 (make-overlay (point-min) (point-min)))
1984 (overlay-put compilation-highlight-overlay 'face 'next-error))
1985 (with-current-buffer (marker-buffer mk)
1987 (if end-mk (goto-char end-mk) (end-of-line))
1988 (let ((end (point)))
1989 (if mk (goto-char mk) (beginning-of-line))
1990 (if (and (stringp highlight-regexp)
1991 (re-search-forward highlight-regexp end t))
1993 (goto-char (match-beginning 0))
1994 (move-overlay compilation-highlight-overlay
1995 (match-beginning 0) (match-end 0)
1997 (move-overlay compilation-highlight-overlay
1998 (point) end (current-buffer)))
1999 (if (or (eq next-error-highlight t)
2000 (numberp next-error-highlight))
2001 ;; We want highlighting: delete overlay on next input.
2002 (add-hook 'pre-command-hook
2003 'compilation-goto-locus-delete-o)
2004 ;; We don't want highlighting: delete overlay now.
2005 (delete-overlay compilation-highlight-overlay))
2006 ;; We want highlighting for a limited time:
2007 ;; set up a timer to delete it.
2008 (when (numberp next-error-highlight)
2009 (setq next-error-highlight-timer
2010 (run-at-time next-error-highlight nil
2011 'compilation-goto-locus-delete-o)))))))
2012 (when (and (eq next-error-highlight 'fringe-arrow))
2013 ;; We want a fringe arrow (instead of highlighting).
2014 (setq next-error-overlay-arrow-position
2015 (copy-marker (line-beginning-position))))))
2017 (defun compilation-goto-locus-delete-o ()
2018 (delete-overlay compilation-highlight-overlay)
2019 ;; Get rid of timer and hook that would try to do this again.
2020 (if (timerp next-error-highlight-timer)
2021 (cancel-timer next-error-highlight-timer))
2022 (remove-hook 'pre-command-hook
2023 'compilation-goto-locus-delete-o))
2025 (defun compilation-find-file (marker filename directory &rest formats)
2026 "Find a buffer for file FILENAME.
2027 If FILENAME is not found at all, ask the user where to find it.
2028 Pop up the buffer containing MARKER and scroll to MARKER if we ask
2029 the user where to find the file.
2030 Search the directories in `compilation-search-path'.
2031 A nil in `compilation-search-path' means to try the
2032 \"current\" directory, which is passed in DIRECTORY.
2033 If DIRECTORY is relative, it is combined with `default-directory'.
2034 If DIRECTORY is nil, that means use `default-directory'.
2035 FORMATS, if given, is a list of formats to reformat FILENAME when
2036 looking for it: for each element FMT in FORMATS, this function
2037 attempts to find a file whose name is produced by (format FMT FILENAME)."
2038 (or formats (setq formats '("%s")))
2039 (let ((dirs compilation-search-path)
2040 (spec-dir (if directory
2041 (expand-file-name directory)
2043 buffer thisdir fmts name)
2044 (if (file-name-absolute-p filename)
2045 ;; The file name is absolute. Use its explicit directory as
2046 ;; the first in the search path, and strip it from FILENAME.
2047 (setq filename (abbreviate-file-name (expand-file-name filename))
2048 dirs (cons (file-name-directory filename) dirs)
2049 filename (file-name-nondirectory filename)))
2050 ;; Now search the path.
2051 (while (and dirs (null buffer))
2052 (setq thisdir (or (car dirs) spec-dir)
2054 ;; For each directory, try each format string.
2055 (while (and fmts (null buffer))
2056 (setq name (expand-file-name (format (car fmts) filename) thisdir)
2057 buffer (and (file-exists-p name)
2058 (find-file-noselect name))
2060 (setq dirs (cdr dirs)))
2061 (while (null buffer) ;Repeat until the user selects an existing file.
2062 ;; The file doesn't exist. Ask the user where to find it.
2063 (save-excursion ;This save-excursion is probably not right.
2064 (let ((pop-up-windows t))
2065 (compilation-set-window (display-buffer (marker-buffer marker))
2067 (let* ((name (read-file-name
2068 (format "Find this %s in (default %s): "
2069 compilation-error filename)
2070 spec-dir filename t nil
2071 ;; The predicate below is fine when called from
2072 ;; minibuffer-complete-and-exit, but it's too
2073 ;; restrictive otherwise, since it also prevents the
2074 ;; user from completing "fo" to "foo/" when she
2075 ;; wants to enter "foo/bar".
2077 ;; Try to make sure the user can only select
2078 ;; a valid answer. This predicate may be ignored,
2079 ;; tho, so we still have to double-check afterwards.
2080 ;; TODO: We should probably fix read-file-name so
2081 ;; that it never ignores this predicate, even when
2082 ;; using popup dialog boxes.
2084 ;; (if (file-directory-p name)
2085 ;; (setq name (expand-file-name filename name)))
2086 ;; (file-exists-p name))
2090 ((not (file-exists-p name))
2091 (message "Cannot find file `%s'" name)
2093 ((and (file-directory-p name)
2095 (setq name (expand-file-name filename name)))))
2096 (message "No `%s' in directory %s" filename origname)
2099 (setq buffer (find-file-noselect name))))))))
2100 ;; Make intangible overlays tangible.
2101 ;; This is weird: it's not even clear which is the current buffer,
2102 ;; so the code below can't be expected to DTRT here. -- Stef
2103 (dolist (ov (overlays-in (point-min) (point-max)))
2104 (when (overlay-get ov 'intangible)
2105 (overlay-put ov 'intangible nil)))
2108 (defun compilation-get-file-structure (file &optional fmt)
2109 "Retrieve FILE's file-structure or create a new one.
2110 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
2111 In the former case, FILENAME may be relative or absolute.
2113 The file-structure looks like this:
2114 (list (list FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)"
2115 (or (gethash file compilation-locs)
2116 ;; File was not previously encountered, at least not in the form passed.
2117 ;; Let's normalize it and look again.
2118 (let ((filename (car file))
2119 ;; Get the specified directory from FILE.
2120 (spec-directory (if (cdr file)
2121 (file-truename (cdr file)))))
2123 ;; Check for a comint-file-name-prefix and prepend it if appropriate.
2124 ;; (This is very useful for compilation-minor-mode in an rlogin-mode
2126 (when (and (boundp 'comint-file-name-prefix)
2127 (not (equal comint-file-name-prefix "")))
2128 (if (file-name-absolute-p filename)
2130 (concat comint-file-name-prefix filename))
2132 (setq spec-directory
2134 (concat comint-file-name-prefix spec-directory))))))
2136 ;; If compilation-parse-errors-filename-function is
2137 ;; defined, use it to process the filename.
2138 (when compilation-parse-errors-filename-function
2140 (funcall compilation-parse-errors-filename-function
2143 ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
2144 ;; file names like "./bar//foo.c" for file "bar/foo.c";
2145 ;; expand-file-name will collapse these into "/foo.c" and fail to find
2146 ;; the appropriate file. So we look for doubled slashes in the file
2147 ;; name and fix them.
2148 (setq filename (command-line-normalize-file-name filename))
2150 ;; Store it for the possibly unnormalized name
2152 ;; Retrieve or create file-structure for normalized name
2153 ;; The gethash used to not use spec-directory, but
2154 ;; this leads to errors when files in different
2155 ;; directories have the same name:
2156 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00463.html
2157 (or (gethash (cons filename spec-directory) compilation-locs)
2158 (puthash (cons filename spec-directory)
2159 (list (list filename spec-directory) fmt)
2161 compilation-locs))))
2163 (add-to-list 'debug-ignored-errors "^No more [-a-z ]+s yet$")
2165 ;;; Compatibility with the old compile.el.
2167 (defun compile-buffer-substring (n) (if n (match-string n)))
2169 (defun compilation-compat-error-properties (err)
2170 "Map old-style error ERR to new-style message."
2171 ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
2172 ;; (MARKER . MARKER).
2173 (let ((dst (cdr err)))
2175 ;; Must start with a face, for font-lock.
2177 message ,(list (list nil nil nil dst) 2)
2178 help-echo "mouse-2: visit the source location"
2179 keymap compilation-button-map
2180 mouse-face highlight)
2181 ;; Too difficult to do it by hand: dispatch to the normal code.
2182 (let* ((file (pop dst))
2185 (filename (pop file))
2186 (dirname (pop file))
2188 (compilation-internal-error-properties
2189 (cons filename dirname) line nil col nil 2 fmt)))))
2191 (defun compilation-compat-parse-errors (limit)
2192 (when compilation-parse-errors-function
2193 ;; FIXME: We should remove the rest of the compilation keywords
2194 ;; but we can't do that from here because font-lock is using
2195 ;; the value right now. --stef
2197 (setq compilation-error-list nil)
2198 ;; Reset compilation-parsing-end each time because font-lock
2199 ;; might force us the re-parse many times (typically because
2200 ;; some code adds some text-property to the output that we
2201 ;; already parsed). You might say "why reparse", well:
2202 ;; because font-lock has just removed the `message' property so
2203 ;; have to do it all over again.
2204 (if compilation-parsing-end
2205 (set-marker compilation-parsing-end (point))
2206 (setq compilation-parsing-end (point-marker)))
2208 ;; Ignore any error: we're calling this function earlier than
2209 ;; in the old compile.el so things might not all be setup yet.
2210 (funcall compilation-parse-errors-function limit nil)
2212 (dolist (err (if (listp compilation-error-list) compilation-error-list))
2213 (let* ((src (car err))
2215 (loc (cond ((markerp dst) (list nil nil nil dst))
2217 (list (nth 2 dst) (nth 1 dst)
2218 (cons (cdar dst) (caar dst)))))))
2221 ;; (put-text-property src (line-end-position) 'font-lock-face 'font-lock-warning-face)
2222 (put-text-property src (line-end-position)
2223 'message (list loc 2)))))))
2227 ;; Beware: this is not only compatiblity code. New code stil uses it. --Stef
2228 (defun compilation-forget-errors ()
2229 ;; In case we hit the same file/line specs, we want to recompute a new
2230 ;; marker for them, so flush our cache.
2231 (setq compilation-locs (make-hash-table :test 'equal :weakness 'value))
2232 (setq compilation-gcpro nil)
2233 ;; FIXME: the old code reset the directory-stack, so maybe we should
2234 ;; put a `directory change' marker of some sort, but where? -stef
2236 ;; FIXME: The old code moved compilation-current-error (which was
2237 ;; virtually represented by a mix of compilation-parsing-end and
2238 ;; compilation-error-list) to point-min, but that was only meaningful for
2239 ;; the internal uses of compilation-forget-errors: all calls from external
2240 ;; packages seem to be followed by a move of compilation-parsing-end to
2241 ;; something equivalent to point-max. So we heuristically move
2242 ;; compilation-current-error to point-max (since the external package
2243 ;; won't know that it should do it). --Stef
2244 (setq compilation-current-error nil)
2245 (let* ((proc (get-buffer-process (current-buffer)))
2246 (mark (if proc (process-mark proc)))
2247 (pos (or mark (point-max))))
2248 (setq compilation-messages-start
2249 ;; In the future, ignore the text already present in the buffer.
2250 ;; Since many process filter functions insert before markers,
2251 ;; we need to put ours just before the insertion point rather
2252 ;; than at the insertion point. If that's not possible, then
2253 ;; don't use a marker. --Stef
2254 (if (> pos (point-min)) (copy-marker (1- pos)) pos)))
2255 ;; Again, since this command is used in buffers that contain several
2256 ;; compilations, to set the beginning of "this compilation", it's a good
2257 ;; place to reset compilation-auto-jump-to-next.
2258 (set (make-local-variable 'compilation-auto-jump-to-next)
2259 (or compilation-auto-jump-to-first-error
2260 (eq compilation-scroll-output 'first-error))))
2263 (add-to-list 'auto-mode-alist '("\\.gcov\\'" . compilation-mode))
2267 ;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c
2268 ;;; compile.el ends here