(ess-s-versions-list): New variable.
[ess.git] / lisp / essd-sp6.el
blob98cfc6fe52a09e8bf206a564eb289b54d6f0ebc6
1 ;;; essd-sp6.el --- S-Plus 6 customization
3 ;; Copyright (C) 2001--2004 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-search-list-command . "searchPaths()\n")
87 (ess-directory-function . S+6-directory-function)
88 (ess-setup-directory-function . S+6-setup-directory-function)
89 (inferior-ess-start-args . inferior-Splus-args)
90 (ess-STERM . "iESS")
92 S+common-cust-alist)
94 "Variables to customize for S+6.")
97 (defun S+6 (&optional proc-name)
98 "Call 'Splus6', based on S version 4, from Bell Labs.
99 New way to do it."
100 (interactive)
101 (setq ess-customize-alist S+6-customize-alist)
102 (ess-write-to-dribble-buffer
103 (format "\n(S+6): ess-dialect=%s, buf=%s\n" ess-dialect (current-buffer)))
104 (inferior-ess)
105 (if inferior-ess-language-start
106 (ess-eval-linewise inferior-ess-language-start)))
109 (defun S+6-mode (&optional proc-name)
110 "Major mode for editing S+6 source. See `ess-mode' for more help."
111 (interactive)
112 (setq ess-customize-alist S+6-customize-alist)
113 (ess-mode S+6-customize-alist proc-name)
114 (if (fboundp 'ess-add-toolbar) (ess-add-toolbar))
115 (if ess-imenu-use-S (ess-imenu-S)))
117 (defun S+6-transcript-mode ()
118 "S-PLUS 6 transcript mode."
119 (interactive)
120 (ess-transcript-mode S+6-customize-alist))
122 (defvar ess-s-versions-list nil
123 "List of other versions of S to add to ESS.
124 Each element of this list is itself a list:
125 \(FUNCTION PATH ARGS\)
126 e.g.
127 \(\"mysplus\" \"/usr/splus7/bin/splus7\" \"-j\"\)
128 FUNCTION is the name of the function to be created by Emacs.
129 PATH is the full path to the variant of S that you want to run.
130 ARGS (optional) are start-up arguments that you want to pass to S.
133 (defvar ess-s-versions '("Splus")
134 "List of partial strings for versions of S to access within ESS.
135 Each string specifies the start of a filename. If a filename
136 beginning with one of these strings is found on `exec-path', a M-x
137 command for that version of S is made available. For example, if the
138 file \"Splus7\" is found and this variable includes the string
139 \"Splus\", a function called `M-x Splus7' will be available to run that
140 version of S.
141 If duplicate versions of the same program are found (which happens if
142 the same path is listed on `exec-path' more than once), they are
143 ignored by calling `ess-uniq-list'.
144 If you set this variable, you need to restart Emacs (and set this variable
145 before ess-site is loaded) for it to take effect.
147 See also `ess-s-versions-list' for another way to add other S
148 processes to ESS. ")
150 (defun ess-s-versions-create ()
151 "Generate defuns for starting other versions of S.
152 See `ess-s-versions' for strings that determine which functions are created.
153 It assumes these versions of S can be run as a substitute for Splus6.
155 This function returns the list of S defuns, if any, that were
156 created. The defuns will normally be placed on the menubar upon
157 ESS initialisation."
159 ;; This works by creating a temp buffer where the template function is
160 ;; edited so that X.Y is replaced by the version name
161 (let ((template "")
162 (template-args)
163 (beg)
164 (versions)
165 (version)
166 (eval-buf (get-buffer-create "*ess-temp-s-evals*"))
167 (ess-s-versions-created)
169 (ess-s-versions-list ess-s-versions-list)
170 ;; make local copy so it won't be destroyed globally
173 ;; This is the template function used for creating M-x Splus
174 (setq template "(defun S-X.Y ()
175 \"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS.
176 This function was generated by `ess-s-versions-create'.\"
177 (interactive \"\")
178 (let ((inferior-S+6-program-name \"S-X.Y\"))
179 (S+6)))
182 (save-excursion
183 (set-buffer eval-buf)
184 ;; clear the buffer.
185 (delete-region (point-min) (point-max))
187 ;; Find which versions of S we want. Remove the pathname, leaving just
188 ;; the name of the executable.
189 (setq versions
190 (ess-uniq-list
191 (mapcar 'file-name-nondirectory
192 (apply 'nconc
193 (mapcar 'ess-find-exec-completions
194 ess-s-versions)))))
195 (ess-write-to-dribble-buffer
196 (format "(S): ess-s-versions-create making M-x defuns for %s"
197 (mapconcat 'identity versions " ")))
198 (setq ess-s-versions-created versions) ;keep copy for returning at end.
199 ;; Iterate over each string in VERSIONS, creating a new defun each time.
200 (while versions
201 (setq version (car versions)
202 versions (cdr versions))
203 (setq beg (point))
204 (insert template)
205 (goto-char beg)
206 (while (search-forward "S-X.Y" nil t)
207 (replace-match version t t))
208 (goto-char (point-max))
212 ;; Check if we have any static defuns to evaluate.
213 (when ess-s-versions-list
215 ;; Need a slightly different template for static defuns.
216 (setq template "(defun S-X.Y ()
217 \"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS.
218 This function will run S-FULL-PATH
219 This function was generated by `ess-s-versions-create'.\"
220 (interactive \"\")
221 (let ((inferior-S+6-program-name \"S-FULL-PATH\"))
222 (S+6)))
225 ;; need another version of template, with args.
226 (setq template-args "(defun S-X.Y ()
227 \"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS.
228 This function will run S-FULL-PATH
229 This function was generated by `ess-s-versions-create'.\"
230 (interactive \"\")
231 (let ((inferior-S+6-program-name \"S-FULL-PATH\")
232 (inferior-Splus-args \"S-MYARGS\"))
233 (S+6)))
236 (while ess-s-versions-list
237 (setq this-S-version (car ess-s-versions-list)
238 S-defun (car this-S-version)
239 S-path (cadr this-S-version)
240 S-args (caddr this-S-version)
241 ess-s-versions-list (cdr ess-s-versions-list))
242 ;; Could do error checking here, that S-defun is not defined
243 ;; before, and that S-path is valid.
244 (setq beg (point))
245 (insert
246 (if S-args
247 template-args
248 template))
249 (goto-char beg)
250 (while (search-forward "S-X.Y" nil t)
251 (replace-match S-defun t t))
252 (goto-char beg)
253 (while (search-forward "S-FULL-PATH" nil t)
254 (replace-match S-path t t))
255 (when S-args
256 (goto-char beg)
257 (while (search-forward "S-MYARGS" nil t)
258 (replace-match S-args t t)))
259 (goto-char (point-max))
260 (add-to-list 'ess-s-versions-created S-defun 'append))
261 ;; buffer has now been created with defuns, so eval them!
262 (eval-buffer)
263 ;;(kill-buffer eval-buf)
265 ess-s-versions-created)))
267 \f ; Provide package
269 (provide 'essd-sp6)
271 \f ; Local variables section
273 ;;; This file is automatically placed in Outline minor mode.
274 ;;; The file is structured as follows:
275 ;;; Chapters: ^L ;
276 ;;; Sections: ;;*;;
277 ;;; Subsections: ;;;*;;;
278 ;;; Components: defuns, defvars, defconsts
279 ;;; Random code beginning with a ;;;;* comment
281 ;;; Local variables:
282 ;;; mode: emacs-lisp
283 ;;; outline-minor-mode: nil
284 ;;; mode: outline-minor
285 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
286 ;;; End:
288 ;;; essd-sp6.el ends here