annotate lisp/progmodes/compile.el @ 98:9228fd17f9aa

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Fri, 14 Sep 1990 19:07:14 +0000
parents a35b34e246fe
children 21a228b6a238
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
71
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;; Run compiler as inferior of Emacs, and parse its error messages.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1985, 1986, 1988, 1989 Free Software Foundation, Inc.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; This file is part of GNU Emacs.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; it under the terms of the GNU General Public License as published by
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; the Free Software Foundation; either version 1, or (at your option)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; any later version.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is distributed in the hope that it will be useful,
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; GNU General Public License for more details.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 (provide 'compile)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 (defvar compilation-error-list nil
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 "List of error message descriptors for visiting erring functions.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 Each error descriptor is a list of length two.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 Its car is a marker pointing to an error message.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 Its cadr is a marker pointing to the text of the line the message is about,
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 or nil if that is not interesting.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 The value may be t instead of a list;
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 this means that the buffer of error messages should be reparsed
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 the next time the list of errors is wanted.")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (defvar compilation-old-error-list nil
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 "Value of `compilation-error-list' after errors were parsed.")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (defvar compilation-last-error nil
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 "List describing the error found by last call to \\[next-error].
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 A list of two markers (ERROR-POS CODE-POS),
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 pointing to the error message and the erroneous code, respectively.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 CODE-POS can be nil, if the error message has no specific source location.")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (defvar compilation-parse-errors-hook 'compilation-parse-errors
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 "Function to call (no args) to parse error messages from a compilation.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 It should read in the source files which have errors
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 and set `compilation-error-list' to a list with an element
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 for each error message found. See that variable for more info.")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (defvar compilation-error-buffer nil
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 "Current compilation buffer for compilation error processing.")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (defvar compilation-parsing-end nil
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 "Position of end of buffer when last error messages parsed.")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (defvar compilation-error-message nil
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 "Message to print when no more matches for compilation-error-regexp are found")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; The filename excludes colons to avoid confusion when error message
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; starts with digits.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (defvar compilation-error-regexp
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 "\\([^ :\n]+\\(: *\\|, line \\|(\\)[0-9]+\\)\\|\\([0-9]+ *of *[^ \n]+\\)\\|\\(\"[^ \n]+\",L[0-9]+\\)"
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 "Regular expression for filename/linenumber in error in compilation log.")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (defvar compile-window-height nil
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 "*Desired height of compilation window. nil means use Emacs default.")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (defvar compile-command "make -k "
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 "Last shell command used to do a compilation; default for next compilation.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 Sometimes it is useful for files to supply local values for this variable.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 You might also use mode hooks to specify it in certain modes, like this:
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (setq c-mode-hook
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 '(lambda () (or (file-exists-p \"makefile\") (file-exists-p \"Makefile\")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (progn (make-local-variable 'compile-command)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (setq compile-command
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (concat \"make -k \"
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 buffer-file-name))))))")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (defvar compilation-search-path '(nil)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 "List of directories to search for source files named in error messages.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 Elements should be directory names, not file names of directories.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 nil as an element means to try the default directory.")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (defun compile (command)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 "Compile the program including the current buffer. Default: run `make'.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 Runs COMMAND, a shell command, in a separate process asynchronously
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 with output going to the buffer `*compilation*'.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 You can then use the command \\[next-error] to find the next error message
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 and move to the source code that caused it.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 To run more than one compilation at once, start one and rename the
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 `*compilation*' buffer to some other name. Then start the next one."
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (interactive (list (read-string "Compile command: " compile-command)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (setq compile-command command)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (save-some-buffers nil nil)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (compile-internal compile-command "No more errors")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (and compile-window-height
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (= (window-width) (screen-width))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (enlarge-window (- (- (screen-height) (window-height))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 compile-window-height) nil)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (defun grep (command-args)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 "Run grep, with user-specified args, and collect output in a buffer.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 While grep runs asynchronously, you can use the \\[next-error] command
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 to find the text that grep hits refer to. It is expected that `grep-command'
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 has a `-n' flag, so that line numbers are displayed for each match."
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (interactive
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (list (read-string (concat "Run "
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (substring grep-command 0
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (string-match "[\t ]+" grep-command))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 " (with args): ")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (progn
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (string-match "-n[\t ]+" grep-command)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (substring grep-command (match-end 0))))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;; why a redundant string-match? It might not be interactive ...
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (setq grep-command (concat (substring grep-command 0
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (progn
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (string-match "-n" grep-command)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (match-end 0)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 " " command-args))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (compile-internal (concat grep-command " /dev/null")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 "No more grep hits" "grep"))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (defun compile-internal (command error-message
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 &optional name-of-mode parser regexp)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 "Run compilation command COMMAND (low level interface).
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ERROR-MESSAGE is a string to print if the user asks to see another error
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 and there are no more errors. Third argument NAME-OF-MODE is the name
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 to display as the major mode in the `*compilation*' buffer.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 Fourth arg PARSER is the error parser function (nil means the default).
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 Fifth arg REGEXP is the error message regexp to use (nil means the default).
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 The defaults for these variables are the global values of
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 `compilation-parse-errors-hook' and `compilation-error-regexp'."
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (save-excursion
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (set-buffer (get-buffer-create "*compilation*"))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (setq buffer-read-only nil)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (let ((comp-proc (get-buffer-process (current-buffer))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (if comp-proc
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (if (or (not (eq (process-status comp-proc) 'run))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (yes-or-no-p "A compilation process is running; kill it? "))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (condition-case ()
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (progn
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (interrupt-process comp-proc)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (sit-for 1)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (delete-process comp-proc))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (error nil))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (error "Cannot have two processes in `*compilation*' at once"))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 ;; In case *compilation* is current buffer,
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 ;; make sure we get the global values of compilation-error-regexp, etc.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (kill-all-local-variables))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (compilation-forget-errors)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (start-process-shell-command "compilation" "*compilation*" command)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (with-output-to-temp-buffer "*compilation*"
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (princ "cd ")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (princ default-directory)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (terpri)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (princ command)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (terpri))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (let* ((regexp (or regexp compilation-error-regexp))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (parser (or parser compilation-parse-errors-hook))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (thisdir default-directory)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (outbuf (get-buffer "*compilation*"))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (outwin (get-buffer-window outbuf)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (if (eq outbuf (current-buffer))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (goto-char (point-max)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (set-process-sentinel (get-buffer-process outbuf)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 'compilation-sentinel)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (save-excursion
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (set-buffer outbuf)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (if (or (eq compilation-error-buffer outbuf)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (eq compilation-error-list t)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (and (null compilation-error-list)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (not (and (get-buffer-process compilation-error-buffer)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (eq (process-status compilation-error-buffer)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 'run)))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (setq compilation-error-list t
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 compilation-error-buffer outbuf))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (setq default-directory thisdir)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (compilation-mode)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (set-window-start outwin (point-min))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (setq mode-name (or name-of-mode "Compilation"))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (setq buffer-read-only t)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (or (eq outwin (selected-window))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (set-window-point outwin (point-min))))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (defvar compilation-mode-map
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (let ((map (make-sparse-keymap)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (define-key map "\C-c\C-c" 'compile-goto-error)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 map)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 "Keymap for compilation log buffers.")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (defun compilation-mode ()
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 "Major mode for compilation log buffers.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 \\<compilation-mode-map>To visit the source for a line-numbered error,
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 move point to the error message line and type \\[compile-goto-error]."
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (interactive)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (fundamental-mode)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (use-local-map compilation-mode-map)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (make-local-variable 'compilation-parse-errors-hook)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (setq compilation-parse-errors-hook parser)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (make-local-variable 'compilation-error-message)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (setq compilation-error-message error-message)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (make-local-variable 'compilation-error-regexp)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (setq compilation-error-regexp regexp)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (buffer-disable-undo (current-buffer))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (setq major-mode 'compilation-mode)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (setq mode-name "Compilation")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ;; Make log buffer's mode line show process state
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (setq mode-line-process '(": %s")))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ;; Called when compilation process changes state.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (defun compilation-sentinel (proc msg)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (cond ((null (buffer-name (process-buffer proc)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 ;; buffer killed
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (set-process-buffer proc nil))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 ((memq (process-status proc) '(signal exit))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (let* ((obuf (current-buffer))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 omax opoint)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 ;; save-excursion isn't the right thing if
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 ;; process-buffer is current-buffer
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (unwind-protect
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (progn
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 ;; Write something in *compilation* and hack its mode line,
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (set-buffer (process-buffer proc))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (setq omax (point-max) opoint (point))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (goto-char (point-max))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (insert ?\n mode-name " " msg)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (forward-char -1)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (insert " at " (substring (current-time-string) 0 19))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (forward-char 1)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (setq mode-line-process
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (concat ": "
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (symbol-name (process-status proc))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 ;; If buffer and mode line will show that the process
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 ;; is dead, we can delete it now. Otherwise it
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 ;; will stay around until M-x list-processes.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (delete-process proc))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 ;; Force mode line redisplay soon
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (set-buffer-modified-p (buffer-modified-p)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (if (and opoint (< opoint omax))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (goto-char opoint))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (set-buffer obuf)))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (defun kill-compilation ()
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 "Kill the process made by the \\[compile] command."
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (interactive)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (let ((buffer
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (if (assq 'compilation-parse-errors-hook (buffer-local-variables))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (current-buffer)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (get-buffer "*compilation*"))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (if (get-buffer-process buffer)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (interrupt-process (get-buffer-process buffer)))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 ;; Reparse errors or parse more/new errors, if appropriate.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (defun compile-reinitialize-errors (argp)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 ;; If we are out of errors, or if user says "reparse",
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 ;; or if we are in a different buffer from the known errors,
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 ;; discard the info we have, to force reparsing.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (if (or (eq compilation-error-list t)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (consp argp)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (if (assq 'compilation-parse-errors-hook (buffer-local-variables))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (not (eq compilation-error-buffer
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (setq compilation-error-buffer (current-buffer))))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (progn (compilation-forget-errors)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (setq compilation-parsing-end 1)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (if compilation-error-list
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 nil
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (save-excursion
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (switch-to-buffer compilation-error-buffer)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (set-buffer-modified-p nil)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (let ((at-start (= compilation-parsing-end 1)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (run-hooks 'compilation-parse-errors-hook)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 ;; Remember the entire list for compilation-forget-errors.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 ;; If this is an incremental parse, append to previous list.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (if at-start
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (setq compilation-old-error-list compilation-error-list)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (setq compilation-old-error-list
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (nconc compilation-old-error-list compilation-error-list)))))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (defun compile-goto-error (&optional argp)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 "Visit the source for the error message point is on.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 Use this command in a compilation log buffer.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 C-u as a prefix arg means to reparse the buffer's error messages first;
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 other kinds of prefix arguments are ignored."
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (interactive "P")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (compile-reinitialize-errors argp)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (save-excursion
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (beginning-of-line)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (setq compilation-error-list
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (memq (assoc (point-marker) compilation-old-error-list)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 compilation-old-error-list)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 ;; Move to another window, so that next-error's window changes
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 ;; result in the desired setup.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (or (one-window-p)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (other-window -1))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (next-error 1))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (defun next-error (&optional argp)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 "Visit next compilation error message and corresponding source code.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 This operates on the output from the \\[compile] command.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 If all preparsed error messages have been processed,
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 the error message buffer is checked for new ones.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 A prefix arg specifies how many error messages to move;
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 negative means move back to previous error messages.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 Just C-u as a prefix means reparse the error message buffer
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 and start at the first error.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 \\[next-error] normally applies to the most recent compilation started,
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 but as long as you are in the middle of parsing errors from one compilation
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 output buffer, you stay with that compilation output buffer.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 Use \\[next-error] in a compilation output buffer to switch to
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 processing errors from that compilation.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 See variables `compilation-parse-errors-hook' and `compilation-error-regexp'
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 for customization ideas. When we return, `compilation-last-error'
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 points to the error message and the erroneous code."
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (interactive "P")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (compile-reinitialize-errors argp)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (if (consp argp)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (setq argp nil))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (let* ((next-errors (nthcdr (+ (- (length compilation-old-error-list)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (length compilation-error-list)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 1)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (prefix-numeric-value argp))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 compilation-old-error-list))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (next-error (car next-errors)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (if (null next-error)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (save-excursion
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (if argp (if (> (prefix-numeric-value argp) 0)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (error "Moved past last error")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (error "Moved back past first error")))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (set-buffer compilation-error-buffer)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (compilation-forget-errors)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (error (concat compilation-error-message
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (if (and (get-buffer-process (current-buffer))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (eq (process-status (current-buffer))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 'run))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 " yet" "")))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (setq compilation-error-list (cdr next-errors))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 ;; If we have an error to go to, go there.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (if (null (car (cdr next-error)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 nil
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (switch-to-buffer (marker-buffer (car (cdr next-error))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (goto-char (car (cdr next-error)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 ;; If narrowing got in the way of going to the right place, widen.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (or (= (point) (car (cdr next-error)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (progn
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (widen)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (goto-char (car (cdr next-error))))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 ;; Show compilation buffer in other window, scrolled to this error.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (let* ((pop-up-windows t)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (w (display-buffer (marker-buffer (car next-error)))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (set-window-point w (car next-error))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (set-window-start w (car next-error)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (setq compilation-last-error next-error)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 ;; Set compilation-error-list to nil, and
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 ;; unchain the markers that point to the error messages and their text,
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 ;; so that they no longer slow down gap motion.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 ;; This would happen anyway at the next garbage collection,
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 ;; but it is better to do it right away.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (defun compilation-forget-errors ()
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (while compilation-old-error-list
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (let ((next-error (car compilation-old-error-list)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (set-marker (car next-error) nil)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (if (car (cdr next-error))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (set-marker (car (cdr next-error)) nil)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (setq compilation-old-error-list (cdr compilation-old-error-list)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (setq compilation-error-list nil))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (defun compilation-parse-errors ()
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 "Parse the current buffer as grep, cc or lint error messages.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 See variable `compilation-parse-errors-hook' for the interface it uses."
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (setq compilation-error-list nil)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (message "Parsing error messages...")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (let (text-buffer
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 last-filename last-linenum)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 ;; Don't reparse messages already seen at last parse.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (goto-char compilation-parsing-end)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 ;; Don't parse the first two lines as error messages.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 ;; This matters for grep.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (if (bobp)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (forward-line 2))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (while (re-search-forward compilation-error-regexp nil t)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (let (linenum filename
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 error-marker text-marker)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 ;; Extract file name and line number from error message.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (save-restriction
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (narrow-to-region (match-beginning 0) (match-end 0))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (goto-char (point-max))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (skip-chars-backward "[0-9]")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 ;; If it's a lint message, use the last file(linenum) on the line.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 ;; Normally we use the first on the line.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (if (= (preceding-char) ?\()
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (progn
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (narrow-to-region (point-min) (1+ (buffer-size)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (end-of-line)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (re-search-backward compilation-error-regexp)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (skip-chars-backward "^ \t\n")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (narrow-to-region (point) (match-end 0))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (goto-char (point-max))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (skip-chars-backward "[0-9]")))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 ;; Are we looking at a "filename-first" or "line-number-first" form?
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (if (looking-at "[0-9]")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (progn
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (setq linenum (read (current-buffer)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (goto-char (point-min)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 ;; Line number at start, file name at end.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (progn
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (goto-char (point-min))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (setq linenum (read (current-buffer)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (goto-char (point-max))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (skip-chars-backward "^ \t\n")))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (setq filename (compilation-grab-filename)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 ;; Locate the erring file and line.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (if (and (equal filename last-filename)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (= linenum last-linenum))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 nil
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (beginning-of-line 1)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (setq error-marker (point-marker))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 ;; text-buffer gets the buffer containing this error's file.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (if (not (equal filename last-filename))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (setq last-filename filename
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 text-buffer (compilation-find-file filename)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 last-linenum 0))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (if text-buffer
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 ;; Go to that buffer and find the erring line.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (save-excursion
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (set-buffer text-buffer)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (if (zerop last-linenum)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (progn
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (goto-char 1)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (setq last-linenum 1)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (forward-line (- linenum last-linenum))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (setq last-linenum linenum)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (setq text-marker (point-marker))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (setq compilation-error-list
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (cons (list error-marker text-marker)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 compilation-error-list)))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (forward-line 1)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (setq compilation-parsing-end (point-max)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (message "Parsing error messages...done")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (setq compilation-error-list (nreverse compilation-error-list)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 ;; Find or create a buffer for file FILENAME.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 ;; Search the directories in compilation-search-path
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 ;; after trying the current directory.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (defun compilation-find-file (filename)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (let ((dirs compilation-search-path)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 result)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (while (and dirs (null result))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (let ((name (if (car dirs)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 (concat (car dirs) filename)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 filename)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 (setq result
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (and (file-exists-p name)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (find-file-noselect name))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (setq dirs (cdr dirs)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 result))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (defun compilation-grab-filename ()
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 "Return a string which is a filename, starting at point.
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 Ignore quotes and parentheses around it, as well as trailing colons."
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (if (eq (following-char) ?\")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (save-restriction
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (narrow-to-region (point)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (progn (forward-sexp 1) (point)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (goto-char (point-min))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (read (current-buffer)))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (buffer-substring (point)
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (progn
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (skip-chars-forward "^ :,\n\t(")
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (point)))))
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477
a35b34e246fe Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (define-key ctl-x-map "`" 'next-error)