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 Free Software Foundation, Inc.
6 ;; Authors: Roland McGrath <roland@gnu.org>,
7 ;; Daniel Pfeiffer <occitan@esperanto.org>
9 ;; Keywords: tools, processes
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
30 ;; This package provides the compile facilities documented in the Emacs user's
33 ;; This mode uses some complex data-structures:
35 ;; LOC (or location) is a list of (COLUMN LINE FILE-STRUCTURE)
37 ;; COLUMN and LINE are numbers parsed from an error message. COLUMN and maybe
38 ;; LINE will be nil for a message that doesn't contain them. Then the
39 ;; location refers to a indented beginning of line or beginning of file.
40 ;; Once any location in some file has been jumped to, the list is extended to
41 ;; (COLUMN LINE FILE-STRUCTURE MARKER . VISITED) for all LOCs pertaining to
43 ;; MARKER initially points to LINE and COLUMN in a buffer visiting that file.
44 ;; Being a marker it sticks to some text, when the buffer grows or shrinks
45 ;; before that point. VISITED is t if we have jumped there, else nil.
47 ;; FILE-STRUCTURE is a list of
48 ;; ((FILENAME . DIRECTORY) FORMATS (LINE LOC ...) ...)
50 ;; FILENAME is a string parsed from an error message. DIRECTORY is a string
51 ;; obtained by following directory change messages. DIRECTORY will be nil for
52 ;; an absolute filename. FORMATS is a list of formats to apply to FILENAME if
53 ;; a file of that name can't be found.
54 ;; The rest of the list is an alist of elements with LINE as key. The keys
55 ;; are either nil or line numbers. If present, nil comes first, followed by
56 ;; the numbers in decreasing order. The LOCs for each line are again an alist
57 ;; ordered the same way. Note that the whole file structure is referenced in
60 ;; MESSAGE is a list of (LOC TYPE END-LOC)
62 ;; TYPE is 0 for info or 1 for warning if the message matcher identified it as
63 ;; such, 2 otherwise (for a real error). END-LOC is a LOC pointing to the
64 ;; other end, if the parsed message contained a range. If the end of the
65 ;; range didn't specify a COLUMN, it defaults to -1, meaning end of line.
66 ;; These are the value of the `message' text-properties in the compilation
71 (eval-when-compile (require 'cl))
73 (defvar font-lock-extra-managed-props)
74 (defvar font-lock-keywords)
75 (defvar font-lock-maximum-size)
76 (defvar font-lock-support-mode)
79 (defgroup compilation nil
80 "Run compiler as inferior of Emacs, parse error messages."
86 (defcustom compilation-mode-hook nil
87 "*List of hook functions run by `compilation-mode' (see `run-mode-hooks')."
92 (defcustom compilation-window-height nil
93 "*Number of lines in a compilation window. If nil, use Emacs default."
94 :type '(choice (const :tag "Default" nil)
98 (defvar compilation-first-column 1
99 "*This is how compilers number the first column, usually 1 or 0.")
101 (defvar compilation-parse-errors-filename-function nil
102 "Function to call to post-process filenames while parsing error messages.
103 It takes one arg FILENAME which is the name of a file as found
104 in the compilation output, and should return a transformed file name.")
107 (defvar compilation-process-setup-function nil
108 "*Function to call to customize the compilation process.
109 This function is called immediately before the compilation process is
110 started. It can be used to set any variables or functions that are used
111 while processing the output of the compilation process. The function
112 is called with variables `compilation-buffer' and `compilation-window'
113 bound to the compilation buffer and window, respectively.")
116 (defvar compilation-buffer-name-function nil
117 "Function to compute the name of a compilation buffer.
118 The function receives one argument, the name of the major mode of the
119 compilation buffer. It should return a string.
120 nil means compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
123 (defvar compilation-finish-function nil
124 "Function to call when a compilation process finishes.
125 It is called with two arguments: the compilation buffer, and a string
126 describing how the process finished.")
128 (make-obsolete-variable 'compilation-finish-function
129 "Use `compilation-finish-functions', but it works a little differently."
133 (defvar compilation-finish-functions nil
134 "Functions to call when a compilation process finishes.
135 Each function is called with two arguments: the compilation buffer,
136 and a string describing how the process finished.")
138 (defvar compilation-in-progress nil
139 "List of compilation processes now running.")
140 (or (assq 'compilation-in-progress minor-mode-alist)
141 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
144 (defvar compilation-error "error"
145 "Stem of message to print when no matches are found.")
147 (defvar compilation-arguments nil
148 "Arguments that were given to `compilation-start'.")
150 (defvar compilation-num-errors-found)
152 (defconst compilation-error-regexp-alist-alist
154 "^\\(?:[Ee]rror on \\|[Ww]arning on\\( \\)\\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
155 of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil (1))
158 "\\(warning: .*\\)? at \\([^ \n]+\\):\\([0-9]+\\)$" 2 3 nil (1))
161 " in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
164 "^[ \t]*\\[[^] \n]+\\][ \t]*\\([^: \n]+\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):[0-9]+:[0-9]+:\\)?\
165 \\( warning\\)?" 1 2 3 (4))
168 "^\\([^: \n\t]+\\): line \\([0-9]+\\):" 1 2)
171 "^\\(?:Error\\|Warnin\\(g\\)\\) \\(?:[FEW][0-9]+ \\)?\
172 \\([a-zA-Z]?:?[^:( \t\n]+\\)\
173 \\([0-9]+\\)\\(?:[) \t]\\|:[^0-9\n]\\)" 2 3 nil (1))
176 "^ *File \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1, lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
177 \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:\\)?\\([ \n]Warning:\\)?\\)"
178 2 (3 . 4) (5 . 6) (7))
181 "^\"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)\
182 \\(?:[(. pos]+\\([0-9]+\\))?\\)?[:.,; (-]\\( warning:\\|[-0-9 ]*(W)\\)?" 1 2 3 (4))
185 "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
188 "at line \\([0-9]+\\) of \"\\([^ \n]+\\)\"$"
192 "^Error [0-9]+ at (\\([0-9]+\\):\\([^)\n]+\\))" 2 1)
195 "\\(^Warning .*\\)? line[ \n]\\([0-9]+\\)[ \n]\\(?:col \\([0-9]+\\)[ \n]\\)?file \\([^ :;\n]+\\)"
199 "^\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(?:Error\\|Warnin\\(g\\)\\)\\[[0-9]+\\]:"
203 "^\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) :\
204 \\(?:warnin\\(g\\)\\|informationa\\(l\\)\\)?" 1 2 3 (4 . 5))
206 ;; fixme: should be `mips'
208 "^[-[:alnum:]_/ ]+: \\(?:\\(?:[sS]evere\\|[eE]rror\\|[wW]arnin\\(g\\)\\|[iI]nf\\(o\\)\\)[0-9 ]*: \\)?\
209 \\([^,\" \n\t]+\\)\\(?:, line\\|:\\) \\([0-9]+\\):" 3 4 nil (1 . 2))
212 "^\\(?:[ \t]+at \\|==[0-9]+== +\\(?:at\\|b\\(y\\)\\)\\).+(\\([^()\n]+\\):\\([0-9]+\\))$" 2 3 nil (1))
215 "^\\(?:Found\\|Issued\\) .* compiling \"\\(.+\\)\":$" 1 nil nil 0)
217 "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)"
219 (2 (compilation-face '(3))))
222 "^\\(?:In file included\\| \\) from \
223 \\(.+\\):\\([0-9]+\\)\\(?:\\(:\\)\\|\\(,\\)\\)?" 1 2 nil (3 . 4))
226 "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\)?\
227 \\([/.]*[a-zA-Z]:?[^ \t\n:]*\\|{standard input}\\): ?\
228 \\([0-9]+\\)\\([.:]?\\)\\([0-9]+\\)?\
229 \\(?:-\\(?:\\([0-9]+\\)\\3\\)?\\.?\\([0-9]+\\)?\\)?:\
230 \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\
231 *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\)\\)?"
232 1 (2 . 5) (4 . 6) (7 . 8))
235 "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)"
239 "^makepp: \\(?:\\(?:warning\\(:\\).*?\\|\\(Scanning\\|[LR]e?l?oading makefile\\|Imported\\) \\|.*?\\)\
240 `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)"
242 ("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]" nil nil
243 (2 compilation-info-face)
244 (3 compilation-line-face nil t)
245 (1 (compilation-error-properties 2 3 nil nil nil 0 nil)
248 ;; Should be lint-1, lint-2 (SysV lint)
250 " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
252 " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2)
255 "^\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
256 : \\(?:error\\|warnin\\(g\\)\\) C[0-9]+:" 2 3 nil (4))
259 "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
260 \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
261 \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
265 " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\)" 1 2)
268 "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
269 \\([0-9]+\\) of file://\\(.+\\)"
273 "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
274 [12][09][0-9][0-9] +\\(.*\\):$"
277 "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
278 nil 3 nil (2) nil (1 (compilation-face '(2))))
279 (sparc-pascal-example
280 "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
281 nil 1 nil (3) nil (2 (compilation-face '(3))))
284 ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
285 File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
289 "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
292 "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
293 \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3))
296 "^ *-: *\\(0\\):Source:\\(.+\\)$"
298 (1 compilation-line-face prepend) (2 compilation-info-face prepend))
300 "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
302 (1 compilation-line-face prepend))
303 ;; Underlines over all lines of gcov output are too uncomfortable to read.
304 ;; However, hyperlinks embedded in the lines are useful.
305 ;; So I put default face on the lines; and then put
306 ;; compilation-*-face by manually to eliminate the underlines.
307 ;; The hyperlinks are still effective.
309 "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
312 (1 compilation-line-face prepend))
314 "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
317 (1 compilation-info-face prepend) (2 compilation-line-face prepend))
319 "^ *\\(#####\\): *\\([0-9]+\\):.*$"
322 (1 compilation-error-face prepend) (2 compilation-line-face prepend))
324 "Alist of values for `compilation-error-regexp-alist'.")
326 (defcustom compilation-error-regexp-alist
327 (mapcar 'car compilation-error-regexp-alist-alist)
328 "Alist that specifies how to match errors in compiler output.
329 On GNU and Unix, any string is a valid filename, so these
330 matchers must make some common sense assumptions, which catch
331 normal cases. A shorter list will be lighter on resource usage.
333 Instead of an alist element, you can use a symbol, which is
334 looked up in `compilation-error-regexp-alist-alist'. You can see
335 the predefined symbols and their effects in the file
336 `etc/compilation.txt' (linked below if you are customizing this).
338 Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
339 HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
340 gives the file name, and the LINE'th subexpression gives the line
341 number. The COLUMN'th subexpression gives the column number on
344 If FILE, LINE or COLUMN are nil or that index didn't match, that
345 information is not present on the matched line. In that case the
346 file name is assumed to be the same as the previous one in the
347 buffer, line number defaults to 1 and column defaults to
348 beginning of line's indentation.
350 FILE can also have the form (FILE FORMAT...), where the FORMATs
351 \(e.g. \"%s.c\") will be applied in turn to the recognized file
352 name, until a file of that name is found. Or FILE can also be a
353 function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
354 In the former case, FILENAME may be relative or absolute.
356 LINE can also be of the form (LINE . END-LINE) meaning a range
357 of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
358 meaning a range of columns starting on LINE and ending on
359 END-LINE, if that matched.
361 TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
362 TYPE can also be of the form (WARNING . INFO). In that case this
363 will be equivalent to 1 if the WARNING'th subexpression matched
364 or else equivalent to 0 if the INFO'th subexpression matched.
365 See `compilation-error-face', `compilation-warning-face',
366 `compilation-info-face' and `compilation-skip-threshold'.
368 What matched the HYPERLINK'th subexpression has `mouse-face' and
369 `compilation-message-face' applied. If this is nil, the text
370 matched by the whole REGEXP becomes the hyperlink.
372 Additional HIGHLIGHTs as described under `font-lock-keywords' can
374 :type `(set :menu-tag "Pick"
375 ,@(mapcar (lambda (elt)
376 (list 'const (car elt)))
377 compilation-error-regexp-alist-alist))
378 :link `(file-link :tag "example file"
379 ,(expand-file-name "compilation.txt" data-directory))
382 (defvar compilation-directory nil
383 "Directory to restore to when doing `recompile'.")
385 (defvar compilation-directory-matcher
386 '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1))
387 "A list for tracking when directories are entered or left.
388 Nil means not to track directories, e.g. if all file names are absolute. The
389 first element is the REGEXP matching these messages. It can match any number
390 of variants, e.g. different languages. The remaining elements are all of the
391 form (DIR . LEAVE). If for any one of these the DIR'th subexpression
392 matches, that is a directory name. If LEAVE is nil or the corresponding
393 LEAVE'th subexpression doesn't match, this message is about going into another
394 directory. If it does match anything, this message is about going back to the
395 directory we were in before the last entering message. If you change this,
396 you may also want to change `compilation-page-delimiter'.")
398 (defvar compilation-page-delimiter
399 "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
400 "Value of `page-delimiter' in Compilation mode.")
402 (defvar compilation-mode-font-lock-keywords
403 '(;; configure output lines.
404 ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
405 (1 font-lock-variable-name-face)
406 (2 (compilation-face '(4 . 3))))
407 ;; Command output lines. Recognize `make[n]:' lines too.
408 ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
409 (1 font-lock-function-name-face) (3 compilation-line-face nil t))
410 (" --?o\\(?:utfile\\|utput\\)?[= ]?\\(\\S +\\)" . 1)
411 ("^Compilation \\(finished\\)"
412 (1 compilation-info-face))
413 ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\)\\(?:.*with code \\([0-9]+\\)\\)?"
414 (1 compilation-error-face)
415 (2 compilation-error-face nil t)))
416 "Additional things to highlight in Compilation mode.
417 This gets tacked on the end of the generated expressions.")
419 (defvar compilation-highlight-regexp t
420 "Regexp matching part of visited source lines to highlight temporarily.
421 Highlight entire line if t; don't highlight source lines if nil.")
423 (defvar compilation-highlight-overlay nil
424 "Overlay used to temporarily highlight compilation matches.")
426 (defcustom compilation-error-screen-columns t
427 "*If non-nil, column numbers in error messages are screen columns.
428 Otherwise they are interpreted as character positions, with
429 each character occupying one column.
430 The default is to use screen columns, which requires that the compilation
431 program and Emacs agree about the display width of the characters,
432 especially the TAB character."
437 (defcustom compilation-read-command t
438 "*Non-nil means \\[compile] reads the compilation command to use.
439 Otherwise, \\[compile] just uses the value of `compile-command'."
444 (defcustom compilation-ask-about-save t
445 "*Non-nil means \\[compile] asks which buffers to save before compiling.
446 Otherwise, it saves all modified buffers without asking."
451 (defcustom compilation-search-path '(nil)
452 "*List of directories to search for source files named in error messages.
453 Elements should be directory names, not file names of directories.
454 nil as an element means to try the default directory."
455 :type '(repeat (choice (const :tag "Default" nil)
456 (string :tag "Directory")))
460 (defcustom compile-command "make -k "
461 "*Last shell command used to do a compilation; default for next compilation.
463 Sometimes it is useful for files to supply local values for this variable.
464 You might also use mode hooks to specify it in certain modes, like this:
466 (add-hook 'c-mode-hook
468 (unless (or (file-exists-p \"makefile\")
469 (file-exists-p \"Makefile\"))
470 (set (make-local-variable 'compile-command)
472 (file-name-sans-extension buffer-file-name))))))"
475 ;;;###autoload(put 'compile-command 'safe-local-variable 'stringp)
478 (defcustom compilation-disable-input nil
479 "*If non-nil, send end-of-file as compilation process input.
480 This only affects platforms that support asynchronous processes (see
481 `start-process'); synchronous compilation processes never accept input."
486 ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
487 ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
488 ;; key. This holds the tree seen from root, for storing new nodes.
489 (defvar compilation-locs ())
491 (defvar compilation-debug nil
492 "*Set this to t before creating a *compilation* buffer.
493 Then every error line will have a debug text property with the matcher that
494 fit this line and the match data. Use `describe-text-properties'.")
496 (defvar compilation-exit-message-function nil "\
497 If non-nil, called when a compilation process dies to return a status message.
498 This should be a function of three arguments: process status, exit status,
499 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
500 write into the compilation buffer, and to put in its mode line.")
502 (defvar compilation-environment nil
503 "*List of environment variables for compilation to inherit.
504 Each element should be a string of the form ENVVARNAME=VALUE.
505 This list is temporarily prepended to `process-environment' prior to
506 starting the compilation process.")
508 ;; History of compile commands.
509 (defvar compile-history nil)
511 (defface compilation-error
512 '((t :inherit font-lock-warning-face))
513 "Face used to highlight compiler errors."
517 (defface compilation-warning
518 '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
519 (((class color)) (:foreground "cyan" :weight bold))
521 "Face used to highlight compiler warnings."
525 (defface compilation-info
526 '((((class color) (min-colors 16) (background light))
527 (:foreground "Green3" :weight bold))
528 (((class color) (min-colors 88) (background dark))
529 (:foreground "Green1" :weight bold))
530 (((class color) (min-colors 16) (background dark))
531 (:foreground "Green" :weight bold))
532 (((class color)) (:foreground "green" :weight bold))
534 "Face used to highlight compiler information."
538 (defface compilation-line-number
539 '((t :inherit font-lock-variable-name-face))
540 "Face for displaying line numbers in compiler messages."
544 (defface compilation-column-number
545 '((t :inherit font-lock-type-face))
546 "Face for displaying column numbers in compiler messages."
550 (defcustom compilation-message-face 'underline
551 "Face name to use for whole messages.
552 Faces `compilation-error-face', `compilation-warning-face',
553 `compilation-info-face', `compilation-line-face' and
554 `compilation-column-face' get prepended to this, when applicable."
559 (defvar compilation-error-face 'compilation-error
560 "Face name to use for file name in error messages.")
562 (defvar compilation-warning-face 'compilation-warning
563 "Face name to use for file name in warning messages.")
565 (defvar compilation-info-face 'compilation-info
566 "Face name to use for file name in informational messages.")
568 (defvar compilation-line-face 'compilation-line-number
569 "Face name to use for line numbers in compiler messages.")
571 (defvar compilation-column-face 'compilation-column-number
572 "Face name to use for column numbers in compiler messages.")
574 ;; same faces as dired uses
575 (defvar compilation-enter-directory-face 'font-lock-function-name-face
576 "Face name to use for entering directory messages.")
578 (defvar compilation-leave-directory-face 'font-lock-type-face
579 "Face name to use for leaving directory messages.")
583 ;; Used for compatibility with the old compile.el.
584 (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
585 (defvar compilation-parsing-end (make-marker))
586 (defvar compilation-parse-errors-function nil)
587 (defvar compilation-error-list nil)
588 (defvar compilation-old-error-list nil)
590 (defun compilation-face (type)
591 (or (and (car type) (match-end (car type)) compilation-warning-face)
592 (and (cdr type) (match-end (cdr type)) compilation-info-face)
593 compilation-error-face))
595 ;; Internal function for calculating the text properties of a directory
596 ;; change message. The directory property is important, because it is
597 ;; the stack of nested enter-messages. Relative filenames on the following
598 ;; lines are relative to the top of the stack.
599 (defun compilation-directory-properties (idx leave)
600 (if leave (setq leave (match-end leave)))
601 ;; find previous stack, and push onto it, or if `leave' pop it
602 (let ((dir (previous-single-property-change (point) 'directory)))
603 (setq dir (if dir (or (get-text-property (1- dir) 'directory)
604 (get-text-property dir 'directory))))
606 compilation-leave-directory-face
607 compilation-enter-directory-face)
610 '(nil)) ; nil only isn't a property-change
611 (cons (match-string-no-properties idx) dir))
613 keymap compilation-button-map
614 help-echo "mouse-2: visit current directory")))
616 ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
617 ;; KEY element from the ALIST, creating it in the right position if not already
618 ;; present. ALIST structure is
619 ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
620 ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
621 ;; may be nil. The other KEYs are ordered backwards so that growing line
622 ;; numbers can be inserted in front and searching can abort after half the
624 (eval-when-compile ;Don't keep it at runtime if not needed.
625 (defmacro compilation-assq (key alist)
628 (car (if (if (null ,key)
629 (if l2 (null (caar l2)))
630 (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
633 (if l2 (eq ,key (caar l2))))
635 (setcdr l1 (cons (list ,key) l2)))))))
638 ;; This function is the central driver, called when font-locking to gather
639 ;; all information needed to later jump to corresponding source code.
640 ;; Return a property list with all meta information on this error location.
642 (defun compilation-error-properties (file line end-line col end-col type fmt)
643 (unless (< (next-single-property-change (match-beginning 0) 'directory nil (point))
647 (setq file (funcall file))
649 (setq file (match-string-no-properties file))
650 (unless (file-name-absolute-p file)
651 (setq dir (previous-single-property-change (point) 'directory)
652 dir (if dir (or (get-text-property (1- dir) 'directory)
653 (get-text-property dir 'directory)))))
654 (setq file (cons file (car dir)))))
655 ;; This message didn't mention one, get it from previous
657 ;; Find the previous message.
658 (previous-single-property-change (point) 'message)))
660 ;; Get the file structure that belongs to it.
662 (or (get-text-property (1- prev-pos) 'message)
663 (get-text-property prev-pos 'message)))
665 (car (nth 2 (car prev)))))
666 ;; Construct FILE . DIR from that.
668 (setq file (cons (car prev-struct)
669 (cadr prev-struct))))))
671 (setq file '("*unknown*")))))
672 ;; All of these fields are optional, get them only if we have an index, and
673 ;; it matched some part of the message.
675 (setq line (match-string-no-properties line))
676 (setq line (string-to-number line)))
678 (setq end-line (match-string-no-properties end-line))
679 (setq end-line (string-to-number end-line)))
682 (setq col (funcall col))
684 (setq col (match-string-no-properties col))
685 (setq col (- (string-to-number col) compilation-first-column)))))
686 (if (and end-col (functionp end-col))
687 (setq end-col (funcall end-col))
688 (if (and end-col (setq end-col (match-string-no-properties end-col)))
689 (setq end-col (- (string-to-number end-col) compilation-first-column -1))
690 (if end-line (setq end-col -1))))
691 (if (consp type) ; not a static type, check what it is.
692 (setq type (or (and (car type) (match-end (car type)) 1)
693 (and (cdr type) (match-end (cdr type)) 0)
695 (compilation-internal-error-properties file line end-line col end-col type fmt)))
697 (defun compilation-move-to-column (col screen)
698 "Go to column COL on the current line.
699 If SCREEN is non-nil, columns are screen columns, otherwise, they are
703 (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
705 (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
706 "Get the meta-info that will be added as text-properties.
707 LINE, END-LINE, COL, END-COL are integers or nil.
708 TYPE can be 0, 1, or 2, meaning error, warning, or just info.
709 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
710 FMTS is a list of format specs for transforming the file name.
711 (See `compilation-error-regexp-alist'.)"
712 (unless file (setq file '("*unknown*")))
713 (let* ((file-struct (compilation-get-file-structure file fmts))
714 ;; Get first already existing marker (if any has one, all have one).
715 ;; Do this first, as the compilation-assq`s may create new nodes.
716 (marker-line (car (cddr file-struct))) ; a line structure
717 (marker (nth 3 (cadr marker-line))) ; its marker
718 (compilation-error-screen-columns compilation-error-screen-columns)
719 end-marker loc end-loc)
720 (if (not (and marker (marker-buffer marker)))
721 (setq marker nil) ; no valid marker for this file
722 (setq loc (or line 1)) ; normalize no linenumber to line 1
723 (catch 'marker ; find nearest loc, at least one exists
724 (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines
725 (if (> (car x) loc) ; still bigger
727 (if (> (- (or (car marker-line) 1) loc)
728 (- loc (car x))) ; current line is nearer
729 (setq marker-line x))
731 (setq marker (nth 3 (cadr marker-line))
732 marker-line (or (car marker-line) 1))
733 (with-current-buffer (marker-buffer marker)
737 (goto-char (marker-position marker))
738 (when (or end-col end-line)
739 (beginning-of-line (- (or end-line line) marker-line -1))
740 (if (or (null end-col) (< end-col 0))
742 (compilation-move-to-column
743 end-col compilation-error-screen-columns))
744 (setq end-marker (list (point-marker))))
745 (beginning-of-line (if end-line
747 (- loc marker-line -1)))
749 (compilation-move-to-column
750 col compilation-error-screen-columns)
751 (forward-to-indentation 0))
752 (setq marker (list (point-marker)))))))
754 (setq loc (compilation-assq line (cdr file-struct)))
756 (setq end-loc (compilation-assq end-line (cdr file-struct))
757 end-loc (compilation-assq end-col end-loc))
758 (if end-col ; use same line element
759 (setq end-loc (compilation-assq end-col loc))))
760 (setq loc (compilation-assq col loc))
761 ;; If they are new, make the loc(s) reference the file they point to.
762 (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker)))
765 (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker))))
767 ;; Must start with face
768 `(face ,compilation-message-face
769 message (,loc ,type ,end-loc)
770 ,@(if compilation-debug
771 `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords)
774 "mouse-2: visit this file, line and column"
776 "mouse-2: visit this file and line"
777 "mouse-2: visit this file"))
778 keymap compilation-button-map
779 mouse-face highlight)))
781 (defun compilation-mode-font-lock-keywords ()
782 "Return expressions to highlight in Compilation mode."
783 (if compilation-parse-errors-function
784 ;; An old package! Try the compatibility code.
785 '((compilation-compat-parse-errors))
787 ;; make directory tracking
788 (if compilation-directory-matcher
789 `((,(car compilation-directory-matcher)
790 ,@(mapcar (lambda (elt)
792 (compilation-directory-properties
793 ,(car elt) ,(cdr elt))
795 (cdr compilation-directory-matcher)))))
797 ;; Compiler warning/error lines.
801 (setq item (cdr (assq item
802 compilation-error-regexp-alist-alist))))
803 (let ((file (nth 1 item))
807 end-line end-col fmt)
808 (if (consp file) (setq fmt (cdr file) file (car file)))
809 (if (consp line) (setq end-line (cdr line) line (car line)))
810 (if (consp col) (setq end-col (cdr col) col (car col)))
813 ;; The old compile.el had here an undocumented hook that
814 ;; allowed `line' to be a function that computed the actual
815 ;; error location. Let's do our best.
818 (compilation-compat-error-properties
819 (funcall ',line (cons (match-string ,file)
820 (cons default-directory
822 ,(if col `(match-string ,col))))))
823 (,file compilation-error-face t))
825 (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
826 (error "HYPERLINK should be an integer: %s" (nth 5 item)))
830 ,@(when (integerp file)
831 `((,file ,(if (consp type)
832 `(compilation-face ',type)
833 (aref [compilation-info-face
834 compilation-warning-face
835 compilation-error-face]
839 `((,line compilation-line-face nil t)))
841 `((,end-line compilation-line-face nil t)))
843 ,@(when (integerp col)
844 `((,col compilation-column-face nil t)))
845 ,@(when (integerp end-col)
846 `((,end-col compilation-column-face nil t)))
849 (,(or (nth 5 item) 0)
850 (compilation-error-properties ',file ,line ,end-line
851 ,col ,end-col ',(or type 2)
853 append))))) ; for compilation-message-face
854 compilation-error-regexp-alist)
856 compilation-mode-font-lock-keywords)))
860 (defun compile (command &optional comint)
861 "Compile the program including the current buffer. Default: run `make'.
862 Runs COMMAND, a shell command, in a separate process asynchronously
863 with output going to the buffer `*compilation*'.
865 If optional second arg COMINT is t the buffer will be in Comint mode with
866 `compilation-shell-minor-mode'.
868 You can then use the command \\[next-error] to find the next error message
869 and move to the source code that caused it.
871 Interactively, prompts for the command if `compilation-read-command' is
872 non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
873 Additionally, with universal prefix arg, compilation buffer will be in
874 comint mode, i.e. interactive.
876 To run more than one compilation at once, start one and rename
877 the \`*compilation*' buffer to some other name with
878 \\[rename-buffer]. Then start the next one. On most systems,
879 termination of the main compilation process kills its
882 The name used for the buffer is actually whatever is returned by
883 the function in `compilation-buffer-name-function', so you can set that
884 to a function that generates a unique name."
887 (let ((command (eval compile-command)))
888 (if (or compilation-read-command current-prefix-arg)
889 (read-from-minibuffer "Compile command: "
891 (if (equal (car compile-history) command)
892 '(compile-history . 1)
895 (consp current-prefix-arg)))
896 (unless (equal command (eval compile-command))
897 (setq compile-command command))
898 (save-some-buffers (not compilation-ask-about-save) nil)
899 (setq compilation-directory default-directory)
900 (compilation-start command comint))
902 ;; run compile with the default command line
904 "Re-compile the program including the current buffer.
905 If this is run in a Compilation mode buffer, re-use the arguments from the
906 original use. Otherwise, recompile using `compile-command'."
908 (save-some-buffers (not compilation-ask-about-save) nil)
909 (let ((default-directory
910 (or (and (not (eq major-mode (nth 1 compilation-arguments)))
911 compilation-directory)
913 (apply 'compilation-start (or compilation-arguments
914 `(,(eval compile-command))))))
916 (defcustom compilation-scroll-output nil
917 "*Non-nil to scroll the *compilation* buffer window as output appears.
919 Setting it causes the Compilation mode commands to put point at the
920 end of their output window so that the end of the output is always
921 visible rather than the beginning."
927 (defun compilation-buffer-name (mode-name mode-command name-function)
928 "Return the name of a compilation buffer to use.
929 If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
930 to determine the buffer name.
931 Likewise if `compilation-buffer-name-function' is non-nil.
932 If current buffer is the mode MODE-COMMAND,
933 return the name of the current buffer, so that it gets reused.
934 Otherwise, construct a buffer name from MODE-NAME."
936 (funcall name-function mode-name))
937 (compilation-buffer-name-function
938 (funcall compilation-buffer-name-function mode-name))
939 ((and (eq mode-command major-mode)
940 (eq major-mode (nth 1 compilation-arguments)))
943 (concat "*" (downcase mode-name) "*"))))
945 ;; This is a rough emulation of the old hack, until the transition to new
946 ;; compile is complete.
947 (defun compile-internal (command error-message
948 &optional name-of-mode parser
949 error-regexp-alist name-function
950 enter-regexp-alist leave-regexp-alist
951 file-regexp-alist nomessage-regexp-alist
952 no-async highlight-regexp local-map)
954 (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
955 (let ((compilation-error-regexp-alist
956 (append file-regexp-alist (or error-regexp-alist
957 compilation-error-regexp-alist)))
958 (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
959 "\\1" error-message)))
960 (compilation-start command nil name-function highlight-regexp)))
961 (make-obsolete 'compile-internal 'compilation-start)
964 (defun compilation-start (command &optional mode name-function highlight-regexp)
965 "Run compilation command COMMAND (low level interface).
966 If COMMAND starts with a cd command, that becomes the `default-directory'.
967 The rest of the arguments are optional; for them, nil means use the default.
969 MODE is the major mode to set in the compilation buffer. Mode
970 may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
971 If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
972 to determine the buffer name.
974 If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
975 the matching section of the visited source line; the default is to use the
976 global value of `compilation-highlight-regexp'.
978 Returns the compilation buffer created."
979 (or mode (setq mode 'compilation-mode))
982 (prog1 "compilation" (require 'comint))
983 (replace-regexp-in-string "-mode$" "" (symbol-name mode))))
984 (thisdir default-directory)
989 (compilation-buffer-name name-of-mode mode name-function)))
990 (let ((comp-proc (get-buffer-process (current-buffer))))
992 (if (or (not (eq (process-status comp-proc) 'run))
994 (format "A %s process is running; kill it? "
998 (interrupt-process comp-proc)
1000 (delete-process comp-proc))
1002 (error "Cannot have two processes in `%s' at once"
1004 (buffer-disable-undo (current-buffer))
1005 ;; first transfer directory from where M-x compile was called
1006 (setq default-directory thisdir)
1007 ;; Make compilation buffer read-only. The filter can still write it.
1008 ;; Clear out the compilation buffer.
1009 (let ((inhibit-read-only t)
1010 (default-directory thisdir))
1011 ;; Then evaluate a cd command if any, but don't perform it yet, else start-command
1012 ;; would do it again through the shell: (cd "..") AND sh -c "cd ..; make"
1013 (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command)
1015 (substitute-env-vars (match-string 1 command))
1019 ;; Select the desired mode.
1020 (if (not (eq mode t))
1022 (setq buffer-read-only nil)
1023 (with-no-warnings (comint-mode))
1024 (compilation-shell-minor-mode))
1025 (if highlight-regexp
1026 (set (make-local-variable 'compilation-highlight-regexp)
1028 ;; Output a mode setter, for saving and later reloading this buffer.
1029 (insert "-*- mode: " name-of-mode
1030 "; default-directory: " (prin1-to-string default-directory)
1032 (format "%s started at %s\n\n"
1034 (substring (current-time-string) 0 19))
1036 (setq thisdir default-directory))
1037 (set-buffer-modified-p nil))
1038 ;; If we're already in the compilation buffer, go to the end
1039 ;; of the buffer, so point will track the compilation output.
1040 (if (eq outbuf (current-buffer))
1041 (goto-char (point-max)))
1042 ;; Pop up the compilation buffer.
1043 (setq outwin (display-buffer outbuf nil t))
1044 (with-current-buffer outbuf
1045 (let ((process-environment
1047 compilation-environment
1048 (if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning
1049 system-uses-terminfo)
1050 (list "TERM=dumb" "TERMCAP="
1051 (format "COLUMNS=%d" (window-width)))
1053 (format "TERMCAP=emacs:co#%d:tc=unknown:"
1055 ;; Set the EMACS variable, but
1056 ;; don't override users' setting of $EMACS.
1057 (unless (getenv "EMACS") '("EMACS=t"))
1058 (copy-sequence process-environment))))
1059 (set (make-local-variable 'compilation-arguments)
1060 (list command mode name-function highlight-regexp))
1061 (set (make-local-variable 'revert-buffer-function)
1062 'compilation-revert-buffer)
1063 (set-window-start outwin (point-min))
1064 (or (eq outwin (selected-window))
1065 (set-window-point outwin (if compilation-scroll-output
1068 ;; The setup function is called before compilation-set-window-height
1069 ;; so it can set the compilation-window-height buffer locally.
1070 (if compilation-process-setup-function
1071 (funcall compilation-process-setup-function))
1072 (compilation-set-window-height outwin)
1073 ;; Start the compilation.
1074 (if (fboundp 'start-process)
1075 (let ((proc (if (eq mode t)
1078 (comint-exec outbuf (downcase mode-name)
1079 shell-file-name nil `("-c" ,command))))
1080 (start-process-shell-command (downcase mode-name)
1082 ;; Make the buffer's mode line show process state.
1083 (setq mode-line-process '(":%s"))
1084 (set-process-sentinel proc 'compilation-sentinel)
1085 (set-process-filter proc 'compilation-filter)
1086 (set-marker (process-mark proc) (point) outbuf)
1087 (when compilation-disable-input
1089 (process-send-eof proc)
1090 ;; The process may have exited already.
1092 (setq compilation-in-progress
1093 (cons proc compilation-in-progress)))
1094 ;; No asynchronous processes available.
1095 (message "Executing `%s'..." command)
1096 ;; Fake modeline display as if `start-process' were run.
1097 (setq mode-line-process ":run")
1098 (force-mode-line-update)
1099 (sit-for 0) ; Force redisplay
1100 (let* ((buffer-read-only nil) ; call-process needs to modify outbuf
1101 (status (call-process shell-file-name nil outbuf nil "-c"
1103 (cond ((numberp status)
1104 (compilation-handle-exit 'exit status
1108 exited abnormally with code %d\n"
1111 (compilation-handle-exit 'signal status
1112 (concat status "\n")))
1114 (compilation-handle-exit 'bizarre status status))))
1115 ;; Without async subprocesses, the buffer is not yet
1116 ;; fontified, so fontify it now.
1117 (let ((font-lock-verbose nil)) ; shut up font-lock messages
1118 (font-lock-fontify-buffer))
1119 (set-buffer-modified-p nil)
1120 (message "Executing `%s'...done" command)))
1121 ;; Now finally cd to where the shell started make/grep/...
1122 (setq default-directory thisdir))
1123 (if (buffer-local-value 'compilation-scroll-output outbuf)
1124 (save-selected-window
1125 (select-window outwin)
1126 (goto-char (point-max))))
1127 ;; Make it so the next C-x ` will use this buffer.
1128 (setq next-error-last-buffer outbuf)))
1130 (defun compilation-set-window-height (window)
1131 "Set the height of WINDOW according to `compilation-window-height'."
1132 (let ((height (buffer-local-value 'compilation-window-height (window-buffer window))))
1134 (= (window-width window) (frame-width (window-frame window)))
1135 ;; If window is alone in its frame, aside from a minibuffer,
1136 ;; don't change its height.
1137 (not (eq window (frame-root-window (window-frame window))))
1138 ;; Stef said that doing the saves in this order is safer:
1140 (save-selected-window
1141 (select-window window)
1142 (enlarge-window (- height (window-height))))))))
1144 (defvar compilation-menu-map
1145 (let ((map (make-sparse-keymap "Errors")))
1146 (define-key map [stop-subjob]
1147 '("Stop Compilation" . kill-compilation))
1148 (define-key map [compilation-mode-separator2]
1150 (define-key map [compilation-first-error]
1151 '("First Error" . first-error))
1152 (define-key map [compilation-previous-error]
1153 '("Previous Error" . previous-error))
1154 (define-key map [compilation-next-error]
1155 '("Next Error" . next-error))
1158 (defvar compilation-minor-mode-map
1159 (let ((map (make-sparse-keymap)))
1160 (define-key map [mouse-2] 'compile-goto-error)
1161 (define-key map [follow-link] 'mouse-face)
1162 (define-key map "\C-c\C-c" 'compile-goto-error)
1163 (define-key map "\C-m" 'compile-goto-error)
1164 (define-key map "\C-c\C-k" 'kill-compilation)
1165 (define-key map "\M-n" 'compilation-next-error)
1166 (define-key map "\M-p" 'compilation-previous-error)
1167 (define-key map "\M-{" 'compilation-previous-file)
1168 (define-key map "\M-}" 'compilation-next-file)
1169 ;; Set up the menu-bar
1170 (define-key map [menu-bar compilation]
1171 (cons "Errors" compilation-menu-map))
1173 "Keymap for `compilation-minor-mode'.")
1175 (defvar compilation-shell-minor-mode-map
1176 (let ((map (make-sparse-keymap)))
1177 (define-key map "\M-\C-m" 'compile-goto-error)
1178 (define-key map "\M-\C-n" 'compilation-next-error)
1179 (define-key map "\M-\C-p" 'compilation-previous-error)
1180 (define-key map "\M-{" 'compilation-previous-file)
1181 (define-key map "\M-}" 'compilation-next-file)
1182 ;; Set up the menu-bar
1183 (define-key map [menu-bar compilation]
1184 (cons "Errors" compilation-menu-map))
1186 "Keymap for `compilation-shell-minor-mode'.")
1188 (defvar compilation-button-map
1189 (let ((map (make-sparse-keymap)))
1190 (define-key map [mouse-2] 'compile-goto-error)
1191 (define-key map [follow-link] 'mouse-face)
1192 (define-key map "\C-m" 'compile-goto-error)
1194 "Keymap for compilation-message buttons.")
1195 (fset 'compilation-button-map compilation-button-map)
1197 (defvar compilation-mode-map
1198 (let ((map (make-sparse-keymap)))
1199 ;; Don't inherit from compilation-minor-mode-map,
1200 ;; because that introduces a menu bar item we don't want.
1201 ;; That confuses C-down-mouse-3.
1202 (define-key map [mouse-2] 'compile-goto-error)
1203 (define-key map [follow-link] 'mouse-face)
1204 (define-key map "\C-c\C-c" 'compile-goto-error)
1205 (define-key map "\C-m" 'compile-goto-error)
1206 (define-key map "\C-c\C-k" 'kill-compilation)
1207 (define-key map "\M-n" 'compilation-next-error)
1208 (define-key map "\M-p" 'compilation-previous-error)
1209 (define-key map "\M-{" 'compilation-previous-file)
1210 (define-key map "\M-}" 'compilation-next-file)
1211 (define-key map "\t" 'compilation-next-error)
1212 (define-key map [backtab] 'compilation-previous-error)
1214 (define-key map " " 'scroll-up)
1215 (define-key map "\^?" 'scroll-down)
1216 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
1218 ;; Set up the menu-bar
1219 (let ((submap (make-sparse-keymap "Compile")))
1220 (define-key map [menu-bar compilation]
1221 (cons "Compile" submap))
1222 (set-keymap-parent submap compilation-menu-map))
1223 (define-key map [menu-bar compilation compilation-separator2]
1225 (define-key map [menu-bar compilation compilation-grep]
1226 '("Search Files (grep)..." . grep))
1227 (define-key map [menu-bar compilation compilation-recompile]
1228 '("Recompile" . recompile))
1229 (define-key map [menu-bar compilation compilation-compile]
1230 '("Compile..." . compile))
1232 "Keymap for compilation log buffers.
1233 `compilation-minor-mode-map' is a parent of this.")
1235 (put 'compilation-mode 'mode-class 'special)
1237 (defvar compilation-skip-to-next-location t
1238 "*If non-nil, skip multiple error messages for the same source location.")
1240 (defcustom compilation-skip-threshold 1
1241 "*Compilation motion commands skip less important messages.
1242 The value can be either 2 -- skip anything less than error, 1 --
1243 skip anything less than warning or 0 -- don't skip any messages.
1244 Note that all messages not positively identified as warning or
1245 info, are considered errors."
1246 :type '(choice (const :tag "Warnings and info" 2)
1247 (const :tag "Info" 1)
1248 (const :tag "None" 0))
1252 (defcustom compilation-skip-visited nil
1253 "*Compilation motion commands skip visited messages if this is t.
1254 Visited messages are ones for which the file, line and column have been jumped
1255 to from the current content in the current compilation buffer, even if it was
1256 from a different message."
1262 (defun compilation-mode (&optional name-of-mode)
1263 "Major mode for compilation log buffers.
1264 \\<compilation-mode-map>To visit the source for a line-numbered error,
1265 move point to the error message line and type \\[compile-goto-error].
1266 To kill the compilation, type \\[kill-compilation].
1268 Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
1270 \\{compilation-mode-map}"
1272 (kill-all-local-variables)
1273 (use-local-map compilation-mode-map)
1274 (setq major-mode 'compilation-mode
1275 mode-name (or name-of-mode "Compilation"))
1276 (set (make-local-variable 'page-delimiter)
1277 compilation-page-delimiter)
1279 (setq buffer-read-only t)
1280 (run-mode-hooks 'compilation-mode-hook))
1282 (defmacro define-compilation-mode (mode name doc &rest body)
1283 "This is like `define-derived-mode' without the PARENT argument.
1284 The parent is always `compilation-mode' and the customizable `compilation-...'
1285 variables are also set from the name of the mode you have chosen,
1286 by replacing the first word, e.g `compilation-scroll-output' from
1287 `grep-scroll-output' if that variable exists."
1288 (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
1289 `(define-derived-mode ,mode compilation-mode ,name
1291 ,@(mapcar (lambda (v)
1293 (intern-soft (replace-regexp-in-string
1294 "^compilation" mode-name
1297 (or (boundp (cdr v))
1298 (if (boundp 'byte-compile-bound-variables)
1299 (memq (cdr v) byte-compile-bound-variables)))
1300 `(set (make-local-variable ',(car v)) ,(cdr v))))
1301 '(compilation-buffer-name-function
1302 compilation-directory-matcher
1304 compilation-error-regexp-alist
1305 compilation-error-regexp-alist-alist
1306 compilation-error-screen-columns
1307 compilation-finish-function
1308 compilation-finish-functions
1309 compilation-first-column
1310 compilation-mode-font-lock-keywords
1311 compilation-page-delimiter
1312 compilation-parse-errors-filename-function
1313 compilation-process-setup-function
1314 compilation-scroll-output
1315 compilation-search-path
1316 compilation-skip-threshold
1317 compilation-window-height))
1320 (defun compilation-revert-buffer (ignore-auto noconfirm)
1321 (if buffer-file-name
1322 (let (revert-buffer-function)
1323 (revert-buffer ignore-auto noconfirm))
1324 (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
1325 (apply 'compilation-start compilation-arguments))))
1327 (defvar compilation-current-error nil
1328 "Marker to the location from where the next error will be found.
1329 The global commands next/previous/first-error/goto-error use this.")
1331 (defvar compilation-messages-start nil
1332 "Buffer position of the beginning of the compilation messages.
1333 If nil, use the beginning of buffer.")
1335 ;; A function name can't be a hook, must be something with a value.
1336 (defconst compilation-turn-on-font-lock 'turn-on-font-lock)
1338 (defun compilation-setup (&optional minor)
1339 "Prepare the buffer for the compilation parsing commands to work.
1340 Optional argument MINOR indicates this is called from
1341 `compilation-minor-mode'."
1342 (make-local-variable 'compilation-current-error)
1343 (make-local-variable 'compilation-messages-start)
1344 (make-local-variable 'compilation-error-screen-columns)
1345 (make-local-variable 'overlay-arrow-position)
1346 (set (make-local-variable 'overlay-arrow-string) "")
1347 (setq next-error-overlay-arrow-position nil)
1348 (add-hook 'kill-buffer-hook
1349 (lambda () (setq next-error-overlay-arrow-position nil)) nil t)
1350 ;; Note that compilation-next-error-function is for interfacing
1351 ;; with the next-error function in simple.el, and it's only
1352 ;; coincidentally named similarly to compilation-next-error.
1353 (setq next-error-function 'compilation-next-error-function)
1354 (set (make-local-variable 'font-lock-extra-managed-props)
1355 '(directory message help-echo mouse-face debug))
1356 (set (make-local-variable 'compilation-locs)
1357 (make-hash-table :test 'equal :weakness 'value))
1358 ;; lazy-lock would never find the message unless it's scrolled to.
1359 ;; jit-lock might fontify some things too late.
1360 (set (make-local-variable 'font-lock-support-mode) nil)
1361 (set (make-local-variable 'font-lock-maximum-size) nil)
1363 (let ((fld font-lock-defaults))
1364 (font-lock-add-keywords nil (compilation-mode-font-lock-keywords))
1367 (font-lock-fontify-buffer)
1368 (font-lock-change-mode)
1369 (turn-on-font-lock))
1370 (turn-on-font-lock)))
1371 (setq font-lock-defaults '(compilation-mode-font-lock-keywords t))
1372 ;; maybe defer font-lock till after derived mode is set up
1373 (run-mode-hooks 'compilation-turn-on-font-lock)))
1376 (define-minor-mode compilation-shell-minor-mode
1377 "Toggle compilation shell minor mode.
1378 With arg, turn compilation mode on if and only if arg is positive.
1379 In this minor mode, all the error-parsing commands of the
1380 Compilation major mode are available but bound to keys that don't
1381 collide with Shell mode. See `compilation-mode'.
1382 Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
1383 nil " Shell-Compile"
1385 (if compilation-shell-minor-mode
1386 (compilation-setup t)
1387 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1388 (font-lock-fontify-buffer)))
1391 (define-minor-mode compilation-minor-mode
1392 "Toggle compilation minor mode.
1393 With arg, turn compilation mode on if and only if arg is positive.
1394 In this minor mode, all the error-parsing commands of the
1395 Compilation major mode are available. See `compilation-mode'.
1396 Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
1399 (if compilation-minor-mode
1400 (compilation-setup t)
1401 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1402 (font-lock-fontify-buffer)))
1404 (defun compilation-handle-exit (process-status exit-status msg)
1405 "Write MSG in the current buffer and hack its mode-line-process."
1406 (let ((inhibit-read-only t)
1407 (status (if compilation-exit-message-function
1408 (funcall compilation-exit-message-function
1409 process-status exit-status msg)
1410 (cons msg exit-status)))
1413 ;; Record where we put the message, so we can ignore it later on.
1415 (insert ?\n mode-name " " (car status))
1416 (if (and (numberp compilation-window-height)
1417 (zerop compilation-window-height))
1418 (message "%s" (cdr status)))
1421 (insert " at " (substring (current-time-string) 0 19))
1422 (goto-char (point-max))
1423 ;; Prevent that message from being recognized as a compilation error.
1424 (add-text-properties omax (point)
1425 (append '(compilation-handle-exit t) nil))
1426 (setq mode-line-process (format ":%s [%s]" process-status (cdr status)))
1427 ;; Force mode line redisplay soon.
1428 (force-mode-line-update)
1429 (if (and opoint (< opoint omax))
1432 (if compilation-finish-function
1433 (funcall compilation-finish-function (current-buffer) msg)))
1434 (let ((functions compilation-finish-functions))
1436 (funcall (car functions) (current-buffer) msg)
1437 (setq functions (cdr functions))))))
1439 ;; Called when compilation process changes state.
1440 (defun compilation-sentinel (proc msg)
1441 "Sentinel for compilation buffers."
1442 (if (memq (process-status proc) '(exit signal))
1443 (let ((buffer (process-buffer proc)))
1444 (if (null (buffer-name buffer))
1446 (set-process-buffer proc nil)
1447 (with-current-buffer buffer
1448 ;; Write something in the compilation buffer
1449 ;; and hack its mode line.
1450 (compilation-handle-exit (process-status proc)
1451 (process-exit-status proc)
1453 ;; Since the buffer and mode line will show that the
1454 ;; process is dead, we can delete it now. Otherwise it
1455 ;; will stay around until M-x list-processes.
1456 (delete-process proc)))
1457 (setq compilation-in-progress (delq proc compilation-in-progress)))))
1459 (defun compilation-filter (proc string)
1460 "Process filter for compilation buffers.
1461 Just inserts the text, but uses `insert-before-markers'."
1462 (if (buffer-name (process-buffer proc))
1463 (with-current-buffer (process-buffer proc)
1464 (let ((inhibit-read-only t))
1466 (goto-char (process-mark proc))
1467 (insert-before-markers string)
1468 (run-hooks 'compilation-filter-hook))))))
1470 ;;; test if a buffer is a compilation buffer, assuming we're in the buffer
1471 (defsubst compilation-buffer-internal-p ()
1472 "Test if inside a compilation buffer."
1473 (local-variable-p 'compilation-locs))
1475 ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p
1476 (defsubst compilation-buffer-p (buffer)
1477 "Test if BUFFER is a compilation buffer."
1478 (with-current-buffer buffer
1479 (compilation-buffer-internal-p)))
1481 (defmacro compilation-loop (< property-change 1+ error)
1483 (or (setq pt (,property-change pt 'message))
1484 (error ,error compilation-error))
1485 ;; prop 'message usually has 2 changes, on and off, so re-search if off
1486 (or (setq msg (get-text-property pt 'message))
1487 (if (setq pt (,property-change pt 'message))
1488 (setq msg (get-text-property pt 'message)))
1489 (error ,error compilation-error))
1490 (or (< (cadr msg) compilation-skip-threshold)
1492 (eq (prog1 last (setq last (nth 2 (car msg))))
1494 (if compilation-skip-visited
1495 (nthcdr 4 (car msg)))
1496 (if compilation-skip-to-next-location
1498 ;; count this message only if none of the above are true
1501 (defun compilation-next-error (n &optional different-file pt)
1502 "Move point to the next error in the compilation buffer.
1503 Prefix arg N says how many error messages to move forwards (or
1504 backwards, if negative).
1505 Does NOT find the source line like \\[next-error]."
1507 (or (compilation-buffer-p (current-buffer))
1508 (error "Not in a compilation buffer"))
1509 (or pt (setq pt (point)))
1510 (let* ((msg (get-text-property pt 'message))
1514 (unless (or msg ; find message near here
1515 (setq msg (get-text-property (max (1- pt) (point-min))
1517 (setq pt (previous-single-property-change pt 'message nil
1518 (line-beginning-position)))
1519 (unless (setq msg (get-text-property (max (1- pt) (point-min)) 'message))
1520 (setq pt (next-single-property-change pt 'message nil
1521 (line-end-position)))
1522 (or (setq msg (get-text-property pt 'message))
1523 (setq pt (point)))))
1524 (setq last (nth 2 (car msg)))
1526 (compilation-loop > next-single-property-change 1-
1527 (if (get-buffer-process (current-buffer))
1529 "Moved past last %s"))
1530 ;; Don't move "back" to message at or before point.
1531 ;; Pass an explicit (point-min) to make sure pt is non-nil.
1532 (setq pt (previous-single-property-change pt 'message nil (point-min)))
1533 (compilation-loop < previous-single-property-change 1+
1534 "Moved back before first %s")))
1537 (error "No %s here" compilation-error))))
1539 (defun compilation-previous-error (n)
1540 "Move point to the previous error in the compilation buffer.
1541 Prefix arg N says how many error messages to move backwards (or
1542 forwards, if negative).
1543 Does NOT find the source line like \\[previous-error]."
1545 (compilation-next-error (- n)))
1547 (defun compilation-next-file (n)
1548 "Move point to the next error for a different file than the current one.
1549 Prefix arg N says how many files to move forwards (or backwards, if negative)."
1551 (compilation-next-error n t))
1553 (defun compilation-previous-file (n)
1554 "Move point to the previous error for a different file than the current one.
1555 Prefix arg N says how many files to move backwards (or forwards, if negative)."
1557 (compilation-next-file (- n)))
1559 (defun kill-compilation ()
1560 "Kill the process made by the \\[compile] or \\[grep] commands."
1562 (let ((buffer (compilation-find-buffer)))
1563 (if (get-buffer-process buffer)
1564 (interrupt-process (get-buffer-process buffer))
1565 (error "The %s process is not running" (downcase mode-name)))))
1567 (defalias 'compile-mouse-goto-error 'compile-goto-error)
1569 (defun compile-goto-error (&optional event)
1570 "Visit the source for the error message at point.
1571 Use this command in a compilation log buffer. Sets the mark at point there."
1572 (interactive (list last-input-event))
1573 (if event (posn-set-point (event-end event)))
1574 (or (compilation-buffer-p (current-buffer))
1575 (error "Not in a compilation buffer"))
1576 (if (get-text-property (point) 'directory)
1577 (dired-other-window (car (get-text-property (point) 'directory)))
1579 (setq compilation-current-error (point))
1580 (next-error-internal)))
1582 ;; Return a compilation buffer.
1583 ;; If the current buffer is a compilation buffer, return it.
1584 ;; Otherwise, look for a compilation buffer and signal an error
1585 ;; if there are none.
1586 (defun compilation-find-buffer (&optional avoid-current)
1587 (next-error-find-buffer avoid-current 'compilation-buffer-internal-p))
1590 (defun compilation-next-error-function (n &optional reset)
1591 "Advance to the next error message and visit the file where the error was.
1592 This is the value of `next-error-function' in Compilation buffers."
1595 (setq compilation-current-error nil))
1596 (let* ((columns compilation-error-screen-columns) ; buffer's local value
1598 (loc (compilation-next-error (or n 1) nil
1599 (or compilation-current-error
1600 compilation-messages-start
1602 (end-loc (nth 2 loc))
1603 (marker (point-marker)))
1604 (setq compilation-current-error (point-marker)
1605 overlay-arrow-position
1607 compilation-current-error
1608 (copy-marker (line-beginning-position)))
1610 ;; If loc contains no marker, no error in that file has been visited. If
1611 ;; the marker is invalid the buffer has been killed. So, recalculate all
1612 ;; markers for that file.
1613 (unless (and (nth 3 loc) (marker-buffer (nth 3 loc)))
1614 (with-current-buffer (compilation-find-file marker (caar (nth 2 loc))
1615 (cadr (car (nth 2 loc))))
1618 (goto-char (point-min))
1619 ;; Treat file's found lines in forward order, 1 by 1.
1620 (dolist (line (reverse (cddr (nth 2 loc))))
1621 (when (car line) ; else this is a filename w/o a line#
1622 (beginning-of-line (- (car line) last -1))
1623 (setq last (car line)))
1624 ;; Treat line's found columns and store/update a marker for each.
1625 (dolist (col (cdr line))
1627 (if (eq (car col) -1) ; special case for range end
1629 (compilation-move-to-column (car col) columns))
1631 (skip-chars-forward " \t"))
1633 (set-marker (nth 3 col) (point))
1634 (setcdr (nthcdr 2 col) `(,(point-marker)))))))))
1635 (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc))
1636 (setcdr (nthcdr 3 loc) t))) ; Set this one as visited.
1638 (defvar compilation-gcpro nil
1639 "Internal variable used to keep some values from being GC'd.")
1640 (make-variable-buffer-local 'compilation-gcpro)
1642 (defun compilation-fake-loc (marker file &optional line col)
1643 "Preassociate MARKER with FILE.
1644 FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
1645 This is useful when you compile temporary files, but want
1646 automatic translation of the messages to the real buffer from
1647 which the temporary file came. This only works if done before a
1648 message about FILE appears!
1650 Optional args LINE and COL default to 1 and beginning of
1651 indentation respectively. The marker is expected to reflect
1652 this. In the simplest case the marker points to the first line
1653 of the region that was saved to the temp file.
1655 If you concatenate several regions into the temp file (e.g. a
1656 header with variable assignments and a code region), you must
1657 call this several times, once each for the last line of one
1658 region and the first line of the next region."
1659 (or (consp file) (setq file (list file)))
1660 (setq file (compilation-get-file-structure file))
1661 ;; Between the current call to compilation-fake-loc and the first occurrence
1662 ;; of an error message referring to `file', the data is only kept is the
1663 ;; weak hash-table compilation-locs, so we need to prevent this entry
1664 ;; in compilation-locs from being GC'd away. --Stef
1665 (push file compilation-gcpro)
1666 (let ((loc (compilation-assq (or line 1) (cdr file))))
1667 (setq loc (compilation-assq col loc))
1669 (setcdr (cddr loc) (list marker))
1670 (setcdr loc (list line file marker)))
1673 (defcustom compilation-context-lines nil
1674 "Display this many lines of leading context before the current message.
1675 If nil and the left fringe is displayed, don't scroll the
1676 compilation output window; an arrow in the left fringe points to
1677 the current message. If nil and there is no left fringe, the message
1678 displays at the top of the window; there is no arrow."
1679 :type '(choice integer (const :tag "No window scrolling" nil))
1683 (defsubst compilation-set-window (w mk)
1684 "Align the compilation output window W with marker MK near top."
1685 (if (integerp compilation-context-lines)
1686 (set-window-start w (save-excursion
1689 (- 1 compilation-context-lines))
1691 ;; If there is no left fringe.
1692 (if (equal (car (window-fringes)) 0)
1693 (set-window-start w (save-excursion
1695 (beginning-of-line 1)
1697 (set-window-point w mk))
1699 (defvar next-error-highlight-timer)
1701 (defun compilation-goto-locus (msg mk end-mk)
1702 "Jump to an error corresponding to MSG at MK.
1703 All arguments are markers. If END-MK is non-nil, mark is set there
1704 and overlay is highlighted between MK and END-MK."
1705 ;; Show compilation buffer in other window, scrolled to this error.
1706 (let* ((from-compilation-buffer (eq (window-buffer (selected-window))
1707 (marker-buffer msg)))
1708 ;; Use an existing window if it is in a visible frame.
1709 (pre-existing (get-buffer-window (marker-buffer msg) 0))
1710 (w (if (and from-compilation-buffer pre-existing)
1711 ;; Calling display-buffer here may end up (partly) hiding
1712 ;; the error location if the two buffers are in two
1713 ;; different frames. So don't do it if it's not necessary.
1715 (let ((display-buffer-reuse-frames t)
1718 (display-buffer (marker-buffer msg)))))
1719 (highlight-regexp (with-current-buffer (marker-buffer msg)
1720 ;; also do this while we change buffer
1721 (compilation-set-window w msg)
1722 compilation-highlight-regexp)))
1723 ;; Ideally, the window-size should be passed to `display-buffer' (via
1724 ;; something like special-display-buffer) so it's only used when
1725 ;; creating a new window.
1726 (unless pre-existing (compilation-set-window-height w))
1728 (if from-compilation-buffer
1729 ;; If the compilation buffer window was selected,
1730 ;; keep the compilation buffer in this window;
1731 ;; display the source in another window.
1732 (let ((pop-up-windows t))
1733 (pop-to-buffer (marker-buffer mk) 'other-window))
1734 (if (window-dedicated-p (selected-window))
1735 (pop-to-buffer (marker-buffer mk))
1736 (switch-to-buffer (marker-buffer mk))))
1737 ;; If narrowing gets in the way of going to the right place, widen.
1738 (unless (eq (goto-char mk) (point))
1742 (push-mark end-mk t)
1743 (if mark-active (setq mark-active)))
1744 ;; If hideshow got in the way of
1745 ;; seeing the right place, open permanently.
1746 (dolist (ov (overlays-at (point)))
1747 (when (eq 'hs (overlay-get ov 'invisible))
1751 (when highlight-regexp
1752 (if (timerp next-error-highlight-timer)
1753 (cancel-timer next-error-highlight-timer))
1754 (unless compilation-highlight-overlay
1755 (setq compilation-highlight-overlay
1756 (make-overlay (point-min) (point-min)))
1757 (overlay-put compilation-highlight-overlay 'face 'next-error))
1758 (with-current-buffer (marker-buffer mk)
1760 (if end-mk (goto-char end-mk) (end-of-line))
1761 (let ((end (point)))
1762 (if mk (goto-char mk) (beginning-of-line))
1763 (if (and (stringp highlight-regexp)
1764 (re-search-forward highlight-regexp end t))
1766 (goto-char (match-beginning 0))
1767 (move-overlay compilation-highlight-overlay
1768 (match-beginning 0) (match-end 0)
1770 (move-overlay compilation-highlight-overlay
1771 (point) end (current-buffer)))
1772 (if (numberp next-error-highlight)
1773 (setq next-error-highlight-timer
1774 (run-at-time next-error-highlight nil 'delete-overlay
1775 compilation-highlight-overlay)))
1776 (if (not (or (eq next-error-highlight t)
1777 (numberp next-error-highlight)))
1778 (delete-overlay compilation-highlight-overlay))))))
1779 (when (and (eq next-error-highlight 'fringe-arrow))
1780 (setq next-error-overlay-arrow-position
1781 (copy-marker (line-beginning-position))))))
1784 (defun compilation-find-file (marker filename directory &rest formats)
1785 "Find a buffer for file FILENAME.
1786 Search the directories in `compilation-search-path'.
1787 A nil in `compilation-search-path' means to try the
1788 \"current\" directory, which is passed in DIRECTORY.
1789 If DIRECTORY. is relative, it is combined with `default-directory'.
1790 If DIRECTORY. is nil, that means use `default-directory'.
1791 If FILENAME is not found at all, ask the user where to find it.
1792 Pop up the buffer containing MARKER and scroll to MARKER if we ask the user."
1793 (or formats (setq formats '("%s")))
1795 (let ((dirs compilation-search-path)
1796 (spec-dir (if directory
1797 (expand-file-name directory)
1799 buffer thisdir fmts name)
1800 (if (file-name-absolute-p filename)
1801 ;; The file name is absolute. Use its explicit directory as
1802 ;; the first in the search path, and strip it from FILENAME.
1803 (setq filename (abbreviate-file-name (expand-file-name filename))
1804 dirs (cons (file-name-directory filename) dirs)
1805 filename (file-name-nondirectory filename)))
1806 ;; Now search the path.
1807 (while (and dirs (null buffer))
1808 (setq thisdir (or (car dirs) spec-dir)
1810 ;; For each directory, try each format string.
1811 (while (and fmts (null buffer))
1812 (setq name (expand-file-name (format (car fmts) filename) thisdir)
1813 buffer (and (file-exists-p name)
1814 (find-file-noselect name))
1816 (setq dirs (cdr dirs)))
1818 ;; The file doesn't exist. Ask the user where to find it.
1819 (let ((pop-up-windows t))
1820 (compilation-set-window (display-buffer (marker-buffer marker))
1822 (let ((name (expand-file-name
1824 (format "Find this %s in (default %s): "
1825 compilation-error filename)
1826 spec-dir filename t))))
1827 (if (file-directory-p name)
1828 (setq name (expand-file-name filename name)))
1829 (setq buffer (and (file-exists-p name)
1830 (find-file name))))))
1831 ;; Make intangible overlays tangible.
1832 (mapcar (function (lambda (ov)
1833 (when (overlay-get ov 'intangible)
1834 (overlay-put ov 'intangible nil))))
1835 (overlays-in (point-min) (point-max)))
1838 (defun compilation-get-file-structure (file &optional fmt)
1839 "Retrieve FILE's file-structure or create a new one.
1840 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
1841 In the former case, FILENAME may be relative or absolute.
1843 The file-structure looks like this:
1844 (list (list FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)
1846 (or (gethash file compilation-locs)
1847 ;; File was not previously encountered, at least not in the form passed.
1848 ;; Let's normalize it and look again.
1849 (let ((filename (car file))
1850 ;; Get the specified directory from FILE.
1851 (spec-directory (if (cdr file)
1852 (file-truename (cdr file)))))
1854 ;; Check for a comint-file-name-prefix and prepend it if appropriate.
1855 ;; (This is very useful for compilation-minor-mode in an rlogin-mode
1857 (when (and (boundp 'comint-file-name-prefix)
1858 (not (equal comint-file-name-prefix "")))
1859 (if (file-name-absolute-p filename)
1861 (concat comint-file-name-prefix filename))
1863 (setq spec-directory
1865 (concat comint-file-name-prefix spec-directory))))))
1867 ;; If compilation-parse-errors-filename-function is
1868 ;; defined, use it to process the filename.
1869 (when compilation-parse-errors-filename-function
1871 (funcall compilation-parse-errors-filename-function
1874 ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
1875 ;; file names like "./bar//foo.c" for file "bar/foo.c";
1876 ;; expand-file-name will collapse these into "/foo.c" and fail to find
1877 ;; the appropriate file. So we look for doubled slashes in the file
1878 ;; name and fix them.
1879 (setq filename (command-line-normalize-file-name filename))
1881 ;; Store it for the possibly unnormalized name
1883 ;; Retrieve or create file-structure for normalized name
1884 (or (gethash (list filename) compilation-locs)
1885 (puthash (list filename)
1886 (list (list filename spec-directory) fmt)
1888 compilation-locs))))
1890 (add-to-list 'debug-ignored-errors "^No more [-a-z ]+s yet$")
1892 ;;; Compatibility with the old compile.el.
1894 (defun compile-buffer-substring (n) (if n (match-string n)))
1896 (defun compilation-compat-error-properties (err)
1897 "Map old-style error ERR to new-style message."
1898 ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
1899 ;; (MARKER . MARKER).
1900 (let ((dst (cdr err)))
1902 ;; Must start with a face, for font-lock.
1904 message ,(list (list nil nil nil dst) 2)
1905 help-echo "mouse-2: visit the source location"
1906 keymap compilation-button-map
1907 mouse-face highlight)
1908 ;; Too difficult to do it by hand: dispatch to the normal code.
1909 (let* ((file (pop dst))
1912 (filename (pop file))
1913 (dirname (pop file))
1915 (compilation-internal-error-properties
1916 (cons filename dirname) line nil col nil 2 fmt)))))
1918 (defun compilation-compat-parse-errors (limit)
1919 (when compilation-parse-errors-function
1920 ;; FIXME: We should remove the rest of the compilation keywords
1921 ;; but we can't do that from here because font-lock is using
1922 ;; the value right now. --stef
1924 (setq compilation-error-list nil)
1925 ;; Reset compilation-parsing-end each time because font-lock
1926 ;; might force us the re-parse many times (typically because
1927 ;; some code adds some text-property to the output that we
1928 ;; already parsed). You might say "why reparse", well:
1929 ;; because font-lock has just removed the `message' property so
1930 ;; have to do it all over again.
1931 (if compilation-parsing-end
1932 (set-marker compilation-parsing-end (point))
1933 (setq compilation-parsing-end (point-marker)))
1935 ;; Ignore any error: we're calling this function earlier than
1936 ;; in the old compile.el so things might not all be setup yet.
1937 (funcall compilation-parse-errors-function limit nil)
1939 (dolist (err (if (listp compilation-error-list) compilation-error-list))
1940 (let* ((src (car err))
1942 (loc (cond ((markerp dst) (list nil nil nil dst))
1944 (list (nth 2 dst) (nth 1 dst)
1945 (cons (cdar dst) (caar dst)))))))
1948 ;; (put-text-property src (line-end-position) 'font-lock-face 'font-lock-warning-face)
1949 (put-text-property src (line-end-position)
1950 'message (list loc 2)))))))
1954 ;; Beware: this is not only compatiblity code. New code stil uses it. --Stef
1955 (defun compilation-forget-errors ()
1956 ;; In case we hit the same file/line specs, we want to recompute a new
1957 ;; marker for them, so flush our cache.
1958 (setq compilation-locs (make-hash-table :test 'equal :weakness 'value))
1959 (setq compilation-gcpro nil)
1960 ;; FIXME: the old code reset the directory-stack, so maybe we should
1961 ;; put a `directory change' marker of some sort, but where? -stef
1963 ;; FIXME: The old code moved compilation-current-error (which was
1964 ;; virtually represented by a mix of compilation-parsing-end and
1965 ;; compilation-error-list) to point-min, but that was only meaningful for
1966 ;; the internal uses of compilation-forget-errors: all calls from external
1967 ;; packages seem to be followed by a move of compilation-parsing-end to
1968 ;; something equivalent to point-max. So we speculatively move
1969 ;; compilation-current-error to point-max (since the external package
1970 ;; won't know that it should do it). --stef
1971 (setq compilation-current-error nil)
1972 (let* ((proc (get-buffer-process (current-buffer)))
1973 (mark (if proc (process-mark proc)))
1974 (pos (or mark (point-max))))
1975 (setq compilation-messages-start
1976 ;; In the future, ignore the text already present in the buffer.
1977 ;; Since many process filter functions insert before markers,
1978 ;; we need to put ours just before the insertion point rather
1979 ;; than at the insertion point. If that's not possible, then
1980 ;; don't use a marker. --Stef
1981 (if (> pos (point-min)) (copy-marker (1- pos)) pos))))
1984 (add-to-list 'auto-mode-alist '("\\.gcov\\'" . compilation-mode))
1988 ;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c
1989 ;;; compile.el ends here