6

When I scroll through an Sweave document (Rnw) with latex and R code, the text jumps around when the mode changes between Latex and ESS. The two modes disagree how text should be wrapped. Moreover, I've noticed that when I do

  1. M-x toggle-truncate-lines to enable truncate long lines while the cursor is within latex code
  2. move the cursor to R code
  3. return to the latex code

the truncated long lines mode is no longer on. Has anyone noticed this? Has anyone solved this problem?

jrm
  • 727
  • 5
  • 18
  • Yes, I've noticed it; it does the same thing with M-x longlines-mode. I've just gotten used to it as I don't know enough about emacs to fix it. Would love to see an answer though. – Aaron left Stack Overflow Dec 15 '11 at 15:36
  • To @csgillespie, I'm splitting hairs with grammar here, but I believe it's **an** Sweave document and not **a** Sweave document. It's the sound (consonant or vowel) that determines whether we use **a** or **an**. See [link](http://grammar.quickanddirtytips.com/a-versus-an.aspx). – jrm Dec 19 '11 at 19:13
  • @jrm: Nothing wrong with splitting hairs, you raise an important [point](http://csgillespie.wordpress.com/2011/03/26/an-r-package-or-a-r-package/) ;) However, I find saying "an Sweave" document a bit grating, and would still go for "a Sweave". – csgillespie Dec 19 '11 at 22:13
  • Thanks for the link @csgillespie. Now I really want to hear your pronunciation. :) – jrm Dec 19 '11 at 22:51
  • I always say "ehs-weave", so "an" works for me too. How do you say Sweave, @csgillespie? – Aaron left Stack Overflow Dec 21 '11 at 17:31

1 Answers1

4

By reading a similar question on the ess-help@r-project.org mailing list, this is what I've learned. When we scroll through the noweb file, we are switching major modes from ESS to LaTeX. Most major modes kill all local variables as part of their initialization, so when we just set the variable locally it's overwritten. To solve this, I modified a hook I found:

(add-hook 'LaTeX-mode-hook '(lambda () (if (string-match "\\.Rnw\\'" buffer-file-name) (setq fill-column 80))))

You could set a similar hook for longlines-mode or toggle-truncate-lines, etc, to meet your needs. The downside to this solution is that you're stuck with a single value for the variable set in the hook.

jrm
  • 727
  • 5
  • 18
  • Thanks, I'm looking forward to trying it. – Aaron left Stack Overflow Dec 15 '11 at 16:50
  • Hi, I found your discussion very interesting. Is there a way use the code above to enable outline minor mode in Sweave?? Because when I move through ESS from LaTeX (and vice versa) all the outlined part were unfolded. – Riccardo Feb 25 '12 at 21:05
  • @Riccardo, I'm not sure how to solve the outline problem because of the description in my answer. That is, unless you hack the major modes to keep local variables. My solution was a bit of a hack so that fill-column sizes were the same for both modes. – jrm Feb 26 '12 at 13:58