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