1 ;;; compile.el --- run compiler as inferior of Emacs, parse error messages
3 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
5 ;; Free Software Foundation, Inc.
7 ;; Authors: Roland McGrath <roland@gnu.org>,
8 ;; Daniel Pfeiffer <occitan@esperanto.org>
10 ;; Keywords: tools, processes
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 3, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
31 ;; This package provides the compile facilities documented in the Emacs user's
34 ;; This mode uses some complex data-structures:
36 ;; LOC (or location) is a list of (COLUMN LINE FILE-STRUCTURE)
38 ;; COLUMN and LINE are numbers parsed from an error message. COLUMN and maybe
39 ;; LINE will be nil for a message that doesn't contain them. Then the
40 ;; location refers to a indented beginning of line or beginning of file.
41 ;; Once any location in some file has been jumped to, the list is extended to
42 ;; (COLUMN LINE FILE-STRUCTURE MARKER TIMESTAMP . VISITED)
43 ;; for all LOCs pertaining to that file.
44 ;; MARKER initially points to LINE and COLUMN in a buffer visiting that file.
45 ;; Being a marker it sticks to some text, when the buffer grows or shrinks
46 ;; before that point. VISITED is t if we have jumped there, else nil.
47 ;; TIMESTAMP is necessary because of "incremental compilation": `omake -P'
48 ;; polls filesystem for changes and recompiles when a file is modified
49 ;; using the same *compilation* buffer. this necessitates re-parsing markers.
51 ;; FILE-STRUCTURE is a list of
52 ;; ((FILENAME . DIRECTORY) FORMATS (LINE LOC ...) ...)
54 ;; FILENAME is a string parsed from an error message. DIRECTORY is a string
55 ;; obtained by following directory change messages. DIRECTORY will be nil for
56 ;; an absolute filename. FORMATS is a list of formats to apply to FILENAME if
57 ;; a file of that name can't be found.
58 ;; The rest of the list is an alist of elements with LINE as key. The keys
59 ;; are either nil or line numbers. If present, nil comes first, followed by
60 ;; the numbers in decreasing order. The LOCs for each line are again an alist
61 ;; ordered the same way. Note that the whole file structure is referenced in
64 ;; MESSAGE is a list of (LOC TYPE END-LOC)
66 ;; TYPE is 0 for info or 1 for warning if the message matcher identified it as
67 ;; such, 2 otherwise (for a real error). END-LOC is a LOC pointing to the
68 ;; other end, if the parsed message contained a range. If the end of the
69 ;; range didn't specify a COLUMN, it defaults to -1, meaning end of line.
70 ;; These are the value of the `message' text-properties in the compilation
75 (eval-when-compile (require 'cl))
77 (defvar font-lock-extra-managed-props)
78 (defvar font-lock-keywords)
79 (defvar font-lock-maximum-size)
80 (defvar font-lock-support-mode)
83 (defgroup compilation nil
84 "Run compiler as inferior of Emacs, parse error messages."
90 (defcustom compilation-mode-hook nil
91 "List of hook functions run by `compilation-mode' (see `run-mode-hooks')."
96 (defcustom compilation-window-height nil
97 "Number of lines in a compilation window. If nil, use Emacs default."
98 :type '(choice (const :tag "Default" nil)
102 (defvar compilation-first-column 1
103 "*This is how compilers number the first column, usually 1 or 0.")
105 (defvar compilation-parse-errors-filename-function nil
106 "Function to call to post-process filenames while parsing error messages.
107 It takes one arg FILENAME which is the name of a file as found
108 in the compilation output, and should return a transformed file name.")
111 (defvar compilation-process-setup-function nil
112 "*Function to call to customize the compilation process.
113 This function is called immediately before the compilation process is
114 started. It can be used to set any variables or functions that are used
115 while processing the output of the compilation process. The function
116 is called with variables `compilation-buffer' and `compilation-window'
117 bound to the compilation buffer and window, respectively.")
120 (defvar compilation-buffer-name-function nil
121 "Function to compute the name of a compilation buffer.
122 The function receives one argument, the name of the major mode of the
123 compilation buffer. It should return a string.
124 If nil, compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
127 (defvar compilation-finish-function nil
128 "Function to call when a compilation process finishes.
129 It is called with two arguments: the compilation buffer, and a string
130 describing how the process finished.")
132 (make-obsolete-variable 'compilation-finish-function
133 "use `compilation-finish-functions', but it works a little differently."
137 (defvar compilation-finish-functions nil
138 "Functions to call when a compilation process finishes.
139 Each function is called with two arguments: the compilation buffer,
140 and a string describing how the process finished.")
142 (defvar compilation-in-progress nil
143 "List of compilation processes now running.")
144 (or (assq 'compilation-in-progress minor-mode-alist)
145 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
148 (defvar compilation-error "error"
149 "Stem of message to print when no matches are found.")
151 (defvar compilation-arguments nil
152 "Arguments that were given to `compilation-start'.")
154 (defvar compilation-num-errors-found)
156 (defconst compilation-error-regexp-alist-alist
158 "^\\(?:[Ee]rror on \\|[Ww]arning on\\( \\)\\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
159 of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil (1))
162 "\\(warning: .*\\)? at \\([^ \n]+\\):\\([0-9]+\\)$" 2 3 nil (1))
165 " in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
168 "^[ \t]*\\[[^] \n]+\\][ \t]*\\([^: \n]+\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):[0-9]+:[0-9]+:\\)?\
169 \\( warning\\)?" 1 2 3 (4))
172 ;; Maven is a popular build tool for Java. Maven is Free Software.
173 "\\(.*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\]" 1 2 3)
176 "^\\([^: \n\t]+\\): line \\([0-9]+\\):" 1 2)
179 "^\\(?:Error\\|Warnin\\(g\\)\\) \\(?:[FEW][0-9]+ \\)?\
180 \\([a-zA-Z]?:?[^:( \t\n]+\\)\
181 \\([0-9]+\\)\\(?:[) \t]\\|:[^0-9\n]\\)" 2 3 nil (1))
184 "^ *File \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1, lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
185 \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:\\)?\\([ \n]Warning:\\)?\\)"
186 2 (3 . 4) (5 . 6) (7))
189 "^\"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)\
190 \\(?:[(. pos]+\\([0-9]+\\))?\\)?[:.,; (-]\\( warning:\\|[-0-9 ]*(W)\\)?" 1 2 3 (4))
193 "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
196 "at line \\([0-9]+\\) of \"\\([^ \n]+\\)\"$"
200 "^Error [0-9]+ at (\\([0-9]+\\):\\([^)\n]+\\))" 2 1)
203 "\\(^Warning .*\\)? line[ \n]\\([0-9]+\\)[ \n]\\(?:col \\([0-9]+\\)[ \n]\\)?file \\([^ :;\n]+\\)"
207 "^\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(?:Error\\|Warnin\\(g\\)\\)\\[[0-9]+\\]:"
211 "^\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) :\
212 \\(?:warnin\\(g\\)\\|informationa\\(l\\)\\)?" 1 2 3 (4 . 5))
214 ;; fixme: should be `mips'
216 "^[-[:alnum:]_/ ]+: \\(?:\\(?:[sS]evere\\|[eE]rror\\|[wW]arnin\\(g\\)\\|[iI]nf\\(o\\)\\)[0-9 ]*: \\)?\
217 \\([^,\" \n\t]+\\)\\(?:, line\\|:\\) \\([0-9]+\\):" 3 4 nil (1 . 2))
220 "^\\(?:[ \t]+at \\|==[0-9]+== +\\(?:at\\|b\\(y\\)\\)\\).+(\\([^()\n]+\\):\\([0-9]+\\))$" 2 3 nil (1))
223 "^\\(?:Found\\|Issued\\) .* compiling \"\\(.+\\)\":$" 1 nil nil 0)
225 "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)"
227 (2 (compilation-face '(3))))
230 ;; I have no idea what this first line is supposed to match, but it
231 ;; makes things ambiguous with output such as "foo:344:50:blabla" since
232 ;; the "foo" part can match this first line (in which case the file
233 ;; name as "344"). To avoid this, the second line disallows filenames
234 ;; exclusively composed of digits. --Stef
235 ;; Similarly, we get lots of false positives with messages including
236 ;; times of the form "HH:MM:SS" where MM is taken as a line number, so
237 ;; the last line tries to rule out message where the info after the
238 ;; line number starts with "SS". --Stef
239 "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\)?\
240 \\([0-9]*[^0-9\n]\\(?:[^\n ]\\| [^-\n]\\)*?\\): ?\
241 \\([0-9]+\\)\\(?:\\([.:]\\)\\([0-9]+\\)\\)?\
242 \\(?:-\\([0-9]+\\)?\\(?:\\3\\([0-9]+\\)\\)?\\)?:\
243 \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\
244 *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\|[Nn]ote\\)\\|\
245 \[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)"
246 1 (2 . 5) (4 . 6) (7 . 8))
248 ;; The `gnu' style above can incorrectly match gcc's "In file
249 ;; included from" message, so we process that first. -- cyd
251 "^\\(?:In file included\\| \\) from \
252 \\(.+\\):\\([0-9]+\\)\\(?:\\(:\\)\\|\\(,\\)\\)?" 1 2 nil (3 . 4))
255 "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)"
259 "^makepp\\(?:\\(?:: warning\\(:\\).*?\\|\\(: Scanning\\|: [LR]e?l?oading makefile\\|: Imported\\|log:.*?\\) \\|: .*?\\)\
260 `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)"
262 ("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]" nil nil
263 (2 compilation-info-face)
264 (3 compilation-line-face nil t)
265 (1 (compilation-error-properties 2 3 nil nil nil 0 nil)
268 ;; Should be lint-1, lint-2 (SysV lint)
270 " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
272 " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2)
275 ;; AFAWK, The message may be a "warning", "error", or "fatal error".
276 "^\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
277 : \\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:" 2 3 nil (4))
280 "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
281 \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
282 \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
285 ;; "during global destruction": This comes out under "use
286 ;; warnings" in recent perl when breaking circular references
287 ;; during program or thread exit.
289 " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \
290 during global destruction\\.$\\)" 1 2)
293 "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
297 "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
298 \\([0-9]+\\) of file://\\(.+\\)"
302 "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
303 [12][09][0-9][0-9] +\\(.*\\):$"
306 "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
307 nil 3 nil (2) nil (1 (compilation-face '(2))))
308 (sparc-pascal-example
309 "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
310 nil 1 nil (3) nil (2 (compilation-face '(3))))
313 ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
314 File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
318 "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
321 "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
322 \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3))
325 "^ *-: *\\(0\\):Source:\\(.+\\)$"
327 (1 compilation-line-face prepend) (2 compilation-info-face prepend))
329 "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
331 (1 compilation-line-face prepend))
332 ;; Underlines over all lines of gcov output are too uncomfortable to read.
333 ;; However, hyperlinks embedded in the lines are useful.
334 ;; So I put default face on the lines; and then put
335 ;; compilation-*-face by manually to eliminate the underlines.
336 ;; The hyperlinks are still effective.
338 "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
341 (1 compilation-line-face prepend))
343 "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
346 (1 compilation-info-face prepend) (2 compilation-line-face prepend))
348 "^ *\\(#####\\): *\\([0-9]+\\):.*$"
351 (1 compilation-error-face prepend) (2 compilation-line-face prepend))
354 ;; podchecker error messages, per Pod::Checker.
355 ;; The style is from the Pod::Checker::poderror() function, eg.
356 ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm
358 ;; Plus end_pod() can give "at line EOF" instead of a
359 ;; number, so for that match "on line N" which is the
360 ;; originating spot, eg.
361 ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm
363 ;; Plus command() can give both "on line N" and "at line N";
364 ;; the latter is desired and is matched because the .* is
366 ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod
368 "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \
369 \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)"
372 ;; perl Test module error messages.
373 ;; Style per the ok() function "$context", eg.
374 ;; # Failed test 1 in foo.t at line 6
376 "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
379 ;; Or when comparing got/want values,
380 ;; # Test 2 got: "xx" (t-compilation-perl-2.t at line 10)
382 ;; And under Test::Harness they're preceded by progress stuff with
384 ;; ... NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
386 "^\\(.*NOK.*\\)?# Test [0-9]+ got:.* (\\([^ \t\r\n]+\\) at line \
390 ;; perl Test::Harness output, eg.
391 ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
393 ;; Test::Harness is slightly designed for tty output, since
394 ;; it prints CRs to overwrite progress messages, but if you
395 ;; run it in with M-x compile this pattern can at least step
396 ;; through the failures.
398 "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
401 ;; The style comes from HTML::Lint::Error::as_string(), eg.
402 ;; index.html (13:1) Unknown element <fdjsk>
404 ;; The pattern only matches filenames without spaces, since that
405 ;; should be usual and should help reduce the chance of a false
406 ;; match of a message from some unrelated program.
408 ;; This message style is quite close to the "ibm" entry which is
409 ;; for IBM C, though that ibm bit doesn't put a space after the
412 "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) "
415 "Alist of values for `compilation-error-regexp-alist'.")
417 (defcustom compilation-error-regexp-alist
418 (mapcar 'car compilation-error-regexp-alist-alist)
419 "Alist that specifies how to match errors in compiler output.
420 On GNU and Unix, any string is a valid filename, so these
421 matchers must make some common sense assumptions, which catch
422 normal cases. A shorter list will be lighter on resource usage.
424 Instead of an alist element, you can use a symbol, which is
425 looked up in `compilation-error-regexp-alist-alist'. You can see
426 the predefined symbols and their effects in the file
427 `etc/compilation.txt' (linked below if you are customizing this).
429 Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
430 HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
431 gives the file name, and the LINE'th subexpression gives the line
432 number. The COLUMN'th subexpression gives the column number on
435 If FILE, LINE or COLUMN are nil or that index didn't match, that
436 information is not present on the matched line. In that case the
437 file name is assumed to be the same as the previous one in the
438 buffer, line number defaults to 1 and column defaults to
439 beginning of line's indentation.
441 FILE can also have the form (FILE FORMAT...), where the FORMATs
442 \(e.g. \"%s.c\") will be applied in turn to the recognized file
443 name, until a file of that name is found. Or FILE can also be a
444 function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
445 In the former case, FILENAME may be relative or absolute.
447 LINE can also be of the form (LINE . END-LINE) meaning a range
448 of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
449 meaning a range of columns starting on LINE and ending on
450 END-LINE, if that matched.
452 TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
453 TYPE can also be of the form (WARNING . INFO). In that case this
454 will be equivalent to 1 if the WARNING'th subexpression matched
455 or else equivalent to 0 if the INFO'th subexpression matched.
456 See `compilation-error-face', `compilation-warning-face',
457 `compilation-info-face' and `compilation-skip-threshold'.
459 What matched the HYPERLINK'th subexpression has `mouse-face' and
460 `compilation-message-face' applied. If this is nil, the text
461 matched by the whole REGEXP becomes the hyperlink.
463 Additional HIGHLIGHTs as described under `font-lock-keywords' can
465 :type `(set :menu-tag "Pick"
466 ,@(mapcar (lambda (elt)
467 (list 'const (car elt)))
468 compilation-error-regexp-alist-alist))
469 :link `(file-link :tag "example file"
470 ,(expand-file-name "compilation.txt" data-directory))
473 ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp)
474 (defvar compilation-directory nil
475 "Directory to restore to when doing `recompile'.")
477 (defvar compilation-directory-matcher
478 '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1))
479 "A list for tracking when directories are entered or left.
480 If nil, do not track directories, e.g. if all file names are absolute. The
481 first element is the REGEXP matching these messages. It can match any number
482 of variants, e.g. different languages. The remaining elements are all of the
483 form (DIR . LEAVE). If for any one of these the DIR'th subexpression
484 matches, that is a directory name. If LEAVE is nil or the corresponding
485 LEAVE'th subexpression doesn't match, this message is about going into another
486 directory. If it does match anything, this message is about going back to the
487 directory we were in before the last entering message. If you change this,
488 you may also want to change `compilation-page-delimiter'.")
490 (defvar compilation-page-delimiter
491 "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
492 "Value of `page-delimiter' in Compilation mode.")
494 (defvar compilation-mode-font-lock-keywords
495 '(;; configure output lines.
496 ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
497 (1 font-lock-variable-name-face)
498 (2 (compilation-face '(4 . 3))))
499 ;; Command output lines. Recognize `make[n]:' lines too.
500 ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
501 (1 font-lock-function-name-face) (3 compilation-line-face nil t))
502 (" --?o\\(?:utfile\\|utput\\)?[= ]?\\(\\S +\\)" . 1)
503 ("^Compilation \\(finished\\).*"
504 (0 '(face nil message nil help-echo nil mouse-face nil) t)
505 (1 compilation-info-face))
506 ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
507 (0 '(face nil message nil help-echo nil mouse-face nil) t)
508 (1 compilation-error-face)
509 (2 compilation-error-face nil t)))
510 "Additional things to highlight in Compilation mode.
511 This gets tacked on the end of the generated expressions.")
513 (defvar compilation-highlight-regexp t
514 "Regexp matching part of visited source lines to highlight temporarily.
515 Highlight entire line if t; don't highlight source lines if nil.")
517 (defvar compilation-highlight-overlay nil
518 "Overlay used to temporarily highlight compilation matches.")
520 (defcustom compilation-error-screen-columns t
521 "If non-nil, column numbers in error messages are screen columns.
522 Otherwise they are interpreted as character positions, with
523 each character occupying one column.
524 The default is to use screen columns, which requires that the compilation
525 program and Emacs agree about the display width of the characters,
526 especially the TAB character."
531 (defcustom compilation-read-command t
532 "Non-nil means \\[compile] reads the compilation command to use.
533 Otherwise, \\[compile] just uses the value of `compile-command'."
538 (defcustom compilation-ask-about-save t
539 "Non-nil means \\[compile] asks which buffers to save before compiling.
540 Otherwise, it saves all modified buffers without asking."
545 (defcustom compilation-search-path '(nil)
546 "List of directories to search for source files named in error messages.
547 Elements should be directory names, not file names of directories.
548 The value nil as an element means to try the default directory."
549 :type '(repeat (choice (const :tag "Default" nil)
550 (string :tag "Directory")))
554 (defcustom compile-command "make -k "
555 "Last shell command used to do a compilation; default for next compilation.
557 Sometimes it is useful for files to supply local values for this variable.
558 You might also use mode hooks to specify it in certain modes, like this:
560 (add-hook 'c-mode-hook
562 (unless (or (file-exists-p \"makefile\")
563 (file-exists-p \"Makefile\"))
564 (set (make-local-variable 'compile-command)
566 (file-name-sans-extension buffer-file-name))))))"
569 ;;;###autoload(put 'compile-command 'safe-local-variable 'stringp)
572 (defcustom compilation-disable-input nil
573 "If non-nil, send end-of-file as compilation process input.
574 This only affects platforms that support asynchronous processes (see
575 `start-process'); synchronous compilation processes never accept input."
580 ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
581 ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
582 ;; key. This holds the tree seen from root, for storing new nodes.
583 (defvar compilation-locs ())
585 (defvar compilation-debug nil
586 "*Set this to t before creating a *compilation* buffer.
587 Then every error line will have a debug text property with the matcher that
588 fit this line and the match data. Use `describe-text-properties'.")
590 (defvar compilation-exit-message-function nil "\
591 If non-nil, called when a compilation process dies to return a status message.
592 This should be a function of three arguments: process status, exit status,
593 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
594 write into the compilation buffer, and to put in its mode line.")
596 (defvar compilation-environment nil
597 "*List of environment variables for compilation to inherit.
598 Each element should be a string of the form ENVVARNAME=VALUE.
599 This list is temporarily prepended to `process-environment' prior to
600 starting the compilation process.")
602 ;; History of compile commands.
603 (defvar compile-history nil)
605 (defface compilation-error
606 '((t :inherit font-lock-warning-face))
607 "Face used to highlight compiler errors."
611 (defface compilation-warning
612 '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
613 (((class color)) (:foreground "cyan" :weight bold))
615 "Face used to highlight compiler warnings."
619 (defface compilation-info
620 '((((class color) (min-colors 16) (background light))
621 (:foreground "Green3" :weight bold))
622 (((class color) (min-colors 88) (background dark))
623 (:foreground "Green1" :weight bold))
624 (((class color) (min-colors 16) (background dark))
625 (:foreground "Green" :weight bold))
626 (((class color)) (:foreground "green" :weight bold))
628 "Face used to highlight compiler information."
632 (defface compilation-line-number
633 '((t :inherit font-lock-variable-name-face))
634 "Face for displaying line numbers in compiler messages."
638 (defface compilation-column-number
639 '((t :inherit font-lock-type-face))
640 "Face for displaying column numbers in compiler messages."
644 (defcustom compilation-message-face 'underline
645 "Face name to use for whole messages.
646 Faces `compilation-error-face', `compilation-warning-face',
647 `compilation-info-face', `compilation-line-face' and
648 `compilation-column-face' get prepended to this, when applicable."
653 (defvar compilation-error-face 'compilation-error
654 "Face name to use for file name in error messages.")
656 (defvar compilation-warning-face 'compilation-warning
657 "Face name to use for file name in warning messages.")
659 (defvar compilation-info-face 'compilation-info
660 "Face name to use for file name in informational messages.")
662 (defvar compilation-line-face 'compilation-line-number
663 "Face name to use for line numbers in compiler messages.")
665 (defvar compilation-column-face 'compilation-column-number
666 "Face name to use for column numbers in compiler messages.")
668 ;; same faces as dired uses
669 (defvar compilation-enter-directory-face 'font-lock-function-name-face
670 "Face name to use for entering directory messages.")
672 (defvar compilation-leave-directory-face 'font-lock-type-face
673 "Face name to use for leaving directory messages.")
677 ;; Used for compatibility with the old compile.el.
678 (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
679 (defvar compilation-parsing-end (make-marker))
680 (defvar compilation-parse-errors-function nil)
681 (defvar compilation-error-list nil)
682 (defvar compilation-old-error-list nil)
684 (defcustom compilation-auto-jump-to-first-error nil
685 "If non-nil, automatically jump to the first error after `compile'."
690 (defvar compilation-auto-jump-to-next nil
691 "If non-nil, automatically jump to the next error encountered.")
692 (make-variable-buffer-local 'compilation-auto-jump-to-next)
695 (defvar compilation-skip-to-next-location t
696 "*If non-nil, skip multiple error messages for the same source location.")
698 (defcustom compilation-skip-threshold 1
699 "Compilation motion commands skip less important messages.
700 The value can be either 2 -- skip anything less than error, 1 --
701 skip anything less than warning or 0 -- don't skip any messages.
702 Note that all messages not positively identified as warning or
703 info, are considered errors."
704 :type '(choice (const :tag "Warnings and info" 2)
705 (const :tag "Info" 1)
706 (const :tag "None" 0))
710 (defcustom compilation-skip-visited nil
711 "Compilation motion commands skip visited messages if this is t.
712 Visited messages are ones for which the file, line and column have been jumped
713 to from the current content in the current compilation buffer, even if it was
714 from a different message."
719 (defun compilation-face (type)
720 (or (and (car type) (match-end (car type)) compilation-warning-face)
721 (and (cdr type) (match-end (cdr type)) compilation-info-face)
722 compilation-error-face))
724 ;; Internal function for calculating the text properties of a directory
725 ;; change message. The directory property is important, because it is
726 ;; the stack of nested enter-messages. Relative filenames on the following
727 ;; lines are relative to the top of the stack.
728 (defun compilation-directory-properties (idx leave)
729 (if leave (setq leave (match-end leave)))
730 ;; find previous stack, and push onto it, or if `leave' pop it
731 (let ((dir (previous-single-property-change (point) 'directory)))
732 (setq dir (if dir (or (get-text-property (1- dir) 'directory)
733 (get-text-property dir 'directory))))
735 compilation-leave-directory-face
736 compilation-enter-directory-face)
739 '(nil)) ; nil only isn't a property-change
740 (cons (match-string-no-properties idx) dir))
742 keymap compilation-button-map
743 help-echo "mouse-2: visit destination directory")))
745 ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
746 ;; KEY element from the ALIST, creating it in the right position if not already
747 ;; present. ALIST structure is
748 ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
749 ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
750 ;; may be nil. The other KEYs are ordered backwards so that growing line
751 ;; numbers can be inserted in front and searching can abort after half the
753 (eval-when-compile ;Don't keep it at runtime if not needed.
754 (defmacro compilation-assq (key alist)
757 (car (if (if (null ,key)
758 (if l2 (null (caar l2)))
759 (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
762 (if l2 (eq ,key (caar l2))))
764 (setcdr l1 (cons (list ,key) l2)))))))
766 (defun compilation-auto-jump (buffer pos)
767 (with-current-buffer buffer
769 (if compilation-auto-jump-to-first-error
770 (compile-goto-error))))
772 ;; This function is the central driver, called when font-locking to gather
773 ;; all information needed to later jump to corresponding source code.
774 ;; Return a property list with all meta information on this error location.
776 (defun compilation-error-properties (file line end-line col end-col type fmt)
777 (unless (< (next-single-property-change (match-beginning 0)
778 'directory nil (point))
782 (setq file (funcall file))
784 (setq file (match-string-no-properties file))
785 (unless (file-name-absolute-p file)
786 (setq dir (previous-single-property-change (point) 'directory)
787 dir (if dir (or (get-text-property (1- dir) 'directory)
788 (get-text-property dir 'directory)))))
789 (setq file (cons file (car dir)))))
790 ;; This message didn't mention one, get it from previous
792 ;; Find the previous message.
793 (previous-single-property-change (point) 'message)))
795 ;; Get the file structure that belongs to it.
797 (or (get-text-property (1- prev-pos) 'message)
798 (get-text-property prev-pos 'message)))
800 (car (nth 2 (car prev)))))
801 ;; Construct FILE . DIR from that.
803 (setq file (cons (car prev-struct)
804 (cadr prev-struct))))))
806 (setq file '("*unknown*")))))
807 ;; All of these fields are optional, get them only if we have an index, and
808 ;; it matched some part of the message.
810 (setq line (match-string-no-properties line))
811 (setq line (string-to-number line)))
813 (setq end-line (match-string-no-properties end-line))
814 (setq end-line (string-to-number end-line)))
817 (setq col (funcall col))
819 (setq col (match-string-no-properties col))
820 (setq col (- (string-to-number col) compilation-first-column)))))
821 (if (and end-col (functionp end-col))
822 (setq end-col (funcall end-col))
823 (if (and end-col (setq end-col (match-string-no-properties end-col)))
824 (setq end-col (- (string-to-number end-col) compilation-first-column -1))
825 (if end-line (setq end-col -1))))
826 (if (consp type) ; not a static type, check what it is.
827 (setq type (or (and (car type) (match-end (car type)) 1)
828 (and (cdr type) (match-end (cdr type)) 0)
831 (when (and compilation-auto-jump-to-next
832 (>= type compilation-skip-threshold))
833 (kill-local-variable 'compilation-auto-jump-to-next)
834 (run-with-timer 0 nil 'compilation-auto-jump
835 (current-buffer) (match-beginning 0)))
837 (compilation-internal-error-properties file line end-line col end-col type fmt)))
839 (defun compilation-move-to-column (col screen)
840 "Go to column COL on the current line.
841 If SCREEN is non-nil, columns are screen columns, otherwise, they are
845 (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
847 (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
848 "Get the meta-info that will be added as text-properties.
849 LINE, END-LINE, COL, END-COL are integers or nil.
850 TYPE can be 0, 1, or 2, meaning error, warning, or just info.
851 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
852 FMTS is a list of format specs for transforming the file name.
853 (See `compilation-error-regexp-alist'.)"
854 (unless file (setq file '("*unknown*")))
855 (let* ((file-struct (compilation-get-file-structure file fmts))
856 ;; Get first already existing marker (if any has one, all have one).
857 ;; Do this first, as the compilation-assq`s may create new nodes.
858 (marker-line (car (cddr file-struct))) ; a line structure
859 (marker (nth 3 (cadr marker-line))) ; its marker
860 (compilation-error-screen-columns compilation-error-screen-columns)
861 end-marker loc end-loc)
862 (if (not (and marker (marker-buffer marker)))
863 (setq marker nil) ; no valid marker for this file
864 (setq loc (or line 1)) ; normalize no linenumber to line 1
865 (catch 'marker ; find nearest loc, at least one exists
866 (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines
867 (if (> (car x) loc) ; still bigger
869 (if (> (- (or (car marker-line) 1) loc)
870 (- loc (car x))) ; current line is nearer
871 (setq marker-line x))
873 (setq marker (nth 3 (cadr marker-line))
874 marker-line (or (car marker-line) 1))
875 (with-current-buffer (marker-buffer marker)
879 (goto-char (marker-position marker))
880 (when (or end-col end-line)
881 (beginning-of-line (- (or end-line line) marker-line -1))
882 (if (or (null end-col) (< end-col 0))
884 (compilation-move-to-column
885 end-col compilation-error-screen-columns))
886 (setq end-marker (list (point-marker))))
887 (beginning-of-line (if end-line
889 (- loc marker-line -1)))
891 (compilation-move-to-column
892 col compilation-error-screen-columns)
893 (forward-to-indentation 0))
894 (setq marker (list (point-marker)))))))
896 (setq loc (compilation-assq line (cdr file-struct)))
898 (setq end-loc (compilation-assq end-line (cdr file-struct))
899 end-loc (compilation-assq end-col end-loc))
900 (if end-col ; use same line element
901 (setq end-loc (compilation-assq end-col loc))))
902 (setq loc (compilation-assq col loc))
903 ;; If they are new, make the loc(s) reference the file they point to.
904 (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker)))
907 (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker))))
909 ;; Must start with face
910 `(face ,compilation-message-face
911 message (,loc ,type ,end-loc)
912 ,@(if compilation-debug
913 `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords)
916 "mouse-2: visit this file, line and column"
918 "mouse-2: visit this file and line"
919 "mouse-2: visit this file"))
920 keymap compilation-button-map
921 mouse-face highlight)))
923 (defun compilation-mode-font-lock-keywords ()
924 "Return expressions to highlight in Compilation mode."
925 (if compilation-parse-errors-function
926 ;; An old package! Try the compatibility code.
927 '((compilation-compat-parse-errors))
929 ;; make directory tracking
930 (if compilation-directory-matcher
931 `((,(car compilation-directory-matcher)
932 ,@(mapcar (lambda (elt)
934 (compilation-directory-properties
935 ,(car elt) ,(cdr elt))
937 (cdr compilation-directory-matcher)))))
939 ;; Compiler warning/error lines.
943 (setq item (cdr (assq item
944 compilation-error-regexp-alist-alist))))
945 (let ((file (nth 1 item))
949 end-line end-col fmt)
950 (if (consp file) (setq fmt (cdr file) file (car file)))
951 (if (consp line) (setq end-line (cdr line) line (car line)))
952 (if (consp col) (setq end-col (cdr col) col (car col)))
955 ;; The old compile.el had here an undocumented hook that
956 ;; allowed `line' to be a function that computed the actual
957 ;; error location. Let's do our best.
960 (compilation-compat-error-properties
961 (funcall ',line (cons (match-string ,file)
962 (cons default-directory
964 ,(if col `(match-string ,col))))))
965 (,file compilation-error-face t))
967 (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
968 (error "HYPERLINK should be an integer: %s" (nth 5 item)))
972 ,@(when (integerp file)
973 `((,file ,(if (consp type)
974 `(compilation-face ',type)
975 (aref [compilation-info-face
976 compilation-warning-face
977 compilation-error-face]
981 `((,line compilation-line-face nil t)))
983 `((,end-line compilation-line-face nil t)))
985 ,@(when (integerp col)
986 `((,col compilation-column-face nil t)))
987 ,@(when (integerp end-col)
988 `((,end-col compilation-column-face nil t)))
991 (,(or (nth 5 item) 0)
992 (compilation-error-properties ',file ,line ,end-line
993 ,col ,end-col ',(or type 2)
995 append))))) ; for compilation-message-face
996 compilation-error-regexp-alist)
998 compilation-mode-font-lock-keywords)))
1002 (defun compile (command &optional comint)
1003 "Compile the program including the current buffer. Default: run `make'.
1004 Runs COMMAND, a shell command, in a separate process asynchronously
1005 with output going to the buffer `*compilation*'.
1007 You can then use the command \\[next-error] to find the next error message
1008 and move to the source code that caused it.
1010 If optional second arg COMINT is t the buffer will be in Comint mode with
1011 `compilation-shell-minor-mode'.
1013 Interactively, prompts for the command if `compilation-read-command' is
1014 non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
1015 Additionally, with universal prefix arg, compilation buffer will be in
1016 comint mode, i.e. interactive.
1018 To run more than one compilation at once, start one then rename
1019 the \`*compilation*' buffer to some other name with
1020 \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
1021 It will create a new \`*compilation*' buffer.
1023 On most systems, termination of the main compilation process
1024 kills its subprocesses.
1026 The name used for the buffer is actually whatever is returned by
1027 the function in `compilation-buffer-name-function', so you can set that
1028 to a function that generates a unique name."
1031 (let ((command (eval compile-command)))
1032 (if (or compilation-read-command current-prefix-arg)
1033 (read-from-minibuffer "Compile 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 (define-key map [stop-subjob]
1292 '("Stop Compilation" . kill-compilation))
1293 (define-key map [compilation-mode-separator2]
1295 (define-key map [compilation-first-error]
1296 '("First Error" . first-error))
1297 (define-key map [compilation-previous-error]
1298 '("Previous Error" . previous-error))
1299 (define-key map [compilation-next-error]
1300 '("Next Error" . next-error))
1303 (defvar compilation-minor-mode-map
1304 (let ((map (make-sparse-keymap)))
1305 (define-key map [mouse-2] 'compile-goto-error)
1306 (define-key map [follow-link] 'mouse-face)
1307 (define-key map "\C-c\C-c" 'compile-goto-error)
1308 (define-key map "\C-m" 'compile-goto-error)
1309 (define-key map "\C-c\C-k" 'kill-compilation)
1310 (define-key map "\M-n" 'compilation-next-error)
1311 (define-key map "\M-p" 'compilation-previous-error)
1312 (define-key map "\M-{" 'compilation-previous-file)
1313 (define-key map "\M-}" 'compilation-next-file)
1314 ;; Set up the menu-bar
1315 (define-key map [menu-bar compilation]
1316 (cons "Errors" compilation-menu-map))
1318 "Keymap for `compilation-minor-mode'.")
1320 (defvar compilation-shell-minor-mode-map
1321 (let ((map (make-sparse-keymap)))
1322 (define-key map "\M-\C-m" 'compile-goto-error)
1323 (define-key map "\M-\C-n" 'compilation-next-error)
1324 (define-key map "\M-\C-p" 'compilation-previous-error)
1325 (define-key map "\M-{" 'compilation-previous-file)
1326 (define-key map "\M-}" 'compilation-next-file)
1327 ;; Set up the menu-bar
1328 (define-key map [menu-bar compilation]
1329 (cons "Errors" compilation-menu-map))
1331 "Keymap for `compilation-shell-minor-mode'.")
1333 (defvar compilation-button-map
1334 (let ((map (make-sparse-keymap)))
1335 (define-key map [mouse-2] 'compile-goto-error)
1336 (define-key map [follow-link] 'mouse-face)
1337 (define-key map "\C-m" 'compile-goto-error)
1339 "Keymap for compilation-message buttons.")
1340 (fset 'compilation-button-map compilation-button-map)
1342 (defvar compilation-mode-map
1343 (let ((map (make-sparse-keymap)))
1344 ;; Don't inherit from compilation-minor-mode-map,
1345 ;; because that introduces a menu bar item we don't want.
1346 ;; That confuses C-down-mouse-3.
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 (define-key map "\t" 'compilation-next-error)
1357 (define-key map [backtab] 'compilation-previous-error)
1359 (define-key map " " 'scroll-up)
1360 (define-key map "\^?" 'scroll-down)
1361 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
1363 ;; Set up the menu-bar
1364 (let ((submap (make-sparse-keymap "Compile")))
1365 (define-key map [menu-bar compilation]
1366 (cons "Compile" submap))
1367 (set-keymap-parent submap compilation-menu-map))
1368 (define-key map [menu-bar compilation compilation-separator2]
1370 (define-key map [menu-bar compilation compilation-grep]
1371 '("Search Files (grep)..." . grep))
1372 (define-key map [menu-bar compilation compilation-recompile]
1373 '("Recompile" . recompile))
1374 (define-key map [menu-bar compilation compilation-compile]
1375 '("Compile..." . compile))
1377 "Keymap for compilation log buffers.
1378 `compilation-minor-mode-map' is a parent of this.")
1380 (put 'compilation-mode 'mode-class 'special)
1383 (defun compilation-mode (&optional name-of-mode)
1384 "Major mode for compilation log buffers.
1385 \\<compilation-mode-map>To visit the source for a line-numbered error,
1386 move point to the error message line and type \\[compile-goto-error].
1387 To kill the compilation, type \\[kill-compilation].
1389 Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
1391 \\{compilation-mode-map}"
1393 (kill-all-local-variables)
1394 (use-local-map compilation-mode-map)
1395 (setq major-mode 'compilation-mode
1396 mode-name (or name-of-mode "Compilation"))
1397 (set (make-local-variable 'page-delimiter)
1398 compilation-page-delimiter)
1400 (setq buffer-read-only t)
1401 (run-mode-hooks 'compilation-mode-hook))
1403 (defmacro define-compilation-mode (mode name doc &rest body)
1404 "This is like `define-derived-mode' without the PARENT argument.
1405 The parent is always `compilation-mode' and the customizable `compilation-...'
1406 variables are also set from the name of the mode you have chosen,
1407 by replacing the first word, e.g `compilation-scroll-output' from
1408 `grep-scroll-output' if that variable exists."
1409 (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
1410 `(define-derived-mode ,mode compilation-mode ,name
1412 ,@(mapcar (lambda (v)
1414 (intern-soft (replace-regexp-in-string
1415 "^compilation" mode-name
1418 (or (boundp (cdr v))
1419 (if (boundp 'byte-compile-bound-variables)
1420 (memq (cdr v) byte-compile-bound-variables)))
1421 `(set (make-local-variable ',(car v)) ,(cdr v))))
1422 '(compilation-buffer-name-function
1423 compilation-directory-matcher
1425 compilation-error-regexp-alist
1426 compilation-error-regexp-alist-alist
1427 compilation-error-screen-columns
1428 compilation-finish-function
1429 compilation-finish-functions
1430 compilation-first-column
1431 compilation-mode-font-lock-keywords
1432 compilation-page-delimiter
1433 compilation-parse-errors-filename-function
1434 compilation-process-setup-function
1435 compilation-scroll-output
1436 compilation-search-path
1437 compilation-skip-threshold
1438 compilation-window-height))
1441 (defun compilation-revert-buffer (ignore-auto noconfirm)
1442 (if buffer-file-name
1443 (let (revert-buffer-function)
1444 (revert-buffer ignore-auto noconfirm))
1445 (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
1446 (apply 'compilation-start compilation-arguments))))
1448 (defvar compilation-current-error nil
1449 "Marker to the location from where the next error will be found.
1450 The global commands next/previous/first-error/goto-error use this.")
1452 (defvar compilation-messages-start nil
1453 "Buffer position of the beginning of the compilation messages.
1454 If nil, use the beginning of buffer.")
1456 ;; A function name can't be a hook, must be something with a value.
1457 (defconst compilation-turn-on-font-lock 'turn-on-font-lock)
1459 (defun compilation-setup (&optional minor)
1460 "Prepare the buffer for the compilation parsing commands to work.
1461 Optional argument MINOR indicates this is called from
1462 `compilation-minor-mode'."
1463 (make-local-variable 'compilation-current-error)
1464 (make-local-variable 'compilation-messages-start)
1465 (make-local-variable 'compilation-error-screen-columns)
1466 (make-local-variable 'overlay-arrow-position)
1467 (set (make-local-variable 'overlay-arrow-string) "")
1468 (setq next-error-overlay-arrow-position nil)
1469 (add-hook 'kill-buffer-hook
1470 (lambda () (setq next-error-overlay-arrow-position nil)) nil t)
1471 ;; Note that compilation-next-error-function is for interfacing
1472 ;; with the next-error function in simple.el, and it's only
1473 ;; coincidentally named similarly to compilation-next-error.
1474 (setq next-error-function 'compilation-next-error-function)
1475 (set (make-local-variable 'comint-file-name-prefix)
1476 (or (file-remote-p default-directory) ""))
1477 (set (make-local-variable 'font-lock-extra-managed-props)
1478 '(directory message help-echo mouse-face debug))
1479 (set (make-local-variable 'compilation-locs)
1480 (make-hash-table :test 'equal :weakness 'value))
1481 ;; lazy-lock would never find the message unless it's scrolled to.
1482 ;; jit-lock might fontify some things too late.
1483 (set (make-local-variable 'font-lock-support-mode) nil)
1484 (set (make-local-variable 'font-lock-maximum-size) nil)
1486 (let ((fld font-lock-defaults))
1487 (font-lock-add-keywords nil (compilation-mode-font-lock-keywords))
1490 (font-lock-fontify-buffer)
1491 (font-lock-change-mode)
1492 (turn-on-font-lock))
1493 (turn-on-font-lock)))
1494 (setq font-lock-defaults '(compilation-mode-font-lock-keywords t))
1495 ;; maybe defer font-lock till after derived mode is set up
1496 (run-mode-hooks 'compilation-turn-on-font-lock)))
1499 (define-minor-mode compilation-shell-minor-mode
1500 "Toggle compilation shell minor mode.
1501 With arg, turn compilation mode on if and only if arg is positive.
1502 In this minor mode, all the error-parsing commands of the
1503 Compilation major mode are available but bound to keys that don't
1504 collide with Shell mode. See `compilation-mode'.
1505 Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
1506 nil " Shell-Compile"
1508 (if compilation-shell-minor-mode
1509 (compilation-setup t)
1510 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1511 (font-lock-fontify-buffer)))
1514 (define-minor-mode compilation-minor-mode
1515 "Toggle compilation minor mode.
1516 With arg, turn compilation mode on if and only if arg is positive.
1517 In this minor mode, all the error-parsing commands of the
1518 Compilation major mode are available. See `compilation-mode'.
1519 Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
1522 (if compilation-minor-mode
1523 (compilation-setup t)
1524 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1525 (font-lock-fontify-buffer)))
1527 (defun compilation-handle-exit (process-status exit-status msg)
1528 "Write MSG in the current buffer and hack its `mode-line-process'."
1529 (let ((inhibit-read-only t)
1530 (status (if compilation-exit-message-function
1531 (funcall compilation-exit-message-function
1532 process-status exit-status msg)
1533 (cons msg exit-status)))
1536 (cur-buffer (current-buffer)))
1537 ;; Record where we put the message, so we can ignore it later on.
1539 (insert ?\n mode-name " " (car status))
1540 (if (and (numberp compilation-window-height)
1541 (zerop compilation-window-height))
1542 (message "%s" (cdr status)))
1545 (insert " at " (substring (current-time-string) 0 19))
1546 (goto-char (point-max))
1547 ;; Prevent that message from being recognized as a compilation error.
1548 (add-text-properties omax (point)
1549 (append '(compilation-handle-exit t) nil))
1550 (setq mode-line-process
1551 (let ((out-string (format ":%s [%s]" process-status (cdr status)))
1552 (tooltip (buffer-substring-no-properties (1+ omax) (point))))
1557 (if (> exit-status 0) 'font-lock-warning-face 'compilation-info))))
1558 (message (format "exit status: %s %s" exit-status (> 0 exit-status)))
1559 ;; Force mode line redisplay soon.
1560 (force-mode-line-update)
1561 (if (and opoint (< opoint omax))
1564 (if compilation-finish-function
1565 (funcall compilation-finish-function cur-buffer msg)))
1566 (run-hook-with-args 'compilation-finish-functions cur-buffer msg)))
1568 ;; Called when compilation process changes state.
1569 (defun compilation-sentinel (proc msg)
1570 "Sentinel for compilation buffers."
1571 (if (memq (process-status proc) '(exit signal))
1572 (let ((buffer (process-buffer proc)))
1573 (if (null (buffer-name buffer))
1575 (set-process-buffer proc nil)
1576 (with-current-buffer buffer
1577 ;; Write something in the compilation buffer
1578 ;; and hack its mode line.
1579 (compilation-handle-exit (process-status proc)
1580 (process-exit-status proc)
1582 ;; Since the buffer and mode line will show that the
1583 ;; process is dead, we can delete it now. Otherwise it
1584 ;; will stay around until M-x list-processes.
1585 (delete-process proc)))
1586 (setq compilation-in-progress (delq proc compilation-in-progress)))))
1588 (defun compilation-filter (proc string)
1589 "Process filter for compilation buffers.
1590 Just inserts the text, but uses `insert-before-markers'."
1591 (if (buffer-name (process-buffer proc))
1592 (with-current-buffer (process-buffer proc)
1593 (let ((inhibit-read-only t))
1595 (goto-char (process-mark proc))
1596 (insert-before-markers string)
1597 (run-hooks 'compilation-filter-hook))))))
1599 ;;; test if a buffer is a compilation buffer, assuming we're in the buffer
1600 (defsubst compilation-buffer-internal-p ()
1601 "Test if inside a compilation buffer."
1602 (local-variable-p 'compilation-locs))
1604 ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p
1605 (defsubst compilation-buffer-p (buffer)
1606 "Test if BUFFER is a compilation buffer."
1607 (with-current-buffer buffer
1608 (compilation-buffer-internal-p)))
1610 (defmacro compilation-loop (< property-change 1+ error limit)
1614 (or (setq pt (,property-change pt 'message))
1615 ;; Handle the case where where the first error message is
1616 ;; at the start of the buffer, and n < 0.
1617 (if (or (eq (get-text-property ,limit 'message)
1618 (get-text-property opt 'message))
1620 (error ,error compilation-error)
1622 ;; prop 'message usually has 2 changes, on and off, so
1624 (or (setq msg (get-text-property pt 'message))
1625 (if (setq pt (,property-change pt 'message nil ,limit))
1626 (setq msg (get-text-property pt 'message)))
1627 (error ,error compilation-error))
1628 (or (< (cadr msg) compilation-skip-threshold)
1630 (eq (prog1 last (setq last (nth 2 (car msg))))
1632 (if compilation-skip-visited
1633 (nthcdr 5 (car msg)))
1634 (if compilation-skip-to-next-location
1636 ;; count this message only if none of the above are true
1637 (setq n (,1+ n))))))
1639 (defun compilation-next-error (n &optional different-file pt)
1640 "Move point to the next error in the compilation buffer.
1641 This function does NOT find the source line like \\[next-error].
1642 Prefix arg N says how many error messages to move forwards (or
1643 backwards, if negative).
1644 Optional arg DIFFERENT-FILE, if non-nil, means find next error for a
1645 file that is different from the current one.
1646 Optional arg PT, if non-nil, specifies the value of point to start
1647 looking for the next message."
1649 (or (compilation-buffer-p (current-buffer))
1650 (error "Not in a compilation buffer"))
1651 (or pt (setq pt (point)))
1652 (let* ((msg (get-text-property pt 'message))
1653 ;; `loc' is used by the compilation-loop macro.
1657 (unless (or msg ; find message near here
1658 (setq msg (get-text-property (max (1- pt) (point-min))
1660 (setq pt (previous-single-property-change pt 'message nil
1661 (line-beginning-position)))
1662 (unless (setq msg (get-text-property (max (1- pt) (point-min)) 'message))
1663 (setq pt (next-single-property-change pt 'message nil
1664 (line-end-position)))
1665 (or (setq msg (get-text-property pt 'message))
1666 (setq pt (point)))))
1667 (setq last (nth 2 (car msg)))
1669 (compilation-loop > next-single-property-change 1-
1670 (if (get-buffer-process (current-buffer))
1672 "Moved past last %s")
1674 ;; Don't move "back" to message at or before point.
1675 ;; Pass an explicit (point-min) to make sure pt is non-nil.
1676 (setq pt (previous-single-property-change pt 'message nil (point-min)))
1677 (compilation-loop < previous-single-property-change 1+
1678 "Moved back before first %s" (point-min))))
1681 (error "No %s here" compilation-error))))
1683 (defun compilation-previous-error (n)
1684 "Move point to the previous error in the compilation buffer.
1685 Prefix arg N says how many error messages to move backwards (or
1686 forwards, if negative).
1687 Does NOT find the source line like \\[previous-error]."
1689 (compilation-next-error (- n)))
1691 (defun compilation-next-file (n)
1692 "Move point to the next error for a different file than the current one.
1693 Prefix arg N says how many files to move forwards (or backwards, if negative)."
1695 (compilation-next-error n t))
1697 (defun compilation-previous-file (n)
1698 "Move point to the previous error for a different file than the current one.
1699 Prefix arg N says how many files to move backwards (or forwards, if negative)."
1701 (compilation-next-file (- n)))
1703 (defun kill-compilation ()
1704 "Kill the process made by the \\[compile] or \\[grep] commands."
1706 (let ((buffer (compilation-find-buffer)))
1707 (if (get-buffer-process buffer)
1708 (interrupt-process (get-buffer-process buffer))
1709 (error "The %s process is not running" (downcase mode-name)))))
1711 (defalias 'compile-mouse-goto-error 'compile-goto-error)
1713 (defun compile-goto-error (&optional event)
1714 "Visit the source for the error message at point.
1715 Use this command in a compilation log buffer. Sets the mark at point there."
1716 (interactive (list last-input-event))
1717 (if event (posn-set-point (event-end event)))
1718 (or (compilation-buffer-p (current-buffer))
1719 (error "Not in a compilation buffer"))
1720 (if (get-text-property (point) 'directory)
1721 (dired-other-window (car (get-text-property (point) 'directory)))
1723 (setq compilation-current-error (point))
1724 (next-error-internal)))
1726 (defun compilation-find-buffer (&optional avoid-current)
1727 "Return a compilation buffer.
1728 If AVOID-CURRENT is nil, and the current buffer is a compilation buffer,
1729 return it. If AVOID-CURRENT is non-nil, return the current buffer only
1731 (if (and (compilation-buffer-internal-p) (not avoid-current))
1733 (next-error-find-buffer avoid-current 'compilation-buffer-internal-p)))
1736 (defun compilation-next-error-function (n &optional reset)
1737 "Advance to the next error message and visit the file where the error was.
1738 This is the value of `next-error-function' in Compilation buffers."
1741 (setq compilation-current-error nil))
1742 (let* ((columns compilation-error-screen-columns) ; buffer's local value
1744 (loc (compilation-next-error (or n 1) nil
1745 (or compilation-current-error
1746 compilation-messages-start
1748 (end-loc (nth 2 loc))
1749 (marker (point-marker)))
1750 (setq compilation-current-error (point-marker)
1751 overlay-arrow-position
1753 compilation-current-error
1754 (copy-marker (line-beginning-position)))
1756 ;; If loc contains no marker, no error in that file has been visited.
1757 ;; If the marker is invalid the buffer has been killed.
1758 ;; If the file is newer than the timestamp, it has been modified
1759 ;; (`omake -P' polls filesystem for changes and recompiles when needed
1760 ;; in the same process and buffer).
1761 ;; So, recalculate all markers for that file.
1762 (unless (and (nth 3 loc) (marker-buffer (nth 3 loc))
1763 ;; There may be no timestamp info if the loc is a `fake-loc'.
1764 ;; So we skip the time-check here, although we should maybe
1765 ;; change `compilation-fake-loc' to add timestamp info.
1766 (or (null (nth 4 loc))
1769 (with-current-buffer
1770 (marker-buffer (nth 3 loc))
1771 (visited-file-modtime))))))
1772 (with-current-buffer (compilation-find-file marker (caar (nth 2 loc))
1773 (cadr (car (nth 2 loc))))
1776 (goto-char (point-min))
1777 ;; Treat file's found lines in forward order, 1 by 1.
1778 (dolist (line (reverse (cddr (nth 2 loc))))
1779 (when (car line) ; else this is a filename w/o a line#
1780 (beginning-of-line (- (car line) last -1))
1781 (setq last (car line)))
1782 ;; Treat line's found columns and store/update a marker for each.
1783 (dolist (col (cdr line))
1785 (if (eq (car col) -1) ; special case for range end
1787 (compilation-move-to-column (car col) columns))
1789 (skip-chars-forward " \t"))
1791 (set-marker (nth 3 col) (point))
1792 (setcdr (nthcdr 2 col) `(,(point-marker)))))))))
1793 (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc))
1794 (setcdr (nthcdr 3 loc) (list timestamp))
1795 (setcdr (nthcdr 4 loc) t))) ; Set this one as visited.
1797 (defvar compilation-gcpro nil
1798 "Internal variable used to keep some values from being GC'd.")
1799 (make-variable-buffer-local 'compilation-gcpro)
1801 (defun compilation-fake-loc (marker file &optional line col)
1802 "Preassociate MARKER with FILE.
1803 FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
1804 This is useful when you compile temporary files, but want
1805 automatic translation of the messages to the real buffer from
1806 which the temporary file came. This only works if done before a
1807 message about FILE appears!
1809 Optional args LINE and COL default to 1 and beginning of
1810 indentation respectively. The marker is expected to reflect
1811 this. In the simplest case the marker points to the first line
1812 of the region that was saved to the temp file.
1814 If you concatenate several regions into the temp file (e.g. a
1815 header with variable assignments and a code region), you must
1816 call this several times, once each for the last line of one
1817 region and the first line of the next region."
1818 (or (consp file) (setq file (list file)))
1819 (setq file (compilation-get-file-structure file))
1820 ;; Between the current call to compilation-fake-loc and the first occurrence
1821 ;; of an error message referring to `file', the data is only kept in the
1822 ;; weak hash-table compilation-locs, so we need to prevent this entry
1823 ;; in compilation-locs from being GC'd away. --Stef
1824 (push file compilation-gcpro)
1825 (let ((loc (compilation-assq (or line 1) (cdr file))))
1826 (setq loc (compilation-assq col loc))
1828 (setcdr (cddr loc) (list marker))
1829 (setcdr loc (list line file marker)))
1832 (defcustom compilation-context-lines nil
1833 "Display this many lines of leading context before the current message.
1834 If nil and the left fringe is displayed, don't scroll the
1835 compilation output window; an arrow in the left fringe points to
1836 the current message. If nil and there is no left fringe, the message
1837 displays at the top of the window; there is no arrow."
1838 :type '(choice integer (const :tag "No window scrolling" nil))
1842 (defsubst compilation-set-window (w mk)
1843 "Align the compilation output window W with marker MK near top."
1844 (if (integerp compilation-context-lines)
1845 (set-window-start w (save-excursion
1848 (- 1 compilation-context-lines))
1850 ;; If there is no left fringe.
1851 (if (equal (car (window-fringes)) 0)
1852 (set-window-start w (save-excursion
1854 (beginning-of-line 1)
1856 (set-window-point w mk))
1858 (defvar next-error-highlight-timer)
1860 (defun compilation-goto-locus (msg mk end-mk)
1861 "Jump to an error corresponding to MSG at MK.
1862 All arguments are markers. If END-MK is non-nil, mark is set there
1863 and overlay is highlighted between MK and END-MK."
1864 ;; Show compilation buffer in other window, scrolled to this error.
1865 (let* ((from-compilation-buffer (eq (window-buffer (selected-window))
1866 (marker-buffer msg)))
1867 ;; Use an existing window if it is in a visible frame.
1868 (pre-existing (get-buffer-window (marker-buffer msg) 0))
1869 (w (if (and from-compilation-buffer pre-existing)
1870 ;; Calling display-buffer here may end up (partly) hiding
1871 ;; the error location if the two buffers are in two
1872 ;; different frames. So don't do it if it's not necessary.
1874 (let ((display-buffer-reuse-frames t)
1877 (display-buffer (marker-buffer msg)))))
1878 (highlight-regexp (with-current-buffer (marker-buffer msg)
1879 ;; also do this while we change buffer
1880 (compilation-set-window w msg)
1881 compilation-highlight-regexp)))
1882 ;; Ideally, the window-size should be passed to `display-buffer' (via
1883 ;; something like special-display-buffer) so it's only used when
1884 ;; creating a new window.
1885 (unless pre-existing (compilation-set-window-height w))
1887 (if from-compilation-buffer
1888 ;; If the compilation buffer window was selected,
1889 ;; keep the compilation buffer in this window;
1890 ;; display the source in another window.
1891 (let ((pop-up-windows t))
1892 (pop-to-buffer (marker-buffer mk) 'other-window))
1893 (if (window-dedicated-p (selected-window))
1894 (pop-to-buffer (marker-buffer mk))
1895 (switch-to-buffer (marker-buffer mk))))
1896 ;; If narrowing gets in the way of going to the right place, widen.
1897 (unless (eq (goto-char mk) (point))
1901 (push-mark end-mk t)
1902 (if mark-active (setq mark-active)))
1903 ;; If hideshow got in the way of
1904 ;; seeing the right place, open permanently.
1905 (dolist (ov (overlays-at (point)))
1906 (when (eq 'hs (overlay-get ov 'invisible))
1910 (when highlight-regexp
1911 (if (timerp next-error-highlight-timer)
1912 (cancel-timer next-error-highlight-timer))
1913 (unless compilation-highlight-overlay
1914 (setq compilation-highlight-overlay
1915 (make-overlay (point-min) (point-min)))
1916 (overlay-put compilation-highlight-overlay 'face 'next-error))
1917 (with-current-buffer (marker-buffer mk)
1919 (if end-mk (goto-char end-mk) (end-of-line))
1920 (let ((end (point)))
1921 (if mk (goto-char mk) (beginning-of-line))
1922 (if (and (stringp highlight-regexp)
1923 (re-search-forward highlight-regexp end t))
1925 (goto-char (match-beginning 0))
1926 (move-overlay compilation-highlight-overlay
1927 (match-beginning 0) (match-end 0)
1929 (move-overlay compilation-highlight-overlay
1930 (point) end (current-buffer)))
1931 (if (or (eq next-error-highlight t)
1932 (numberp next-error-highlight))
1933 ;; We want highlighting: delete overlay on next input.
1934 (add-hook 'pre-command-hook
1935 'compilation-goto-locus-delete-o)
1936 ;; We don't want highlighting: delete overlay now.
1937 (delete-overlay compilation-highlight-overlay))
1938 ;; We want highlighting for a limited time:
1939 ;; set up a timer to delete it.
1940 (when (numberp next-error-highlight)
1941 (setq next-error-highlight-timer
1942 (run-at-time next-error-highlight nil
1943 'compilation-goto-locus-delete-o)))))))
1944 (when (and (eq next-error-highlight 'fringe-arrow))
1945 ;; We want a fringe arrow (instead of highlighting).
1946 (setq next-error-overlay-arrow-position
1947 (copy-marker (line-beginning-position))))))
1949 (defun compilation-goto-locus-delete-o ()
1950 (delete-overlay compilation-highlight-overlay)
1951 ;; Get rid of timer and hook that would try to do this again.
1952 (if (timerp next-error-highlight-timer)
1953 (cancel-timer next-error-highlight-timer))
1954 (remove-hook 'pre-command-hook
1955 'compilation-goto-locus-delete-o))
1957 (defun compilation-find-file (marker filename directory &rest formats)
1958 "Find a buffer for file FILENAME.
1959 If FILENAME is not found at all, ask the user where to find it.
1960 Pop up the buffer containing MARKER and scroll to MARKER if we ask
1961 the user where to find the file.
1962 Search the directories in `compilation-search-path'.
1963 A nil in `compilation-search-path' means to try the
1964 \"current\" directory, which is passed in DIRECTORY.
1965 If DIRECTORY is relative, it is combined with `default-directory'.
1966 If DIRECTORY is nil, that means use `default-directory'.
1967 FORMATS, if given, is a list of formats to reformat FILENAME when
1968 looking for it: for each element FMT in FORMATS, this function
1969 attempts to find a file whose name is produced by (format FMT FILENAME)."
1970 (or formats (setq formats '("%s")))
1971 (let ((dirs compilation-search-path)
1972 (spec-dir (if directory
1973 (expand-file-name directory)
1975 buffer thisdir fmts name)
1976 (if (file-name-absolute-p filename)
1977 ;; The file name is absolute. Use its explicit directory as
1978 ;; the first in the search path, and strip it from FILENAME.
1979 (setq filename (abbreviate-file-name (expand-file-name filename))
1980 dirs (cons (file-name-directory filename) dirs)
1981 filename (file-name-nondirectory filename)))
1982 ;; Now search the path.
1983 (while (and dirs (null buffer))
1984 (setq thisdir (or (car dirs) spec-dir)
1986 ;; For each directory, try each format string.
1987 (while (and fmts (null buffer))
1988 (setq name (expand-file-name (format (car fmts) filename) thisdir)
1989 buffer (and (file-exists-p name)
1990 (find-file-noselect name))
1992 (setq dirs (cdr dirs)))
1993 (while (null buffer) ;Repeat until the user selects an existing file.
1994 ;; The file doesn't exist. Ask the user where to find it.
1995 (save-excursion ;This save-excursion is probably not right.
1996 (let ((pop-up-windows t))
1997 (compilation-set-window (display-buffer (marker-buffer marker))
1999 (let* ((name (read-file-name
2000 (format "Find this %s in (default %s): "
2001 compilation-error filename)
2002 spec-dir filename t nil
2003 ;; The predicate below is fine when called from
2004 ;; minibuffer-complete-and-exit, but it's too
2005 ;; restrictive otherwise, since it also prevents the
2006 ;; user from completing "fo" to "foo/" when she
2007 ;; wants to enter "foo/bar".
2009 ;; Try to make sure the user can only select
2010 ;; a valid answer. This predicate may be ignored,
2011 ;; tho, so we still have to double-check afterwards.
2012 ;; TODO: We should probably fix read-file-name so
2013 ;; that it never ignores this predicate, even when
2014 ;; using popup dialog boxes.
2016 ;; (if (file-directory-p name)
2017 ;; (setq name (expand-file-name filename name)))
2018 ;; (file-exists-p name))
2022 ((not (file-exists-p name))
2023 (message "Cannot find file `%s'" name)
2025 ((and (file-directory-p name)
2027 (setq name (expand-file-name filename name)))))
2028 (message "No `%s' in directory %s" filename origname)
2031 (setq buffer (find-file-noselect name))))))))
2032 ;; Make intangible overlays tangible.
2033 ;; This is weird: it's not even clear which is the current buffer,
2034 ;; so the code below can't be expected to DTRT here. -- Stef
2035 (dolist (ov (overlays-in (point-min) (point-max)))
2036 (when (overlay-get ov 'intangible)
2037 (overlay-put ov 'intangible nil)))
2040 (defun compilation-get-file-structure (file &optional fmt)
2041 "Retrieve FILE's file-structure or create a new one.
2042 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
2043 In the former case, FILENAME may be relative or absolute.
2045 The file-structure looks like this:
2046 (list (list FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)"
2047 (or (gethash file compilation-locs)
2048 ;; File was not previously encountered, at least not in the form passed.
2049 ;; Let's normalize it and look again.
2050 (let ((filename (car file))
2051 ;; Get the specified directory from FILE.
2052 (spec-directory (if (cdr file)
2053 (file-truename (cdr file)))))
2055 ;; Check for a comint-file-name-prefix and prepend it if appropriate.
2056 ;; (This is very useful for compilation-minor-mode in an rlogin-mode
2058 (when (and (boundp 'comint-file-name-prefix)
2059 (not (equal comint-file-name-prefix "")))
2060 (if (file-name-absolute-p filename)
2062 (concat comint-file-name-prefix filename))
2064 (setq spec-directory
2066 (concat comint-file-name-prefix spec-directory))))))
2068 ;; If compilation-parse-errors-filename-function is
2069 ;; defined, use it to process the filename.
2070 (when compilation-parse-errors-filename-function
2072 (funcall compilation-parse-errors-filename-function
2075 ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
2076 ;; file names like "./bar//foo.c" for file "bar/foo.c";
2077 ;; expand-file-name will collapse these into "/foo.c" and fail to find
2078 ;; the appropriate file. So we look for doubled slashes in the file
2079 ;; name and fix them.
2080 (setq filename (command-line-normalize-file-name filename))
2082 ;; Store it for the possibly unnormalized name
2084 ;; Retrieve or create file-structure for normalized name
2085 ;; The gethash used to not use spec-directory, but
2086 ;; this leads to errors when files in different
2087 ;; directories have the same name:
2088 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00463.html
2089 (or (gethash (cons filename spec-directory) compilation-locs)
2090 (puthash (cons filename spec-directory)
2091 (list (list filename spec-directory) fmt)
2093 compilation-locs))))
2095 (add-to-list 'debug-ignored-errors "^No more [-a-z ]+s yet$")
2097 ;;; Compatibility with the old compile.el.
2099 (defun compile-buffer-substring (n) (if n (match-string n)))
2101 (defun compilation-compat-error-properties (err)
2102 "Map old-style error ERR to new-style message."
2103 ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
2104 ;; (MARKER . MARKER).
2105 (let ((dst (cdr err)))
2107 ;; Must start with a face, for font-lock.
2109 message ,(list (list nil nil nil dst) 2)
2110 help-echo "mouse-2: visit the source location"
2111 keymap compilation-button-map
2112 mouse-face highlight)
2113 ;; Too difficult to do it by hand: dispatch to the normal code.
2114 (let* ((file (pop dst))
2117 (filename (pop file))
2118 (dirname (pop file))
2120 (compilation-internal-error-properties
2121 (cons filename dirname) line nil col nil 2 fmt)))))
2123 (defun compilation-compat-parse-errors (limit)
2124 (when compilation-parse-errors-function
2125 ;; FIXME: We should remove the rest of the compilation keywords
2126 ;; but we can't do that from here because font-lock is using
2127 ;; the value right now. --stef
2129 (setq compilation-error-list nil)
2130 ;; Reset compilation-parsing-end each time because font-lock
2131 ;; might force us the re-parse many times (typically because
2132 ;; some code adds some text-property to the output that we
2133 ;; already parsed). You might say "why reparse", well:
2134 ;; because font-lock has just removed the `message' property so
2135 ;; have to do it all over again.
2136 (if compilation-parsing-end
2137 (set-marker compilation-parsing-end (point))
2138 (setq compilation-parsing-end (point-marker)))
2140 ;; Ignore any error: we're calling this function earlier than
2141 ;; in the old compile.el so things might not all be setup yet.
2142 (funcall compilation-parse-errors-function limit nil)
2144 (dolist (err (if (listp compilation-error-list) compilation-error-list))
2145 (let* ((src (car err))
2147 (loc (cond ((markerp dst) (list nil nil nil dst))
2149 (list (nth 2 dst) (nth 1 dst)
2150 (cons (cdar dst) (caar dst)))))))
2153 ;; (put-text-property src (line-end-position) 'font-lock-face 'font-lock-warning-face)
2154 (put-text-property src (line-end-position)
2155 'message (list loc 2)))))))
2159 ;; Beware: this is not only compatiblity code. New code stil uses it. --Stef
2160 (defun compilation-forget-errors ()
2161 ;; In case we hit the same file/line specs, we want to recompute a new
2162 ;; marker for them, so flush our cache.
2163 (setq compilation-locs (make-hash-table :test 'equal :weakness 'value))
2164 (setq compilation-gcpro nil)
2165 ;; FIXME: the old code reset the directory-stack, so maybe we should
2166 ;; put a `directory change' marker of some sort, but where? -stef
2168 ;; FIXME: The old code moved compilation-current-error (which was
2169 ;; virtually represented by a mix of compilation-parsing-end and
2170 ;; compilation-error-list) to point-min, but that was only meaningful for
2171 ;; the internal uses of compilation-forget-errors: all calls from external
2172 ;; packages seem to be followed by a move of compilation-parsing-end to
2173 ;; something equivalent to point-max. So we heuristically move
2174 ;; compilation-current-error to point-max (since the external package
2175 ;; won't know that it should do it). --Stef
2176 (setq compilation-current-error nil)
2177 (let* ((proc (get-buffer-process (current-buffer)))
2178 (mark (if proc (process-mark proc)))
2179 (pos (or mark (point-max))))
2180 (setq compilation-messages-start
2181 ;; In the future, ignore the text already present in the buffer.
2182 ;; Since many process filter functions insert before markers,
2183 ;; we need to put ours just before the insertion point rather
2184 ;; than at the insertion point. If that's not possible, then
2185 ;; don't use a marker. --Stef
2186 (if (> pos (point-min)) (copy-marker (1- pos)) pos)))
2187 ;; Again, since this command is used in buffers that contain several
2188 ;; compilations, to set the beginning of "this compilation", it's a good
2189 ;; place to reset compilation-auto-jump-to-next.
2190 (set (make-local-variable 'compilation-auto-jump-to-next)
2191 (or compilation-auto-jump-to-first-error
2192 (eq compilation-scroll-output 'first-error))))
2195 (add-to-list 'auto-mode-alist '("\\.gcov\\'" . compilation-mode))
2199 ;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c
2200 ;;; compile.el ends here