1 ;;; ess-menu.el --- Menu and Speedbar support for statistical
2 ;;; programming and analysis
4 ;; Copyright (C) 2000--2004 A.J. Rossini, Rich M. Heiberger, Martin
5 ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
7 ;; Original Author: A.J. Rossini
8 ;; Created: September 4, 2000
9 ;; Maintainer: ESS Core Team <ESS-core@stat.math.ethz.ch>
11 ;; Keywords: statistical support
13 ;; Summary: general functions for ESS
15 ;; This file is part of ESS
17 ;; This file is free software; you can redistribute it and/or modify
18 ;; it under the terms of the GNU General Public License as published by
19 ;; the Free Software Foundation; either version 2, or (at your option)
22 ;; This file is distributed in the hope that it will be useful,
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;; GNU General Public License for more details.
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with GNU Emacs; see the file COPYING. If not, write to
29 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
36 \f;;*;; Requires and autoloads
37 ;;;=====================================================
40 (if (and (featurep 'xemacs); need this, since require in XEmacs has only 2 arg
41 (not (require 'imenu "imenu.elc")))
42 (message "** warning: 'imenu not available for this version of XEmacs"))
44 ;;(defgroup ess-menu nil
45 ;; "ESS: object menu systems."
50 \f ;;; Function Menu (func-menu) for XEmacs:
52 ;; (if ess-funcmenu-use-p
53 ;; (defvar fume-function-name-regexp-S
55 ;; '((s-mode . fume-function-name-regexp-smode)
56 ;; (r-mode . fume-function-name-regexp-smode))
57 ;; fume-function-name-regexp-alist)
58 ;; "Expression to get function names"))
60 \f ;;; Imenu for Emacs/XEmacs...
64 (defcustom ess-imenu-use-S ess-imenu-use-p
65 "*Non-nil means include an Imenu menu item in S buffers."
69 (defvar ess-imenu-S-generic-expression
70 '(("Functions" "^\\(.+\\)\\s-*<-[ \t\n]*function[ ]*(" 1)
71 ("Classes" "^.*setClass(\\(.*\\)," 1)
72 ("Generics" "^.*setGeneric(\\(.*\\)," 1)
73 ;;("Methods" "^.*setMethod(\\(.*,\\(signature=\\)?.*\\)," 1)
74 ;;("Other" "^\\(.+\\)\\s-*<-[ \t\n]*[^\\(function\\|read\\|.*data\.frame\\)]" 1)
75 ("Methods" "^.*setMethod(\"\\(.+\\)\","1) ;;[ ]*\\signature=\\)?(\\(.*,?\\)*\\)," 1)
76 ("Package" "^.*\\(library\\|require\\)(\\(.*\\)," 2)
77 ("Data" "^\\(.+\\)\\s-*<-[ \t\n]*\\(read\\|.*data\.frame\\).*(" 1)))
79 (defun ess-imenu-S (&optional arg)
80 "S Language Imenu support for ESS."
82 (setq imenu-generic-expression ess-imenu-S-generic-expression)
83 (imenu-add-to-menubar "Imenu-S"))
85 (fset 'ess-imenu-R 'ess-imenu-S)
89 ;(defun ess-imenu-XLS (&optional arg)
90 ; "XLispStat Language Imenu support for ESS."
92 ; (setq imenu-generic-expression
93 ; '( (nil "New one needed" 1)))
94 ; (imenu-add-to-menubar "XLS-fcts"))
96 ;(defun imenu-example--XLS-extract-index-name ()
97 ; ;; Example of a candidate for `imenu-extract-index-name-function'.
98 ; ;; This will generate a flat index of definitions in a lisp file.
100 ; (and (looking-at "(def")
101 ; (condition-case nil
105 ; (let ((beg (point))
106 ; (end (progn (forward-sexp -1) (point))))
107 ; (buffer-substring beg end)))
110 ;(defun imenu-example--create-XLS-index ()
111 ; ;; Example of a candidate for `imenu-create-index-function'.
112 ; ;; It will generate a nested index of definitions.
113 ; (let ((index-alist '())
114 ; (index-var-alist '())
115 ; (index-type-alist '())
116 ; (index-unknown-alist '())
118 ; (goto-char (point-max))
119 ; (imenu-progress-message prev-pos 0)
120 ; ;; Search for the function
121 ; (while (beginning-of-defun)
122 ; (imenu-progress-message prev-pos nil t)
124 ; (and (looking-at "(def")
128 ; ((looking-at "def\\(var\\|const\\)")
130 ; (push (imenu-example--name-and-position)
132 ; ((looking-at "def\\(un\\|subst\\|macro\\|advice\\)")
134 ; (push (imenu-example--name-and-position)
136 ; ((looking-at "def\\(type\\|struct\\|class\\|ine-condition\\)")
138 ; (if (= (char-after (1- (point))) ?\))
143 ; (push (imenu-example--name-and-position)
147 ; (push (imenu-example--name-and-position)
148 ; index-unknown-alist)))))))
149 ; (imenu-progress-message prev-pos 100)
150 ; (and index-var-alist
151 ; (push (cons "Variables" index-var-alist)
153 ; (and index-type-alist
154 ; (push (cons "Types" index-type-alist)
156 ; (and index-unknown-alist
157 ; (push (cons "Syntax-unknown" index-unknown-alist)
161 ;(defun ess-imenu-STA (&optional arg)
162 ; "Stata Language Imenu support for ESS."
164 ; (setq imenu-generic-expression
165 ; '( (nil "New one needed" 1)))
166 ; (imenu-add-to-menubar "Stata-fcts"))
168 (defun ess-imenu-SAS (&optional arg)
169 "SAS language Imenu support for ESS."
171 (setq imenu-generic-expression
172 '( (nil "[ \t\n=]\\([a-zA-Z_][a-zA-Z_0-9]*[.][a-zA-Z_][a-zA-Z_0-9]*\\)[ ,()\t\n;]" 1)))
173 (imenu-add-to-menubar "SAS Datasets"))
175 \f ;;; Speedbar stuff.
177 (defun ess-S-initialize-speedbar ()
178 "Extend to all extensions; see initialization, and edit."
179 (speedbar-add-supported-extension ".R")
180 (speedbar-add-supported-extension ".S")
181 (speedbar-add-supported-extension ".s")
182 (speedbar-add-supported-extension ".q"))
184 ;(if (featurep 'speedbar)
186 ; (message "enabling speedbar support")
187 ; (require 'speedbar)
188 ; (ess-S-initialize-speedbar)))
194 (when (featurep 'speedbar)
195 (message "enabling speedbar support")
197 (defun S-speedbar-buttons (buffer)
200 ;;(speedbar-make-tag-line)
201 ;;(speedbar-insert-button)
202 (speedbar-with-writable))
204 (fset 'R-speedbar-buttons 'S-speedbar-buttons)
206 (defun S-speedbar-menu-items ( )
209 (ess-S-initialize-speedbar)))
212 \f ; Run load hook and provide package
216 \f ; Local variables section
218 ;;; This file is automatically placed in Outline minor mode.
219 ;;; The file is structured as follows:
222 ;;; Subsections: ;;;*;;;
223 ;;; Components: defuns, defvars, defconsts
224 ;;; Random code beginning with a ;;;;* comment
228 ;;; mode: outline-minor
229 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
232 ;;; ess-menu.el ends here