16
votes

Is there an Emacs minor-mode (or piece of elisp code) that lets you selectively hide/show environments while in Sweave (Sweave = R + LaTeX)?

For instance, I would like to move to the beginning of a code block (<<>>), hit a keystroke, and have the contents of the environment hidden from view.

Is this possible? I just tried hs-minor-mode, allout-mode, and outline-minor-mode, but most of them don't recognize R environments.

I also tryed org-mode that works great for folding/unfolding but, do not support the LaTeX highlighting code for expression like: \cite{}; \ref{}; \ce{} ...

Best Riccardo

--EDIT--

I tried for some day to use emacs-folding-mode but, because I work on a very long code (more than 2000 rows), folding mode "goes crazy" and for example misunderstand the mining of some special character (i.e. $), that has very different use both in R than LaTeX. I think the problem is intrinsic to Sweave, because in the same buffer I have R code and LaTeX code together.

So, now I'm testing emacs outline minor mode. But when I move through R from LaTeX (and vice versa) all the outlined part were unfolded despite I write in my .emacs:

(defun turn-on-outline-minor-mode ()
 (outline-minor-mode 1))
  (add-hook 'ess-mode-hook 'turn-on-outline-minor-mode)
  (add-hook 'LaTeX-mode-hook 'turn-on-outline-minor-mode)
  (add-hook 'latex-mode-hook 'turn-on-outline-minor-mode)
(setq outline-minor-mode-prefix "\C-c\C-o")

Do you have any suggestions??

Regards

--EDIT 2--

It seems to work:

(load "folding" 'nomessage 'noerror)
(folding-mode-add-find-file-hook)
(add-hook 'LaTeX-mode-hook 'folding-mode) 
(add-hook 'ess-mode-hook 'folding-mode) 
(folding-add-to-marks-list 'ess-mode "#{{{ " "#}}}" " ")

I don't know if is right that, when you leave the chunk, it is automatically unfolded.

2
it's the implementation of Rnw mode which gives you the trouble. I've also tried hideshow. But because Rnw resets the mode in the chunks you leave/enter, everything is getting reset. There are some talks in ESS to rewrite the Rnw, based on a better noweb.el.VitoshKa
Hi, I partially solved the problem using the folding mode. I re-re-edited the post with mine solution.Riccardo

2 Answers

1
votes
0
votes

I have had very good results with the hideshow hs-minor-mode, these are the lines I basically use in my ~/.emacs.d/init.el:

(add-hook 'ess-mode-hook 'hs-minor-mode)

(eval-after-load 'hideshow
 '(progn
   (global-set-key (kbd "C-+") 'hs-toggle-hiding)))