6
votes

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?

1
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
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. - jrm
@jrm: Nothing wrong with splitting hairs, you raise an important point ;) However, I find saying "an Sweave" document a bit grating, and would still go for "a Sweave". - csgillespie
Thanks for the link @csgillespie. Now I really want to hear your pronunciation. :) - jrm
I always say "ehs-weave", so "an" works for me too. How do you say Sweave, @csgillespie? - Aaron left Stack Overflow

1 Answers

4
votes

By reading a similar question on the [email protected] 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.