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
240 "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\)?\
241 \\([0-9]*[^0-9\n]\\(?:[^\n ]\\| [^-\n]\\)*?\\): ?\
242 \\([0-9]+\\)\\(?:\\([.:]\\)\\([0-9]+\\)\\)?\
243 \\(?:-\\([0-9]+\\)?\\(?:\\3\\([0-9]+\\)\\)?\\)?:\
244 \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\
245 *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\|[Nn]ote\\)\\|\
246 \[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)"
247 1 (2 . 5) (4 . 6) (7 . 8))
249 ;; The `gnu' style above can incorrectly match gcc's "In file
250 ;; included from" message, so we process that first. -- cyd
252 "^\\(?:In file included\\| \\) from \
253 \\(.+\\):\\([0-9]+\\)\\(?:\\(:\\)\\|\\(,\\)\\)?" 1 2 nil (3 . 4))
256 "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)"
260 "^makepp\\(?:\\(?:: warning\\(:\\).*?\\|\\(: Scanning\\|: [LR]e?l?oading makefile\\|: Imported\\|log:.*?\\) \\|: .*?\\)\
261 `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)"
263 ("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]" nil nil
264 (2 compilation-info-face)
265 (3 compilation-line-face nil t)
266 (1 (compilation-error-properties 2 3 nil nil nil 0 nil)
269 ;; Should be lint-1, lint-2 (SysV lint)
271 " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
273 " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2)
276 ;; AFAWK, The message may be a "warning", "error", or "fatal error".
277 "^\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
278 : \\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:" 2 3 nil (4))
281 "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
282 \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
283 \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
286 ;; "during global destruction": This comes out under "use
287 ;; warnings" in recent perl when breaking circular references
288 ;; during program or thread exit.
290 " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \
291 during global destruction\\.$\\)" 1 2)
294 "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
298 "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
299 \\([0-9]+\\) of file://\\(.+\\)"
303 "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
304 [12][09][0-9][0-9] +\\(.*\\):$"
307 "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
308 nil 3 nil (2) nil (1 (compilation-face '(2))))
309 (sparc-pascal-example
310 "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
311 nil 1 nil (3) nil (2 (compilation-face '(3))))
314 ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
315 File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
319 "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
322 "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
323 \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3))
326 "^ *-: *\\(0\\):Source:\\(.+\\)$"
328 (1 compilation-line-face prepend) (2 compilation-info-face prepend))
330 "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
332 (1 compilation-line-face prepend))
333 ;; Underlines over all lines of gcov output are too uncomfortable to read.
334 ;; However, hyperlinks embedded in the lines are useful.
335 ;; So I put default face on the lines; and then put
336 ;; compilation-*-face by manually to eliminate the underlines.
337 ;; The hyperlinks are still effective.
339 "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
342 (1 compilation-line-face prepend))
344 "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
347 (1 compilation-info-face prepend) (2 compilation-line-face prepend))
349 "^ *\\(#####\\): *\\([0-9]+\\):.*$"
352 (1 compilation-error-face prepend) (2 compilation-line-face prepend))
355 ;; podchecker error messages, per Pod::Checker.
356 ;; The style is from the Pod::Checker::poderror() function, eg.
357 ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm
359 ;; Plus end_pod() can give "at line EOF" instead of a
360 ;; number, so for that match "on line N" which is the
361 ;; originating spot, eg.
362 ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm
364 ;; Plus command() can give both "on line N" and "at line N";
365 ;; the latter is desired and is matched because the .* is
367 ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod
369 "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \
370 \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)"
373 ;; perl Test module error messages.
374 ;; Style per the ok() function "$context", eg.
375 ;; # Failed test 1 in foo.t at line 6
377 "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
380 ;; Or when comparing got/want values,
381 ;; # Test 2 got: "xx" (t-compilation-perl-2.t at line 10)
383 ;; And under Test::Harness they're preceded by progress stuff with
385 ;; ... NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
387 "^\\(.*NOK.*\\)?# Test [0-9]+ got:.* (\\([^ \t\r\n]+\\) at line \
391 ;; perl Test::Harness output, eg.
392 ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
394 ;; Test::Harness is slightly designed for tty output, since
395 ;; it prints CRs to overwrite progress messages, but if you
396 ;; run it in with M-x compile this pattern can at least step
397 ;; through the failures.
399 "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
402 ;; The style comes from HTML::Lint::Error::as_string(), eg.
403 ;; index.html (13:1) Unknown element <fdjsk>
405 ;; The pattern only matches filenames without spaces, since that
406 ;; should be usual and should help reduce the chance of a false
407 ;; match of a message from some unrelated program.
409 ;; This message style is quite close to the "ibm" entry which is
410 ;; for IBM C, though that ibm bit doesn't put a space after the
413 "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) "
416 "Alist of values for `compilation-error-regexp-alist'.")
418 (defcustom compilation-error-regexp-alist
419 (mapcar 'car compilation-error-regexp-alist-alist)
420 "Alist that specifies how to match errors in compiler output.
421 On GNU and Unix, any string is a valid filename, so these
422 matchers must make some common sense assumptions, which catch
423 normal cases. A shorter list will be lighter on resource usage.
425 Instead of an alist element, you can use a symbol, which is
426 looked up in `compilation-error-regexp-alist-alist'. You can see
427 the predefined symbols and their effects in the file
428 `etc/compilation.txt' (linked below if you are customizing this).
430 Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
431 HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
432 gives the file name, and the LINE'th subexpression gives the line
433 number. The COLUMN'th subexpression gives the column number on
436 If FILE, LINE or COLUMN are nil or that index didn't match, that
437 information is not present on the matched line. In that case the
438 file name is assumed to be the same as the previous one in the
439 buffer, line number defaults to 1 and column defaults to
440 beginning of line's indentation.
442 FILE can also have the form (FILE FORMAT...), where the FORMATs
443 \(e.g. \"%s.c\") will be applied in turn to the recognized file
444 name, until a file of that name is found. Or FILE can also be a
445 function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
446 In the former case, FILENAME may be relative or absolute.
448 LINE can also be of the form (LINE . END-LINE) meaning a range
449 of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
450 meaning a range of columns starting on LINE and ending on
451 END-LINE, if that matched.
453 TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
454 TYPE can also be of the form (WARNING . INFO). In that case this
455 will be equivalent to 1 if the WARNING'th subexpression matched
456 or else equivalent to 0 if the INFO'th subexpression matched.
457 See `compilation-error-face', `compilation-warning-face',
458 `compilation-info-face' and `compilation-skip-threshold'.
460 What matched the HYPERLINK'th subexpression has `mouse-face' and
461 `compilation-message-face' applied. If this is nil, the text
462 matched by the whole REGEXP becomes the hyperlink.
464 Additional HIGHLIGHTs as described under `font-lock-keywords' can
466 :type `(set :menu-tag "Pick"
467 ,@(mapcar (lambda (elt)
468 (list 'const (car elt)))
469 compilation-error-regexp-alist-alist))
470 :link `(file-link :tag "example file"
471 ,(expand-file-name "compilation.txt" data-directory))
474 ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp)
475 (defvar compilation-directory nil
476 "Directory to restore to when doing `recompile'.")
478 (defvar compilation-directory-matcher
479 '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1))
480 "A list for tracking when directories are entered or left.
481 If nil, do not track directories, e.g. if all file names are absolute. The
482 first element is the REGEXP matching these messages. It can match any number
483 of variants, e.g. different languages. The remaining elements are all of the
484 form (DIR . LEAVE). If for any one of these the DIR'th subexpression
485 matches, that is a directory name. If LEAVE is nil or the corresponding
486 LEAVE'th subexpression doesn't match, this message is about going into another
487 directory. If it does match anything, this message is about going back to the
488 directory we were in before the last entering message. If you change this,
489 you may also want to change `compilation-page-delimiter'.")
491 (defvar compilation-page-delimiter
492 "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
493 "Value of `page-delimiter' in Compilation mode.")
495 (defvar compilation-mode-font-lock-keywords
496 '(;; configure output lines.
497 ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
498 (1 font-lock-variable-name-face)
499 (2 (compilation-face '(4 . 3))))
500 ;; Command output lines. Recognize `make[n]:' lines too.
501 ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
502 (1 font-lock-function-name-face) (3 compilation-line-face nil t))
503 (" --?o\\(?:utfile\\|utput\\)?[= ]?\\(\\S +\\)" . 1)
504 ("^Compilation \\(finished\\).*"
505 (0 '(face nil message nil help-echo nil mouse-face nil) t)
506 (1 compilation-info-face))
507 ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
508 (0 '(face nil message nil help-echo nil mouse-face nil) t)
509 (1 compilation-error-face)
510 (2 compilation-error-face nil t)))
511 "Additional things to highlight in Compilation mode.
512 This gets tacked on the end of the generated expressions.")
514 (defvar compilation-highlight-regexp t
515 "Regexp matching part of visited source lines to highlight temporarily.
516 Highlight entire line if t; don't highlight source lines if nil.")
518 (defvar compilation-highlight-overlay nil
519 "Overlay used to temporarily highlight compilation matches.")
521 (defcustom compilation-error-screen-columns t
522 "If non-nil, column numbers in error messages are screen columns.
523 Otherwise they are interpreted as character positions, with
524 each character occupying one column.
525 The default is to use screen columns, which requires that the compilation
526 program and Emacs agree about the display width of the characters,
527 especially the TAB character."
532 (defcustom compilation-read-command t
533 "Non-nil means \\[compile] reads the compilation command to use.
534 Otherwise, \\[compile] just uses the value of `compile-command'."
539 (defcustom compilation-ask-about-save t
540 "Non-nil means \\[compile] asks which buffers to save before compiling.
541 Otherwise, it saves all modified buffers without asking."
546 (defcustom compilation-search-path '(nil)
547 "List of directories to search for source files named in error messages.
548 Elements should be directory names, not file names of directories.
549 The value nil as an element means to try the default directory."
550 :type '(repeat (choice (const :tag "Default" nil)
551 (string :tag "Directory")))
555 (defcustom compile-command "make -k "
556 "Last shell command used to do a compilation; default for next compilation.
558 Sometimes it is useful for files to supply local values for this variable.
559 You might also use mode hooks to specify it in certain modes, like this:
561 (add-hook 'c-mode-hook
563 (unless (or (file-exists-p \"makefile\")
564 (file-exists-p \"Makefile\"))
565 (set (make-local-variable 'compile-command)
567 (file-name-sans-extension buffer-file-name))))))"
570 ;;;###autoload(put 'compile-command 'safe-local-variable 'stringp)
573 (defcustom compilation-disable-input nil
574 "If non-nil, send end-of-file as compilation process input.
575 This only affects platforms that support asynchronous processes (see
576 `start-process'); synchronous compilation processes never accept input."
581 ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
582 ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
583 ;; key. This holds the tree seen from root, for storing new nodes.
584 (defvar compilation-locs ())
586 (defvar compilation-debug nil
587 "*Set this to t before creating a *compilation* buffer.
588 Then every error line will have a debug text property with the matcher that
589 fit this line and the match data. Use `describe-text-properties'.")
591 (defvar compilation-exit-message-function nil "\
592 If non-nil, called when a compilation process dies to return a status message.
593 This should be a function of three arguments: process status, exit status,
594 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
595 write into the compilation buffer, and to put in its mode line.")
597 (defvar compilation-environment nil
598 "*List of environment variables for compilation to inherit.
599 Each element should be a string of the form ENVVARNAME=VALUE.
600 This list is temporarily prepended to `process-environment' prior to
601 starting the compilation process.")
603 ;; History of compile commands.
604 (defvar compile-history nil)
606 (defface compilation-error
607 '((t :inherit font-lock-warning-face))
608 "Face used to highlight compiler errors."
612 (defface compilation-warning
613 '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
614 (((class color)) (:foreground "cyan" :weight bold))
616 "Face used to highlight compiler warnings."
620 (defface compilation-info
621 '((((class color) (min-colors 16) (background light))
622 (:foreground "Green3" :weight bold))
623 (((class color) (min-colors 88) (background dark))
624 (:foreground "Green1" :weight bold))
625 (((class color) (min-colors 16) (background dark))
626 (:foreground "Green" :weight bold))
627 (((class color)) (:foreground "green" :weight bold))
629 "Face used to highlight compiler information."
633 (defface compilation-line-number
634 '((t :inherit font-lock-variable-name-face))
635 "Face for displaying line numbers in compiler messages."
639 (defface compilation-column-number
640 '((t :inherit font-lock-type-face))
641 "Face for displaying column numbers in compiler messages."
645 (defcustom compilation-message-face 'underline
646 "Face name to use for whole messages.
647 Faces `compilation-error-face', `compilation-warning-face',
648 `compilation-info-face', `compilation-line-face' and
649 `compilation-column-face' get prepended to this, when applicable."
654 (defvar compilation-error-face 'compilation-error
655 "Face name to use for file name in error messages.")
657 (defvar compilation-warning-face 'compilation-warning
658 "Face name to use for file name in warning messages.")
660 (defvar compilation-info-face 'compilation-info
661 "Face name to use for file name in informational messages.")
663 (defvar compilation-line-face 'compilation-line-number
664 "Face name to use for line numbers in compiler messages.")
666 (defvar compilation-column-face 'compilation-column-number
667 "Face name to use for column numbers in compiler messages.")
669 ;; same faces as dired uses
670 (defvar compilation-enter-directory-face 'font-lock-function-name-face
671 "Face name to use for entering directory messages.")
673 (defvar compilation-leave-directory-face 'font-lock-type-face
674 "Face name to use for leaving directory messages.")
678 ;; Used for compatibility with the old compile.el.
679 (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
680 (defvar compilation-parsing-end (make-marker))
681 (defvar compilation-parse-errors-function nil)
682 (defvar compilation-error-list nil)
683 (defvar compilation-old-error-list nil)
685 (defcustom compilation-auto-jump-to-first-error nil
686 "If non-nil, automatically jump to the first error after `compile'."
691 (defvar compilation-auto-jump-to-next nil
692 "If non-nil, automatically jump to the next error encountered.")
693 (make-variable-buffer-local 'compilation-auto-jump-to-next)
696 (defvar compilation-skip-to-next-location t
697 "*If non-nil, skip multiple error messages for the same source location.")
699 (defcustom compilation-skip-threshold 1
700 "Compilation motion commands skip less important messages.
701 The value can be either 2 -- skip anything less than error, 1 --
702 skip anything less than warning or 0 -- don't skip any messages.
703 Note that all messages not positively identified as warning or
704 info, are considered errors."
705 :type '(choice (const :tag "Warnings and info" 2)
706 (const :tag "Info" 1)
707 (const :tag "None" 0))
711 (defcustom compilation-skip-visited nil
712 "Compilation motion commands skip visited messages if this is t.
713 Visited messages are ones for which the file, line and column have been jumped
714 to from the current content in the current compilation buffer, even if it was
715 from a different message."
720 (defun compilation-face (type)
721 (or (and (car type) (match-end (car type)) compilation-warning-face)
722 (and (cdr type) (match-end (cdr type)) compilation-info-face)
723 compilation-error-face))
725 ;; Internal function for calculating the text properties of a directory
726 ;; change message. The directory property is important, because it is
727 ;; the stack of nested enter-messages. Relative filenames on the following
728 ;; lines are relative to the top of the stack.
729 (defun compilation-directory-properties (idx leave)
730 (if leave (setq leave (match-end leave)))
731 ;; find previous stack, and push onto it, or if `leave' pop it
732 (let ((dir (previous-single-property-change (point) 'directory)))
733 (setq dir (if dir (or (get-text-property (1- dir) 'directory)
734 (get-text-property dir 'directory))))
736 compilation-leave-directory-face
737 compilation-enter-directory-face)
740 '(nil)) ; nil only isn't a property-change
741 (cons (match-string-no-properties idx) dir))
743 keymap compilation-button-map
744 help-echo "mouse-2: visit destination directory")))
746 ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
747 ;; KEY element from the ALIST, creating it in the right position if not already
748 ;; present. ALIST structure is
749 ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
750 ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
751 ;; may be nil. The other KEYs are ordered backwards so that growing line
752 ;; numbers can be inserted in front and searching can abort after half the
754 (eval-when-compile ;Don't keep it at runtime if not needed.
755 (defmacro compilation-assq (key alist)
758 (car (if (if (null ,key)
759 (if l2 (null (caar l2)))
760 (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
763 (if l2 (eq ,key (caar l2))))
765 (setcdr l1 (cons (list ,key) l2)))))))
767 (defun compilation-auto-jump (buffer pos)
768 (with-current-buffer buffer
770 (if compilation-auto-jump-to-first-error
771 (compile-goto-error))))
773 ;; This function is the central driver, called when font-locking to gather
774 ;; all information needed to later jump to corresponding source code.
775 ;; Return a property list with all meta information on this error location.
777 (defun compilation-error-properties (file line end-line col end-col type fmt)
778 (unless (< (next-single-property-change (match-beginning 0)
779 'directory nil (point))
783 (setq file (funcall file))
785 (setq file (match-string-no-properties file))
786 (unless (file-name-absolute-p file)
787 (setq dir (previous-single-property-change (point) 'directory)
788 dir (if dir (or (get-text-property (1- dir) 'directory)
789 (get-text-property dir 'directory)))))
790 (setq file (cons file (car dir)))))
791 ;; This message didn't mention one, get it from previous
793 ;; Find the previous message.
794 (previous-single-property-change (point) 'message)))
796 ;; Get the file structure that belongs to it.
798 (or (get-text-property (1- prev-pos) 'message)
799 (get-text-property prev-pos 'message)))
801 (car (nth 2 (car prev)))))
802 ;; Construct FILE . DIR from that.
804 (setq file (cons (car prev-struct)
805 (cadr prev-struct))))))
807 (setq file '("*unknown*")))))
808 ;; All of these fields are optional, get them only if we have an index, and
809 ;; it matched some part of the message.
811 (setq line (match-string-no-properties line))
812 (setq line (string-to-number line)))
814 (setq end-line (match-string-no-properties end-line))
815 (setq end-line (string-to-number end-line)))
818 (setq col (funcall col))
820 (setq col (match-string-no-properties col))
821 (setq col (- (string-to-number col) compilation-first-column)))))
822 (if (and end-col (functionp end-col))
823 (setq end-col (funcall end-col))
824 (if (and end-col (setq end-col (match-string-no-properties end-col)))
825 (setq end-col (- (string-to-number end-col) compilation-first-column -1))
826 (if end-line (setq end-col -1))))
827 (if (consp type) ; not a static type, check what it is.
828 (setq type (or (and (car type) (match-end (car type)) 1)
829 (and (cdr type) (match-end (cdr type)) 0)
832 (when (and compilation-auto-jump-to-next
833 (>= type compilation-skip-threshold))
834 (kill-local-variable 'compilation-auto-jump-to-next)
835 (run-with-timer 0 nil 'compilation-auto-jump
836 (current-buffer) (match-beginning 0)))
838 (compilation-internal-error-properties file line end-line col end-col type fmt)))
840 (defun compilation-move-to-column (col screen)
841 "Go to column COL on the current line.
842 If SCREEN is non-nil, columns are screen columns, otherwise, they are
846 (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
848 (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
849 "Get the meta-info that will be added as text-properties.
850 LINE, END-LINE, COL, END-COL are integers or nil.
851 TYPE can be 0, 1, or 2, meaning error, warning, or just info.
852 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
853 FMTS is a list of format specs for transforming the file name.
854 (See `compilation-error-regexp-alist'.)"
855 (unless file (setq file '("*unknown*")))
856 (let* ((file-struct (compilation-get-file-structure file fmts))
857 ;; Get first already existing marker (if any has one, all have one).
858 ;; Do this first, as the compilation-assq`s may create new nodes.
859 (marker-line (car (cddr file-struct))) ; a line structure
860 (marker (nth 3 (cadr marker-line))) ; its marker
861 (compilation-error-screen-columns compilation-error-screen-columns)
862 end-marker loc end-loc)
863 (if (not (and marker (marker-buffer marker)))
864 (setq marker nil) ; no valid marker for this file
865 (setq loc (or line 1)) ; normalize no linenumber to line 1
866 (catch 'marker ; find nearest loc, at least one exists
867 (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines
868 (if (> (car x) loc) ; still bigger
870 (if (> (- (or (car marker-line) 1) loc)
871 (- loc (car x))) ; current line is nearer
872 (setq marker-line x))
874 (setq marker (nth 3 (cadr marker-line))
875 marker-line (or (car marker-line) 1))
876 (with-current-buffer (marker-buffer marker)
880 (goto-char (marker-position marker))
881 (when (or end-col end-line)
882 (beginning-of-line (- (or end-line line) marker-line -1))
883 (if (or (null end-col) (< end-col 0))
885 (compilation-move-to-column
886 end-col compilation-error-screen-columns))
887 (setq end-marker (list (point-marker))))
888 (beginning-of-line (if end-line
890 (- loc marker-line -1)))
892 (compilation-move-to-column
893 col compilation-error-screen-columns)
894 (forward-to-indentation 0))
895 (setq marker (list (point-marker)))))))
897 (setq loc (compilation-assq line (cdr file-struct)))
899 (setq end-loc (compilation-assq end-line (cdr file-struct))
900 end-loc (compilation-assq end-col end-loc))
901 (if end-col ; use same line element
902 (setq end-loc (compilation-assq end-col loc))))
903 (setq loc (compilation-assq col loc))
904 ;; If they are new, make the loc(s) reference the file they point to.
905 (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker)))
908 (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker))))
910 ;; Must start with face
911 `(face ,compilation-message-face
912 message (,loc ,type ,end-loc)
913 ,@(if compilation-debug
914 `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords)
917 "mouse-2: visit this file, line and column"
919 "mouse-2: visit this file and line"
920 "mouse-2: visit this file"))
921 keymap compilation-button-map
922 mouse-face highlight)))
924 (defun compilation-mode-font-lock-keywords ()
925 "Return expressions to highlight in Compilation mode."
926 (if compilation-parse-errors-function
927 ;; An old package! Try the compatibility code.
928 '((compilation-compat-parse-errors))
930 ;; make directory tracking
931 (if compilation-directory-matcher
932 `((,(car compilation-directory-matcher)
933 ,@(mapcar (lambda (elt)
935 (compilation-directory-properties
936 ,(car elt) ,(cdr elt))
938 (cdr compilation-directory-matcher)))))
940 ;; Compiler warning/error lines.
944 (setq item (cdr (assq item
945 compilation-error-regexp-alist-alist))))
946 (let ((file (nth 1 item))
950 end-line end-col fmt)
951 (if (consp file) (setq fmt (cdr file) file (car file)))
952 (if (consp line) (setq end-line (cdr line) line (car line)))
953 (if (consp col) (setq end-col (cdr col) col (car col)))
956 ;; The old compile.el had here an undocumented hook that
957 ;; allowed `line' to be a function that computed the actual
958 ;; error location. Let's do our best.
961 (compilation-compat-error-properties
962 (funcall ',line (cons (match-string ,file)
963 (cons default-directory
965 ,(if col `(match-string ,col))))))
966 (,file compilation-error-face t))
968 (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
969 (error "HYPERLINK should be an integer: %s" (nth 5 item)))
973 ,@(when (integerp file)
974 `((,file ,(if (consp type)
975 `(compilation-face ',type)
976 (aref [compilation-info-face
977 compilation-warning-face
978 compilation-error-face]
982 `((,line compilation-line-face nil t)))
984 `((,end-line compilation-line-face nil t)))
986 ,@(when (integerp col)
987 `((,col compilation-column-face nil t)))
988 ,@(when (integerp end-col)
989 `((,end-col compilation-column-face nil t)))
992 (,(or (nth 5 item) 0)
993 (compilation-error-properties ',file ,line ,end-line
994 ,col ,end-col ',(or type 2)
996 append))))) ; for compilation-message-face
997 compilation-error-regexp-alist)
999 compilation-mode-font-lock-keywords)))
1003 (defun compile (command &optional comint)
1004 "Compile the program including the current buffer. Default: run `make'.
1005 Runs COMMAND, a shell command, in a separate process asynchronously
1006 with output going to the buffer `*compilation*'.
1008 You can then use the command \\[next-error] to find the next error message
1009 and move to the source code that caused it.
1011 If optional second arg COMINT is t the buffer will be in Comint mode with
1012 `compilation-shell-minor-mode'.
1014 Interactively, prompts for the command if `compilation-read-command' is
1015 non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
1016 Additionally, with universal prefix arg, compilation buffer will be in
1017 comint mode, i.e. interactive.
1019 To run more than one compilation at once, start one then rename
1020 the \`*compilation*' buffer to some other name with
1021 \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
1022 It will create a new \`*compilation*' buffer.
1024 On most systems, termination of the main compilation process
1025 kills its subprocesses.
1027 The name used for the buffer is actually whatever is returned by
1028 the function in `compilation-buffer-name-function', so you can set that
1029 to a function that generates a unique name."
1032 (let ((command (eval compile-command)))
1033 (if (or compilation-read-command current-prefix-arg)
1034 (read-shell-command "Compile command: " command
1035 (if (equal (car compile-history) command)
1036 '(compile-history . 1)
1039 (consp current-prefix-arg)))
1040 (unless (equal command (eval compile-command))
1041 (setq compile-command command))
1042 (save-some-buffers (not compilation-ask-about-save) nil)
1043 (setq-default compilation-directory default-directory)
1044 (compilation-start command comint))
1046 ;; run compile with the default command line
1048 "Re-compile the program including the current buffer.
1049 If this is run in a Compilation mode buffer, re-use the arguments from the
1050 original use. Otherwise, recompile using `compile-command'."
1052 (save-some-buffers (not compilation-ask-about-save) nil)
1053 (let ((default-directory (or compilation-directory default-directory)))
1054 (apply 'compilation-start (or compilation-arguments
1055 `(,(eval compile-command))))))
1057 (defcustom compilation-scroll-output nil
1058 "Non-nil to scroll the *compilation* buffer window as output appears.
1060 Setting it causes the Compilation mode commands to put point at the
1061 end of their output window so that the end of the output is always
1062 visible rather than the beginning.
1064 The value `first-error' stops scrolling at the first error, and leaves
1065 point on its location in the *compilation* buffer."
1066 :type '(choice (const :tag "No scrolling" nil)
1067 (const :tag "Scroll compilation output" t)
1068 (const :tag "Stop scrolling at the first error" first-error))
1070 :group 'compilation)
1073 (defun compilation-buffer-name (mode-name mode-command name-function)
1074 "Return the name of a compilation buffer to use.
1075 If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
1076 to determine the buffer name.
1077 Likewise if `compilation-buffer-name-function' is non-nil.
1078 If current buffer has the major mode MODE-COMMAND,
1079 return the name of the current buffer, so that it gets reused.
1080 Otherwise, construct a buffer name from MODE-NAME."
1081 (cond (name-function
1082 (funcall name-function mode-name))
1083 (compilation-buffer-name-function
1084 (funcall compilation-buffer-name-function mode-name))
1085 ((eq mode-command major-mode)
1088 (concat "*" (downcase mode-name) "*"))))
1090 ;; This is a rough emulation of the old hack, until the transition to new
1091 ;; compile is complete.
1092 (defun compile-internal (command error-message
1093 &optional name-of-mode parser
1094 error-regexp-alist name-function
1095 enter-regexp-alist leave-regexp-alist
1096 file-regexp-alist nomessage-regexp-alist
1097 no-async highlight-regexp local-map)
1099 (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
1100 (let ((compilation-error-regexp-alist
1101 (append file-regexp-alist (or error-regexp-alist
1102 compilation-error-regexp-alist)))
1103 (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
1104 "\\1" error-message)))
1105 (compilation-start command nil name-function highlight-regexp)))
1106 (make-obsolete 'compile-internal 'compilation-start)
1109 (defun compilation-start (command &optional mode name-function highlight-regexp)
1110 "Run compilation command COMMAND (low level interface).
1111 If COMMAND starts with a cd command, that becomes the `default-directory'.
1112 The rest of the arguments are optional; for them, nil means use the default.
1114 MODE is the major mode to set in the compilation buffer. Mode
1115 may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
1117 If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
1118 to determine the buffer name. Otherwise, the default is to
1119 reuses the current buffer if it has the proper major mode,
1120 else use or create a buffer with name based on the major mode.
1122 If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
1123 the matching section of the visited source line; the default is to use the
1124 global value of `compilation-highlight-regexp'.
1126 Returns the compilation buffer created."
1127 (or mode (setq mode 'compilation-mode))
1128 (let* ((name-of-mode
1130 (prog1 "compilation" (require 'comint))
1131 (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
1132 (thisdir default-directory)
1134 (with-current-buffer
1137 (compilation-buffer-name name-of-mode mode name-function)))
1138 (let ((comp-proc (get-buffer-process (current-buffer))))
1140 (if (or (not (eq (process-status comp-proc) 'run))
1142 (format "A %s process is running; kill it? "
1146 (interrupt-process comp-proc)
1148 (delete-process comp-proc))
1150 (error "Cannot have two processes in `%s' at once"
1152 (buffer-disable-undo (current-buffer))
1153 ;; first transfer directory from where M-x compile was called
1154 (setq default-directory thisdir)
1155 ;; Remember the original dir, so we can use it when we recompile.
1156 ;; default-directory' can't be used reliably for that because it may be
1157 ;; affected by the special handling of "cd ...;".
1158 (set (make-local-variable 'compilation-directory) thisdir)
1159 ;; Make compilation buffer read-only. The filter can still write it.
1160 ;; Clear out the compilation buffer.
1161 (let ((inhibit-read-only t)
1162 (default-directory thisdir))
1163 ;; Then evaluate a cd command if any, but don't perform it yet, else
1164 ;; start-command would do it again through the shell: (cd "..") AND
1165 ;; sh -c "cd ..; make"
1166 (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command)
1168 (substitute-env-vars (match-string 1 command))
1172 ;; Select the desired mode.
1173 (if (not (eq mode t))
1175 (setq buffer-read-only nil)
1176 (with-no-warnings (comint-mode))
1177 (compilation-shell-minor-mode))
1178 (if highlight-regexp
1179 (set (make-local-variable 'compilation-highlight-regexp)
1181 (if (or compilation-auto-jump-to-first-error
1182 (eq compilation-scroll-output 'first-error))
1183 (set (make-local-variable 'compilation-auto-jump-to-next) t))
1184 ;; Output a mode setter, for saving and later reloading this buffer.
1185 (insert "-*- mode: " name-of-mode
1186 "; default-directory: " (prin1-to-string default-directory)
1188 (format "%s started at %s\n\n"
1190 (substring (current-time-string) 0 19))
1192 (setq thisdir default-directory))
1193 (set-buffer-modified-p nil))
1194 ;; Pop up the compilation buffer.
1195 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html
1196 (setq outwin (display-buffer outbuf))
1197 (with-current-buffer outbuf
1198 (let ((process-environment
1200 compilation-environment
1201 (if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning
1202 system-uses-terminfo)
1203 (list "TERM=dumb" "TERMCAP="
1204 (format "COLUMNS=%d" (window-width)))
1206 (format "TERMCAP=emacs:co#%d:tc=unknown:"
1208 ;; Set the EMACS variable, but
1209 ;; don't override users' setting of $EMACS.
1210 (unless (getenv "EMACS")
1212 (list "INSIDE_EMACS=t")
1213 (copy-sequence process-environment))))
1214 (set (make-local-variable 'compilation-arguments)
1215 (list command mode name-function highlight-regexp))
1216 (set (make-local-variable 'revert-buffer-function)
1217 'compilation-revert-buffer)
1218 (set-window-start outwin (point-min))
1220 ;; Position point as the user will see it.
1221 (let ((desired-visible-point
1222 ;; Put it at the end if `compilation-scroll-output' is set.
1223 (if compilation-scroll-output
1225 ;; Normally put it at the top.
1227 (if (eq outwin (selected-window))
1228 (goto-char desired-visible-point)
1229 (set-window-point outwin desired-visible-point)))
1231 ;; The setup function is called before compilation-set-window-height
1232 ;; so it can set the compilation-window-height buffer locally.
1233 (if compilation-process-setup-function
1234 (funcall compilation-process-setup-function))
1235 (compilation-set-window-height outwin)
1236 ;; Start the compilation.
1239 ;; comint uses `start-file-process'.
1243 outbuf (downcase mode-name)
1244 (if (file-remote-p default-directory)
1247 nil `("-c" ,command))))
1248 (start-file-process-shell-command (downcase mode-name)
1250 ;; Make the buffer's mode line show process state.
1251 (setq mode-line-process
1252 (list (propertize ":%s" 'face 'compilation-warning)))
1253 (set-process-sentinel proc 'compilation-sentinel)
1254 (set-process-filter proc 'compilation-filter)
1255 ;; Use (point-max) here so that output comes in
1256 ;; after the initial text,
1257 ;; regardless of where the user sees point.
1258 (set-marker (process-mark proc) (point-max) outbuf)
1259 (when compilation-disable-input
1261 (process-send-eof proc)
1262 ;; The process may have exited already.
1264 (setq compilation-in-progress
1265 (cons proc compilation-in-progress))))
1266 ;; Now finally cd to where the shell started make/grep/...
1267 (setq default-directory thisdir))
1268 (if (buffer-local-value 'compilation-scroll-output outbuf)
1269 (save-selected-window
1270 (select-window outwin)
1271 (goto-char (point-max))))
1272 ;; Make it so the next C-x ` will use this buffer.
1273 (setq next-error-last-buffer outbuf)))
1275 (defun compilation-set-window-height (window)
1276 "Set the height of WINDOW according to `compilation-window-height'."
1277 (let ((height (buffer-local-value 'compilation-window-height (window-buffer window))))
1279 (window-full-width-p window)
1280 ;; If window is alone in its frame, aside from a minibuffer,
1281 ;; don't change its height.
1282 (not (eq window (frame-root-window (window-frame window))))
1283 ;; Stef said that doing the saves in this order is safer:
1285 (save-selected-window
1286 (select-window window)
1287 (enlarge-window (- height (window-height))))))))
1289 (defvar compilation-menu-map
1290 (let ((map (make-sparse-keymap "Errors"))
1291 (opt-map (make-sparse-keymap "Skip")))
1292 (define-key map [stop-subjob]
1293 '(menu-item "Stop Compilation" kill-compilation
1294 :help "Kill the process made by the M-x compile or M-x grep commands"))
1295 (define-key map [compilation-mode-separator3]
1297 (define-key map [compilation-next-error-follow-minor-mode]
1299 "Auto Error Display" next-error-follow-minor-mode
1300 :help "Display the error under cursor when moving the cursor"
1301 :button (:toggle . next-error-follow-minor-mode)))
1302 (define-key map [compilation-skip]
1303 (cons "Skip Less Important Messages" opt-map))
1304 (define-key opt-map [compilation-skip-none]
1305 '(menu-item "Don't Skip Any Messages"
1308 (customize-set-variable 'compilation-skip-threshold 0))
1309 :help "Do not skip any type of messages"
1310 :button (:radio . (eq compilation-skip-threshold 0))))
1311 (define-key opt-map [compilation-skip-info]
1312 '(menu-item "Skip Info"
1315 (customize-set-variable 'compilation-skip-threshold 1))
1316 :help "Skip anything less than warning"
1317 :button (:radio . (eq compilation-skip-threshold 1))))
1318 (define-key opt-map [compilation-skip-warning-and-info]
1319 '(menu-item "Skip Warnings and Info"
1322 (customize-set-variable 'compilation-skip-threshold 2))
1323 :help "Skip over Warnings and Info, stop for errors"
1324 :button (:radio . (eq compilation-skip-threshold 2))))
1325 (define-key map [compilation-mode-separator2]
1327 (define-key map [compilation-first-error]
1328 '(menu-item "First Error" first-error
1329 :help "Restart at the first error, visit corresponding source code"))
1330 (define-key map [compilation-previous-error]
1331 '(menu-item "Previous Error" previous-error
1332 :help "Visit previous `next-error' message and corresponding source code"))
1333 (define-key map [compilation-next-error]
1334 '(menu-item "Next Error" next-error
1335 :help "Visit next `next-error' message and corresponding source code"))
1338 (defvar compilation-minor-mode-map
1339 (let ((map (make-sparse-keymap)))
1340 (define-key map [mouse-2] 'compile-goto-error)
1341 (define-key map [follow-link] 'mouse-face)
1342 (define-key map "\C-c\C-c" 'compile-goto-error)
1343 (define-key map "\C-m" 'compile-goto-error)
1344 (define-key map "\C-c\C-k" 'kill-compilation)
1345 (define-key map "\M-n" 'compilation-next-error)
1346 (define-key map "\M-p" 'compilation-previous-error)
1347 (define-key map "\M-{" 'compilation-previous-file)
1348 (define-key map "\M-}" 'compilation-next-file)
1349 ;; Set up the menu-bar
1350 (define-key map [menu-bar compilation]
1351 (cons "Errors" compilation-menu-map))
1353 "Keymap for `compilation-minor-mode'.")
1355 (defvar compilation-shell-minor-mode-map
1356 (let ((map (make-sparse-keymap)))
1357 (define-key map "\M-\C-m" 'compile-goto-error)
1358 (define-key map "\M-\C-n" 'compilation-next-error)
1359 (define-key map "\M-\C-p" 'compilation-previous-error)
1360 (define-key map "\M-{" 'compilation-previous-file)
1361 (define-key map "\M-}" 'compilation-next-file)
1362 ;; Set up the menu-bar
1363 (define-key map [menu-bar compilation]
1364 (cons "Errors" compilation-menu-map))
1366 "Keymap for `compilation-shell-minor-mode'.")
1368 (defvar compilation-button-map
1369 (let ((map (make-sparse-keymap)))
1370 (define-key map [mouse-2] 'compile-goto-error)
1371 (define-key map [follow-link] 'mouse-face)
1372 (define-key map "\C-m" 'compile-goto-error)
1374 "Keymap for compilation-message buttons.")
1375 (fset 'compilation-button-map compilation-button-map)
1377 (defvar compilation-mode-map
1378 (let ((map (make-sparse-keymap)))
1379 ;; Don't inherit from compilation-minor-mode-map,
1380 ;; because that introduces a menu bar item we don't want.
1381 ;; That confuses C-down-mouse-3.
1382 (define-key map [mouse-2] 'compile-goto-error)
1383 (define-key map [follow-link] 'mouse-face)
1384 (define-key map "\C-c\C-c" 'compile-goto-error)
1385 (define-key map "\C-m" 'compile-goto-error)
1386 (define-key map "\C-c\C-k" 'kill-compilation)
1387 (define-key map "\M-n" 'compilation-next-error)
1388 (define-key map "\M-p" 'compilation-previous-error)
1389 (define-key map "\M-{" 'compilation-previous-file)
1390 (define-key map "\M-}" 'compilation-next-file)
1391 (define-key map "\t" 'compilation-next-error)
1392 (define-key map [backtab] 'compilation-previous-error)
1394 (define-key map " " 'scroll-up)
1395 (define-key map "\^?" 'scroll-down)
1396 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
1398 ;; Set up the menu-bar
1399 (let ((submap (make-sparse-keymap "Compile")))
1400 (define-key map [menu-bar compilation]
1401 (cons "Compile" submap))
1402 (set-keymap-parent submap compilation-menu-map))
1403 (define-key map [menu-bar compilation compilation-separator2]
1405 (define-key map [menu-bar compilation compilation-grep]
1406 '(menu-item "Search Files (grep)..." grep
1407 :help "Run grep, with user-specified args, and collect output in a buffer"))
1408 (define-key map [menu-bar compilation compilation-recompile]
1409 '(menu-item "Recompile" recompile
1410 :help "Re-compile the program including the current buffer"))
1411 (define-key map [menu-bar compilation compilation-compile]
1412 '(menu-item "Compile..." compile
1413 :help "Compile the program including the current buffer. Default: run `make'"))
1415 "Keymap for compilation log buffers.
1416 `compilation-minor-mode-map' is a parent of this.")
1418 (defvar compilation-mode-tool-bar-map
1419 (if (display-graphic-p)
1420 (let ((map (butlast (copy-keymap tool-bar-map)))
1421 (help (last tool-bar-map))) ;; Keep Help last in tool bar
1422 (tool-bar-local-item
1423 "left-arrow" 'previous-error-no-select 'previous-error-no-select map
1425 :help "Goto previous error")
1426 (tool-bar-local-item
1427 "right-arrow" 'next-error-no-select 'next-error-no-select map
1429 :help "Goto next error")
1430 (tool-bar-local-item
1431 "cancel" 'kill-compilation 'kill-compilation map
1432 :enable '(let ((buffer (compilation-find-buffer)))
1433 (get-buffer-process buffer))
1434 :help "Stop compilation")
1435 (tool-bar-local-item
1436 "refresh" 'recompile 'recompile map
1437 :help "Restart compilation")
1438 (append map help))))
1440 (put 'compilation-mode 'mode-class 'special)
1443 (defun compilation-mode (&optional name-of-mode)
1444 "Major mode for compilation log buffers.
1445 \\<compilation-mode-map>To visit the source for a line-numbered error,
1446 move point to the error message line and type \\[compile-goto-error].
1447 To kill the compilation, type \\[kill-compilation].
1449 Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
1451 \\{compilation-mode-map}"
1453 (kill-all-local-variables)
1454 (use-local-map compilation-mode-map)
1455 (set (make-local-variable 'tool-bar-map) compilation-mode-tool-bar-map)
1456 (setq major-mode 'compilation-mode
1457 mode-name (or name-of-mode "Compilation"))
1458 (set (make-local-variable 'page-delimiter)
1459 compilation-page-delimiter)
1461 (setq buffer-read-only t)
1462 (run-mode-hooks 'compilation-mode-hook))
1464 (defmacro define-compilation-mode (mode name doc &rest body)
1465 "This is like `define-derived-mode' without the PARENT argument.
1466 The parent is always `compilation-mode' and the customizable `compilation-...'
1467 variables are also set from the name of the mode you have chosen,
1468 by replacing the first word, e.g `compilation-scroll-output' from
1469 `grep-scroll-output' if that variable exists."
1470 (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
1471 `(define-derived-mode ,mode compilation-mode ,name
1473 ,@(mapcar (lambda (v)
1475 (intern-soft (replace-regexp-in-string
1476 "^compilation" mode-name
1479 (or (boundp (cdr v))
1480 (if (boundp 'byte-compile-bound-variables)
1481 (memq (cdr v) byte-compile-bound-variables)))
1482 `(set (make-local-variable ',(car v)) ,(cdr v))))
1483 '(compilation-buffer-name-function
1484 compilation-directory-matcher
1486 compilation-error-regexp-alist
1487 compilation-error-regexp-alist-alist
1488 compilation-error-screen-columns
1489 compilation-finish-function
1490 compilation-finish-functions
1491 compilation-first-column
1492 compilation-mode-font-lock-keywords
1493 compilation-page-delimiter
1494 compilation-parse-errors-filename-function
1495 compilation-process-setup-function
1496 compilation-scroll-output
1497 compilation-search-path
1498 compilation-skip-threshold
1499 compilation-window-height))
1502 (defun compilation-revert-buffer (ignore-auto noconfirm)
1503 (if buffer-file-name
1504 (let (revert-buffer-function)
1505 (revert-buffer ignore-auto noconfirm))
1506 (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
1507 (apply 'compilation-start compilation-arguments))))
1509 (defvar compilation-current-error nil
1510 "Marker to the location from where the next error will be found.
1511 The global commands next/previous/first-error/goto-error use this.")
1513 (defvar compilation-messages-start nil
1514 "Buffer position of the beginning of the compilation messages.
1515 If nil, use the beginning of buffer.")
1517 ;; A function name can't be a hook, must be something with a value.
1518 (defconst compilation-turn-on-font-lock 'turn-on-font-lock)
1520 (defun compilation-setup (&optional minor)
1521 "Prepare the buffer for the compilation parsing commands to work.
1522 Optional argument MINOR indicates this is called from
1523 `compilation-minor-mode'."
1524 (make-local-variable 'compilation-current-error)
1525 (make-local-variable 'compilation-messages-start)
1526 (make-local-variable 'compilation-error-screen-columns)
1527 (make-local-variable 'overlay-arrow-position)
1528 (set (make-local-variable 'overlay-arrow-string) "")
1529 (setq next-error-overlay-arrow-position nil)
1530 (add-hook 'kill-buffer-hook
1531 (lambda () (setq next-error-overlay-arrow-position nil)) nil t)
1532 ;; Note that compilation-next-error-function is for interfacing
1533 ;; with the next-error function in simple.el, and it's only
1534 ;; coincidentally named similarly to compilation-next-error.
1535 (setq next-error-function 'compilation-next-error-function)
1536 (set (make-local-variable 'comint-file-name-prefix)
1537 (or (file-remote-p default-directory) ""))
1538 (set (make-local-variable 'font-lock-extra-managed-props)
1539 '(directory message help-echo mouse-face debug))
1540 (set (make-local-variable 'compilation-locs)
1541 (make-hash-table :test 'equal :weakness 'value))
1542 ;; lazy-lock would never find the message unless it's scrolled to.
1543 ;; jit-lock might fontify some things too late.
1544 (set (make-local-variable 'font-lock-support-mode) nil)
1545 (set (make-local-variable 'font-lock-maximum-size) nil)
1547 (let ((fld font-lock-defaults))
1548 (font-lock-add-keywords nil (compilation-mode-font-lock-keywords))
1551 (font-lock-fontify-buffer)
1552 (font-lock-change-mode)
1553 (turn-on-font-lock))
1554 (turn-on-font-lock)))
1555 (setq font-lock-defaults '(compilation-mode-font-lock-keywords t))
1556 ;; maybe defer font-lock till after derived mode is set up
1557 (run-mode-hooks 'compilation-turn-on-font-lock)))
1560 (define-minor-mode compilation-shell-minor-mode
1561 "Toggle compilation shell minor mode.
1562 With arg, turn compilation mode on if and only if arg is positive.
1563 In this minor mode, all the error-parsing commands of the
1564 Compilation major mode are available but bound to keys that don't
1565 collide with Shell mode. See `compilation-mode'.
1566 Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
1567 nil " Shell-Compile"
1569 (if compilation-shell-minor-mode
1570 (compilation-setup t)
1571 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1572 (font-lock-fontify-buffer)))
1575 (define-minor-mode compilation-minor-mode
1576 "Toggle compilation minor mode.
1577 With arg, turn compilation mode on if and only if arg is positive.
1578 In this minor mode, all the error-parsing commands of the
1579 Compilation major mode are available. See `compilation-mode'.
1580 Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
1583 (if compilation-minor-mode
1584 (compilation-setup t)
1585 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1586 (font-lock-fontify-buffer)))
1588 (defun compilation-handle-exit (process-status exit-status msg)
1589 "Write MSG in the current buffer and hack its `mode-line-process'."
1590 (let ((inhibit-read-only t)
1591 (status (if compilation-exit-message-function
1592 (funcall compilation-exit-message-function
1593 process-status exit-status msg)
1594 (cons msg exit-status)))
1597 (cur-buffer (current-buffer)))
1598 ;; Record where we put the message, so we can ignore it later on.
1600 (insert ?\n mode-name " " (car status))
1601 (if (and (numberp compilation-window-height)
1602 (zerop compilation-window-height))
1603 (message "%s" (cdr status)))
1606 (insert " at " (substring (current-time-string) 0 19))
1607 (goto-char (point-max))
1608 ;; Prevent that message from being recognized as a compilation error.
1609 (add-text-properties omax (point)
1610 (append '(compilation-handle-exit t) nil))
1611 (setq mode-line-process
1612 (let ((out-string (format ":%s [%s]" process-status (cdr status)))
1613 (msg (format "%s %s" mode-name
1614 (replace-regexp-in-string "\n?$" "" (car status)))))
1616 (propertize out-string
1617 'help-echo msg 'face (if (> exit-status 0)
1619 'compilation-info))))
1620 ;; Force mode line redisplay soon.
1621 (force-mode-line-update)
1622 (if (and opoint (< opoint omax))
1625 (if compilation-finish-function
1626 (funcall compilation-finish-function cur-buffer msg)))
1627 (run-hook-with-args 'compilation-finish-functions cur-buffer msg)))
1629 ;; Called when compilation process changes state.
1630 (defun compilation-sentinel (proc msg)
1631 "Sentinel for compilation buffers."
1632 (if (memq (process-status proc) '(exit signal))
1633 (let ((buffer (process-buffer proc)))
1634 (if (null (buffer-name buffer))
1636 (set-process-buffer proc nil)
1637 (with-current-buffer buffer
1638 ;; Write something in the compilation buffer
1639 ;; and hack its mode line.
1640 (compilation-handle-exit (process-status proc)
1641 (process-exit-status proc)
1643 ;; Since the buffer and mode line will show that the
1644 ;; process is dead, we can delete it now. Otherwise it
1645 ;; will stay around until M-x list-processes.
1646 (delete-process proc)))
1647 (setq compilation-in-progress (delq proc compilation-in-progress)))))
1649 (defun compilation-filter (proc string)
1650 "Process filter for compilation buffers.
1651 Just inserts the text, but uses `insert-before-markers'."
1652 (if (buffer-name (process-buffer proc))
1653 (with-current-buffer (process-buffer proc)
1654 (let ((inhibit-read-only t))
1656 (goto-char (process-mark proc))
1657 (insert-before-markers string)
1658 (run-hooks 'compilation-filter-hook))))))
1660 ;;; test if a buffer is a compilation buffer, assuming we're in the buffer
1661 (defsubst compilation-buffer-internal-p ()
1662 "Test if inside a compilation buffer."
1663 (local-variable-p 'compilation-locs))
1665 ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p
1666 (defsubst compilation-buffer-p (buffer)
1667 "Test if BUFFER is a compilation buffer."
1668 (with-current-buffer buffer
1669 (compilation-buffer-internal-p)))
1671 (defmacro compilation-loop (< property-change 1+ error limit)
1675 (or (setq pt (,property-change pt 'message))
1676 ;; Handle the case where where the first error message is
1677 ;; at the start of the buffer, and n < 0.
1678 (if (or (eq (get-text-property ,limit 'message)
1679 (get-text-property opt 'message))
1681 (error ,error compilation-error)
1683 ;; prop 'message usually has 2 changes, on and off, so
1685 (or (setq msg (get-text-property pt 'message))
1686 (if (setq pt (,property-change pt 'message nil ,limit))
1687 (setq msg (get-text-property pt 'message)))
1688 (error ,error compilation-error))
1689 (or (< (cadr msg) compilation-skip-threshold)
1691 (eq (prog1 last (setq last (nth 2 (car msg))))
1693 (if compilation-skip-visited
1694 (nthcdr 5 (car msg)))
1695 (if compilation-skip-to-next-location
1697 ;; count this message only if none of the above are true
1698 (setq n (,1+ n))))))
1700 (defun compilation-next-error (n &optional different-file pt)
1701 "Move point to the next error in the compilation buffer.
1702 This function does NOT find the source line like \\[next-error].
1703 Prefix arg N says how many error messages to move forwards (or
1704 backwards, if negative).
1705 Optional arg DIFFERENT-FILE, if non-nil, means find next error for a
1706 file that is different from the current one.
1707 Optional arg PT, if non-nil, specifies the value of point to start
1708 looking for the next message."
1710 (or (compilation-buffer-p (current-buffer))
1711 (error "Not in a compilation buffer"))
1712 (or pt (setq pt (point)))
1713 (let* ((msg (get-text-property pt 'message))
1714 ;; `loc' is used by the compilation-loop macro.
1718 (unless (or msg ; find message near here
1719 (setq msg (get-text-property (max (1- pt) (point-min))
1721 (setq pt (previous-single-property-change pt 'message nil
1722 (line-beginning-position)))
1723 (unless (setq msg (get-text-property (max (1- pt) (point-min)) 'message))
1724 (setq pt (next-single-property-change pt 'message nil
1725 (line-end-position)))
1726 (or (setq msg (get-text-property pt 'message))
1727 (setq pt (point)))))
1728 (setq last (nth 2 (car msg)))
1730 (compilation-loop > next-single-property-change 1-
1731 (if (get-buffer-process (current-buffer))
1733 "Moved past last %s")
1735 ;; Don't move "back" to message at or before point.
1736 ;; Pass an explicit (point-min) to make sure pt is non-nil.
1737 (setq pt (previous-single-property-change pt 'message nil (point-min)))
1738 (compilation-loop < previous-single-property-change 1+
1739 "Moved back before first %s" (point-min))))
1742 (error "No %s here" compilation-error))))
1744 (defun compilation-previous-error (n)
1745 "Move point to the previous error in the compilation buffer.
1746 Prefix arg N says how many error messages to move backwards (or
1747 forwards, if negative).
1748 Does NOT find the source line like \\[previous-error]."
1750 (compilation-next-error (- n)))
1752 (defun compilation-next-file (n)
1753 "Move point to the next error for a different file than the current one.
1754 Prefix arg N says how many files to move forwards (or backwards, if negative)."
1756 (compilation-next-error n t))
1758 (defun compilation-previous-file (n)
1759 "Move point to the previous error for a different file than the current one.
1760 Prefix arg N says how many files to move backwards (or forwards, if negative)."
1762 (compilation-next-file (- n)))
1764 (defun kill-compilation ()
1765 "Kill the process made by the \\[compile] or \\[grep] commands."
1767 (let ((buffer (compilation-find-buffer)))
1768 (if (get-buffer-process buffer)
1769 (interrupt-process (get-buffer-process buffer))
1770 (error "The %s process is not running" (downcase mode-name)))))
1772 (defalias 'compile-mouse-goto-error 'compile-goto-error)
1774 (defun compile-goto-error (&optional event)
1775 "Visit the source for the error message at point.
1776 Use this command in a compilation log buffer. Sets the mark at point there."
1777 (interactive (list last-input-event))
1778 (if event (posn-set-point (event-end event)))
1779 (or (compilation-buffer-p (current-buffer))
1780 (error "Not in a compilation buffer"))
1781 (if (get-text-property (point) 'directory)
1782 (dired-other-window (car (get-text-property (point) 'directory)))
1784 (setq compilation-current-error (point))
1785 (next-error-internal)))
1787 (defun compilation-find-buffer (&optional avoid-current)
1788 "Return a compilation buffer.
1789 If AVOID-CURRENT is nil, and the current buffer is a compilation buffer,
1790 return it. If AVOID-CURRENT is non-nil, return the current buffer only
1792 (if (and (compilation-buffer-internal-p) (not avoid-current))
1794 (next-error-find-buffer avoid-current 'compilation-buffer-internal-p)))
1797 (defun compilation-next-error-function (n &optional reset)
1798 "Advance to the next error message and visit the file where the error was.
1799 This is the value of `next-error-function' in Compilation buffers."
1802 (setq compilation-current-error nil))
1803 (let* ((columns compilation-error-screen-columns) ; buffer's local value
1805 (loc (compilation-next-error (or n 1) nil
1806 (or compilation-current-error
1807 compilation-messages-start
1809 (end-loc (nth 2 loc))
1810 (marker (point-marker)))
1811 (setq compilation-current-error (point-marker)
1812 overlay-arrow-position
1814 compilation-current-error
1815 (copy-marker (line-beginning-position)))
1817 ;; If loc contains no marker, no error in that file has been visited.
1818 ;; If the marker is invalid the buffer has been killed.
1819 ;; If the file is newer than the timestamp, it has been modified
1820 ;; (`omake -P' polls filesystem for changes and recompiles when needed
1821 ;; in the same process and buffer).
1822 ;; So, recalculate all markers for that file.
1823 (unless (and (nth 3 loc) (marker-buffer (nth 3 loc))
1824 ;; There may be no timestamp info if the loc is a `fake-loc'.
1825 ;; So we skip the time-check here, although we should maybe
1826 ;; change `compilation-fake-loc' to add timestamp info.
1827 (or (null (nth 4 loc))
1830 (with-current-buffer
1831 (marker-buffer (nth 3 loc))
1832 (visited-file-modtime))))))
1833 (with-current-buffer (compilation-find-file marker (caar (nth 2 loc))
1834 (cadr (car (nth 2 loc))))
1837 (goto-char (point-min))
1838 ;; Treat file's found lines in forward order, 1 by 1.
1839 (dolist (line (reverse (cddr (nth 2 loc))))
1840 (when (car line) ; else this is a filename w/o a line#
1841 (beginning-of-line (- (car line) last -1))
1842 (setq last (car line)))
1843 ;; Treat line's found columns and store/update a marker for each.
1844 (dolist (col (cdr line))
1846 (if (eq (car col) -1) ; special case for range end
1848 (compilation-move-to-column (car col) columns))
1850 (skip-chars-forward " \t"))
1852 (set-marker (nth 3 col) (point))
1853 (setcdr (nthcdr 2 col) `(,(point-marker)))))))))
1854 (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc))
1855 (setcdr (nthcdr 3 loc) (list timestamp))
1856 (setcdr (nthcdr 4 loc) t))) ; Set this one as visited.
1858 (defvar compilation-gcpro nil
1859 "Internal variable used to keep some values from being GC'd.")
1860 (make-variable-buffer-local 'compilation-gcpro)
1862 (defun compilation-fake-loc (marker file &optional line col)
1863 "Preassociate MARKER with FILE.
1864 FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
1865 This is useful when you compile temporary files, but want
1866 automatic translation of the messages to the real buffer from
1867 which the temporary file came. This only works if done before a
1868 message about FILE appears!
1870 Optional args LINE and COL default to 1 and beginning of
1871 indentation respectively. The marker is expected to reflect
1872 this. In the simplest case the marker points to the first line
1873 of the region that was saved to the temp file.
1875 If you concatenate several regions into the temp file (e.g. a
1876 header with variable assignments and a code region), you must
1877 call this several times, once each for the last line of one
1878 region and the first line of the next region."
1879 (or (consp file) (setq file (list file)))
1880 (setq file (compilation-get-file-structure file))
1881 ;; Between the current call to compilation-fake-loc and the first occurrence
1882 ;; of an error message referring to `file', the data is only kept in the
1883 ;; weak hash-table compilation-locs, so we need to prevent this entry
1884 ;; in compilation-locs from being GC'd away. --Stef
1885 (push file compilation-gcpro)
1886 (let ((loc (compilation-assq (or line 1) (cdr file))))
1887 (setq loc (compilation-assq col loc))
1889 (setcdr (cddr loc) (list marker))
1890 (setcdr loc (list line file marker)))
1893 (defcustom compilation-context-lines nil
1894 "Display this many lines of leading context before the current message.
1895 If nil and the left fringe is displayed, don't scroll the
1896 compilation output window; an arrow in the left fringe points to
1897 the current message. If nil and there is no left fringe, the message
1898 displays at the top of the window; there is no arrow."
1899 :type '(choice integer (const :tag "No window scrolling" nil))
1903 (defsubst compilation-set-window (w mk)
1904 "Align the compilation output window W with marker MK near top."
1905 (if (integerp compilation-context-lines)
1906 (set-window-start w (save-excursion
1909 (- 1 compilation-context-lines))
1911 ;; If there is no left fringe.
1912 (if (equal (car (window-fringes)) 0)
1913 (set-window-start w (save-excursion
1915 (beginning-of-line 1)
1917 (set-window-point w mk))
1919 (defvar next-error-highlight-timer)
1921 (defun compilation-goto-locus (msg mk end-mk)
1922 "Jump to an error corresponding to MSG at MK.
1923 All arguments are markers. If END-MK is non-nil, mark is set there
1924 and overlay is highlighted between MK and END-MK."
1925 ;; Show compilation buffer in other window, scrolled to this error.
1926 (let* ((from-compilation-buffer (eq (window-buffer (selected-window))
1927 (marker-buffer msg)))
1928 ;; Use an existing window if it is in a visible frame.
1929 (pre-existing (get-buffer-window (marker-buffer msg) 0))
1930 (w (if (and from-compilation-buffer pre-existing)
1931 ;; Calling display-buffer here may end up (partly) hiding
1932 ;; the error location if the two buffers are in two
1933 ;; different frames. So don't do it if it's not necessary.
1935 (let ((display-buffer-reuse-frames t)
1938 (display-buffer (marker-buffer msg)))))
1939 (highlight-regexp (with-current-buffer (marker-buffer msg)
1940 ;; also do this while we change buffer
1941 (compilation-set-window w msg)
1942 compilation-highlight-regexp)))
1943 ;; Ideally, the window-size should be passed to `display-buffer' (via
1944 ;; something like special-display-buffer) so it's only used when
1945 ;; creating a new window.
1946 (unless pre-existing (compilation-set-window-height w))
1948 (if from-compilation-buffer
1949 ;; If the compilation buffer window was selected,
1950 ;; keep the compilation buffer in this window;
1951 ;; display the source in another window.
1952 (let ((pop-up-windows t))
1953 (pop-to-buffer (marker-buffer mk) 'other-window))
1954 (if (window-dedicated-p (selected-window))
1955 (pop-to-buffer (marker-buffer mk))
1956 (switch-to-buffer (marker-buffer mk))))
1957 ;; If narrowing gets in the way of going to the right place, widen.
1958 (unless (eq (goto-char mk) (point))
1962 (push-mark end-mk t)
1963 (if mark-active (setq mark-active)))
1964 ;; If hideshow got in the way of
1965 ;; seeing the right place, open permanently.
1966 (dolist (ov (overlays-at (point)))
1967 (when (eq 'hs (overlay-get ov 'invisible))
1971 (when highlight-regexp
1972 (if (timerp next-error-highlight-timer)
1973 (cancel-timer next-error-highlight-timer))
1974 (unless compilation-highlight-overlay
1975 (setq compilation-highlight-overlay
1976 (make-overlay (point-min) (point-min)))
1977 (overlay-put compilation-highlight-overlay 'face 'next-error))
1978 (with-current-buffer (marker-buffer mk)
1980 (if end-mk (goto-char end-mk) (end-of-line))
1981 (let ((end (point)))
1982 (if mk (goto-char mk) (beginning-of-line))
1983 (if (and (stringp highlight-regexp)
1984 (re-search-forward highlight-regexp end t))
1986 (goto-char (match-beginning 0))
1987 (move-overlay compilation-highlight-overlay
1988 (match-beginning 0) (match-end 0)
1990 (move-overlay compilation-highlight-overlay
1991 (point) end (current-buffer)))
1992 (if (or (eq next-error-highlight t)
1993 (numberp next-error-highlight))
1994 ;; We want highlighting: delete overlay on next input.
1995 (add-hook 'pre-command-hook
1996 'compilation-goto-locus-delete-o)
1997 ;; We don't want highlighting: delete overlay now.
1998 (delete-overlay compilation-highlight-overlay))
1999 ;; We want highlighting for a limited time:
2000 ;; set up a timer to delete it.
2001 (when (numberp next-error-highlight)
2002 (setq next-error-highlight-timer
2003 (run-at-time next-error-highlight nil
2004 'compilation-goto-locus-delete-o)))))))
2005 (when (and (eq next-error-highlight 'fringe-arrow))
2006 ;; We want a fringe arrow (instead of highlighting).
2007 (setq next-error-overlay-arrow-position
2008 (copy-marker (line-beginning-position))))))
2010 (defun compilation-goto-locus-delete-o ()
2011 (delete-overlay compilation-highlight-overlay)
2012 ;; Get rid of timer and hook that would try to do this again.
2013 (if (timerp next-error-highlight-timer)
2014 (cancel-timer next-error-highlight-timer))
2015 (remove-hook 'pre-command-hook
2016 'compilation-goto-locus-delete-o))
2018 (defun compilation-find-file (marker filename directory &rest formats)
2019 "Find a buffer for file FILENAME.
2020 If FILENAME is not found at all, ask the user where to find it.
2021 Pop up the buffer containing MARKER and scroll to MARKER if we ask
2022 the user where to find the file.
2023 Search the directories in `compilation-search-path'.
2024 A nil in `compilation-search-path' means to try the
2025 \"current\" directory, which is passed in DIRECTORY.
2026 If DIRECTORY is relative, it is combined with `default-directory'.
2027 If DIRECTORY is nil, that means use `default-directory'.
2028 FORMATS, if given, is a list of formats to reformat FILENAME when
2029 looking for it: for each element FMT in FORMATS, this function
2030 attempts to find a file whose name is produced by (format FMT FILENAME)."
2031 (or formats (setq formats '("%s")))
2032 (let ((dirs compilation-search-path)
2033 (spec-dir (if directory
2034 (expand-file-name directory)
2036 buffer thisdir fmts name)
2037 (if (file-name-absolute-p filename)
2038 ;; The file name is absolute. Use its explicit directory as
2039 ;; the first in the search path, and strip it from FILENAME.
2040 (setq filename (abbreviate-file-name (expand-file-name filename))
2041 dirs (cons (file-name-directory filename) dirs)
2042 filename (file-name-nondirectory filename)))
2043 ;; Now search the path.
2044 (while (and dirs (null buffer))
2045 (setq thisdir (or (car dirs) spec-dir)
2047 ;; For each directory, try each format string.
2048 (while (and fmts (null buffer))
2049 (setq name (expand-file-name (format (car fmts) filename) thisdir)
2050 buffer (and (file-exists-p name)
2051 (find-file-noselect name))
2053 (setq dirs (cdr dirs)))
2054 (while (null buffer) ;Repeat until the user selects an existing file.
2055 ;; The file doesn't exist. Ask the user where to find it.
2056 (save-excursion ;This save-excursion is probably not right.
2057 (let ((pop-up-windows t))
2058 (compilation-set-window (display-buffer (marker-buffer marker))
2060 (let* ((name (read-file-name
2061 (format "Find this %s in (default %s): "
2062 compilation-error filename)
2063 spec-dir filename t nil
2064 ;; The predicate below is fine when called from
2065 ;; minibuffer-complete-and-exit, but it's too
2066 ;; restrictive otherwise, since it also prevents the
2067 ;; user from completing "fo" to "foo/" when she
2068 ;; wants to enter "foo/bar".
2070 ;; Try to make sure the user can only select
2071 ;; a valid answer. This predicate may be ignored,
2072 ;; tho, so we still have to double-check afterwards.
2073 ;; TODO: We should probably fix read-file-name so
2074 ;; that it never ignores this predicate, even when
2075 ;; using popup dialog boxes.
2077 ;; (if (file-directory-p name)
2078 ;; (setq name (expand-file-name filename name)))
2079 ;; (file-exists-p name))
2083 ((not (file-exists-p name))
2084 (message "Cannot find file `%s'" name)
2086 ((and (file-directory-p name)
2088 (setq name (expand-file-name filename name)))))
2089 (message "No `%s' in directory %s" filename origname)
2092 (setq buffer (find-file-noselect name))))))))
2093 ;; Make intangible overlays tangible.
2094 ;; This is weird: it's not even clear which is the current buffer,
2095 ;; so the code below can't be expected to DTRT here. -- Stef
2096 (dolist (ov (overlays-in (point-min) (point-max)))
2097 (when (overlay-get ov 'intangible)
2098 (overlay-put ov 'intangible nil)))
2101 (defun compilation-get-file-structure (file &optional fmt)
2102 "Retrieve FILE's file-structure or create a new one.
2103 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
2104 In the former case, FILENAME may be relative or absolute.
2106 The file-structure looks like this:
2107 (list (list FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)"
2108 (or (gethash file compilation-locs)
2109 ;; File was not previously encountered, at least not in the form passed.
2110 ;; Let's normalize it and look again.
2111 (let ((filename (car file))
2112 ;; Get the specified directory from FILE.
2113 (spec-directory (if (cdr file)
2114 (file-truename (cdr file)))))
2116 ;; Check for a comint-file-name-prefix and prepend it if appropriate.
2117 ;; (This is very useful for compilation-minor-mode in an rlogin-mode
2119 (when (and (boundp 'comint-file-name-prefix)
2120 (not (equal comint-file-name-prefix "")))
2121 (if (file-name-absolute-p filename)
2123 (concat comint-file-name-prefix filename))
2125 (setq spec-directory
2127 (concat comint-file-name-prefix spec-directory))))))
2129 ;; If compilation-parse-errors-filename-function is
2130 ;; defined, use it to process the filename.
2131 (when compilation-parse-errors-filename-function
2133 (funcall compilation-parse-errors-filename-function
2136 ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
2137 ;; file names like "./bar//foo.c" for file "bar/foo.c";
2138 ;; expand-file-name will collapse these into "/foo.c" and fail to find
2139 ;; the appropriate file. So we look for doubled slashes in the file
2140 ;; name and fix them.
2141 (setq filename (command-line-normalize-file-name filename))
2143 ;; Store it for the possibly unnormalized name
2145 ;; Retrieve or create file-structure for normalized name
2146 ;; The gethash used to not use spec-directory, but
2147 ;; this leads to errors when files in different
2148 ;; directories have the same name:
2149 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00463.html
2150 (or (gethash (cons filename spec-directory) compilation-locs)
2151 (puthash (cons filename spec-directory)
2152 (list (list filename spec-directory) fmt)
2154 compilation-locs))))
2156 (add-to-list 'debug-ignored-errors "^No more [-a-z ]+s yet$")
2158 ;;; Compatibility with the old compile.el.
2160 (defun compile-buffer-substring (n) (if n (match-string n)))
2162 (defun compilation-compat-error-properties (err)
2163 "Map old-style error ERR to new-style message."
2164 ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
2165 ;; (MARKER . MARKER).
2166 (let ((dst (cdr err)))
2168 ;; Must start with a face, for font-lock.
2170 message ,(list (list nil nil nil dst) 2)
2171 help-echo "mouse-2: visit the source location"
2172 keymap compilation-button-map
2173 mouse-face highlight)
2174 ;; Too difficult to do it by hand: dispatch to the normal code.
2175 (let* ((file (pop dst))
2178 (filename (pop file))
2179 (dirname (pop file))
2181 (compilation-internal-error-properties
2182 (cons filename dirname) line nil col nil 2 fmt)))))
2184 (defun compilation-compat-parse-errors (limit)
2185 (when compilation-parse-errors-function
2186 ;; FIXME: We should remove the rest of the compilation keywords
2187 ;; but we can't do that from here because font-lock is using
2188 ;; the value right now. --stef
2190 (setq compilation-error-list nil)
2191 ;; Reset compilation-parsing-end each time because font-lock
2192 ;; might force us the re-parse many times (typically because
2193 ;; some code adds some text-property to the output that we
2194 ;; already parsed). You might say "why reparse", well:
2195 ;; because font-lock has just removed the `message' property so
2196 ;; have to do it all over again.
2197 (if compilation-parsing-end
2198 (set-marker compilation-parsing-end (point))
2199 (setq compilation-parsing-end (point-marker)))
2201 ;; Ignore any error: we're calling this function earlier than
2202 ;; in the old compile.el so things might not all be setup yet.
2203 (funcall compilation-parse-errors-function limit nil)
2205 (dolist (err (if (listp compilation-error-list) compilation-error-list))
2206 (let* ((src (car err))
2208 (loc (cond ((markerp dst) (list nil nil nil dst))
2210 (list (nth 2 dst) (nth 1 dst)
2211 (cons (cdar dst) (caar dst)))))))
2214 ;; (put-text-property src (line-end-position) 'font-lock-face 'font-lock-warning-face)
2215 (put-text-property src (line-end-position)
2216 'message (list loc 2)))))))
2220 ;; Beware: this is not only compatiblity code. New code stil uses it. --Stef
2221 (defun compilation-forget-errors ()
2222 ;; In case we hit the same file/line specs, we want to recompute a new
2223 ;; marker for them, so flush our cache.
2224 (setq compilation-locs (make-hash-table :test 'equal :weakness 'value))
2225 (setq compilation-gcpro nil)
2226 ;; FIXME: the old code reset the directory-stack, so maybe we should
2227 ;; put a `directory change' marker of some sort, but where? -stef
2229 ;; FIXME: The old code moved compilation-current-error (which was
2230 ;; virtually represented by a mix of compilation-parsing-end and
2231 ;; compilation-error-list) to point-min, but that was only meaningful for
2232 ;; the internal uses of compilation-forget-errors: all calls from external
2233 ;; packages seem to be followed by a move of compilation-parsing-end to
2234 ;; something equivalent to point-max. So we heuristically move
2235 ;; compilation-current-error to point-max (since the external package
2236 ;; won't know that it should do it). --Stef
2237 (setq compilation-current-error nil)
2238 (let* ((proc (get-buffer-process (current-buffer)))
2239 (mark (if proc (process-mark proc)))
2240 (pos (or mark (point-max))))
2241 (setq compilation-messages-start
2242 ;; In the future, ignore the text already present in the buffer.
2243 ;; Since many process filter functions insert before markers,
2244 ;; we need to put ours just before the insertion point rather
2245 ;; than at the insertion point. If that's not possible, then
2246 ;; don't use a marker. --Stef
2247 (if (> pos (point-min)) (copy-marker (1- pos)) pos)))
2248 ;; Again, since this command is used in buffers that contain several
2249 ;; compilations, to set the beginning of "this compilation", it's a good
2250 ;; place to reset compilation-auto-jump-to-next.
2251 (set (make-local-variable 'compilation-auto-jump-to-next)
2252 (or compilation-auto-jump-to-first-error
2253 (eq compilation-scroll-output 'first-error))))
2256 (add-to-list 'auto-mode-alist '("\\.gcov\\'" . compilation-mode))
2260 ;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c
2261 ;;; compile.el ends here