Mercurial > emacs
comparison lisp/progmodes/compile.el @ 54939:9c3e575d5a2b
(compilation-error-properties): Fix for adding messages when there are already
markers for their file.
(compilation-fake-loc): New function.
author | Daniel Pfeiffer <occitan@esperanto.org> |
---|---|
date | Fri, 16 Apr 2004 23:04:23 +0000 |
parents | 21c1ccea9533 |
children | 2f96b3c58e6d |
comparison
equal
deleted
inserted
replaced
54938:109b2bf180dd | 54939:9c3e575d5a2b |
---|---|
562 ;; This message didn't mention one, get it from previous | 562 ;; This message didn't mention one, get it from previous |
563 (setq file (previous-single-property-change (point) 'message) | 563 (setq file (previous-single-property-change (point) 'message) |
564 file (or (if file | 564 file (or (if file |
565 (nth 2 (car (or (get-text-property (1- file) 'message) | 565 (nth 2 (car (or (get-text-property (1- file) 'message) |
566 (get-text-property file 'message))))) | 566 (get-text-property file 'message))))) |
567 ;; no previous either -- let font-lock continue | 567 ;; no previous either -- but don't let font-lock fail |
568 (gethash (setq file '("*unknown*")) compilation-locs) | 568 (gethash (setq file '("*unknown*")) compilation-locs) |
569 (puthash file (list file fmt) compilation-locs)))) | 569 (puthash file (list file fmt) compilation-locs)))) |
570 ;; All of these fields are optional, get them only if we have an index, and | 570 ;; All of these fields are optional, get them only if we have an index, and |
571 ;; it matched some part of the message. | 571 ;; it matched some part of the message. |
572 (and line | 572 (and line |
579 (setq col (match-string-no-properties col)) | 579 (setq col (match-string-no-properties col)) |
580 (setq col (- (string-to-number col) compilation-first-column))) | 580 (setq col (- (string-to-number col) compilation-first-column))) |
581 (if (and end-col (setq end-col (match-string-no-properties end-col))) | 581 (if (and end-col (setq end-col (match-string-no-properties end-col))) |
582 (setq end-col (- (string-to-number end-col) compilation-first-column)) | 582 (setq end-col (- (string-to-number end-col) compilation-first-column)) |
583 (if end-line (setq end-col -1))) | 583 (if end-line (setq end-col -1))) |
584 (if (consp type) ; not a preset type, check what it is. | 584 (if (consp type) ; not a static type, check what it is. |
585 (setq type (or (and (car type) (match-end (car type)) 1) | 585 (setq type (or (and (car type) (match-end (car type)) 1) |
586 (and (cdr type) (match-end (cdr type)) 0) | 586 (and (cdr type) (match-end (cdr type)) 0) |
587 2))) | 587 2))) |
588 ;; Get any (first) already existing marker (if any has one, all have one). | 588 ;; Get first already existing marker (if any has one, all have one). |
589 ;; Do this first, as the next assq`s may create new nodes. | 589 ;; Do this first, as the compilation-assq`s may create new nodes. |
590 (let ((marker (nth 3 (car (cdar (cddr file))))) | 590 (let* ((marker-line (car (cddr file))) ; a line structure |
591 (loc (compilation-assq line (cdr file))) | 591 (marker (nth 3 (cadr marker-line))) ; its marker |
592 end-loc) | 592 (compilation-error-screen-columns compilation-error-screen-columns) |
593 end-marker loc end-loc) | |
594 (if (not (and marker (marker-buffer marker))) | |
595 (setq marker) ; no valid marker for this file | |
596 (setq loc (or line 1) ; normalize no linenumber to line 1 | |
597 marker-line) | |
598 (catch 'marker ; find nearest loc, at least one exists | |
599 (dolist (x (cddr file)) ; loop over lines | |
600 (if (> (or (car x) 1) loc) ; still bigger | |
601 (setq marker-line x) | |
602 (if (or (not marker-line) ; first in list | |
603 (> (- (or (car marker-line) 1) loc) | |
604 (- loc (or (car x) 1)))) ; current line is nearer | |
605 (setq marker-line x)) | |
606 (throw 'marker t)))) | |
607 (setq marker (nth 3 (cadr marker-line)) | |
608 marker-line (car marker-line)) | |
609 (with-current-buffer (marker-buffer marker) | |
610 (save-restriction | |
611 (widen) | |
612 (goto-char (marker-position marker)) | |
613 (when (or end-col end-line) | |
614 (beginning-of-line (- (or end-line line) marker-line -1)) | |
615 (if (< end-col 0) | |
616 (end-of-line) | |
617 (if compilation-error-screen-columns | |
618 (move-to-column end-col) | |
619 (forward-char end-col))) | |
620 (setq end-marker (list (point-marker)))) | |
621 (beginning-of-line (if end-line | |
622 (- end-line line -1) | |
623 (- loc marker-line -1))) | |
624 (if col | |
625 (if compilation-error-screen-columns | |
626 (move-to-column col) | |
627 (forward-char col)) | |
628 (forward-to-indentation 0)) | |
629 (setq marker (list (point-marker)))))) | |
630 | |
631 (setq loc (compilation-assq line (cdr file))) | |
593 (if end-line | 632 (if end-line |
594 (setq end-loc (compilation-assq end-line (cdr file)) | 633 (setq end-loc (compilation-assq end-line (cdr file)) |
595 end-loc (compilation-assq end-col end-loc)) | 634 end-loc (compilation-assq end-col end-loc)) |
596 (if end-col ; use same line element | 635 (if end-col ; use same line element |
597 (setq end-loc (compilation-assq end-col loc)))) | 636 (setq end-loc (compilation-assq end-col loc)))) |
598 (setq loc (compilation-assq col loc)) | 637 (setq loc (compilation-assq col loc)) |
599 ;; If they are new, make the loc(s) reference the file they point to. | 638 ;; If they are new, make the loc(s) reference the file they point to. |
600 (or (cdr loc) (setcdr loc (list line file))) | 639 (or (cdr loc) (setcdr loc `(,line ,file ,@marker))) |
601 (if end-loc | 640 (if end-loc |
602 (or (cdr end-loc) (setcdr end-loc (list (or end-line line) file)))) | 641 (or (cdr end-loc) (setcdr end-loc `(,(or end-line line) ,file ,@end-marker)))) |
603 ;; If we'd found a marker, ensure that the new locs also get markers | 642 |
604 (when (and marker | |
605 (not (or (cddr loc) (cddr end-loc))) ; maybe new node w/o marker | |
606 (marker-buffer marker)) ; other marker still valid | |
607 (or line (setq line 1)) ; normalize no linenumber to line 1 | |
608 (catch 'marker ; find nearest loc, at least one exists | |
609 (dolist (x (cddr file)) | |
610 (if (> (or (car x) 1) line) | |
611 (setq marker x) | |
612 (if (eq (or (car x) 1) line) | |
613 (if (cdr (cddr x)) ; at least one other column | |
614 (throw 'marker (setq marker x)) | |
615 (if marker (throw 'marker t))) | |
616 (throw 'marker (or marker (setq marker x))))))) | |
617 (setq marker (if (eq (car (cddr marker)) col) | |
618 (nthcdr 3 marker) | |
619 (cddr marker)) | |
620 file compilation-error-screen-columns) | |
621 (with-current-buffer (marker-buffer (cddr marker)) | |
622 (save-restriction | |
623 (widen) | |
624 (goto-char (marker-position (cddr marker))) | |
625 (beginning-of-line (- line (car (cadr marker)) -1)) | |
626 (if file ; original c.-error-screen-columns | |
627 (move-to-column (car loc)) | |
628 (forward-char (car loc))) | |
629 (setcdr (cdr loc) (point-marker)) | |
630 (when end-loc | |
631 (beginning-of-line (- end-line line -1)) | |
632 (if (< end-col 0) | |
633 (end-of-line) | |
634 (if file ; original c.-error-screen-columns | |
635 (move-to-column (car end-loc)) | |
636 (forward-char (car end-loc)))) | |
637 (setcdr (cdr end-loc) (point-marker)))))) | |
638 ;; Must start with face | 643 ;; Must start with face |
639 `(face ,compilation-message-face | 644 `(face ,compilation-message-face |
640 message (,loc ,type ,end-loc) | 645 message (,loc ,type ,end-loc) |
641 ,@(if compilation-debug | 646 ,@(if compilation-debug |
642 `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords) | 647 `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords) |
1447 (point-marker))) | 1452 (point-marker))) |
1448 loc (car loc)) | 1453 loc (car loc)) |
1449 ;; If loc contains no marker, no error in that file has been visited. If | 1454 ;; If loc contains no marker, no error in that file has been visited. If |
1450 ;; the marker is invalid the buffer has been killed. So, recalculate all | 1455 ;; the marker is invalid the buffer has been killed. So, recalculate all |
1451 ;; markers for that file. | 1456 ;; markers for that file. |
1452 (unless (and (nthcdr 3 loc) (marker-buffer (nth 3 loc))) | 1457 (unless (and (nth 3 loc) (marker-buffer (nth 3 loc))) |
1453 (with-current-buffer (compilation-find-file marker (caar (nth 2 loc)) | 1458 (with-current-buffer (compilation-find-file marker (caar (nth 2 loc)) |
1454 (or (cdar (nth 2 loc)) | 1459 (or (cdar (nth 2 loc)) |
1455 default-directory)) | 1460 default-directory)) |
1456 (save-restriction | 1461 (save-restriction |
1457 (widen) | 1462 (widen) |
1470 (move-to-column (car col)) | 1475 (move-to-column (car col)) |
1471 (beginning-of-line) | 1476 (beginning-of-line) |
1472 (forward-char (car col)))) | 1477 (forward-char (car col)))) |
1473 (beginning-of-line) | 1478 (beginning-of-line) |
1474 (skip-chars-forward " \t")) | 1479 (skip-chars-forward " \t")) |
1475 (if (nthcdr 3 col) | 1480 (if (nth 3 col) |
1476 (set-marker (nth 3 col) (point)) | 1481 (set-marker (nth 3 col) (point)) |
1477 (setcdr (nthcdr 2 col) `(,(point-marker))))))))) | 1482 (setcdr (nthcdr 2 col) `(,(point-marker))))))))) |
1478 (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc)) | 1483 (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc)) |
1479 (setcdr (nthcdr 3 loc) t))) ; Set this one as visited. | 1484 (setcdr (nthcdr 3 loc) t))) ; Set this one as visited. |
1480 | 1485 |
1496 This operates on the output from the \\[compile] command." | 1501 This operates on the output from the \\[compile] command." |
1497 (interactive "p") | 1502 (interactive "p") |
1498 (set-buffer (setq compilation-last-buffer (compilation-find-buffer))) | 1503 (set-buffer (setq compilation-last-buffer (compilation-find-buffer))) |
1499 (setq compilation-current-error nil) | 1504 (setq compilation-current-error nil) |
1500 (next-error n)) | 1505 (next-error n)) |
1506 | |
1507 (defun compilation-fake-loc (marker file &optional line col) | |
1508 "Preassociate MARKER with FILE. | |
1509 This is useful when you compile temporary files, but want | |
1510 automatic translation of the messages to the real buffer from | |
1511 which the temporary file came. This only works if done before a | |
1512 message about FILE appears! | |
1513 | |
1514 Optional args LINE and COL default to 1 and beginning of | |
1515 indentation respectively. The marker is expected to reflect | |
1516 this. In the simplest case the marker points to the first line | |
1517 of the region that was saved to the temp file. | |
1518 | |
1519 If you concatenate several regions into the temp file (e.g. a | |
1520 header with variable assignments and a code region), you must | |
1521 call this several times, once each for the last line of one | |
1522 region and the first line of the next region." | |
1523 (or (consp file) (setq file (list file))) | |
1524 (setq file (or (gethash file compilation-locs) | |
1525 (puthash file (list file nil) compilation-locs))) | |
1526 (let ((loc (compilation-assq (or line 1) (cdr file)))) | |
1527 (setq loc (compilation-assq col loc)) | |
1528 (if (cdr loc) | |
1529 (setcdr (cddr loc) (list marker)) | |
1530 (setcdr loc (list (or line 1) file marker))) | |
1531 loc)) | |
1501 | 1532 |
1502 (defcustom compilation-context-lines next-screen-context-lines | 1533 (defcustom compilation-context-lines next-screen-context-lines |
1503 "*Display this many lines of leading context before message." | 1534 "*Display this many lines of leading context before message." |
1504 :type 'integer | 1535 :type 'integer |
1505 :group 'compilation | 1536 :group 'compilation |