Mercurial > emacs
annotate lisp/progmodes/compile.el @ 2472:f911936cec3f
(compilation-filter): New function.
(compile-internal): Make it the process's filter.
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Wed, 07 Apr 1993 18:34:17 +0000 |
parents | c5e43751f9aa |
children | 57e371b49128 |
rev | line source |
---|---|
727 | 1 ;;; compile.el --- run compiler as inferior of Emacs, parse error messages. |
712
16823e891d56
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
621
diff
changeset
|
2 |
2460
7dad88221a45
(compilation-error-regexp-alist): Changed MIPS RISC CC regexp (last one) to
Roland McGrath <roland@gnu.org>
parents:
2337
diff
changeset
|
3 ;; Copyright (C) 1985, 86, 87, 93 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
4 |
804 | 5 ;; Author: Roland McGrath <roland@prep.ai.mit.edu> |
795
c693d56ef36d
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
6 ;; Maintainer: FSF |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1846
diff
changeset
|
7 ;; Keywords: tools, processes |
795
c693d56ef36d
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
8 |
71 | 9 ;; This file is part of GNU Emacs. |
10 | |
804 | 11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
71 | 15 |
804 | 16 ;; GNU Emacs is distributed in the hope that it will be useful, |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
71 | 24 |
2337
2ee64176069c
Fix library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
25 ;;; Commentary: |
2ee64176069c
Fix library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
26 |
2ee64176069c
Fix library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
27 ;; This package provides the compile and grep facilities documented in |
2ee64176069c
Fix library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
28 ;; the Emacs user's manual. |
2ee64176069c
Fix library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
29 |
795
c693d56ef36d
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
30 ;;; Code: |
c693d56ef36d
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
31 |
569 | 32 ;;;###autoload |
33 (defvar compilation-mode-hook nil | |
34 "*List of hook functions run by compilation-mode (see `run-hooks').") | |
35 | |
36 ;;;###autoload | |
418 | 37 (defconst compilation-window-height nil |
38 "*Number of lines in a compilation window. If nil, use Emacs default.") | |
39 | |
71 | 40 (defvar compilation-error-list nil |
41 "List of error message descriptors for visiting erring functions. | |
894 | 42 Each error descriptor is a cons (or nil). Its car is a marker pointing to |
43 an error message. If its cdr is a marker, it points to the text of the | |
44 line the message is about. If its cdr is a cons, that cons's car is a cons | |
45 \(DIRECTORY . FILE\), specifying the file the message is about, and its cdr | |
46 is the number of the line the message is about. Or its cdr may be nil if | |
47 that error is not interesting. | |
418 | 48 |
49 The value may be t instead of a list; this means that the buffer of | |
50 error messages should be reparsed the next time the list of errors is wanted.") | |
71 | 51 |
52 (defvar compilation-old-error-list nil | |
53 "Value of `compilation-error-list' after errors were parsed.") | |
54 | |
418 | 55 (defvar compilation-parse-errors-function 'compilation-parse-errors |
885 | 56 "Function to call to parse error messages from a compilation. |
907 | 57 It takes args LIMIT-SEARCH and FIND-AT-LEAST. |
58 If LIMIT-SEARCH is non-nil, don't bother parsing past that location. | |
59 If FIND-AT-LEAST is non-nil, don't bother parsing after finding that | |
60 many new erros. | |
418 | 61 It should read in the source files which have errors and set |
62 `compilation-error-list' to a list with an element for each error message | |
63 found. See that variable for more info.") | |
71 | 64 |
474 | 65 ;;;###autoload |
418 | 66 (defvar compilation-buffer-name-function nil |
1133 | 67 "Function to compute the name of a compilation buffer. |
68 The function receives one argument, the name of the major mode of the | |
69 compilation buffer. It should return a string. | |
70 nil means compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.") | |
71 | 71 |
474 | 72 ;;;###autoload |
418 | 73 (defvar compilation-finish-function nil |
474 | 74 "*Function to call when a compilation process finishes. |
418 | 75 It is called with two arguments: the compilation buffer, and a string |
76 describing how the process finished.") | |
77 | |
78 (defvar compilation-last-buffer nil | |
1133 | 79 "The most recent compilation buffer. |
80 A buffer becomes most recent when its compilation is started | |
81 or when it is used with \\[next-error] or \\[compile-goto-error].") | |
71 | 82 |
740 | 83 (defvar compilation-in-progress nil |
84 "List of compilation processes now running.") | |
85 (or (assq 'compilation-in-progress minor-mode-alist) | |
86 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling") | |
87 minor-mode-alist))) | |
88 | |
71 | 89 (defvar compilation-parsing-end nil |
418 | 90 "Position of end of buffer when last error messages were parsed.") |
71 | 91 |
418 | 92 (defvar compilation-error-message "No more errors" |
1133 | 93 "Message to print when no more matches are found.") |
94 | |
95 (defvar compilation-num-errors-found) | |
71 | 96 |
418 | 97 (defvar compilation-error-regexp-alist |
98 '( | |
1072 | 99 ;; NOTE! This first one is repeated in grep-regexp-alist, below. |
2461
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
100 |
418 | 101 ;; 4.3BSD grep, cc, lint pass 1: |
2461
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
102 ;; /usr/src/foo/foo.c(8): warning: w may be used before set |
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
103 ;; or GNU utilities: |
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
104 ;; foo.c:8: error message |
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
105 ;; or HP-UX 7.0 fc: |
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
106 ;; foo.f :16 some horrible error message |
1702
817bd71e0e72
* compile.el (compilation-error-regexp-alist): Tightened up
Jim Blandy <jimb@redhat.com>
parents:
1554
diff
changeset
|
107 ;; |
817bd71e0e72
* compile.el (compilation-error-regexp-alist): Tightened up
Jim Blandy <jimb@redhat.com>
parents:
1554
diff
changeset
|
108 ;; We'll insist that the number be followed by a colon or closing |
817bd71e0e72
* compile.el (compilation-error-regexp-alist): Tightened up
Jim Blandy <jimb@redhat.com>
parents:
1554
diff
changeset
|
109 ;; paren, because otherwise this matches just about anything |
817bd71e0e72
* compile.el (compilation-error-regexp-alist): Tightened up
Jim Blandy <jimb@redhat.com>
parents:
1554
diff
changeset
|
110 ;; containing a number with spaces around it. |
2461
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
111 ("^\\([^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2) |
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
112 |
418 | 113 ;; 4.3BSD lint pass 2 |
2461
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
114 ;; strcmp: variable # of args. llib-lc(359) :: /usr/src/foo/foo.c(8) |
727 | 115 ("[ \t:]+\\([^:( \t\n]+\\)[ \t]*[:(]*(+[ \t]*\\([0-9]+\\))[:) \t]*$" 1 2) |
2461
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
116 |
418 | 117 ;; 4.3BSD lint pass 3 |
2461
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
118 ;; bloofle defined( /users/wolfgang/foo.c(4) ), but never used |
727 | 119 ;; This used to be |
120 ;; ("[ \t(]+\\([^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]+" 1 2) | |
121 ;; which is regexp Impressionism - it matches almost anything! | |
122 ("([ \t]*\\([^:( \t\n]+\\)[ \t]*[:(][ \t]*\\([0-9]+\\))" 1 2) | |
2461
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
123 |
418 | 124 ;; Line 45 of "foo.c": bloofel undefined (who does this?) |
727 | 125 ("^[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+of[ \t]+\"\\([^\"\n]+\\)\":" 2 1) |
2461
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
126 |
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
127 ;; Apollo cc, 4.3BSD fc: |
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
128 ;; "foo.f", line 3: Error: syntax error near end of statement |
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
129 ;; or MIPS RISC CC - the one distributed with Ultrix: |
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
130 ;; ccom: Error: foo.c, line 2: syntax error |
2471
c5e43751f9aa
(compilation-error-regexp-alist): Fixed MIPS CC regexp to match file
Roland McGrath <roland@gnu.org>
parents:
2461
diff
changeset
|
131 ("\\b\"?\\([^,\" \n\t]+\\)\"?, line \\([0-9]+\\):" 1 2) |
2461
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
132 |
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
133 ;; IBM AIX PS/2 C version 1.1: |
1ecb75748794
(compilation-error-regexp-alist): Merged HP-UX 7.0 fc regexp with the
Roland McGrath <roland@gnu.org>
parents:
2460
diff
changeset
|
134 ;; ****** Error number 140 in line 8 of file errors.c ****** |
727 | 135 ("in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1) |
418 | 136 ;; IBM AIX lint is too painful to do right this way. File name |
137 ;; prefixes entire sections rather than being on each line. | |
1702
817bd71e0e72
* compile.el (compilation-error-regexp-alist): Tightened up
Jim Blandy <jimb@redhat.com>
parents:
1554
diff
changeset
|
138 |
418 | 139 ) |
1133 | 140 "Alist that specifies how to match errors in compiler output. |
141 Each element has the form (REGEXP FILE-IDX LINE-IDX). | |
142 If REGEXP matches, the FILE-IDX'th subexpression gives the file | |
418 | 143 name, and the LINE-IDX'th subexpression gives the line number.") |
71 | 144 |
1072 | 145 (defvar grep-regexp-alist |
146 '(("^\\([^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2)) | |
147 "Regexp used to match grep hits. See `compilation-error-regexp-alist'.") | |
148 | |
569 | 149 ;;;###autoload |
418 | 150 (defvar compilation-search-path '(nil) |
569 | 151 "*List of directories to search for source files named in error messages. |
418 | 152 Elements should be directory names, not file names of directories. |
153 nil as an element means to try the default directory.") | |
71 | 154 |
155 (defvar compile-command "make -k " | |
156 "Last shell command used to do a compilation; default for next compilation. | |
157 | |
158 Sometimes it is useful for files to supply local values for this variable. | |
159 You might also use mode hooks to specify it in certain modes, like this: | |
160 | |
161 (setq c-mode-hook | |
162 '(lambda () (or (file-exists-p \"makefile\") (file-exists-p \"Makefile\") | |
163 (progn (make-local-variable 'compile-command) | |
164 (setq compile-command | |
165 (concat \"make -k \" | |
166 buffer-file-name))))))") | |
167 | |
418 | 168 (defconst compilation-enter-directory-regexp |
727 | 169 ": Entering directory `\\(.*\\)'$" |
1133 | 170 "Regular expression matching lines that indicate a new current directory. |
171 This must contain one \\(, \\) pair around the directory name. | |
418 | 172 |
173 The default value matches lines printed by the `-w' option of GNU Make.") | |
71 | 174 |
418 | 175 (defconst compilation-leave-directory-regexp |
727 | 176 ": Leaving directory `\\(.*\\)'$" |
1133 | 177 "Regular expression matching lines that indicate restoring current directory. |
178 This may contain one \\(, \\) pair around the name of the directory | |
179 being moved from. If it does not, the last directory entered \(by a | |
180 line matching `compilation-enter-directory-regexp'\) is assumed. | |
418 | 181 |
182 The default value matches lines printed by the `-w' option of GNU Make.") | |
183 | |
184 (defvar compilation-directory-stack nil | |
1133 | 185 "Stack of previous directories for `compilation-leave-directory-regexp'. |
186 The head element is the directory the compilation was started in.") | |
418 | 187 |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
188 ;; History of compile commands. |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
189 (defvar compile-history nil) |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
190 ;; History of grep commands. |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
191 (defvar grep-history nil) |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
192 |
418 | 193 ;;;###autoload |
71 | 194 (defun compile (command) |
195 "Compile the program including the current buffer. Default: run `make'. | |
196 Runs COMMAND, a shell command, in a separate process asynchronously | |
197 with output going to the buffer `*compilation*'. | |
418 | 198 |
71 | 199 You can then use the command \\[next-error] to find the next error message |
200 and move to the source code that caused it. | |
201 | |
202 To run more than one compilation at once, start one and rename the | |
418 | 203 \`*compilation*' buffer to some other name with \\[rename-buffer]. |
204 Then start the next one. | |
205 | |
206 The name used for the buffer is actually whatever is returned by | |
207 the function in `compilation-buffer-name-function', so you can set that | |
208 to a function that generates a unique name." | |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
209 (interactive (list (read-from-minibuffer "Compile command: " |
865
637812e90946
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
864
diff
changeset
|
210 compile-command nil nil |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
211 '(compile-history . 1)))) |
71 | 212 (setq compile-command command) |
213 (save-some-buffers nil nil) | |
418 | 214 (compile-internal compile-command "No more errors")) |
71 | 215 |
418 | 216 ;;;###autoload |
71 | 217 (defun grep (command-args) |
218 "Run grep, with user-specified args, and collect output in a buffer. | |
219 While grep runs asynchronously, you can use the \\[next-error] command | |
418 | 220 to find the text that grep hits refer to. |
221 | |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
222 This command uses a special history list for its arguments, so you can |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
223 easily repeat a grep command." |
71 | 224 (interactive |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
225 (list (read-from-minibuffer "Run grep (like this): " |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
226 "grep -n " nil nil 'grep-history))) |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
227 (compile-internal (concat command-args " /dev/null") |
1072 | 228 "No more grep hits" "grep" |
229 ;; Give it a simpler regexp to match. | |
230 nil grep-regexp-alist)) | |
71 | 231 |
232 (defun compile-internal (command error-message | |
418 | 233 &optional name-of-mode parser regexp-alist |
234 name-function) | |
71 | 235 "Run compilation command COMMAND (low level interface). |
236 ERROR-MESSAGE is a string to print if the user asks to see another error | |
237 and there are no more errors. Third argument NAME-OF-MODE is the name | |
418 | 238 to display as the major mode in the compilation buffer. |
71 | 239 |
418 | 240 Fourth arg PARSER is the error parser function (nil means the default). Fifth |
241 arg REGEXP-ALIST is the error message regexp alist to use (nil means the | |
242 default). Sixth arg NAME-FUNCTION is a function called to name the buffer (nil | |
243 means the default). The defaults for these variables are the global values of | |
244 \`compilation-parse-errors-function', `compilation-error-regexp-alist', and | |
894 | 245 \`compilation-buffer-name-function', respectively. |
246 | |
247 Returns the compilation buffer created." | |
418 | 248 (let (outbuf) |
71 | 249 (save-excursion |
418 | 250 (or name-of-mode |
251 (setq name-of-mode "Compilation")) | |
252 (setq outbuf | |
253 (get-buffer-create | |
254 (funcall (or name-function compilation-buffer-name-function | |
255 (function (lambda (mode) | |
256 (concat "*" (downcase mode) "*")))) | |
257 name-of-mode))) | |
71 | 258 (set-buffer outbuf) |
418 | 259 (let ((comp-proc (get-buffer-process (current-buffer)))) |
260 (if comp-proc | |
261 (if (or (not (eq (process-status comp-proc) 'run)) | |
262 (yes-or-no-p | |
1554
5af75a1a9a24
* compile.el (compile-internal): Use NAME-OF-MODE in the prompt
Jim Blandy <jimb@redhat.com>
parents:
1294
diff
changeset
|
263 (format "A %s process is running; kill it? " |
5af75a1a9a24
* compile.el (compile-internal): Use NAME-OF-MODE in the prompt
Jim Blandy <jimb@redhat.com>
parents:
1294
diff
changeset
|
264 name-of-mode))) |
418 | 265 (condition-case () |
266 (progn | |
267 (interrupt-process comp-proc) | |
268 (sit-for 1) | |
269 (delete-process comp-proc)) | |
270 (error nil)) | |
271 (error "Cannot have two processes in `%s' at once" | |
272 (buffer-name)) | |
273 ))) | |
274 ;; In case the compilation buffer is current, make sure we get the global | |
275 ;; values of compilation-error-regexp-alist, etc. | |
276 (kill-all-local-variables)) | |
277 (let ((regexp-alist (or regexp-alist compilation-error-regexp-alist)) | |
278 (parser (or parser compilation-parse-errors-function)) | |
279 (thisdir default-directory) | |
280 outwin) | |
281 (save-excursion | |
282 ;; Clear out the compilation buffer and make it writable. | |
283 ;; Change its default-directory to the directory where the compilation | |
284 ;; will happen, and insert a `cd' command to indicate this. | |
285 (set-buffer outbuf) | |
286 (setq buffer-read-only nil) | |
287 (erase-buffer) | |
288 (setq default-directory thisdir) | |
289 (insert "cd " thisdir "\n" command "\n") | |
290 (set-buffer-modified-p nil)) | |
291 ;; If we're already in the compilation buffer, go to the end | |
292 ;; of the buffer, so point will track the compilation output. | |
293 (if (eq outbuf (current-buffer)) | |
294 (goto-char (point-max))) | |
295 ;; Pop up the compilation buffer. | |
296 (setq outwin (display-buffer outbuf)) | |
297 (set-buffer outbuf) | |
71 | 298 (compilation-mode) |
712
16823e891d56
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
621
diff
changeset
|
299 (buffer-disable-undo (current-buffer)) |
732 | 300 (setq buffer-read-only t) |
418 | 301 (set (make-local-variable 'compilation-parse-errors-function) parser) |
302 (set (make-local-variable 'compilation-error-message) error-message) | |
303 (set (make-local-variable 'compilation-error-regexp-alist) regexp-alist) | |
304 (setq default-directory thisdir | |
305 compilation-directory-stack (list default-directory)) | |
71 | 306 (set-window-start outwin (point-min)) |
418 | 307 (setq mode-name name-of-mode) |
71 | 308 (or (eq outwin (selected-window)) |
418 | 309 (set-window-point outwin (point-min))) |
310 (and compilation-window-height | |
778 | 311 (= (window-width outwin) (frame-width)) |
418 | 312 (let ((w (selected-window))) |
313 (unwind-protect | |
314 (progn | |
315 (select-window outwin) | |
316 (enlarge-window (- compilation-window-height | |
317 (window-height)))) | |
318 (select-window w)))) | |
319 ;; Start the compilation. | |
740 | 320 (let ((proc (start-process-shell-command (downcase mode-name) |
321 outbuf | |
322 command))) | |
323 (set-process-sentinel proc 'compilation-sentinel) | |
2472
f911936cec3f
(compilation-filter): New function.
Roland McGrath <roland@gnu.org>
parents:
2471
diff
changeset
|
324 (set-process-filter proc 'compilation-filter) |
740 | 325 (setq compilation-in-progress (cons proc compilation-in-progress)))) |
418 | 326 ;; Make it so the next C-x ` will use this buffer. |
327 (setq compilation-last-buffer outbuf))) | |
71 | 328 |
329 (defvar compilation-mode-map | |
330 (let ((map (make-sparse-keymap))) | |
331 (define-key map "\C-c\C-c" 'compile-goto-error) | |
418 | 332 (define-key map "\C-c\C-k" 'kill-compilation) |
894 | 333 (define-key map " " 'scroll-up) |
334 (define-key map "\^?" 'scroll-down) | |
335 (define-key map "\M-n" 'compilation-next-error) | |
336 (define-key map "\M-p" 'compilation-previous-error) | |
946 | 337 (define-key map "\M-{" 'compilation-previous-file) |
338 (define-key map "\M-}" 'compilation-next-file) | |
71 | 339 map) |
340 "Keymap for compilation log buffers.") | |
341 | |
342 (defun compilation-mode () | |
343 "Major mode for compilation log buffers. | |
344 \\<compilation-mode-map>To visit the source for a line-numbered error, | |
418 | 345 move point to the error message line and type \\[compile-goto-error]. |
569 | 346 To kill the compilation, type \\[kill-compilation]. |
347 | |
348 Runs `compilation-mode-hook' with `run-hooks' (which see)." | |
71 | 349 (interactive) |
350 (fundamental-mode) | |
351 (use-local-map compilation-mode-map) | |
352 (setq major-mode 'compilation-mode) | |
353 (setq mode-name "Compilation") | |
418 | 354 ;; Make buffer's mode line show process state |
355 (setq mode-line-process '(": %s")) | |
356 (set (make-local-variable 'compilation-error-list) nil) | |
357 (set (make-local-variable 'compilation-old-error-list) nil) | |
358 (set (make-local-variable 'compilation-parsing-end) 1) | |
359 (set (make-local-variable 'compilation-directory-stack) nil) | |
569 | 360 (setq compilation-last-buffer (current-buffer)) |
361 (run-hooks 'compilation-mode-hook)) | |
71 | 362 |
363 ;; Called when compilation process changes state. | |
364 (defun compilation-sentinel (proc msg) | |
418 | 365 "Sentinel for compilation buffers." |
366 (let ((buffer (process-buffer proc))) | |
740 | 367 (if (memq (process-status proc) '(signal exit)) |
368 (progn | |
369 (if (null (buffer-name buffer)) | |
370 ;; buffer killed | |
371 (set-process-buffer proc nil) | |
372 (let ((obuf (current-buffer)) | |
373 omax opoint) | |
374 ;; save-excursion isn't the right thing if | |
375 ;; process-buffer is current-buffer | |
376 (unwind-protect | |
377 (progn | |
378 ;; Write something in the compilation buffer | |
379 ;; and hack its mode line. | |
380 (set-buffer buffer) | |
1731
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
381 (let ((buffer-read-only nil)) |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
382 (setq omax (point-max) |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
383 opoint (point)) |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
384 (goto-char omax) |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
385 ;; Record where we put the message, so we can ignore it |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
386 ;; later on. |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
387 (insert ?\n mode-name " " msg) |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
388 (forward-char -1) |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
389 (insert " at " (substring (current-time-string) 0 19)) |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
390 (forward-char 1) |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
391 (setq mode-line-process |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
392 (concat ": " |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
393 (symbol-name (process-status proc)))) |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
394 ;; Since the buffer and mode line will show that the |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
395 ;; process is dead, we can delete it now. Otherwise it |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
396 ;; will stay around until M-x list-processes. |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
397 (delete-process proc) |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
398 ;; Force mode line redisplay soon. |
d1a56482a2af
(compilation-sentinel): Change buffer-read-only with let.
Richard M. Stallman <rms@gnu.org>
parents:
1702
diff
changeset
|
399 (set-buffer-modified-p (buffer-modified-p))) |
740 | 400 (if (and opoint (< opoint omax)) |
1133 | 401 (goto-char opoint)) |
402 (if compilation-finish-function | |
403 (funcall compilation-finish-function buffer msg))) | |
404 (set-buffer obuf)))) | |
740 | 405 (setq compilation-in-progress (delq proc compilation-in-progress)) |
406 )))) | |
71 | 407 |
2472
f911936cec3f
(compilation-filter): New function.
Roland McGrath <roland@gnu.org>
parents:
2471
diff
changeset
|
408 (defun compilation-filter (proc string) |
f911936cec3f
(compilation-filter): New function.
Roland McGrath <roland@gnu.org>
parents:
2471
diff
changeset
|
409 "Process filter for compilation buffers. |
f911936cec3f
(compilation-filter): New function.
Roland McGrath <roland@gnu.org>
parents:
2471
diff
changeset
|
410 Just inserts the text, but uses insert-before-markers." |
f911936cec3f
(compilation-filter): New function.
Roland McGrath <roland@gnu.org>
parents:
2471
diff
changeset
|
411 (save-excursion |
f911936cec3f
(compilation-filter): New function.
Roland McGrath <roland@gnu.org>
parents:
2471
diff
changeset
|
412 (set-buffer (process-buffer proc)) |
f911936cec3f
(compilation-filter): New function.
Roland McGrath <roland@gnu.org>
parents:
2471
diff
changeset
|
413 (let ((buffer-read-only nil)) |
f911936cec3f
(compilation-filter): New function.
Roland McGrath <roland@gnu.org>
parents:
2471
diff
changeset
|
414 (save-excursion |
f911936cec3f
(compilation-filter): New function.
Roland McGrath <roland@gnu.org>
parents:
2471
diff
changeset
|
415 (goto-char (process-mark proc)) |
f911936cec3f
(compilation-filter): New function.
Roland McGrath <roland@gnu.org>
parents:
2471
diff
changeset
|
416 (insert-before-markers string) |
f911936cec3f
(compilation-filter): New function.
Roland McGrath <roland@gnu.org>
parents:
2471
diff
changeset
|
417 (set-marker (process-mark proc) (point)))))) |
f911936cec3f
(compilation-filter): New function.
Roland McGrath <roland@gnu.org>
parents:
2471
diff
changeset
|
418 |
920 | 419 ;; Return the cdr of compilation-old-error-list for the error containing point. |
420 (defun compile-error-at-point () | |
421 (compile-reinitialize-errors nil (point)) | |
422 (let ((errors compilation-old-error-list)) | |
423 (while (and errors | |
424 (> (point) (car (car errors)))) | |
425 (setq errors (cdr errors))) | |
426 errors)) | |
427 | |
894 | 428 (defun compilation-next-error (n) |
429 "Move point to the next error in the compilation buffer. | |
430 Does NOT find the source line like \\[next-error]." | |
431 (interactive "p") | |
432 (or (compilation-buffer-p (current-buffer)) | |
433 (error "Not in a compilation buffer.")) | |
434 (setq compilation-last-buffer (current-buffer)) | |
435 | |
920 | 436 (let ((errors (compile-error-at-point))) |
894 | 437 |
920 | 438 ;; Move to the error after the one containing point. |
439 (goto-char (car (if (< n 0) | |
440 (let ((i 0) | |
441 (e compilation-old-error-list)) | |
442 ;; See how many cdrs away ERRORS is from the start. | |
443 (while (not (eq e errors)) | |
444 (setq i (1+ i) | |
445 e (cdr e))) | |
446 (if (> (- n) i) | |
447 (error "Moved back past first error") | |
448 (nth (+ i n) compilation-old-error-list))) | |
449 (let ((compilation-error-list (cdr errors))) | |
450 (compile-reinitialize-errors nil nil n) | |
451 (if compilation-error-list | |
452 (nth (1- n) compilation-error-list) | |
453 (error "Moved past last error")))))))) | |
894 | 454 |
455 (defun compilation-previous-error (n) | |
456 "Move point to the previous error in the compilation buffer. | |
457 Does NOT find the source line like \\[next-error]." | |
458 (interactive "p") | |
459 (compilation-next-error (- n))) | |
460 | |
461 | |
920 | 462 (defun compile-file-of-error (data) |
463 (setq data (cdr data)) | |
464 (if (markerp data) | |
465 (buffer-file-name (marker-buffer data)) | |
466 (setq data (car data)) | |
467 (expand-file-name (cdr data) (car data)))) | |
468 | |
469 (defun compilation-next-file (n) | |
470 "Move point to the next error for a different file than the current one." | |
471 (interactive "p") | |
472 (or (compilation-buffer-p (current-buffer)) | |
473 (error "Not in a compilation buffer.")) | |
474 (setq compilation-last-buffer (current-buffer)) | |
475 | |
476 (let ((reversed (< n 0)) | |
477 errors file) | |
478 | |
479 (if (not reversed) | |
480 (setq errors (or (compile-error-at-point) | |
481 (error "Moved past last error"))) | |
482 | |
483 ;; Get a reversed list of the errors up through the one containing point. | |
484 (compile-reinitialize-errors nil (point)) | |
485 (setq errors (reverse compilation-old-error-list) | |
486 n (- n)) | |
487 | |
488 ;; Ignore errors after point. (car ERRORS) will be the error | |
489 ;; containing point, (cadr ERRORS) the one before it. | |
490 (while (and errors | |
491 (< (point) (car (car errors)))) | |
492 (setq errors (cdr errors)))) | |
493 | |
494 (while (> n 0) | |
495 (setq file (compile-file-of-error (car errors))) | |
496 | |
497 ;; Skip past the other errors for this file. | |
498 (while (string= file | |
499 (compile-file-of-error | |
500 (car (or errors | |
501 (if reversed | |
936 | 502 (error "%s the first erring file" file) |
920 | 503 (let ((compilation-error-list nil)) |
504 ;; Parse some more. | |
505 (compile-reinitialize-errors nil nil 2) | |
506 (setq errors compilation-error-list))) | |
936 | 507 (error "%s is the last erring file" file))))) |
920 | 508 (setq errors (cdr errors))) |
509 | |
510 (setq n (1- n))) | |
511 | |
512 ;; Move to the following error. | |
513 (goto-char (car (car (or errors | |
514 (if reversed | |
515 (error "This is the first erring file") | |
516 (let ((compilation-error-list nil)) | |
517 ;; Parse the last one. | |
518 (compile-reinitialize-errors nil nil 1) | |
519 compilation-error-list)))))))) | |
520 | |
521 (defun compilation-previous-file (n) | |
522 "Move point to the previous error for a different file than the current one." | |
523 (interactive "p") | |
524 (compilation-next-file (- n))) | |
525 | |
526 | |
71 | 527 (defun kill-compilation () |
528 "Kill the process made by the \\[compile] command." | |
529 (interactive) | |
418 | 530 (let ((buffer (compilation-find-buffer))) |
71 | 531 (if (get-buffer-process buffer) |
418 | 532 (interrupt-process (get-buffer-process buffer)) |
533 (error "The compilation process is not running.")))) | |
71 | 534 |
418 | 535 |
536 ;; Parse any new errors in the compilation buffer, | |
537 ;; or reparse from the beginning if the user has asked for that. | |
907 | 538 (defun compile-reinitialize-errors (argp &optional limit-search find-at-least) |
418 | 539 (save-excursion |
540 (set-buffer compilation-last-buffer) | |
541 ;; If we are out of errors, or if user says "reparse", | |
542 ;; discard the info we have, to force reparsing. | |
543 (if (or (eq compilation-error-list t) | |
544 (consp argp)) | |
545 (progn (compilation-forget-errors) | |
546 (setq compilation-parsing-end 1))) | |
907 | 547 (if (and compilation-error-list |
920 | 548 (or (not limit-search) |
549 (> compilation-parsing-end limit-search)) | |
907 | 550 (or (not find-at-least) |
551 (> (length compilation-error-list) find-at-least))) | |
418 | 552 ;; Since compilation-error-list is non-nil, it points to a specific |
553 ;; error the user wanted. So don't move it around. | |
554 nil | |
555 (switch-to-buffer compilation-last-buffer) | |
71 | 556 (set-buffer-modified-p nil) |
920 | 557 (if (< compilation-parsing-end (point-max)) |
558 (let ((at-start (= compilation-parsing-end 1))) | |
559 (funcall compilation-parse-errors-function | |
560 limit-search find-at-least) | |
561 ;; Remember the entire list for compilation-forget-errors. | |
562 ;; If this is an incremental parse, append to previous list. | |
563 (if at-start | |
564 (setq compilation-old-error-list compilation-error-list) | |
565 (setq compilation-old-error-list | |
566 (nconc compilation-old-error-list compilation-error-list))) | |
567 ))))) | |
71 | 568 |
569 (defun compile-goto-error (&optional argp) | |
570 "Visit the source for the error message point is on. | |
571 Use this command in a compilation log buffer. | |
885 | 572 \\[universal-argument] as a prefix arg means to reparse the buffer's error messages first; |
71 | 573 other kinds of prefix arguments are ignored." |
574 (interactive "P") | |
418 | 575 (or (compilation-buffer-p (current-buffer)) |
576 (error "Not in a compilation buffer.")) | |
577 (setq compilation-last-buffer (current-buffer)) | |
885 | 578 (compile-reinitialize-errors argp (point)) |
894 | 579 |
1072 | 580 ;; Move to bol; the marker for the error on this line will point there. |
581 (beginning-of-line) | |
582 | |
894 | 583 ;; Move compilation-error-list to the elt of compilation-old-error-list |
901 | 584 ;; we want. |
894 | 585 (setq compilation-error-list compilation-old-error-list) |
901 | 586 (while (and compilation-error-list |
587 (> (point) (car (car compilation-error-list)))) | |
894 | 588 (setq compilation-error-list (cdr compilation-error-list))) |
589 | |
71 | 590 ;; Move to another window, so that next-error's window changes |
591 ;; result in the desired setup. | |
592 (or (one-window-p) | |
894 | 593 (progn |
594 (other-window -1) | |
595 ;; other-window changed the selected buffer, | |
596 ;; but we didn't want to do that. | |
597 (set-buffer compilation-last-buffer))) | |
598 | |
901 | 599 (next-error 1)) |
71 | 600 |
418 | 601 (defun compilation-buffer-p (buffer) |
602 (assq 'compilation-error-list (buffer-local-variables buffer))) | |
603 | |
604 ;; Return a compilation buffer. | |
605 ;; If the current buffer is a compilation buffer, return it. | |
606 ;; If compilation-last-buffer is set to a live buffer, use that. | |
607 ;; Otherwise, look for a compilation buffer and signal an error | |
608 ;; if there are none. | |
621 | 609 (defun compilation-find-buffer (&optional other-buffer) |
610 (if (and (not other-buffer) | |
611 (compilation-buffer-p (current-buffer))) | |
418 | 612 ;; The current buffer is a compilation buffer. |
613 (current-buffer) | |
621 | 614 (if (and compilation-last-buffer (buffer-name compilation-last-buffer) |
615 (or (not other-buffer) (not (eq compilation-last-buffer | |
616 (current-buffer))))) | |
418 | 617 compilation-last-buffer |
618 (let ((buffers (buffer-list))) | |
621 | 619 (while (and buffers (or (not (compilation-buffer-p (car buffers))) |
620 (and other-buffer | |
621 (eq (car buffers) (current-buffer))))) | |
418 | 622 (setq buffers (cdr buffers))) |
623 (if buffers | |
624 (car buffers) | |
621 | 625 (or (and other-buffer |
626 (compilation-buffer-p (current-buffer)) | |
627 ;; The current buffer is a compilation buffer. | |
628 (progn | |
629 (if other-buffer | |
630 (message "This is the only compilation buffer.")) | |
631 (current-buffer))) | |
632 (error "No compilation started!"))))))) | |
418 | 633 |
634 ;;;###autoload | |
71 | 635 (defun next-error (&optional argp) |
636 "Visit next compilation error message and corresponding source code. | |
637 This operates on the output from the \\[compile] command. | |
638 If all preparsed error messages have been processed, | |
639 the error message buffer is checked for new ones. | |
640 | |
641 A prefix arg specifies how many error messages to move; | |
642 negative means move back to previous error messages. | |
643 Just C-u as a prefix means reparse the error message buffer | |
644 and start at the first error. | |
645 | |
646 \\[next-error] normally applies to the most recent compilation started, | |
647 but as long as you are in the middle of parsing errors from one compilation | |
648 output buffer, you stay with that compilation output buffer. | |
649 | |
650 Use \\[next-error] in a compilation output buffer to switch to | |
651 processing errors from that compilation. | |
652 | |
418 | 653 See variables `compilation-parse-errors-function' and |
654 \`compilation-error-regexp-alist' for customization ideas." | |
71 | 655 (interactive "P") |
418 | 656 (setq compilation-last-buffer (compilation-find-buffer)) |
1846
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
657 (compile-reinitialize-errors argp nil |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
658 ;; We want to pass a number here only if |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
659 ;; we got a numeric prefix arg, not just C-u. |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
660 (and (not (consp argp)) |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
661 (1- (prefix-numeric-value argp)))) |
418 | 662 ;; Make ARGP nil if the prefix arg was just C-u, |
663 ;; since that means to reparse the errors, which the | |
664 ;; compile-reinitialize-errors call just did. | |
665 ;; Now we are only interested in a numeric prefix arg. | |
71 | 666 (if (consp argp) |
667 (setq argp nil)) | |
418 | 668 (let (next-errors next-error) |
669 (save-excursion | |
670 (set-buffer compilation-last-buffer) | |
901 | 671 ;; compilation-error-list points to the "current" error. |
672 (setq next-errors (nthcdr (1- (prefix-numeric-value argp)) | |
894 | 673 compilation-error-list) |
418 | 674 next-error (car next-errors)) |
675 (while | |
71 | 676 (progn |
418 | 677 (if (null next-error) |
678 (progn | |
679 (if argp (if (> (prefix-numeric-value argp) 0) | |
680 (error "Moved past last error") | |
681 (error "Moved back past first error"))) | |
682 (compilation-forget-errors) | |
683 (error (concat compilation-error-message | |
684 (and (get-buffer-process (current-buffer)) | |
685 (eq (process-status | |
686 (get-buffer-process | |
687 (current-buffer))) | |
688 'run) | |
689 " yet")))) | |
690 (setq compilation-error-list (cdr next-errors)) | |
691 (if (null (cdr next-error)) | |
692 ;; This error is boring. Go to the next. | |
693 t | |
694 (or (markerp (cdr next-error)) | |
695 ;; This error has a filename/lineno pair. | |
696 ;; Find the file and turn it into a marker. | |
697 (let* ((fileinfo (car (cdr next-error))) | |
698 (buffer (compilation-find-file (cdr fileinfo) | |
699 (car fileinfo) | |
700 (car next-error)))) | |
701 (if (null buffer) | |
702 ;; We can't find this error's file. | |
703 ;; Remove all errors in the same file. | |
704 (progn | |
705 (setq next-errors compilation-old-error-list) | |
706 (while next-errors | |
707 (and (consp (cdr (car next-errors))) | |
708 (equal (car (cdr (car next-errors))) | |
709 fileinfo) | |
710 (progn | |
711 (set-marker (car (car next-errors)) nil) | |
712 (setcdr (car next-errors) nil))) | |
713 (setq next-errors (cdr next-errors))) | |
714 ;; Look for the next error. | |
715 t) | |
716 ;; We found the file. Get a marker for this error. | |
1846
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
717 ;; compilation-old-error-list is a buffer-local |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
718 ;; variable, so we must be careful to extract its value |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
719 ;; before switching to the source file buffer. |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
720 (let ((errors compilation-old-error-list) |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
721 (last-line (cdr (cdr next-error)))) |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
722 (set-buffer buffer) |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
723 (save-excursion |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
724 (save-restriction |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
725 (widen) |
418 | 726 (goto-line last-line) |
727 (beginning-of-line) | |
728 (setcdr next-error (point-marker)) | |
729 ;; Make all the other error messages referring | |
730 ;; to the same file have markers into the buffer. | |
731 (while errors | |
732 (and (consp (cdr (car errors))) | |
733 (equal (car (cdr (car errors))) fileinfo) | |
734 (let ((this (cdr (cdr (car errors)))) | |
735 (lines (- (cdr (cdr (car errors))) | |
736 last-line))) | |
737 (if (eq selective-display t) | |
738 (if (< lines 0) | |
739 (re-search-backward "[\n\C-m]" | |
740 nil 'end | |
741 (- lines)) | |
742 (re-search-forward "[\n\C-m]" | |
743 nil 'end | |
744 lines)) | |
745 (forward-line lines)) | |
746 (setq last-line this) | |
747 (setcdr (car errors) (point-marker)))) | |
748 (setq errors (cdr errors))))))))) | |
749 ;; If we didn't get a marker for this error, | |
750 ;; go on to the next one. | |
751 (not (markerp (cdr next-error)))))) | |
752 (setq next-errors compilation-error-list | |
753 next-error (car next-errors)))) | |
754 | |
755 ;; Skip over multiple error messages for the same source location, | |
756 ;; so the next C-x ` won't go to an error in the same place. | |
757 (while (and compilation-error-list | |
758 (equal (cdr (car compilation-error-list)) (cdr next-error))) | |
759 (setq compilation-error-list (cdr compilation-error-list))) | |
760 | |
761 ;; We now have a marker for the position of the error. | |
762 (switch-to-buffer (marker-buffer (cdr next-error))) | |
763 (goto-char (cdr next-error)) | |
764 ;; If narrowing got in the way of | |
765 ;; going to the right place, widen. | |
766 (or (= (point) (marker-position (cdr next-error))) | |
767 (progn | |
768 (widen) | |
769 (goto-char (cdr next-error)))) | |
770 | |
71 | 771 ;; Show compilation buffer in other window, scrolled to this error. |
772 (let* ((pop-up-windows t) | |
773 (w (display-buffer (marker-buffer (car next-error))))) | |
774 (set-window-point w (car next-error)) | |
418 | 775 (set-window-start w (car next-error))))) |
776 | |
777 ;;;###autoload | |
778 (define-key ctl-x-map "`" 'next-error) | |
71 | 779 |
418 | 780 ;; Find a buffer for file FILENAME. |
781 ;; Search the directories in compilation-search-path. | |
782 ;; A nil in compilation-search-path means to try the | |
783 ;; current directory, which is passed in DIR. | |
784 ;; If FILENAME is not found at all, ask the user where to find it. | |
785 ;; Pop up the buffer containing MARKER and scroll to MARKER if we ask the user. | |
786 (defun compilation-find-file (filename dir marker) | |
787 (let ((dirs compilation-search-path) | |
788 result name) | |
789 (while (and dirs (null result)) | |
790 (setq name (expand-file-name filename (or (car dirs) dir)) | |
791 result (and (file-exists-p name) | |
792 (find-file-noselect name)) | |
793 dirs (cdr dirs))) | |
794 (or result | |
795 ;; The file doesn't exist. | |
796 ;; Ask the user where to find it. | |
797 ;; If he hits C-g, then the next time he does | |
798 ;; next-error, he'll skip past it. | |
799 (progn | |
800 (let* ((pop-up-windows t) | |
801 (w (display-buffer (marker-buffer marker)))) | |
802 (set-window-point w marker) | |
803 (set-window-start w marker)) | |
804 (setq name | |
805 (expand-file-name | |
806 (read-file-name | |
807 (format "Find this error in: (default %s) " | |
808 filename) dir filename t))) | |
809 (if (file-directory-p name) | |
810 (setq name (concat (file-name-as-directory name) filename))) | |
811 (if (file-exists-p name) | |
812 (find-file-noselect name)))))) | |
813 | |
814 ;; Set compilation-error-list to nil, and unchain the markers that point to the | |
815 ;; error messages and their text, so that they no longer slow down gap motion. | |
816 ;; This would happen anyway at the next garbage collection, but it is better to | |
894 | 817 ;; do it right away. |
71 | 818 (defun compilation-forget-errors () |
819 (while compilation-old-error-list | |
820 (let ((next-error (car compilation-old-error-list))) | |
821 (set-marker (car next-error) nil) | |
418 | 822 (if (markerp (cdr next-error)) |
823 (set-marker (cdr next-error) nil))) | |
71 | 824 (setq compilation-old-error-list (cdr compilation-old-error-list))) |
1846
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
825 (setq compilation-error-list nil |
19c13118ba0c
(compilation-forget-errors): Just set
Roland McGrath <roland@gnu.org>
parents:
1731
diff
changeset
|
826 compilation-directory-stack nil)) |
418 | 827 |
828 | |
829 (defun count-regexp-groupings (regexp) | |
830 "Return the number of \\( ... \\) groupings in REGEXP (a string)." | |
831 (let ((groupings 0) | |
832 (len (length regexp)) | |
833 (i 0) | |
834 c) | |
835 (while (< i len) | |
836 (setq c (aref regexp i) | |
837 i (1+ i)) | |
838 (cond ((= c ?\[) | |
839 ;; Find the end of this [...]. | |
840 (while (and (< i len) | |
841 (not (= (aref regexp i) ?\]))) | |
842 (setq i (1+ i)))) | |
843 ((= c ?\\) | |
844 (if (< i len) | |
845 (progn | |
846 (setq c (aref regexp i) | |
847 i (1+ i)) | |
848 (if (= c ?\)) | |
849 ;; We found the end of a grouping, | |
850 ;; so bump our counter. | |
851 (setq groupings (1+ groupings)))))))) | |
852 groupings)) | |
71 | 853 |
907 | 854 (defun compilation-parse-errors (limit-search find-at-least) |
71 | 855 "Parse the current buffer as grep, cc or lint error messages. |
418 | 856 See variable `compilation-parse-errors-function' for the interface it uses." |
71 | 857 (setq compilation-error-list nil) |
858 (message "Parsing error messages...") | |
859 (let (text-buffer | |
418 | 860 regexp enter-group leave-group error-group |
885 | 861 alist subexpr error-regexp-groups |
907 | 862 (found-desired nil) |
1133 | 863 (compilation-num-errors-found 0)) |
418 | 864 |
71 | 865 ;; Don't reparse messages already seen at last parse. |
866 (goto-char compilation-parsing-end) | |
867 ;; Don't parse the first two lines as error messages. | |
868 ;; This matters for grep. | |
869 (if (bobp) | |
870 (forward-line 2)) | |
418 | 871 |
872 ;; Compile all the regexps we want to search for into one. | |
873 (setq regexp (concat "\\(" compilation-enter-directory-regexp "\\)\\|" | |
874 "\\(" compilation-leave-directory-regexp "\\)\\|" | |
875 "\\(" (mapconcat (function | |
876 (lambda (elt) | |
877 (concat "\\(" (car elt) "\\)"))) | |
878 compilation-error-regexp-alist | |
879 "\\|") "\\)")) | |
880 | |
881 ;; Find out how many \(...\) groupings are in each of the regexps, and set | |
882 ;; *-GROUP to the grouping containing each constituent regexp (whose | |
883 ;; subgroups will come immediately thereafter) of the big regexp we have | |
884 ;; just constructed. | |
885 (setq enter-group 1 | |
886 leave-group (+ enter-group | |
887 (count-regexp-groupings | |
888 compilation-enter-directory-regexp) | |
889 1) | |
890 error-group (+ leave-group | |
891 (count-regexp-groupings | |
892 compilation-leave-directory-regexp) | |
893 1)) | |
894 | |
895 ;; Compile an alist (IDX FILE LINE), where IDX is the number of the | |
896 ;; subexpression for an entire error-regexp, and FILE and LINE are the | |
897 ;; numbers for the subexpressions giving the file name and line number. | |
2471
c5e43751f9aa
(compilation-error-regexp-alist): Fixed MIPS CC regexp to match file
Roland McGrath <roland@gnu.org>
parents:
2461
diff
changeset
|
898 (setq alist (or compilation-error-regexp-alist |
c5e43751f9aa
(compilation-error-regexp-alist): Fixed MIPS CC regexp to match file
Roland McGrath <roland@gnu.org>
parents:
2461
diff
changeset
|
899 (error "compilation-error-regexp-alist is empty!")) |
418 | 900 subexpr (1+ error-group)) |
901 (while alist | |
902 (setq error-regexp-groups (cons (list subexpr | |
903 (+ subexpr (nth 1 (car alist))) | |
904 (+ subexpr (nth 2 (car alist)))) | |
905 error-regexp-groups)) | |
906 (setq subexpr (+ subexpr 1 (count-regexp-groupings (car (car alist))))) | |
907 (setq alist (cdr alist))) | |
908 | |
894 | 909 (while (and (not found-desired) |
885 | 910 ;; We don't just pass LIMIT-SEARCH to re-search-forward |
911 ;; because we want to find matches containing LIMIT-SEARCH | |
912 ;; but which extend past it. | |
894 | 913 (re-search-forward regexp nil t)) |
935 | 914 |
418 | 915 ;; Figure out which constituent regexp matched. |
916 (cond ((match-beginning enter-group) | |
917 ;; The match was the enter-directory regexp. | |
918 (let ((dir | |
919 (file-name-as-directory | |
920 (expand-file-name | |
921 (buffer-substring (match-beginning (+ enter-group 1)) | |
922 (match-end (+ enter-group 1))))))) | |
923 (setq compilation-directory-stack | |
924 (cons dir compilation-directory-stack)) | |
925 (and (file-directory-p dir) | |
926 (setq default-directory dir)))) | |
927 | |
928 ((match-beginning leave-group) | |
929 ;; The match was the leave-directory regexp. | |
930 (let ((beg (match-beginning (+ leave-group 1))) | |
931 (stack compilation-directory-stack)) | |
932 (if beg | |
933 (let ((dir | |
934 (file-name-as-directory | |
935 (expand-file-name | |
936 (buffer-substring beg | |
937 (match-end (+ leave-group | |
938 1))))))) | |
939 (while (and stack | |
940 (not (string-equal (car stack) dir))) | |
941 (setq stack (cdr stack))))) | |
942 (setq compilation-directory-stack (cdr stack)) | |
943 (setq stack (car compilation-directory-stack)) | |
944 (if stack | |
945 (setq default-directory stack)) | |
946 )) | |
947 | |
948 ((match-beginning error-group) | |
949 ;; The match was the composite error regexp. | |
950 ;; Find out which individual regexp matched. | |
951 (setq alist error-regexp-groups) | |
952 (while (and alist | |
953 (null (match-beginning (car (car alist))))) | |
954 (setq alist (cdr alist))) | |
2471
c5e43751f9aa
(compilation-error-regexp-alist): Fixed MIPS CC regexp to match file
Roland McGrath <roland@gnu.org>
parents:
2461
diff
changeset
|
955 (setq losing-data (match-data)) |
418 | 956 (if alist |
957 (setq alist (car alist)) | |
2471
c5e43751f9aa
(compilation-error-regexp-alist): Fixed MIPS CC regexp to match file
Roland McGrath <roland@gnu.org>
parents:
2461
diff
changeset
|
958 (error "compilation-parse-errors: impossible regexp match!")) |
418 | 959 |
960 ;; Extract the file name and line number from the error message. | |
1294
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
961 (let ((beginning-of-match (match-beginning 0)) ;looking-at nukes |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
962 (filename |
418 | 963 (cons default-directory |
964 (buffer-substring (match-beginning (nth 1 alist)) | |
965 (match-end (nth 1 alist))))) | |
966 (linenum (save-restriction | |
967 (narrow-to-region | |
968 (match-beginning (nth 2 alist)) | |
969 (match-end (nth 2 alist))) | |
970 (goto-char (point-min)) | |
971 (if (looking-at "[0-9]") | |
972 (read (current-buffer)))))) | |
973 ;; Locate the erring file and line. | |
974 ;; Cons a new elt onto compilation-error-list, | |
975 ;; giving a marker for the current compilation buffer | |
976 ;; location, and the file and line number of the error. | |
977 (save-excursion | |
978 (beginning-of-line 1) | |
979 (setq compilation-error-list | |
980 (cons (cons (point-marker) | |
981 (cons filename linenum)) | |
1294
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
982 compilation-error-list))) |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
983 (setq compilation-num-errors-found |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
984 (1+ compilation-num-errors-found)) |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
985 (and find-at-least (>= compilation-num-errors-found |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
986 find-at-least) |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
987 ;; We have found as many new errors as the user wants. |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
988 ;; We continue to parse until we have seen all |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
989 ;; the consecutive errors in the same file, |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
990 ;; so the error positions will be recorded as markers |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
991 ;; in this buffer that might change. |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
992 (cdr compilation-error-list) ; Must check at least two. |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
993 (not (equal (car (cdr (nth 0 compilation-error-list))) |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
994 (car (cdr (nth 1 compilation-error-list))))) |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
995 (progn |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
996 ;; Discard the error just parsed, so that the next |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
997 ;; parsing run can get it and the following errors in |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
998 ;; the same file all at once. If we didn't do this, we |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
999 ;; would have the same problem we are trying to avoid |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
1000 ;; with the test above, just delayed until the next run! |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
1001 (setq compilation-error-list |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
1002 (cdr compilation-error-list)) |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
1003 (goto-char beginning-of-match) |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
1004 (setq found-desired t))) |
81c5d1c4a7ed
(compilation-parse-errors): Save (match-beginning 0) in a variable, so the
Roland McGrath <roland@gnu.org>
parents:
1273
diff
changeset
|
1005 ) |
1273
bbf7e139412b
(compilation-parse-errors): After we get enough errors to stop early, toss
Roland McGrath <roland@gnu.org>
parents:
1271
diff
changeset
|
1006 ) |
418 | 1007 (t |
2471
c5e43751f9aa
(compilation-error-regexp-alist): Fixed MIPS CC regexp to match file
Roland McGrath <roland@gnu.org>
parents:
2461
diff
changeset
|
1008 (error "compilation-parse-errors: known groups didn't match!"))) |
935 | 1009 |
1010 (message "Parsing error messages...%d (%d%% of buffer)" | |
1133 | 1011 compilation-num-errors-found |
935 | 1012 (/ (* 100 (point)) (point-max))) |
1013 | |
885 | 1014 (and limit-search (>= (point) limit-search) |
1015 ;; The user wanted a specific error, and we're past it. | |
1016 (setq found-desired t))) | |
907 | 1017 (setq compilation-parsing-end (if found-desired |
1018 (point) | |
1019 ;; We have searched the whole buffer. | |
1020 (point-max)))) | |
1021 (setq compilation-error-list (nreverse compilation-error-list)) | |
1022 (message "Parsing error messages...done")) | |
71 | 1023 |
1024 (define-key ctl-x-map "`" 'next-error) | |
621 | 1025 |
1026 (provide 'compile) | |
712
16823e891d56
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
621
diff
changeset
|
1027 |
16823e891d56
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
621
diff
changeset
|
1028 ;;; compile.el ends here |