aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland McGrath1996-01-06 20:54:19 +0000
committerRoland McGrath1996-01-06 20:54:19 +0000
commitfd5e58d78df3745e518659b3c4c5f2c07e246018 (patch)
tree74e249b0b696862147d1b15ea4cde1ae803de420
parent0f09bac62e88bb00387efc56aafed095672f773e (diff)
downloademacs-fd5e58d78df3745e518659b3c4c5f2c07e246018.tar.gz
emacs-fd5e58d78df3745e518659b3c4c5f2c07e246018.zip
(compilation-handle-exit): New function, broken out of compilation-sentinel.
(compilation-sentinel, compile-internal): Use it. (compilation-exit-message-function): Doc fix for protocol change: take process status and exit-code args instead of process object. (grep): Use new protocol for compilation-exit-message-function.
-rw-r--r--lisp/progmodes/compile.el135
1 files changed, 65 insertions, 70 deletions
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 99426a3665a..464fcc90d3a 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -1,6 +1,6 @@
1;;; compile.el --- run compiler as inferior of Emacs, parse error messages. 1;;; compile.el --- run compiler as inferior of Emacs, parse error messages.
2 2
3;; Copyright (C) 1985, 86, 87, 93, 94, 1995 Free Software Foundation, Inc. 3;; Copyright (C) 1985, 86, 87, 93, 94, 1995, 1996 Free Software Foundation, Inc.
4 4
5;; Author: Roland McGrath <roland@prep.ai.mit.edu> 5;; Author: Roland McGrath <roland@prep.ai.mit.edu>
6;; Maintainer: FSF 6;; Maintainer: FSF
@@ -259,9 +259,9 @@ The head element is the directory the compilation was started in.")
259 259
260(defvar compilation-exit-message-function nil "\ 260(defvar compilation-exit-message-function nil "\
261If non-nil, called when a compilation process dies to return a status message. 261If non-nil, called when a compilation process dies to return a status message.
262This should be a function a two arguments as passed to a process sentinel 262This should be a function of three arguments: process status, exit status,
263\(see `set-process-sentinel\); it returns a cons (MESSAGE . MODELINE) of the 263and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to
264strings to write into the compilation buffer, and to put in its mode line.") 264write into the compilation buffer, and to put in its mode line.")
265 265
266;; History of compile commands. 266;; History of compile commands.
267(defvar compile-history nil) 267(defvar compile-history nil)
@@ -331,16 +331,15 @@ easily repeat a grep command."
331 (save-excursion 331 (save-excursion
332 (set-buffer buf) 332 (set-buffer buf)
333 (set (make-local-variable 'compilation-exit-message-function) 333 (set (make-local-variable 'compilation-exit-message-function)
334 (lambda (proc msg) 334 (lambda (status code msg)
335 (let ((code (process-exit-status proc))) 335 (if (eq status 'exit)
336 (if (eq (process-status proc) 'exit) 336 (cond ((zerop code)
337 (cond ((zerop code) 337 '("finished (matches found)\n" . "matched"))
338 '("finished (matches found)\n" . "matched")) 338 ((= code 1)
339 ((= code 1) 339 '("finished with no matches found\n" . "no match"))
340 '("finished with no matches found\n" . "no match")) 340 (t
341 (t 341 (cons msg code)))
342 (cons msg code))) 342 (cons msg code)))))))
343 (cons msg code))))))))
344 343
345(defun compile-internal (command error-message 344(defun compile-internal (command error-message
346 &optional name-of-mode parser regexp-alist 345 &optional name-of-mode parser regexp-alist
@@ -434,36 +433,27 @@ Returns the compilation buffer created."
434 (set-marker (process-mark proc) (point) outbuf) 433 (set-marker (process-mark proc) (point) outbuf)
435 (setq compilation-in-progress 434 (setq compilation-in-progress
436 (cons proc compilation-in-progress))) 435 (cons proc compilation-in-progress)))
437 ;; No asynchronous processes available 436 ;; No asynchronous processes available.
438 (message (format "Executing `%s'..." command)) 437 (message "Executing `%s'..." command)
439 ;; Fake modeline display as if `start-process' were run. 438 ;; Fake modeline display as if `start-process' were run.
440 (setq mode-line-process ":run") 439 (setq mode-line-process ":run")
441 (sit-for 0) ;; Force redisplay 440 (force-mode-line-update)
441 (sit-for 0) ; Force redisplay
442 (let ((status (call-process shell-file-name nil outbuf nil "-c" 442 (let ((status (call-process shell-file-name nil outbuf nil "-c"
443 command)) 443 command)))
444 finish-msg) 444 (cond ((numberp status)
445 ;; Fake modeline after exit. 445 (compilation-handle-exit 'exit status
446 (setq mode-line-process 446 (if (zerop status)
447 (cond ((numberp status) (format ":exit[%d]" status)) 447 "finished\n"
448 ((stringp status) (format ":exit[-1: %s]" status)) 448 (format "\
449 (t ":exit[???]"))) 449exited abnormally with code %d\n"
450 ;; Call `compilation-finish-function' as `compilation-sentinel' 450 status))))
451 ;; would, and finish up the compilation buffer with the same 451 ((stringp status)
452 ;; message we would get from `start-process'. 452 (compilation-handle-exit 'signal status
453 (setq finish-msg 453 (concat status "\n")))
454 (if (numberp status) 454 (t
455 (if (zerop status) 455 (compilation-handle-exit 'bizarre status status))))
456 "finished\n" 456 (message "Executing `%s'...done" command))))
457 (format "exited abnormally with code %d\n" status))
458 "exited abnormally with code -1\n"))
459 (goto-char (point-max))
460 (insert "\nCompilation " finish-msg)
461 (forward-char -1)
462 (insert " at " (substring (current-time-string) 0 19)) ; no year
463 (forward-char 1)
464 (if compilation-finish-function
465 (funcall compilation-finish-function outbuf finish-msg)))
466 (message (format "Executing `%s'...done" command)))))
467 ;; Make it so the next C-x ` will use this buffer. 457 ;; Make it so the next C-x ` will use this buffer.
468 (setq compilation-last-buffer outbuf))) 458 (setq compilation-last-buffer outbuf)))
469 459
@@ -581,6 +571,32 @@ See `compilation-mode'."
581 (> (prefix-numeric-value arg) 0))) 571 (> (prefix-numeric-value arg) 0)))
582 (compilation-setup))) 572 (compilation-setup)))
583 573
574;; Write msg in the current buffer and hack its mode-line-process.
575(defun compilation-handle-exit (process-status exit-status msg)
576 (let ((buffer-read-only nil)
577 (status (if compilation-exit-message-function
578 (funcall compilation-exit-message-function
579 process-status exit-status msg)
580 (cons msg exit-status)))
581 (omax (point-max))
582 (opoint (point)))
583 ;; Record where we put the message, so we can ignore it
584 ;; later on.
585 (goto-char omax)
586 (insert ?\n mode-name " " (car status))
587 (forward-char -1)
588 (insert " at " (substring (current-time-string) 0 19))
589 (forward-char 1)
590 (setq mode-line-process
591 (format ":%s [%s]"
592 (process-status proc) (cdr status)))
593 ;; Force mode line redisplay soon.
594 (force-mode-line-update)
595 (if (and opoint (< opoint omax))
596 (goto-char opoint))
597 (if compilation-finish-function
598 (funcall compilation-finish-function buffer msg))))
599
584;; Called when compilation process changes state. 600;; Called when compilation process changes state.
585(defun compilation-sentinel (proc msg) 601(defun compilation-sentinel (proc msg)
586 "Sentinel for compilation buffers." 602 "Sentinel for compilation buffers."
@@ -590,8 +606,7 @@ See `compilation-mode'."
590 (if (null (buffer-name buffer)) 606 (if (null (buffer-name buffer))
591 ;; buffer killed 607 ;; buffer killed
592 (set-process-buffer proc nil) 608 (set-process-buffer proc nil)
593 (let ((obuf (current-buffer)) 609 (let ((obuf (current-buffer)))
594 omax opoint)
595 ;; save-excursion isn't the right thing if 610 ;; save-excursion isn't the right thing if
596 ;; process-buffer is current-buffer 611 ;; process-buffer is current-buffer
597 (unwind-protect 612 (unwind-protect
@@ -599,33 +614,13 @@ See `compilation-mode'."
599 ;; Write something in the compilation buffer 614 ;; Write something in the compilation buffer
600 ;; and hack its mode line. 615 ;; and hack its mode line.
601 (set-buffer buffer) 616 (set-buffer buffer)
602 (let ((buffer-read-only nil) 617 (compilation-handle-exit (process-status proc)
603 (status (if compilation-exit-message-function 618 (process-exit-status proc)
604 (funcall compilation-exit-message-function 619 msg)
605 proc msg) 620 ;; Since the buffer and mode line will show that the
606 (cons msg (process-exit-status proc))))) 621 ;; process is dead, we can delete it now. Otherwise it
607 (setq omax (point-max) 622 ;; will stay around until M-x list-processes.
608 opoint (point)) 623 (delete-process proc))
609 (goto-char omax)
610 ;; Record where we put the message, so we can ignore it
611 ;; later on.
612 (insert ?\n mode-name " " (car status))
613 (forward-char -1)
614 (insert " at " (substring (current-time-string) 0 19))
615 (forward-char 1)
616 (setq mode-line-process
617 (format ":%s [%s]"
618 (process-status proc) (cdr status)))
619 ;; Since the buffer and mode line will show that the
620 ;; process is dead, we can delete it now. Otherwise it
621 ;; will stay around until M-x list-processes.
622 (delete-process proc)
623 ;; Force mode line redisplay soon.
624 (force-mode-line-update))
625 (if (and opoint (< opoint omax))
626 (goto-char opoint))
627 (if compilation-finish-function
628 (funcall compilation-finish-function buffer msg)))
629 (set-buffer obuf)))) 624 (set-buffer obuf))))
630 (setq compilation-in-progress (delq proc compilation-in-progress)) 625 (setq compilation-in-progress (delq proc compilation-in-progress))
631 )))) 626 ))))