Subject: Re: latex error message starts dired

From: Chong Yidong <[email-masked]>
Date: Fri, 25 Jul 2008 13:35:13 -0400

>> In latex mode, when latex produces an error, sometimes using C-x `
>> (next-error) opens a dired buffer instead of jumping to the error.
>>
>> Here is the output of latex, as it appears in the *tex-shell* buffer.
>>
>> Runaway argument?
>>  g(\polar , s) &= \Re \phi (se^{i\polar })\frac {1}{4\pi }s \psi (i(\pi \ETC.
>> ! Paragraph ended before \align was complete.
>
> The parser finds this error and subsequently tries to determine the file
> name.  In course of that it checks the "(\pi" construct with point right
> before the backslash.  In this case the form
> (file-readable-p (thing-at-point 'filename))
> returns t and the file name is set to an empty string.  (This is what
> `(thing-at-point 'filename)' returns.)

How bout the following patch to tex-mode?

*** textmodes/tex-mode.el.~1.213.~	2008-06-25 18:35:53.000000000 -0400
--- textmodes/tex-mode.el	2008-07-25 13:32:46.000000000 -0400
***************
*** 2188,2193 ****
--- 2188,2194 ----
        (let* ((this-error (copy-marker begin-of-error))
  	     (linenum (string-to-number (match-string 1)))
  	     (error-text (regexp-quote (match-string 3)))
+ 	     try-filename
  	     (filename
  	      ;; Prefer --file-liner-error filename if we have it.
  	      (or errfilename
***************
*** 2195,2201 ****
  		    (with-syntax-table tex-error-parse-syntax-table
  		      (backward-up-list 1)
  		      (skip-syntax-forward "(_")
! 		      (while (not (file-readable-p (thing-at-point 'filename)))
  			(skip-syntax-backward "(_")
  			(backward-up-list 1)
  			(skip-syntax-forward "(_"))
--- 2196,2206 ----
  		    (with-syntax-table tex-error-parse-syntax-table
  		      (backward-up-list 1)
  		      (skip-syntax-forward "(_")
! 		      (while (not 
! 			      (and (setq try-filename (thing-at-point
! 						       'filename))
! 				   (not (string= "" try-filename))
! 				   (file-readable-p try-filename)))
  			(skip-syntax-backward "(_")
  			(backward-up-list 1)
  			(skip-syntax-forward "(_"))