[ESS] Folding chunks in Sweave?

Thomas Lumley tlumley at u.washington.edu
Mon Jul 24 18:37:44 CEST 2006


On Mon, 24 Jul 2006, Gregor Gorjanc wrote:

> Seth Falcon <sethfalcon <at> gmail.com> writes:
>
>>
>> Sebastian Luque <spluque <at> gmail.com> writes:
>>> Have you looked at folding-mode?  In Debian, it is included as part of the
>>> emacs-goodies-el.  I haven't used it, but think this might be possible
>>> with it, from what I remember of its info pages.
>>
>> Thanks.  I did find that during a web search.  Looks like it will do
>> what I want, but that I will have to add markers in the text to allow
>> it to work.  In theory, code chunks have enough markup to allow them
>> to fold, but I'm sure this will require some customization.
>
> I also interested in this application and took a look and found the
> following in
> the folding.el
>
> ;;  Example: changing default fold marks
> ;;
> ;;      In case you're not happy with the default folding marks, you
> ;;      can change them easily. Here is an example
> ;;
> ;;          (setq folding-load-hook 'my-folding-load-hook)
> ;;
> ;;          (defun my-folding-load-hook ()
> ;;            "Folding vars setup."
> ;;            (let* ((ptr (assq 'text-mode folding-mode-marks-alist)))
> ;;              (setcdr ptr (list "# {{{" "# }}}"))))
>
> So this should be hacked to work with Sweave chunks. However I am a bit
> sceptic about "enough markup". There surely is enough for the start i.e.
> <<someRegExp>>=, but the end is only @. And this character also appears
> in R code.
>

I don't think any sane R code will have a @ at the start of a line, but if 
you want to rule out insane code you will need to count parentheses 
carefully, eg
<<>>
1 + (a # ) 
@
b

This can't be done with a regexp -- it takes a stack machine to check that 
parentheses are matched. On the other hand, Sweave itself just uses the 
regexp "^@" to match the end of a code chunk, and there is presumably no 
need to handle Sweave syntax better than Sweave does.

 	-thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle




More information about the ESS-help mailing list