Commit | Line | Data |
---|---|---|
55535639 | 1 | ;;; compile.el --- run compiler as inferior of Emacs, parse error messages |
fad160d5 | 2 | |
930a3e46 | 3 | ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
049dcb6f GM |
4 | ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
5 | ;; Free Software Foundation, Inc. | |
3a801d0c | 6 | |
7837c247 SM |
7 | ;; Authors: Roland McGrath <roland@gnu.org>, |
8 | ;; Daniel Pfeiffer <occitan@esperanto.org> | |
d1c7011d | 9 | ;; Maintainer: FSF |
e9571d2a | 10 | ;; Keywords: tools, processes |
d1c7011d | 11 | |
55dfd2c4 RS |
12 | ;; This file is part of GNU Emacs. |
13 | ||
29add8b9 RM |
14 | ;; GNU Emacs is free software; you can redistribute it and/or modify |
15 | ;; it under the terms of the GNU General Public License as published by | |
1a484753 | 16 | ;; the Free Software Foundation; either version 3, or (at your option) |
29add8b9 RM |
17 | ;; any later version. |
18 | ||
55dfd2c4 | 19 | ;; GNU Emacs is distributed in the hope that it will be useful, |
29add8b9 RM |
20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | ;; GNU General Public License for more details. | |
23 | ||
24 | ;; You should have received a copy of the GNU General Public License | |
b578f267 | 25 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
3a35cf56 LK |
26 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
27 | ;; Boston, MA 02110-1301, USA. | |
55dfd2c4 | 28 | |
5cc57841 ER |
29 | ;;; Commentary: |
30 | ||
7837c247 SM |
31 | ;; This package provides the compile facilities documented in the Emacs user's |
32 | ;; manual. | |
5cc57841 | 33 | |
c536bb39 | 34 | ;; This mode uses some complex data-structures: |
7837c247 | 35 | |
c536bb39 | 36 | ;; LOC (or location) is a list of (COLUMN LINE FILE-STRUCTURE) |
7837c247 SM |
37 | |
38 | ;; COLUMN and LINE are numbers parsed from an error message. COLUMN and maybe | |
39 | ;; LINE will be nil for a message that doesn't contain them. Then the | |
40 | ;; location refers to a indented beginning of line or beginning of file. | |
41 | ;; Once any location in some file has been jumped to, the list is extended to | |
b84acff6 SS |
42 | ;; (COLUMN LINE FILE-STRUCTURE MARKER TIMESTAMP . VISITED) |
43 | ;; for all LOCs pertaining to that file. | |
7837c247 SM |
44 | ;; MARKER initially points to LINE and COLUMN in a buffer visiting that file. |
45 | ;; Being a marker it sticks to some text, when the buffer grows or shrinks | |
46 | ;; before that point. VISITED is t if we have jumped there, else nil. | |
b84acff6 SS |
47 | ;; TIMESTAMP is necessary because of "incremental compilation": `omake -P' |
48 | ;; polls filesystem for changes and recompiles when a file is modified | |
49 | ;; using the same *compilation* buffer. this necessitates re-parsing markers. | |
7837c247 | 50 | |
c536bb39 SM |
51 | ;; FILE-STRUCTURE is a list of |
52 | ;; ((FILENAME . DIRECTORY) FORMATS (LINE LOC ...) ...) | |
7837c247 SM |
53 | |
54 | ;; FILENAME is a string parsed from an error message. DIRECTORY is a string | |
55 | ;; obtained by following directory change messages. DIRECTORY will be nil for | |
56 | ;; an absolute filename. FORMATS is a list of formats to apply to FILENAME if | |
57 | ;; a file of that name can't be found. | |
58 | ;; The rest of the list is an alist of elements with LINE as key. The keys | |
59 | ;; are either nil or line numbers. If present, nil comes first, followed by | |
60 | ;; the numbers in decreasing order. The LOCs for each line are again an alist | |
61 | ;; ordered the same way. Note that the whole file structure is referenced in | |
62 | ;; every LOC. | |
63 | ||
c536bb39 | 64 | ;; MESSAGE is a list of (LOC TYPE END-LOC) |
7837c247 SM |
65 | |
66 | ;; TYPE is 0 for info or 1 for warning if the message matcher identified it as | |
67 | ;; such, 2 otherwise (for a real error). END-LOC is a LOC pointing to the | |
4fffd73b | 68 | ;; other end, if the parsed message contained a range. If the end of the |
7837c247 SM |
69 | ;; range didn't specify a COLUMN, it defaults to -1, meaning end of line. |
70 | ;; These are the value of the `message' text-properties in the compilation | |
71 | ;; buffer. | |
72 | ||
24299582 DP |
73 | ;;; Code: |
74 | ||
583a15bb SM |
75 | (eval-when-compile (require 'cl)) |
76 | ||
e623859c JB |
77 | (defvar font-lock-extra-managed-props) |
78 | (defvar font-lock-keywords) | |
79 | (defvar font-lock-maximum-size) | |
80 | (defvar font-lock-support-mode) | |
81 | ||
82 | ||
c5049fa0 RS |
83 | (defgroup compilation nil |
84 | "Run compiler as inferior of Emacs, parse error messages." | |
85 | :group 'tools | |
86 | :group 'processes) | |
87 | ||
88 | ||
7c163413 | 89 | ;;;###autoload |
c5049fa0 | 90 | (defcustom compilation-mode-hook nil |
813fb3fe | 91 | "List of hook functions run by `compilation-mode' (see `run-mode-hooks')." |
c5049fa0 RS |
92 | :type 'hook |
93 | :group 'compilation) | |
7c163413 RM |
94 | |
95 | ;;;###autoload | |
c5049fa0 | 96 | (defcustom compilation-window-height nil |
813fb3fe | 97 | "Number of lines in a compilation window. If nil, use Emacs default." |
c5049fa0 RS |
98 | :type '(choice (const :tag "Default" nil) |
99 | integer) | |
100 | :group 'compilation) | |
d3cb357b | 101 | |
7837c247 SM |
102 | (defvar compilation-first-column 1 |
103 | "*This is how compilers number the first column, usually 1 or 0.") | |
55dfd2c4 | 104 | |
e335e194 GM |
105 | (defvar compilation-parse-errors-filename-function nil |
106 | "Function to call to post-process filenames while parsing error messages. | |
107 | It takes one arg FILENAME which is the name of a file as found | |
108 | in the compilation output, and should return a transformed file name.") | |
109 | ||
49683a13 EZ |
110 | ;;;###autoload |
111 | (defvar compilation-process-setup-function nil | |
112 | "*Function to call to customize the compilation process. | |
6f5b7627 | 113 | This function is called immediately before the compilation process is |
49683a13 | 114 | started. It can be used to set any variables or functions that are used |
9ac57479 KS |
115 | while processing the output of the compilation process. The function |
116 | is called with variables `compilation-buffer' and `compilation-window' | |
7837c247 | 117 | bound to the compilation buffer and window, respectively.") |
49683a13 | 118 | |
aa228418 | 119 | ;;;###autoload |
d3cb357b | 120 | (defvar compilation-buffer-name-function nil |
6c43f2f9 RS |
121 | "Function to compute the name of a compilation buffer. |
122 | The function receives one argument, the name of the major mode of the | |
123 | compilation buffer. It should return a string. | |
f441be5b | 124 | If nil, compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.") |
55dfd2c4 | 125 | |
aa228418 | 126 | ;;;###autoload |
d3cb357b | 127 | (defvar compilation-finish-function nil |
c5049fa0 | 128 | "Function to call when a compilation process finishes. |
d3cb357b | 129 | It is called with two arguments: the compilation buffer, and a string |
620d3304 | 130 | describing how the process finished.") |
3c9e7f42 RS |
131 | |
132 | (make-obsolete-variable 'compilation-finish-function | |
f441be5b | 133 | "use `compilation-finish-functions', but it works a little differently." |
3c9e7f42 | 134 | "22.1") |
55dfd2c4 | 135 | |
4cc36b17 RS |
136 | ;;;###autoload |
137 | (defvar compilation-finish-functions nil | |
c5049fa0 | 138 | "Functions to call when a compilation process finishes. |
4cc36b17 RS |
139 | Each function is called with two arguments: the compilation buffer, |
140 | and a string describing how the process finished.") | |
141 | ||
ebff767c RM |
142 | (defvar compilation-in-progress nil |
143 | "List of compilation processes now running.") | |
144 | (or (assq 'compilation-in-progress minor-mode-alist) | |
145 | (setq minor-mode-alist (cons '(compilation-in-progress " Compiling") | |
146 | minor-mode-alist))) | |
147 | ||
7837c247 SM |
148 | (defvar compilation-error "error" |
149 | "Stem of message to print when no matches are found.") | |
6c43f2f9 | 150 | |
58856335 | 151 | (defvar compilation-arguments nil |
7837c247 | 152 | "Arguments that were given to `compilation-start'.") |
58856335 | 153 | |
6c43f2f9 | 154 | (defvar compilation-num-errors-found) |
d3cb357b | 155 | |
7837c247 SM |
156 | (defconst compilation-error-regexp-alist-alist |
157 | '((absoft | |
158 | "^\\(?:[Ee]rror on \\|[Ww]arning on\\( \\)\\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\ | |
159 | of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil (1)) | |
5dfa3d35 | 160 | |
7837c247 SM |
161 | (ada |
162 | "\\(warning: .*\\)? at \\([^ \n]+\\):\\([0-9]+\\)$" 2 3 nil (1)) | |
c7c5bbc0 | 163 | |
7837c247 SM |
164 | (aix |
165 | " in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1) | |
e1f540f2 | 166 | |
7837c247 SM |
167 | (ant |
168 | "^[ \t]*\\[[^] \n]+\\][ \t]*\\([^: \n]+\\):\\([0-9]+\\):\\(?:\\([0-9]+\\):[0-9]+:[0-9]+:\\)?\ | |
169 | \\( warning\\)?" 1 2 3 (4)) | |
e1f540f2 | 170 | |
bffa7817 SM |
171 | (maven |
172 | ;; Maven is a popular build tool for Java. Maven is Free Software. | |
173 | "\\(.*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\]" 1 2 3) | |
c94d5f81 | 174 | |
7837c247 SM |
175 | (bash |
176 | "^\\([^: \n\t]+\\): line \\([0-9]+\\):" 1 2) | |
e1f540f2 | 177 | |
7837c247 SM |
178 | (borland |
179 | "^\\(?:Error\\|Warnin\\(g\\)\\) \\(?:[FEW][0-9]+ \\)?\ | |
180 | \\([a-zA-Z]?:?[^:( \t\n]+\\)\ | |
181 | \\([0-9]+\\)\\(?:[) \t]\\|:[^0-9\n]\\)" 2 3 nil (1)) | |
182 | ||
183 | (caml | |
f6164cdd DP |
184 | "^ *File \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1, lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\ |
185 | \\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:\\)?\\([ \n]Warning:\\)?\\)" | |
186 | 2 (3 . 4) (5 . 6) (7)) | |
7837c247 SM |
187 | |
188 | (comma | |
189 | "^\"\\([^,\" \n\t]+\\)\", line \\([0-9]+\\)\ | |
190 | \\(?:[(. pos]+\\([0-9]+\\))?\\)?[:.,; (-]\\( warning:\\|[-0-9 ]*(W)\\)?" 1 2 3 (4)) | |
191 | ||
c39bf546 DP |
192 | (edg-1 |
193 | "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)" | |
194 | 1 2 nil (3 . 4)) | |
195 | (edg-2 | |
196 | "at line \\([0-9]+\\) of \"\\([^ \n]+\\)\"$" | |
197 | 2 1 nil 0) | |
198 | ||
7837c247 | 199 | (epc |
c39bf546 | 200 | "^Error [0-9]+ at (\\([0-9]+\\):\\([^)\n]+\\))" 2 1) |
7837c247 | 201 | |
12221c84 DP |
202 | (ftnchek |
203 | "\\(^Warning .*\\)? line[ \n]\\([0-9]+\\)[ \n]\\(?:col \\([0-9]+\\)[ \n]\\)?file \\([^ :;\n]+\\)" | |
204 | 4 2 3 (1)) | |
9fcabe79 | 205 | |
7837c247 SM |
206 | (iar |
207 | "^\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(?:Error\\|Warnin\\(g\\)\\)\\[[0-9]+\\]:" | |
208 | 1 2 nil (3)) | |
209 | ||
210 | (ibm | |
211 | "^\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) :\ | |
212 | \\(?:warnin\\(g\\)\\|informationa\\(l\\)\\)?" 1 2 3 (4 . 5)) | |
213 | ||
6f5b7627 | 214 | ;; fixme: should be `mips' |
7837c247 | 215 | (irix |
9fcabe79 DP |
216 | "^[-[:alnum:]_/ ]+: \\(?:\\(?:[sS]evere\\|[eE]rror\\|[wW]arnin\\(g\\)\\|[iI]nf\\(o\\)\\)[0-9 ]*: \\)?\ |
217 | \\([^,\" \n\t]+\\)\\(?:, line\\|:\\) \\([0-9]+\\):" 3 4 nil (1 . 2)) | |
7837c247 SM |
218 | |
219 | (java | |
220 | "^\\(?:[ \t]+at \\|==[0-9]+== +\\(?:at\\|b\\(y\\)\\)\\).+(\\([^()\n]+\\):\\([0-9]+\\))$" 2 3 nil (1)) | |
221 | ||
222 | (jikes-file | |
223 | "^\\(?:Found\\|Issued\\) .* compiling \"\\(.+\\)\":$" 1 nil nil 0) | |
224 | (jikes-line | |
225 | "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)" | |
226 | nil 1 nil 2 0 | |
227 | (2 (compilation-face '(3)))) | |
228 | ||
7837c247 | 229 | (gnu |
b8fa0ffd SM |
230 | ;; I have no idea what this first line is supposed to match, but it |
231 | ;; makes things ambiguous with output such as "foo:344:50:blabla" since | |
232 | ;; the "foo" part can match this first line (in which case the file | |
0ab31e4a SM |
233 | ;; name as "344"). To avoid this, the second line disallows filenames |
234 | ;; exclusively composed of digits. --Stef | |
235 | ;; Similarly, we get lots of false positives with messages including | |
236 | ;; times of the form "HH:MM:SS" where MM is taken as a line number, so | |
237 | ;; the last line tries to rule out message where the info after the | |
238 | ;; line number starts with "SS". --Stef | |
6f5b7627 | 239 | "^\\(?:[[:alpha:]][-[:alnum:].]+: ?\\)?\ |
d25593b7 | 240 | \\([0-9]*[^0-9\n]\\(?:[^\n ]\\| [^-\n]\\)*?\\): ?\ |
8decc87f SM |
241 | \\([0-9]+\\)\\(?:\\([.:]\\)\\([0-9]+\\)\\)?\ |
242 | \\(?:-\\([0-9]+\\)?\\(?:\\3\\([0-9]+\\)\\)?\\)?:\ | |
7837c247 | 243 | \\(?: *\\(\\(?:Future\\|Runtime\\)?[Ww]arning\\|W:\\)\\|\ |
d40a86f9 | 244 | *\\([Ii]nfo\\(?:\\>\\|rmationa?l?\\)\\|I:\\|instantiated from\\|[Nn]ote\\)\\|\ |
0ab31e4a | 245 | \[0-9]?\\(?:[^0-9\n]\\|$\\)\\|[0-9][0-9][0-9]\\)" |
7837c247 SM |
246 | 1 (2 . 5) (4 . 6) (7 . 8)) |
247 | ||
6e1a9597 CY |
248 | ;; The `gnu' style above can incorrectly match gcc's "In file |
249 | ;; included from" message, so we process that first. -- cyd | |
250 | (gcc-include | |
251 | "^\\(?:In file included\\| \\) from \ | |
252 | \\(.+\\):\\([0-9]+\\)\\(?:\\(:\\)\\|\\(,\\)\\)?" 1 2 nil (3 . 4)) | |
253 | ||
7837c247 SM |
254 | (lcc |
255 | "^\\(?:E\\|\\(W\\)\\), \\([^(\n]+\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)" | |
256 | 2 3 4 (1)) | |
257 | ||
258 | (makepp | |
250540cd | 259 | "^makepp\\(?:\\(?:: warning\\(:\\).*?\\|\\(: Scanning\\|: [LR]e?l?oading makefile\\|: Imported\\|log:.*?\\) \\|: .*?\\)\ |
3b79dd20 | 260 | `\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]\\)" |
7837c247 | 261 | 4 5 nil (1 . 2) 3 |
3b79dd20 | 262 | ("`\\(\\(\\S +?\\)\\(?::\\([0-9]+\\)\\)?\\)['(]" nil nil |
7837c247 SM |
263 | (2 compilation-info-face) |
264 | (3 compilation-line-face nil t) | |
51c8ad03 | 265 | (1 (compilation-error-properties 2 3 nil nil nil 0 nil) |
7837c247 SM |
266 | append))) |
267 | ||
6f5b7627 | 268 | ;; Should be lint-1, lint-2 (SysV lint) |
7837c247 SM |
269 | (mips-1 |
270 | " (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1) | |
271 | (mips-2 | |
272 | " in \\([^()\n ]+\\)(\\([0-9]+\\))$" 1 2) | |
273 | ||
274 | (msft | |
28547c1f | 275 | "^\\([0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \ |
2a516a73 | 276 | : \\(?:error\\|warnin\\(g\\)\\) C[0-9]+:" 2 3 nil (4)) |
7837c247 SM |
277 | |
278 | (oracle | |
b3ef54c5 DP |
279 | "^\\(?:Semantic error\\|Error\\|PCC-[0-9]+:\\).* line \\([0-9]+\\)\ |
280 | \\(?:\\(?:,\\| at\\)? column \\([0-9]+\\)\\)?\ | |
281 | \\(?:,\\| in\\| of\\)? file \\(.*?\\):?$" | |
7837c247 | 282 | 3 1 2) |
40d63d1f | 283 | |
049dcb6f GM |
284 | ;; "during global destruction": This comes out under "use |
285 | ;; warnings" in recent perl when breaking circular references | |
286 | ;; during program or thread exit. | |
7837c247 | 287 | (perl |
049dcb6f GM |
288 | " at \\([^ \n]+\\) line \\([0-9]+\\)\\(?:[,.]\\|$\\| \ |
289 | during global destruction\\.$\\)" 1 2) | |
7837c247 SM |
290 | |
291 | (rxp | |
292 | "^\\(?:Error\\|Warnin\\(g\\)\\):.*\n.* line \\([0-9]+\\) char\ | |
293 | \\([0-9]+\\) of file://\\(.+\\)" | |
294 | 4 2 3 (1)) | |
295 | ||
296 | (sparc-pascal-file | |
297 | "^\\w\\w\\w \\w\\w\\w +[0-3]?[0-9] +[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\ | |
298 | [12][09][0-9][0-9] +\\(.*\\):$" | |
299 | 1 nil nil 0) | |
300 | (sparc-pascal-line | |
301 | "^\\(\\(?:E\\|\\(w\\)\\) +[0-9]+\\) line \\([0-9]+\\) - " | |
302 | nil 3 nil (2) nil (1 (compilation-face '(2)))) | |
303 | (sparc-pascal-example | |
304 | "^ +\\([0-9]+\\) +.*\n\\(\\(?:e\\|\\(w\\)\\) [0-9]+\\)-+" | |
305 | nil 1 nil (3) nil (2 (compilation-face '(3)))) | |
306 | ||
307 | (sun | |
6f5b7627 | 308 | ": \\(?:ERROR\\|WARNIN\\(G\\)\\|REMAR\\(K\\)\\) \\(?:[[:alnum:] ]+, \\)?\ |
7837c247 SM |
309 | File = \\(.+\\), Line = \\([0-9]+\\)\\(?:, Column = \\([0-9]+\\)\\)?" |
310 | 3 4 5 (1 . 2)) | |
311 | ||
312 | (sun-ada | |
313 | "^\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3) | |
314 | ||
7837c247 SM |
315 | (4bsd |
316 | "\\(?:^\\|:: \\|\\S ( \\)\\(/[^ \n\t()]+\\)(\\([0-9]+\\))\ | |
0c9a01ff MY |
317 | \\(?:: \\(warning:\\)?\\|$\\| ),\\)" 1 2 nil (3)) |
318 | ||
319 | (gcov-file | |
b8fa0ffd | 320 | "^ *-: *\\(0\\):Source:\\(.+\\)$" |
eb3d9609 MY |
321 | 2 1 nil 0 nil |
322 | (1 compilation-line-face prepend) (2 compilation-info-face prepend)) | |
323 | (gcov-header | |
324 | "^ *-: *\\(0\\):\\(?:Object\\|Graph\\|Data\\|Runs\\|Programs\\):.+$" | |
325 | nil 1 nil 0 nil | |
326 | (1 compilation-line-face prepend)) | |
327 | ;; Underlines over all lines of gcov output are too uncomfortable to read. | |
328 | ;; However, hyperlinks embedded in the lines are useful. | |
329 | ;; So I put default face on the lines; and then put | |
330 | ;; compilation-*-face by manually to eliminate the underlines. | |
331 | ;; The hyperlinks are still effective. | |
332 | (gcov-nomark | |
333 | "^ *-: *\\([1-9]\\|[0-9]\\{2,\\}\\):.*$" | |
334 | nil 1 nil 0 nil | |
335 | (0 'default t) | |
336 | (1 compilation-line-face prepend)) | |
0c9a01ff | 337 | (gcov-called-line |
eb3d9609 | 338 | "^ *\\([0-9]+\\): *\\([0-9]+\\):.*$" |
b8fa0ffd | 339 | nil 2 nil 0 nil |
eb3d9609 MY |
340 | (0 'default t) |
341 | (1 compilation-info-face prepend) (2 compilation-line-face prepend)) | |
342 | (gcov-never-called | |
b8fa0ffd | 343 | "^ *\\(#####\\): *\\([0-9]+\\):.*$" |
eb3d9609 MY |
344 | nil 2 nil 2 nil |
345 | (0 'default t) | |
346 | (1 compilation-error-face prepend) (2 compilation-line-face prepend)) | |
ddab7705 VJL |
347 | |
348 | (compilation-perl--Pod::Checker | |
349 | ;; podchecker error messages, per Pod::Checker. | |
350 | ;; The style is from the Pod::Checker::poderror() function, eg. | |
351 | ;; *** ERROR: Spurious text after =cut at line 193 in file foo.pm | |
352 | ;; | |
353 | ;; Plus end_pod() can give "at line EOF" instead of a | |
354 | ;; number, so for that match "on line N" which is the | |
355 | ;; originating spot, eg. | |
356 | ;; *** ERROR: =over on line 37 without closing =back at line EOF in file bar.pm | |
357 | ;; | |
358 | ;; Plus command() can give both "on line N" and "at line N"; | |
359 | ;; the latter is desired and is matched because the .* is | |
360 | ;; greedy. | |
361 | ;; *** ERROR: =over on line 1 without closing =back (at head1) at line 3 in file x.pod | |
362 | ;; | |
363 | "^\\*\\*\\* \\(?:ERROR\\|\\(WARNING\\)\\).* \\(?:at\\|on\\) line \ | |
364 | \\([0-9]+\\) \\(?:.* \\)?in file \\([^ \t\n]+\\)" | |
365 | 3 2 nil (1)) | |
366 | (compilation-perl--Test | |
367 | ;; perl Test module error messages. | |
368 | ;; Style per the ok() function "$context", eg. | |
369 | ;; # Failed test 1 in foo.t at line 6 | |
370 | ;; | |
371 | "^# Failed test [0-9]+ in \\([^ \t\r\n]+\\) at line \\([0-9]+\\)" | |
372 | 1 2) | |
373 | (compilation-perl--Test::Harness | |
374 | ;; perl Test::Harness output, eg. | |
375 | ;; NOK 1# Test 1 got: "1234" (t/foo.t at line 46) | |
376 | ;; | |
377 | ;; Test::Harness is slightly designed for tty output, since | |
378 | ;; it prints CRs to overwrite progress messages, but if you | |
379 | ;; run it in with M-x compile this pattern can at least step | |
380 | ;; through the failures. | |
381 | ;; | |
382 | "^.*NOK.* \\([^ \t\r\n]+\\) at line \\([0-9]+\\)" | |
383 | 1 2) | |
384 | (compilation-weblint | |
385 | ;; The style comes from HTML::Lint::Error::as_string(), eg. | |
386 | ;; index.html (13:1) Unknown element <fdjsk> | |
387 | ;; | |
388 | ;; The pattern only matches filenames without spaces, since that | |
389 | ;; should be usual and should help reduce the chance of a false | |
390 | ;; match of a message from some unrelated program. | |
391 | ;; | |
392 | ;; This message style is quite close to the "ibm" entry which is | |
393 | ;; for IBM C, though that ibm bit doesn't put a space after the | |
394 | ;; filename. | |
395 | ;; | |
396 | "^\\([^ \t\r\n(]+\\) (\\([0-9]+\\):\\([0-9]+\\)) " | |
397 | 1 2 3) | |
eb3d9609 | 398 | ) |
7837c247 SM |
399 | "Alist of values for `compilation-error-regexp-alist'.") |
400 | ||
401 | (defcustom compilation-error-regexp-alist | |
402 | (mapcar 'car compilation-error-regexp-alist-alist) | |
6c43f2f9 | 403 | "Alist that specifies how to match errors in compiler output. |
7957baea | 404 | On GNU and Unix, any string is a valid filename, so these |
7837c247 SM |
405 | matchers must make some common sense assumptions, which catch |
406 | normal cases. A shorter list will be lighter on resource usage. | |
407 | ||
408 | Instead of an alist element, you can use a symbol, which is | |
409 | looked up in `compilation-error-regexp-alist-alist'. You can see | |
410 | the predefined symbols and their effects in the file | |
6f5b7627 | 411 | `etc/compilation.txt' (linked below if you are customizing this). |
7837c247 SM |
412 | |
413 | Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK | |
414 | HIGHLIGHT...]). If REGEXP matches, the FILE'th subexpression | |
415 | gives the file name, and the LINE'th subexpression gives the line | |
416 | number. The COLUMN'th subexpression gives the column number on | |
417 | that line. | |
418 | ||
419 | If FILE, LINE or COLUMN are nil or that index didn't match, that | |
420 | information is not present on the matched line. In that case the | |
421 | file name is assumed to be the same as the previous one in the | |
422 | buffer, line number defaults to 1 and column defaults to | |
423 | beginning of line's indentation. | |
424 | ||
425 | FILE can also have the form (FILE FORMAT...), where the FORMATs | |
426 | \(e.g. \"%s.c\") will be applied in turn to the recognized file | |
427 | name, until a file of that name is found. Or FILE can also be a | |
4aede2f2 RS |
428 | function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME). |
429 | In the former case, FILENAME may be relative or absolute. | |
7837c247 SM |
430 | |
431 | LINE can also be of the form (LINE . END-LINE) meaning a range | |
432 | of lines. COLUMN can also be of the form (COLUMN . END-COLUMN) | |
433 | meaning a range of columns starting on LINE and ending on | |
434 | END-LINE, if that matched. | |
435 | ||
436 | TYPE is 2 or nil for a real error or 1 for warning or 0 for info. | |
437 | TYPE can also be of the form (WARNING . INFO). In that case this | |
438 | will be equivalent to 1 if the WARNING'th subexpression matched | |
439 | or else equivalent to 0 if the INFO'th subexpression matched. | |
440 | See `compilation-error-face', `compilation-warning-face', | |
441 | `compilation-info-face' and `compilation-skip-threshold'. | |
442 | ||
443 | What matched the HYPERLINK'th subexpression has `mouse-face' and | |
444 | `compilation-message-face' applied. If this is nil, the text | |
445 | matched by the whole REGEXP becomes the hyperlink. | |
446 | ||
447 | Additional HIGHLIGHTs as described under `font-lock-keywords' can | |
448 | be added." | |
449 | :type `(set :menu-tag "Pick" | |
450 | ,@(mapcar (lambda (elt) | |
451 | (list 'const (car elt))) | |
452 | compilation-error-regexp-alist-alist)) | |
453 | :link `(file-link :tag "example file" | |
eeb3ede4 | 454 | ,(expand-file-name "compilation.txt" data-directory)) |
7837c247 | 455 | :group 'compilation) |
55dfd2c4 | 456 | |
98d4c36f | 457 | ;;;###autoload(put 'compilation-directory 'safe-local-variable 'stringp) |
ebb8cb68 EZ |
458 | (defvar compilation-directory nil |
459 | "Directory to restore to when doing `recompile'.") | |
460 | ||
7837c247 SM |
461 | (defvar compilation-directory-matcher |
462 | '("\\(?:Entering\\|Leavin\\(g\\)\\) directory `\\(.+\\)'$" (2 . 1)) | |
463 | "A list for tracking when directories are entered or left. | |
434520fa | 464 | If nil, do not track directories, e.g. if all file names are absolute. The |
7837c247 SM |
465 | first element is the REGEXP matching these messages. It can match any number |
466 | of variants, e.g. different languages. The remaining elements are all of the | |
467 | form (DIR . LEAVE). If for any one of these the DIR'th subexpression | |
468 | matches, that is a directory name. If LEAVE is nil or the corresponding | |
469 | LEAVE'th subexpression doesn't match, this message is about going into another | |
470 | directory. If it does match anything, this message is about going back to the | |
471 | directory we were in before the last entering message. If you change this, | |
472 | you may also want to change `compilation-page-delimiter'.") | |
473 | ||
474 | (defvar compilation-page-delimiter | |
475 | "^\\(?:\f\\|.*\\(?:Entering\\|Leaving\\) directory `.+'\n\\)+" | |
476 | "Value of `page-delimiter' in Compilation mode.") | |
477 | ||
478 | (defvar compilation-mode-font-lock-keywords | |
0ab31e4a | 479 | '(;; configure output lines. |
7837c247 SM |
480 | ("^[Cc]hecking \\(?:[Ff]or \\|[Ii]f \\|[Ww]hether \\(?:to \\)?\\)?\\(.+\\)\\.\\.\\. *\\(?:(cached) *\\)?\\(\\(yes\\(?: .+\\)?\\)\\|no\\|\\(.*\\)\\)$" |
481 | (1 font-lock-variable-name-face) | |
38dbf92b | 482 | (2 (compilation-face '(4 . 3)))) |
7837c247 | 483 | ;; Command output lines. Recognize `make[n]:' lines too. |
6f5b7627 | 484 | ("^\\([[:alnum:]_/.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:" |
7837c247 SM |
485 | (1 font-lock-function-name-face) (3 compilation-line-face nil t)) |
486 | (" --?o\\(?:utfile\\|utput\\)?[= ]?\\(\\S +\\)" . 1) | |
47f97084 RF |
487 | ("^Compilation \\(finished\\).*" |
488 | (0 '(face nil message nil help-echo nil mouse-face nil) t) | |
314b410b | 489 | (1 compilation-info-face)) |
0ab31e4a | 490 | ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*" |
47f97084 | 491 | (0 '(face nil message nil help-echo nil mouse-face nil) t) |
314b410b JL |
492 | (1 compilation-error-face) |
493 | (2 compilation-error-face nil t))) | |
7837c247 SM |
494 | "Additional things to highlight in Compilation mode. |
495 | This gets tacked on the end of the generated expressions.") | |
a24770bc | 496 | |
9ac57479 KS |
497 | (defvar compilation-highlight-regexp t |
498 | "Regexp matching part of visited source lines to highlight temporarily. | |
499 | Highlight entire line if t; don't highlight source lines if nil.") | |
500 | ||
501 | (defvar compilation-highlight-overlay nil | |
502 | "Overlay used to temporarily highlight compilation matches.") | |
503 | ||
f8e03ecb | 504 | (defcustom compilation-error-screen-columns t |
813fb3fe | 505 | "If non-nil, column numbers in error messages are screen columns. |
f8e03ecb AS |
506 | Otherwise they are interpreted as character positions, with |
507 | each character occupying one column. | |
508 | The default is to use screen columns, which requires that the compilation | |
509 | program and Emacs agree about the display width of the characters, | |
510 | especially the TAB character." | |
511 | :type 'boolean | |
512 | :group 'compilation | |
513 | :version "20.4") | |
514 | ||
c5049fa0 | 515 | (defcustom compilation-read-command t |
813fb3fe | 516 | "Non-nil means \\[compile] reads the compilation command to use. |
851231e9 | 517 | Otherwise, \\[compile] just uses the value of `compile-command'." |
c5049fa0 RS |
518 | :type 'boolean |
519 | :group 'compilation) | |
90016295 | 520 | |
e83be080 | 521 | ;;;###autoload |
c5049fa0 | 522 | (defcustom compilation-ask-about-save t |
813fb3fe | 523 | "Non-nil means \\[compile] asks which buffers to save before compiling. |
c5049fa0 RS |
524 | Otherwise, it saves all modified buffers without asking." |
525 | :type 'boolean | |
526 | :group 'compilation) | |
90016295 | 527 | |
7c163413 | 528 | ;;;###autoload |
c5049fa0 | 529 | (defcustom compilation-search-path '(nil) |
813fb3fe | 530 | "List of directories to search for source files named in error messages. |
d3cb357b | 531 | Elements should be directory names, not file names of directories. |
f441be5b | 532 | The value nil as an element means to try the default directory." |
c5049fa0 RS |
533 | :type '(repeat (choice (const :tag "Default" nil) |
534 | (string :tag "Directory"))) | |
535 | :group 'compilation) | |
55dfd2c4 | 536 | |
7957baea | 537 | ;;;###autoload |
c5049fa0 | 538 | (defcustom compile-command "make -k " |
813fb3fe | 539 | "Last shell command used to do a compilation; default for next compilation. |
55dfd2c4 RS |
540 | |
541 | Sometimes it is useful for files to supply local values for this variable. | |
542 | You might also use mode hooks to specify it in certain modes, like this: | |
543 | ||
61c4aaf8 | 544 | (add-hook 'c-mode-hook |
61c4aaf8 RS |
545 | (lambda () |
546 | (unless (or (file-exists-p \"makefile\") | |
547 | (file-exists-p \"Makefile\")) | |
5b6858da SM |
548 | (set (make-local-variable 'compile-command) |
549 | (concat \"make -k \" | |
7837c247 | 550 | (file-name-sans-extension buffer-file-name))))))" |
c5049fa0 RS |
551 | :type 'string |
552 | :group 'compilation) | |
631c8020 | 553 | ;;;###autoload(put 'compile-command 'safe-local-variable 'stringp) |
55dfd2c4 | 554 | |
7957baea | 555 | ;;;###autoload |
93ef35e4 | 556 | (defcustom compilation-disable-input nil |
813fb3fe | 557 | "If non-nil, send end-of-file as compilation process input. |
3fa37cd1 | 558 | This only affects platforms that support asynchronous processes (see |
bac3a1c9 | 559 | `start-process'); synchronous compilation processes never accept input." |
3fa37cd1 EZ |
560 | :type 'boolean |
561 | :group 'compilation | |
562 | :version "22.1") | |
563 | ||
7837c247 SM |
564 | ;; A weak per-compilation-buffer hash indexed by (FILENAME . DIRECTORY). Each |
565 | ;; value is a FILE-STRUCTURE as described above, with the car eq to the hash | |
4fffd73b | 566 | ;; key. This holds the tree seen from root, for storing new nodes. |
7837c247 SM |
567 | (defvar compilation-locs ()) |
568 | ||
569 | (defvar compilation-debug nil | |
6f5b7627 | 570 | "*Set this to t before creating a *compilation* buffer. |
7837c247 SM |
571 | Then every error line will have a debug text property with the matcher that |
572 | fit this line and the match data. Use `describe-text-properties'.") | |
d3cb357b | 573 | |
01f89d11 RM |
574 | (defvar compilation-exit-message-function nil "\ |
575 | If non-nil, called when a compilation process dies to return a status message. | |
fd5e58d7 RM |
576 | This should be a function of three arguments: process status, exit status, |
577 | and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to | |
578 | write into the compilation buffer, and to put in its mode line.") | |
01f89d11 | 579 | |
c20f961b JPW |
580 | (defvar compilation-environment nil |
581 | "*List of environment variables for compilation to inherit. | |
582 | Each element should be a string of the form ENVVARNAME=VALUE. | |
583 | This list is temporarily prepended to `process-environment' prior to | |
584 | starting the compilation process.") | |
585 | ||
770970cb RS |
586 | ;; History of compile commands. |
587 | (defvar compile-history nil) | |
770970cb | 588 | |
fa947ef3 JL |
589 | (defface compilation-error |
590 | '((t :inherit font-lock-warning-face)) | |
591 | "Face used to highlight compiler errors." | |
da742205 | 592 | :group 'compilation |
fa947ef3 JL |
593 | :version "22.1") |
594 | ||
541a6d0d | 595 | (defface compilation-warning |
bc3621a0 EZ |
596 | '((((class color) (min-colors 16)) (:foreground "Orange" :weight bold)) |
597 | (((class color)) (:foreground "cyan" :weight bold)) | |
7837c247 SM |
598 | (t (:weight bold))) |
599 | "Face used to highlight compiler warnings." | |
da742205 | 600 | :group 'compilation |
bf247b6e | 601 | :version "22.1") |
7837c247 | 602 | |
541a6d0d | 603 | (defface compilation-info |
e4aa3c94 | 604 | '((((class color) (min-colors 16) (background light)) |
bc3621a0 | 605 | (:foreground "Green3" :weight bold)) |
ea81d57e DN |
606 | (((class color) (min-colors 88) (background dark)) |
607 | (:foreground "Green1" :weight bold)) | |
e4aa3c94 | 608 | (((class color) (min-colors 16) (background dark)) |
bc3621a0 EZ |
609 | (:foreground "Green" :weight bold)) |
610 | (((class color)) (:foreground "green" :weight bold)) | |
7837c247 | 611 | (t (:weight bold))) |
fa947ef3 | 612 | "Face used to highlight compiler information." |
da742205 | 613 | :group 'compilation |
bf247b6e | 614 | :version "22.1") |
7837c247 | 615 | |
a5f1c37e | 616 | (defface compilation-line-number |
38dbf92b | 617 | '((t :inherit font-lock-variable-name-face)) |
fa947ef3 | 618 | "Face for displaying line numbers in compiler messages." |
da742205 | 619 | :group 'compilation |
a5f1c37e RS |
620 | :version "22.1") |
621 | ||
622 | (defface compilation-column-number | |
38dbf92b | 623 | '((t :inherit font-lock-type-face)) |
fa947ef3 | 624 | "Face for displaying column numbers in compiler messages." |
da742205 | 625 | :group 'compilation |
a5f1c37e RS |
626 | :version "22.1") |
627 | ||
f4beca06 | 628 | (defcustom compilation-message-face 'underline |
7837c247 SM |
629 | "Face name to use for whole messages. |
630 | Faces `compilation-error-face', `compilation-warning-face', | |
631 | `compilation-info-face', `compilation-line-face' and | |
f4beca06 RS |
632 | `compilation-column-face' get prepended to this, when applicable." |
633 | :type 'face | |
634 | :group 'compilation | |
635 | :version "22.1") | |
7837c247 | 636 | |
38dbf92b | 637 | (defvar compilation-error-face 'compilation-error |
7837c247 SM |
638 | "Face name to use for file name in error messages.") |
639 | ||
38dbf92b | 640 | (defvar compilation-warning-face 'compilation-warning |
7837c247 SM |
641 | "Face name to use for file name in warning messages.") |
642 | ||
38dbf92b | 643 | (defvar compilation-info-face 'compilation-info |
7837c247 SM |
644 | "Face name to use for file name in informational messages.") |
645 | ||
a5f1c37e | 646 | (defvar compilation-line-face 'compilation-line-number |
38dbf92b | 647 | "Face name to use for line numbers in compiler messages.") |
7837c247 | 648 | |
a5f1c37e | 649 | (defvar compilation-column-face 'compilation-column-number |
fa947ef3 | 650 | "Face name to use for column numbers in compiler messages.") |
7837c247 SM |
651 | |
652 | ;; same faces as dired uses | |
653 | (defvar compilation-enter-directory-face 'font-lock-function-name-face | |
fa947ef3 | 654 | "Face name to use for entering directory messages.") |
7837c247 SM |
655 | |
656 | (defvar compilation-leave-directory-face 'font-lock-type-face | |
fa947ef3 | 657 | "Face name to use for leaving directory messages.") |
7837c247 SM |
658 | |
659 | ||
660 | ||
c536bb39 | 661 | ;; Used for compatibility with the old compile.el. |
0ff7f01e | 662 | (defvaralias 'compilation-last-buffer 'next-error-last-buffer) |
6f5b7627 | 663 | (defvar compilation-parsing-end (make-marker)) |
c536bb39 SM |
664 | (defvar compilation-parse-errors-function nil) |
665 | (defvar compilation-error-list nil) | |
666 | (defvar compilation-old-error-list nil) | |
667 | ||
813fb3fe SM |
668 | (defcustom compilation-auto-jump-to-first-error nil |
669 | "If non-nil, automatically jump to the first error after `compile'." | |
765831a0 DN |
670 | :type 'boolean |
671 | :group 'compilation | |
672 | :version "23.1") | |
813fb3fe SM |
673 | |
674 | (defvar compilation-auto-jump-to-next nil | |
675 | "If non-nil, automatically jump to the next error encountered.") | |
676 | (make-variable-buffer-local 'compilation-auto-jump-to-next) | |
677 | ||
97546017 DN |
678 | |
679 | (defvar compilation-skip-to-next-location t | |
680 | "*If non-nil, skip multiple error messages for the same source location.") | |
681 | ||
682 | (defcustom compilation-skip-threshold 1 | |
683 | "Compilation motion commands skip less important messages. | |
684 | The value can be either 2 -- skip anything less than error, 1 -- | |
685 | skip anything less than warning or 0 -- don't skip any messages. | |
686 | Note that all messages not positively identified as warning or | |
687 | info, are considered errors." | |
688 | :type '(choice (const :tag "Warnings and info" 2) | |
689 | (const :tag "Info" 1) | |
690 | (const :tag "None" 0)) | |
691 | :group 'compilation | |
692 | :version "22.1") | |
693 | ||
694 | (defcustom compilation-skip-visited nil | |
695 | "Compilation motion commands skip visited messages if this is t. | |
696 | Visited messages are ones for which the file, line and column have been jumped | |
697 | to from the current content in the current compilation buffer, even if it was | |
698 | from a different message." | |
699 | :type 'boolean | |
700 | :group 'compilation | |
701 | :version "22.1") | |
702 | ||
7837c247 SM |
703 | (defun compilation-face (type) |
704 | (or (and (car type) (match-end (car type)) compilation-warning-face) | |
705 | (and (cdr type) (match-end (cdr type)) compilation-info-face) | |
706 | compilation-error-face)) | |
707 | ||
deda0c65 DP |
708 | ;; Internal function for calculating the text properties of a directory |
709 | ;; change message. The directory property is important, because it is | |
710 | ;; the stack of nested enter-messages. Relative filenames on the following | |
711 | ;; lines are relative to the top of the stack. | |
7837c247 SM |
712 | (defun compilation-directory-properties (idx leave) |
713 | (if leave (setq leave (match-end leave))) | |
714 | ;; find previous stack, and push onto it, or if `leave' pop it | |
715 | (let ((dir (previous-single-property-change (point) 'directory))) | |
716 | (setq dir (if dir (or (get-text-property (1- dir) 'directory) | |
717 | (get-text-property dir 'directory)))) | |
718 | `(face ,(if leave | |
719 | compilation-leave-directory-face | |
720 | compilation-enter-directory-face) | |
721 | directory ,(if leave | |
722 | (or (cdr dir) | |
723 | '(nil)) ; nil only isn't a property-change | |
724 | (cons (match-string-no-properties idx) dir)) | |
725 | mouse-face highlight | |
6f5b7627 | 726 | keymap compilation-button-map |
5ae48997 | 727 | help-echo "mouse-2: visit destination directory"))) |
7837c247 | 728 | |
4fffd73b | 729 | ;; Data type `reverse-ordered-alist' retriever. This function retrieves the |
7837c247 SM |
730 | ;; KEY element from the ALIST, creating it in the right position if not already |
731 | ;; present. ALIST structure is | |
732 | ;; '(ANCHOR (KEY1 ...) (KEY2 ...)... (KEYn ALIST ...)) | |
733 | ;; ANCHOR is ignored, but necessary so that elements can be inserted. KEY1 | |
4fffd73b | 734 | ;; may be nil. The other KEYs are ordered backwards so that growing line |
7837c247 SM |
735 | ;; numbers can be inserted in front and searching can abort after half the |
736 | ;; list on average. | |
6f5b7627 | 737 | (eval-when-compile ;Don't keep it at runtime if not needed. |
7837c247 SM |
738 | (defmacro compilation-assq (key alist) |
739 | `(let* ((l1 ,alist) | |
740 | (l2 (cdr l1))) | |
741 | (car (if (if (null ,key) | |
742 | (if l2 (null (caar l2))) | |
743 | (while (if l2 (if (caar l2) (< ,key (caar l2)) t)) | |
744 | (setq l1 l2 | |
745 | l2 (cdr l1))) | |
746 | (if l2 (eq ,key (caar l2)))) | |
747 | l2 | |
6f5b7627 | 748 | (setcdr l1 (cons (list ,key) l2))))))) |
7837c247 | 749 | |
813fb3fe SM |
750 | (defun compilation-auto-jump (buffer pos) |
751 | (with-current-buffer buffer | |
752 | (goto-char pos) | |
753 | (compile-goto-error))) | |
7837c247 SM |
754 | |
755 | ;; This function is the central driver, called when font-locking to gather | |
756 | ;; all information needed to later jump to corresponding source code. | |
757 | ;; Return a property list with all meta information on this error location. | |
f0685ed1 | 758 | |
7837c247 | 759 | (defun compilation-error-properties (file line end-line col end-col type fmt) |
813fb3fe SM |
760 | (unless (< (next-single-property-change (match-beginning 0) |
761 | 'directory nil (point)) | |
7837c247 SM |
762 | (point)) |
763 | (if file | |
764 | (if (functionp file) | |
765 | (setq file (funcall file)) | |
766 | (let (dir) | |
767 | (setq file (match-string-no-properties file)) | |
768 | (unless (file-name-absolute-p file) | |
769 | (setq dir (previous-single-property-change (point) 'directory) | |
770 | dir (if dir (or (get-text-property (1- dir) 'directory) | |
771 | (get-text-property dir 'directory))))) | |
efb0e677 | 772 | (setq file (cons file (car dir))))) |
7837c247 | 773 | ;; This message didn't mention one, get it from previous |
f0685ed1 RS |
774 | (let ((prev-pos |
775 | ;; Find the previous message. | |
776 | (previous-single-property-change (point) 'message))) | |
777 | (if prev-pos | |
778 | ;; Get the file structure that belongs to it. | |
779 | (let* ((prev | |
780 | (or (get-text-property (1- prev-pos) 'message) | |
781 | (get-text-property prev-pos 'message))) | |
782 | (prev-struct | |
783 | (car (nth 2 (car prev))))) | |
784 | ;; Construct FILE . DIR from that. | |
785 | (if prev-struct | |
786 | (setq file (cons (car prev-struct) | |
787 | (cadr prev-struct)))))) | |
788 | (unless file | |
789 | (setq file '("*unknown*"))))) | |
7837c247 SM |
790 | ;; All of these fields are optional, get them only if we have an index, and |
791 | ;; it matched some part of the message. | |
792 | (and line | |
793 | (setq line (match-string-no-properties line)) | |
794 | (setq line (string-to-number line))) | |
795 | (and end-line | |
796 | (setq end-line (match-string-no-properties end-line)) | |
797 | (setq end-line (string-to-number end-line))) | |
9dc3a46a JL |
798 | (if col |
799 | (if (functionp col) | |
800 | (setq col (funcall col)) | |
801 | (and | |
802 | (setq col (match-string-no-properties col)) | |
803 | (setq col (- (string-to-number col) compilation-first-column))))) | |
804 | (if (and end-col (functionp end-col)) | |
805 | (setq end-col (funcall end-col)) | |
806 | (if (and end-col (setq end-col (match-string-no-properties end-col))) | |
807 | (setq end-col (- (string-to-number end-col) compilation-first-column -1)) | |
808 | (if end-line (setq end-col -1)))) | |
eb6fb6e2 | 809 | (if (consp type) ; not a static type, check what it is. |
7837c247 SM |
810 | (setq type (or (and (car type) (match-end (car type)) 1) |
811 | (and (cdr type) (match-end (cdr type)) 0) | |
812 | 2))) | |
813fb3fe SM |
813 | |
814 | (when (and compilation-auto-jump-to-next | |
815 | (>= type compilation-skip-threshold)) | |
816 | (kill-local-variable 'compilation-auto-jump-to-next) | |
817 | (run-with-timer 0 nil 'compilation-auto-jump | |
818 | (current-buffer) (match-beginning 0))) | |
819 | ||
efb0e677 SM |
820 | (compilation-internal-error-properties file line end-line col end-col type fmt))) |
821 | ||
9c8e6c85 SM |
822 | (defun compilation-move-to-column (col screen) |
823 | "Go to column COL on the current line. | |
824 | If SCREEN is non-nil, columns are screen columns, otherwise, they are | |
825 | just char-counts." | |
826 | (if screen | |
827 | (move-to-column col) | |
828 | (goto-char (min (+ (line-beginning-position) col) (line-end-position))))) | |
829 | ||
7957baea | 830 | (defun compilation-internal-error-properties (file line end-line col end-col type fmts) |
efb0e677 SM |
831 | "Get the meta-info that will be added as text-properties. |
832 | LINE, END-LINE, COL, END-COL are integers or nil. | |
7957baea RS |
833 | TYPE can be 0, 1, or 2, meaning error, warning, or just info. |
834 | FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME) or nil. | |
835 | FMTS is a list of format specs for transforming the file name. | |
836 | (See `compilation-error-regexp-alist'.)" | |
efb0e677 | 837 | (unless file (setq file '("*unknown*"))) |
7957baea RS |
838 | (let* ((file-struct (compilation-get-file-structure file fmts)) |
839 | ;; Get first already existing marker (if any has one, all have one). | |
840 | ;; Do this first, as the compilation-assq`s may create new nodes. | |
841 | (marker-line (car (cddr file-struct))) ; a line structure | |
efb0e677 SM |
842 | (marker (nth 3 (cadr marker-line))) ; its marker |
843 | (compilation-error-screen-columns compilation-error-screen-columns) | |
844 | end-marker loc end-loc) | |
845 | (if (not (and marker (marker-buffer marker))) | |
7957baea | 846 | (setq marker nil) ; no valid marker for this file |
dbd97672 DP |
847 | (setq loc (or line 1)) ; normalize no linenumber to line 1 |
848 | (catch 'marker ; find nearest loc, at least one exists | |
7957baea | 849 | (dolist (x (nthcdr 3 file-struct)) ; loop over remaining lines |
dbd97672 | 850 | (if (> (car x) loc) ; still bigger |
efb0e677 | 851 | (setq marker-line x) |
dbd97672 DP |
852 | (if (> (- (or (car marker-line) 1) loc) |
853 | (- loc (car x))) ; current line is nearer | |
efb0e677 SM |
854 | (setq marker-line x)) |
855 | (throw 'marker t)))) | |
856 | (setq marker (nth 3 (cadr marker-line)) | |
dbd97672 | 857 | marker-line (or (car marker-line) 1)) |
efb0e677 | 858 | (with-current-buffer (marker-buffer marker) |
8dfb3e16 RS |
859 | (save-excursion |
860 | (save-restriction | |
861 | (widen) | |
862 | (goto-char (marker-position marker)) | |
863 | (when (or end-col end-line) | |
864 | (beginning-of-line (- (or end-line line) marker-line -1)) | |
865 | (if (or (null end-col) (< end-col 0)) | |
866 | (end-of-line) | |
867 | (compilation-move-to-column | |
868 | end-col compilation-error-screen-columns)) | |
869 | (setq end-marker (list (point-marker)))) | |
870 | (beginning-of-line (if end-line | |
871 | (- line end-line -1) | |
872 | (- loc marker-line -1))) | |
873 | (if col | |
874 | (compilation-move-to-column | |
875 | col compilation-error-screen-columns) | |
876 | (forward-to-indentation 0)) | |
877 | (setq marker (list (point-marker))))))) | |
efb0e677 | 878 | |
7957baea | 879 | (setq loc (compilation-assq line (cdr file-struct))) |
efb0e677 | 880 | (if end-line |
7957baea | 881 | (setq end-loc (compilation-assq end-line (cdr file-struct)) |
efb0e677 SM |
882 | end-loc (compilation-assq end-col end-loc)) |
883 | (if end-col ; use same line element | |
884 | (setq end-loc (compilation-assq end-col loc)))) | |
885 | (setq loc (compilation-assq col loc)) | |
886 | ;; If they are new, make the loc(s) reference the file they point to. | |
7957baea | 887 | (or (cdr loc) (setcdr loc `(,line ,file-struct ,@marker))) |
efb0e677 | 888 | (if end-loc |
7957baea RS |
889 | (or (cdr end-loc) |
890 | (setcdr end-loc `(,(or end-line line) ,file-struct ,@end-marker)))) | |
efb0e677 SM |
891 | |
892 | ;; Must start with face | |
893 | `(face ,compilation-message-face | |
894 | message (,loc ,type ,end-loc) | |
895 | ,@(if compilation-debug | |
896 | `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords) | |
897 | ,@(match-data)))) | |
898 | help-echo ,(if col | |
899 | "mouse-2: visit this file, line and column" | |
900 | (if line | |
901 | "mouse-2: visit this file and line" | |
902 | "mouse-2: visit this file")) | |
903 | keymap compilation-button-map | |
904 | mouse-face highlight))) | |
7837c247 | 905 | |
e93b2a55 SM |
906 | (defun compilation-mode-font-lock-keywords () |
907 | "Return expressions to highlight in Compilation mode." | |
91fa27cd SM |
908 | (if compilation-parse-errors-function |
909 | ;; An old package! Try the compatibility code. | |
910 | '((compilation-compat-parse-errors)) | |
911 | (append | |
912 | ;; make directory tracking | |
913 | (if compilation-directory-matcher | |
914 | `((,(car compilation-directory-matcher) | |
915 | ,@(mapcar (lambda (elt) | |
916 | `(,(car elt) | |
917 | (compilation-directory-properties | |
918 | ,(car elt) ,(cdr elt)) | |
0ea50e43 | 919 | t t)) |
91fa27cd SM |
920 | (cdr compilation-directory-matcher))))) |
921 | ||
922 | ;; Compiler warning/error lines. | |
923 | (mapcar | |
924 | (lambda (item) | |
925 | (if (symbolp item) | |
926 | (setq item (cdr (assq item | |
927 | compilation-error-regexp-alist-alist)))) | |
928 | (let ((file (nth 1 item)) | |
929 | (line (nth 2 item)) | |
930 | (col (nth 3 item)) | |
931 | (type (nth 4 item)) | |
932 | end-line end-col fmt) | |
b3a7f48f DP |
933 | (if (consp file) (setq fmt (cdr file) file (car file))) |
934 | (if (consp line) (setq end-line (cdr line) line (car line))) | |
91fa27cd | 935 | (if (consp col) (setq end-col (cdr col) col (car col))) |
b3a7f48f | 936 | |
544dccaa | 937 | (if (functionp line) |
91fa27cd SM |
938 | ;; The old compile.el had here an undocumented hook that |
939 | ;; allowed `line' to be a function that computed the actual | |
940 | ;; error location. Let's do our best. | |
941 | `(,(car item) | |
0ea50e43 RS |
942 | (0 (save-match-data |
943 | (compilation-compat-error-properties | |
944 | (funcall ',line (cons (match-string ,file) | |
945 | (cons default-directory | |
946 | ',(nthcdr 4 item))) | |
947 | ,(if col `(match-string ,col)))))) | |
91fa27cd | 948 | (,file compilation-error-face t)) |
b3a7f48f | 949 | |
f71d34b0 SM |
950 | (unless (or (null (nth 5 item)) (integerp (nth 5 item))) |
951 | (error "HYPERLINK should be an integer: %s" (nth 5 item))) | |
952 | ||
91fa27cd SM |
953 | `(,(nth 0 item) |
954 | ||
955 | ,@(when (integerp file) | |
956 | `((,file ,(if (consp type) | |
957 | `(compilation-face ',type) | |
958 | (aref [compilation-info-face | |
959 | compilation-warning-face | |
960 | compilation-error-face] | |
961 | (or type 2)))))) | |
962 | ||
963 | ,@(when line | |
964 | `((,line compilation-line-face nil t))) | |
965 | ,@(when end-line | |
966 | `((,end-line compilation-line-face nil t))) | |
967 | ||
9dc3a46a | 968 | ,@(when (integerp col) |
91fa27cd | 969 | `((,col compilation-column-face nil t))) |
9dc3a46a | 970 | ,@(when (integerp end-col) |
91fa27cd SM |
971 | `((,end-col compilation-column-face nil t))) |
972 | ||
973 | ,@(nthcdr 6 item) | |
974 | (,(or (nth 5 item) 0) | |
975 | (compilation-error-properties ',file ,line ,end-line | |
976 | ,col ,end-col ',(or type 2) | |
977 | ',fmt) | |
978 | append))))) ; for compilation-message-face | |
979 | compilation-error-regexp-alist) | |
980 | ||
981 | compilation-mode-font-lock-keywords))) | |
7837c247 | 982 | |
01f89d11 | 983 | \f |
d3cb357b | 984 | ;;;###autoload |
7837c247 | 985 | (defun compile (command &optional comint) |
55dfd2c4 RS |
986 | "Compile the program including the current buffer. Default: run `make'. |
987 | Runs COMMAND, a shell command, in a separate process asynchronously | |
988 | with output going to the buffer `*compilation*'. | |
d3cb357b | 989 | |
55dfd2c4 RS |
990 | You can then use the command \\[next-error] to find the next error message |
991 | and move to the source code that caused it. | |
992 | ||
8f72171b RS |
993 | If optional second arg COMINT is t the buffer will be in Comint mode with |
994 | `compilation-shell-minor-mode'. | |
995 | ||
08b1edf4 RM |
996 | Interactively, prompts for the command if `compilation-read-command' is |
997 | non-nil; otherwise uses `compile-command'. With prefix arg, always prompts. | |
c39bf546 DP |
998 | Additionally, with universal prefix arg, compilation buffer will be in |
999 | comint mode, i.e. interactive. | |
08b1edf4 | 1000 | |
7d1dad0c | 1001 | To run more than one compilation at once, start one then rename |
c72095b3 | 1002 | the \`*compilation*' buffer to some other name with |
7d1dad0c RS |
1003 | \\[rename-buffer]. Then _switch buffers_ and start the new compilation. |
1004 | It will create a new \`*compilation*' buffer. | |
1005 | ||
1006 | On most systems, termination of the main compilation process | |
1007 | kills its subprocesses. | |
d3cb357b RM |
1008 | |
1009 | The name used for the buffer is actually whatever is returned by | |
1010 | the function in `compilation-buffer-name-function', so you can set that | |
1011 | to a function that generates a unique name." | |
90016295 | 1012 | (interactive |
c39bf546 | 1013 | (list |
20320c65 JL |
1014 | (let ((command (eval compile-command))) |
1015 | (if (or compilation-read-command current-prefix-arg) | |
1016 | (read-from-minibuffer "Compile command: " | |
1017 | command nil nil | |
1018 | (if (equal (car compile-history) command) | |
1019 | '(compile-history . 1) | |
1020 | 'compile-history)) | |
1021 | command)) | |
c39bf546 | 1022 | (consp current-prefix-arg))) |
5b6858da SM |
1023 | (unless (equal command (eval compile-command)) |
1024 | (setq compile-command command)) | |
90016295 | 1025 | (save-some-buffers (not compilation-ask-about-save) nil) |
091525d5 | 1026 | (setq-default compilation-directory default-directory) |
7837c247 | 1027 | (compilation-start command comint)) |
55dfd2c4 | 1028 | |
5b6858da | 1029 | ;; run compile with the default command line |
e60476ca | 1030 | (defun recompile () |
6867356a | 1031 | "Re-compile the program including the current buffer. |
6f5b7627 SM |
1032 | If this is run in a Compilation mode buffer, re-use the arguments from the |
1033 | original use. Otherwise, recompile using `compile-command'." | |
e60476ca RS |
1034 | (interactive) |
1035 | (save-some-buffers (not compilation-ask-about-save) nil) | |
091525d5 | 1036 | (let ((default-directory (or compilation-directory default-directory))) |
7837c247 SM |
1037 | (apply 'compilation-start (or compilation-arguments |
1038 | `(,(eval compile-command)))))) | |
09843b4a | 1039 | |
b5812513 | 1040 | (defcustom compilation-scroll-output nil |
813fb3fe | 1041 | "Non-nil to scroll the *compilation* buffer window as output appears. |
b5812513 | 1042 | |
6f5b7627 | 1043 | Setting it causes the Compilation mode commands to put point at the |
b5812513 | 1044 | end of their output window so that the end of the output is always |
6f5b7627 | 1045 | visible rather than the beginning." |
b5812513 | 1046 | :type 'boolean |
a46fddeb | 1047 | :version "20.3" |
b5812513 DL |
1048 | :group 'compilation) |
1049 | ||
7bdb67b2 | 1050 | |
ae0cc840 | 1051 | (defun compilation-buffer-name (mode-name mode-command name-function) |
7bdb67b2 GM |
1052 | "Return the name of a compilation buffer to use. |
1053 | If NAME-FUNCTION is non-nil, call it with one argument MODE-NAME | |
1054 | to determine the buffer name. | |
1055 | Likewise if `compilation-buffer-name-function' is non-nil. | |
7d1dad0c | 1056 | If current buffer has the major mode MODE-COMMAND, |
7bdb67b2 GM |
1057 | return the name of the current buffer, so that it gets reused. |
1058 | Otherwise, construct a buffer name from MODE-NAME." | |
dc2feacf | 1059 | (cond (name-function |
7bdb67b2 | 1060 | (funcall name-function mode-name)) |
dc2feacf | 1061 | (compilation-buffer-name-function |
7bdb67b2 | 1062 | (funcall compilation-buffer-name-function mode-name)) |
be947101 | 1063 | ((eq mode-command major-mode) |
7bdb67b2 GM |
1064 | (buffer-name)) |
1065 | (t | |
1066 | (concat "*" (downcase mode-name) "*")))) | |
1067 | ||
7837c247 SM |
1068 | ;; This is a rough emulation of the old hack, until the transition to new |
1069 | ;; compile is complete. | |
55dfd2c4 | 1070 | (defun compile-internal (command error-message |
a24770bc RS |
1071 | &optional name-of-mode parser |
1072 | error-regexp-alist name-function | |
1073 | enter-regexp-alist leave-regexp-alist | |
23b0c5fc | 1074 | file-regexp-alist nomessage-regexp-alist |
9ac57479 | 1075 | no-async highlight-regexp local-map) |
7837c247 SM |
1076 | (if parser |
1077 | (error "Compile now works very differently, see `compilation-error-regexp-alist'")) | |
1078 | (let ((compilation-error-regexp-alist | |
1079 | (append file-regexp-alist (or error-regexp-alist | |
1080 | compilation-error-regexp-alist))) | |
1081 | (compilation-error (replace-regexp-in-string "^No more \\(.+\\)s\\.?" | |
1082 | "\\1" error-message))) | |
1083 | (compilation-start command nil name-function highlight-regexp))) | |
1084 | (make-obsolete 'compile-internal 'compilation-start) | |
1085 | ||
a24c45d2 | 1086 | ;;;###autoload |
7837c247 | 1087 | (defun compilation-start (command &optional mode name-function highlight-regexp) |
55dfd2c4 | 1088 | "Run compilation command COMMAND (low level interface). |
489a8034 | 1089 | If COMMAND starts with a cd command, that becomes the `default-directory'. |
9ac57479 KS |
1090 | The rest of the arguments are optional; for them, nil means use the default. |
1091 | ||
7837c247 | 1092 | MODE is the major mode to set in the compilation buffer. Mode |
6f5b7627 | 1093 | may also be t meaning use `compilation-shell-minor-mode' under `comint-mode'. |
7d1dad0c | 1094 | |
5b317d74 | 1095 | If NAME-FUNCTION is non-nil, call it with one argument (the mode name) |
7d1dad0c RS |
1096 | to determine the buffer name. Otherwise, the default is to |
1097 | reuses the current buffer if it has the proper major mode, | |
1098 | else use or create a buffer with name based on the major mode. | |
23b0c5fc | 1099 | |
9ac57479 | 1100 | If HIGHLIGHT-REGEXP is non-nil, `next-error' will temporarily highlight |
6f5b7627 | 1101 | the matching section of the visited source line; the default is to use the |
9ac57479 KS |
1102 | global value of `compilation-highlight-regexp'. |
1103 | ||
646bd331 | 1104 | Returns the compilation buffer created." |
7837c247 | 1105 | (or mode (setq mode 'compilation-mode)) |
489a8034 DP |
1106 | (let* ((name-of-mode |
1107 | (if (eq mode t) | |
1108 | (prog1 "compilation" (require 'comint)) | |
1109 | (replace-regexp-in-string "-mode$" "" (symbol-name mode)))) | |
199143f1 | 1110 | (thisdir default-directory) |
489a8034 | 1111 | outwin outbuf) |
c536bb39 SM |
1112 | (with-current-buffer |
1113 | (setq outbuf | |
1114 | (get-buffer-create | |
be947101 | 1115 | (compilation-buffer-name name-of-mode mode name-function))) |
d3cb357b RM |
1116 | (let ((comp-proc (get-buffer-process (current-buffer)))) |
1117 | (if comp-proc | |
1118 | (if (or (not (eq (process-status comp-proc) 'run)) | |
1119 | (yes-or-no-p | |
bea1d57a JB |
1120 | (format "A %s process is running; kill it? " |
1121 | name-of-mode))) | |
d3cb357b RM |
1122 | (condition-case () |
1123 | (progn | |
1124 | (interrupt-process comp-proc) | |
1125 | (sit-for 1) | |
1126 | (delete-process comp-proc)) | |
1127 | (error nil)) | |
1128 | (error "Cannot have two processes in `%s' at once" | |
7837c247 | 1129 | (buffer-name))))) |
7837c247 | 1130 | (buffer-disable-undo (current-buffer)) |
199143f1 DP |
1131 | ;; first transfer directory from where M-x compile was called |
1132 | (setq default-directory thisdir) | |
091525d5 SM |
1133 | ;; Remember the original dir, so we can use it when we recompile. |
1134 | ;; default-directory' can't be used reliably for that because it may be | |
1135 | ;; affected by the special handling of "cd ...;". | |
1136 | (set (make-local-variable 'compilation-directory) thisdir) | |
d42c87ab RS |
1137 | ;; Make compilation buffer read-only. The filter can still write it. |
1138 | ;; Clear out the compilation buffer. | |
199143f1 DP |
1139 | (let ((inhibit-read-only t) |
1140 | (default-directory thisdir)) | |
813fb3fe SM |
1141 | ;; Then evaluate a cd command if any, but don't perform it yet, else |
1142 | ;; start-command would do it again through the shell: (cd "..") AND | |
1143 | ;; sh -c "cd ..; make" | |
199143f1 DP |
1144 | (cd (if (string-match "^\\s *cd\\(?:\\s +\\(\\S +?\\)\\)?\\s *[;&\n]" command) |
1145 | (if (match-end 1) | |
12221c84 | 1146 | (substitute-env-vars (match-string 1 command)) |
199143f1 DP |
1147 | "~") |
1148 | default-directory)) | |
abed5267 | 1149 | (erase-buffer) |
6d2957c4 RS |
1150 | ;; Select the desired mode. |
1151 | (if (not (eq mode t)) | |
1152 | (funcall mode) | |
1153 | (setq buffer-read-only nil) | |
1154 | (with-no-warnings (comint-mode)) | |
1155 | (compilation-shell-minor-mode)) | |
1156 | (if highlight-regexp | |
1157 | (set (make-local-variable 'compilation-highlight-regexp) | |
1158 | highlight-regexp)) | |
813fb3fe SM |
1159 | (if compilation-auto-jump-to-first-error |
1160 | (set (make-local-variable 'compilation-auto-jump-to-next) t)) | |
6d2957c4 | 1161 | ;; Output a mode setter, for saving and later reloading this buffer. |
d42c87ab | 1162 | (insert "-*- mode: " name-of-mode |
4b025f47 | 1163 | "; default-directory: " (prin1-to-string default-directory) |
a67e5425 | 1164 | " -*-\n" |
314b410b JL |
1165 | (format "%s started at %s\n\n" |
1166 | mode-name | |
1167 | (substring (current-time-string) 0 19)) | |
a67e5425 | 1168 | command "\n") |
abed5267 | 1169 | (setq thisdir default-directory)) |
7837c247 | 1170 | (set-buffer-modified-p nil)) |
7837c247 | 1171 | ;; Pop up the compilation buffer. |
c34dc850 GM |
1172 | ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html |
1173 | (setq outwin (display-buffer outbuf)) | |
7837c247 | 1174 | (with-current-buffer outbuf |
577bf5d2 JL |
1175 | (let ((process-environment |
1176 | (append | |
1177 | compilation-environment | |
1178 | (if (if (boundp 'system-uses-terminfo) ; `if' for compiler warning | |
1179 | system-uses-terminfo) | |
1180 | (list "TERM=dumb" "TERMCAP=" | |
1181 | (format "COLUMNS=%d" (window-width))) | |
1182 | (list "TERM=emacs" | |
1183 | (format "TERMCAP=emacs:co#%d:tc=unknown:" | |
1184 | (window-width)))) | |
1185 | ;; Set the EMACS variable, but | |
1186 | ;; don't override users' setting of $EMACS. | |
4b1aaa8b | 1187 | (unless (getenv "EMACS") |
e725507a CY |
1188 | (list "EMACS=t")) |
1189 | (list "INSIDE_EMACS=t") | |
a9e11582 | 1190 | (copy-sequence process-environment)))) |
577bf5d2 JL |
1191 | (set (make-local-variable 'compilation-arguments) |
1192 | (list command mode name-function highlight-regexp)) | |
1193 | (set (make-local-variable 'revert-buffer-function) | |
1194 | 'compilation-revert-buffer) | |
1195 | (set-window-start outwin (point-min)) | |
2d0a22f8 RS |
1196 | |
1197 | ;; Position point as the user will see it. | |
1198 | (let ((desired-visible-point | |
1199 | ;; Put it at the end if `compilation-scroll-output' is set. | |
1200 | (if compilation-scroll-output | |
1201 | (point-max) | |
1202 | ;; Normally put it at the top. | |
1203 | (point-min)))) | |
1204 | (if (eq outwin (selected-window)) | |
1205 | (goto-char desired-visible-point) | |
1206 | (set-window-point outwin desired-visible-point))) | |
1207 | ||
577bf5d2 JL |
1208 | ;; The setup function is called before compilation-set-window-height |
1209 | ;; so it can set the compilation-window-height buffer locally. | |
1210 | (if compilation-process-setup-function | |
1211 | (funcall compilation-process-setup-function)) | |
1212 | (compilation-set-window-height outwin) | |
1213 | ;; Start the compilation. | |
db8af973 MA |
1214 | (let ((proc |
1215 | (if (eq mode t) | |
1216 | ;; comint uses `start-file-process'. | |
1217 | (get-buffer-process | |
1218 | (with-no-warnings | |
a9e11582 MA |
1219 | (comint-exec |
1220 | outbuf (downcase mode-name) | |
1221 | (if (file-remote-p default-directory) | |
1222 | "/bin/sh" | |
1223 | shell-file-name) | |
c94d5f81 | 1224 | nil `("-c" ,command)))) |
a9e11582 MA |
1225 | (start-file-process-shell-command (downcase mode-name) |
1226 | outbuf command)))) | |
4b29e550 MA |
1227 | ;; Make the buffer's mode line show process state. |
1228 | (setq mode-line-process '(":%s")) | |
1229 | (set-process-sentinel proc 'compilation-sentinel) | |
1230 | (set-process-filter proc 'compilation-filter) | |
b17f53ab MB |
1231 | ;; Use (point-max) here so that output comes in |
1232 | ;; after the initial text, | |
1233 | ;; regardless of where the user sees point. | |
1234 | (set-marker (process-mark proc) (point-max) outbuf) | |
4b29e550 MA |
1235 | (when compilation-disable-input |
1236 | (condition-case nil | |
1237 | (process-send-eof proc) | |
1238 | ;; The process may have exited already. | |
1239 | (error nil))) | |
1240 | (setq compilation-in-progress | |
1241 | (cons proc compilation-in-progress)))) | |
199143f1 DP |
1242 | ;; Now finally cd to where the shell started make/grep/... |
1243 | (setq default-directory thisdir)) | |
7837c247 SM |
1244 | (if (buffer-local-value 'compilation-scroll-output outbuf) |
1245 | (save-selected-window | |
1246 | (select-window outwin) | |
043442b4 KS |
1247 | (goto-char (point-max)))) |
1248 | ;; Make it so the next C-x ` will use this buffer. | |
5d9f0de2 | 1249 | (setq next-error-last-buffer outbuf))) |
55dfd2c4 | 1250 | |
c94b02d6 | 1251 | (defun compilation-set-window-height (window) |
851231e9 | 1252 | "Set the height of WINDOW according to `compilation-window-height'." |
9ac57479 KS |
1253 | (let ((height (buffer-local-value 'compilation-window-height (window-buffer window)))) |
1254 | (and height | |
0dad3dfe | 1255 | (window-full-width-p window) |
9ac57479 KS |
1256 | ;; If window is alone in its frame, aside from a minibuffer, |
1257 | ;; don't change its height. | |
1258 | (not (eq window (frame-root-window (window-frame window)))) | |
b3ef54c5 DP |
1259 | ;; Stef said that doing the saves in this order is safer: |
1260 | (save-excursion | |
9ac57479 | 1261 | (save-selected-window |
b3ef54c5 DP |
1262 | (select-window window) |
1263 | (enlarge-window (- height (window-height)))))))) | |
c94b02d6 | 1264 | |
4282eba1 SM |
1265 | (defvar compilation-menu-map |
1266 | (let ((map (make-sparse-keymap "Errors"))) | |
1267 | (define-key map [stop-subjob] | |
37bf89ab | 1268 | '("Stop Compilation" . kill-compilation)) |
4282eba1 SM |
1269 | (define-key map [compilation-mode-separator2] |
1270 | '("----" . nil)) | |
9ac57479 | 1271 | (define-key map [compilation-first-error] |
4282eba1 | 1272 | '("First Error" . first-error)) |
9ac57479 | 1273 | (define-key map [compilation-previous-error] |
4282eba1 | 1274 | '("Previous Error" . previous-error)) |
9ac57479 | 1275 | (define-key map [compilation-next-error] |
4282eba1 SM |
1276 | '("Next Error" . next-error)) |
1277 | map)) | |
1278 | ||
0b18a8f6 | 1279 | (defvar compilation-minor-mode-map |
55dfd2c4 | 1280 | (let ((map (make-sparse-keymap))) |
9da85ee5 | 1281 | (define-key map [mouse-2] 'compile-goto-error) |
0ac804df | 1282 | (define-key map [follow-link] 'mouse-face) |
55dfd2c4 | 1283 | (define-key map "\C-c\C-c" 'compile-goto-error) |
4e7ce12e | 1284 | (define-key map "\C-m" 'compile-goto-error) |
d3cb357b | 1285 | (define-key map "\C-c\C-k" 'kill-compilation) |
646bd331 RM |
1286 | (define-key map "\M-n" 'compilation-next-error) |
1287 | (define-key map "\M-p" 'compilation-previous-error) | |
d1ed4475 RM |
1288 | (define-key map "\M-{" 'compilation-previous-file) |
1289 | (define-key map "\M-}" 'compilation-next-file) | |
4282eba1 SM |
1290 | ;; Set up the menu-bar |
1291 | (define-key map [menu-bar compilation] | |
1292 | (cons "Errors" compilation-menu-map)) | |
55dfd2c4 | 1293 | map) |
4f6e4ad6 | 1294 | "Keymap for `compilation-minor-mode'.") |
0b18a8f6 | 1295 | |
a24770bc RS |
1296 | (defvar compilation-shell-minor-mode-map |
1297 | (let ((map (make-sparse-keymap))) | |
a24770bc RS |
1298 | (define-key map "\M-\C-m" 'compile-goto-error) |
1299 | (define-key map "\M-\C-n" 'compilation-next-error) | |
1300 | (define-key map "\M-\C-p" 'compilation-previous-error) | |
1301 | (define-key map "\M-{" 'compilation-previous-file) | |
1302 | (define-key map "\M-}" 'compilation-next-file) | |
1303 | ;; Set up the menu-bar | |
4282eba1 SM |
1304 | (define-key map [menu-bar compilation] |
1305 | (cons "Errors" compilation-menu-map)) | |
a24770bc RS |
1306 | map) |
1307 | "Keymap for `compilation-shell-minor-mode'.") | |
1308 | ||
60470fd2 SM |
1309 | (defvar compilation-button-map |
1310 | (let ((map (make-sparse-keymap))) | |
1311 | (define-key map [mouse-2] 'compile-goto-error) | |
0ac804df | 1312 | (define-key map [follow-link] 'mouse-face) |
60470fd2 SM |
1313 | (define-key map "\C-m" 'compile-goto-error) |
1314 | map) | |
1315 | "Keymap for compilation-message buttons.") | |
1316 | (fset 'compilation-button-map compilation-button-map) | |
1317 | ||
0b18a8f6 | 1318 | (defvar compilation-mode-map |
4282eba1 | 1319 | (let ((map (make-sparse-keymap))) |
261b01c6 RS |
1320 | ;; Don't inherit from compilation-minor-mode-map, |
1321 | ;; because that introduces a menu bar item we don't want. | |
1322 | ;; That confuses C-down-mouse-3. | |
5988691b | 1323 | (define-key map [mouse-2] 'compile-goto-error) |
0ac804df | 1324 | (define-key map [follow-link] 'mouse-face) |
5988691b RS |
1325 | (define-key map "\C-c\C-c" 'compile-goto-error) |
1326 | (define-key map "\C-m" 'compile-goto-error) | |
1327 | (define-key map "\C-c\C-k" 'kill-compilation) | |
1328 | (define-key map "\M-n" 'compilation-next-error) | |
1329 | (define-key map "\M-p" 'compilation-previous-error) | |
1330 | (define-key map "\M-{" 'compilation-previous-file) | |
1331 | (define-key map "\M-}" 'compilation-next-file) | |
70fec115 JL |
1332 | (define-key map "\t" 'compilation-next-error) |
1333 | (define-key map [backtab] 'compilation-previous-error) | |
5988691b | 1334 | |
0b18a8f6 RM |
1335 | (define-key map " " 'scroll-up) |
1336 | (define-key map "\^?" 'scroll-down) | |
221206e3 | 1337 | (define-key map "\C-c\C-f" 'next-error-follow-minor-mode) |
9ac57479 | 1338 | |
e60476ca | 1339 | ;; Set up the menu-bar |
5988691b RS |
1340 | (let ((submap (make-sparse-keymap "Compile"))) |
1341 | (define-key map [menu-bar compilation] | |
1342 | (cons "Compile" submap)) | |
1343 | (set-keymap-parent submap compilation-menu-map)) | |
4282eba1 | 1344 | (define-key map [menu-bar compilation compilation-separator2] |
e60476ca | 1345 | '("----" . nil)) |
9ac57479 | 1346 | (define-key map [menu-bar compilation compilation-grep] |
314b410b | 1347 | '("Search Files (grep)..." . grep)) |
9ac57479 | 1348 | (define-key map [menu-bar compilation compilation-recompile] |
e60476ca | 1349 | '("Recompile" . recompile)) |
9ac57479 | 1350 | (define-key map [menu-bar compilation compilation-compile] |
32f4ab17 | 1351 | '("Compile..." . compile)) |
0b18a8f6 RM |
1352 | map) |
1353 | "Keymap for compilation log buffers. | |
4282eba1 | 1354 | `compilation-minor-mode-map' is a parent of this.") |
55dfd2c4 | 1355 | |
0a35bd79 RS |
1356 | (put 'compilation-mode 'mode-class 'special) |
1357 | ||
501cf428 | 1358 | ;;;###autoload |
d42c87ab | 1359 | (defun compilation-mode (&optional name-of-mode) |
55dfd2c4 RS |
1360 | "Major mode for compilation log buffers. |
1361 | \\<compilation-mode-map>To visit the source for a line-numbered error, | |
d3cb357b | 1362 | move point to the error message line and type \\[compile-goto-error]. |
7c163413 RM |
1363 | To kill the compilation, type \\[kill-compilation]. |
1364 | ||
2894bd96 | 1365 | Runs `compilation-mode-hook' with `run-mode-hooks' (which see). |
8ff2ed52 RS |
1366 | |
1367 | \\{compilation-mode-map}" | |
55dfd2c4 | 1368 | (interactive) |
9af0d309 | 1369 | (kill-all-local-variables) |
55dfd2c4 | 1370 | (use-local-map compilation-mode-map) |
0b18a8f6 | 1371 | (setq major-mode 'compilation-mode |
d42c87ab | 1372 | mode-name (or name-of-mode "Compilation")) |
7837c247 SM |
1373 | (set (make-local-variable 'page-delimiter) |
1374 | compilation-page-delimiter) | |
0b18a8f6 | 1375 | (compilation-setup) |
bd8c6db5 | 1376 | (setq buffer-read-only t) |
7837c247 SM |
1377 | (run-mode-hooks 'compilation-mode-hook)) |
1378 | ||
1379 | (defmacro define-compilation-mode (mode name doc &rest body) | |
1380 | "This is like `define-derived-mode' without the PARENT argument. | |
1381 | The parent is always `compilation-mode' and the customizable `compilation-...' | |
bac3a1c9 JL |
1382 | variables are also set from the name of the mode you have chosen, |
1383 | by replacing the first word, e.g `compilation-scroll-output' from | |
1384 | `grep-scroll-output' if that variable exists." | |
7837c247 SM |
1385 | (let ((mode-name (replace-regexp-in-string "-mode\\'" "" (symbol-name mode)))) |
1386 | `(define-derived-mode ,mode compilation-mode ,name | |
1387 | ,doc | |
1388 | ,@(mapcar (lambda (v) | |
1389 | (setq v (cons v | |
1390 | (intern-soft (replace-regexp-in-string | |
1391 | "^compilation" mode-name | |
1392 | (symbol-name v))))) | |
1393 | (and (cdr v) | |
1394 | (or (boundp (cdr v)) | |
1395 | (if (boundp 'byte-compile-bound-variables) | |
1396 | (memq (cdr v) byte-compile-bound-variables))) | |
1397 | `(set (make-local-variable ',(car v)) ,(cdr v)))) | |
1398 | '(compilation-buffer-name-function | |
1399 | compilation-directory-matcher | |
1400 | compilation-error | |
1401 | compilation-error-regexp-alist | |
1402 | compilation-error-regexp-alist-alist | |
1403 | compilation-error-screen-columns | |
1404 | compilation-finish-function | |
1405 | compilation-finish-functions | |
1406 | compilation-first-column | |
1407 | compilation-mode-font-lock-keywords | |
1408 | compilation-page-delimiter | |
1409 | compilation-parse-errors-filename-function | |
1410 | compilation-process-setup-function | |
1411 | compilation-scroll-output | |
1412 | compilation-search-path | |
1413 | compilation-skip-threshold | |
1414 | compilation-window-height)) | |
1415 | ,@body))) | |
0b18a8f6 | 1416 | |
58856335 | 1417 | (defun compilation-revert-buffer (ignore-auto noconfirm) |
9ed2ab9f RS |
1418 | (if buffer-file-name |
1419 | (let (revert-buffer-function) | |
9ac57479 | 1420 | (revert-buffer ignore-auto noconfirm)) |
9ed2ab9f | 1421 | (if (or noconfirm (yes-or-no-p (format "Restart compilation? "))) |
7837c247 SM |
1422 | (apply 'compilation-start compilation-arguments)))) |
1423 | ||
c536bb39 SM |
1424 | (defvar compilation-current-error nil |
1425 | "Marker to the location from where the next error will be found. | |
1426 | The global commands next/previous/first-error/goto-error use this.") | |
51c8ad03 | 1427 | |
9b7b51a2 SM |
1428 | (defvar compilation-messages-start nil |
1429 | "Buffer position of the beginning of the compilation messages. | |
1430 | If nil, use the beginning of buffer.") | |
1431 | ||
7837c247 SM |
1432 | ;; A function name can't be a hook, must be something with a value. |
1433 | (defconst compilation-turn-on-font-lock 'turn-on-font-lock) | |
58856335 | 1434 | |
7837c247 | 1435 | (defun compilation-setup (&optional minor) |
6f5b7627 SM |
1436 | "Prepare the buffer for the compilation parsing commands to work. |
1437 | Optional argument MINOR indicates this is called from | |
1438 | `compilation-minor-mode'." | |
51c8ad03 | 1439 | (make-local-variable 'compilation-current-error) |
9b7b51a2 | 1440 | (make-local-variable 'compilation-messages-start) |
18aac618 | 1441 | (make-local-variable 'compilation-error-screen-columns) |
b3a7f48f | 1442 | (make-local-variable 'overlay-arrow-position) |
8b71e4d1 | 1443 | (set (make-local-variable 'overlay-arrow-string) "") |
6a1cdc5b JL |
1444 | (setq next-error-overlay-arrow-position nil) |
1445 | (add-hook 'kill-buffer-hook | |
1446 | (lambda () (setq next-error-overlay-arrow-position nil)) nil t) | |
9b7b51a2 SM |
1447 | ;; Note that compilation-next-error-function is for interfacing |
1448 | ;; with the next-error function in simple.el, and it's only | |
1449 | ;; coincidentally named similarly to compilation-next-error. | |
1450 | (setq next-error-function 'compilation-next-error-function) | |
00d6fd04 MA |
1451 | (set (make-local-variable 'comint-file-name-prefix) |
1452 | (or (file-remote-p default-directory) "")) | |
7837c247 SM |
1453 | (set (make-local-variable 'font-lock-extra-managed-props) |
1454 | '(directory message help-echo mouse-face debug)) | |
1455 | (set (make-local-variable 'compilation-locs) | |
1456 | (make-hash-table :test 'equal :weakness 'value)) | |
6f5b7627 | 1457 | ;; lazy-lock would never find the message unless it's scrolled to. |
c536bb39 SM |
1458 | ;; jit-lock might fontify some things too late. |
1459 | (set (make-local-variable 'font-lock-support-mode) nil) | |
7837c247 | 1460 | (set (make-local-variable 'font-lock-maximum-size) nil) |
963b2040 CY |
1461 | (if minor |
1462 | (let ((fld font-lock-defaults)) | |
f6164cdd | 1463 | (font-lock-add-keywords nil (compilation-mode-font-lock-keywords)) |
f6164cdd DP |
1464 | (if font-lock-mode |
1465 | (if fld | |
1466 | (font-lock-fontify-buffer) | |
1467 | (font-lock-change-mode) | |
1468 | (turn-on-font-lock)) | |
963b2040 | 1469 | (turn-on-font-lock))) |
49d11c49 | 1470 | (setq font-lock-defaults '(compilation-mode-font-lock-keywords t)) |
963b2040 CY |
1471 | ;; maybe defer font-lock till after derived mode is set up |
1472 | (run-mode-hooks 'compilation-turn-on-font-lock))) | |
0b18a8f6 | 1473 | |
7052680b | 1474 | ;;;###autoload |
4282eba1 | 1475 | (define-minor-mode compilation-shell-minor-mode |
7052680b RS |
1476 | "Toggle compilation shell minor mode. |
1477 | With arg, turn compilation mode on if and only if arg is positive. | |
4282eba1 SM |
1478 | In this minor mode, all the error-parsing commands of the |
1479 | Compilation major mode are available but bound to keys that don't | |
1480 | collide with Shell mode. See `compilation-mode'. | |
7052680b | 1481 | Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'." |
7837c247 | 1482 | nil " Shell-Compile" |
d408fed8 | 1483 | :group 'compilation |
7837c247 SM |
1484 | (if compilation-shell-minor-mode |
1485 | (compilation-setup t) | |
1486 | (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords)) | |
1487 | (font-lock-fontify-buffer))) | |
7052680b | 1488 | |
d6bd8dca | 1489 | ;;;###autoload |
4282eba1 | 1490 | (define-minor-mode compilation-minor-mode |
0b18a8f6 RM |
1491 | "Toggle compilation minor mode. |
1492 | With arg, turn compilation mode on if and only if arg is positive. | |
4282eba1 SM |
1493 | In this minor mode, all the error-parsing commands of the |
1494 | Compilation major mode are available. See `compilation-mode'. | |
fee3f63a | 1495 | Turning the mode on runs the normal hook `compilation-minor-mode-hook'." |
7837c247 | 1496 | nil " Compilation" |
d408fed8 | 1497 | :group 'compilation |
7837c247 SM |
1498 | (if compilation-minor-mode |
1499 | (compilation-setup t) | |
1500 | (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords)) | |
1501 | (font-lock-fontify-buffer))) | |
55dfd2c4 | 1502 | |
fd5e58d7 | 1503 | (defun compilation-handle-exit (process-status exit-status msg) |
f441be5b | 1504 | "Write MSG in the current buffer and hack its `mode-line-process'." |
d42c87ab | 1505 | (let ((inhibit-read-only t) |
fd5e58d7 RM |
1506 | (status (if compilation-exit-message-function |
1507 | (funcall compilation-exit-message-function | |
1508 | process-status exit-status msg) | |
1509 | (cons msg exit-status))) | |
1510 | (omax (point-max)) | |
c96e025a GM |
1511 | (opoint (point)) |
1512 | (cur-buffer (current-buffer))) | |
b3a7f48f | 1513 | ;; Record where we put the message, so we can ignore it later on. |
fd5e58d7 RM |
1514 | (goto-char omax) |
1515 | (insert ?\n mode-name " " (car status)) | |
0eac1faa | 1516 | (if (and (numberp compilation-window-height) |
7837c247 SM |
1517 | (zerop compilation-window-height)) |
1518 | (message "%s" (cdr status))) | |
01c50447 RS |
1519 | (if (bolp) |
1520 | (forward-char -1)) | |
fd5e58d7 | 1521 | (insert " at " (substring (current-time-string) 0 19)) |
01c50447 | 1522 | (goto-char (point-max)) |
47092737 RS |
1523 | ;; Prevent that message from being recognized as a compilation error. |
1524 | (add-text-properties omax (point) | |
1525 | (append '(compilation-handle-exit t) nil)) | |
52f84622 | 1526 | (setq mode-line-process (format ":%s [%s]" process-status (cdr status))) |
fd5e58d7 RM |
1527 | ;; Force mode line redisplay soon. |
1528 | (force-mode-line-update) | |
1529 | (if (and opoint (< opoint omax)) | |
1530 | (goto-char opoint)) | |
a5f1c37e RS |
1531 | (with-no-warnings |
1532 | (if compilation-finish-function | |
c96e025a GM |
1533 | (funcall compilation-finish-function cur-buffer msg))) |
1534 | (run-hook-with-args 'compilation-finish-functions cur-buffer msg))) | |
fd5e58d7 | 1535 | |
55dfd2c4 | 1536 | ;; Called when compilation process changes state. |
55dfd2c4 | 1537 | (defun compilation-sentinel (proc msg) |
d3cb357b | 1538 | "Sentinel for compilation buffers." |
b3a7f48f DP |
1539 | (if (memq (process-status proc) '(exit signal)) |
1540 | (let ((buffer (process-buffer proc))) | |
1541 | (if (null (buffer-name buffer)) | |
1542 | ;; buffer killed | |
1543 | (set-process-buffer proc nil) | |
1544 | (with-current-buffer buffer | |
1545 | ;; Write something in the compilation buffer | |
1546 | ;; and hack its mode line. | |
1547 | (compilation-handle-exit (process-status proc) | |
1548 | (process-exit-status proc) | |
1549 | msg) | |
1550 | ;; Since the buffer and mode line will show that the | |
1551 | ;; process is dead, we can delete it now. Otherwise it | |
1552 | ;; will stay around until M-x list-processes. | |
1553 | (delete-process proc))) | |
1554 | (setq compilation-in-progress (delq proc compilation-in-progress))))) | |
55dfd2c4 | 1555 | |
ad62b7f1 RM |
1556 | (defun compilation-filter (proc string) |
1557 | "Process filter for compilation buffers. | |
4f6e4ad6 | 1558 | Just inserts the text, but uses `insert-before-markers'." |
991c70f8 | 1559 | (if (buffer-name (process-buffer proc)) |
c536bb39 SM |
1560 | (with-current-buffer (process-buffer proc) |
1561 | (let ((inhibit-read-only t)) | |
991c70f8 RS |
1562 | (save-excursion |
1563 | (goto-char (process-mark proc)) | |
1564 | (insert-before-markers string) | |
7837c247 | 1565 | (run-hooks 'compilation-filter-hook)))))) |
b5bb472e | 1566 | |
5d9f0de2 KS |
1567 | ;;; test if a buffer is a compilation buffer, assuming we're in the buffer |
1568 | (defsubst compilation-buffer-internal-p () | |
1569 | "Test if inside a compilation buffer." | |
1570 | (local-variable-p 'compilation-locs)) | |
1571 | ||
1572 | ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p | |
51ba27e7 | 1573 | (defsubst compilation-buffer-p (buffer) |
5d9f0de2 KS |
1574 | "Test if BUFFER is a compilation buffer." |
1575 | (with-current-buffer buffer | |
1576 | (compilation-buffer-internal-p))) | |
7837c247 | 1577 | |
060d5dc1 CY |
1578 | (defmacro compilation-loop (< property-change 1+ error limit) |
1579 | `(let (opt) | |
1580 | (while (,< n 0) | |
1581 | (setq opt pt) | |
1582 | (or (setq pt (,property-change pt 'message)) | |
1583 | ;; Handle the case where where the first error message is | |
1584 | ;; at the start of the buffer, and n < 0. | |
1585 | (if (or (eq (get-text-property ,limit 'message) | |
1586 | (get-text-property opt 'message)) | |
1587 | (eq pt opt)) | |
1588 | (error ,error compilation-error) | |
1589 | (setq pt ,limit))) | |
1590 | ;; prop 'message usually has 2 changes, on and off, so | |
1591 | ;; re-search if off | |
1592 | (or (setq msg (get-text-property pt 'message)) | |
1593 | (if (setq pt (,property-change pt 'message nil ,limit)) | |
1594 | (setq msg (get-text-property pt 'message))) | |
1595 | (error ,error compilation-error)) | |
1596 | (or (< (cadr msg) compilation-skip-threshold) | |
1597 | (if different-file | |
1598 | (eq (prog1 last (setq last (nth 2 (car msg)))) | |
1599 | last)) | |
1600 | (if compilation-skip-visited | |
b84acff6 | 1601 | (nthcdr 5 (car msg))) |
060d5dc1 CY |
1602 | (if compilation-skip-to-next-location |
1603 | (eq (car msg) loc)) | |
1604 | ;; count this message only if none of the above are true | |
1605 | (setq n (,1+ n)))))) | |
7837c247 | 1606 | |
51c8ad03 | 1607 | (defun compilation-next-error (n &optional different-file pt) |
646bd331 | 1608 | "Move point to the next error in the compilation buffer. |
851231e9 DL |
1609 | Prefix arg N says how many error messages to move forwards (or |
1610 | backwards, if negative). | |
646bd331 RM |
1611 | Does NOT find the source line like \\[next-error]." |
1612 | (interactive "p") | |
1613 | (or (compilation-buffer-p (current-buffer)) | |
851231e9 | 1614 | (error "Not in a compilation buffer")) |
51c8ad03 | 1615 | (or pt (setq pt (point))) |
51c8ad03 DP |
1616 | (let* ((msg (get-text-property pt 'message)) |
1617 | (loc (car msg)) | |
1618 | last) | |
7837c247 SM |
1619 | (if (zerop n) |
1620 | (unless (or msg ; find message near here | |
c536bb39 SM |
1621 | (setq msg (get-text-property (max (1- pt) (point-min)) |
1622 | 'message))) | |
7837c247 | 1623 | (setq pt (previous-single-property-change pt 'message nil |
c536bb39 | 1624 | (line-beginning-position))) |
b3a7f48f | 1625 | (unless (setq msg (get-text-property (max (1- pt) (point-min)) 'message)) |
7837c247 | 1626 | (setq pt (next-single-property-change pt 'message nil |
c536bb39 | 1627 | (line-end-position))) |
b3a7f48f DP |
1628 | (or (setq msg (get-text-property pt 'message)) |
1629 | (setq pt (point))))) | |
7837c247 | 1630 | (setq last (nth 2 (car msg))) |
51c8ad03 DP |
1631 | (if (>= n 0) |
1632 | (compilation-loop > next-single-property-change 1- | |
1633 | (if (get-buffer-process (current-buffer)) | |
1634 | "No more %ss yet" | |
060d5dc1 CY |
1635 | "Moved past last %s") |
1636 | (point-max)) | |
c536bb39 SM |
1637 | ;; Don't move "back" to message at or before point. |
1638 | ;; Pass an explicit (point-min) to make sure pt is non-nil. | |
1639 | (setq pt (previous-single-property-change pt 'message nil (point-min))) | |
51c8ad03 | 1640 | (compilation-loop < previous-single-property-change 1+ |
060d5dc1 | 1641 | "Moved back before first %s" (point-min)))) |
7837c247 SM |
1642 | (goto-char pt) |
1643 | (or msg | |
1644 | (error "No %s here" compilation-error)))) | |
646bd331 RM |
1645 | |
1646 | (defun compilation-previous-error (n) | |
1647 | "Move point to the previous error in the compilation buffer. | |
851231e9 DL |
1648 | Prefix arg N says how many error messages to move backwards (or |
1649 | forwards, if negative). | |
7837c247 | 1650 | Does NOT find the source line like \\[previous-error]." |
646bd331 RM |
1651 | (interactive "p") |
1652 | (compilation-next-error (- n))) | |
1653 | ||
b5bb472e | 1654 | (defun compilation-next-file (n) |
24299582 DP |
1655 | "Move point to the next error for a different file than the current one. |
1656 | Prefix arg N says how many files to move forwards (or backwards, if negative)." | |
b5bb472e | 1657 | (interactive "p") |
7837c247 | 1658 | (compilation-next-error n t)) |
b5bb472e RM |
1659 | |
1660 | (defun compilation-previous-file (n) | |
24299582 DP |
1661 | "Move point to the previous error for a different file than the current one. |
1662 | Prefix arg N says how many files to move backwards (or forwards, if negative)." | |
b5bb472e RM |
1663 | (interactive "p") |
1664 | (compilation-next-file (- n))) | |
1665 | ||
55dfd2c4 | 1666 | (defun kill-compilation () |
b765ba64 | 1667 | "Kill the process made by the \\[compile] or \\[grep] commands." |
55dfd2c4 | 1668 | (interactive) |
d3cb357b | 1669 | (let ((buffer (compilation-find-buffer))) |
55dfd2c4 | 1670 | (if (get-buffer-process buffer) |
d3cb357b | 1671 | (interrupt-process (get-buffer-process buffer)) |
bac3a1c9 | 1672 | (error "The %s process is not running" (downcase mode-name))))) |
d3cb357b | 1673 | |
9da85ee5 | 1674 | (defalias 'compile-mouse-goto-error 'compile-goto-error) |
c536bb39 | 1675 | |
9da85ee5 SM |
1676 | (defun compile-goto-error (&optional event) |
1677 | "Visit the source for the error message at point. | |
7837c247 | 1678 | Use this command in a compilation log buffer. Sets the mark at point there." |
9da85ee5 | 1679 | (interactive (list last-input-event)) |
a6cd3f65 | 1680 | (if event (posn-set-point (event-end event))) |
d3cb357b | 1681 | (or (compilation-buffer-p (current-buffer)) |
851231e9 | 1682 | (error "Not in a compilation buffer")) |
b3a7f48f DP |
1683 | (if (get-text-property (point) 'directory) |
1684 | (dired-other-window (car (get-text-property (point) 'directory))) | |
1685 | (push-mark) | |
1686 | (setq compilation-current-error (point)) | |
942c40e3 | 1687 | (next-error-internal))) |
55dfd2c4 | 1688 | |
749354f0 | 1689 | (defun compilation-find-buffer (&optional avoid-current) |
7d1dad0c | 1690 | "Return a compilation buffer. |
0dad3dfe MR |
1691 | If AVOID-CURRENT is nil, and the current buffer is a compilation buffer, |
1692 | return it. If AVOID-CURRENT is non-nil, return the current buffer only | |
1693 | as a last resort." | |
1694 | (if (and (compilation-buffer-internal-p) (not avoid-current)) | |
7d1dad0c RS |
1695 | (current-buffer) |
1696 | (next-error-find-buffer avoid-current 'compilation-buffer-internal-p))) | |
d3cb357b RM |
1697 | |
1698 | ;;;###autoload | |
5d9f0de2 | 1699 | (defun compilation-next-error-function (n &optional reset) |
a5f1c37e RS |
1700 | "Advance to the next error message and visit the file where the error was. |
1701 | This is the value of `next-error-function' in Compilation buffers." | |
7837c247 | 1702 | (interactive "p") |
5d9f0de2 KS |
1703 | (when reset |
1704 | (setq compilation-current-error nil)) | |
7837c247 | 1705 | (let* ((columns compilation-error-screen-columns) ; buffer's local value |
b84acff6 | 1706 | (last 1) timestamp |
51c8ad03 | 1707 | (loc (compilation-next-error (or n 1) nil |
9b7b51a2 SM |
1708 | (or compilation-current-error |
1709 | compilation-messages-start | |
1710 | (point-min)))) | |
7837c247 SM |
1711 | (end-loc (nth 2 loc)) |
1712 | (marker (point-marker))) | |
51c8ad03 | 1713 | (setq compilation-current-error (point-marker) |
b3a7f48f DP |
1714 | overlay-arrow-position |
1715 | (if (bolp) | |
1716 | compilation-current-error | |
9b7b51a2 | 1717 | (copy-marker (line-beginning-position))) |
51c8ad03 | 1718 | loc (car loc)) |
b84acff6 SS |
1719 | ;; If loc contains no marker, no error in that file has been visited. |
1720 | ;; If the marker is invalid the buffer has been killed. | |
1721 | ;; If the file is newer than the timestamp, it has been modified | |
1722 | ;; (`omake -P' polls filesystem for changes and recompiles when needed | |
1723 | ;; in the same process and buffer). | |
1724 | ;; So, recalculate all markers for that file. | |
1725 | (unless (and (nth 3 loc) (marker-buffer (nth 3 loc)) | |
77041513 SM |
1726 | ;; There may be no timestamp info if the loc is a `fake-loc'. |
1727 | ;; So we skip the time-check here, although we should maybe | |
1728 | ;; change `compilation-fake-loc' to add timestamp info. | |
1729 | (or (null (nth 4 loc)) | |
1730 | (equal (nth 4 loc) | |
1731 | (setq timestamp | |
1732 | (with-current-buffer | |
1733 | (marker-buffer (nth 3 loc)) | |
1734 | (visited-file-modtime)))))) | |
c536bb39 | 1735 | (with-current-buffer (compilation-find-file marker (caar (nth 2 loc)) |
7957baea | 1736 | (cadr (car (nth 2 loc)))) |
7837c247 SM |
1737 | (save-restriction |
1738 | (widen) | |
c536bb39 | 1739 | (goto-char (point-min)) |
7837c247 SM |
1740 | ;; Treat file's found lines in forward order, 1 by 1. |
1741 | (dolist (line (reverse (cddr (nth 2 loc)))) | |
1742 | (when (car line) ; else this is a filename w/o a line# | |
1743 | (beginning-of-line (- (car line) last -1)) | |
1744 | (setq last (car line))) | |
1745 | ;; Treat line's found columns and store/update a marker for each. | |
1746 | (dolist (col (cdr line)) | |
1747 | (if (car col) | |
1748 | (if (eq (car col) -1) ; special case for range end | |
1749 | (end-of-line) | |
9c8e6c85 | 1750 | (compilation-move-to-column (car col) columns)) |
7837c247 SM |
1751 | (beginning-of-line) |
1752 | (skip-chars-forward " \t")) | |
eb6fb6e2 | 1753 | (if (nth 3 col) |
7837c247 SM |
1754 | (set-marker (nth 3 col) (point)) |
1755 | (setcdr (nthcdr 2 col) `(,(point-marker))))))))) | |
1756 | (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc)) | |
b84acff6 SS |
1757 | (setcdr (nthcdr 3 loc) (list timestamp)) |
1758 | (setcdr (nthcdr 4 loc) t))) ; Set this one as visited. | |
7837c247 | 1759 | |
e3bef839 SM |
1760 | (defvar compilation-gcpro nil |
1761 | "Internal variable used to keep some values from being GC'd.") | |
1762 | (make-variable-buffer-local 'compilation-gcpro) | |
1763 | ||
eb6fb6e2 DP |
1764 | (defun compilation-fake-loc (marker file &optional line col) |
1765 | "Preassociate MARKER with FILE. | |
dbd97672 | 1766 | FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME). |
eb6fb6e2 DP |
1767 | This is useful when you compile temporary files, but want |
1768 | automatic translation of the messages to the real buffer from | |
1769 | which the temporary file came. This only works if done before a | |
1770 | message about FILE appears! | |
1771 | ||
1772 | Optional args LINE and COL default to 1 and beginning of | |
1773 | indentation respectively. The marker is expected to reflect | |
1774 | this. In the simplest case the marker points to the first line | |
1775 | of the region that was saved to the temp file. | |
1776 | ||
1777 | If you concatenate several regions into the temp file (e.g. a | |
1778 | header with variable assignments and a code region), you must | |
1779 | call this several times, once each for the last line of one | |
1780 | region and the first line of the next region." | |
1781 | (or (consp file) (setq file (list file))) | |
dbd97672 | 1782 | (setq file (compilation-get-file-structure file)) |
e3bef839 | 1783 | ;; Between the current call to compilation-fake-loc and the first occurrence |
77041513 | 1784 | ;; of an error message referring to `file', the data is only kept in the |
e3bef839 SM |
1785 | ;; weak hash-table compilation-locs, so we need to prevent this entry |
1786 | ;; in compilation-locs from being GC'd away. --Stef | |
1787 | (push file compilation-gcpro) | |
eb6fb6e2 DP |
1788 | (let ((loc (compilation-assq (or line 1) (cdr file)))) |
1789 | (setq loc (compilation-assq col loc)) | |
1790 | (if (cdr loc) | |
1791 | (setcdr (cddr loc) (list marker)) | |
dbd97672 | 1792 | (setcdr loc (list line file marker))) |
eb6fb6e2 DP |
1793 | loc)) |
1794 | ||
8b71e4d1 NR |
1795 | (defcustom compilation-context-lines nil |
1796 | "Display this many lines of leading context before the current message. | |
1797 | If nil and the left fringe is displayed, don't scroll the | |
1798 | compilation output window; an arrow in the left fringe points to | |
1799 | the current message. If nil and there is no left fringe, the message | |
1800 | displays at the top of the window; there is no arrow." | |
a3a9c080 | 1801 | :type '(choice integer (const :tag "No window scrolling" nil)) |
f6164cdd | 1802 | :group 'compilation |
bf247b6e | 1803 | :version "22.1") |
7837c247 SM |
1804 | |
1805 | (defsubst compilation-set-window (w mk) | |
6f5b7627 | 1806 | "Align the compilation output window W with marker MK near top." |
a3a9c080 JL |
1807 | (if (integerp compilation-context-lines) |
1808 | (set-window-start w (save-excursion | |
8b71e4d1 NR |
1809 | (goto-char mk) |
1810 | (beginning-of-line | |
1811 | (- 1 compilation-context-lines)) | |
1812 | (point))) | |
3c9e7f42 RS |
1813 | ;; If there is no left fringe. |
1814 | (if (equal (car (window-fringes)) 0) | |
8b71e4d1 NR |
1815 | (set-window-start w (save-excursion |
1816 | (goto-char mk) | |
1817 | (beginning-of-line 1) | |
1818 | (point))))) | |
1819 | (set-window-point w mk)) | |
7837c247 | 1820 | |
0ea50e43 RS |
1821 | (defvar next-error-highlight-timer) |
1822 | ||
7837c247 | 1823 | (defun compilation-goto-locus (msg mk end-mk) |
6f5b7627 | 1824 | "Jump to an error corresponding to MSG at MK. |
9dc3a46a JL |
1825 | All arguments are markers. If END-MK is non-nil, mark is set there |
1826 | and overlay is highlighted between MK and END-MK." | |
eaa3cac5 | 1827 | ;; Show compilation buffer in other window, scrolled to this error. |
e5456e73 SM |
1828 | (let* ((from-compilation-buffer (eq (window-buffer (selected-window)) |
1829 | (marker-buffer msg))) | |
1830 | ;; Use an existing window if it is in a visible frame. | |
7bbbd31f | 1831 | (pre-existing (get-buffer-window (marker-buffer msg) 0)) |
e5456e73 SM |
1832 | (w (if (and from-compilation-buffer pre-existing) |
1833 | ;; Calling display-buffer here may end up (partly) hiding | |
1834 | ;; the error location if the two buffers are in two | |
1835 | ;; different frames. So don't do it if it's not necessary. | |
1836 | pre-existing | |
1837 | (let ((display-buffer-reuse-frames t) | |
1838 | (pop-up-windows t)) | |
1839 | ;; Pop up a window. | |
1840 | (display-buffer (marker-buffer msg))))) | |
7837c247 SM |
1841 | (highlight-regexp (with-current-buffer (marker-buffer msg) |
1842 | ;; also do this while we change buffer | |
1843 | (compilation-set-window w msg) | |
9ac57479 | 1844 | compilation-highlight-regexp))) |
7bbbd31f SM |
1845 | ;; Ideally, the window-size should be passed to `display-buffer' (via |
1846 | ;; something like special-display-buffer) so it's only used when | |
1847 | ;; creating a new window. | |
1848 | (unless pre-existing (compilation-set-window-height w)) | |
9ac57479 | 1849 | |
e5456e73 SM |
1850 | (if from-compilation-buffer |
1851 | ;; If the compilation buffer window was selected, | |
1852 | ;; keep the compilation buffer in this window; | |
1853 | ;; display the source in another window. | |
1854 | (let ((pop-up-windows t)) | |
1855 | (pop-to-buffer (marker-buffer mk) 'other-window)) | |
1856 | (if (window-dedicated-p (selected-window)) | |
1857 | (pop-to-buffer (marker-buffer mk)) | |
1858 | (switch-to-buffer (marker-buffer mk)))) | |
1859 | ;; If narrowing gets in the way of going to the right place, widen. | |
1860 | (unless (eq (goto-char mk) (point)) | |
1861 | (widen) | |
1862 | (goto-char mk)) | |
1863 | (if end-mk | |
1864 | (push-mark end-mk t) | |
1865 | (if mark-active (setq mark-active))) | |
1866 | ;; If hideshow got in the way of | |
1867 | ;; seeing the right place, open permanently. | |
1868 | (dolist (ov (overlays-at (point))) | |
1869 | (when (eq 'hs (overlay-get ov 'invisible)) | |
1870 | (delete-overlay ov) | |
1871 | (goto-char mk))) | |
1872 | ||
9dc3a46a | 1873 | (when highlight-regexp |
073fcaf6 JL |
1874 | (if (timerp next-error-highlight-timer) |
1875 | (cancel-timer next-error-highlight-timer)) | |
9ac57479 | 1876 | (unless compilation-highlight-overlay |
c536bb39 SM |
1877 | (setq compilation-highlight-overlay |
1878 | (make-overlay (point-min) (point-min))) | |
2beb6aa0 | 1879 | (overlay-put compilation-highlight-overlay 'face 'next-error)) |
7837c247 | 1880 | (with-current-buffer (marker-buffer mk) |
9ac57479 | 1881 | (save-excursion |
9dc3a46a | 1882 | (if end-mk (goto-char end-mk) (end-of-line)) |
c536bb39 | 1883 | (let ((end (point))) |
9dc3a46a | 1884 | (if mk (goto-char mk) (beginning-of-line)) |
9ac57479 | 1885 | (if (and (stringp highlight-regexp) |
7837c247 | 1886 | (re-search-forward highlight-regexp end t)) |
9ac57479 KS |
1887 | (progn |
1888 | (goto-char (match-beginning 0)) | |
2beb6aa0 JL |
1889 | (move-overlay compilation-highlight-overlay |
1890 | (match-beginning 0) (match-end 0) | |
1891 | (current-buffer))) | |
1892 | (move-overlay compilation-highlight-overlay | |
1893 | (point) end (current-buffer))) | |
63522e3a RS |
1894 | (if (or (eq next-error-highlight t) |
1895 | (numberp next-error-highlight)) | |
1896 | ;; We want highlighting: delete overlay on next input. | |
1897 | (add-hook 'pre-command-hook | |
1898 | 'compilation-goto-locus-delete-o) | |
1899 | ;; We don't want highlighting: delete overlay now. | |
1900 | (delete-overlay compilation-highlight-overlay)) | |
1901 | ;; We want highlighting for a limited time: | |
1902 | ;; set up a timer to delete it. | |
1903 | (when (numberp next-error-highlight) | |
1904 | (setq next-error-highlight-timer | |
1905 | (run-at-time next-error-highlight nil | |
1906 | 'compilation-goto-locus-delete-o))))))) | |
2beb6aa0 | 1907 | (when (and (eq next-error-highlight 'fringe-arrow)) |
63522e3a | 1908 | ;; We want a fringe arrow (instead of highlighting). |
6a1cdc5b JL |
1909 | (setq next-error-overlay-arrow-position |
1910 | (copy-marker (line-beginning-position)))))) | |
1911 | ||
63522e3a RS |
1912 | (defun compilation-goto-locus-delete-o () |
1913 | (delete-overlay compilation-highlight-overlay) | |
1914 | ;; Get rid of timer and hook that would try to do this again. | |
1915 | (if (timerp next-error-highlight-timer) | |
1916 | (cancel-timer next-error-highlight-timer)) | |
1917 | (remove-hook 'pre-command-hook | |
1918 | 'compilation-goto-locus-delete-o)) | |
eaa3cac5 | 1919 | \f |
7957baea | 1920 | (defun compilation-find-file (marker filename directory &rest formats) |
851231e9 | 1921 | "Find a buffer for file FILENAME. |
ffb4b7a1 SM |
1922 | Search the directories in `compilation-search-path'. |
1923 | A nil in `compilation-search-path' means to try the | |
7957baea | 1924 | \"current\" directory, which is passed in DIRECTORY. |
f441be5b JB |
1925 | If DIRECTORY is relative, it is combined with `default-directory'. |
1926 | If DIRECTORY is nil, that means use `default-directory'. | |
851231e9 DL |
1927 | If FILENAME is not found at all, ask the user where to find it. |
1928 | Pop up the buffer containing MARKER and scroll to MARKER if we ask the user." | |
20c1daec | 1929 | (or formats (setq formats '("%s"))) |
b8fa0ffd SM |
1930 | (let ((dirs compilation-search-path) |
1931 | (spec-dir (if directory | |
1932 | (expand-file-name directory) | |
1933 | default-directory)) | |
1934 | buffer thisdir fmts name) | |
1935 | (if (file-name-absolute-p filename) | |
1936 | ;; The file name is absolute. Use its explicit directory as | |
1937 | ;; the first in the search path, and strip it from FILENAME. | |
1938 | (setq filename (abbreviate-file-name (expand-file-name filename)) | |
1939 | dirs (cons (file-name-directory filename) dirs) | |
1940 | filename (file-name-nondirectory filename))) | |
1941 | ;; Now search the path. | |
1942 | (while (and dirs (null buffer)) | |
1943 | (setq thisdir (or (car dirs) spec-dir) | |
1944 | fmts formats) | |
1945 | ;; For each directory, try each format string. | |
1946 | (while (and fmts (null buffer)) | |
1947 | (setq name (expand-file-name (format (car fmts) filename) thisdir) | |
1948 | buffer (and (file-exists-p name) | |
1949 | (find-file-noselect name)) | |
1950 | fmts (cdr fmts))) | |
1951 | (setq dirs (cdr dirs))) | |
f65b9df2 SM |
1952 | (while (null buffer) ;Repeat until the user selects an existing file. |
1953 | ;; The file doesn't exist. Ask the user where to find it. | |
1954 | (save-excursion ;This save-excursion is probably not right. | |
1955 | (let ((pop-up-windows t)) | |
1956 | (compilation-set-window (display-buffer (marker-buffer marker)) | |
1957 | marker) | |
1958 | (let* ((name (read-file-name | |
1959 | (format "Find this %s in (default %s): " | |
1960 | compilation-error filename) | |
44038dc8 SM |
1961 | spec-dir filename t nil |
1962 | ;; The predicate below is fine when called from | |
1963 | ;; minibuffer-complete-and-exit, but it's too | |
1964 | ;; restrictive otherwise, since it also prevents the | |
1965 | ;; user from completing "fo" to "foo/" when she | |
1966 | ;; wants to enter "foo/bar". | |
f441be5b | 1967 | ;; |
44038dc8 SM |
1968 | ;; Try to make sure the user can only select |
1969 | ;; a valid answer. This predicate may be ignored, | |
1970 | ;; tho, so we still have to double-check afterwards. | |
1971 | ;; TODO: We should probably fix read-file-name so | |
1972 | ;; that it never ignores this predicate, even when | |
1973 | ;; using popup dialog boxes. | |
1974 | ;; (lambda (name) | |
1975 | ;; (if (file-directory-p name) | |
1976 | ;; (setq name (expand-file-name filename name))) | |
1977 | ;; (file-exists-p name)) | |
1978 | )) | |
f65b9df2 SM |
1979 | (origname name)) |
1980 | (cond | |
1981 | ((not (file-exists-p name)) | |
1982 | (message "Cannot find file `%s'" name) | |
1983 | (ding) (sit-for 2)) | |
1984 | ((and (file-directory-p name) | |
1985 | (not (file-exists-p | |
1986 | (setq name (expand-file-name filename name))))) | |
1987 | (message "No `%s' in directory %s" filename origname) | |
1988 | (ding) (sit-for 2)) | |
1989 | (t | |
1990 | (setq buffer (find-file-noselect name)))))))) | |
b8fa0ffd | 1991 | ;; Make intangible overlays tangible. |
f65b9df2 SM |
1992 | ;; This is weird: it's not even clear which is the current buffer, |
1993 | ;; so the code below can't be expected to DTRT here. -- Stef | |
1994 | (dolist (ov (overlays-in (point-min) (point-max))) | |
1995 | (when (overlay-get ov 'intangible) | |
1996 | (overlay-put ov 'intangible nil))) | |
b8fa0ffd | 1997 | buffer)) |
721cfafe | 1998 | |
dbd97672 DP |
1999 | (defun compilation-get-file-structure (file &optional fmt) |
2000 | "Retrieve FILE's file-structure or create a new one. | |
7957baea RS |
2001 | FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME). |
2002 | In the former case, FILENAME may be relative or absolute. | |
dbd97672 | 2003 | |
7957baea | 2004 | The file-structure looks like this: |
34a9bf20 | 2005 | (list (list FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)" |
dbd97672 DP |
2006 | (or (gethash file compilation-locs) |
2007 | ;; File was not previously encountered, at least not in the form passed. | |
2008 | ;; Let's normalize it and look again. | |
2009 | (let ((filename (car file)) | |
7957baea RS |
2010 | ;; Get the specified directory from FILE. |
2011 | (spec-directory (if (cdr file) | |
2012 | (file-truename (cdr file))))) | |
dbd97672 DP |
2013 | |
2014 | ;; Check for a comint-file-name-prefix and prepend it if appropriate. | |
2015 | ;; (This is very useful for compilation-minor-mode in an rlogin-mode | |
2016 | ;; buffer.) | |
7957baea RS |
2017 | (when (and (boundp 'comint-file-name-prefix) |
2018 | (not (equal comint-file-name-prefix ""))) | |
2019 | (if (file-name-absolute-p filename) | |
2020 | (setq filename | |
2021 | (concat comint-file-name-prefix filename)) | |
2022 | (if spec-directory | |
2023 | (setq spec-directory | |
2024 | (file-truename | |
2025 | (concat comint-file-name-prefix spec-directory)))))) | |
dbd97672 DP |
2026 | |
2027 | ;; If compilation-parse-errors-filename-function is | |
2028 | ;; defined, use it to process the filename. | |
2029 | (when compilation-parse-errors-filename-function | |
2030 | (setq filename | |
2031 | (funcall compilation-parse-errors-filename-function | |
2032 | filename))) | |
2033 | ||
2034 | ;; Some compilers (e.g. Sun's java compiler, reportedly) produce bogus | |
2035 | ;; file names like "./bar//foo.c" for file "bar/foo.c"; | |
2036 | ;; expand-file-name will collapse these into "/foo.c" and fail to find | |
2037 | ;; the appropriate file. So we look for doubled slashes in the file | |
2038 | ;; name and fix them. | |
2039 | (setq filename (command-line-normalize-file-name filename)) | |
2040 | ||
dbd97672 DP |
2041 | ;; Store it for the possibly unnormalized name |
2042 | (puthash file | |
2043 | ;; Retrieve or create file-structure for normalized name | |
e68b1841 GM |
2044 | ;; The gethash used to not use spec-directory, but |
2045 | ;; this leads to errors when files in different | |
2046 | ;; directories have the same name: | |
2047 | ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00463.html | |
2048 | (or (gethash (cons filename spec-directory) compilation-locs) | |
34a9bf20 | 2049 | (puthash (cons filename spec-directory) |
7957baea RS |
2050 | (list (list filename spec-directory) fmt) |
2051 | compilation-locs)) | |
dbd97672 | 2052 | compilation-locs)))) |
51501e54 | 2053 | |
7837c247 | 2054 | (add-to-list 'debug-ignored-errors "^No more [-a-z ]+s yet$") |
f1ed9461 | 2055 | |
c536bb39 SM |
2056 | ;;; Compatibility with the old compile.el. |
2057 | ||
2058 | (defun compile-buffer-substring (n) (if n (match-string n))) | |
2059 | ||
2060 | (defun compilation-compat-error-properties (err) | |
6f5b7627 | 2061 | "Map old-style error ERR to new-style message." |
efb0e677 SM |
2062 | ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or |
2063 | ;; (MARKER . MARKER). | |
2064 | (let ((dst (cdr err))) | |
2065 | (if (markerp dst) | |
2066 | ;; Must start with a face, for font-lock. | |
2067 | `(face nil | |
2068 | message ,(list (list nil nil nil dst) 2) | |
2069 | help-echo "mouse-2: visit the source location" | |
2070 | keymap compilation-button-map | |
2071 | mouse-face highlight) | |
2072 | ;; Too difficult to do it by hand: dispatch to the normal code. | |
2073 | (let* ((file (pop dst)) | |
2074 | (line (pop dst)) | |
2075 | (col (pop dst)) | |
2076 | (filename (pop file)) | |
2077 | (dirname (pop file)) | |
2078 | (fmt (pop file))) | |
2079 | (compilation-internal-error-properties | |
2080 | (cons filename dirname) line nil col nil 2 fmt))))) | |
c536bb39 SM |
2081 | |
2082 | (defun compilation-compat-parse-errors (limit) | |
2083 | (when compilation-parse-errors-function | |
2084 | ;; FIXME: We should remove the rest of the compilation keywords | |
2085 | ;; but we can't do that from here because font-lock is using | |
2086 | ;; the value right now. --stef | |
2087 | (save-excursion | |
2088 | (setq compilation-error-list nil) | |
2089 | ;; Reset compilation-parsing-end each time because font-lock | |
2090 | ;; might force us the re-parse many times (typically because | |
2091 | ;; some code adds some text-property to the output that we | |
2092 | ;; already parsed). You might say "why reparse", well: | |
2093 | ;; because font-lock has just removed the `message' property so | |
2094 | ;; have to do it all over again. | |
2095 | (if compilation-parsing-end | |
2096 | (set-marker compilation-parsing-end (point)) | |
2097 | (setq compilation-parsing-end (point-marker))) | |
2098 | (condition-case nil | |
2099 | ;; Ignore any error: we're calling this function earlier than | |
2100 | ;; in the old compile.el so things might not all be setup yet. | |
2101 | (funcall compilation-parse-errors-function limit nil) | |
2102 | (error nil)) | |
2103 | (dolist (err (if (listp compilation-error-list) compilation-error-list)) | |
2104 | (let* ((src (car err)) | |
2105 | (dst (cdr err)) | |
2106 | (loc (cond ((markerp dst) (list nil nil nil dst)) | |
2107 | ((consp dst) | |
2108 | (list (nth 2 dst) (nth 1 dst) | |
2109 | (cons (cdar dst) (caar dst))))))) | |
2110 | (when loc | |
2111 | (goto-char src) | |
2112 | ;; (put-text-property src (line-end-position) 'font-lock-face 'font-lock-warning-face) | |
2113 | (put-text-property src (line-end-position) | |
2114 | 'message (list loc 2))))))) | |
2115 | (goto-char limit) | |
2116 | nil) | |
2117 | ||
9b7b51a2 | 2118 | ;; Beware: this is not only compatiblity code. New code stil uses it. --Stef |
c536bb39 SM |
2119 | (defun compilation-forget-errors () |
2120 | ;; In case we hit the same file/line specs, we want to recompute a new | |
2121 | ;; marker for them, so flush our cache. | |
b3a7f48f | 2122 | (setq compilation-locs (make-hash-table :test 'equal :weakness 'value)) |
e3bef839 | 2123 | (setq compilation-gcpro nil) |
c536bb39 SM |
2124 | ;; FIXME: the old code reset the directory-stack, so maybe we should |
2125 | ;; put a `directory change' marker of some sort, but where? -stef | |
b3a7f48f | 2126 | ;; |
c536bb39 SM |
2127 | ;; FIXME: The old code moved compilation-current-error (which was |
2128 | ;; virtually represented by a mix of compilation-parsing-end and | |
2129 | ;; compilation-error-list) to point-min, but that was only meaningful for | |
2130 | ;; the internal uses of compilation-forget-errors: all calls from external | |
2131 | ;; packages seem to be followed by a move of compilation-parsing-end to | |
b956d64f | 2132 | ;; something equivalent to point-max. So we heuristically move |
c536bb39 | 2133 | ;; compilation-current-error to point-max (since the external package |
b956d64f | 2134 | ;; won't know that it should do it). --Stef |
9b7b51a2 SM |
2135 | (setq compilation-current-error nil) |
2136 | (let* ((proc (get-buffer-process (current-buffer))) | |
2137 | (mark (if proc (process-mark proc))) | |
2138 | (pos (or mark (point-max)))) | |
2139 | (setq compilation-messages-start | |
2140 | ;; In the future, ignore the text already present in the buffer. | |
2141 | ;; Since many process filter functions insert before markers, | |
2142 | ;; we need to put ours just before the insertion point rather | |
2143 | ;; than at the insertion point. If that's not possible, then | |
2144 | ;; don't use a marker. --Stef | |
b956d64f SM |
2145 | (if (> pos (point-min)) (copy-marker (1- pos)) pos))) |
2146 | ;; Again, since this command is used in buffers that contain several | |
2147 | ;; compilations, to set the beginning of "this compilation", it's a good | |
2148 | ;; place to reset compilation-auto-jump-to-next. | |
2149 | (set (make-local-variable 'compilation-auto-jump-to-next) | |
2150 | compilation-auto-jump-to-first-error)) | |
c536bb39 | 2151 | |
0c9a01ff MY |
2152 | ;;;###autoload |
2153 | (add-to-list 'auto-mode-alist '("\\.gcov\\'" . compilation-mode)) | |
2154 | ||
4746118a | 2155 | (provide 'compile) |
fad160d5 | 2156 | |
822001db | 2157 | ;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c |
fad160d5 | 2158 | ;;; compile.el ends here |