ESS[SAS]: somebody forgot about the SUM statement (probably me)
[ess.git] / lisp / essd-sp6.el
blob1421b0d8248c0756894c9400edf6df504098611b
1 ;;; essd-sp6.el --- S-Plus 6 & 7 & 8 customization
3 ;; Copyright (C) 2001--2005 A.J. Rossini, Rich M. Heiberger, Martin
4 ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
6 ;; Original Author: A.J. Rossini <rossini@u.washington.edu>
7 ;; Created: 2001/02/06
8 ;; Maintainer: ESS Core Team <ESS-core@stat.math.ethz.ch>
10 ;; Keywords: start up, configuration.
12 ;; This file is part of ESS.
14 ;; This file is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
19 ;; This file is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to
26 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28 ;;; Commentary:
29 ;;; AJR copied S+5 to be S+6.
30 ;;; AJR copied S4 to be S+5.
31 ;;; DB contributed the changes from essd-sp3.el to
32 ;;; essd-s4.el. (removed the old ugly approach).
33 ;;; This file defines Sp5 customizations for ess-mode. Lots of thanks
34 ;;; to RMH and JMC for code and suggestions
35 ;;; Thanks to MM for making this sensible.
37 ;;; Requires and Autoloads:
39 (require 'essl-s)
41 (autoload 'inferior-ess "ess-inf" "Run an ESS process.")
42 (autoload 'ess-mode "ess-mode" "Edit an ESS process.")
44 ;;; Code:
46 ;; You now need to make sure you've defined if you are running 5.0 or 5.1.
47 ;; Lots of things are broken between them, GRR...
49 (defvar S+6-dialect-name "S+6"
50 "Name of 'dialect' for S-PLUS 6.");easily changeable in a user's .emacs
52 (defun S+6-directory-p (directory)
53 "Splus 5++ directories have a .Data directory and a __Meta directory within."
54 (and directory
55 (file-directory-p (concat directory ".Data"))
56 (file-directory-p (concat directory ".Data/__Meta"))))
58 (defvar S+6-directory-function
59 #'(lambda ()
60 (if (S+6-directory-p default-directory)
61 default-directory
62 (or ess-directory default-directory))))
64 (defvar S+6-setup-directory-function
65 #'(lambda (startdir)
66 (if (and startdir (S+6-directory-p startdir))
67 (progn
68 (setenv "S_WORK"
69 (if (getenv "S_WORK")
70 (concat startdir ":" (getenv "S_WORK"))
71 ;;(message "adding %s to S_WORK" startdir)
72 startdir))
73 ))))
75 (defvar S+6-customize-alist
76 (append
77 '((ess-local-customize-alist . 'S+6-customize-alist)
78 (ess-dialect . S+6-dialect-name)
79 (ess-loop-timeout . ess-S-loop-timeout);fixme: dialect spec.
80 (ess-function-pattern . ess-R-function-pattern)
82 (ess-object-name-db-file . "ess-sp6-namedb.el")
83 (inferior-ess-program . inferior-S+6-program-name)
84 (inferior-ess-help-command . "help(\"%s\",pager=\"slynx -dump\",window=F)\n")
85 (inferior-ess-help-filetype . nil)
86 (inferior-ess-search-list-command . "searchPaths()\n")
88 (ess-directory-function . S+6-directory-function)
89 (ess-setup-directory-function . S+6-setup-directory-function)
90 (inferior-ess-start-args . inferior-Splus-args)
91 (ess-STERM . "iESS")
93 S+common-cust-alist)
95 "Variables to customize for S+6.")
98 (defun S+6 (&optional proc-name)
99 "Call 'Splus6', based on S version 4, from Bell Labs.
100 New way to do it."
101 (interactive)
102 (setq ess-customize-alist S+6-customize-alist)
103 (ess-write-to-dribble-buffer
104 (format "\n(S+6): ess-dialect=%s, buf=%s\n" ess-dialect (current-buffer)))
105 (inferior-ess)
106 (if inferior-ess-language-start
107 (ess-eval-linewise inferior-ess-language-start)))
110 (defun S+6-mode (&optional proc-name)
111 "Major mode for editing S+6 source. See `ess-mode' for more help."
112 (interactive)
113 (setq ess-customize-alist S+6-customize-alist)
114 (ess-mode S+6-customize-alist proc-name)
115 (if (fboundp 'ess-add-toolbar) (ess-add-toolbar))
116 (if ess-imenu-use-S (ess-imenu-S)))
118 (defun S+6-transcript-mode ()
119 "S-PLUS 6 transcript mode."
120 (interactive)
121 (ess-transcript-mode S+6-customize-alist))
123 (defvar ess-s-versions-list nil
124 "List of other versions of S to add to ESS.
125 Each element of this list is itself a list:
126 \(FUNCTION PATH ARGS\)
127 e.g.
128 \(\"mysplus\" \"/usr/splus7/bin/splus7\" \"-j\"\)
129 FUNCTION is the name of the function to be created by Emacs.
130 PATH is the full path to the variant of S that you want to run.
131 ARGS (optional) are start-up arguments that you want to pass to S.
134 (defvar ess-s-versions '("Splus")
135 "List of partial strings for versions of S to access within ESS.
136 Each string specifies the start of a filename. If a filename
137 beginning with one of these strings is found on `exec-path', a M-x
138 command for that version of S is made available. For example, if the
139 file \"Splus7\" is found and this variable includes the string
140 \"Splus\", a function called `M-x Splus7' will be available to run that
141 version of S.
142 If duplicate versions of the same program are found (which happens if
143 the same path is listed on `exec-path' more than once), they are
144 ignored by calling `ess-uniq-list'.
145 Set this variable to nil to disable searching for other versions
146 of S using this method.
147 If you set this variable, you need to restart Emacs (and set this variable
148 before ess-site is loaded) for it to take effect.
150 See also `ess-s-versions-list' for another way to add other S
151 processes to ESS. ")
153 (defun ess-s-versions-create ()
154 "Generate defuns for starting other versions of S.
155 See `ess-s-versions' for strings that determine which functions are created.
156 It assumes these versions of S can be run as a substitute for Splus6.
158 This function returns the list of S defuns, if any, that were
159 created. The defuns will normally be placed on the menubar upon
160 ESS initialisation."
162 ;; This works by creating a temp buffer where the template function is
163 ;; edited so that X.Y is replaced by the version name
164 (let ((template "")
165 (template-args)
166 (beg)
167 (versions)
168 (version)
169 (eval-buf (get-buffer-create "*ess-temp-s-evals*"))
170 (ess-s-versions-created)
172 (ess-s-versions-list ess-s-versions-list)
173 ;; make local copy so it won't be destroyed globally
176 ;; This is the template function used for creating M-x Splus
177 (setq template "(defun S-X.Y ()
178 \"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS.
179 This function was generated by `ess-s-versions-create'.\"
180 (interactive \"\")
181 (let ((inferior-S+6-program-name \"S-X.Y\"))
182 (S+6)))
185 (save-excursion
186 (set-buffer eval-buf)
187 ;; clear the buffer.
188 (delete-region (point-min) (point-max))
190 (when ess-s-versions
191 ;; Find which versions of S we want. Remove the pathname, leaving just
192 ;; the name of the executable.
193 (setq versions
194 (ess-uniq-list
195 (mapcar 'file-name-nondirectory
196 (apply 'nconc
197 (mapcar 'ess-find-exec-completions
198 ess-s-versions)))))
199 (ess-write-to-dribble-buffer
200 (format "(S): ess-s-versions-create making M-x defuns for \n %s\n"
201 (mapconcat 'identity versions "\n ")))
202 (setq ess-s-versions-created versions) ;keep copy for returning at end.
203 ;; Iterate over each string in VERSIONS, creating a new defun each time.
204 (while versions
205 (setq version (car versions)
206 versions (cdr versions))
207 (setq beg (point))
208 (insert template)
209 (goto-char beg)
210 (while (search-forward "S-X.Y" nil t)
211 (replace-match version t t))
212 (goto-char (point-max))
215 ;; Check if we have any static defuns to evaluate.
216 (when ess-s-versions-list
218 ;; Need a slightly different template for static defuns.
219 (setq template "(defun S-X.Y ()
220 \"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS.
221 This function will run S-FULL-PATH
222 This function was generated by `ess-s-versions-create'.\"
223 (interactive \"\")
224 (let ((inferior-S+6-program-name \"S-FULL-PATH\"))
225 (S+6)))
228 ;; need another version of template, with args.
229 (setq template-args "(defun S-X.Y ()
230 \"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS.
231 This function will run S-FULL-PATH
232 This function was generated by `ess-s-versions-create'.\"
233 (interactive \"\")
234 (let ((inferior-S+6-program-name \"S-FULL-PATH\")
235 (inferior-Splus-args \"S-MYARGS\"))
236 (S+6)))
239 (while ess-s-versions-list
240 (let* ((this-S-version (car ess-s-versions-list))
241 (S-defun (nth 0 this-S-version))
242 (S-path (nth 1 this-S-version))
243 (S-args (nth 2 this-S-version)))
244 (setq ess-s-versions-list (cdr ess-s-versions-list))
245 ;; Could do error checking here, that S-defun is not defined
246 ;; before, and that S-path is valid.
247 (setq beg (point))
248 (insert
249 (if S-args
250 template-args
251 template))
252 (goto-char beg)
253 (while (search-forward "S-X.Y" nil t)
254 (replace-match S-defun t t))
255 (goto-char beg)
256 (while (search-forward "S-FULL-PATH" nil t)
257 (replace-match S-path t t))
258 (when S-args
259 (goto-char beg)
260 (while (search-forward "S-MYARGS" nil t)
261 (replace-match S-args t t)))
262 (goto-char (point-max))
263 (add-to-list 'ess-s-versions-created S-defun 'append))))
265 ;; buffer has now been created with defuns, so eval them!
266 (eval-buffer)
267 (kill-buffer eval-buf); < comment this for debugging
268 ess-s-versions-created)))
270 \f ; Provide package
272 (provide 'essd-sp6)
274 \f ; Local variables section
276 ;;; This file is automatically placed in Outline minor mode.
277 ;;; The file is structured as follows:
278 ;;; Chapters: ^L ;
279 ;;; Sections: ;;*;;
280 ;;; Subsections: ;;;*;;;
281 ;;; Components: defuns, defvars, defconsts
282 ;;; Random code beginning with a ;;;;* comment
284 ;;; Local variables:
285 ;;; mode: emacs-lisp
286 ;;; outline-minor-mode: nil
287 ;;; mode: outline-minor
288 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
289 ;;; End:
291 ;;; essd-sp6.el ends here