Regexp for imenu
Stephen Eglen
stephen at cogsci.ed.ac.uk
Fri Jan 11 23:25:10 CET 2002
Wright, Kevin writes:
> I typically format my functions this way:
>
> a<-function(){...}
>
> but imenu fails to recognize this as a function, expecting spaces around the
> assignment operator:
>
> a <- function()
>
> I think that the relevant part of ess-menu.el is
> "ess-S-imenu-function-regexp". The default value for this string is
>
> "^\\(.+\\)\\s-*<-\\s-*function"
>
>
> I've tried playing around with this regexp, for example
> "^\\(.+\\)[ ]*<-[ ]*function"
> and
> "^\\(.+\\)<-function"
>
>
>
> It looks to me like any of these should work for me, but I'm not having any
> luck. Am I missing something obvious?
yes, the regexps you suggest look fine. However, it seems the imenu
regexp is hardcoded (at least in 5.1.19) in the function ess-imenu-S:
(defun ess-imenu-S (&optional arg)
"S Language Imenu support for ESS.
Initial version from Stephen Eglen <stephen at cogsci.ed.ac.uk>."
(interactive)
(setq imenu-generic-expression
'( (nil ;;ess-S-imenu-generic-expression
"^\\(.+\\)\\s-+<-\\s-+function"
1)))
(imenu-add-to-menubar "Imenu-S"))
You can do a couple of things as workaround:
1) since imenu-generic-expression is buffer local, evaluate the
following in each R/S buffer that you want imenu to work in:
(setq imenu-generic-expression '( (nil "^\\(.+\\)\\s-*<-\\s-*function" 1)))
(that worked for me when removing whitespace around one of my function
definitions).
2) change the regexp in the defun above and visit a new R buffer (or
restart Emacs).
The problem you found is that are relevant variables in ESS that you
can set (such as ess-S-imenu-function-regexp), but they are not being
used by ess-imenu-S. (Why is ess-S-imenu-generic-expression in the
above defun commented out?)
Best wishes,
Stephen
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
ess-help mailing list -- To (un)subscribe, send
subscribe or unsubscribe
(in the "body", not the subject !) To: ess-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the ESS-help
mailing list