df8e044d20a84d0aff3820b4a72f3cf519033c6b
[bpt/emacs.git] / lisp / progmodes / compile.el
1 ;;; compile.el --- run compiler as inferior of Emacs, parse error messages
2
3 ;; Copyright (C) 1985-1987, 1993-1999, 2001-2011
4 ;; Free Software Foundation, Inc.
5
6 ;; Authors: Roland McGrath <roland@gnu.org>,
7 ;; Daniel Pfeiffer <occitan@esperanto.org>
8 ;; Maintainer: FSF
9 ;; Keywords: tools, processes
10
11 ;; This file is part of GNU Emacs.
12
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 3 of the License, or
16 ;; (at your option) any later version.
17
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.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Commentary:
27
28 ;; This package provides the compile facilities documented in the Emacs user's
29 ;; manual.
30
31 ;;; Code:
32
33 (eval-when-compile (require 'cl))
34 (require 'tool-bar)
35 (require 'comint)
36
37 (defgroup compilation nil
38 "Run compiler as inferior of Emacs, parse error messages."
39 :group 'tools
40 :group 'processes)
41
42
43 ;;;###autoload
44 (defcustom compilation-mode-hook nil
45 "List of hook functions run by `compilation-mode' (see `run-mode-hooks')."
46 :type 'hook
47 :group 'compilation)
48
49 ;;;###autoload
50 (defcustom compilation-start-hook nil
51 "List of hook functions run by `compilation-start' on the compilation process.
52 \(See `run-hook-with-args').
53 If you use \"omake -P\" and do not want \\[save-buffers-kill-terminal] to ask whether you want
54 the compilation to be killed, you can use this hook:
55 (add-hook 'compilation-start-hook
56 (lambda (process) (set-process-query-on-exit-flag process nil)) nil t)"
57 :type 'hook
58 :group 'compilation)
59
60 ;;;###autoload
61 (defcustom compilation-window-height nil
62 "Number of lines in a compilation window. If nil, use Emacs default."
63 :type '(choice (const :tag "Default" nil)
64 integer)
65 :group 'compilation)
66
67 (defvar compilation-first-column 1
68 "*This is how compilers number the first column, usually 1 or 0.")
69
70 (defvar compilation-parse-errors-filename-function nil
71 "Function to call to post-process filenames while parsing error messages.
72 It takes one arg FILENAME which is the name of a file as found
73 in the compilation output, and should return a transformed file name.")
74
75 ;;;###autoload
76 (defvar compilation-process-setup-function nil
77 "*Function to call to customize the compilation process.
78 This function is called immediately before the compilation process is
79 started. It can be used to set any variables or functions that are used
80 while processing the output of the compilation process.")
81
82 ;;;###autoload
83 (defvar compilation-buffer-name-function nil
84 "Function to compute the name of a compilation buffer.
85 The function receives one argument, the name of the major mode of the
86 compilation buffer. It should return a string.
87 If nil, compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
88
89 ;;;###autoload
90 (defvar compilation-finish-function nil
91 "Function to call when a compilation process finishes.
92 It is called with two arguments: the compilation buffer, and a string
93 describing how the process finished.")
94
95 (make-obsolete-variable 'compilation-finish-function
96 "use `compilation-finish-functions', but it works a little differently."
97 "22.1")
98
99 ;;;###autoload
100 (defvar compilation-finish-functions nil
101 "Functions to call when a compilation process finishes.
102 Each function is called with two arguments: the compilation buffer,
103 and a string describing how the process finished.")
104
105 (defvar compilation-in-progress nil
106 "List of compilation processes now running.")
107 (or (assq 'compilation-in-progress minor-mode-alist)
108 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
109 minor-mode-alist)))
110
111 (defvar compilation-error "error"
112 "Stem of message to print when no matches are found.")
113
114 (defvar compilation-arguments nil
115 "Arguments that were given to `compilation-start'.")
116
117 (defvar compilation-num-errors-found)
118
119 (defvar compilation-error-regexp-alist-alist
120 '((absoft
121 "^\\(?:[Ee]rror on \\|[Ww]arning on\\( \\)\\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
122 of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil (1))
123
124 (ada
125 "\\(warning: .*\\)? at \\([^ \n]+\\):\\([0-9]+\\)$" 2 3 nil (1))
126
127 (aix
128 " in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
129
130 (ant
131 "^[ \t]*\\[[^] \n]+\\][ \t]*\\([^: \n]+\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):[0-9]+:[0-9]+:\\)?\
132 \\( warning\\)?" 1 2 3 (4))
133
134 (bash
135 "^\\([^: \n\t]+\\): line \\([0-9]+\\):" 1 2)
136
137 (borland
138 "^\\(?:Error\\|Warnin\\(g\\)\\) \\(?:[FEW][0-9]+ \\)?\
139 \\([a-zA-Z]?:?[^:( \t\n]+\\)\
140 \\([0-9]+\\)\\(?:[) \t]\\|:[^0-9\n]\\)" 2 3 nil (1))
141
142 (caml
143 "^ *File \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1, lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
144 \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:\\)?\\([ \n]Warning:\\)?\\)"
145 2 (3 . 4) (5 . 6) (7))
146
147 (comma
148 "^\"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)\
149 \\(?:[(. pos]+\\([0-9]+\\))?\\)?[:.,; (-]\\( warning:\\|[-0-9 ]*(W)\\)?" 1 2 3 (4))
150
151 (cucumber
152 "\\(?:^cucumber\\(?: -p [^[:space:]]+\\)?\\|#\\)\
153 \\(?: \\)\\([^\(].*\\):\\([1-9][0-9]*\\)" 1 2)
154
155 (edg-1
156 "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
157 1 2 nil (3 . 4))
158 (edg-2
159 "at line \\([0-9]+\\) of \"\\([^ \n]+\\)\"$"
160 2 1 nil 0)
161
162 (epc
163 "^Error [0-9]+ at (\\([0-9]+\\):\\([^)\n]+\\))" 2 1)
164
165 (ftnchek
166 "\\(^Warning .*\\)? line[ \n]\\([0-9]+\\)[ \n]\\(?:col \\([0-9]+\\)[ \n]\\)?file \\([^ :;\n]+\\)"
167 4 2 3 (1))
168
169 (iar
170 "^\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(?:Error\\|Warnin\\(g\\)\\)\\[[0-9]+\\]:"
171 1 2 nil (3))
172
173 (ibm
174 "^\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) :\
175 \\(?:warnin\\(g\\)\\|informationa\\(l\\)\\)?" 1 2 3 (4 . 5))
176
177 ;; fixme: should be `mips'
178 (irix
179 "^[-[:alnum:]_/ ]+: \\(?:\\(?:[sS]evere\\|[eE]rror\\|[wW]arnin\\(g\\)\\|[iI]nf\\(o\\)\\)[0-9 ]*: \\)?\
180 \\([^,\" \n\t]+\\)\\(?:, line\\|:\\) \\([0-9]+\\):" 3 4 nil (1 . 2))
181
182 (java
183 "^\\(?:[ \t]+at \\|==[0-9]+== +\\(?:at\\|b\\(y\\)\\)\\).+(\\([^()\n]+\\):\\([0-9]+\\))$" 2 3 nil (1))
184
185 (jikes-file
186 "^\\(?:Found\\|Issued\\) .* compiling \"\\(.+\\)\":$" 1 nil nil 0)
187 (jikes-line
188 "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)"
189 nil 1 nil 2 0
190 (2 (compilation-face '(3))))
191
192 (gcc-include
193 "^\\(?:In file included \\| \\|\t\\)from \
194 \\([0-9]*[^0-9\n]\\(?:[^\n :]\\| [^-/\n]\\|:[^ \n]\\)*?\\):\
195 \\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?\\(?:\\(:\\)\\|\\(,\\|$\\)\\)?"
196 1 2 3 (4 . 5))
197
198 (gnu
199 ;; The first line matches the program name for
200
201 ;; PROGRAM:SOURCE-FILE-NAME:LINENO: MESSAGE
202
203 ;; format, which is used for non-interactive programs other than
204 ;; compilers (e.g. the "jade:" entry in compilation.txt).
205
206 ;; This first line makes things ambiguous with output such as
207 ;; "foo:344:50:blabla" since the "foo" part can match this first
208 ;; line (in which case the file name as "344"). To avoid this,
209 ;; the second line disallows filenames exclusively composed of
210 ;; digits.
211
212 ;; Similarly, we get lots of false positives with messages including
213 ;; times of the form "HH:MM:SS" where MM is taken as a line number, so
214 ;; the last line tries to rule out message where the info after the
215 ;; line number starts with "SS". --Stef
216
217 ;; The core of the regexp is the one with *?. It says that a file name
218 ;; can be composed of any non-newline char, but it also rules out some
219 ;; valid but unlikely cases, such as a trailing space or a space
220 ;; followed by a -, or a colon followed by a space.
221
222 ;; The "in \\|from " exception was added to handle messages from Ruby.
223 "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\|[ \t]+\\(?:in \\|from \\)\\)?\
224 \\([0-9]*[^0-9\n]\\(?:[^\n :]\\| [^-/\n]\\|:[^ \n]\\)*?\\): ?\
225 \\([0-9]+\\)\\(?:[.:]\\([0-9]+\\)\\)?\
226 \\(?:-\\([0-9]+\\)?\\(?:\\.\\([0-9]+\\)\\)?\\)?:\
227 \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\
228 *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\|[Nn]ote\\)\\|\
229 \[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)"
230 1 (2 . 4) (3 . 5) (6 . 7))
231
232 (lcc
233 "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)"
234 2 3 4 (1))
235
236 (makepp
237 "^makepp\\(?:\\(?:: warning\\(:\\).*?\\|\\(: Scanning\\|: [LR]e?l?oading makefile\\|: Imported\\|log:.*?\\) \\|: .*?\\)\
238 `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)"
239 4 5 nil (1 . 2) 3
240 (0 (progn (save-match-data
241 (compilation-parse-errors
242 (match-end 0) (line-end-position)
243 `("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]"
244 2 3 nil
245 ,(cond ((match-end 1) 1) ((match-end 2) 0) (t 2))
246 1)))
247 (end-of-line)
248 nil)))
249
250 ;; This regexp is pathologically slow on long lines (Bug#3441).
251 ;; (maven
252 ;; ;; Maven is a popular build tool for Java. Maven is Free Software.
253 ;; "\\(.*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\]" 1 2 3)
254
255 ;; Should be lint-1, lint-2 (SysV lint)
256 (mips-1
257 " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
258 (mips-2
259 " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2)
260
261 (msft
262 ;; The message may be a "warning", "error", or "fatal error" with
263 ;; an error code, or "see declaration of" without an error code.
264 "^ *\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
265 : \\(?:see declaration\\|\\(?:warnin\\(g\\)\\|[a-z ]+\\) C[0-9]+:\\)"
266 2 3 nil (4))
267
268 (omake
269 ;; "omake -P" reports "file foo changed"
270 ;; (useful if you do "cvs up" and want to see what has changed)
271 "omake: file \\(.*\\) changed" 1 nil nil nil nil
272 ;; FIXME-omake: This tries to prevent reusing pre-existing markers
273 ;; for subsequent messages, since those messages's line numbers
274 ;; are about another version of the file.
275 (0 (progn (compilation--flush-file-structure (match-string 1))
276 nil)))
277
278 (oracle
279 "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\
280 \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\
281 \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$"
282 3 1 2)
283
284 ;; "during global destruction": This comes out under "use
285 ;; warnings" in recent perl when breaking circular references
286 ;; during program or thread exit.
287 (perl
288 " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \
289 during global destruction\\.$\\)" 1 2)
290
291 (php
292 "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"
293 2 3 nil nil)
294
295 (ruby-Test::Unit
296 "[\t ]*\\[\\([^\(].*\\):\\([1-9][0-9]*\\)\\(\\]\\)?:$" 1 2)
297
298 (rxp
299 "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\
300 \\([0-9]+\\) of file://\\(.+\\)"
301 4 2 3 (1))
302
303 (sparc-pascal-file
304 "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\
305 [12][09][0-9][0-9] +\\(.*\\):$"
306 1 nil nil 0)
307 (sparc-pascal-line
308 "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - "
309 nil 3 nil (2) nil (1 (compilation-face '(2))))
310 (sparc-pascal-example
311 "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+"
312 nil 1 nil (3) nil (2 (compilation-face '(3))))
313
314 (sun
315 ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\
316 File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?"
317 3 4 5 (1 . 2))
318
319 (sun-ada
320 "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
321
322 (watcom
323 "^[ \t]*\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)): ?\
324 \\(?:\\(Error! E[0-9]+\\)\\|\\(Warning! W[0-9]+\\)\\):"
325 1 2 nil (4))
326
327 (4bsd
328 "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\
329 \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3))
330
331 (gcov-file
332 "^ *-: *\\(0\\):Source:\\(.+\\)$"
333 2 1 nil 0 nil)
334 (gcov-header
335 "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$"
336 nil 1 nil 0 nil)
337 ;; Underlines over all lines of gcov output are too uncomfortable to read.
338 ;; However, hyperlinks embedded in the lines are useful.
339 ;; So I put default face on the lines; and then put
340 ;; compilation-*-face by manually to eliminate the underlines.
341 ;; The hyperlinks are still effective.
342 (gcov-nomark
343 "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$"
344 nil 1 nil 0 nil
345 (0 'default)
346 (1 compilation-line-face))
347 (gcov-called-line
348 "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$"
349 nil 2 nil 0 nil
350 (0 'default)
351 (1 compilation-info-face) (2 compilation-line-face))
352 (gcov-never-called
353 "^ *\\(#####\\): *\\([0-9]+\\):.*$"
354 nil 2 nil 2 nil
355 (0 'default)
356 (1 compilation-error-face) (2 compilation-line-face))
357
358 (perl--Pod::Checker
359 ;; podchecker error messages, per Pod::Checker.
360 ;; The style is from the Pod::Checker::poderror() function, eg.
361 ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm
362 ;;
363 ;; Plus end_pod() can give "at line EOF" instead of a
364 ;; number, so for that match "on line N" which is the
365 ;; originating spot, eg.
366 ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm
367 ;;
368 ;; Plus command() can give both "on line N" and "at line N";
369 ;; the latter is desired and is matched because the .* is
370 ;; greedy.
371 ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod
372 ;;
373 "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \
374 \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)"
375 3 2 nil (1))
376 (perl--Test
377 ;; perl Test module error messages.
378 ;; Style per the ok() function "$context", eg.
379 ;; # Failed test 1 in foo.t at line 6
380 ;;
381 "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
382 1 2)
383 (perl--Test2
384 ;; Or when comparing got/want values,
385 ;; # Test 2 got: "xx" (t-compilation-perl-2.t at line 10)
386 ;;
387 ;; And under Test::Harness they're preceded by progress stuff with
388 ;; \r and "NOK",
389 ;; ... NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
390 ;;
391 "^\\(.*NOK.*\\)?# Test [0-9]+ got:.* (\\([^ \t\r\n]+\\) at line \
392 \\([0-9]+\\))"
393 2 3)
394 (perl--Test::Harness
395 ;; perl Test::Harness output, eg.
396 ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46)
397 ;;
398 ;; Test::Harness is slightly designed for tty output, since
399 ;; it prints CRs to overwrite progress messages, but if you
400 ;; run it in with M-x compile this pattern can at least step
401 ;; through the failures.
402 ;;
403 "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)"
404 1 2)
405 (weblint
406 ;; The style comes from HTML::Lint::Error::as_string(), eg.
407 ;; index.html (13:1) Unknown element <fdjsk>
408 ;;
409 ;; The pattern only matches filenames without spaces, since that
410 ;; should be usual and should help reduce the chance of a false
411 ;; match of a message from some unrelated program.
412 ;;
413 ;; This message style is quite close to the "ibm" entry which is
414 ;; for IBM C, though that ibm bit doesn't put a space after the
415 ;; filename.
416 ;;
417 "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) "
418 1 2 3)
419 )
420 "Alist of values for `compilation-error-regexp-alist'.")
421
422 (defcustom compilation-error-regexp-alist
423 (mapcar 'car compilation-error-regexp-alist-alist)
424 "Alist that specifies how to match errors in compiler output.
425 On GNU and Unix, any string is a valid filename, so these
426 matchers must make some common sense assumptions, which catch
427 normal cases. A shorter list will be lighter on resource usage.
428
429 Instead of an alist element, you can use a symbol, which is
430 looked up in `compilation-error-regexp-alist-alist'. You can see
431 the predefined symbols and their effects in the file
432 `etc/compilation.txt' (linked below if you are customizing this).
433
434 Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
435 HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression
436 gives the file name, and the LINE'th subexpression gives the line
437 number. The COLUMN'th subexpression gives the column number on
438 that line.
439
440 If FILE, LINE or COLUMN are nil or that index didn't match, that
441 information is not present on the matched line. In that case the
442 file name is assumed to be the same as the previous one in the
443 buffer, line number defaults to 1 and column defaults to
444 beginning of line's indentation.
445
446 FILE can also have the form (FILE FORMAT...), where the FORMATs
447 \(e.g. \"%s.c\") will be applied in turn to the recognized file
448 name, until a file of that name is found. Or FILE can also be a
449 function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
450 In the former case, FILENAME may be relative or absolute.
451
452 LINE can also be of the form (LINE . END-LINE) meaning a range
453 of lines. COLUMN can also be of the form (COLUMN . END-COLUMN)
454 meaning a range of columns starting on LINE and ending on
455 END-LINE, if that matched.
456
457 TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
458 TYPE can also be of the form (WARNING . INFO). In that case this
459 will be equivalent to 1 if the WARNING'th subexpression matched
460 or else equivalent to 0 if the INFO'th subexpression matched.
461 See `compilation-error-face', `compilation-warning-face',
462 `compilation-info-face' and `compilation-skip-threshold'.
463
464 What matched the HYPERLINK'th subexpression has `mouse-face' and
465 `compilation-message-face' applied. If this is nil, the text
466 matched by the whole REGEXP becomes the hyperlink.
467
468 Additional HIGHLIGHTs take the shape (SUBMATCH FACE), where SUBMATCH is
469 the number of a submatch that should be highlighted when it matches,
470 and FACE is an expression returning the face to use for that submatch.."
471 :type '(repeat (choice (symbol :tag "Predefined symbol")
472 (sexp :tag "Error specification")))
473 :link `(file-link :tag "example file"
474 ,(expand-file-name "compilation.txt" data-directory))
475 :group 'compilation)
476
477 ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp)
478 (defvar compilation-directory nil
479 "Directory to restore to when doing `recompile'.")
480
481 (defvar compilation-directory-matcher
482 '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1))
483 "A list for tracking when directories are entered or left.
484 If nil, do not track directories, e.g. if all file names are absolute. The
485 first element is the REGEXP matching these messages. It can match any number
486 of variants, e.g. different languages. The remaining elements are all of the
487 form (DIR . LEAVE). If for any one of these the DIR'th subexpression
488 matches, that is a directory name. If LEAVE is nil or the corresponding
489 LEAVE'th subexpression doesn't match, this message is about going into another
490 directory. If it does match anything, this message is about going back to the
491 directory we were in before the last entering message. If you change this,
492 you may also want to change `compilation-page-delimiter'.")
493
494 (defvar compilation-page-delimiter
495 "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+"
496 "Value of `page-delimiter' in Compilation mode.")
497
498 (defvar compilation-mode-font-lock-keywords
499 '(;; configure output lines.
500 ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$"
501 (1 font-lock-variable-name-face)
502 (2 (compilation-face '(4 . 3))))
503 ;; Command output lines. Recognize `make[n]:' lines too.
504 ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
505 (1 font-lock-function-name-face) (3 compilation-line-face nil t))
506 (" -\\(?:o[= ]?\\|-\\(?:outfile\\|output\\)[= ]\\)\\(\\S +\\)" . 1)
507 ("^Compilation \\(finished\\).*"
508 (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t)
509 (1 compilation-info-face))
510 ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
511 (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t)
512 (1 compilation-error-face)
513 (2 compilation-error-face nil t)))
514 "Additional things to highlight in Compilation mode.
515 This gets tacked on the end of the generated expressions.")
516
517 (defvar compilation-highlight-regexp t
518 "Regexp matching part of visited source lines to highlight temporarily.
519 Highlight entire line if t; don't highlight source lines if nil.")
520
521 (defvar compilation-highlight-overlay nil
522 "Overlay used to temporarily highlight compilation matches.")
523
524 (defcustom compilation-error-screen-columns t
525 "If non-nil, column numbers in error messages are screen columns.
526 Otherwise they are interpreted as character positions, with
527 each character occupying one column.
528 The default is to use screen columns, which requires that the compilation
529 program and Emacs agree about the display width of the characters,
530 especially the TAB character."
531 :type 'boolean
532 :group 'compilation
533 :version "20.4")
534
535 (defcustom compilation-read-command t
536 "Non-nil means \\[compile] reads the compilation command to use.
537 Otherwise, \\[compile] just uses the value of `compile-command'.
538
539 Note that changing this to nil may be a security risk, because a
540 file might define a malicious `compile-command' as a file local
541 variable, and you might not notice. Therefore, `compile-command'
542 is considered unsafe if this variable is nil."
543 :type 'boolean
544 :group 'compilation)
545
546 ;;;###autoload
547 (defcustom compilation-ask-about-save t
548 "Non-nil means \\[compile] asks which buffers to save before compiling.
549 Otherwise, it saves all modified buffers without asking."
550 :type 'boolean
551 :group 'compilation)
552
553 (defcustom compilation-save-buffers-predicate nil
554 "The second argument (PRED) passed to `save-some-buffers' before compiling.
555 E.g., one can set this to
556 (lambda ()
557 (string-prefix-p my-compilation-root (file-truename (buffer-file-name))))
558 to limit saving to files located under `my-compilation-root'.
559 Note, that, in general, `compilation-directory' cannot be used instead
560 of `my-compilation-root' here."
561 :type '(choice
562 (const :tag "Default (save all file-visiting buffers)" nil)
563 (const :tag "Save all buffers" t)
564 function)
565 :group 'compilation
566 :version "24.1")
567
568 ;;;###autoload
569 (defcustom compilation-search-path '(nil)
570 "List of directories to search for source files named in error messages.
571 Elements should be directory names, not file names of directories.
572 The value nil as an element means to try the default directory."
573 :type '(repeat (choice (const :tag "Default" nil)
574 (string :tag "Directory")))
575 :group 'compilation)
576
577 ;;;###autoload
578 (defcustom compile-command (purecopy "make -k ")
579 "Last shell command used to do a compilation; default for next compilation.
580
581 Sometimes it is useful for files to supply local values for this variable.
582 You might also use mode hooks to specify it in certain modes, like this:
583
584 (add-hook 'c-mode-hook
585 (lambda ()
586 (unless (or (file-exists-p \"makefile\")
587 (file-exists-p \"Makefile\"))
588 (set (make-local-variable 'compile-command)
589 (concat \"make -k \"
590 (file-name-sans-extension buffer-file-name))))))"
591 :type 'string
592 :group 'compilation)
593 ;;;###autoload(put 'compile-command 'safe-local-variable (lambda (a) (and (stringp a) (or (not (boundp 'compilation-read-command)) compilation-read-command))))
594
595 ;;;###autoload
596 (defcustom compilation-disable-input nil
597 "If non-nil, send end-of-file as compilation process input.
598 This only affects platforms that support asynchronous processes (see
599 `start-process'); synchronous compilation processes never accept input."
600 :type 'boolean
601 :group 'compilation
602 :version "22.1")
603
604 ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each
605 ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash
606 ;; key. This holds the tree seen from root, for storing new nodes.
607 (defvar compilation-locs ())
608
609 (defvar compilation-debug nil
610 "*Set this to t before creating a *compilation* buffer.
611 Then every error line will have a debug text property with the matcher that
612 fit this line and the match data. Use `describe-text-properties'.")
613
614 (defvar compilation-exit-message-function nil "\
615 If non-nil, called when a compilation process dies to return a status message.
616 This should be a function of three arguments: process status, exit status,
617 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
618 write into the compilation buffer, and to put in its mode line.")
619
620 (defvar compilation-environment nil
621 "*List of environment variables for compilation to inherit.
622 Each element should be a string of the form ENVVARNAME=VALUE.
623 This list is temporarily prepended to `process-environment' prior to
624 starting the compilation process.")
625
626 ;; History of compile commands.
627 (defvar compile-history nil)
628
629 (defface compilation-error
630 '((t :inherit font-lock-warning-face))
631 "Face used to highlight compiler errors."
632 :group 'compilation
633 :version "22.1")
634
635 (defface compilation-warning
636 '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold))
637 (((class color)) (:foreground "cyan" :weight bold))
638 (t (:weight bold)))
639 "Face used to highlight compiler warnings."
640 :group 'compilation
641 :version "22.1")
642
643 (defface compilation-info
644 '((((class color) (min-colors 16) (background light))
645 (:foreground "Green3" :weight bold))
646 (((class color) (min-colors 88) (background dark))
647 (:foreground "Green1" :weight bold))
648 (((class color) (min-colors 16) (background dark))
649 (:foreground "Green" :weight bold))
650 (((class color)) (:foreground "green" :weight bold))
651 (t (:weight bold)))
652 "Face used to highlight compiler information."
653 :group 'compilation
654 :version "22.1")
655
656 (defface compilation-line-number
657 '((t :inherit font-lock-variable-name-face))
658 "Face for displaying line numbers in compiler messages."
659 :group 'compilation
660 :version "22.1")
661
662 (defface compilation-column-number
663 '((t :inherit font-lock-type-face))
664 "Face for displaying column numbers in compiler messages."
665 :group 'compilation
666 :version "22.1")
667
668 (defcustom compilation-message-face 'underline
669 "Face name to use for whole messages.
670 Faces `compilation-error-face', `compilation-warning-face',
671 `compilation-info-face', `compilation-line-face' and
672 `compilation-column-face' get prepended to this, when applicable."
673 :type 'face
674 :group 'compilation
675 :version "22.1")
676
677 (defvar compilation-error-face 'compilation-error
678 "Face name to use for file name in error messages.")
679
680 (defvar compilation-warning-face 'compilation-warning
681 "Face name to use for file name in warning messages.")
682
683 (defvar compilation-info-face 'compilation-info
684 "Face name to use for file name in informational messages.")
685
686 (defvar compilation-line-face 'compilation-line-number
687 "Face name to use for line numbers in compiler messages.")
688
689 (defvar compilation-column-face 'compilation-column-number
690 "Face name to use for column numbers in compiler messages.")
691
692 ;; same faces as dired uses
693 (defvar compilation-enter-directory-face 'font-lock-function-name-face
694 "Face name to use for entering directory messages.")
695
696 (defvar compilation-leave-directory-face 'font-lock-type-face
697 "Face name to use for leaving directory messages.")
698
699
700
701 ;; Used for compatibility with the old compile.el.
702 (defvar compilation-parse-errors-function nil)
703 (make-obsolete 'compilation-parse-errors-function
704 'compilation-error-regexp-alist "24.1")
705
706 (defcustom compilation-auto-jump-to-first-error nil
707 "If non-nil, automatically jump to the first error during compilation."
708 :type 'boolean
709 :group 'compilation
710 :version "23.1")
711
712 (defvar compilation-auto-jump-to-next nil
713 "If non-nil, automatically jump to the next error encountered.")
714 (make-variable-buffer-local 'compilation-auto-jump-to-next)
715
716 ;; (defvar compilation-buffer-modtime nil
717 ;; "The buffer modification time, for buffers not associated with files.")
718 ;; (make-variable-buffer-local 'compilation-buffer-modtime)
719
720 (defvar compilation-skip-to-next-location t
721 "*If non-nil, skip multiple error messages for the same source location.")
722
723 (defcustom compilation-skip-threshold 1
724 "Compilation motion commands skip less important messages.
725 The value can be either 2 -- skip anything less than error, 1 --
726 skip anything less than warning or 0 -- don't skip any messages.
727 Note that all messages not positively identified as warning or
728 info, are considered errors."
729 :type '(choice (const :tag "Skip warnings and info" 2)
730 (const :tag "Skip info" 1)
731 (const :tag "No skip" 0))
732 :group 'compilation
733 :version "22.1")
734
735 (defun compilation-set-skip-threshold (level)
736 "Switch the `compilation-skip-threshold' level."
737 (interactive
738 (list
739 (mod (if current-prefix-arg
740 (prefix-numeric-value current-prefix-arg)
741 (1+ compilation-skip-threshold))
742 3)))
743 (setq compilation-skip-threshold level)
744 (message "Skipping %s"
745 (case compilation-skip-threshold
746 (0 "Nothing")
747 (1 "Info messages")
748 (2 "Warnings and info"))))
749
750 (defcustom compilation-skip-visited nil
751 "Compilation motion commands skip visited messages if this is t.
752 Visited messages are ones for which the file, line and column have been jumped
753 to from the current content in the current compilation buffer, even if it was
754 from a different message."
755 :type 'boolean
756 :group 'compilation
757 :version "22.1")
758
759 (defun compilation-face (type)
760 (or (and (car type) (match-end (car type)) compilation-warning-face)
761 (and (cdr type) (match-end (cdr type)) compilation-info-face)
762 compilation-error-face))
763
764 ;; LOC (or location) is a list of (COLUMN LINE FILE-STRUCTURE nil nil)
765
766 ;; COLUMN and LINE are numbers parsed from an error message. COLUMN and maybe
767 ;; LINE will be nil for a message that doesn't contain them. Then the
768 ;; location refers to a indented beginning of line or beginning of file.
769 ;; Once any location in some file has been jumped to, the list is extended to
770 ;; (COLUMN LINE FILE-STRUCTURE MARKER TIMESTAMP . VISITED)
771 ;; for all LOCs pertaining to that file.
772 ;; MARKER initially points to LINE and COLUMN in a buffer visiting that file.
773 ;; Being a marker it sticks to some text, when the buffer grows or shrinks
774 ;; before that point. VISITED is t if we have jumped there, else nil.
775 ;; FIXME-omake: TIMESTAMP was used to try and handle "incremental compilation":
776 ;; `omake -P' polls filesystem for changes and recompiles when a file is
777 ;; modified using the same *compilation* buffer. this necessitates
778 ;; re-parsing markers.
779
780 ;; (defstruct (compilation--loc
781 ;; (:constructor nil)
782 ;; (:copier nil)
783 ;; (:constructor compilation--make-loc
784 ;; (file-struct line col marker))
785 ;; (:conc-name compilation--loc->))
786 ;; col line file-struct marker timestamp visited)
787
788 ;; FIXME: We don't use a defstruct because of compilation-assq which looks up
789 ;; and creates part of the LOC (only the first cons cell containing the COL).
790
791 (defmacro compilation--make-cdrloc (line file-struct marker)
792 `(list ,line ,file-struct ,marker nil))
793 (defmacro compilation--loc->col (loc) `(car ,loc))
794 (defmacro compilation--loc->line (loc) `(cadr ,loc))
795 (defmacro compilation--loc->file-struct (loc) `(nth 2 ,loc))
796 (defmacro compilation--loc->marker (loc) `(nth 3 ,loc))
797 ;; (defmacro compilation--loc->timestamp (loc) `(nth 4 ,loc))
798 (defmacro compilation--loc->visited (loc) `(nthcdr 5 ,loc))
799
800 ;; FILE-STRUCTURE is a list of
801 ;; ((FILENAME DIRECTORY) FORMATS (LINE LOC ...) ...)
802
803 ;; FILENAME is a string parsed from an error message. DIRECTORY is a string
804 ;; obtained by following directory change messages. DIRECTORY will be nil for
805 ;; an absolute filename. FORMATS is a list of formats to apply to FILENAME if
806 ;; a file of that name can't be found.
807 ;; The rest of the list is an alist of elements with LINE as key. The keys
808 ;; are either nil or line numbers. If present, nil comes first, followed by
809 ;; the numbers in decreasing order. The LOCs for each line are again an alist
810 ;; ordered the same way. Note that the whole file structure is referenced in
811 ;; every LOC.
812
813 (defmacro compilation--make-file-struct (file-spec formats &optional loc-tree)
814 `(cons ,file-spec (cons ,formats ,loc-tree)))
815 (defmacro compilation--file-struct->file-spec (fs) `(car ,fs))
816 (defmacro compilation--file-struct->formats (fs) `(cadr ,fs))
817 ;; The FORMATS field plays the role of ANCHOR in the loc-tree.
818 (defmacro compilation--file-struct->loc-tree (fs) `(cdr ,fs))
819
820 ;; MESSAGE is a list of (LOC TYPE END-LOC)
821
822 ;; TYPE is 0 for info or 1 for warning if the message matcher identified it as
823 ;; such, 2 otherwise (for a real error). END-LOC is a LOC pointing to the
824 ;; other end, if the parsed message contained a range. If the end of the
825 ;; range didn't specify a COLUMN, it defaults to -1, meaning end of line.
826 ;; These are the value of the `compilation-message' text-properties in the
827 ;; compilation buffer.
828
829 (defstruct (compilation--message
830 (:constructor nil)
831 (:copier nil)
832 ;; (:type list) ;Old representation.
833 (:constructor compilation--make-message (loc type end-loc))
834 (:conc-name compilation--message->))
835 loc type end-loc)
836
837 (defvar compilation--previous-directory-cache nil
838 "A pair (POS . RES) caching the result of previous directory search.
839 Basically, this pair says that calling
840 (previous-single-property-change POS 'compilation-directory)
841 returned RES, i.e. there is no change of `compilation-directory' between
842 POS and RES.")
843 (make-variable-buffer-local 'compilation--previous-directory-cache)
844
845 (defun compilation--flush-directory-cache (start end)
846 (cond
847 ((or (not compilation--previous-directory-cache)
848 (<= (car compilation--previous-directory-cache) start)))
849 ((or (not (cdr compilation--previous-directory-cache))
850 (<= (cdr compilation--previous-directory-cache) start))
851 (set-marker (car compilation--previous-directory-cache) start))
852 (t (setq compilation--previous-directory-cache nil))))
853
854 (defun compilation--previous-directory (pos)
855 "Like (previous-single-property-change POS 'compilation-directory), but faster."
856 ;; This avoids an N² behavior when there's no/few compilation-directory
857 ;; entries, in which case each call to previous-single-property-change
858 ;; ends up having to walk very far back to find the last change.
859 (if (and compilation--previous-directory-cache
860 (< pos (car compilation--previous-directory-cache))
861 (or (null (cdr compilation--previous-directory-cache))
862 (< (cdr compilation--previous-directory-cache) pos)))
863 ;; No need to call previous-single-property-change.
864 (cdr compilation--previous-directory-cache)
865
866 (let* ((cache (and compilation--previous-directory-cache
867 (<= (car compilation--previous-directory-cache) pos)
868 (car compilation--previous-directory-cache)))
869 (prev
870 (previous-single-property-change
871 pos 'compilation-directory nil cache)))
872 (cond
873 ((null cache)
874 (setq compilation--previous-directory-cache
875 (cons (copy-marker pos) (copy-marker prev)))
876 prev)
877 ((eq prev cache)
878 (if cache
879 (set-marker (car compilation--previous-directory-cache) pos)
880 (setq compilation--previous-directory-cache
881 (cons (copy-marker pos) nil)))
882 (cdr compilation--previous-directory-cache))
883 (t
884 (if cache
885 (progn
886 (set-marker (car compilation--previous-directory-cache) pos)
887 (setcdr compilation--previous-directory-cache
888 (copy-marker prev)))
889 (setq compilation--previous-directory-cache
890 (cons (copy-marker pos) (copy-marker prev))))
891 prev)))))
892
893 ;; Internal function for calculating the text properties of a directory
894 ;; change message. The compilation-directory property is important, because it
895 ;; is the stack of nested enter-messages. Relative filenames on the following
896 ;; lines are relative to the top of the stack.
897 (defun compilation-directory-properties (idx leave)
898 (if leave (setq leave (match-end leave)))
899 ;; find previous stack, and push onto it, or if `leave' pop it
900 (let ((dir (compilation--previous-directory (point))))
901 (setq dir (if dir (or (get-text-property (1- dir) 'compilation-directory)
902 (get-text-property dir 'compilation-directory))))
903 `(font-lock-face ,(if leave
904 compilation-leave-directory-face
905 compilation-enter-directory-face)
906 compilation-directory ,(if leave
907 (or (cdr dir)
908 '(nil)) ; nil only isn't a property-change
909 (cons (match-string-no-properties idx) dir))
910 ;; Place a `compilation-message' everywhere we change text-properties
911 ;; so compilation--remove-properties can know what to remove.
912 compilation-message ,(compilation--make-message nil 0 nil)
913 mouse-face highlight
914 keymap compilation-button-map
915 help-echo "mouse-2: visit destination directory")))
916
917 ;; Data type `reverse-ordered-alist' retriever. This function retrieves the
918 ;; KEY element from the ALIST, creating it in the right position if not already
919 ;; present. ALIST structure is
920 ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...))
921 ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1
922 ;; may be nil. The other KEYs are ordered backwards so that growing line
923 ;; numbers can be inserted in front and searching can abort after half the
924 ;; list on average.
925 (eval-when-compile ;Don't keep it at runtime if not needed.
926 (defmacro compilation-assq (key alist)
927 `(let* ((l1 ,alist)
928 (l2 (cdr l1)))
929 (car (if (if (null ,key)
930 (if l2 (null (caar l2)))
931 (while (if l2 (if (caar l2) (< ,key (caar l2)) t))
932 (setq l1 l2
933 l2 (cdr l1)))
934 (if l2 (eq ,key (caar l2))))
935 l2
936 (setcdr l1 (cons (list ,key) l2)))))))
937
938 (defun compilation-auto-jump (buffer pos)
939 (with-current-buffer buffer
940 (goto-char pos)
941 (let ((win (get-buffer-window buffer 0)))
942 (if win (set-window-point win pos)))
943 (if compilation-auto-jump-to-first-error
944 (compile-goto-error))))
945
946 ;; This function is the central driver, called when font-locking to gather
947 ;; all information needed to later jump to corresponding source code.
948 ;; Return a property list with all meta information on this error location.
949
950 (defun compilation-error-properties (file line end-line col end-col type fmt)
951 (unless (text-property-not-all (match-beginning 0) (point)
952 'compilation-message nil)
953 (if file
954 (when (stringp
955 (setq file (if (functionp file) (funcall file)
956 (match-string-no-properties file))))
957 (let ((dir
958 (unless (file-name-absolute-p file)
959 (let ((pos (compilation--previous-directory (point))))
960 (when pos
961 (or (get-text-property (1- pos) 'compilation-directory)
962 (get-text-property pos 'compilation-directory)))))))
963 (setq file (cons file (car dir)))))
964 ;; This message didn't mention one, get it from previous
965 (let ((prev-pos
966 ;; Find the previous message.
967 (previous-single-property-change (point) 'compilation-message)))
968 (if prev-pos
969 ;; Get the file structure that belongs to it.
970 (let* ((prev
971 (or (get-text-property (1- prev-pos) 'compilation-message)
972 (get-text-property prev-pos 'compilation-message)))
973 (prev-struct
974 (car (nth 2 (car prev)))))
975 ;; Construct FILE . DIR from that.
976 (if prev-struct
977 (setq file (cons (car prev-struct)
978 (cadr prev-struct))))))
979 (unless file
980 (setq file '("*unknown*")))))
981 ;; All of these fields are optional, get them only if we have an index, and
982 ;; it matched some part of the message.
983 (and line
984 (setq line (match-string-no-properties line))
985 (setq line (string-to-number line)))
986 (and end-line
987 (setq end-line (match-string-no-properties end-line))
988 (setq end-line (string-to-number end-line)))
989 (if col
990 (if (functionp col)
991 (setq col (funcall col))
992 (and
993 (setq col (match-string-no-properties col))
994 (setq col (- (string-to-number col) compilation-first-column)))))
995 (if (and end-col (functionp end-col))
996 (setq end-col (funcall end-col))
997 (if (and end-col (setq end-col (match-string-no-properties end-col)))
998 (setq end-col (- (string-to-number end-col) compilation-first-column -1))
999 (if end-line (setq end-col -1))))
1000 (if (consp type) ; not a static type, check what it is.
1001 (setq type (or (and (car type) (match-end (car type)) 1)
1002 (and (cdr type) (match-end (cdr type)) 0)
1003 2)))
1004
1005 (when (and compilation-auto-jump-to-next
1006 (>= type compilation-skip-threshold))
1007 (kill-local-variable 'compilation-auto-jump-to-next)
1008 (run-with-timer 0 nil 'compilation-auto-jump
1009 (current-buffer) (match-beginning 0)))
1010
1011 (compilation-internal-error-properties
1012 file line end-line col end-col type fmt)))
1013
1014 (defun compilation-move-to-column (col screen)
1015 "Go to column COL on the current line.
1016 If SCREEN is non-nil, columns are screen columns, otherwise, they are
1017 just char-counts."
1018 (if screen
1019 (move-to-column (max col 0))
1020 (goto-char (min (+ (line-beginning-position) col) (line-end-position)))))
1021
1022 (defun compilation-internal-error-properties (file line end-line col end-col type fmts)
1023 "Get the meta-info that will be added as text-properties.
1024 LINE, END-LINE, COL, END-COL are integers or nil.
1025 TYPE can be 0, 1, or 2, meaning error, warning, or just info.
1026 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil.
1027 FMTS is a list of format specs for transforming the file name.
1028 (See `compilation-error-regexp-alist'.)"
1029 (unless file (setq file '("*unknown*")))
1030 (let* ((file-struct (compilation-get-file-structure file fmts))
1031 ;; Get first already existing marker (if any has one, all have one).
1032 ;; Do this first, as the compilation-assq`s may create new nodes.
1033 (marker-line ; a line structure
1034 (cadr (compilation--file-struct->loc-tree file-struct)))
1035 (marker
1036 (if marker-line (compilation--loc->marker (cadr marker-line))))
1037 (compilation-error-screen-columns compilation-error-screen-columns)
1038 end-marker loc end-loc)
1039 (if (not (and marker (marker-buffer marker)))
1040 (setq marker nil) ; no valid marker for this file
1041 (setq loc (or line 1)) ; normalize no linenumber to line 1
1042 (catch 'marker ; find nearest loc, at least one exists
1043 (dolist (x (cddr (compilation--file-struct->loc-tree
1044 file-struct))) ; Loop over remaining lines.
1045 (if (> (car x) loc) ; still bigger
1046 (setq marker-line x)
1047 (if (> (- (or (car marker-line) 1) loc)
1048 (- loc (car x))) ; current line is nearer
1049 (setq marker-line x))
1050 (throw 'marker t))))
1051 (setq marker (compilation--loc->marker (cadr marker-line))
1052 marker-line (or (car marker-line) 1))
1053 (with-current-buffer (marker-buffer marker)
1054 (save-excursion
1055 (save-restriction
1056 (widen)
1057 (goto-char (marker-position marker))
1058 (when (or end-col end-line)
1059 (beginning-of-line (- (or end-line line) marker-line -1))
1060 (if (or (null end-col) (< end-col 0))
1061 (end-of-line)
1062 (compilation-move-to-column
1063 end-col compilation-error-screen-columns))
1064 (setq end-marker (point-marker)))
1065 (beginning-of-line (if end-line
1066 (- line end-line -1)
1067 (- loc marker-line -1)))
1068 (if col
1069 (compilation-move-to-column
1070 col compilation-error-screen-columns)
1071 (forward-to-indentation 0))
1072 (setq marker (point-marker))))))
1073
1074 (setq loc (compilation-assq line (compilation--file-struct->loc-tree
1075 file-struct)))
1076 (setq end-loc
1077 (if end-line
1078 (compilation-assq
1079 end-col (compilation-assq
1080 end-line (compilation--file-struct->loc-tree
1081 file-struct)))
1082 (if end-col ; use same line element
1083 (compilation-assq end-col loc))))
1084 (setq loc (compilation-assq col loc))
1085 ;; If they are new, make the loc(s) reference the file they point to.
1086 ;; FIXME-omake: there's a problem with timestamps here: the markers
1087 ;; relative to which we computed the current `marker' have a timestamp
1088 ;; almost guaranteed to be different from compilation-buffer-modtime, so if
1089 ;; we use their timestamp, we'll never use `loc' since the timestamp won't
1090 ;; match compilation-buffer-modtime, and if we use
1091 ;; compilation-buffer-modtime then we have different timestamps for
1092 ;; locations that were computed together, which doesn't make sense either.
1093 ;; I think this points to a fundamental problem in our approach to the
1094 ;; "omake -P" problem. --Stef
1095 (or (cdr loc)
1096 (setcdr loc (compilation--make-cdrloc line file-struct marker)))
1097 (if end-loc
1098 (or (cdr end-loc)
1099 (setcdr end-loc
1100 (compilation--make-cdrloc (or end-line line) file-struct
1101 end-marker))))
1102
1103 ;; Must start with face
1104 `(font-lock-face ,compilation-message-face
1105 compilation-message ,(compilation--make-message loc type end-loc)
1106 help-echo ,(if col
1107 "mouse-2: visit this file, line and column"
1108 (if line
1109 "mouse-2: visit this file and line"
1110 "mouse-2: visit this file"))
1111 keymap compilation-button-map
1112 mouse-face highlight)))
1113
1114 (defun compilation--put-prop (matchnum prop val)
1115 (when (and (integerp matchnum) (match-beginning matchnum))
1116 (put-text-property
1117 (match-beginning matchnum) (match-end matchnum)
1118 prop val)))
1119
1120 (defun compilation--remove-properties (&optional start end)
1121 (with-silent-modifications
1122 ;; When compile.el used font-lock directly, we could just remove all
1123 ;; our text-properties in one go, but now that we manually place
1124 ;; font-lock-face, we have to be careful to only remove the font-lock-face
1125 ;; we placed.
1126 ;; (remove-list-of-text-properties
1127 ;; (or start (point-min)) (or end (point-max))
1128 ;; '(compilation-debug compilation-directory compilation-message
1129 ;; font-lock-face help-echo mouse-face))
1130 (let (next)
1131 (unless start (setq start (point-min)))
1132 (unless end (setq end (point-max)))
1133 (compilation--flush-directory-cache start end)
1134 (while
1135 (progn
1136 (setq next (or (next-single-property-change
1137 start 'compilation-message nil end)
1138 end))
1139 (when (get-text-property start 'compilation-message)
1140 (remove-list-of-text-properties
1141 start next
1142 '(compilation-debug compilation-directory compilation-message
1143 font-lock-face help-echo mouse-face)))
1144 (< next end))
1145 (setq start next)))))
1146
1147 (defun compilation--parse-region (start end)
1148 (goto-char end)
1149 (unless (bolp)
1150 ;; We generally don't like to parse partial lines.
1151 (assert (eobp))
1152 (when (let ((proc (get-buffer-process (current-buffer))))
1153 (and proc (memq (process-status proc) '(run open))))
1154 (setq end (line-beginning-position))))
1155 (compilation--remove-properties start end)
1156 (if compilation-parse-errors-function
1157 ;; An old package! Try the compatibility code.
1158 (progn
1159 (goto-char start)
1160 (compilation--compat-parse-errors end))
1161
1162 ;; compilation-directory-matcher is the only part that really needs to be
1163 ;; parsed sequentially. So we could split it out, handle directories
1164 ;; like syntax-propertize, and the rest as font-lock-keywords. But since
1165 ;; we want to have it work even when font-lock is off, we'd then need to
1166 ;; use our own compilation-parsed text-property to keep track of the parts
1167 ;; that have already been parsed.
1168 (goto-char start)
1169 (while (re-search-forward (car compilation-directory-matcher)
1170 end t)
1171 (compilation--flush-directory-cache (match-beginning 0) (match-end 0))
1172 (when compilation-debug
1173 (font-lock-append-text-property
1174 (match-beginning 0) (match-end 0)
1175 'compilation-debug
1176 (vector 'directory compilation-directory-matcher)))
1177 (dolist (elt (cdr compilation-directory-matcher))
1178 (add-text-properties (match-beginning (car elt))
1179 (match-end (car elt))
1180 (compilation-directory-properties
1181 (car elt) (cdr elt)))))
1182
1183 (compilation-parse-errors start end)))
1184
1185 (defun compilation-parse-errors (start end &rest rules)
1186 "Parse errors between START and END.
1187 The errors recognized are the ones specified in RULES which default
1188 to `compilation-error-regexp-alist' if RULES is nil."
1189 (dolist (item (or rules compilation-error-regexp-alist))
1190 (if (symbolp item)
1191 (setq item (cdr (assq item
1192 compilation-error-regexp-alist-alist))))
1193 (let ((file (nth 1 item))
1194 (line (nth 2 item))
1195 (col (nth 3 item))
1196 (type (nth 4 item))
1197 (pat (car item))
1198 end-line end-col fmt
1199 props)
1200
1201 ;; omake reports some error indented, so skip the indentation.
1202 ;; another solution is to modify (some?) regexps in
1203 ;; `compilation-error-regexp-alist'.
1204 ;; note that omake usage is not limited to ocaml and C (for stubs).
1205 ;; FIXME-omake: Doing it here seems wrong, at least it should depend on
1206 ;; whether or not omake's own error messages are recognized.
1207 (cond
1208 ((not (memq 'omake compilation-error-regexp-alist)) nil)
1209 ((string-match "\\`\\([^^]\\|^\\( \\*\\|\\[\\)\\)" pat)
1210 nil) ;; Not anchored or anchored but already allows empty spaces.
1211 (t (setq pat (concat "^ *" (substring pat 1)))))
1212
1213 (if (consp file) (setq fmt (cdr file) file (car file)))
1214 (if (consp line) (setq end-line (cdr line) line (car line)))
1215 (if (consp col) (setq end-col (cdr col) col (car col)))
1216
1217 (if (functionp line)
1218 ;; The old compile.el had here an undocumented hook that
1219 ;; allowed `line' to be a function that computed the actual
1220 ;; error location. Let's do our best.
1221 (progn
1222 (goto-char start)
1223 (while (re-search-forward pat end t)
1224 (save-match-data
1225 (when compilation-debug
1226 (font-lock-append-text-property
1227 (match-beginning 0) (match-end 0)
1228 'compilation-debug (vector 'functionp item)))
1229 (add-text-properties
1230 (match-beginning 0) (match-end 0)
1231 (compilation--compat-error-properties
1232 (funcall line (cons (match-string file)
1233 (cons default-directory
1234 (nthcdr 4 item)))
1235 (if col (match-string col))))))
1236 (compilation--put-prop
1237 file 'font-lock-face compilation-error-face)))
1238
1239 (unless (or (null (nth 5 item)) (integerp (nth 5 item)))
1240 (error "HYPERLINK should be an integer: %s" (nth 5 item)))
1241
1242 (goto-char start)
1243 (while (re-search-forward pat end t)
1244 (when (setq props (compilation-error-properties
1245 file line end-line col end-col (or type 2) fmt))
1246
1247 (when (integerp file)
1248 (compilation--put-prop
1249 file 'font-lock-face
1250 (if (consp type)
1251 (compilation-face type)
1252 (symbol-value (aref [compilation-info-face
1253 compilation-warning-face
1254 compilation-error-face]
1255 (or type 2))))))
1256
1257 (compilation--put-prop
1258 line 'font-lock-face compilation-line-face)
1259 (compilation--put-prop
1260 end-line 'font-lock-face compilation-line-face)
1261
1262 (compilation--put-prop
1263 col 'font-lock-face compilation-column-face)
1264 (compilation--put-prop
1265 end-col 'font-lock-face compilation-column-face)
1266
1267 (dolist (extra-item (nthcdr 6 item))
1268 (let ((mn (pop extra-item)))
1269 (when (match-beginning mn)
1270 (let ((face (eval (car extra-item))))
1271 (cond
1272 ((null face))
1273 ((symbolp face)
1274 (put-text-property
1275 (match-beginning mn) (match-end mn)
1276 'font-lock-face face))
1277 (t
1278 (error "Don't know how to handle face %S"
1279 face)))))))
1280 (let ((mn (or (nth 5 item) 0)))
1281 (when compilation-debug
1282 (font-lock-append-text-property
1283 (match-beginning 0) (match-end 0)
1284 'compilation-debug (vector 'std item props)))
1285 (add-text-properties
1286 (match-beginning mn) (match-end mn)
1287 (cddr props))
1288 (font-lock-append-text-property
1289 (match-beginning mn) (match-end mn)
1290 'font-lock-face (cadr props)))))))))
1291
1292 (defvar compilation--parsed -1)
1293 (make-variable-buffer-local 'compilation--parsed)
1294
1295 (defun compilation--ensure-parse (limit)
1296 "Make sure the text has been parsed up to LIMIT."
1297 (save-excursion
1298 (goto-char limit)
1299 (setq limit (line-beginning-position 2))
1300 (unless (markerp compilation--parsed)
1301 ;; We use a marker for compilation--parsed so that users (such as
1302 ;; grep.el) don't need to flush-parse when they modify the buffer
1303 ;; in a way that impacts buffer positions but does not require
1304 ;; re-parsing.
1305 (setq compilation--parsed (point-min-marker)))
1306 (when (< compilation--parsed limit)
1307 (let ((start (max compilation--parsed (point-min))))
1308 (move-marker compilation--parsed limit)
1309 (goto-char start)
1310 (forward-line 0) ;Not line-beginning-position: ignore (comint) fields.
1311 (with-silent-modifications
1312 (compilation--parse-region (point) compilation--parsed)))))
1313 nil)
1314
1315 (defun compilation--flush-parse (start end)
1316 "Mark the region between START and END for re-parsing."
1317 (if (markerp compilation--parsed)
1318 (move-marker compilation--parsed (min start compilation--parsed))))
1319
1320 (defun compilation-mode-font-lock-keywords ()
1321 "Return expressions to highlight in Compilation mode."
1322 (append
1323 '((compilation--ensure-parse))
1324 compilation-mode-font-lock-keywords))
1325
1326 (defun compilation-read-command (command)
1327 (read-shell-command "Compile command: " command
1328 (if (equal (car compile-history) command)
1329 '(compile-history . 1)
1330 'compile-history)))
1331
1332 \f
1333 ;;;###autoload
1334 (defun compile (command &optional comint)
1335 "Compile the program including the current buffer. Default: run `make'.
1336 Runs COMMAND, a shell command, in a separate process asynchronously
1337 with output going to the buffer `*compilation*'.
1338
1339 You can then use the command \\[next-error] to find the next error message
1340 and move to the source code that caused it.
1341
1342 If optional second arg COMINT is t the buffer will be in Comint mode with
1343 `compilation-shell-minor-mode'.
1344
1345 Interactively, prompts for the command if `compilation-read-command' is
1346 non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
1347 Additionally, with universal prefix arg, compilation buffer will be in
1348 comint mode, i.e. interactive.
1349
1350 To run more than one compilation at once, start one then rename
1351 the \`*compilation*' buffer to some other name with
1352 \\[rename-buffer]. Then _switch buffers_ and start the new compilation.
1353 It will create a new \`*compilation*' buffer.
1354
1355 On most systems, termination of the main compilation process
1356 kills its subprocesses.
1357
1358 The name used for the buffer is actually whatever is returned by
1359 the function in `compilation-buffer-name-function', so you can set that
1360 to a function that generates a unique name."
1361 (interactive
1362 (list
1363 (let ((command (eval compile-command)))
1364 (if (or compilation-read-command current-prefix-arg)
1365 (compilation-read-command command)
1366 command))
1367 (consp current-prefix-arg)))
1368 (unless (equal command (eval compile-command))
1369 (setq compile-command command))
1370 (save-some-buffers (not compilation-ask-about-save)
1371 compilation-save-buffers-predicate)
1372 (setq-default compilation-directory default-directory)
1373 (compilation-start command comint))
1374
1375 ;; run compile with the default command line
1376 (defun recompile (&optional edit-command)
1377 "Re-compile the program including the current buffer.
1378 If this is run in a Compilation mode buffer, re-use the arguments from the
1379 original use. Otherwise, recompile using `compile-command'.
1380 If the optional argument `edit-command' is non-nil, the command can be edited."
1381 (interactive "P")
1382 (save-some-buffers (not compilation-ask-about-save)
1383 compilation-save-buffers-predicate)
1384 (let ((default-directory (or compilation-directory default-directory)))
1385 (when edit-command
1386 (setcar compilation-arguments
1387 (compilation-read-command (car compilation-arguments))))
1388 (apply 'compilation-start (or compilation-arguments
1389 `(,(eval compile-command))))))
1390
1391 (defcustom compilation-scroll-output nil
1392 "Non-nil to scroll the *compilation* buffer window as output appears.
1393
1394 Setting it causes the Compilation mode commands to put point at the
1395 end of their output window so that the end of the output is always
1396 visible rather than the beginning.
1397
1398 The value `first-error' stops scrolling at the first error, and leaves
1399 point on its location in the *compilation* buffer."
1400 :type '(choice (const :tag "No scrolling" nil)
1401 (const :tag "Scroll compilation output" t)
1402 (const :tag "Stop scrolling at the first error" first-error))
1403 :version "20.3"
1404 :group 'compilation)
1405
1406
1407 (defun compilation-buffer-name (mode-name mode-command name-function)
1408 "Return the name of a compilation buffer to use.
1409 If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME
1410 to determine the buffer name.
1411 Likewise if `compilation-buffer-name-function' is non-nil.
1412 If current buffer has the major mode MODE-COMMAND,
1413 return the name of the current buffer, so that it gets reused.
1414 Otherwise, construct a buffer name from MODE-NAME."
1415 (cond (name-function
1416 (funcall name-function mode-name))
1417 (compilation-buffer-name-function
1418 (funcall compilation-buffer-name-function mode-name))
1419 ((eq mode-command major-mode)
1420 (buffer-name))
1421 (t
1422 (concat "*" (downcase mode-name) "*"))))
1423
1424 ;; This is a rough emulation of the old hack, until the transition to new
1425 ;; compile is complete.
1426 (defun compile-internal (command error-message
1427 &optional name-of-mode parser
1428 error-regexp-alist name-function
1429 enter-regexp-alist leave-regexp-alist
1430 file-regexp-alist nomessage-regexp-alist
1431 no-async highlight-regexp local-map)
1432 (if parser
1433 (error "Compile now works very differently, see `compilation-error-regexp-alist'"))
1434 (let ((compilation-error-regexp-alist
1435 (append file-regexp-alist (or error-regexp-alist
1436 compilation-error-regexp-alist)))
1437 (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?"
1438 "\\1" error-message)))
1439 (compilation-start command nil name-function highlight-regexp)))
1440 (make-obsolete 'compile-internal 'compilation-start "22.1")
1441
1442 ;;;###autoload
1443 (defun compilation-start (command &optional mode name-function highlight-regexp)
1444 "Run compilation command COMMAND (low level interface).
1445 If COMMAND starts with a cd command, that becomes the `default-directory'.
1446 The rest of the arguments are optional; for them, nil means use the default.
1447
1448 MODE is the major mode to set in the compilation buffer. Mode
1449 may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'.
1450
1451 If NAME-FUNCTION is non-nil, call it with one argument (the mode name)
1452 to determine the buffer name. Otherwise, the default is to
1453 reuses the current buffer if it has the proper major mode,
1454 else use or create a buffer with name based on the major mode.
1455
1456 If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight
1457 the matching section of the visited source line; the default is to use the
1458 global value of `compilation-highlight-regexp'.
1459
1460 Returns the compilation buffer created."
1461 (or mode (setq mode 'compilation-mode))
1462 (let* ((name-of-mode
1463 (if (eq mode t)
1464 "compilation"
1465 (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
1466 (thisdir default-directory)
1467 outwin outbuf)
1468 (with-current-buffer
1469 (setq outbuf
1470 (get-buffer-create
1471 (compilation-buffer-name name-of-mode mode name-function)))
1472 (let ((comp-proc (get-buffer-process (current-buffer))))
1473 (if comp-proc
1474 (if (or (not (eq (process-status comp-proc) 'run))
1475 (yes-or-no-p
1476 (format "A %s process is running; kill it? "
1477 name-of-mode)))
1478 (condition-case ()
1479 (progn
1480 (interrupt-process comp-proc)
1481 (sit-for 1)
1482 (delete-process comp-proc))
1483 (error nil))
1484 (error "Cannot have two processes in `%s' at once"
1485 (buffer-name)))))
1486 ;; first transfer directory from where M-x compile was called
1487 (setq default-directory thisdir)
1488 ;; Make compilation buffer read-only. The filter can still write it.
1489 ;; Clear out the compilation buffer.
1490 (let ((inhibit-read-only t)
1491 (default-directory thisdir))
1492 ;; Then evaluate a cd command if any, but don't perform it yet, else
1493 ;; start-command would do it again through the shell: (cd "..") AND
1494 ;; sh -c "cd ..; make"
1495 (cd (if (string-match "\\`\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]"
1496 command)
1497 (if (match-end 1)
1498 (substitute-env-vars (match-string 1 command))
1499 "~")
1500 default-directory))
1501 (erase-buffer)
1502 ;; Select the desired mode.
1503 (if (not (eq mode t))
1504 (progn
1505 (buffer-disable-undo)
1506 (funcall mode))
1507 (setq buffer-read-only nil)
1508 (with-no-warnings (comint-mode))
1509 (compilation-shell-minor-mode))
1510 ;; Remember the original dir, so we can use it when we recompile.
1511 ;; default-directory' can't be used reliably for that because it may be
1512 ;; affected by the special handling of "cd ...;".
1513 ;; NB: must be fone after (funcall mode) as that resets local variables
1514 (set (make-local-variable 'compilation-directory) thisdir)
1515 (if highlight-regexp
1516 (set (make-local-variable 'compilation-highlight-regexp)
1517 highlight-regexp))
1518 (if (or compilation-auto-jump-to-first-error
1519 (eq compilation-scroll-output 'first-error))
1520 (set (make-local-variable 'compilation-auto-jump-to-next) t))
1521 ;; Output a mode setter, for saving and later reloading this buffer.
1522 (insert "-*- mode: " name-of-mode
1523 "; default-directory: "
1524 (prin1-to-string (abbreviate-file-name default-directory))
1525 " -*-\n"
1526 (format "%s started at %s\n\n"
1527 mode-name
1528 (substring (current-time-string) 0 19))
1529 command "\n")
1530 (setq thisdir default-directory))
1531 (set-buffer-modified-p nil))
1532 ;; Pop up the compilation buffer.
1533 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html
1534 (setq outwin (display-buffer outbuf))
1535 (with-current-buffer outbuf
1536 (let ((process-environment
1537 (append
1538 compilation-environment
1539 (if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning
1540 system-uses-terminfo)
1541 (list "TERM=dumb" "TERMCAP="
1542 (format "COLUMNS=%d" (window-width)))
1543 (list "TERM=emacs"
1544 (format "TERMCAP=emacs:co#%d:tc=unknown:"
1545 (window-width))))
1546 ;; Set the EMACS variable, but
1547 ;; don't override users' setting of $EMACS.
1548 (unless (getenv "EMACS")
1549 (list "EMACS=t"))
1550 (list "INSIDE_EMACS=t")
1551 (copy-sequence process-environment))))
1552 (set (make-local-variable 'compilation-arguments)
1553 (list command mode name-function highlight-regexp))
1554 (set (make-local-variable 'revert-buffer-function)
1555 'compilation-revert-buffer)
1556 (set-window-start outwin (point-min))
1557
1558 ;; Position point as the user will see it.
1559 (let ((desired-visible-point
1560 ;; Put it at the end if `compilation-scroll-output' is set.
1561 (if compilation-scroll-output
1562 (point-max)
1563 ;; Normally put it at the top.
1564 (point-min))))
1565 (if (eq outwin (selected-window))
1566 (goto-char desired-visible-point)
1567 (set-window-point outwin desired-visible-point)))
1568
1569 ;; The setup function is called before compilation-set-window-height
1570 ;; so it can set the compilation-window-height buffer locally.
1571 (if compilation-process-setup-function
1572 (funcall compilation-process-setup-function))
1573 (compilation-set-window-height outwin)
1574 ;; Start the compilation.
1575 (if (fboundp 'start-process)
1576 (let ((proc
1577 (if (eq mode t)
1578 ;; comint uses `start-file-process'.
1579 (get-buffer-process
1580 (with-no-warnings
1581 (comint-exec
1582 outbuf (downcase mode-name)
1583 (if (file-remote-p default-directory)
1584 "/bin/sh"
1585 shell-file-name)
1586 nil `("-c" ,command))))
1587 (start-file-process-shell-command (downcase mode-name)
1588 outbuf command))))
1589 ;; Make the buffer's mode line show process state.
1590 (setq mode-line-process
1591 (list (propertize ":%s" 'face 'compilation-warning)))
1592 (set-process-sentinel proc 'compilation-sentinel)
1593 (unless (eq mode t)
1594 ;; Keep the comint filter, since it's needed for proper handling
1595 ;; of the prompts.
1596 (set-process-filter proc 'compilation-filter))
1597 ;; Use (point-max) here so that output comes in
1598 ;; after the initial text,
1599 ;; regardless of where the user sees point.
1600 (set-marker (process-mark proc) (point-max) outbuf)
1601 (when compilation-disable-input
1602 (condition-case nil
1603 (process-send-eof proc)
1604 ;; The process may have exited already.
1605 (error nil)))
1606 (run-hook-with-args 'compilation-start-hook proc)
1607 (setq compilation-in-progress
1608 (cons proc compilation-in-progress)))
1609 ;; No asynchronous processes available.
1610 (message "Executing `%s'..." command)
1611 ;; Fake modeline display as if `start-process' were run.
1612 (setq mode-line-process
1613 (list (propertize ":run" 'face 'compilation-warning)))
1614 (force-mode-line-update)
1615 (sit-for 0) ; Force redisplay
1616 (save-excursion
1617 ;; Insert the output at the end, after the initial text,
1618 ;; regardless of where the user sees point.
1619 (goto-char (point-max))
1620 (let* ((inhibit-read-only t) ; call-process needs to modify outbuf
1621 (status (call-process shell-file-name nil outbuf nil "-c"
1622 command)))
1623 (cond ((numberp status)
1624 (compilation-handle-exit
1625 'exit status
1626 (if (zerop status)
1627 "finished\n"
1628 (format "exited abnormally with code %d\n" status))))
1629 ((stringp status)
1630 (compilation-handle-exit 'signal status
1631 (concat status "\n")))
1632 (t
1633 (compilation-handle-exit 'bizarre status status)))))
1634 (set-buffer-modified-p nil)
1635 (message "Executing `%s'...done" command)))
1636 ;; Now finally cd to where the shell started make/grep/...
1637 (setq default-directory thisdir)
1638 ;; The following form selected outwin ever since revision 1.183,
1639 ;; so possibly messing up point in some other window (bug#1073).
1640 ;; Moved into the scope of with-current-buffer, though still with
1641 ;; complete disregard for the case when compilation-scroll-output
1642 ;; equals 'first-error (martin 2008-10-04).
1643 (when compilation-scroll-output
1644 (goto-char (point-max))))
1645
1646 ;; Make it so the next C-x ` will use this buffer.
1647 (setq next-error-last-buffer outbuf)))
1648
1649 (defun compilation-set-window-height (window)
1650 "Set the height of WINDOW according to `compilation-window-height'."
1651 (let ((height (buffer-local-value 'compilation-window-height (window-buffer window))))
1652 (and height
1653 (window-full-width-p window)
1654 ;; If window is alone in its frame, aside from a minibuffer,
1655 ;; don't change its height.
1656 (not (eq window (frame-root-window (window-frame window))))
1657 ;; Stef said that doing the saves in this order is safer:
1658 (save-excursion
1659 (save-selected-window
1660 (select-window window)
1661 (enlarge-window (- height (window-height))))))))
1662
1663 (defvar compilation-menu-map
1664 (let ((map (make-sparse-keymap "Errors"))
1665 (opt-map (make-sparse-keymap "Skip")))
1666 (define-key map [stop-subjob]
1667 '(menu-item "Stop Compilation" kill-compilation
1668 :help "Kill the process made by the M-x compile or M-x grep commands"))
1669 (define-key map [compilation-mode-separator3]
1670 '("----" . nil))
1671 (define-key map [compilation-next-error-follow-minor-mode]
1672 '(menu-item
1673 "Auto Error Display" next-error-follow-minor-mode
1674 :help "Display the error under cursor when moving the cursor"
1675 :button (:toggle . next-error-follow-minor-mode)))
1676 (define-key map [compilation-skip]
1677 (cons "Skip Less Important Messages" opt-map))
1678 (define-key opt-map [compilation-skip-none]
1679 '(menu-item "Don't Skip Any Messages"
1680 (lambda ()
1681 (interactive)
1682 (customize-set-variable 'compilation-skip-threshold 0))
1683 :help "Do not skip any type of messages"
1684 :button (:radio . (eq compilation-skip-threshold 0))))
1685 (define-key opt-map [compilation-skip-info]
1686 '(menu-item "Skip Info"
1687 (lambda ()
1688 (interactive)
1689 (customize-set-variable 'compilation-skip-threshold 1))
1690 :help "Skip anything less than warning"
1691 :button (:radio . (eq compilation-skip-threshold 1))))
1692 (define-key opt-map [compilation-skip-warning-and-info]
1693 '(menu-item "Skip Warnings and Info"
1694 (lambda ()
1695 (interactive)
1696 (customize-set-variable 'compilation-skip-threshold 2))
1697 :help "Skip over Warnings and Info, stop for errors"
1698 :button (:radio . (eq compilation-skip-threshold 2))))
1699 (define-key map [compilation-mode-separator2]
1700 '("----" . nil))
1701 (define-key map [compilation-first-error]
1702 '(menu-item "First Error" first-error
1703 :help "Restart at the first error, visit corresponding source code"))
1704 (define-key map [compilation-previous-error]
1705 '(menu-item "Previous Error" previous-error
1706 :help "Visit previous `next-error' message and corresponding source code"))
1707 (define-key map [compilation-next-error]
1708 '(menu-item "Next Error" next-error
1709 :help "Visit next `next-error' message and corresponding source code"))
1710 map))
1711
1712 (defvar compilation-minor-mode-map
1713 (let ((map (make-sparse-keymap)))
1714 (define-key map [mouse-2] 'compile-goto-error)
1715 (define-key map [follow-link] 'mouse-face)
1716 (define-key map "\C-c\C-c" 'compile-goto-error)
1717 (define-key map "\C-m" 'compile-goto-error)
1718 (define-key map "\C-c\C-k" 'kill-compilation)
1719 (define-key map "\M-n" 'compilation-next-error)
1720 (define-key map "\M-p" 'compilation-previous-error)
1721 (define-key map "\M-{" 'compilation-previous-file)
1722 (define-key map "\M-}" 'compilation-next-file)
1723 (define-key map "g" 'recompile) ; revert
1724 (define-key map "q" 'quit-window)
1725 ;; Set up the menu-bar
1726 (define-key map [menu-bar compilation]
1727 (cons "Errors" compilation-menu-map))
1728 map)
1729 "Keymap for `compilation-minor-mode'.")
1730
1731 (defvar compilation-shell-minor-mode-map
1732 (let ((map (make-sparse-keymap)))
1733 (define-key map "\M-\C-m" 'compile-goto-error)
1734 (define-key map "\M-\C-n" 'compilation-next-error)
1735 (define-key map "\M-\C-p" 'compilation-previous-error)
1736 (define-key map "\M-{" 'compilation-previous-file)
1737 (define-key map "\M-}" 'compilation-next-file)
1738 ;; Set up the menu-bar
1739 (define-key map [menu-bar compilation]
1740 (cons "Errors" compilation-menu-map))
1741 map)
1742 "Keymap for `compilation-shell-minor-mode'.")
1743
1744 (defvar compilation-button-map
1745 (let ((map (make-sparse-keymap)))
1746 (define-key map [mouse-2] 'compile-goto-error)
1747 (define-key map [follow-link] 'mouse-face)
1748 (define-key map "\C-m" 'compile-goto-error)
1749 map)
1750 "Keymap for compilation-message buttons.")
1751 (fset 'compilation-button-map compilation-button-map)
1752
1753 (defvar compilation-mode-map
1754 (let ((map (make-sparse-keymap)))
1755 ;; Don't inherit from compilation-minor-mode-map,
1756 ;; because that introduces a menu bar item we don't want.
1757 ;; That confuses C-down-mouse-3.
1758 (define-key map [mouse-2] 'compile-goto-error)
1759 (define-key map [follow-link] 'mouse-face)
1760 (define-key map "\C-c\C-c" 'compile-goto-error)
1761 (define-key map "\C-m" 'compile-goto-error)
1762 (define-key map "\C-c\C-k" 'kill-compilation)
1763 (define-key map "\M-n" 'compilation-next-error)
1764 (define-key map "\M-p" 'compilation-previous-error)
1765 (define-key map "\M-{" 'compilation-previous-file)
1766 (define-key map "\M-}" 'compilation-next-file)
1767 (define-key map "\t" 'compilation-next-error)
1768 (define-key map [backtab] 'compilation-previous-error)
1769 (define-key map "g" 'recompile) ; revert
1770 (define-key map "q" 'quit-window)
1771
1772 (define-key map " " 'scroll-up)
1773 (define-key map "\^?" 'scroll-down)
1774 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
1775
1776 ;; Set up the menu-bar
1777 (let ((submap (make-sparse-keymap "Compile")))
1778 (define-key map [menu-bar compilation]
1779 (cons "Compile" submap))
1780 (set-keymap-parent submap compilation-menu-map))
1781 (define-key map [menu-bar compilation compilation-separator2]
1782 '("----" . nil))
1783 (define-key map [menu-bar compilation compilation-grep]
1784 '(menu-item "Search Files (grep)..." grep
1785 :help "Run grep, with user-specified args, and collect output in a buffer"))
1786 (define-key map [menu-bar compilation compilation-recompile]
1787 '(menu-item "Recompile" recompile
1788 :help "Re-compile the program including the current buffer"))
1789 (define-key map [menu-bar compilation compilation-compile]
1790 '(menu-item "Compile..." compile
1791 :help "Compile the program including the current buffer. Default: run `make'"))
1792 map)
1793 "Keymap for compilation log buffers.
1794 `compilation-minor-mode-map' is a parent of this.")
1795
1796 (defvar compilation-mode-tool-bar-map
1797 ;; When bootstrapping, tool-bar-map is not properly initialized yet,
1798 ;; so don't do anything.
1799 (when (keymapp tool-bar-map)
1800 (let ((map (copy-keymap tool-bar-map)))
1801 (define-key map [undo] nil)
1802 (define-key map [separator-2] nil)
1803 (define-key-after map [separator-compile] menu-bar-separator)
1804 (tool-bar-local-item
1805 "left-arrow" 'previous-error-no-select 'previous-error-no-select map
1806 :rtl "right-arrow"
1807 :help "Goto previous error")
1808 (tool-bar-local-item
1809 "right-arrow" 'next-error-no-select 'next-error-no-select map
1810 :rtl "left-arrow"
1811 :help "Goto next error")
1812 (tool-bar-local-item
1813 "cancel" 'kill-compilation 'kill-compilation map
1814 :enable '(let ((buffer (compilation-find-buffer)))
1815 (get-buffer-process buffer))
1816 :help "Stop compilation")
1817 (tool-bar-local-item
1818 "refresh" 'recompile 'recompile map
1819 :help "Restart compilation")
1820 map)))
1821
1822 (put 'compilation-mode 'mode-class 'special)
1823
1824 ;;;###autoload
1825 (defun compilation-mode (&optional name-of-mode)
1826 "Major mode for compilation log buffers.
1827 \\<compilation-mode-map>To visit the source for a line-numbered error,
1828 move point to the error message line and type \\[compile-goto-error].
1829 To kill the compilation, type \\[kill-compilation].
1830
1831 Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
1832
1833 \\{compilation-mode-map}"
1834 (interactive)
1835 (kill-all-local-variables)
1836 (use-local-map compilation-mode-map)
1837 ;; Let windows scroll along with the output.
1838 (set (make-local-variable 'window-point-insertion-type) t)
1839 (set (make-local-variable 'tool-bar-map) compilation-mode-tool-bar-map)
1840 (setq major-mode 'compilation-mode ; FIXME: Use define-derived-mode.
1841 mode-name (or name-of-mode "Compilation"))
1842 (set (make-local-variable 'page-delimiter)
1843 compilation-page-delimiter)
1844 ;; (set (make-local-variable 'compilation-buffer-modtime) nil)
1845 (compilation-setup)
1846 (setq buffer-read-only t)
1847 (run-mode-hooks 'compilation-mode-hook))
1848
1849 (defmacro define-compilation-mode (mode name doc &rest body)
1850 "This is like `define-derived-mode' without the PARENT argument.
1851 The parent is always `compilation-mode' and the customizable `compilation-...'
1852 variables are also set from the name of the mode you have chosen,
1853 by replacing the first word, e.g `compilation-scroll-output' from
1854 `grep-scroll-output' if that variable exists."
1855 (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode))))
1856 `(define-derived-mode ,mode compilation-mode ,name
1857 ,doc
1858 ,@(mapcar (lambda (v)
1859 (setq v (cons v
1860 (intern-soft (replace-regexp-in-string
1861 "^compilation" mode-name
1862 (symbol-name v)))))
1863 (and (cdr v)
1864 (or (boundp (cdr v))
1865 ;; FIXME: This is hackish, using undocumented info.
1866 (if (boundp 'byte-compile-bound-variables)
1867 (memq (cdr v) byte-compile-bound-variables)))
1868 `(set (make-local-variable ',(car v)) ,(cdr v))))
1869 '(compilation-buffer-name-function
1870 compilation-directory-matcher
1871 compilation-error
1872 compilation-error-regexp-alist
1873 compilation-error-regexp-alist-alist
1874 compilation-error-screen-columns
1875 compilation-finish-function
1876 compilation-finish-functions
1877 compilation-first-column
1878 compilation-mode-font-lock-keywords
1879 compilation-page-delimiter
1880 compilation-parse-errors-filename-function
1881 compilation-process-setup-function
1882 compilation-scroll-output
1883 compilation-search-path
1884 compilation-skip-threshold
1885 compilation-window-height))
1886 ,@body)))
1887
1888 (defun compilation-revert-buffer (ignore-auto noconfirm)
1889 (if buffer-file-name
1890 (let (revert-buffer-function)
1891 (revert-buffer ignore-auto noconfirm))
1892 (if (or noconfirm (yes-or-no-p (format "Restart compilation? ")))
1893 (apply 'compilation-start compilation-arguments))))
1894
1895 (defvar compilation-current-error nil
1896 "Marker to the location from where the next error will be found.
1897 The global commands next/previous/first-error/goto-error use this.")
1898
1899 (defvar compilation-messages-start nil
1900 "Buffer position of the beginning of the compilation messages.
1901 If nil, use the beginning of buffer.")
1902
1903 (defun compilation-setup (&optional minor)
1904 "Prepare the buffer for the compilation parsing commands to work.
1905 Optional argument MINOR indicates this is called from
1906 `compilation-minor-mode'."
1907 (make-local-variable 'compilation-current-error)
1908 (make-local-variable 'compilation-messages-start)
1909 (make-local-variable 'compilation-error-screen-columns)
1910 (make-local-variable 'overlay-arrow-position)
1911 (set (make-local-variable 'overlay-arrow-string) "")
1912 (setq next-error-overlay-arrow-position nil)
1913 (add-hook 'kill-buffer-hook
1914 (lambda () (setq next-error-overlay-arrow-position nil)) nil t)
1915 ;; Note that compilation-next-error-function is for interfacing
1916 ;; with the next-error function in simple.el, and it's only
1917 ;; coincidentally named similarly to compilation-next-error.
1918 (setq next-error-function 'compilation-next-error-function)
1919 (set (make-local-variable 'comint-file-name-prefix)
1920 (or (file-remote-p default-directory) ""))
1921 (set (make-local-variable 'compilation-locs)
1922 (make-hash-table :test 'equal :weakness 'value))
1923 ;; It's generally preferable to use after-change-functions since they
1924 ;; can be subject to combine-after-change-calls, but if we do that, we risk
1925 ;; running our hook after font-lock, resulting in incorrect refontification.
1926 (add-hook 'before-change-functions 'compilation--flush-parse nil t)
1927 ;; Also for minor mode, since it's not permanent-local.
1928 (add-hook 'change-major-mode-hook #'compilation--remove-properties nil t)
1929 (if minor
1930 (progn
1931 (font-lock-add-keywords nil (compilation-mode-font-lock-keywords))
1932 (if font-lock-mode
1933 (font-lock-fontify-buffer)))
1934 (setq font-lock-defaults '(compilation-mode-font-lock-keywords t))))
1935
1936 (defun compilation--unsetup ()
1937 ;; Only for minor mode.
1938 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1939 (remove-hook 'before-change-functions 'compilation--flush-parse t)
1940 (kill-local-variable 'compilation--parsed)
1941 (compilation--remove-properties)
1942 (if font-lock-mode
1943 (font-lock-fontify-buffer)))
1944
1945 ;;;###autoload
1946 (define-minor-mode compilation-shell-minor-mode
1947 "Toggle compilation shell minor mode.
1948 With arg, turn compilation mode on if and only if arg is positive.
1949 In this minor mode, all the error-parsing commands of the
1950 Compilation major mode are available but bound to keys that don't
1951 collide with Shell mode. See `compilation-mode'.
1952 Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
1953 nil " Shell-Compile"
1954 :group 'compilation
1955 (if compilation-shell-minor-mode
1956 (compilation-setup t)
1957 (compilation--unsetup)))
1958
1959 ;;;###autoload
1960 (define-minor-mode compilation-minor-mode
1961 "Toggle compilation minor mode.
1962 With arg, turn compilation mode on if and only if arg is positive.
1963 In this minor mode, all the error-parsing commands of the
1964 Compilation major mode are available. See `compilation-mode'.
1965 Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
1966 nil " Compilation"
1967 :group 'compilation
1968 (if compilation-minor-mode
1969 (compilation-setup t)
1970 (compilation--unsetup)))
1971
1972 (defun compilation-handle-exit (process-status exit-status msg)
1973 "Write MSG in the current buffer and hack its `mode-line-process'."
1974 (let ((inhibit-read-only t)
1975 (status (if compilation-exit-message-function
1976 (funcall compilation-exit-message-function
1977 process-status exit-status msg)
1978 (cons msg exit-status)))
1979 (omax (point-max))
1980 (opoint (point))
1981 (cur-buffer (current-buffer)))
1982 ;; Record where we put the message, so we can ignore it later on.
1983 (goto-char omax)
1984 (insert ?\n mode-name " " (car status))
1985 (if (and (numberp compilation-window-height)
1986 (zerop compilation-window-height))
1987 (message "%s" (cdr status)))
1988 (if (bolp)
1989 (forward-char -1))
1990 (insert " at " (substring (current-time-string) 0 19))
1991 (goto-char (point-max))
1992 ;; Prevent that message from being recognized as a compilation error.
1993 (add-text-properties omax (point)
1994 (append '(compilation-handle-exit t) nil))
1995 (setq mode-line-process
1996 (let ((out-string (format ":%s [%s]" process-status (cdr status)))
1997 (msg (format "%s %s" mode-name
1998 (replace-regexp-in-string "\n?$" ""
1999 (car status)))))
2000 (message "%s" msg)
2001 (propertize out-string
2002 'help-echo msg 'face (if (> exit-status 0)
2003 'compilation-error
2004 'compilation-info))))
2005 ;; Force mode line redisplay soon.
2006 (force-mode-line-update)
2007 (if (and opoint (< opoint omax))
2008 (goto-char opoint))
2009 (with-no-warnings
2010 (if compilation-finish-function
2011 (funcall compilation-finish-function cur-buffer msg)))
2012 (run-hook-with-args 'compilation-finish-functions cur-buffer msg)))
2013
2014 ;; Called when compilation process changes state.
2015 (defun compilation-sentinel (proc msg)
2016 "Sentinel for compilation buffers."
2017 (if (memq (process-status proc) '(exit signal))
2018 (let ((buffer (process-buffer proc)))
2019 (if (null (buffer-name buffer))
2020 ;; buffer killed
2021 (set-process-buffer proc nil)
2022 (with-current-buffer buffer
2023 ;; Write something in the compilation buffer
2024 ;; and hack its mode line.
2025 (compilation-handle-exit (process-status proc)
2026 (process-exit-status proc)
2027 msg)
2028 ;; Since the buffer and mode line will show that the
2029 ;; process is dead, we can delete it now. Otherwise it
2030 ;; will stay around until M-x list-processes.
2031 (delete-process proc)))
2032 (setq compilation-in-progress (delq proc compilation-in-progress)))))
2033
2034 (defun compilation-filter (proc string)
2035 "Process filter for compilation buffers.
2036 Just inserts the text,
2037 handles carriage motion (see `comint-inhibit-carriage-motion'),
2038 and runs `compilation-filter-hook'."
2039 (when (buffer-live-p (process-buffer proc))
2040 (with-current-buffer (process-buffer proc)
2041 (let ((inhibit-read-only t)
2042 ;; `save-excursion' doesn't use the right insertion-type for us.
2043 (pos (copy-marker (point) t))
2044 ;; `save-restriction' doesn't use the right insertion type either:
2045 ;; If we are inserting at the end of the accessible part of the
2046 ;; buffer, keep the inserted text visible.
2047 (min (point-min-marker))
2048 (max (copy-marker (point-max) t)))
2049 (unwind-protect
2050 (progn
2051 (widen)
2052 (goto-char (process-mark proc))
2053 ;; We used to use `insert-before-markers', so that windows with
2054 ;; point at `process-mark' scroll along with the output, but we
2055 ;; now use window-point-insertion-type instead.
2056 (insert string)
2057 (unless comint-inhibit-carriage-motion
2058 (comint-carriage-motion (process-mark proc) (point)))
2059 (set-marker (process-mark proc) (point))
2060 ;; (set (make-local-variable 'compilation-buffer-modtime)
2061 ;; (current-time))
2062 (run-hooks 'compilation-filter-hook))
2063 (goto-char pos)
2064 (narrow-to-region min max)
2065 (set-marker pos nil)
2066 (set-marker min nil)
2067 (set-marker max nil))))))
2068
2069 ;;; test if a buffer is a compilation buffer, assuming we're in the buffer
2070 (defsubst compilation-buffer-internal-p ()
2071 "Test if inside a compilation buffer."
2072 (local-variable-p 'compilation-locs))
2073
2074 ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p
2075 (defsubst compilation-buffer-p (buffer)
2076 "Test if BUFFER is a compilation buffer."
2077 (with-current-buffer buffer
2078 (compilation-buffer-internal-p)))
2079
2080 (defmacro compilation-loop (< property-change 1+ error limit)
2081 `(let (opt)
2082 (while (,< n 0)
2083 (setq opt pt)
2084 (or (setq pt (,property-change pt 'compilation-message))
2085 ;; Handle the case where where the first error message is
2086 ;; at the start of the buffer, and n < 0.
2087 (if (or (eq (get-text-property ,limit 'compilation-message)
2088 (get-text-property opt 'compilation-message))
2089 (eq pt opt))
2090 (error ,error compilation-error)
2091 (setq pt ,limit)))
2092 ;; prop 'compilation-message usually has 2 changes, on and off, so
2093 ;; re-search if off
2094 (or (setq msg (get-text-property pt 'compilation-message))
2095 (if (setq pt (,property-change pt 'compilation-message nil ,limit))
2096 (setq msg (get-text-property pt 'compilation-message)))
2097 (error ,error compilation-error))
2098 (or (< (compilation--message->type msg) compilation-skip-threshold)
2099 (if different-file
2100 (eq (prog1 last
2101 (setq last (compilation--loc->file-struct
2102 (compilation--message->loc msg))))
2103 last))
2104 (if compilation-skip-visited
2105 (compilation--loc->visited (compilation--message->loc msg)))
2106 (if compilation-skip-to-next-location
2107 (eq (compilation--message->loc msg) loc))
2108 ;; count this message only if none of the above are true
2109 (setq n (,1+ n))))))
2110
2111 (defun compilation-next-single-property-change (position prop
2112 &optional object limit)
2113 (let (parsed res)
2114 (while (progn
2115 ;; We parse the buffer here "on-demand" by chunks of 500 chars.
2116 ;; But we could also just parse the whole buffer.
2117 (compilation--ensure-parse
2118 (setq parsed (max compilation--parsed
2119 (min (+ position 500)
2120 (or limit (point-max))))))
2121 (and (or (not (setq res (next-single-property-change
2122 position prop object limit)))
2123 (eq res limit))
2124 (< position (or limit (point-max)))))
2125 (setq position parsed))
2126 res))
2127
2128 (defun compilation-next-error (n &optional different-file pt)
2129 "Move point to the next error in the compilation buffer.
2130 This function does NOT find the source line like \\[next-error].
2131 Prefix arg N says how many error messages to move forwards (or
2132 backwards, if negative).
2133 Optional arg DIFFERENT-FILE, if non-nil, means find next error for a
2134 file that is different from the current one.
2135 Optional arg PT, if non-nil, specifies the value of point to start
2136 looking for the next message."
2137 (interactive "p")
2138 (or (compilation-buffer-p (current-buffer))
2139 (error "Not in a compilation buffer"))
2140 (or pt (setq pt (point)))
2141 (let* ((msg (get-text-property pt 'compilation-message))
2142 ;; `loc', `msg', and `last' are used by the compilation-loop macro.
2143 (loc (and msg (compilation--message->loc msg)))
2144 last)
2145 (if (zerop n)
2146 (unless (or msg ; find message near here
2147 (setq msg (get-text-property (max (1- pt) (point-min))
2148 'compilation-message)))
2149 (setq pt (previous-single-property-change pt 'compilation-message nil
2150 (line-beginning-position)))
2151 (unless (setq msg (get-text-property (max (1- pt) (point-min))
2152 'compilation-message))
2153 (setq pt (next-single-property-change pt 'compilation-message nil
2154 (line-end-position)))
2155 (or (setq msg (get-text-property pt 'compilation-message))
2156 (setq pt (point)))))
2157 (setq last (compilation--loc->file-struct loc))
2158 (if (>= n 0)
2159 (compilation-loop > compilation-next-single-property-change 1-
2160 (if (get-buffer-process (current-buffer))
2161 "No more %ss yet"
2162 "Moved past last %s")
2163 (point-max))
2164 (compilation--ensure-parse pt)
2165 ;; Don't move "back" to message at or before point.
2166 ;; Pass an explicit (point-min) to make sure pt is non-nil.
2167 (setq pt (previous-single-property-change
2168 pt 'compilation-message nil (point-min)))
2169 (compilation-loop < previous-single-property-change 1+
2170 "Moved back before first %s" (point-min))))
2171 (goto-char pt)
2172 (or msg
2173 (error "No %s here" compilation-error))))
2174
2175 (defun compilation-previous-error (n)
2176 "Move point to the previous error in the compilation buffer.
2177 Prefix arg N says how many error messages to move backwards (or
2178 forwards, if negative).
2179 Does NOT find the source line like \\[previous-error]."
2180 (interactive "p")
2181 (compilation-next-error (- n)))
2182
2183 (defun compilation-next-file (n)
2184 "Move point to the next error for a different file than the current one.
2185 Prefix arg N says how many files to move forwards (or backwards, if negative)."
2186 (interactive "p")
2187 (compilation-next-error n t))
2188
2189 (defun compilation-previous-file (n)
2190 "Move point to the previous error for a different file than the current one.
2191 Prefix arg N says how many files to move backwards (or forwards, if negative)."
2192 (interactive "p")
2193 (compilation-next-file (- n)))
2194
2195 (defun kill-compilation ()
2196 "Kill the process made by the \\[compile] or \\[grep] commands."
2197 (interactive)
2198 (let ((buffer (compilation-find-buffer)))
2199 (if (get-buffer-process buffer)
2200 (interrupt-process (get-buffer-process buffer))
2201 (error "The %s process is not running" (downcase mode-name)))))
2202
2203 (defalias 'compile-mouse-goto-error 'compile-goto-error)
2204
2205 (defun compile-goto-error (&optional event)
2206 "Visit the source for the error message at point.
2207 Use this command in a compilation log buffer. Sets the mark at point there."
2208 (interactive (list last-input-event))
2209 (if event (posn-set-point (event-end event)))
2210 (or (compilation-buffer-p (current-buffer))
2211 (error "Not in a compilation buffer"))
2212 (compilation--ensure-parse (point))
2213 (if (get-text-property (point) 'compilation-directory)
2214 (dired-other-window
2215 (car (get-text-property (point) 'compilation-directory)))
2216 (push-mark)
2217 (setq compilation-current-error (point))
2218 (next-error-internal)))
2219
2220 ;; This is mostly unused, but we keep it for the sake of some external
2221 ;; packages which seem to make use of it.
2222 (defun compilation-find-buffer (&optional avoid-current)
2223 "Return a compilation buffer.
2224 If AVOID-CURRENT is nil, and the current buffer is a compilation buffer,
2225 return it. If AVOID-CURRENT is non-nil, return the current buffer only
2226 as a last resort."
2227 (if (and (compilation-buffer-internal-p) (not avoid-current))
2228 (current-buffer)
2229 (next-error-find-buffer avoid-current 'compilation-buffer-internal-p)))
2230
2231 ;;;###autoload
2232 (defun compilation-next-error-function (n &optional reset)
2233 "Advance to the next error message and visit the file where the error was.
2234 This is the value of `next-error-function' in Compilation buffers."
2235 (interactive "p")
2236 (when reset
2237 (setq compilation-current-error nil))
2238 (let* ((columns compilation-error-screen-columns) ; buffer's local value
2239 (last 1) timestamp
2240 (msg (compilation-next-error (or n 1) nil
2241 (or compilation-current-error
2242 compilation-messages-start
2243 (point-min))))
2244 (loc (compilation--message->loc msg))
2245 (end-loc (compilation--message->end-loc msg))
2246 (marker (point-marker)))
2247 (setq compilation-current-error (point-marker)
2248 overlay-arrow-position
2249 (if (bolp)
2250 compilation-current-error
2251 (copy-marker (line-beginning-position))))
2252 ;; If loc contains no marker, no error in that file has been visited.
2253 ;; If the marker is invalid the buffer has been killed.
2254 ;; So, recalculate all markers for that file.
2255 (unless (and (compilation--loc->marker loc)
2256 (marker-buffer (compilation--loc->marker loc))
2257 ;; FIXME-omake: For "omake -P", which automatically recompiles
2258 ;; when the file is modified, the line numbers of new output
2259 ;; may not be related to line numbers from earlier output
2260 ;; (earlier markers), so we used to try to detect it here and
2261 ;; force a reparse. But that caused more problems elsewhere,
2262 ;; so instead we now flush the file-structure when we see
2263 ;; omake's message telling it's about to recompile a file.
2264 ;; (or (null (compilation--loc->timestamp loc)) ;A fake-loc
2265 ;; (equal (compilation--loc->timestamp loc)
2266 ;; (setq timestamp compilation-buffer-modtime)))
2267 )
2268 (with-current-buffer
2269 (compilation-find-file
2270 marker
2271 (caar (compilation--loc->file-struct loc))
2272 (cadr (car (compilation--loc->file-struct loc))))
2273 (save-restriction
2274 (widen)
2275 (goto-char (point-min))
2276 ;; Treat file's found lines in forward order, 1 by 1.
2277 (dolist (line (reverse (cddr (compilation--loc->file-struct loc))))
2278 (when (car line) ; else this is a filename w/o a line#
2279 (beginning-of-line (- (car line) last -1))
2280 (setq last (car line)))
2281 ;; Treat line's found columns and store/update a marker for each.
2282 (dolist (col (cdr line))
2283 (if (compilation--loc->col col)
2284 (if (eq (compilation--loc->col col) -1)
2285 ;; Special case for range end.
2286 (end-of-line)
2287 (compilation-move-to-column (compilation--loc->col col)
2288 columns))
2289 (beginning-of-line)
2290 (skip-chars-forward " \t"))
2291 (if (compilation--loc->marker col)
2292 (set-marker (compilation--loc->marker col) (point))
2293 (setf (compilation--loc->marker col) (point-marker)))
2294 ;; (setf (compilation--loc->timestamp col) timestamp)
2295 )))))
2296 (compilation-goto-locus marker (compilation--loc->marker loc)
2297 (compilation--loc->marker end-loc))
2298 (setf (compilation--loc->visited loc) t)))
2299
2300 (defvar compilation-gcpro nil
2301 "Internal variable used to keep some values from being GC'd.")
2302 (make-variable-buffer-local 'compilation-gcpro)
2303
2304 (defun compilation-fake-loc (marker file &optional line col)
2305 "Preassociate MARKER with FILE.
2306 FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
2307 This is useful when you compile temporary files, but want
2308 automatic translation of the messages to the real buffer from
2309 which the temporary file came. This may also affect previous messages
2310 about FILE.
2311
2312 Optional args LINE and COL default to 1 and beginning of
2313 indentation respectively. The marker is expected to reflect
2314 this. In the simplest case the marker points to the first line
2315 of the region that was saved to the temp file.
2316
2317 If you concatenate several regions into the temp file (e.g. a
2318 header with variable assignments and a code region), you must
2319 call this several times, once each for the last line of one
2320 region and the first line of the next region."
2321 (or (consp file) (setq file (list file)))
2322 (compilation--flush-file-structure file)
2323 (let ((fs (compilation-get-file-structure file)))
2324 ;; Between the current call to compilation-fake-loc and the first
2325 ;; occurrence of an error message referring to `file', the data is
2326 ;; only kept in the weak hash-table compilation-locs, so we need
2327 ;; to prevent this entry in compilation-locs from being GC'd
2328 ;; away. --Stef
2329 (push fs compilation-gcpro)
2330 (let ((loc (compilation-assq (or line 1) (cdr fs))))
2331 (setq loc (compilation-assq col loc))
2332 (assert (null (cdr loc)))
2333 (setcdr loc (compilation--make-cdrloc line fs marker))
2334 loc)))
2335
2336 (defcustom compilation-context-lines nil
2337 "Display this many lines of leading context before the current message.
2338 If nil and the left fringe is displayed, don't scroll the
2339 compilation output window; an arrow in the left fringe points to
2340 the current message. If nil and there is no left fringe, the message
2341 displays at the top of the window; there is no arrow."
2342 :type '(choice integer (const :tag "No window scrolling" nil))
2343 :group 'compilation
2344 :version "22.1")
2345
2346 (defsubst compilation-set-window (w mk)
2347 "Align the compilation output window W with marker MK near top."
2348 (if (integerp compilation-context-lines)
2349 (set-window-start w (save-excursion
2350 (goto-char mk)
2351 (beginning-of-line
2352 (- 1 compilation-context-lines))
2353 (point)))
2354 ;; If there is no left fringe.
2355 (if (equal (car (window-fringes)) 0)
2356 (set-window-start w (save-excursion
2357 (goto-char mk)
2358 (beginning-of-line 1)
2359 (point)))))
2360 (set-window-point w mk))
2361
2362 (defvar next-error-highlight-timer)
2363
2364 (defun compilation-goto-locus (msg mk end-mk)
2365 "Jump to an error corresponding to MSG at MK.
2366 All arguments are markers. If END-MK is non-nil, mark is set there
2367 and overlay is highlighted between MK and END-MK."
2368 ;; Show compilation buffer in other window, scrolled to this error.
2369 (let* ((from-compilation-buffer (eq (window-buffer (selected-window))
2370 (marker-buffer msg)))
2371 ;; Use an existing window if it is in a visible frame.
2372 (pre-existing (get-buffer-window (marker-buffer msg) 0))
2373 (w (if (and from-compilation-buffer pre-existing)
2374 ;; Calling display-buffer here may end up (partly) hiding
2375 ;; the error location if the two buffers are in two
2376 ;; different frames. So don't do it if it's not necessary.
2377 pre-existing
2378 (let ((display-buffer-reuse-frames t)
2379 (pop-up-windows t))
2380 ;; Pop up a window.
2381 (display-buffer (marker-buffer msg)))))
2382 (highlight-regexp (with-current-buffer (marker-buffer msg)
2383 ;; also do this while we change buffer
2384 (compilation-set-window w msg)
2385 compilation-highlight-regexp)))
2386 ;; Ideally, the window-size should be passed to `display-buffer' (via
2387 ;; something like special-display-buffer) so it's only used when
2388 ;; creating a new window.
2389 (unless pre-existing (compilation-set-window-height w))
2390
2391 (if from-compilation-buffer
2392 ;; If the compilation buffer window was selected,
2393 ;; keep the compilation buffer in this window;
2394 ;; display the source in another window.
2395 (let ((pop-up-windows t))
2396 (pop-to-buffer (marker-buffer mk) 'other-window))
2397 (if (window-dedicated-p (selected-window))
2398 (pop-to-buffer (marker-buffer mk))
2399 (switch-to-buffer (marker-buffer mk))))
2400 (unless (eq (goto-char mk) (point))
2401 ;; If narrowing gets in the way of going to the right place, widen.
2402 (widen)
2403 (if next-error-move-function
2404 (funcall next-error-move-function msg mk)
2405 (goto-char mk)))
2406 (if end-mk
2407 (push-mark end-mk t)
2408 (if mark-active (setq mark-active)))
2409 ;; If hideshow got in the way of
2410 ;; seeing the right place, open permanently.
2411 (dolist (ov (overlays-at (point)))
2412 (when (eq 'hs (overlay-get ov 'invisible))
2413 (delete-overlay ov)
2414 (goto-char mk)))
2415
2416 (when highlight-regexp
2417 (if (timerp next-error-highlight-timer)
2418 (cancel-timer next-error-highlight-timer))
2419 (unless compilation-highlight-overlay
2420 (setq compilation-highlight-overlay
2421 (make-overlay (point-min) (point-min)))
2422 (overlay-put compilation-highlight-overlay 'face 'next-error))
2423 (with-current-buffer (marker-buffer mk)
2424 (save-excursion
2425 (if end-mk (goto-char end-mk) (end-of-line))
2426 (let ((end (point)))
2427 (if mk (goto-char mk) (beginning-of-line))
2428 (if (and (stringp highlight-regexp)
2429 (re-search-forward highlight-regexp end t))
2430 (progn
2431 (goto-char (match-beginning 0))
2432 (move-overlay compilation-highlight-overlay
2433 (match-beginning 0) (match-end 0)
2434 (current-buffer)))
2435 (move-overlay compilation-highlight-overlay
2436 (point) end (current-buffer)))
2437 (if (or (eq next-error-highlight t)
2438 (numberp next-error-highlight))
2439 ;; We want highlighting: delete overlay on next input.
2440 (add-hook 'pre-command-hook
2441 'compilation-goto-locus-delete-o)
2442 ;; We don't want highlighting: delete overlay now.
2443 (delete-overlay compilation-highlight-overlay))
2444 ;; We want highlighting for a limited time:
2445 ;; set up a timer to delete it.
2446 (when (numberp next-error-highlight)
2447 (setq next-error-highlight-timer
2448 (run-at-time next-error-highlight nil
2449 'compilation-goto-locus-delete-o)))))))
2450 (when (and (eq next-error-highlight 'fringe-arrow))
2451 ;; We want a fringe arrow (instead of highlighting).
2452 (setq next-error-overlay-arrow-position
2453 (copy-marker (line-beginning-position))))))
2454
2455 (defun compilation-goto-locus-delete-o ()
2456 (delete-overlay compilation-highlight-overlay)
2457 ;; Get rid of timer and hook that would try to do this again.
2458 (if (timerp next-error-highlight-timer)
2459 (cancel-timer next-error-highlight-timer))
2460 (remove-hook 'pre-command-hook
2461 'compilation-goto-locus-delete-o))
2462 \f
2463 (defun compilation-find-file (marker filename directory &rest formats)
2464 "Find a buffer for file FILENAME.
2465 If FILENAME is not found at all, ask the user where to find it.
2466 Pop up the buffer containing MARKER and scroll to MARKER if we ask
2467 the user where to find the file.
2468 Search the directories in `compilation-search-path'.
2469 A nil in `compilation-search-path' means to try the
2470 \"current\" directory, which is passed in DIRECTORY.
2471 If DIRECTORY is relative, it is combined with `default-directory'.
2472 If DIRECTORY is nil, that means use `default-directory'.
2473 FORMATS, if given, is a list of formats to reformat FILENAME when
2474 looking for it: for each element FMT in FORMATS, this function
2475 attempts to find a file whose name is produced by (format FMT FILENAME)."
2476 (or formats (setq formats '("%s")))
2477 (let ((dirs compilation-search-path)
2478 (spec-dir (if directory
2479 (expand-file-name directory)
2480 default-directory))
2481 buffer thisdir fmts name)
2482 (if (file-name-absolute-p filename)
2483 ;; The file name is absolute. Use its explicit directory as
2484 ;; the first in the search path, and strip it from FILENAME.
2485 (setq filename (abbreviate-file-name (expand-file-name filename))
2486 dirs (cons (file-name-directory filename) dirs)
2487 filename (file-name-nondirectory filename)))
2488 ;; Now search the path.
2489 (while (and dirs (null buffer))
2490 (setq thisdir (or (car dirs) spec-dir)
2491 fmts formats)
2492 ;; For each directory, try each format string.
2493 (while (and fmts (null buffer))
2494 (setq name (expand-file-name (format (car fmts) filename) thisdir)
2495 buffer (and (file-exists-p name)
2496 (find-file-noselect name))
2497 fmts (cdr fmts)))
2498 (setq dirs (cdr dirs)))
2499 (while (null buffer) ;Repeat until the user selects an existing file.
2500 ;; The file doesn't exist. Ask the user where to find it.
2501 (save-excursion ;This save-excursion is probably not right.
2502 (let ((pop-up-windows t))
2503 (compilation-set-window (display-buffer (marker-buffer marker))
2504 marker)
2505 (let* ((name (read-file-name
2506 (format "Find this %s in (default %s): "
2507 compilation-error filename)
2508 spec-dir filename t nil
2509 ;; The predicate below is fine when called from
2510 ;; minibuffer-complete-and-exit, but it's too
2511 ;; restrictive otherwise, since it also prevents the
2512 ;; user from completing "fo" to "foo/" when she
2513 ;; wants to enter "foo/bar".
2514 ;;
2515 ;; Try to make sure the user can only select
2516 ;; a valid answer. This predicate may be ignored,
2517 ;; tho, so we still have to double-check afterwards.
2518 ;; TODO: We should probably fix read-file-name so
2519 ;; that it never ignores this predicate, even when
2520 ;; using popup dialog boxes.
2521 ;; (lambda (name)
2522 ;; (if (file-directory-p name)
2523 ;; (setq name (expand-file-name filename name)))
2524 ;; (file-exists-p name))
2525 ))
2526 (origname name))
2527 (cond
2528 ((not (file-exists-p name))
2529 (message "Cannot find file `%s'" name)
2530 (ding) (sit-for 2))
2531 ((and (file-directory-p name)
2532 (not (file-exists-p
2533 (setq name (expand-file-name filename name)))))
2534 (message "No `%s' in directory %s" filename origname)
2535 (ding) (sit-for 2))
2536 (t
2537 (setq buffer (find-file-noselect name))))))))
2538 ;; Make intangible overlays tangible.
2539 ;; This is weird: it's not even clear which is the current buffer,
2540 ;; so the code below can't be expected to DTRT here. -- Stef
2541 (dolist (ov (overlays-in (point-min) (point-max)))
2542 (when (overlay-get ov 'intangible)
2543 (overlay-put ov 'intangible nil)))
2544 buffer))
2545
2546 (defun compilation-get-file-structure (file &optional fmt)
2547 "Retrieve FILE's file-structure or create a new one.
2548 FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
2549 In the former case, FILENAME may be relative or absolute.
2550
2551 The file-structure looks like this:
2552 ((FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)"
2553 (or (gethash file compilation-locs)
2554 ;; File was not previously encountered, at least not in the form passed.
2555 ;; Let's normalize it and look again.
2556 (let ((filename (car file))
2557 ;; Get the specified directory from FILE.
2558 (spec-directory (if (cdr file)
2559 (file-truename (cdr file)))))
2560
2561 ;; Check for a comint-file-name-prefix and prepend it if appropriate.
2562 ;; (This is very useful for compilation-minor-mode in an rlogin-mode
2563 ;; buffer.)
2564 (when (and (boundp 'comint-file-name-prefix)
2565 (not (equal comint-file-name-prefix "")))
2566 (if (file-name-absolute-p filename)
2567 (setq filename
2568 (concat comint-file-name-prefix filename))
2569 (if spec-directory
2570 (setq spec-directory
2571 (file-truename
2572 (concat comint-file-name-prefix spec-directory))))))
2573
2574 ;; If compilation-parse-errors-filename-function is
2575 ;; defined, use it to process the filename.
2576 (when compilation-parse-errors-filename-function
2577 (setq filename
2578 (funcall compilation-parse-errors-filename-function
2579 filename)))
2580
2581 ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus
2582 ;; file names like "./bar//foo.c" for file "bar/foo.c";
2583 ;; expand-file-name will collapse these into "/foo.c" and fail to find
2584 ;; the appropriate file. So we look for doubled slashes in the file
2585 ;; name and fix them.
2586 (setq filename (command-line-normalize-file-name filename))
2587
2588 ;; Store it for the possibly unnormalized name
2589 (puthash file
2590 ;; Retrieve or create file-structure for normalized name
2591 ;; The gethash used to not use spec-directory, but
2592 ;; this leads to errors when files in different
2593 ;; directories have the same name:
2594 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00463.html
2595 (or (gethash (cons filename spec-directory) compilation-locs)
2596 (puthash (cons filename spec-directory)
2597 (compilation--make-file-struct
2598 (list filename spec-directory) fmt)
2599 compilation-locs))
2600 compilation-locs))))
2601
2602 (defun compilation--flush-file-structure (file)
2603 (or (consp file) (setq file (list file)))
2604 (let ((fs (compilation-get-file-structure file)))
2605 (assert (eq fs (gethash file compilation-locs)))
2606 (assert (eq fs (gethash (cons (caar fs) (cadr (car fs)))
2607 compilation-locs)))
2608 (maphash (lambda (k v)
2609 (if (eq v fs) (remhash k compilation-locs)))
2610 compilation-locs)))
2611
2612 (add-to-list 'debug-ignored-errors "\\`No more [-a-z ]+s yet\\'")
2613 (add-to-list 'debug-ignored-errors "\\`Moved past last .*")
2614
2615 ;;; Compatibility with the old compile.el.
2616
2617 (defvaralias 'compilation-last-buffer 'next-error-last-buffer)
2618 (defvar compilation-parsing-end (make-marker))
2619 (defvar compilation-error-list nil)
2620 (defvar compilation-old-error-list nil)
2621
2622 (defun compilation--compat-error-properties (err)
2623 "Map old-style error ERR to new-style message."
2624 ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
2625 ;; (MARKER . MARKER).
2626 (let ((dst (cdr err)))
2627 (if (markerp dst)
2628 `(compilation-message ,(compilation--make-message
2629 (cons nil (compilation--make-cdrloc
2630 nil nil dst))
2631 2 nil)
2632 help-echo "mouse-2: visit the source location"
2633 keymap compilation-button-map
2634 mouse-face highlight)
2635 ;; Too difficult to do it by hand: dispatch to the normal code.
2636 (let* ((file (pop dst))
2637 (line (pop dst))
2638 (col (pop dst))
2639 (filename (pop file))
2640 (dirname (pop file))
2641 (fmt (pop file)))
2642 (compilation-internal-error-properties
2643 (cons filename dirname) line nil col nil 2 fmt)))))
2644
2645 (defun compilation--compat-parse-errors (limit)
2646 (when compilation-parse-errors-function
2647 ;; FIXME: We should remove the rest of the compilation keywords
2648 ;; but we can't do that from here because font-lock is using
2649 ;; the value right now. --Stef
2650 (save-excursion
2651 (setq compilation-error-list nil)
2652 ;; Reset compilation-parsing-end each time because font-lock
2653 ;; might force us the re-parse many times (typically because
2654 ;; some code adds some text-property to the output that we
2655 ;; already parsed). You might say "why reparse", well:
2656 ;; because font-lock has just removed the `compilation-message' property
2657 ;; so have to do it all over again.
2658 (if compilation-parsing-end
2659 (set-marker compilation-parsing-end (point))
2660 (setq compilation-parsing-end (point-marker)))
2661 (condition-case nil
2662 ;; Ignore any error: we're calling this function earlier than
2663 ;; in the old compile.el so things might not all be setup yet.
2664 (funcall compilation-parse-errors-function limit nil)
2665 (error nil))
2666 (dolist (err (if (listp compilation-error-list) compilation-error-list))
2667 (let* ((src (car err))
2668 (dst (cdr err))
2669 (loc (cond ((markerp dst)
2670 (cons nil
2671 (compilation--make-cdrloc nil nil dst)))
2672 ((consp dst)
2673 (cons (nth 2 dst)
2674 (compilation--make-cdrloc
2675 (nth 1 dst)
2676 (cons (cdar dst) (caar dst))
2677 nil))))))
2678 (when loc
2679 (goto-char src)
2680 ;; (put-text-property src (line-end-position)
2681 ;; 'font-lock-face 'font-lock-warning-face)
2682 (put-text-property src (line-end-position)
2683 'compilation-message
2684 (compilation--make-message loc 2 nil)))))))
2685 (goto-char limit)
2686 nil)
2687
2688 ;; Beware! this is not only compatibility code. New code also uses it. --Stef
2689 (defun compilation-forget-errors ()
2690 ;; In case we hit the same file/line specs, we want to recompute a new
2691 ;; marker for them, so flush our cache.
2692 (clrhash compilation-locs)
2693 (setq compilation-gcpro nil)
2694 ;; FIXME: the old code reset the directory-stack, so maybe we should
2695 ;; put a `directory change' marker of some sort, but where? -stef
2696 ;;
2697 ;; FIXME: The old code moved compilation-current-error (which was
2698 ;; virtually represented by a mix of compilation-parsing-end and
2699 ;; compilation-error-list) to point-min, but that was only meaningful for
2700 ;; the internal uses of compilation-forget-errors: all calls from external
2701 ;; packages seem to be followed by a move of compilation-parsing-end to
2702 ;; something equivalent to point-max. So we heuristically move
2703 ;; compilation-current-error to point-max (since the external package
2704 ;; won't know that it should do it). --Stef
2705 (setq compilation-current-error nil)
2706 (let* ((proc (get-buffer-process (current-buffer)))
2707 (mark (if proc (process-mark proc)))
2708 (pos (or mark (point-max))))
2709 (setq compilation-messages-start
2710 ;; In the future, ignore the text already present in the buffer.
2711 ;; Since many process filter functions insert before markers,
2712 ;; we need to put ours just before the insertion point rather
2713 ;; than at the insertion point. If that's not possible, then
2714 ;; don't use a marker. --Stef
2715 (if (> pos (point-min)) (copy-marker (1- pos)) pos)))
2716 ;; Again, since this command is used in buffers that contain several
2717 ;; compilations, to set the beginning of "this compilation", it's a good
2718 ;; place to reset compilation-auto-jump-to-next.
2719 (set (make-local-variable 'compilation-auto-jump-to-next)
2720 (or compilation-auto-jump-to-first-error
2721 (eq compilation-scroll-output 'first-error))))
2722
2723 (provide 'compile)
2724
2725 ;;; compile.el ends here