Current function name in R/S-Plus

Stephen Eglen eglen at pcg.wustl.edu
Sun Jun 23 00:53:38 CEST 2002


 > I sometimes want to know the name of the function that I'm editing.  After
 > some searching on Google, it appears that "which-function-mode" can be used
 > with imenu.  Since R source files support imenu, this might be a way to
 > continuously see the function name in the modeline.
 > 
 > My modeline space is precious and also ess seems not to support imenu for S
 > source code files, so I spent the last hour hacking a function to print the
 > name of the current function to the minibuffer.  I bind the function to a
 > key.

hi Kevin,

I worked a bit on getting imenu support under R, and I think the same
code should work under S mode, since there is no difference in syntax
(as I understand).


So, first to test that imenu works okay in S modes, when you are in a
S mode buffer eval the code:

  M-: (ess-imenu-S)

and you should see the "Imenu-S" menubar.

If that works, to switch Imenu on in all S mode buffers, you may want
to follow the way that R does it.  At the moment, R-mode is defined
as:

(defun R-mode  (&optional proc-name)
  "Major mode for editing R source.  See `ess-mode' for more help."
  (interactive)
  (setq ess-customize-alist R-customize-alist)
  ;;(setq imenu-generic-expression R-imenu-generic-expression)
  (ess-mode R-customize-alist proc-name)
  ;;; AJR: Need to condition on this...!
  ;; MM: and you probably should really use ess-imenu-mode-function from above!
  (ess-imenu-R))

So, you could switch on imenu by changing S-mode to:

(defun S+6-mode (&optional proc-name)
  "Major mode for editing S+6 source.  See `ess-mode' for more help."
  (interactive)
  (setq ess-customize-alist S+6-customize-alist)
  (ess-mode S+6-customize-alist proc-name)
  (ess-imenu-S))				;add this line


Once that works, can which-function-mode then just work from imenu
support?  (how did you hook up your defun into which-function-mode?)

I'd also suggest to the ESS core that the code also be tweaked a bit
more.  The following two vars are defined in ess-menu.el, but they don't seem to be used.

(defcustom ess-use-imenu t
  "Use imenu if exists."
  :group 'ess
  :type  'boolean)

(defcustom ess-S-use-imenu ess-use-imenu
  "Use imenu if exists."
  :group 'ess
  :type  'boolean)

Presumably they could be used (if still needed) in the following way:

(defun R-mode  (&optional proc-name)
  "Major mode for editing R source.  See `ess-mode' for more help."
  (interactive)
  (setq ess-customize-alist R-customize-alist)
  (ess-mode R-customize-alist proc-name)
  (if ess-S-use-imenu
      (ess-imenu-R)))

(defun S+6-mode (&optional proc-name)
  "Major mode for editing S+6 source.  See `ess-mode' for more help."
  (interactive)
  (setq ess-customize-alist S+6-customize-alist)
  (ess-mode S+6-customize-alist proc-name)
  (if ess-S-use-imenu
      (ess-imenu-S)))



Cheers,
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