[ESS] Sweave: focus after `M-n P'

Martin Maechler maechler at stat.math.ethz.ch
Thu May 3 13:47:29 CEST 2007


>>>>> "MM" == Martin Maechler <maechler at stat.math.ethz.ch>
>>>>>     on Thu, 3 May 2007 10:45:00 +0200 writes:

>>>>> "PaDre" == Patrick Drechsler <patrick at pdrechsler.de>
>>>>>     on Wed, 02 May 2007 23:25:43 +0200 writes:

    PaDre> Hi, when invoking `M-n s' on foo.Rnw and everything
    PaDre> is OK one normally then parses the result (foo.tex)
    PaDre> through (pdf)latex with `M-n l' or `M-n P'.

    PaDre> Failing an interface between ESS and AUCTeX, I think
    PaDre> it would be a good idea to place the "cursor focus"
    PaDre> at the end of the *Shell Command Output Buffer*
    PaDre> instead of the empty *Async Shell Command* buffer.

    PaDre> Let me try to show using a minimal example:

    MM> very nice and reproducible.  Thank you, Patrick!

    MM> Let me reply here instead of interspersed into your text.

    MM> You are entirely right with your diagnosis,
    MM> and indeed that behavior is not satisfactory.
    MM> It's simply because the (ess-swv-PDF) function which you call
    MM> via "M-n P"
    MM> ends with these two lines :

    MM> (shell-command (concat "pdflatex " tex-filename))
    MM> (shell-command (concat pdfviewer " " namestem ".pdf &"))))

    MM> which is simple, but really not sufficient.
    MM> The pdfviewer should not be called at all, as soon as an error
    MM> happens in "pdflatex".
    MM> I see that (shell-command .) could work with a separate error
    MM> buffer, and ESS could look at that error buffer.  That may be
    MM> one solution.

    MM> Alternatively, I think --- and I'd be glad for advice
    MM> from Emacs experts --- we should rather do these things
    MM> similarly as "M-n l" == (ess-swv-latex) does it, namely
    MM> using a deticated buffer, and switch back to *.Rnw etc;
    MM> maybe also using (call-process) which has the advantage
    MM> that it provides a return value.

    MM> We will try to implement one of the above approaches.

I've done so in the mean time.
The current version has changes in three files,

ess.el  ess-cust.el and ess-swv.el

You can get them from the development repository,
  https://svn.r-project.org/ESS/trunk/lisp/

or also via anonymous FTP; if you do
  cd <myESS>/lisp
  wget ftp://stat.ethz.ch/U/maechler/ESS/ess\*.el      

you should get these three files and replace them with the ones
from ESS 5.3.4.

I'd be glad for feedback about the changed and improved new
behavior

[... read on ..]

    MM> Can you confirm that 'M-n l'  behaves more conveniently?

can you?

[... read on ..]

    PaDre> 1. Save this as ~/tmp/foo.Rnw:

    PaDre> --8<---------------cut here---------------start------------->8---
    PaDre> \documentclass{article}
    PaDre> \begin{document}
    PaDre> \section{Intro}
    PaDre> \label{sec:intro}
    PaDre> some text some \emph{bold} text.
    PaDre> \end{document}
    PaDre> --8<---------------cut here---------------end--------------->8---

    PaDre> 2. Start R with `M-x R' and switch back to the foo.Rnw buffer[1].
    PaDre> 3. `M-n s'
    PaDre> 4. `M-n P'

    PaDre> Everything is fine.

    PaDre> 5. Now include a small syntax error by deleting the closing bracket after
    PaDre> `\label' so your foo.Rnw file looks like this:

    PaDre> --8<---------------cut here---------------start------------->8---
    PaDre> \documentclass{article}
    PaDre> \begin{document}
    PaDre> \section{Intro}
    PaDre> \label{sec:intro
    PaDre> some text some \emph{bold} text.
    PaDre> \end{document}
    PaDre> --8<---------------cut here---------------end--------------->8---

    PaDre> 6. `M-n s'
    PaDre> 7. 'M-n P'

    PaDre> The PDF file which is displayed is the same as after step 4. The user
    PaDre> will not see that the command `M-n P' had an error message. 

    PaDre> Why? 

    PaDre> At this time the standard Emacs screen is split in two: The top part
    PaDre> showing the source buffer code of `foo.Rnw', the bottom part showing
    PaDre> an empty buffer called *Async Shell Command*.

    PaDre> Switching to the end of the *Shell Command Output* buffer one gets
    PaDre> this:

    PaDre> ,----
    PaDre> | ))
    PaDre> | Runaway argument?
    PaDre> | {sec:intro some text some \emph {bold} text. \end {document} 
    PaDre> | ! File ended while scanning use of \label.
    PaDre> | <inserted text> 
    PaDre> |                 \par 
    PaDre> | <*> foo.tex
    PaDre> |            
    PaDre> | ? 
    PaDre> | ! Emergency stop.
    PaDre> | <inserted text> 
    PaDre> |                 \par 
    PaDre> | <*> foo.tex
    PaDre> |            
    PaDre> | !  ==> Fatal error occurred, no output PDF file produced!
    PaDre> | Transcript written on foo.log.
    PaDre> `----

    PaDre> I think that the the bottom buffer should display the end of the
    PaDre> *Shell Command Output* buffer (instead of *Async Shell Command*) after
    PaDre> invoking `M-n P'.

    PaDre> Cheers

    PaDre> Patrick

    PaDre> Footnotes: 
    PaDre> [1] I always switch back to the Rnw buffer anyway. Can I keep the
    PaDre> focus there by default?

I now let R start automatically from an *.Rnw file, when you do
    M-n s (Sweave)
or  M-n T (Stangle)

Martin




More information about the ESS-help mailing list