Regexp for imenu

Martin Maechler maechler at stat.math.ethz.ch
Mon Jan 14 10:37:54 CET 2002


>>>>> "StEgl" == Stephen Eglen <stephen at cogsci.ed.ac.uk> writes:

    StEgl> 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()

Just one *strong* comment :

Almost all experienced S (R and S-plus) programmers I know
*strongly* recommend using spaces around "<-" 

The current ESS behavior would encourage you to change your
(wrong space saving) behavior.   One other way to encourage the
" <- " is the fact that using "_" (underscore) has been
producing " <- " automagically in ESS for a while
{and yes; it also did it in SAS-mode once which *was* a bug ..}

    >> 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?

The real problem with the imenu regexp is that it's not
compatible with, the Emacs syntax table or at least font-lock's
behavior, and IMO the real bug of ess-imenu's regexp is that

mylongnamedfunction.Method <-
   function(x, y, ....) {

}

is not `seen' by the current regexp!
So, yes, we *do* have to fix this, and may also allow the
VERY-UGLY-no-whitespace assignment arrow.

Martin


    StEgl> yes, the regexps you suggest look fine.  However, it
    StEgl> seems the imenu regexp is hardcoded (at least in
    StEgl> 5.1.19) in the function ess-imenu-S:

    StEgl> (defun ess-imenu-S (&optional arg) "S Language Imenu
    StEgl> support for ESS.  Initial version from Stephen Eglen
    StEgl> <stephen at cogsci.ed.ac.uk>."  (interactive) (setq
    StEgl> imenu-generic-expression '( (nil
    StEgl> ;;ess-S-imenu-generic-expression
    StEgl> "^\\(.+\\)\\s-+<-\\s-+function" 1)))
    StEgl> (imenu-add-to-menubar "Imenu-S"))

    StEgl> You can do a couple of things as workaround:

    StEgl> 1) since imenu-generic-expression is buffer local,
    StEgl> evaluate the following in each R/S buffer that you
    StEgl> want imenu to work in:

    StEgl> (setq imenu-generic-expression '( (nil
    StEgl> "^\\(.+\\)\\s-*<-\\s-*function" 1)))

    StEgl>  (that worked for me when removing whitespace around
    StEgl> one of my function definitions).

    StEgl> 2) change the regexp in the defun above and visit a
    StEgl> new R buffer (or restart Emacs).

    StEgl> The problem you found is that are relevant variables
    StEgl> in ESS that you can set (such as
    StEgl> ess-S-imenu-function-regexp), but they are not being
    StEgl> used by ess-imenu-S.  (Why is
    StEgl> ess-S-imenu-generic-expression in the above defun
    StEgl> commented out?)

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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