[ESS-bugs] ess-function-pattern not working for some valid functions
Keith Ponting
k.ponting at aurix.com
Tue Mar 15 15:54:19 CET 2011
Dear Martin,
Toby and I have already discovered our coincident interest in this and have been in communication, with the upshot that we will put the revised regexps on the inlinedocs web site. I appreciate your reasons for caution.
It turns out that neither of us had our original submissions quite right (among other things we also need a change to ess-set-function-pattern), but I have been happily working with the current version for some days now. However I am not a heavy user of S4 classes so have only done limited tests on the "set" functions. Is there a "torture test" for these function patterns somewhere?
>From a long term maintenance point of view, I would still like to propose a change to the ESS sources to avoid forking - for example I expect you will be modifying or have modified to support setRefClass - but I would be happy to accept some kind of "quarantine period" while we (and I hope some others) try out the patterns.
My current ess-mode-hook includes the following, but I think that I could remove everything after function\\b, so will try that out when I have time:
(add-hook 'ess-mode-hook
'(lambda()
;; modifications to function pattern allow R.oo setConstructorS3, setMethodS3, (inlinedocs) structure call and documentation between keyword function and opening (
(setq ess-function-pattern "\\(\\(\\(\\s\"\\[?\\[?\\(\\sw\\|\\s_\\)*\\(<-\\)?\\(\\sw\\|\\s_\\)*\\s\"\\)\\|\\(\\(^\\|[ ]\\)\\(\\sw\\|\\s_\\)+\\)\\)\\s-*\\(<-\\|=\\)\\|^set\\(As\\|Method\\|MethodS3\\|ConstructorS3\\|Generic\\|GroupMethod\\|ReplaceMethod\\)(\\s\"\\[?\\[?\\(\\sw\\|\\s_\\)*\\s\",\\(\\s-\\|\n\\)*.*\\)\\(\\(\\s-\\|\n\\)*\\s<.*\\s>\\)*\\(\\s-\\|\n\\)*\\(structure\\s-*(\\s-*\\(?:\\(?:#.*\\)?\n\\s-*\\)*\\)?function\\b\\s-*\\(?:\\(?:#.*\\)?\n\\s-*\\)*(?")
;; modifications to function start allow R.oo setConstructorS3, setMethodS3 and (inlinedocs) structure call
(setq ess-set-function-start "\\(^set[MGARC][Ma-z]+\\(?:S3\\)?\\)\\|\\(.*<-\\s-*structure\\)\\s-*(")
))
Regards,
Keith
P.S. I forgot to say last time how much I appreciate ESS and all the work you do - I am an avid lurker on the ess-help list!
Keith Ponting
Aurix Ltd, Malvern WR14 3SZ UK
> -----Original Message-----
> From: Martin Maechler [mailto:maechler at stat.math.ethz.ch]
> Sent: 15 March 2011 14:01
> To: Toby Dylan Hocking
> Cc: Keith Ponting; ess-bugs at stat.math.ethz.ch
> Subject: Re: [ESS-bugs] ess-function-pattern not working for some valid
> functions
>
> Dear Toby,
> your attachment did not come through the filters
> .. -> .. -> ESS-bugs -> ESS-core ->
>
> but interestingly, somewhat simultaneously to your post to ESS-bugs,
> there was one to ESS-help from Keith Ponting.
> see the list archive entry
> https://stat.ethz.ch/pipermail/ess-help/2011-March/006764.html
> (and then the attachment in there -- he used HTML in e-mail --)
>
> where he writes
>
> > However the comments between the function keyword and the opening >
> parenthesis do not match ess-function-pattern. I realise that it is >
> already an extremely complicated regexp, but after a bit of tweaking I
> > found that the following change (which also allows the function
> argument > list opening parenthesis to be on a new line without any
> intervening > comments) appears to work: replace the trailing
> "function\\s-*(" with > "function\\s-*\\(?:\\(?:#.*\\)?\n\\s-*\\)*(".
> This modification can be > done locally in any number of ways (emacs
> file-local variables, > directory-local variables, ess-mode-hook etc.),
> but I wonder whether I > could propose the above as a modification to
> ESS?
>
> and I haven't much tried his proposition yet, either.
>
> I do know that I had spent too many numerous hours in the past, fiddling
> with those regexps, and the last few improvement attempts all had failed
> in sofar as they fixed one case but broke another one.
>
> Have you guys both worked for several days with the *changed* regexps?
> (I don't know yet Toby's changes).
>
> Toby, could you show us your patch?
>
> Thank you for your contributions; I'd definitely like to look into.
>
> Best regards,
> Martin
>
> Martin <Maechler at stat.math.ethz.ch> http://stat.ethz.ch/people/maechler
> Seminar für Statistik, ETH Zürich HG G 16 Rämistrasse 101
> CH-8092 Zurich, SWITZERLAND
> phone: +41-44-632-3408 fax: ...-1228 <><
>
>
> >>>>> Toby Dylan Hocking <Toby.Hocking at inria.fr>
> >>>>> on Thu, 10 Mar 2011 15:00:33 +0100 writes:
>
> > Dear ESS developers,
> > First of all, thank you very much for ESS, a great piece of free
> > software which I use every day!
>
> > I like using the C-c C-f key sequence to load individual
> > functions into an inferior R process, but I noticed that it
> > doesn't work for some syntactically-valid functions, such as
>
> > comments.and.ex <- structure(function
> > ### some docs
> > ### more
> > (arg,
> > arg2
> > ){
> > foo
> > ### value
> > },ex=function(){
> > some.code
> > })
>
> > To solve this problem, I propose a patch to ess-mode.el, which
> > simply updates the regular expression used to match functions.
>
> > I have attached the patch and some R code that illustrates
> > several example functions which are valid R code, but are not
> > currently matched by ess-function-pattern.
>
> > Does this patch pose any problem for you guys? Can you
> > incorporate it into the main ESS source code?
>
> > Thanks for the great package, and for your consideration,
> > Toby Dylan Hocking
> > http://cbio.ensmp.fr/~thocking/
>
>
> > ------------------------------------------------------------------
> ----
> > testfun <- function(foo){ bar } testfun <- function (foo){ bar }
> > oneline <- function(foo)bar comments <- function ### some docs
> > ### more (arg, arg2 ){ foo
> > ###
> > }
>
> > comments.and.ex <- structure(function
> > ### some docs
> > ### more
> > (arg,
> > arg2
> > ){
> > foo
> > ###
> > },ex=function(){
> > some.code
> > })
>
> > ------------------------------------------------------------------
> ----
> > _______________________________________________ ESS-bugs
> > ESS-bugs at r-project.org
> > https://stat.ethz.ch/mailman/listinfo/ess-bugs
>
> > ------------------------------------------------------------------
> ----
> > _______________________________________________ ESS-core list:
> > https://stat.ethz.ch/mailman/listinfo/ess-core
More information about the ESS-bugs
mailing list