🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #87655

compile.el/compile-goto-error doesn't go to selected error

#87655
From: Gary Barnes
Date: Thu, 08 Sep 1994 02:04
104 lines
4826 bytes
Emacs 19.25, unmodified, no .emacs in use
SPARCstation-2, SunOS 4.1.3
gcc 2.6.0 compiled

The compile-goto-error function does not always go to the error that is
selected.  For example, if you have this foo.c compilation unit:

    #include <stdio.h>

    void
    main (intx argc,
          char **argv) 
    {

        blah = argc,;

        argv[0] = argv[argc];

    }

And do a M-x compile for foo.o, your *compilation* window will look
something like this:

    cd ~/
    nice -10 make -k foo.o
    cc   -target sun4 -c  foo.c
    "foo.c", line 4: syntax error at or near variable name "argc"
    "foo.c", line 8: blah undefined
    "foo.c", line 8: argc undefined
    "foo.c", line 8: syntax error at or near symbol ;
    "foo.c", line 10: argv undefined
    *** Error code 1
    make: Warning: Target `foo.o' not remade because of errors

    Compilation finished at Wed Sep  7 16:47:15

Then there are 3 errors on line 8.  The compilation-error-list will
have only one entry for errors on line 8.  That error has a value of
(point) recorded that is for the first error for line 8.  If the user
places the cursor on the 2nd or 3rd error for line 8 and executes
compile-goto-error, then the error for line 10 will be selected.  This
is because there are no entries in the error list for the 2nd and 3rd
errors for line 8.  This is not the behavior that is expected based on 
the commentary for the function.

Below is a modified copy of compile-goto-error.  Look for the ";; GEB"
comments.  It looks for a match for point, just like the old function,
but, when that match is not found, it then uses the previous error.
This fixes the immediate problem.

I suppose it might introduce a problem for compilation logs that
contains lots of meaningless "whitespace", such as "Now in directory
/a/b/c" messages.  A user might or might not be happy to find that
placing the cursor "between" two error messages always selected the
previous message.  Personally, that would be fine by me.

    Gary

(defun compile-goto-error (&optional argp)
  "Visit the source for the error message point is on.
Use this command in a compilation log buffer.  Sets the mark at point there.
\\[universal-argument] as a prefix arg means to reparse the buffer's error messages first;
other kinds of prefix arguments are ignored."
  (interactive "P")
  (or (compilation-buffer-p (current-buffer))
      (error "Not in a compilation buffer."))
  (setq compilation-last-buffer (current-buffer))
  (compile-reinitialize-errors (consp argp) (point))

  ;; Move to bol; the marker for the error on this line will point there.
  (beginning-of-line)

  ;; Move compilation-error-list to the elt of compilation-old-error-list
  ;; we want.
  ;; GEB If we find an error that is *past* the error line we wanted, that
  ;; GEB means the error parser combined several errors together (or that
  ;; GEB errors span more than one line) and so the error we want is the
  ;; GEB previous error.
  (setq compilation-error-list compilation-old-error-list)
  (let ;; GEB remember the previous error
      ((previous-error compilation-error-list))
    (while (and compilation-error-list
                (> (point) (car (car compilation-error-list))))
      ;; GEB remember the previous error.
      (setq previous-error         compilation-error-list)
      (setq compilation-error-list (cdr compilation-error-list)))
    ;; GEB If the error we found isn't right-on, then use the previous error.
    (if (and compilation-error-list
             (/= (point) (car (car compilation-error-list))))
        (setq compilation-error-list previous-error)
      )
    )

  ;; Move to another window, so that next-error's window changes
  ;; result in the desired setup.
  (or (one-window-p)
      (progn
	(other-window -1)
	;; other-window changed the selected buffer,
	;; but we didn't want to do that.
	(set-buffer compilation-last-buffer)))

  (push-mark)
  (next-error 1))
Technical Details
Message-ID: <9409080156.AA13943@igor.Rational.COM>
Path: arc1-ca.pugleaf.net!nntp.gmd.de!xlink.net!slsv6bt!slbh01.bln.sel.alcatel.de!rcvie!Austria.EU.net!newsfeed.ACO.net!paladin.american.edu!zombie.ncsc.mil!news.duke.edu!news-feed-1.peachnet.edu!gatech!psuvax1!rutgers!cis.ohio-state.edu!rational.com!geb

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,d7eb16ea768808a8,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1994-09-08 13:00:21 PST
Path: arc1-ca.pugleaf.net!nntp.gmd.de!xlink.net!slsv6bt!slbh01.bln.sel.alcatel.de!rcvie!Austria.EU.net!newsfeed.ACO.net!paladin.american.edu!zombie.ncsc.mil!news.duke.edu!news-feed-1.peachnet.edu!gatech!psuvax1!rutgers!cis.ohio-state.edu!rational.com!geb
From: geb@rational.com (Gary Barnes)
Newsgroups: gnu.emacs.bug
Subject: compile.el/compile-goto-error doesn't go to selected error
Date: 7 Sep 1994 22:04:51 -0400
Organization: GNUs Not Usenet
Lines: 104
Sender: daemon@cis.ohio-state.edu
Approved: bug-gnu-emacs@prep.ai.mit.edu
Distribution: gnu
Message-ID: <9409080156.AA13943@igor.Rational.COM>
Reply-To: geb@rational.com