*** empty log message ***
[ess.git] / lisp / essd-sp6.el
blob00910e77820e8d310ad5ce4c54fbfec539eddeb4
1 ;;; essd-sp6.el --- S-Plus 6 & 7 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-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 Set this variable to nil to disable searching for other versions
145 of S using this method.
146 If you set this variable, you need to restart Emacs (and set this variable
147 before ess-site is loaded) for it to take effect.
149 See also `ess-s-versions-list' for another way to add other S
150 processes to ESS. ")
152 (defun ess-s-versions-create ()
153 "Generate defuns for starting other versions of S.
154 See `ess-s-versions' for strings that determine which functions are created.
155 It assumes these versions of S can be run as a substitute for Splus6.
157 This function returns the list of S defuns, if any, that were
158 created. The defuns will normally be placed on the menubar upon
159 ESS initialisation."
161 ;; This works by creating a temp buffer where the template function is
162 ;; edited so that X.Y is replaced by the version name
163 (let ((template "")
164 (template-args)
165 (beg)
166 (versions)
167 (version)
168 (eval-buf (get-buffer-create "*ess-temp-s-evals*"))
169 (ess-s-versions-created)
171 (ess-s-versions-list ess-s-versions-list)
172 ;; make local copy so it won't be destroyed globally
175 ;; This is the template function used for creating M-x Splus
176 (setq template "(defun S-X.Y ()
177 \"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS.
178 This function was generated by `ess-s-versions-create'.\"
179 (interactive \"\")
180 (let ((inferior-S+6-program-name \"S-X.Y\"))
181 (S+6)))
184 (save-excursion
185 (set-buffer eval-buf)
186 ;; clear the buffer.
187 (delete-region (point-min) (point-max))
189 (when ess-s-versions
190 ;; Find which versions of S we want. Remove the pathname, leaving just
191 ;; the name of the executable.
192 (setq versions
193 (ess-uniq-list
194 (mapcar 'file-name-nondirectory
195 (apply 'nconc
196 (mapcar 'ess-find-exec-completions
197 ess-s-versions)))))
198 (ess-write-to-dribble-buffer
199 (format "(S): ess-s-versions-create making M-x defuns for %s"
200 (mapconcat 'identity versions " ")))
201 (setq ess-s-versions-created versions) ;keep copy for returning at end.
202 ;; Iterate over each string in VERSIONS, creating a new defun each time.
203 (while versions
204 (setq version (car versions)
205 versions (cdr versions))
206 (setq beg (point))
207 (insert template)
208 (goto-char beg)
209 (while (search-forward "S-X.Y" nil t)
210 (replace-match version t t))
211 (goto-char (point-max))
214 ;; Check if we have any static defuns to evaluate.
215 (when ess-s-versions-list
217 ;; Need a slightly different template for static defuns.
218 (setq template "(defun S-X.Y ()
219 \"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS.
220 This function will run S-FULL-PATH
221 This function was generated by `ess-s-versions-create'.\"
222 (interactive \"\")
223 (let ((inferior-S+6-program-name \"S-FULL-PATH\"))
224 (S+6)))
227 ;; need another version of template, with args.
228 (setq template-args "(defun S-X.Y ()
229 \"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS.
230 This function will run S-FULL-PATH
231 This function was generated by `ess-s-versions-create'.\"
232 (interactive \"\")
233 (let ((inferior-S+6-program-name \"S-FULL-PATH\")
234 (inferior-Splus-args \"S-MYARGS\"))
235 (S+6)))
238 (while ess-s-versions-list
239 (let* ((this-S-version (car ess-s-versions-list))
240 (S-defun (nth 0 this-S-version))
241 (S-path (nth 1 this-S-version))
242 (S-args (nth 2 this-S-version)))
243 (setq ess-s-versions-list (cdr ess-s-versions-list))
244 ;; Could do error checking here, that S-defun is not defined
245 ;; before, and that S-path is valid.
246 (setq beg (point))
247 (insert
248 (if S-args
249 template-args
250 template))
251 (goto-char beg)
252 (while (search-forward "S-X.Y" nil t)
253 (replace-match S-defun t t))
254 (goto-char beg)
255 (while (search-forward "S-FULL-PATH" nil t)
256 (replace-match S-path t t))
257 (when S-args
258 (goto-char beg)
259 (while (search-forward "S-MYARGS" nil t)
260 (replace-match S-args t t)))
261 (goto-char (point-max))
262 (add-to-list 'ess-s-versions-created S-defun 'append))))
264 ;; buffer has now been created with defuns, so eval them!
265 (eval-buffer)
266 (kill-buffer eval-buf); < comment this for debugging
267 ess-s-versions-created)))
269 \f ; Provide package
271 (provide 'essd-sp6)
273 \f ; Local variables section
275 ;;; This file is automatically placed in Outline minor mode.
276 ;;; The file is structured as follows:
277 ;;; Chapters: ^L ;
278 ;;; Sections: ;;*;;
279 ;;; Subsections: ;;;*;;;
280 ;;; Components: defuns, defvars, defconsts
281 ;;; Random code beginning with a ;;;;* comment
283 ;;; Local variables:
284 ;;; mode: emacs-lisp
285 ;;; outline-minor-mode: nil
286 ;;; mode: outline-minor
287 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
288 ;;; End:
290 ;;; essd-sp6.el ends here