Mercurial > emacs
comparison lisp/progmodes/compile.el @ 14045:1300c7703f67
(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.
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Sat, 06 Jan 1996 20:54:19 +0000 |
parents | 6d4e18531dd2 |
children | 000d4719b874 |
comparison
equal
deleted
inserted
replaced
14044:1c331f9332ae | 14045:1300c7703f67 |
---|---|
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 |
7 ;; Keywords: tools, processes | 7 ;; Keywords: tools, processes |
8 | 8 |
257 "Stack of previous directories for `compilation-leave-directory-regexp'. | 257 "Stack of previous directories for `compilation-leave-directory-regexp'. |
258 The head element is the directory the compilation was started in.") | 258 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 "\ |
261 If non-nil, called when a compilation process dies to return a status message. | 261 If non-nil, called when a compilation process dies to return a status message. |
262 This should be a function a two arguments as passed to a process sentinel | 262 This should be a function of three arguments: process status, exit status, |
263 \(see `set-process-sentinel\); it returns a cons (MESSAGE . MODELINE) of the | 263 and exit message; it returns a cons (MESSAGE . MODELINE) of the strings to |
264 strings to write into the compilation buffer, and to put in its mode line.") | 264 write 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) |
268 ;; History of grep commands. | 268 ;; History of grep commands. |
269 (defvar grep-history nil) | 269 (defvar grep-history nil) |
329 ;; Give it a simpler regexp to match. | 329 ;; Give it a simpler regexp to match. |
330 nil grep-regexp-alist))) | 330 nil grep-regexp-alist))) |
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 |
347 name-function) | 346 name-function) |
348 "Run compilation command COMMAND (low level interface). | 347 "Run compilation command COMMAND (low level interface). |
432 (set-process-sentinel proc 'compilation-sentinel) | 431 (set-process-sentinel proc 'compilation-sentinel) |
433 (set-process-filter proc 'compilation-filter) | 432 (set-process-filter proc 'compilation-filter) |
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[???]"))) | 449 exited 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 |
470 ;; Set the height of WINDOW according to compilation-window-height. | 460 ;; Set the height of WINDOW according to compilation-window-height. |
471 (defun compilation-set-window-height (window) | 461 (defun compilation-set-window-height (window) |
579 (if (setq compilation-minor-mode (if (null arg) | 569 (if (setq compilation-minor-mode (if (null arg) |
580 (null compilation-minor-mode) | 570 (null compilation-minor-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." |
587 (let ((buffer (process-buffer proc))) | 603 (let ((buffer (process-buffer proc))) |
588 (if (memq (process-status proc) '(signal exit)) | 604 (if (memq (process-status proc) '(signal exit)) |
589 (progn | 605 (progn |
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 |
598 (progn | 613 (progn |
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 )))) |
632 | 627 |
633 (defun compilation-filter (proc string) | 628 (defun compilation-filter (proc string) |