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>
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)
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.
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:
41 (autoload 'inferior-ess
"ess-inf" "Run an ESS process.")
42 (autoload 'ess-mode
"ess-mode" "Edit an ESS process.")
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."
55 (file-directory-p (concat directory
".Data"))
56 (file-directory-p (concat directory
".Data/__Meta"))))
58 (defvar S
+6-directory-function
60 (if (S+6-directory-p default-directory
)
62 (or ess-directory default-directory
))))
64 (defvar S
+6-setup-directory-function
66 (if (and startdir
(S+6-directory-p startdir
))
70 (concat startdir
":" (getenv "S_WORK"))
71 ;;(message "adding %s to S_WORK" startdir)
75 (defvar S
+6-customize-alist
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
)
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.
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)))
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."
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."
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\)
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
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
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
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
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'.\"
180 (let ((inferior-S+6-program-name \"S-X.Y\"))
185 (set-buffer eval-buf
)
187 (delete-region (point-min) (point-max))
190 ;; Find which versions of S we want. Remove the pathname, leaving just
191 ;; the name of the executable.
194 (mapcar 'file-name-nondirectory
196 (mapcar 'ess-find-exec-completions
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.
204 (setq version
(car versions
)
205 versions
(cdr versions
))
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'.\"
223 (let ((inferior-S+6-program-name \"S-FULL-PATH\"))
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'.\"
233 (let ((inferior-S+6-program-name \"S-FULL-PATH\")
234 (inferior-Splus-args \"S-MYARGS\"))
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.
252 (while (search-forward "S-X.Y" nil t
)
253 (replace-match S-defun
t t
))
255 (while (search-forward "S-FULL-PATH" nil t
)
256 (replace-match S-path t t
))
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!
266 (kill-buffer eval-buf
); < comment this for debugging
267 ess-s-versions-created
)))
273 \f ; Local variables section
275 ;;; This file is automatically placed in Outline minor mode.
276 ;;; The file is structured as follows:
279 ;;; Subsections: ;;;*;;;
280 ;;; Components: defuns, defvars, defconsts
281 ;;; Random code beginning with a ;;;;* comment
285 ;;; outline-minor-mode: nil
286 ;;; mode: outline-minor
287 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
290 ;;; essd-sp6.el ends here