comparison lisp/progmodes/compile.el @ 6240:5ce2192f76e1

(compile-reinitialize-errors): Rename first arg from ARGP to REPARSE. Test only its nilness. (compile-goto-error): Pass (consp ARGP) to compile-reinitialize-errors instead of ARGP itself. (next-error): Code broken out into two new functions; call them. (compilation-next-error-locus): New function; bulk of code from next-error. Silently skip errors whose source loci are markers in killed buffers. (compilation-goto-locus): New function, final code from next-error.
author Roland McGrath <roland@gnu.org>
date Mon, 07 Mar 1994 22:31:48 +0000
parents 8ddddba0de43
children 84d5a22db4c8
comparison
equal deleted inserted replaced
6239:31e12709b654 6240:5ce2192f76e1
631 (error "The compilation process is not running.")))) 631 (error "The compilation process is not running."))))
632 632
633 633
634 ;; Parse any new errors in the compilation buffer, 634 ;; Parse any new errors in the compilation buffer,
635 ;; or reparse from the beginning if the user has asked for that. 635 ;; or reparse from the beginning if the user has asked for that.
636 (defun compile-reinitialize-errors (argp &optional limit-search find-at-least) 636 (defun compile-reinitialize-errors (reparse
637 &optional limit-search find-at-least)
637 (save-excursion 638 (save-excursion
638 (set-buffer compilation-last-buffer) 639 (set-buffer compilation-last-buffer)
639 ;; If we are out of errors, or if user says "reparse", 640 ;; If we are out of errors, or if user says "reparse",
640 ;; discard the info we have, to force reparsing. 641 ;; discard the info we have, to force reparsing.
641 (if (or (eq compilation-error-list t) 642 (if (or (eq compilation-error-list t)
642 (consp argp)) 643 reparse)
643 (compilation-forget-errors)) 644 (compilation-forget-errors))
644 (if (and compilation-error-list 645 (if (and compilation-error-list
645 (or (not limit-search) 646 (or (not limit-search)
646 (> compilation-parsing-end limit-search)) 647 (> compilation-parsing-end limit-search))
647 (or (not find-at-least) 648 (or (not find-at-least)
684 other kinds of prefix arguments are ignored." 685 other kinds of prefix arguments are ignored."
685 (interactive "P") 686 (interactive "P")
686 (or (compilation-buffer-p (current-buffer)) 687 (or (compilation-buffer-p (current-buffer))
687 (error "Not in a compilation buffer.")) 688 (error "Not in a compilation buffer."))
688 (setq compilation-last-buffer (current-buffer)) 689 (setq compilation-last-buffer (current-buffer))
689 (compile-reinitialize-errors argp (point)) 690 (compile-reinitialize-errors (consp argp) (point))
690 691
691 ;; Move to bol; the marker for the error on this line will point there. 692 ;; Move to bol; the marker for the error on this line will point there.
692 (beginning-of-line) 693 (beginning-of-line)
693 694
694 ;; Move compilation-error-list to the elt of compilation-old-error-list 695 ;; Move compilation-error-list to the elt of compilation-old-error-list
761 762
762 See variables `compilation-parse-errors-function' and 763 See variables `compilation-parse-errors-function' and
763 \`compilation-error-regexp-alist' for customization ideas." 764 \`compilation-error-regexp-alist' for customization ideas."
764 (interactive "P") 765 (interactive "P")
765 (setq compilation-last-buffer (compilation-find-buffer)) 766 (setq compilation-last-buffer (compilation-find-buffer))
766 (compile-reinitialize-errors argp nil 767 (compilation-goto-locus (compilation-next-error-locus
767 ;; We want to pass a number here only if 768 ;; We want to pass a number here only if
768 ;; we got a numeric prefix arg, not just C-u. 769 ;; we got a numeric prefix arg, not just C-u.
769 (and (not (consp argp)) 770 (and (not (consp argp))
770 (if (< (prefix-numeric-value argp) 1) 771 (prefix-numeric-value argp))
771 0 772 (consp argp))))
772 (1- (prefix-numeric-value argp))))) 773 ;;;###autoload (define-key ctl-x-map "`" 'next-error)
773 ;; Make ARGP nil if the prefix arg was just C-u, 774
774 ;; since that means to reparse the errors, which the 775 (defun compilation-next-error-locus (&optional move reparse)
775 ;; compile-reinitialize-errors call just did. 776 "Visit next compilation error and return locus in corresponding source code.
776 ;; Now we are only interested in a numeric prefix arg. 777 This operates on the output from the \\[compile] command.
777 (if (consp argp) 778 If all preparsed error messages have been processed,
778 (setq argp nil)) 779 the error message buffer is checked for new ones.
780
781 Returns a cons (ERROR . SOURCE) of two markers: ERROR is a marker at the
782 location of the error message in the compilation buffer, and SOURCE is a
783 marker at the location in the source code indicated by the error message.
784
785 Optional first arg MOVE says how many error messages to move forwards (or
786 backwards, if negative); default is 1. Optional second arg REPARSE, if
787 non-nil, says to reparse the error message buffer and reset to the first
788 error (plus MOVE - 1).
789
790 The current buffer should be the desired compilation output buffer."
791 (or move (setq move 1))
792 (compile-reinitialize-errors reparse nil (and (not reparse)
793 (if (< move 1) 0 (1- move))))
779 (let (next-errors next-error) 794 (let (next-errors next-error)
780 (save-excursion 795 (save-excursion
781 (set-buffer compilation-last-buffer) 796 (set-buffer compilation-last-buffer)
782 ;; compilation-error-list points to the "current" error. 797 ;; compilation-error-list points to the "current" error.
783 (setq next-errors 798 (setq next-errors
784 (if (> (prefix-numeric-value argp) 0) 799 (if (> move 0)
785 (nthcdr (1- (prefix-numeric-value argp)) 800 (nthcdr (1- move)
786 compilation-error-list) 801 compilation-error-list)
787 ;; Zero or negative arg; we need to move back in the list. 802 ;; Zero or negative arg; we need to move back in the list.
788 (let ((n (1- (prefix-numeric-value argp))) 803 (let ((n (1- move))
789 (i 0) 804 (i 0)
790 (e compilation-old-error-list)) 805 (e compilation-old-error-list))
791 ;; See how many cdrs away the current error is from the start. 806 ;; See how many cdrs away the current error is from the start.
792 (while (not (eq e compilation-error-list)) 807 (while (not (eq e compilation-error-list))
793 (setq i (1+ i) 808 (setq i (1+ i)
795 (if (> (- n) i) 810 (if (> (- n) i)
796 (error "Moved back past first error") 811 (error "Moved back past first error")
797 (nthcdr (+ i n) compilation-old-error-list)))) 812 (nthcdr (+ i n) compilation-old-error-list))))
798 next-error (car next-errors)) 813 next-error (car next-errors))
799 (while 814 (while
800 (progn 815 (if (null next-error)
801 (if (null next-error) 816 (progn
802 (progn 817 (if move (if (> move 0)
803 (if argp (if (> (prefix-numeric-value argp) 0) 818 (error "Moved past last error")
804 (error "Moved past last error") 819 (error "Moved back past first error")))
805 (error "Moved back past first error"))) 820 (compilation-forget-errors)
806 (compilation-forget-errors) 821 (error (concat compilation-error-message
807 (error (concat compilation-error-message 822 (and (get-buffer-process (current-buffer))
808 (and (get-buffer-process (current-buffer)) 823 (eq (process-status
809 (eq (process-status 824 (get-buffer-process
810 (get-buffer-process 825 (current-buffer)))
811 (current-buffer))) 826 'run)
812 'run) 827 " yet"))))
813 " yet")))) 828 (setq compilation-error-list (cdr next-errors))
814 (setq compilation-error-list (cdr next-errors)) 829 (if (null (cdr next-error))
815 (if (null (cdr next-error)) 830 ;; This error is boring. Go to the next.
816 ;; This error is boring. Go to the next. 831 t
817 t 832 (or (markerp (cdr next-error))
818 (or (markerp (cdr next-error)) 833 ;; This error has a filename/lineno pair.
819 ;; This error has a filename/lineno pair. 834 ;; Find the file and turn it into a marker.
820 ;; Find the file and turn it into a marker. 835 (let* ((fileinfo (car (cdr next-error)))
821 (let* ((fileinfo (car (cdr next-error))) 836 (buffer (compilation-find-file (cdr fileinfo)
822 (buffer (compilation-find-file (cdr fileinfo) 837 (car fileinfo)
823 (car fileinfo) 838 (car next-error))))
824 (car next-error)))) 839 (if (null buffer)
825 (if (null buffer) 840 ;; We can't find this error's file.
826 ;; We can't find this error's file. 841 ;; Remove all errors in the same file.
827 ;; Remove all errors in the same file. 842 (progn
828 (progn 843 (setq next-errors compilation-old-error-list)
829 (setq next-errors compilation-old-error-list) 844 (while next-errors
830 (while next-errors 845 (and (consp (cdr (car next-errors)))
831 (and (consp (cdr (car next-errors))) 846 (equal (car (cdr (car next-errors)))
832 (equal (car (cdr (car next-errors))) 847 fileinfo)
833 fileinfo) 848 (progn
834 (progn 849 (set-marker (car (car next-errors)) nil)
835 (set-marker (car (car next-errors)) nil) 850 (setcdr (car next-errors) nil)))
836 (setcdr (car next-errors) nil))) 851 (setq next-errors (cdr next-errors)))
837 (setq next-errors (cdr next-errors))) 852 ;; Look for the next error.
838 ;; Look for the next error. 853 t)
839 t) 854 ;; We found the file. Get a marker for this error.
840 ;; We found the file. Get a marker for this error. 855 ;; compilation-old-error-list is a buffer-local
841 ;; compilation-old-error-list is a buffer-local 856 ;; variable, so we must be careful to extract its value
842 ;; variable, so we must be careful to extract its value 857 ;; before switching to the source file buffer.
843 ;; before switching to the source file buffer. 858 (let ((errors compilation-old-error-list)
844 (let ((errors compilation-old-error-list) 859 (last-line (nth 1 (cdr next-error)))
845 (last-line (nth 1 (cdr next-error))) 860 (column (nth 2 (cdr next-error))))
846 (column (nth 2 (cdr next-error)))) 861 (set-buffer buffer)
847 (set-buffer buffer) 862 (save-excursion
848 (save-excursion 863 (save-restriction
849 (save-restriction 864 (widen)
850 (widen) 865 (goto-line last-line)
851 (goto-line last-line) 866 (if column
852 (if column 867 (move-to-column column)
853 (move-to-column column) 868 (beginning-of-line))
854 (beginning-of-line)) 869 (setcdr next-error (point-marker))
855 (setcdr next-error (point-marker)) 870 ;; Make all the other error messages referring
856 ;; Make all the other error messages referring 871 ;; to the same file have markers into the buffer.
857 ;; to the same file have markers into the buffer. 872 (while errors
858 (while errors 873 (and (consp (cdr (car errors)))
859 (and (consp (cdr (car errors))) 874 (equal (car (cdr (car errors))) fileinfo)
860 (equal (car (cdr (car errors))) fileinfo) 875 (let* ((this (nth 1 (cdr (car errors))))
861 (let* ((this (nth 1 (cdr (car errors)))) 876 (column (nth 2 (cdr (car errors))))
862 (column (nth 2 (cdr (car errors)))) 877 (lines (- this last-line)))
863 (lines (- this last-line))) 878 (if (eq selective-display t)
864 (if (eq selective-display t) 879 ;; When selective-display is t,
865 ;; When selective-display is t, 880 ;; each C-m is a line boundary,
866 ;; each C-m is a line boundary, 881 ;; as well as each newline.
867 ;; as well as each newline. 882 (if (< lines 0)
868 (if (< lines 0) 883 (re-search-backward "[\n\C-m]"
869 (re-search-backward "[\n\C-m]" 884 nil 'end
870 nil 'end 885 (- lines))
871 (- lines)) 886 (re-search-forward "[\n\C-m]"
872 (re-search-forward "[\n\C-m]" 887 nil 'end
873 nil 'end 888 lines))
874 lines)) 889 (forward-line lines))
875 (forward-line lines)) 890 (if column
876 (if column 891 (move-to-column column))
877 (move-to-column column)) 892 (setq last-line this)
878 (setq last-line this) 893 (setcdr (car errors) (point-marker))))
879 (setcdr (car errors) (point-marker)))) 894 (setq errors (cdr errors)))))))))
880 (setq errors (cdr errors))))))))) 895 ;; If we didn't get a marker for this error, or this
881 ;; If we didn't get a marker for this error, 896 ;; marker's buffer was killed, go on to the next one.
882 ;; go on to the next one. 897 (or (not (markerp (cdr next-error)))
883 (not (markerp (cdr next-error)))))) 898 (not (marker-buffer (cdr next-error))))))
884 (setq next-errors compilation-error-list 899 (setq next-errors compilation-error-list
885 next-error (car next-errors)))) 900 next-error (car next-errors))))
886 901
887 ;; Skip over multiple error messages for the same source location, 902 ;; Skip over multiple error messages for the same source location,
888 ;; so the next C-x ` won't go to an error in the same place. 903 ;; so the next C-x ` won't go to an error in the same place.
889 (while (and compilation-error-list 904 (while (and compilation-error-list
890 (equal (cdr (car compilation-error-list)) (cdr next-error))) 905 (equal (cdr (car compilation-error-list)) (cdr next-error)))
891 (setq compilation-error-list (cdr compilation-error-list))) 906 (setq compilation-error-list (cdr compilation-error-list)))
892 907
893 ;; We now have a marker for the position of the error. 908 ;; We now have a marker for the position of the error source code.
894 (switch-to-buffer (marker-buffer (cdr next-error))) 909 ;; NEXT-ERROR is a cons (ERROR . SOURCE) of two markers.
895 (goto-char (cdr next-error)) 910 next-error))
896 ;; If narrowing got in the way of 911
897 ;; going to the right place, widen. 912 (defun compilation-goto-locus (next-error)
898 (or (= (point) (marker-position (cdr next-error))) 913 "Jump to an error locus returned by `compilation-next-error-locus'.
899 (progn 914 Takes one argument, a cons (ERROR . SOURCE) of two markers.
900 (widen) 915 Selects a window with point at SOURCE, with another window displaying ERROR."
901 (goto-char (cdr next-error)))) 916 (switch-to-buffer (marker-buffer (cdr next-error)))
902 917 (goto-char (cdr next-error))
903 ;; Show compilation buffer in other window, scrolled to this error. 918 ;; If narrowing got in the way of
904 (let* ((pop-up-windows t) 919 ;; going to the right place, widen.
905 (w (display-buffer (marker-buffer (car next-error))))) 920 (or (= (point) (marker-position (cdr next-error)))
906 (set-window-point w (car next-error)) 921 (progn
907 (set-window-start w (car next-error))))) 922 (widen)
908 923 (goto-char (cdr next-error))))
909 ;;;###autoload (define-key ctl-x-map "`" 'next-error) 924
910 925 ;; Show compilation buffer in other window, scrolled to this error.
926 (let* ((pop-up-windows t)
927 (w (display-buffer (marker-buffer (car next-error)))))
928 (set-window-point w (car next-error))
929 (set-window-start w (car next-error))))
930
911 ;; Find a buffer for file FILENAME. 931 ;; Find a buffer for file FILENAME.
912 ;; Search the directories in compilation-search-path. 932 ;; Search the directories in compilation-search-path.
913 ;; A nil in compilation-search-path means to try the 933 ;; A nil in compilation-search-path means to try the
914 ;; current directory, which is passed in DIR. 934 ;; current directory, which is passed in DIR.
915 ;; If FILENAME is not found at all, ask the user where to find it. 935 ;; If FILENAME is not found at all, ask the user where to find it.