comparison lisp/progmodes/compile.el @ 55299:19ff0d2ea8e8

(compilation-messages-start): New var. (compilation-mode): Don't setup next-error-function here. (compilation-setup): Set it up here instead (for minor modes as well). Make compilation-messages-start buffer local. (compilation-next-error-function): Use it. (compilation-forget-errors): Set compilation-messages-start.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 01 May 2004 21:13:00 +0000
parents 37068e6cd644
children 3757f583f280
comparison
equal deleted inserted replaced
55298:72ed5a7627d2 55299:19ff0d2ea8e8
1093 (setq major-mode 'compilation-mode 1093 (setq major-mode 'compilation-mode
1094 mode-name "Compilation") 1094 mode-name "Compilation")
1095 (set (make-local-variable 'page-delimiter) 1095 (set (make-local-variable 'page-delimiter)
1096 compilation-page-delimiter) 1096 compilation-page-delimiter)
1097 (compilation-setup) 1097 (compilation-setup)
1098 ;; note that compilation-next-error-function is for interfacing
1099 ;; with the next-error function in simple.el, and it's only
1100 ;; coincidentally named similarly to compilation-next-error
1101 (setq next-error-function 'compilation-next-error-function)
1102 (run-mode-hooks 'compilation-mode-hook)) 1098 (run-mode-hooks 'compilation-mode-hook))
1103 1099
1104 (defmacro define-compilation-mode (mode name doc &rest body) 1100 (defmacro define-compilation-mode (mode name doc &rest body)
1105 "This is like `define-derived-mode' without the PARENT argument. 1101 "This is like `define-derived-mode' without the PARENT argument.
1106 The parent is always `compilation-mode' and the customizable `compilation-...' 1102 The parent is always `compilation-mode' and the customizable `compilation-...'
1148 1144
1149 (defvar compilation-current-error nil 1145 (defvar compilation-current-error nil
1150 "Marker to the location from where the next error will be found. 1146 "Marker to the location from where the next error will be found.
1151 The global commands next/previous/first-error/goto-error use this.") 1147 The global commands next/previous/first-error/goto-error use this.")
1152 1148
1149 (defvar compilation-messages-start nil
1150 "Buffer position of the beginning of the compilation messages.
1151 If nil, use the beginning of buffer.")
1152
1153 ;; A function name can't be a hook, must be something with a value. 1153 ;; A function name can't be a hook, must be something with a value.
1154 (defconst compilation-turn-on-font-lock 'turn-on-font-lock) 1154 (defconst compilation-turn-on-font-lock 'turn-on-font-lock)
1155 1155
1156 (defun compilation-setup (&optional minor) 1156 (defun compilation-setup (&optional minor)
1157 "Prepare the buffer for the compilation parsing commands to work. 1157 "Prepare the buffer for the compilation parsing commands to work.
1158 Optional argument MINOR indicates this is called from 1158 Optional argument MINOR indicates this is called from
1159 `compilation-minor-mode'." 1159 `compilation-minor-mode'."
1160 (make-local-variable 'compilation-current-error) 1160 (make-local-variable 'compilation-current-error)
1161 (make-local-variable 'compilation-messages-start)
1161 (make-local-variable 'compilation-error-screen-columns) 1162 (make-local-variable 'compilation-error-screen-columns)
1162 (make-local-variable 'overlay-arrow-position) 1163 (make-local-variable 'overlay-arrow-position)
1164 ;; Note that compilation-next-error-function is for interfacing
1165 ;; with the next-error function in simple.el, and it's only
1166 ;; coincidentally named similarly to compilation-next-error.
1167 (setq next-error-function 'compilation-next-error-function)
1163 (set (make-local-variable 'font-lock-extra-managed-props) 1168 (set (make-local-variable 'font-lock-extra-managed-props)
1164 '(directory message help-echo mouse-face debug)) 1169 '(directory message help-echo mouse-face debug))
1165 (set (make-local-variable 'compilation-locs) 1170 (set (make-local-variable 'compilation-locs)
1166 (make-hash-table :test 'equal :weakness 'value)) 1171 (make-hash-table :test 'equal :weakness 'value))
1167 ;; lazy-lock would never find the message unless it's scrolled to. 1172 ;; lazy-lock would never find the message unless it's scrolled to.
1402 (when reset 1407 (when reset
1403 (setq compilation-current-error nil)) 1408 (setq compilation-current-error nil))
1404 (let* ((columns compilation-error-screen-columns) ; buffer's local value 1409 (let* ((columns compilation-error-screen-columns) ; buffer's local value
1405 (last 1) 1410 (last 1)
1406 (loc (compilation-next-error (or n 1) nil 1411 (loc (compilation-next-error (or n 1) nil
1407 (or compilation-current-error (point-min)))) 1412 (or compilation-current-error
1413 compilation-messages-start
1414 (point-min))))
1408 (end-loc (nth 2 loc)) 1415 (end-loc (nth 2 loc))
1409 (marker (point-marker))) 1416 (marker (point-marker)))
1410 (setq compilation-current-error (point-marker) 1417 (setq compilation-current-error (point-marker)
1411 overlay-arrow-position 1418 overlay-arrow-position
1412 (if (bolp) 1419 (if (bolp)
1413 compilation-current-error 1420 compilation-current-error
1414 (save-excursion 1421 (copy-marker (line-beginning-position)))
1415 (beginning-of-line)
1416 (point-marker)))
1417 loc (car loc)) 1422 loc (car loc))
1418 ;; If loc contains no marker, no error in that file has been visited. If 1423 ;; If loc contains no marker, no error in that file has been visited. If
1419 ;; the marker is invalid the buffer has been killed. So, recalculate all 1424 ;; the marker is invalid the buffer has been killed. So, recalculate all
1420 ;; markers for that file. 1425 ;; markers for that file.
1421 (unless (and (nth 3 loc) (marker-buffer (nth 3 loc))) 1426 (unless (and (nth 3 loc) (marker-buffer (nth 3 loc)))
1713 (put-text-property src (line-end-position) 1718 (put-text-property src (line-end-position)
1714 'message (list loc 2))))))) 1719 'message (list loc 2)))))))
1715 (goto-char limit) 1720 (goto-char limit)
1716 nil) 1721 nil)
1717 1722
1723 ;; Beware: this is not only compatiblity code. New code stil uses it. --Stef
1718 (defun compilation-forget-errors () 1724 (defun compilation-forget-errors ()
1719 ;; In case we hit the same file/line specs, we want to recompute a new 1725 ;; In case we hit the same file/line specs, we want to recompute a new
1720 ;; marker for them, so flush our cache. 1726 ;; marker for them, so flush our cache.
1721 (setq compilation-locs (make-hash-table :test 'equal :weakness 'value)) 1727 (setq compilation-locs (make-hash-table :test 'equal :weakness 'value))
1722 ;; FIXME: the old code reset the directory-stack, so maybe we should 1728 ;; FIXME: the old code reset the directory-stack, so maybe we should
1728 ;; the internal uses of compilation-forget-errors: all calls from external 1734 ;; the internal uses of compilation-forget-errors: all calls from external
1729 ;; packages seem to be followed by a move of compilation-parsing-end to 1735 ;; packages seem to be followed by a move of compilation-parsing-end to
1730 ;; something equivalent to point-max. So we speculatively move 1736 ;; something equivalent to point-max. So we speculatively move
1731 ;; compilation-current-error to point-max (since the external package 1737 ;; compilation-current-error to point-max (since the external package
1732 ;; won't know that it should do it). --stef 1738 ;; won't know that it should do it). --stef
1733 (setq compilation-current-error (point-max))) 1739 (setq compilation-current-error nil)
1740 (let* ((proc (get-buffer-process (current-buffer)))
1741 (mark (if proc (process-mark proc)))
1742 (pos (or mark (point-max))))
1743 (setq compilation-messages-start
1744 ;; In the future, ignore the text already present in the buffer.
1745 ;; Since many process filter functions insert before markers,
1746 ;; we need to put ours just before the insertion point rather
1747 ;; than at the insertion point. If that's not possible, then
1748 ;; don't use a marker. --Stef
1749 (if (> pos (point-min)) (copy-marker (1- pos)) pos))))
1734 1750
1735 (provide 'compile) 1751 (provide 'compile)
1736 1752
1737 ;;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c 1753 ;;; arch-tag: 12465727-7382-4f72-b234-79855a00dd8c
1738 ;;; compile.el ends here 1754 ;;; compile.el ends here