Initial Commit
[packages] / xemacs-packages / ess / lisp / ess-menu.el
1 ;;; ess-menu.el --- Menu and Speedbar support for statistical
2 ;;; programming and analysis
3
4 ;; Copyright (C) 2000--2004 A.J. Rossini, Rich M. Heiberger, Martin
5 ;;      Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
6
7 ;; Original Author: A.J. Rossini
8 ;; Created: September 4, 2000
9 ;; Maintainer: ESS Core Team <ESS-core@stat.math.ethz.ch>
10
11 ;; Keywords: statistical support
12
13 ;; Summary: general functions for ESS
14
15 ;; This file is part of ESS
16
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)
20 ;; any later version.
21 ;;
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.
26 ;;
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.
30 ;;
31
32 ;;; Commentary:
33
34 ;;; Code:
35
36 \f;;*;; Requires and autoloads
37 ;;;=====================================================
38
39 (require 'ess-cust)
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"))
43
44 ;;(defgroup ess-menu nil
45 ;;  "ESS: object menu systems."
46 ;;  :group 'ess
47 ;;  :prefix "ess-")
48
49
50 \f ;;; Function Menu (func-menu) for XEmacs:
51
52 ;; (if ess-funcmenu-use-p 
53 ;;     (defvar fume-function-name-regexp-S
54 ;;       (append
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"))
59
60 \f ;;; Imenu for Emacs/XEmacs...
61
62 ;;; S imenu support
63
64 (defcustom ess-imenu-use-S ess-imenu-use-p
65   "*Non-nil means include an Imenu menu item in S buffers."
66   :group 'ess
67   :type  'boolean)
68
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)))
78
79 (defun ess-imenu-S (&optional arg)
80   "S Language Imenu support for ESS."
81   (interactive)
82   (setq imenu-generic-expression ess-imenu-S-generic-expression)
83   (imenu-add-to-menubar "Imenu-S"))
84
85 (fset 'ess-imenu-R 'ess-imenu-S)
86
87 ;;; XLS imenu support
88
89 ;(defun ess-imenu-XLS (&optional arg)
90 ;  "XLispStat Language Imenu support for ESS."
91 ;  (interactive)
92 ;  (setq imenu-generic-expression
93 ;       '( (nil "New one needed" 1)))
94 ;  (imenu-add-to-menubar "XLS-fcts"))
95
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.
99 ;  (save-match-data
100 ;    (and (looking-at "(def")
101 ;        (condition-case nil
102 ;            (progn
103 ;              (down-list 1)
104 ;              (forward-sexp 2)
105 ;              (let ((beg (point))
106 ;                    (end (progn (forward-sexp -1) (point))))
107 ;                (buffer-substring beg end)))
108 ;          (error nil)))))
109
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 '())
117 ;       prev-pos)
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)
123 ;      (save-match-data
124 ;       (and (looking-at "(def")
125 ;            (save-excursion
126 ;              (down-list 1)
127 ;              (cond
128 ;               ((looking-at "def\\(var\\|const\\)")
129 ;                (forward-sexp 2)
130 ;                (push (imenu-example--name-and-position)
131 ;                      index-var-alist))
132 ;               ((looking-at "def\\(un\\|subst\\|macro\\|advice\\)")
133 ;                (forward-sexp 2)
134 ;                (push (imenu-example--name-and-position)
135 ;                      index-alist))
136 ;               ((looking-at "def\\(type\\|struct\\|class\\|ine-condition\\)")
137 ;                (forward-sexp 2)
138 ;                (if (= (char-after (1- (point))) ?\))
139 ;                    (progn
140 ;                      (forward-sexp -1)
141 ;                      (down-list 1)
142 ;                      (forward-sexp 1)))
143 ;                (push (imenu-example--name-and-position)
144 ;                      index-type-alist))
145 ;               (t
146 ;                (forward-sexp 2)
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)
152 ;              index-alist))
153 ;    (and index-type-alist
154 ;        (push (cons "Types" index-type-alist)
155 ;              index-alist))
156 ;    (and index-unknown-alist
157 ;        (push (cons "Syntax-unknown" index-unknown-alist)
158 ;              index-alist))
159 ;    index-alist))
160
161 ;(defun ess-imenu-STA (&optional arg)
162 ;  "Stata Language Imenu support for ESS."
163 ;  (interactive)
164 ;  (setq imenu-generic-expression
165 ;       '( (nil "New one needed" 1)))
166 ;  (imenu-add-to-menubar "Stata-fcts"))
167
168 (defun ess-imenu-SAS (&optional arg)
169   "SAS language Imenu support for ESS."
170   (interactive)
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"))
174
175 \f ;;; Speedbar stuff.
176
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"))
183
184 ;(if (featurep 'speedbar)
185 ;    (progn
186 ;      (message "enabling speedbar support")
187 ;      (require 'speedbar)
188 ;      (ess-S-initialize-speedbar)))
189
190 (eval-when-compile
191   (condition-case nil
192     (progn
193       (require 'speedbar)
194         (when (featurep 'speedbar)
195           (message "enabling speedbar support")
196
197             (defun S-speedbar-buttons (buffer)
198                 "attempted hack."
199
200                 ;;(speedbar-make-tag-line)
201                 ;;(speedbar-insert-button)
202                 (speedbar-with-writable))
203
204             (fset 'R-speedbar-buttons 'S-speedbar-buttons)
205
206             (defun S-speedbar-menu-items  ( )
207                 "Need to write.")
208
209       (ess-S-initialize-speedbar)))
210     (error nil)))
211
212 \f ; Run load hook and provide package
213
214 (provide 'ess-menu)
215
216 \f ; Local variables section
217
218 ;;; This file is automatically placed in Outline minor mode.
219 ;;; The file is structured as follows:
220 ;;; Chapters:     ^L ;
221 ;;; Sections:    ;;*;;
222 ;;; Subsections: ;;;*;;;
223 ;;; Components:  defuns, defvars, defconsts
224 ;;;              Random code beginning with a ;;;;* comment
225
226 ;;; Local variables:
227 ;;; mode: emacs-lisp
228 ;;; mode: outline-minor
229 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
230 ;;; End:
231
232 ;;; ess-menu.el ends here