comparison lisp/progmodes/compile.el @ 12920:905444ab8d92

(compilation-exit-message-function): New variable. (compilation-sentinel): If compilation-exit-message-function is non-nil, call it to produce messages for buffer and mode line. (grep): Use that variable to produce snazzier messages.
author Roland McGrath <roland@gnu.org>
date Mon, 21 Aug 1995 22:15:58 +0000
parents 287cc74602fa
children c38b7ee76ecc
comparison
equal deleted inserted replaced
12919:cb9fe3733db5 12920:905444ab8d92
255 255
256 (defvar compilation-directory-stack nil 256 (defvar compilation-directory-stack nil
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 "\
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
263 \(see `set-process-sentinel\); it returns a cons (MESSAGE . MODELINE) of the
264 strings to write into the compilation buffer, and to put in its mode line.")
265
260 ;; History of compile commands. 266 ;; History of compile commands.
261 (defvar compile-history nil) 267 (defvar compile-history nil)
262 ;; History of grep commands. 268 ;; History of grep commands.
263 (defvar grep-history nil) 269 (defvar grep-history nil)
264 270
265 (defvar compilation-mode-font-lock-keywords 271 (defvar compilation-mode-font-lock-keywords
266 '(("^\\([^\n:]*:\\([0-9]+:\\)+\\)\\(.*\\)$" 1 font-lock-function-name-face)) 272 '(("^\\([^\n:]*:\\([0-9]+:\\)+\\)\\(.*\\)$" 1 font-lock-function-name-face))
267 ;;; ("^\\([^\n:]*:\\([0-9]+:\\)+\\)\\(.*\\)$" 0 font-lock-keyword-face keep) 273 ;;; ("^\\([^\n:]*:\\([0-9]+:\\)+\\)\\(.*\\)$" 0 font-lock-keyword-face keep)
268 "Additional expressions to highlight in Compilation mode.") 274 "Additional expressions to highlight in Compilation mode.")
269 275
270 ;;;###autoload 276 ;;;###autoload
271 (defun compile (command) 277 (defun compile (command)
272 "Compile the program including the current buffer. Default: run `make'. 278 "Compile the program including the current buffer. Default: run `make'.
273 Runs COMMAND, a shell command, in a separate process asynchronously 279 Runs COMMAND, a shell command, in a separate process asynchronously
274 with output going to the buffer `*compilation*'. 280 with output going to the buffer `*compilation*'.
315 This command uses a special history list for its arguments, so you can 321 This command uses a special history list for its arguments, so you can
316 easily repeat a grep command." 322 easily repeat a grep command."
317 (interactive 323 (interactive
318 (list (read-from-minibuffer "Run grep (like this): " 324 (list (read-from-minibuffer "Run grep (like this): "
319 grep-command nil nil 'grep-history))) 325 grep-command nil nil 'grep-history)))
320 (compile-internal (concat command-args " " grep-null-device) 326 (let ((buf (compile-internal (concat command-args " " grep-null-device)
321 "No more grep hits" "grep" 327 "No more grep hits" "grep"
322 ;; Give it a simpler regexp to match. 328 ;; Give it a simpler regexp to match.
323 nil grep-regexp-alist)) 329 nil grep-regexp-alist)))
330 (save-excursion
331 (set-buffer buf)
332 (set (make-local-variable 'compilation-exit-message-function)
333 (lambda (proc msg)
334 (let ((code (process-exit-status proc)))
335 (if (eq (process-status proc) 'exit)
336 (cond ((zerop code)
337 '("finished (matches found)\n" . "matched"))
338 ((= code 1)
339 '("finished with no matches found\n" . "no match"))
340 (t
341 (cons msg code)))
342 (cons msg code))))))))
324 343
325 (defun compile-internal (command error-message 344 (defun compile-internal (command error-message
326 &optional name-of-mode parser regexp-alist 345 &optional name-of-mode parser regexp-alist
327 name-function) 346 name-function)
328 "Run compilation command COMMAND (low level interface). 347 "Run compilation command COMMAND (low level interface).
544 (progn 563 (progn
545 (if (null (buffer-name buffer)) 564 (if (null (buffer-name buffer))
546 ;; buffer killed 565 ;; buffer killed
547 (set-process-buffer proc nil) 566 (set-process-buffer proc nil)
548 (let ((obuf (current-buffer)) 567 (let ((obuf (current-buffer))
549 omax opoint) 568 omax opoint
569 (status (if compilation-exit-message-function
570 (funcall compilation-exit-message-function
571 proc msg)
572 (cons msg (process-exit-status proc)))))
550 ;; save-excursion isn't the right thing if 573 ;; save-excursion isn't the right thing if
551 ;; process-buffer is current-buffer 574 ;; process-buffer is current-buffer
552 (unwind-protect 575 (unwind-protect
553 (progn 576 (progn
554 ;; Write something in the compilation buffer 577 ;; Write something in the compilation buffer
558 (setq omax (point-max) 581 (setq omax (point-max)
559 opoint (point)) 582 opoint (point))
560 (goto-char omax) 583 (goto-char omax)
561 ;; Record where we put the message, so we can ignore it 584 ;; Record where we put the message, so we can ignore it
562 ;; later on. 585 ;; later on.
563 (insert ?\n mode-name " " msg) 586 (insert ?\n mode-name " " (car status))
564 (forward-char -1) 587 (forward-char -1)
565 (insert " at " (substring (current-time-string) 0 19)) 588 (insert " at " (substring (current-time-string) 0 19))
566 (forward-char 1) 589 (forward-char 1)
567 (setq mode-line-process 590 (setq mode-line-process
568 (format ":%s [%d]" (process-status proc) 591 (format ":%s [%s]"
569 (process-exit-status proc))) 592 (process-status proc) (cdr status)))
570 ;; Since the buffer and mode line will show that the 593 ;; Since the buffer and mode line will show that the
571 ;; process is dead, we can delete it now. Otherwise it 594 ;; process is dead, we can delete it now. Otherwise it
572 ;; will stay around until M-x list-processes. 595 ;; will stay around until M-x list-processes.
573 (delete-process proc) 596 (delete-process proc)
574 ;; Force mode line redisplay soon. 597 ;; Force mode line redisplay soon.