[ESS] Folding chunks in Sweave?

Gregor Gorjanc gregor.gorjanc at bfro.uni-lj.si
Mon Jul 24 21:19:08 CEST 2006


Thomas Lumley <tlumley <at> u.washington.edu> writes:
> On Mon, 24 Jul 2006, Gregor Gorjanc wrote:
...
> >
> > ;;  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  <at> . And this character also
> > appears
> > in R code.
> >
> 
> I don't think any sane R code will have a  <at>  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 # ) 
>  <at> 
> 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 "^ <at> " to match the end of a code chunk, and there is presumably no 
> need to handle Sweave syntax better than Sweave does.

Thank you Stephen and Thomas for this. Seems that regexp "^@" will do the 
job for markup at the end. I was to fast before on sending mail about 
default fold marks as one can also define mode specific markups - this is 
the example from documentation for c-mode

(folding-add-to-marks-list 'c-mode "/* {{{ " "/* }}} */" " */" t)

Now U just need someone to write appropriate lisp code with before 
mentioned regexps. Lisp is really an overhead for me. Anyone?.

Thanks, Gregor




More information about the ESS-help mailing list