comparison lisp/progmodes/compile.el @ 43135:10b506b00785

(grep-compute-defaults): Definition moved up.
author Richard M. Stallman <rms@gnu.org>
date Wed, 06 Feb 2002 15:37:35 +0000
parents 0786ea38f9fd
children d7e7a906dbe4
comparison
equal deleted inserted replaced
43134:ecd029f63cc0 43135:10b506b00785
64 :type '(choice (const :tag "All" t) 64 :type '(choice (const :tag "All" t)
65 (const :tag "None" nil) 65 (const :tag "None" nil)
66 (integer :tag "First N lines")) 66 (integer :tag "First N lines"))
67 :group 'compilation) 67 :group 'compilation)
68 68
69 (defcustom grep-command nil 69 ;;; This has to be here so it can be called
70 "The default grep command for \\[grep]. 70 ;;; by the following defcustoms.
71 If the grep program used supports an option to always include file names
72 in its output (such as the `-H' option to GNU grep), it's a good idea to
73 include it when specifying `grep-command'.
74
75 The default value of this variable is set up by `grep-compute-defaults';
76 call that function before using this variable in your program."
77 :type 'string
78 :get '(lambda (symbol)
79 (or grep-command
80 (progn (grep-compute-defaults) grep-command)))
81 :group 'compilation)
82
83 (defcustom grep-use-null-device 'auto-detect
84 "If non-nil, append the value of `null-device' to grep commands.
85 This is done to ensure that the output of grep includes the filename of
86 any match in the case where only a single file is searched, and is not
87 necessary if the grep program used supports the `-H' option.
88
89 The default value of this variable is set up by `grep-compute-defaults';
90 call that function before using this variable in your program."
91 :type 'boolean
92 :get '(lambda (symbol)
93 (if (and grep-use-null-device (not (eq grep-use-null-device t)))
94 (progn (grep-compute-defaults) grep-use-null-device)
95 grep-use-null-device))
96 :group 'compilation)
97
98 (defcustom grep-find-command nil
99 "The default find command for \\[grep-find].
100 The default value of this variable is set up by `grep-compute-defaults';
101 call that function before using this variable in your program."
102 :type 'string
103 :get (lambda (symbol)
104 (or grep-find-command
105 (progn (grep-compute-defaults) grep-find-command)))
106 :group 'compilation)
107
108 (defvar compilation-error-list nil
109 "List of error message descriptors for visiting erring functions.
110 Each error descriptor is a cons (or nil). Its car is a marker pointing to
111 an error message. If its cdr is a marker, it points to the text of the
112 line the message is about. If its cdr is a cons, it is a list
113 \(\(DIRECTORY . FILE\) LINE [COLUMN]\). Or its cdr may be nil if that
114 error is not interesting.
115
116 The value may be t instead of a list; this means that the buffer of
117 error messages should be reparsed the next time the list of errors is wanted.
118
119 Some other commands (like `diff') use this list to control the error
120 message tracking facilities; if you change its structure, you should make
121 sure you also change those packages. Perhaps it is better not to change
122 it at all.")
123
124 (defvar compilation-old-error-list nil
125 "Value of `compilation-error-list' after errors were parsed.")
126
127 (defvar compilation-parse-errors-function 'compilation-parse-errors
128 "Function to call to parse error messages from a compilation.
129 It takes args LIMIT-SEARCH and FIND-AT-LEAST.
130 If LIMIT-SEARCH is non-nil, don't bother parsing past that location.
131 If FIND-AT-LEAST is non-nil, don't bother parsing after finding that
132 many new errors.
133 It should read in the source files which have errors and set
134 `compilation-error-list' to a list with an element for each error message
135 found. See that variable for more info.")
136
137 (defvar compilation-parse-errors-filename-function nil
138 "Function to call to post-process filenames while parsing error messages.
139 It takes one arg FILENAME which is the name of a file as found
140 in the compilation output, and should return a transformed file name.")
141
142 ;;;###autoload
143 (defvar compilation-process-setup-function nil
144 "*Function to call to customize the compilation process.
145 This functions is called immediately before the compilation process is
146 started. It can be used to set any variables or functions that are used
147 while processing the output of the compilation process.")
148
149 ;;;###autoload
150 (defvar compilation-buffer-name-function nil
151 "Function to compute the name of a compilation buffer.
152 The function receives one argument, the name of the major mode of the
153 compilation buffer. It should return a string.
154 nil means compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
155
156 ;;;###autoload
157 (defvar compilation-finish-function nil
158 "Function to call when a compilation process finishes.
159 It is called with two arguments: the compilation buffer, and a string
160 describing how the process finished.")
161
162 ;;;###autoload
163 (defvar compilation-finish-functions nil
164 "Functions to call when a compilation process finishes.
165 Each function is called with two arguments: the compilation buffer,
166 and a string describing how the process finished.")
167
168 (defvar compilation-last-buffer nil
169 "The most recent compilation buffer.
170 A buffer becomes most recent when its compilation is started
171 or when it is used with \\[next-error] or \\[compile-goto-error].")
172
173 (defvar compilation-in-progress nil
174 "List of compilation processes now running.")
175 (or (assq 'compilation-in-progress minor-mode-alist)
176 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
177 minor-mode-alist)))
178
179 (defvar compilation-parsing-end nil
180 "Marker position of end of buffer when last error messages were parsed.")
181
182 (defvar compilation-error-message "No more errors"
183 "Message to print when no more matches are found.")
184
185 (defvar compilation-arguments nil
186 "Arguments that were given to `compile-internal'.")
187
188 (defvar compilation-num-errors-found)
189
190 (defvar compilation-error-regexp-alist
191 '(
192 ;; NOTE! See also grep-regexp-alist, below.
193
194 ;; 4.3BSD grep, cc, lint pass 1:
195 ;; /usr/src/foo/foo.c(8): warning: w may be used before set
196 ;; or GNU utilities:
197 ;; foo.c:8: error message
198 ;; or HP-UX 7.0 fc:
199 ;; foo.f :16 some horrible error message
200 ;; or GNU utilities with column (GNAT 1.82):
201 ;; foo.adb:2:1: Unit name does not match file name
202 ;; or with column and program name:
203 ;; jade:dbcommon.dsl:133:17:E: missing argument for function call
204 ;;
205 ;; We'll insist that the number be followed by a colon or closing
206 ;; paren, because otherwise this matches just about anything
207 ;; containing a number with spaces around it.
208
209 ;; We insist on a non-digit in the file name
210 ;; so that we don't mistake the file name for a command name
211 ;; and take the line number as the file name.
212 ("\\([a-zA-Z][-a-zA-Z._0-9]+: ?\\)?\
213 \\([a-zA-Z]?:?[^:( \t\n]*[^:( \t\n0-9][^:( \t\n]*\\)[:(][ \t]*\\([0-9]+\\)\
214 \\([) \t]\\|:\\(\\([0-9]+:\\)\\|[0-9]*[^:0-9]\\)\\)" 2 3 6)
215
216 ;; Microsoft C/C++:
217 ;; keyboard.c(537) : warning C4005: 'min' : macro redefinition
218 ;; d:\tmp\test.c(23) : error C2143: syntax error : missing ';' before 'if'
219 ;; This used to be less selective and allow characters other than
220 ;; parens around the line number, but that caused confusion for
221 ;; GNU-style error messages.
222 ;; This used to reject spaces and dashes in file names,
223 ;; but they are valid now; so I made it more strict about the error
224 ;; message that follows.
225 ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
226 : \\(error\\|warning\\) C[0-9]+:" 1 3)
227
228 ;; Borland C++, C++Builder:
229 ;; Error ping.c 15: Unable to open include file 'sys/types.h'
230 ;; Warning ping.c 68: Call to function 'func' with no prototype
231 ;; Error E2010 ping.c 15: Unable to open include file 'sys/types.h'
232 ;; Warning W1022 ping.c 68: Call to function 'func' with no prototype
233 ("\\(Error\\|Warning\\) \\(\\([FEW][0-9]+\\) \\)?\
234 \\([a-zA-Z]?:?[^:( \t\n]+\\)\
235 \\([0-9]+\\)\\([) \t]\\|:[^0-9\n]\\)" 4 5)
236
237 ;; 4.3BSD lint pass 2
238 ;; strcmp: variable # of args. llib-lc(359) :: /usr/src/foo/foo.c(8)
239 (".*[ \t:]\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(](+[ \t]*\\([0-9]+\\))[:) \t]*$"
240 1 2)
241
242 ;; 4.3BSD lint pass 3
243 ;; bloofle defined( /users/wolfgang/foo.c(4) ), but never used
244 ;; This used to be
245 ;; ("[ \t(]+\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]+" 1 2)
246 ;; which is regexp Impressionism - it matches almost anything!
247 (".*([ \t]*\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\))" 1 2)
248
249 ;; MIPS lint pass<n>; looks good for SunPro lint also
250 ;; TrimMask (255) in solomon.c may be indistinguishable from TrimMasks (93) in solomon.c due to truncation
251 ("[^\n ]+ (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
252 ;; name defined but never used: LinInt in cmap_calc.c(199)
253 (".*in \\([^(\n]+\\)(\\([0-9]+\\))$" 1 2)
254
255 ;; Ultrix 3.0 f77:
256 ;; fort: Severe: addstf.f, line 82: Missing operator or delimiter symbol
257 ;; Some SGI cc version:
258 ;; cfe: Warning 835: foo.c, line 2: something
259 ("\\(cfe\\|fort\\): [^:\n]*: \\([^ \n]*\\), line \\([0-9]+\\):" 2 3)
260 ;; Error on line 3 of t.f: Execution error unclassifiable statement
261 ;; Unknown who does this:
262 ;; Line 45 of "foo.c": bloofle undefined
263 ;; Absoft FORTRAN 77 Compiler 3.1.3
264 ;; error on line 19 of fplot.f: spelling error?
265 ;; warning on line 17 of fplot.f: data type is undefined for variable d
266 ("\\(.* on \\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
267 of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2)
268
269 ;; Apollo cc, 4.3BSD fc:
270 ;; "foo.f", line 3: Error: syntax error near end of statement
271 ;; IBM RS6000:
272 ;; "vvouch.c", line 19.5: 1506-046 (S) Syntax error.
273 ;; Microtec mcc68k:
274 ;; "foo.c", line 32 pos 1; (E) syntax error; unexpected symbol: "lossage"
275 ;; GNAT (as of July 94):
276 ;; "foo.adb", line 2(11): warning: file name does not match ...
277 ;; IBM AIX xlc compiler:
278 ;; "src/swapping.c", line 30.34: 1506-342 (W) "/*" detected in comment.
279 (".*\"\\([^,\" \n\t]+\\)\", lines? \
280 \\([0-9]+\\)\\([\(.]\\([0-9]+\\)\)?\\)?[:., (-]" 1 2 4)
281
282 ;; Caml compiler:
283 ;; File "foobar.ml", lines 5-8, characters 20-155: blah blah
284 ("^File \"\\([^,\" \n\t]+\\)\", lines? \\([0-9]+\\)[-0-9]*, characters? \\([0-9]+\\)" 1 2 3)
285
286 ;; MIPS RISC CC - the one distributed with Ultrix:
287 ;; ccom: Error: foo.c, line 2: syntax error
288 ;; DEC AXP OSF/1 cc
289 ;; /usr/lib/cmplrs/cc/cfe: Error: foo.c: 1: blah blah
290 ("[a-z0-9/]+: \\([eE]rror\\|[wW]arning\\): \\([^,\" \n\t]+\\)[,:] \\(line \\)?\\([0-9]+\\):" 2 4)
291
292 ;; IBM AIX PS/2 C version 1.1:
293 ;; ****** Error number 140 in line 8 of file errors.c ******
294 (".*in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
295 ;; IBM AIX lint is too painful to do right this way. File name
296 ;; prefixes entire sections rather than being on each line.
297
298 ;; SPARCcompiler Pascal:
299 ;; 20 linjer : array[1..4] of linje;
300 ;; e 18480-----------^--- Inserted ';'
301 ;; and
302 ;; E 18520 line 61 - 0 is undefined
303 ;; These messages don't contain a file name. Instead the compiler gives
304 ;; a message whenever the file being compiled is changed.
305 (" +\\([0-9]+\\) +.*\n[ew] [0-9]+-+" nil 1)
306 ("[Ew] +[0-9]+ line \\([0-9]+\\) - " nil 1)
307
308 ;; Lucid Compiler, lcc 3.x
309 ;; E, file.cc(35,52) Illegal operation on pointers
310 ("[EW], \\([^(\n]*\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)" 1 2 3)
311
312 ;; This seems to be superfluous because the first pattern matches it.
313 ;; ;; GNU messages with program name and optional column number.
314 ;; ("[a-zA-Z]?:?[^0-9 \n\t:]+[^ \n\t:]*:[ \t]*\\([^ \n\t:]+\\):\
315 ;;\\([0-9]+\\):\\(\\([0-9]+\\)[: \t]\\)?" 1 2 4)
316
317 ;; Cray C compiler error messages
318 ("\\(cc\\| cft\\)-[0-9]+ c\\(c\\|f77\\): ERROR \\([^,\n]+, \\)* File = \
319 \\([^,\n]+\\), Line = \\([0-9]+\\)" 4 5)
320
321 ;; IBM C/C++ Tools 2.01:
322 ;; foo.c(2:0) : informational EDC0804: Function foo is not referenced.
323 ;; foo.c(3:8) : warning EDC0833: Implicit return statement encountered.
324 ;; foo.c(5:5) : error EDC0350: Syntax error.
325 ("\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) : " 1 2 3)
326
327 ;; IAR Systems C Compiler:
328 ;; "foo.c",3 Error[32]: Error message
329 ;; "foo.c",3 Warning[32]: Error message
330 ("\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(Error\\|Warning\\)\\[[0-9]+\\]:" 1 2)
331
332 ;; Sun ada (VADS, Solaris):
333 ;; /home3/xdhar/rcds_rc/main.a, line 361, char 6:syntax error: "," inserted
334 ("\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
335
336 ;; Perl -w:
337 ;; syntax error at automake line 922, near "':'"
338 ;; Perl debugging traces
339 ;; store::odrecall('File_A', 'x2') called at store.pm line 90
340 (".* at \\([^ \n]+\\) line \\([0-9]+\\)[,.\n]" 1 2)
341
342 ;; Oracle pro*c:
343 ;; Semantic error at line 528, column 5, file erosacqdb.pc:
344 ("Semantic error at line \\([0-9]+\\), column \\([0-9]+\\), file \\(.*\\):"
345 3 1 2)
346
347 ;; EPC F90 compiler:
348 ;; Error 24 at (2:progran.f90) : syntax error
349 ("Error [0-9]+ at (\\([0-9]*\\):\\([^)\n]+\\))" 2 1)
350
351 ;; SGI IRIX MipsPro 7.3 compilers:
352 ;; cc-1070 cc: ERROR File = linkl.c, Line = 38
353 (".*: ERROR File = \\(.+\\), Line = \\([0-9]+\\)" 1 2)
354 (".*: WARNING File = \\(.+\\), Line = \\([0-9]+\\)" 1 2)
355
356 ;; Sun F90 error messages:
357 ;; cf90-113 f90comp: ERROR NSE, File = Hoved.f90, Line = 16, Column = 3
358 (".* ERROR [a-zA-Z0-9 ]+, File = \\(.+\\), Line = \\([0-9]+\\), Column = \\([0-9]+\\)"
359 1 2 3)
360
361 ;; RXP - GPL XML validator at http://www.cogsci.ed.ac.uk/~richard/rxp.html:
362 ;; Error: Mismatched end tag: expected </geroup>, got </group>
363 ;; in unnamed entity at line 71 char 8 of file:///home/reto/test/group.xml
364 ("Error:.*\n.* line \\([0-9]+\\) char \\([0-9]+\\) of file://\\(.+\\)"
365 3 1 2)
366 ;; Warning: Start tag for undeclared element geroup
367 ;; in unnamed entity at line 4 char 8 of file:///home/reto/test/group.xml
368 ("Warning:.*\n.* line \\([0-9]+\\) char \\([0-9]+\\) of file://\\(.+\\)"
369 3 1 2)
370 )
371
372 "Alist that specifies how to match errors in compiler output.
373 Each elt has the form (REGEXP FILE-IDX LINE-IDX [COLUMN-IDX FILE-FORMAT...])
374 If REGEXP matches, the FILE-IDX'th subexpression gives the file name, and
375 the LINE-IDX'th subexpression gives the line number. If COLUMN-IDX is
376 given, the COLUMN-IDX'th subexpression gives the column number on that line.
377 If any FILE-FORMAT is given, each is a format string to produce a file name to
378 try; %s in the string is replaced by the text matching the FILE-IDX'th
379 subexpression.")
380
381 (defvar compilation-enter-directory-regexp-alist
382 '(
383 ;; Matches lines printed by the `-w' option of GNU Make.
384 (".*: Entering directory `\\(.*\\)'$" 1)
385 )
386 "Alist specifying how to match lines that indicate a new current directory.
387 Note that the match is done at the beginning of lines.
388 Each elt has the form (REGEXP IDX).
389 If REGEXP matches, the IDX'th subexpression gives the directory name.
390
391 The default value matches lines printed by the `-w' option of GNU Make.")
392
393 (defvar compilation-leave-directory-regexp-alist
394 '(
395 ;; Matches lines printed by the `-w' option of GNU Make.
396 (".*: Leaving directory `\\(.*\\)'$" 1)
397 )
398 "Alist specifying how to match lines that indicate restoring current directory.
399 Note that the match is done at the beginning of lines.
400 Each elt has the form (REGEXP IDX).
401 If REGEXP matches, the IDX'th subexpression gives the name of the directory
402 being moved from. If IDX is nil, the last directory entered \(by a line
403 matching `compilation-enter-directory-regexp-alist'\) is assumed.
404
405 The default value matches lines printed by the `-w' option of GNU Make.")
406
407 (defvar compilation-file-regexp-alist
408 '(
409 ;; This matches entries with date time year file-name: like
410 ;; Thu May 14 10:46:12 1992 mom3.p:
411 ("\\w\\w\\w \\w\\w\\w +[0-9]+ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9] \\(.*\\):$" 1)
412 )
413 "Alist specifying how to match lines that indicate a new current file.
414 Note that the match is done at the beginning of lines.
415 Each elt has the form (REGEXP IDX).
416 If REGEXP matches, the IDX'th subexpression gives the file name. This is
417 used with compilers that don't indicate file name in every error message.")
418
419 ;; There is no generally useful regexp that will match non messages, but
420 ;; in special cases there might be one. The lines that are not matched by
421 ;; a regexp take much longer time than the ones that are recognized so if
422 ;; you have same regexeps here, parsing is faster.
423 (defvar compilation-nomessage-regexp-alist
424 '(
425 )
426 "Alist specifying how to match lines that have no message.
427 Note that the match is done at the beginning of lines.
428 Each elt has the form (REGEXP). This alist is by default empty, but if
429 you have some good regexps here, the parsing of messages will be faster.")
430
431 (defcustom compilation-error-screen-columns t
432 "*If non-nil, column numbers in error messages are screen columns.
433 Otherwise they are interpreted as character positions, with
434 each character occupying one column.
435 The default is to use screen columns, which requires that the compilation
436 program and Emacs agree about the display width of the characters,
437 especially the TAB character."
438 :type 'boolean
439 :group 'compilation
440 :version "20.4")
441
442 (defcustom compilation-read-command t
443 "*Non-nil means \\[compile] reads the compilation command to use.
444 Otherwise, \\[compile] just uses the value of `compile-command'."
445 :type 'boolean
446 :group 'compilation)
447
448 ;;;###autoload
449 (defcustom compilation-ask-about-save t
450 "*Non-nil means \\[compile] asks which buffers to save before compiling.
451 Otherwise, it saves all modified buffers without asking."
452 :type 'boolean
453 :group 'compilation)
454
455 ;; Note: the character class after the optional drive letter does not
456 ;; include a space to support file names with blanks.
457 (defvar grep-regexp-alist
458 '(("\\([a-zA-Z]?:?[^:(\t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2))
459 "Regexp used to match grep hits. See `compilation-error-regexp-alist'.")
460
461 (defvar grep-program
462 ;; Currently zgrep has trouble. It runs egrep instead of grep,
463 ;; and it doesn't pass along long options right.
464 "grep"
465 ;; (if (equal (condition-case nil ; in case "zgrep" isn't in exec-path
466 ;; (call-process "zgrep" nil nil nil
467 ;; "foo" null-device)
468 ;; (error nil))
469 ;; 1)
470 ;; "zgrep"
471 ;; "grep")
472 "The default grep program for `grep-command' and `grep-find-command'.
473 This variable's value takes effect when `grep-compute-defaults' is called.")
474
475 (defvar find-program "find"
476 "The default find program for `grep-find-command'.
477 This variable's value takes effect when `grep-compute-defaults' is called.")
478
479 (defvar grep-find-use-xargs nil
480 "Whether \\[grep-find] uses the `xargs' utility by default.
481
482 If nil, it uses `grep -exec'; if `gnu', it uses `find -print0' and `xargs -0';
483 if not nil and not `gnu', it uses `find -print' and `xargs'.
484
485 This variable's value takes effect when `grep-compute-defaults' is called.")
486
487 ;;;###autoload
488 (defcustom compilation-search-path '(nil)
489 "*List of directories to search for source files named in error messages.
490 Elements should be directory names, not file names of directories.
491 nil as an element means to try the default directory."
492 :type '(repeat (choice (const :tag "Default" nil)
493 (string :tag "Directory")))
494 :group 'compilation)
495
496 (defcustom compile-command "make -k "
497 "*Last shell command used to do a compilation; default for next compilation.
498
499 Sometimes it is useful for files to supply local values for this variable.
500 You might also use mode hooks to specify it in certain modes, like this:
501
502 (add-hook 'c-mode-hook
503 (lambda ()
504 (unless (or (file-exists-p \"makefile\")
505 (file-exists-p \"Makefile\"))
506 (set (make-local-variable 'compile-command)
507 (concat \"make -k \"
508 (file-name-sans-extension buffer-file-name))))))"
509 :type 'string
510 :group 'compilation)
511
512 (defvar compilation-directory-stack nil
513 "Stack of previous directories for `compilation-leave-directory-regexp'.
514 The last element is the directory the compilation was started in.")
515
516 (defvar compilation-exit-message-function nil "\
517 If non-nil, called when a compilation process dies to return a status message.
518 This should be a function of three arguments: process status, exit status,
519 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
520 write into the compilation buffer, and to put in its mode line.")
521
522 ;; History of compile commands.
523 (defvar compile-history nil)
524 ;; History of grep commands.
525 (defvar grep-history nil)
526 (defvar grep-find-history nil)
527
528 (defun compilation-mode-font-lock-keywords ()
529 "Return expressions to highlight in Compilation mode."
530 (nconc
531 ;;
532 ;; Compiler warning/error lines.
533 (mapcar (function
534 (lambda (item)
535 ;; Prepend "^", adjusting FILE-IDX and LINE-IDX accordingly.
536 (let ((file-idx (nth 1 item))
537 (line-idx (nth 2 item))
538 (col-idx (nth 3 item))
539 keyword)
540 (when (numberp col-idx)
541 (setq keyword
542 (cons (list (1+ col-idx) 'font-lock-type-face nil t)
543 keyword)))
544 (when (numberp line-idx)
545 (setq keyword
546 (cons (list (1+ line-idx) 'font-lock-variable-name-face)
547 keyword)))
548 (when (numberp file-idx)
549 (setq keyword
550 (cons (list (1+ file-idx) 'font-lock-warning-face)
551 keyword)))
552 (cons (concat "^\\(" (nth 0 item) "\\)") keyword))))
553 compilation-error-regexp-alist)
554 (list
555 ;;
556 ;; Compiler output lines. Recognize `make[n]:' lines too.
557 '("^\\([A-Za-z_0-9/\.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
558 (1 font-lock-function-name-face) (3 font-lock-comment-face nil t)))
559 ))
560
561 ;;;###autoload
562 (defun compile (command)
563 "Compile the program including the current buffer. Default: run `make'.
564 Runs COMMAND, a shell command, in a separate process asynchronously
565 with output going to the buffer `*compilation*'.
566
567 You can then use the command \\[next-error] to find the next error message
568 and move to the source code that caused it.
569
570 Interactively, prompts for the command if `compilation-read-command' is
571 non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
572
573 To run more than one compilation at once, start one and rename the
574 \`*compilation*' buffer to some other name with \\[rename-buffer].
575 Then start the next one.
576
577 The name used for the buffer is actually whatever is returned by
578 the function in `compilation-buffer-name-function', so you can set that
579 to a function that generates a unique name."
580 (interactive
581 (if (or compilation-read-command current-prefix-arg)
582 (list (read-from-minibuffer "Compile command: "
583 (eval compile-command) nil nil
584 '(compile-history . 1)))
585 (list (eval compile-command))))
586 (unless (equal command (eval compile-command))
587 (setq compile-command command))
588 (save-some-buffers (not compilation-ask-about-save) nil)
589 (compile-internal command "No more errors"))
590
591 ;; run compile with the default command line
592 (defun recompile ()
593 "Re-compile the program including the current buffer.
594 If this is run in a compilation-mode buffer, re-use the arguments from the
595 original use. Otherwise, it recompiles using `compile-command'."
596 (interactive)
597 (save-some-buffers (not compilation-ask-about-save) nil)
598 (apply 'compile-internal (or compilation-arguments
599 `(,(eval compile-command) "No more errors"))))
600
601 (defun grep-process-setup ()
602 "Set up `compilation-exit-message-function' for `grep'."
603 (set (make-local-variable 'compilation-exit-message-function)
604 (lambda (status code msg)
605 (if (eq status 'exit)
606 (cond ((zerop code)
607 '("finished (matches found)\n" . "matched"))
608 ((= code 1)
609 '("finished with no matches found\n" . "no match"))
610 (t
611 (cons msg code)))
612 (cons msg code)))))
613
614 (defun grep-compute-defaults () 71 (defun grep-compute-defaults ()
615 (unless (or (not grep-use-null-device) (eq grep-use-null-device t)) 72 (unless (or (not grep-use-null-device) (eq grep-use-null-device t))
616 (setq grep-use-null-device 73 (setq grep-use-null-device
617 (with-temp-buffer 74 (with-temp-buffer
618 (let ((hello-file (expand-file-name "HELLO" data-directory))) 75 (let ((hello-file (expand-file-name "HELLO" data-directory)))
663 (format "%s . -type f -print | xargs %s" 120 (format "%s . -type f -print | xargs %s"
664 find-program grep-command)) 121 find-program grep-command))
665 (t (cons (format "%s . -type f -exec %s {} %s \\;" 122 (t (cons (format "%s . -type f -exec %s {} %s \\;"
666 find-program grep-command null-device) 123 find-program grep-command null-device)
667 (+ 22 (length grep-command)))))))) 124 (+ 22 (length grep-command))))))))
125
126 (defcustom grep-command nil
127 "The default grep command for \\[grep].
128 If the grep program used supports an option to always include file names
129 in its output (such as the `-H' option to GNU grep), it's a good idea to
130 include it when specifying `grep-command'.
131
132 The default value of this variable is set up by `grep-compute-defaults';
133 call that function before using this variable in your program."
134 :type 'string
135 :get '(lambda (symbol)
136 (or grep-command
137 (progn (grep-compute-defaults) grep-command)))
138 :group 'compilation)
139
140 (defcustom grep-use-null-device 'auto-detect
141 "If non-nil, append the value of `null-device' to grep commands.
142 This is done to ensure that the output of grep includes the filename of
143 any match in the case where only a single file is searched, and is not
144 necessary if the grep program used supports the `-H' option.
145
146 The default value of this variable is set up by `grep-compute-defaults';
147 call that function before using this variable in your program."
148 :type 'boolean
149 :get '(lambda (symbol)
150 (if (and grep-use-null-device (not (eq grep-use-null-device t)))
151 (progn (grep-compute-defaults) grep-use-null-device)
152 grep-use-null-device))
153 :group 'compilation)
154
155 (defcustom grep-find-command nil
156 "The default find command for \\[grep-find].
157 The default value of this variable is set up by `grep-compute-defaults';
158 call that function before using this variable in your program."
159 :type 'string
160 :get (lambda (symbol)
161 (or grep-find-command
162 (progn (grep-compute-defaults) grep-find-command)))
163 :group 'compilation)
164
165 (defvar compilation-error-list nil
166 "List of error message descriptors for visiting erring functions.
167 Each error descriptor is a cons (or nil). Its car is a marker pointing to
168 an error message. If its cdr is a marker, it points to the text of the
169 line the message is about. If its cdr is a cons, it is a list
170 \(\(DIRECTORY . FILE\) LINE [COLUMN]\). Or its cdr may be nil if that
171 error is not interesting.
172
173 The value may be t instead of a list; this means that the buffer of
174 error messages should be reparsed the next time the list of errors is wanted.
175
176 Some other commands (like `diff') use this list to control the error
177 message tracking facilities; if you change its structure, you should make
178 sure you also change those packages. Perhaps it is better not to change
179 it at all.")
180
181 (defvar compilation-old-error-list nil
182 "Value of `compilation-error-list' after errors were parsed.")
183
184 (defvar compilation-parse-errors-function 'compilation-parse-errors
185 "Function to call to parse error messages from a compilation.
186 It takes args LIMIT-SEARCH and FIND-AT-LEAST.
187 If LIMIT-SEARCH is non-nil, don't bother parsing past that location.
188 If FIND-AT-LEAST is non-nil, don't bother parsing after finding that
189 many new errors.
190 It should read in the source files which have errors and set
191 `compilation-error-list' to a list with an element for each error message
192 found. See that variable for more info.")
193
194 (defvar compilation-parse-errors-filename-function nil
195 "Function to call to post-process filenames while parsing error messages.
196 It takes one arg FILENAME which is the name of a file as found
197 in the compilation output, and should return a transformed file name.")
198
199 ;;;###autoload
200 (defvar compilation-process-setup-function nil
201 "*Function to call to customize the compilation process.
202 This functions is called immediately before the compilation process is
203 started. It can be used to set any variables or functions that are used
204 while processing the output of the compilation process.")
205
206 ;;;###autoload
207 (defvar compilation-buffer-name-function nil
208 "Function to compute the name of a compilation buffer.
209 The function receives one argument, the name of the major mode of the
210 compilation buffer. It should return a string.
211 nil means compute the name with `(concat \"*\" (downcase major-mode) \"*\")'.")
212
213 ;;;###autoload
214 (defvar compilation-finish-function nil
215 "Function to call when a compilation process finishes.
216 It is called with two arguments: the compilation buffer, and a string
217 describing how the process finished.")
218
219 ;;;###autoload
220 (defvar compilation-finish-functions nil
221 "Functions to call when a compilation process finishes.
222 Each function is called with two arguments: the compilation buffer,
223 and a string describing how the process finished.")
224
225 (defvar compilation-last-buffer nil
226 "The most recent compilation buffer.
227 A buffer becomes most recent when its compilation is started
228 or when it is used with \\[next-error] or \\[compile-goto-error].")
229
230 (defvar compilation-in-progress nil
231 "List of compilation processes now running.")
232 (or (assq 'compilation-in-progress minor-mode-alist)
233 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
234 minor-mode-alist)))
235
236 (defvar compilation-parsing-end nil
237 "Marker position of end of buffer when last error messages were parsed.")
238
239 (defvar compilation-error-message "No more errors"
240 "Message to print when no more matches are found.")
241
242 (defvar compilation-arguments nil
243 "Arguments that were given to `compile-internal'.")
244
245 (defvar compilation-num-errors-found)
246
247 (defvar compilation-error-regexp-alist
248 '(
249 ;; NOTE! See also grep-regexp-alist, below.
250
251 ;; 4.3BSD grep, cc, lint pass 1:
252 ;; /usr/src/foo/foo.c(8): warning: w may be used before set
253 ;; or GNU utilities:
254 ;; foo.c:8: error message
255 ;; or HP-UX 7.0 fc:
256 ;; foo.f :16 some horrible error message
257 ;; or GNU utilities with column (GNAT 1.82):
258 ;; foo.adb:2:1: Unit name does not match file name
259 ;; or with column and program name:
260 ;; jade:dbcommon.dsl:133:17:E: missing argument for function call
261 ;;
262 ;; We'll insist that the number be followed by a colon or closing
263 ;; paren, because otherwise this matches just about anything
264 ;; containing a number with spaces around it.
265
266 ;; We insist on a non-digit in the file name
267 ;; so that we don't mistake the file name for a command name
268 ;; and take the line number as the file name.
269 ("\\([a-zA-Z][-a-zA-Z._0-9]+: ?\\)?\
270 \\([a-zA-Z]?:?[^:( \t\n]*[^:( \t\n0-9][^:( \t\n]*\\)[:(][ \t]*\\([0-9]+\\)\
271 \\([) \t]\\|:\\(\\([0-9]+:\\)\\|[0-9]*[^:0-9]\\)\\)" 2 3 6)
272
273 ;; Microsoft C/C++:
274 ;; keyboard.c(537) : warning C4005: 'min' : macro redefinition
275 ;; d:\tmp\test.c(23) : error C2143: syntax error : missing ';' before 'if'
276 ;; This used to be less selective and allow characters other than
277 ;; parens around the line number, but that caused confusion for
278 ;; GNU-style error messages.
279 ;; This used to reject spaces and dashes in file names,
280 ;; but they are valid now; so I made it more strict about the error
281 ;; message that follows.
282 ("\\(\\([a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\)) \
283 : \\(error\\|warning\\) C[0-9]+:" 1 3)
284
285 ;; Borland C++, C++Builder:
286 ;; Error ping.c 15: Unable to open include file 'sys/types.h'
287 ;; Warning ping.c 68: Call to function 'func' with no prototype
288 ;; Error E2010 ping.c 15: Unable to open include file 'sys/types.h'
289 ;; Warning W1022 ping.c 68: Call to function 'func' with no prototype
290 ("\\(Error\\|Warning\\) \\(\\([FEW][0-9]+\\) \\)?\
291 \\([a-zA-Z]?:?[^:( \t\n]+\\)\
292 \\([0-9]+\\)\\([) \t]\\|:[^0-9\n]\\)" 4 5)
293
294 ;; 4.3BSD lint pass 2
295 ;; strcmp: variable # of args. llib-lc(359) :: /usr/src/foo/foo.c(8)
296 (".*[ \t:]\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(](+[ \t]*\\([0-9]+\\))[:) \t]*$"
297 1 2)
298
299 ;; 4.3BSD lint pass 3
300 ;; bloofle defined( /users/wolfgang/foo.c(4) ), but never used
301 ;; This used to be
302 ;; ("[ \t(]+\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]+" 1 2)
303 ;; which is regexp Impressionism - it matches almost anything!
304 (".*([ \t]*\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\))" 1 2)
305
306 ;; MIPS lint pass<n>; looks good for SunPro lint also
307 ;; TrimMask (255) in solomon.c may be indistinguishable from TrimMasks (93) in solomon.c due to truncation
308 ("[^\n ]+ (\\([0-9]+\\)) in \\([^ \n]+\\)" 2 1)
309 ;; name defined but never used: LinInt in cmap_calc.c(199)
310 (".*in \\([^(\n]+\\)(\\([0-9]+\\))$" 1 2)
311
312 ;; Ultrix 3.0 f77:
313 ;; fort: Severe: addstf.f, line 82: Missing operator or delimiter symbol
314 ;; Some SGI cc version:
315 ;; cfe: Warning 835: foo.c, line 2: something
316 ("\\(cfe\\|fort\\): [^:\n]*: \\([^ \n]*\\), line \\([0-9]+\\):" 2 3)
317 ;; Error on line 3 of t.f: Execution error unclassifiable statement
318 ;; Unknown who does this:
319 ;; Line 45 of "foo.c": bloofle undefined
320 ;; Absoft FORTRAN 77 Compiler 3.1.3
321 ;; error on line 19 of fplot.f: spelling error?
322 ;; warning on line 17 of fplot.f: data type is undefined for variable d
323 ("\\(.* on \\)?[Ll]ine[ \t]+\\([0-9]+\\)[ \t]+\
324 of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2)
325
326 ;; Apollo cc, 4.3BSD fc:
327 ;; "foo.f", line 3: Error: syntax error near end of statement
328 ;; IBM RS6000:
329 ;; "vvouch.c", line 19.5: 1506-046 (S) Syntax error.
330 ;; Microtec mcc68k:
331 ;; "foo.c", line 32 pos 1; (E) syntax error; unexpected symbol: "lossage"
332 ;; GNAT (as of July 94):
333 ;; "foo.adb", line 2(11): warning: file name does not match ...
334 ;; IBM AIX xlc compiler:
335 ;; "src/swapping.c", line 30.34: 1506-342 (W) "/*" detected in comment.
336 (".*\"\\([^,\" \n\t]+\\)\", lines? \
337 \\([0-9]+\\)\\([\(.]\\([0-9]+\\)\)?\\)?[:., (-]" 1 2 4)
338
339 ;; Caml compiler:
340 ;; File "foobar.ml", lines 5-8, characters 20-155: blah blah
341 ("^File \"\\([^,\" \n\t]+\\)\", lines? \\([0-9]+\\)[-0-9]*, characters? \\([0-9]+\\)" 1 2 3)
342
343 ;; MIPS RISC CC - the one distributed with Ultrix:
344 ;; ccom: Error: foo.c, line 2: syntax error
345 ;; DEC AXP OSF/1 cc
346 ;; /usr/lib/cmplrs/cc/cfe: Error: foo.c: 1: blah blah
347 ("[a-z0-9/]+: \\([eE]rror\\|[wW]arning\\): \\([^,\" \n\t]+\\)[,:] \\(line \\)?\\([0-9]+\\):" 2 4)
348
349 ;; IBM AIX PS/2 C version 1.1:
350 ;; ****** Error number 140 in line 8 of file errors.c ******
351 (".*in line \\([0-9]+\\) of file \\([^ \n]+[^. \n]\\)\\.? " 2 1)
352 ;; IBM AIX lint is too painful to do right this way. File name
353 ;; prefixes entire sections rather than being on each line.
354
355 ;; SPARCcompiler Pascal:
356 ;; 20 linjer : array[1..4] of linje;
357 ;; e 18480-----------^--- Inserted ';'
358 ;; and
359 ;; E 18520 line 61 - 0 is undefined
360 ;; These messages don't contain a file name. Instead the compiler gives
361 ;; a message whenever the file being compiled is changed.
362 (" +\\([0-9]+\\) +.*\n[ew] [0-9]+-+" nil 1)
363 ("[Ew] +[0-9]+ line \\([0-9]+\\) - " nil 1)
364
365 ;; Lucid Compiler, lcc 3.x
366 ;; E, file.cc(35,52) Illegal operation on pointers
367 ("[EW], \\([^(\n]*\\)(\\([0-9]+\\),[ \t]*\\([0-9]+\\)" 1 2 3)
368
369 ;; This seems to be superfluous because the first pattern matches it.
370 ;; ;; GNU messages with program name and optional column number.
371 ;; ("[a-zA-Z]?:?[^0-9 \n\t:]+[^ \n\t:]*:[ \t]*\\([^ \n\t:]+\\):\
372 ;;\\([0-9]+\\):\\(\\([0-9]+\\)[: \t]\\)?" 1 2 4)
373
374 ;; Cray C compiler error messages
375 ("\\(cc\\| cft\\)-[0-9]+ c\\(c\\|f77\\): ERROR \\([^,\n]+, \\)* File = \
376 \\([^,\n]+\\), Line = \\([0-9]+\\)" 4 5)
377
378 ;; IBM C/C++ Tools 2.01:
379 ;; foo.c(2:0) : informational EDC0804: Function foo is not referenced.
380 ;; foo.c(3:8) : warning EDC0833: Implicit return statement encountered.
381 ;; foo.c(5:5) : error EDC0350: Syntax error.
382 ("\\([^( \n\t]+\\)(\\([0-9]+\\):\\([0-9]+\\)) : " 1 2 3)
383
384 ;; IAR Systems C Compiler:
385 ;; "foo.c",3 Error[32]: Error message
386 ;; "foo.c",3 Warning[32]: Error message
387 ("\"\\(.*\\)\",\\([0-9]+\\)\\s-+\\(Error\\|Warning\\)\\[[0-9]+\\]:" 1 2)
388
389 ;; Sun ada (VADS, Solaris):
390 ;; /home3/xdhar/rcds_rc/main.a, line 361, char 6:syntax error: "," inserted
391 ("\\([^, \n\t]+\\), line \\([0-9]+\\), char \\([0-9]+\\)[:., \(-]" 1 2 3)
392
393 ;; Perl -w:
394 ;; syntax error at automake line 922, near "':'"
395 ;; Perl debugging traces
396 ;; store::odrecall('File_A', 'x2') called at store.pm line 90
397 (".* at \\([^ \n]+\\) line \\([0-9]+\\)[,.\n]" 1 2)
398
399 ;; Oracle pro*c:
400 ;; Semantic error at line 528, column 5, file erosacqdb.pc:
401 ("Semantic error at line \\([0-9]+\\), column \\([0-9]+\\), file \\(.*\\):"
402 3 1 2)
403
404 ;; EPC F90 compiler:
405 ;; Error 24 at (2:progran.f90) : syntax error
406 ("Error [0-9]+ at (\\([0-9]*\\):\\([^)\n]+\\))" 2 1)
407
408 ;; SGI IRIX MipsPro 7.3 compilers:
409 ;; cc-1070 cc: ERROR File = linkl.c, Line = 38
410 (".*: ERROR File = \\(.+\\), Line = \\([0-9]+\\)" 1 2)
411 (".*: WARNING File = \\(.+\\), Line = \\([0-9]+\\)" 1 2)
412
413 ;; Sun F90 error messages:
414 ;; cf90-113 f90comp: ERROR NSE, File = Hoved.f90, Line = 16, Column = 3
415 (".* ERROR [a-zA-Z0-9 ]+, File = \\(.+\\), Line = \\([0-9]+\\), Column = \\([0-9]+\\)"
416 1 2 3)
417
418 ;; RXP - GPL XML validator at http://www.cogsci.ed.ac.uk/~richard/rxp.html:
419 ;; Error: Mismatched end tag: expected </geroup>, got </group>
420 ;; in unnamed entity at line 71 char 8 of file:///home/reto/test/group.xml
421 ("Error:.*\n.* line \\([0-9]+\\) char \\([0-9]+\\) of file://\\(.+\\)"
422 3 1 2)
423 ;; Warning: Start tag for undeclared element geroup
424 ;; in unnamed entity at line 4 char 8 of file:///home/reto/test/group.xml
425 ("Warning:.*\n.* line \\([0-9]+\\) char \\([0-9]+\\) of file://\\(.+\\)"
426 3 1 2)
427 )
428
429 "Alist that specifies how to match errors in compiler output.
430 Each elt has the form (REGEXP FILE-IDX LINE-IDX [COLUMN-IDX FILE-FORMAT...])
431 If REGEXP matches, the FILE-IDX'th subexpression gives the file name, and
432 the LINE-IDX'th subexpression gives the line number. If COLUMN-IDX is
433 given, the COLUMN-IDX'th subexpression gives the column number on that line.
434 If any FILE-FORMAT is given, each is a format string to produce a file name to
435 try; %s in the string is replaced by the text matching the FILE-IDX'th
436 subexpression.")
437
438 (defvar compilation-enter-directory-regexp-alist
439 '(
440 ;; Matches lines printed by the `-w' option of GNU Make.
441 (".*: Entering directory `\\(.*\\)'$" 1)
442 )
443 "Alist specifying how to match lines that indicate a new current directory.
444 Note that the match is done at the beginning of lines.
445 Each elt has the form (REGEXP IDX).
446 If REGEXP matches, the IDX'th subexpression gives the directory name.
447
448 The default value matches lines printed by the `-w' option of GNU Make.")
449
450 (defvar compilation-leave-directory-regexp-alist
451 '(
452 ;; Matches lines printed by the `-w' option of GNU Make.
453 (".*: Leaving directory `\\(.*\\)'$" 1)
454 )
455 "Alist specifying how to match lines that indicate restoring current directory.
456 Note that the match is done at the beginning of lines.
457 Each elt has the form (REGEXP IDX).
458 If REGEXP matches, the IDX'th subexpression gives the name of the directory
459 being moved from. If IDX is nil, the last directory entered \(by a line
460 matching `compilation-enter-directory-regexp-alist'\) is assumed.
461
462 The default value matches lines printed by the `-w' option of GNU Make.")
463
464 (defvar compilation-file-regexp-alist
465 '(
466 ;; This matches entries with date time year file-name: like
467 ;; Thu May 14 10:46:12 1992 mom3.p:
468 ("\\w\\w\\w \\w\\w\\w +[0-9]+ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9] \\(.*\\):$" 1)
469 )
470 "Alist specifying how to match lines that indicate a new current file.
471 Note that the match is done at the beginning of lines.
472 Each elt has the form (REGEXP IDX).
473 If REGEXP matches, the IDX'th subexpression gives the file name. This is
474 used with compilers that don't indicate file name in every error message.")
475
476 ;; There is no generally useful regexp that will match non messages, but
477 ;; in special cases there might be one. The lines that are not matched by
478 ;; a regexp take much longer time than the ones that are recognized so if
479 ;; you have same regexeps here, parsing is faster.
480 (defvar compilation-nomessage-regexp-alist
481 '(
482 )
483 "Alist specifying how to match lines that have no message.
484 Note that the match is done at the beginning of lines.
485 Each elt has the form (REGEXP). This alist is by default empty, but if
486 you have some good regexps here, the parsing of messages will be faster.")
487
488 (defcustom compilation-error-screen-columns t
489 "*If non-nil, column numbers in error messages are screen columns.
490 Otherwise they are interpreted as character positions, with
491 each character occupying one column.
492 The default is to use screen columns, which requires that the compilation
493 program and Emacs agree about the display width of the characters,
494 especially the TAB character."
495 :type 'boolean
496 :group 'compilation
497 :version "20.4")
498
499 (defcustom compilation-read-command t
500 "*Non-nil means \\[compile] reads the compilation command to use.
501 Otherwise, \\[compile] just uses the value of `compile-command'."
502 :type 'boolean
503 :group 'compilation)
504
505 ;;;###autoload
506 (defcustom compilation-ask-about-save t
507 "*Non-nil means \\[compile] asks which buffers to save before compiling.
508 Otherwise, it saves all modified buffers without asking."
509 :type 'boolean
510 :group 'compilation)
511
512 ;; Note: the character class after the optional drive letter does not
513 ;; include a space to support file names with blanks.
514 (defvar grep-regexp-alist
515 '(("\\([a-zA-Z]?:?[^:(\t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2))
516 "Regexp used to match grep hits. See `compilation-error-regexp-alist'.")
517
518 (defvar grep-program
519 ;; Currently zgrep has trouble. It runs egrep instead of grep,
520 ;; and it doesn't pass along long options right.
521 "grep"
522 ;; (if (equal (condition-case nil ; in case "zgrep" isn't in exec-path
523 ;; (call-process "zgrep" nil nil nil
524 ;; "foo" null-device)
525 ;; (error nil))
526 ;; 1)
527 ;; "zgrep"
528 ;; "grep")
529 "The default grep program for `grep-command' and `grep-find-command'.
530 This variable's value takes effect when `grep-compute-defaults' is called.")
531
532 (defvar find-program "find"
533 "The default find program for `grep-find-command'.
534 This variable's value takes effect when `grep-compute-defaults' is called.")
535
536 (defvar grep-find-use-xargs nil
537 "Whether \\[grep-find] uses the `xargs' utility by default.
538
539 If nil, it uses `grep -exec'; if `gnu', it uses `find -print0' and `xargs -0';
540 if not nil and not `gnu', it uses `find -print' and `xargs'.
541
542 This variable's value takes effect when `grep-compute-defaults' is called.")
543
544 ;;;###autoload
545 (defcustom compilation-search-path '(nil)
546 "*List of directories to search for source files named in error messages.
547 Elements should be directory names, not file names of directories.
548 nil as an element means to try the default directory."
549 :type '(repeat (choice (const :tag "Default" nil)
550 (string :tag "Directory")))
551 :group 'compilation)
552
553 (defcustom compile-command "make -k "
554 "*Last shell command used to do a compilation; default for next compilation.
555
556 Sometimes it is useful for files to supply local values for this variable.
557 You might also use mode hooks to specify it in certain modes, like this:
558
559 (add-hook 'c-mode-hook
560 (lambda ()
561 (unless (or (file-exists-p \"makefile\")
562 (file-exists-p \"Makefile\"))
563 (set (make-local-variable 'compile-command)
564 (concat \"make -k \"
565 (file-name-sans-extension buffer-file-name))))))"
566 :type 'string
567 :group 'compilation)
568
569 (defvar compilation-directory-stack nil
570 "Stack of previous directories for `compilation-leave-directory-regexp'.
571 The last element is the directory the compilation was started in.")
572
573 (defvar compilation-exit-message-function nil "\
574 If non-nil, called when a compilation process dies to return a status message.
575 This should be a function of three arguments: process status, exit status,
576 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
577 write into the compilation buffer, and to put in its mode line.")
578
579 ;; History of compile commands.
580 (defvar compile-history nil)
581 ;; History of grep commands.
582 (defvar grep-history nil)
583 (defvar grep-find-history nil)
584
585 (defun compilation-mode-font-lock-keywords ()
586 "Return expressions to highlight in Compilation mode."
587 (nconc
588 ;;
589 ;; Compiler warning/error lines.
590 (mapcar (function
591 (lambda (item)
592 ;; Prepend "^", adjusting FILE-IDX and LINE-IDX accordingly.
593 (let ((file-idx (nth 1 item))
594 (line-idx (nth 2 item))
595 (col-idx (nth 3 item))
596 keyword)
597 (when (numberp col-idx)
598 (setq keyword
599 (cons (list (1+ col-idx) 'font-lock-type-face nil t)
600 keyword)))
601 (when (numberp line-idx)
602 (setq keyword
603 (cons (list (1+ line-idx) 'font-lock-variable-name-face)
604 keyword)))
605 (when (numberp file-idx)
606 (setq keyword
607 (cons (list (1+ file-idx) 'font-lock-warning-face)
608 keyword)))
609 (cons (concat "^\\(" (nth 0 item) "\\)") keyword))))
610 compilation-error-regexp-alist)
611 (list
612 ;;
613 ;; Compiler output lines. Recognize `make[n]:' lines too.
614 '("^\\([A-Za-z_0-9/\.+-]+\\)\\(\\[\\([0-9]+\\)\\]\\)?[ \t]*:"
615 (1 font-lock-function-name-face) (3 font-lock-comment-face nil t)))
616 ))
617
618 ;;;###autoload
619 (defun compile (command)
620 "Compile the program including the current buffer. Default: run `make'.
621 Runs COMMAND, a shell command, in a separate process asynchronously
622 with output going to the buffer `*compilation*'.
623
624 You can then use the command \\[next-error] to find the next error message
625 and move to the source code that caused it.
626
627 Interactively, prompts for the command if `compilation-read-command' is
628 non-nil; otherwise uses `compile-command'. With prefix arg, always prompts.
629
630 To run more than one compilation at once, start one and rename the
631 \`*compilation*' buffer to some other name with \\[rename-buffer].
632 Then start the next one.
633
634 The name used for the buffer is actually whatever is returned by
635 the function in `compilation-buffer-name-function', so you can set that
636 to a function that generates a unique name."
637 (interactive
638 (if (or compilation-read-command current-prefix-arg)
639 (list (read-from-minibuffer "Compile command: "
640 (eval compile-command) nil nil
641 '(compile-history . 1)))
642 (list (eval compile-command))))
643 (unless (equal command (eval compile-command))
644 (setq compile-command command))
645 (save-some-buffers (not compilation-ask-about-save) nil)
646 (compile-internal command "No more errors"))
647
648 ;; run compile with the default command line
649 (defun recompile ()
650 "Re-compile the program including the current buffer.
651 If this is run in a compilation-mode buffer, re-use the arguments from the
652 original use. Otherwise, it recompiles using `compile-command'."
653 (interactive)
654 (save-some-buffers (not compilation-ask-about-save) nil)
655 (apply 'compile-internal (or compilation-arguments
656 `(,(eval compile-command) "No more errors"))))
657
658 (defun grep-process-setup ()
659 "Set up `compilation-exit-message-function' for `grep'."
660 (set (make-local-variable 'compilation-exit-message-function)
661 (lambda (status code msg)
662 (if (eq status 'exit)
663 (cond ((zerop code)
664 '("finished (matches found)\n" . "matched"))
665 ((= code 1)
666 '("finished with no matches found\n" . "no match"))
667 (t
668 (cons msg code)))
669 (cons msg code)))))
668 670
669 ;;;###autoload 671 ;;;###autoload
670 (defun grep (command-args) 672 (defun grep (command-args)
671 "Run grep, with user-specified args, and collect output in a buffer. 673 "Run grep, with user-specified args, and collect output in a buffer.
672 While grep runs asynchronously, you can use \\[next-error] (M-x next-error), 674 While grep runs asynchronously, you can use \\[next-error] (M-x next-error),