Mercurial > emacs
comparison lisp/progmodes/compile.el @ 55068:0cdcedeb25c5
From: Teodor Zlatanov <tzz@lifelogs.com>
(compilation-start): Set next-error-last-buffer so
next-error knows where to jump.
(compilation-setup): Set the buffer-local variable
next-error-function to 'compilation-next-error-function.
(compilation-buffer-p, compilation-buffer-internal-p): Use an
alternate way to find if a buffer is a compilation buffer, for
next-error convenience.
(next-error-no-select, previous-error-no-select, next-error)
(previous-error, first-error): Move to simple.el.
(compilation-find-buffer): Move to next-error-find-buffer in simple.el.
(compilation-last-buffer): Remove.
(compilation-start, compilation-next-error, compilation-setup)
(compilation-next-error-function, compilation-find-buffer):
Remove compilation-last-buffer use.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Wed, 21 Apr 2004 21:37:18 +0000 |
parents | c4901d9dd86a |
children | b8afe141e350 |
comparison
equal
deleted
inserted
replaced
55067:b335edb455ad | 55068:0cdcedeb25c5 |
---|---|
122 ;;;###autoload | 122 ;;;###autoload |
123 (defvar compilation-finish-functions nil | 123 (defvar compilation-finish-functions nil |
124 "Functions to call when a compilation process finishes. | 124 "Functions to call when a compilation process finishes. |
125 Each function is called with two arguments: the compilation buffer, | 125 Each function is called with two arguments: the compilation buffer, |
126 and a string describing how the process finished.") | 126 and a string describing how the process finished.") |
127 | |
128 (defvar compilation-last-buffer nil | |
129 "The most recent compilation buffer. | |
130 A buffer becomes most recent when its compilation is started | |
131 or when it is used with \\[next-error] or \\[compile-goto-error].") | |
132 | 127 |
133 (defvar compilation-in-progress nil | 128 (defvar compilation-in-progress nil |
134 "List of compilation processes now running.") | 129 "List of compilation processes now running.") |
135 (or (assq 'compilation-in-progress minor-mode-alist) | 130 (or (assq 'compilation-in-progress minor-mode-alist) |
136 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling") | 131 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling") |
966 (if (buffer-local-value 'compilation-scroll-output outbuf) | 961 (if (buffer-local-value 'compilation-scroll-output outbuf) |
967 (save-selected-window | 962 (save-selected-window |
968 (select-window outwin) | 963 (select-window outwin) |
969 (goto-char (point-max)))) | 964 (goto-char (point-max)))) |
970 ;; Make it so the next C-x ` will use this buffer. | 965 ;; Make it so the next C-x ` will use this buffer. |
971 (setq compilation-last-buffer outbuf))) | 966 (setq next-error-last-buffer outbuf))) |
972 | 967 |
973 (defun compilation-set-window-height (window) | 968 (defun compilation-set-window-height (window) |
974 "Set the height of WINDOW according to `compilation-window-height'." | 969 "Set the height of WINDOW according to `compilation-window-height'." |
975 (let ((height (buffer-local-value 'compilation-window-height (window-buffer window)))) | 970 (let ((height (buffer-local-value 'compilation-window-height (window-buffer window)))) |
976 (and height | 971 (and height |
1097 (setq major-mode 'compilation-mode | 1092 (setq major-mode 'compilation-mode |
1098 mode-name "Compilation") | 1093 mode-name "Compilation") |
1099 (set (make-local-variable 'page-delimiter) | 1094 (set (make-local-variable 'page-delimiter) |
1100 compilation-page-delimiter) | 1095 compilation-page-delimiter) |
1101 (compilation-setup) | 1096 (compilation-setup) |
1097 ;; note that compilation-next-error-function is for interfacing | |
1098 ;; with the next-error function in simple.el, and it's only | |
1099 ;; coincidentally named similarly to compilation-next-error | |
1100 (setq next-error-function 'compilation-next-error-function) | |
1102 (run-mode-hooks 'compilation-mode-hook)) | 1101 (run-mode-hooks 'compilation-mode-hook)) |
1103 | 1102 |
1104 (defmacro define-compilation-mode (mode name doc &rest body) | 1103 (defmacro define-compilation-mode (mode name doc &rest body) |
1105 "This is like `define-derived-mode' without the PARENT argument. | 1104 "This is like `define-derived-mode' without the PARENT argument. |
1106 The parent is always `compilation-mode' and the customizable `compilation-...' | 1105 The parent is always `compilation-mode' and the customizable `compilation-...' |
1158 Optional argument MINOR indicates this is called from | 1157 Optional argument MINOR indicates this is called from |
1159 `compilation-minor-mode'." | 1158 `compilation-minor-mode'." |
1160 (make-local-variable 'compilation-current-error) | 1159 (make-local-variable 'compilation-current-error) |
1161 (make-local-variable 'compilation-error-screen-columns) | 1160 (make-local-variable 'compilation-error-screen-columns) |
1162 (make-local-variable 'overlay-arrow-position) | 1161 (make-local-variable 'overlay-arrow-position) |
1163 (setq compilation-last-buffer (current-buffer)) | |
1164 (set (make-local-variable 'font-lock-extra-managed-props) | 1162 (set (make-local-variable 'font-lock-extra-managed-props) |
1165 '(directory message help-echo mouse-face debug)) | 1163 '(directory message help-echo mouse-face debug)) |
1166 (set (make-local-variable 'compilation-locs) | 1164 (set (make-local-variable 'compilation-locs) |
1167 (make-hash-table :test 'equal :weakness 'value)) | 1165 (make-hash-table :test 'equal :weakness 'value)) |
1168 ;; lazy-lock would never find the message unless it's scrolled to. | 1166 ;; lazy-lock would never find the message unless it's scrolled to. |
1275 (save-excursion | 1273 (save-excursion |
1276 (goto-char (process-mark proc)) | 1274 (goto-char (process-mark proc)) |
1277 (insert-before-markers string) | 1275 (insert-before-markers string) |
1278 (run-hooks 'compilation-filter-hook)))))) | 1276 (run-hooks 'compilation-filter-hook)))))) |
1279 | 1277 |
1278 ;;; test if a buffer is a compilation buffer, assuming we're in the buffer | |
1279 (defsubst compilation-buffer-internal-p () | |
1280 "Test if inside a compilation buffer." | |
1281 (local-variable-p 'compilation-locs)) | |
1282 | |
1283 ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p | |
1280 (defsubst compilation-buffer-p (buffer) | 1284 (defsubst compilation-buffer-p (buffer) |
1281 (local-variable-p 'compilation-locs buffer)) | 1285 "Test if BUFFER is a compilation buffer." |
1286 (with-current-buffer buffer | |
1287 (compilation-buffer-internal-p))) | |
1282 | 1288 |
1283 (defmacro compilation-loop (< property-change 1+ error) | 1289 (defmacro compilation-loop (< property-change 1+ error) |
1284 `(while (,< n 0) | 1290 `(while (,< n 0) |
1285 (or (setq pt (,property-change pt 'message)) | 1291 (or (setq pt (,property-change pt 'message)) |
1286 (error ,error compilation-error)) | 1292 (error ,error compilation-error)) |
1307 Does NOT find the source line like \\[next-error]." | 1313 Does NOT find the source line like \\[next-error]." |
1308 (interactive "p") | 1314 (interactive "p") |
1309 (or (compilation-buffer-p (current-buffer)) | 1315 (or (compilation-buffer-p (current-buffer)) |
1310 (error "Not in a compilation buffer")) | 1316 (error "Not in a compilation buffer")) |
1311 (or pt (setq pt (point))) | 1317 (or pt (setq pt (point))) |
1312 (setq compilation-last-buffer (current-buffer)) | |
1313 (let* ((msg (get-text-property pt 'message)) | 1318 (let* ((msg (get-text-property pt 'message)) |
1314 (loc (car msg)) | 1319 (loc (car msg)) |
1315 last) | 1320 last) |
1316 (if (zerop n) | 1321 (if (zerop n) |
1317 (unless (or msg ; find message near here | 1322 (unless (or msg ; find message near here |
1345 forwards, if negative). | 1350 forwards, if negative). |
1346 Does NOT find the source line like \\[previous-error]." | 1351 Does NOT find the source line like \\[previous-error]." |
1347 (interactive "p") | 1352 (interactive "p") |
1348 (compilation-next-error (- n))) | 1353 (compilation-next-error (- n))) |
1349 | 1354 |
1350 (defun next-error-no-select (n) | |
1351 "Move point to the next error in the compilation buffer and highlight match. | |
1352 Prefix arg N says how many error messages to move forwards (or | |
1353 backwards, if negative). | |
1354 Finds and highlights the source line like \\[next-error], but does not | |
1355 select the source buffer." | |
1356 (interactive "p") | |
1357 (next-error n) | |
1358 (pop-to-buffer compilation-last-buffer)) | |
1359 | |
1360 (defun previous-error-no-select (n) | |
1361 "Move point to previous error in compilation buffer and highlight match. | |
1362 Prefix arg N says how many error messages to move backwards (or | |
1363 forwards, if negative). | |
1364 Finds and highlights the source line like \\[previous-error], but does not | |
1365 select the source buffer." | |
1366 (interactive "p") | |
1367 (next-error-no-select (- n))) | |
1368 | |
1369 (defun compilation-next-file (n) | 1355 (defun compilation-next-file (n) |
1370 "Move point to the next error for a different file than the current one. | 1356 "Move point to the next error for a different file than the current one. |
1371 Prefix arg N says how many files to move forwards (or backwards, if negative)." | 1357 Prefix arg N says how many files to move forwards (or backwards, if negative)." |
1372 (interactive "p") | 1358 (interactive "p") |
1373 (compilation-next-error n t)) | 1359 (compilation-next-error n t)) |
1401 (setq compilation-current-error (point)) | 1387 (setq compilation-current-error (point)) |
1402 (next-error 0))) | 1388 (next-error 0))) |
1403 | 1389 |
1404 ;; Return a compilation buffer. | 1390 ;; Return a compilation buffer. |
1405 ;; If the current buffer is a compilation buffer, return it. | 1391 ;; If the current buffer is a compilation buffer, return it. |
1406 ;; If compilation-last-buffer is set to a live buffer, use that. | |
1407 ;; Otherwise, look for a compilation buffer and signal an error | 1392 ;; Otherwise, look for a compilation buffer and signal an error |
1408 ;; if there are none. | 1393 ;; if there are none. |
1409 (defun compilation-find-buffer (&optional other-buffer) | 1394 (defun compilation-find-buffer (&optional other-buffer) |
1410 (if (and (not other-buffer) | 1395 (next-error-find-buffer other-buffer 'compilation-buffer-internal-p)) |
1411 (compilation-buffer-p (current-buffer))) | |
1412 ;; The current buffer is a compilation buffer. | |
1413 (current-buffer) | |
1414 (if (and compilation-last-buffer (buffer-name compilation-last-buffer) | |
1415 (compilation-buffer-p compilation-last-buffer) | |
1416 (or (not other-buffer) (not (eq compilation-last-buffer | |
1417 (current-buffer))))) | |
1418 compilation-last-buffer | |
1419 (let ((buffers (buffer-list))) | |
1420 (while (and buffers (or (not (compilation-buffer-p (car buffers))) | |
1421 (and other-buffer | |
1422 (eq (car buffers) (current-buffer))))) | |
1423 (setq buffers (cdr buffers))) | |
1424 (if buffers | |
1425 (car buffers) | |
1426 (or (and other-buffer | |
1427 (compilation-buffer-p (current-buffer)) | |
1428 ;; The current buffer is a compilation buffer. | |
1429 (progn | |
1430 (if other-buffer | |
1431 (message "This is the only compilation buffer.")) | |
1432 (current-buffer))) | |
1433 (error "No compilation started!"))))))) | |
1434 | 1396 |
1435 ;;;###autoload | 1397 ;;;###autoload |
1436 (defun next-error (&optional n) | 1398 (defun compilation-next-error-function (n &optional reset) |
1437 "Visit next compilation error message and corresponding source code. | |
1438 Prefix arg N says how many error messages to move forwards (or | |
1439 backwards, if negative). | |
1440 | |
1441 \\[next-error] normally uses the most recently started compilation or | |
1442 grep buffer. However, it can operate on any buffer with output from | |
1443 the \\[compile] and \\[grep] commands, or, more generally, on any | |
1444 buffer in Compilation mode or with Compilation Minor mode enabled. To | |
1445 specify use of a particular buffer for error messages, type | |
1446 \\[next-error] in that buffer. | |
1447 | |
1448 Once \\[next-error] has chosen the buffer for error messages, | |
1449 it stays with that buffer until you use it in some other buffer which | |
1450 uses Compilation mode or Compilation Minor mode. | |
1451 | |
1452 See variable `compilation-error-regexp-alist' for customization ideas." | |
1453 (interactive "p") | 1399 (interactive "p") |
1454 (set-buffer (setq compilation-last-buffer (compilation-find-buffer))) | 1400 (set-buffer (compilation-find-buffer)) |
1401 (when reset | |
1402 (setq compilation-current-error nil)) | |
1455 (let* ((columns compilation-error-screen-columns) ; buffer's local value | 1403 (let* ((columns compilation-error-screen-columns) ; buffer's local value |
1456 (last 1) | 1404 (last 1) |
1457 (loc (compilation-next-error (or n 1) nil | 1405 (loc (compilation-next-error (or n 1) nil |
1458 (or compilation-current-error (point-min)))) | 1406 (or compilation-current-error (point-min)))) |
1459 (end-loc (nth 2 loc)) | 1407 (end-loc (nth 2 loc)) |
1495 (if (nth 3 col) | 1443 (if (nth 3 col) |
1496 (set-marker (nth 3 col) (point)) | 1444 (set-marker (nth 3 col) (point)) |
1497 (setcdr (nthcdr 2 col) `(,(point-marker))))))))) | 1445 (setcdr (nthcdr 2 col) `(,(point-marker))))))))) |
1498 (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc)) | 1446 (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc)) |
1499 (setcdr (nthcdr 3 loc) t))) ; Set this one as visited. | 1447 (setcdr (nthcdr 3 loc) t))) ; Set this one as visited. |
1500 | |
1501 ;;;###autoload (define-key ctl-x-map "`" 'next-error) | |
1502 | |
1503 (defun previous-error (n) | |
1504 "Visit previous compilation error message and corresponding source code. | |
1505 Prefix arg N says how many error messages to move backwards (or | |
1506 forwards, if negative). | |
1507 | |
1508 This operates on the output from the \\[compile] and \\[grep] commands." | |
1509 (interactive "p") | |
1510 (next-error (- n))) | |
1511 | |
1512 (defun first-error (n) | |
1513 "Restart at the first error. | |
1514 Visit corresponding source code. | |
1515 With prefix arg N, visit the source code of the Nth error. | |
1516 This operates on the output from the \\[compile] command." | |
1517 (interactive "p") | |
1518 (set-buffer (setq compilation-last-buffer (compilation-find-buffer))) | |
1519 (setq compilation-current-error nil) | |
1520 (next-error n)) | |
1521 | 1448 |
1522 (defun compilation-fake-loc (marker file &optional line col) | 1449 (defun compilation-fake-loc (marker file &optional line col) |
1523 "Preassociate MARKER with FILE. | 1450 "Preassociate MARKER with FILE. |
1524 This is useful when you compile temporary files, but want | 1451 This is useful when you compile temporary files, but want |
1525 automatic translation of the messages to the real buffer from | 1452 automatic translation of the messages to the real buffer from |