Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2701 views
1
;;; ess-sp6-d.el --- S-Plus 6 & 7 & 8 customization
2
3
;; Copyright (C) 2001--2005 A.J. Rossini, Richard M. Heiberger, Martin
4
;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
5
6
;; Author: A.J. Rossini <[email protected]>
7
;; Created: 2001/02/06
8
;; Maintainer: ESS Core Team <[email protected]>
9
10
;; Keywords: languages
11
12
;; This file is part of ESS.
13
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.
18
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.
23
24
;; A copy of the GNU General Public License is available at
25
;; http://www.r-project.org/Licenses/
26
27
;;; Commentary:
28
29
;; AJR copied S+5 to be S+6.
30
;; AJR copied S4 to be S+5.
31
;; DB contributed the changes from ess-sp3-d.el to
32
;; ess-s4-d.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.
36
37
;;; Code:
38
39
(autoload 'inferior-ess "ess-inf" "Run an ESS process.")
40
(autoload 'ess-mode "ess-mode" "Edit an ESS process.")
41
42
(require 'ess-s-l)
43
44
;; You now need to make sure you've defined if you are running 5.0 or 5.1.
45
;; Lots of things are broken between them, GRR...
46
47
(defun S+-directory-p (directory)
48
"Splus 5++ directories have a .Data directory and a __Meta directory within."
49
(and directory
50
(file-directory-p (concat directory ".Data"))
51
(file-directory-p (concat directory ".Data/__Meta"))))
52
53
(defvar S+-directory-function
54
(lambda ()
55
(if (S+-directory-p default-directory)
56
default-directory
57
(or ess-directory default-directory))))
58
59
(defvaralias 'S+6-setup-directory-function 'S+-setup-directory-function)
60
(defvar S+-setup-directory-function
61
(lambda (startdir)
62
(when (and startdir (S+-directory-p startdir))
63
(setenv "S_WORK"
64
(if (getenv "S_WORK")
65
(concat startdir ":" (getenv "S_WORK"))
66
;;(message "adding %s to S_WORK" startdir)
67
startdir)))))
68
69
70
71
(defvaralias 'S+6-customize-alist 'S+-customize-alist)
72
(defvar S+-customize-alist
73
(append
74
'((ess-local-customize-alist . 'S+-customize-alist)
75
(ess-dialect . S+-dialect-name)
76
(ess-loop-timeout . ess-S-loop-timeout);fixme: dialect spec.
77
(ess-function-pattern . ess-R-function-pattern)
78
79
(ess-object-name-db-file . "ess-sp6-namedb.el")
80
(inferior-ess-program . inferior-S+-program-name)
81
(inferior-ess-help-command . "help(\"%s\", pager=\"slynx -dump\", window=FALSE)\n")
82
(inferior-ess-help-filetype . nil)
83
(inferior-ess-search-list-command . "searchPaths()\n")
84
85
(ess-directory-function . S+-directory-function)
86
(ess-setup-directory-function . S+-setup-directory-function)
87
(inferior-ess-start-args . inferior-S+-start-args)
88
(ess-STERM . "iESS")
89
)
90
S+common-cust-alist)
91
92
"Variables to customize for S+.")
93
94
(defvar ess-S+-post-run-hook nil
95
"Functions run in process buffer after the initialization of S+
96
process.")
97
98
(defalias 'S+6 'S+)
99
(defun S+ (&optional proc-name)
100
"Call 'Splus6', based on S version 4, from Bell Labs.
101
New way to do it."
102
(interactive)
103
(setq ess-customize-alist S+-customize-alist)
104
(ess-write-to-dribble-buffer
105
(format "\n(S+): ess-dialect=%s, buf=%s\n" ess-dialect (current-buffer)))
106
(inferior-ess)
107
(ess-command ess-S+--injected-code)
108
(if inferior-ess-language-start
109
(ess-eval-linewise inferior-ess-language-start))
110
(with-ess-process-buffer nil
111
(run-mode-hooks 'ess-S+-post-run-hook)))
112
113
(defvar ess-S+--injected-code
114
".ess_funargs <- function(funname){
115
## funname <- deparse(substitute(object))
116
fun <- try(eval(parse(text=funname)), silent = TRUE)
117
if(is.function(fun)) {
118
special <- grepl('[:$@[]', funname)
119
args <- args(fun)
120
fmls <- formals(args)
121
fmls.names <- names(fmls)
122
fmls <- gsub('\\\"', '\\\\\\\"', as.character(fmls), fixed = TRUE)
123
args.alist <- sprintf(\"'(%s)\", paste(\"(\\\"\", fmls.names, \"\\\" . \\\"\", fmls, \"\\\")\", sep = '', collapse = ' '))
124
## envname <- environmentName(environment(fun))
125
envname <- if (special) '' else 'S+'
126
cat(sprintf('(list \\\"%s\\\" %s )\\n', envname, args.alist))
127
}
128
}
129
")
130
131
132
(defalias 'S+6-mode 'S+-mode)
133
(defun S+-mode (&optional proc-name)
134
"Major mode for editing S+ source. See `ess-mode' for more help."
135
(interactive)
136
(setq ess-customize-alist S+-customize-alist)
137
(ess-mode S+-customize-alist proc-name)
138
(if (fboundp 'ess-add-toolbar) (ess-add-toolbar))
139
(if ess-imenu-use-S (ess-imenu-S)))
140
141
(defalias 'S+6-transcript-mode 'S+-transcript-mode)
142
(defun S+-transcript-mode ()
143
"S-PLUS 6 transcript mode."
144
(interactive)
145
(ess-transcript-mode S+-customize-alist))
146
147
(defvar ess-s-versions-list nil
148
"List of other versions of S to add to ESS.
149
Each element of this list is itself a list:
150
\(FUNCTION PATH ARGS\)
151
e.g.
152
\(\"mysplus\" \"/usr/splus7/bin/splus7\" \"-j\"\)
153
FUNCTION is the name of the function to be created by Emacs.
154
PATH is the full path to the variant of S that you want to run.
155
ARGS (optional) are start-up arguments that you want to pass to S.
156
")
157
158
(defvar ess-s-versions '("Splus")
159
"List of partial strings for versions of S to access within ESS.
160
Each string specifies the start of a filename. If a filename
161
beginning with one of these strings is found on `exec-path', a M-x
162
command for that version of S is made available. For example, if the
163
file \"Splus7\" is found and this variable includes the string
164
\"Splus\", a function called `M-x Splus7' will be available to run that
165
version of S.
166
If duplicate versions of the same program are found (which happens if
167
the same path is listed on `exec-path' more than once), they are
168
ignored by calling `ess-uniq-list'.
169
Set this variable to nil to disable searching for other versions
170
of S using this method.
171
If you set this variable, you need to restart Emacs (and set this variable
172
before ess-site is loaded) for it to take effect.
173
174
See also `ess-s-versions-list' for another way to add other S
175
processes to ESS. ")
176
177
(defun ess-s-versions-create ()
178
"Generate defuns for starting other versions of S.
179
See `ess-s-versions' for strings that determine which functions are created.
180
It assumes these versions of S can be run as a substitute for Splus6.
181
182
This function returns the list of S defuns, if any, that were
183
created. The defuns will normally be placed on the menubar upon
184
ESS initialisation."
185
186
;; This works by creating a temp buffer where the template function is
187
;; edited so that X.Y is replaced by the version name
188
(let ((template "")
189
(template-args)
190
(beg)
191
(versions)
192
(version)
193
(eval-buf (get-buffer-create "*ess-temp-s-evals*"))
194
(ess-s-versions-created)
195
196
(ess-s-versions-list ess-s-versions-list)
197
;; make local copy so it won't be destroyed globally
198
)
199
;;
200
;; This is the template function used for creating M-x Splus
201
(setq template "(defun S-X.Y ()
202
\"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS.
203
This function was generated by `ess-s-versions-create'.\"
204
(interactive \"\")
205
(let ((inferior-S+-program-name \"S-X.Y\"))
206
(S+)))
207
208
")
209
(with-current-buffer eval-buf
210
;; clear the buffer.
211
(delete-region (point-min) (point-max))
212
213
(when ess-s-versions
214
;; Find which versions of S we want. Remove the pathname, leaving just
215
;; the name of the executable.
216
(setq versions
217
(ess-uniq-list
218
(mapcar 'file-name-nondirectory
219
(apply 'nconc
220
(mapcar 'ess-find-exec-completions
221
ess-s-versions)))))
222
(ess-write-to-dribble-buffer
223
(format "(S): ess-s-versions-create making M-x defuns for \n %s\n"
224
(mapconcat 'identity versions "\n ")))
225
(setq ess-s-versions-created versions) ;keep copy for returning at end.
226
;; Iterate over each string in VERSIONS, creating a new defun each time.
227
(while versions
228
(setq version (car versions)
229
versions (cdr versions))
230
(setq beg (point))
231
(insert template)
232
(goto-char beg)
233
(while (search-forward "S-X.Y" nil t)
234
(replace-match version t t))
235
(goto-char (point-max))
236
))
237
238
;; Check if we have any static defuns to evaluate.
239
(when ess-s-versions-list
240
241
;; Need a slightly different template for static defuns.
242
(setq template "(defun S-X.Y ()
243
\"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS.
244
This function will run S-FULL-PATH
245
This function was generated by `ess-s-versions-create'.\"
246
(interactive \"\")
247
(let ((inferior-S+-program-name \"S-FULL-PATH\"))
248
(S+)))
249
250
")
251
;; need another version of template, with args.
252
(setq template-args "(defun S-X.Y ()
253
\"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS.
254
This function will run S-FULL-PATH
255
This function was generated by `ess-s-versions-create'.\"
256
(interactive \"\")
257
(let ((inferior-S+-program-name \"S-FULL-PATH\")
258
(inferior-S+-start-args \"S-MYARGS\"))
259
(S+)))
260
261
")
262
(while ess-s-versions-list
263
(let* ((this-S-version (car ess-s-versions-list))
264
(S-defun (nth 0 this-S-version))
265
(S-path (nth 1 this-S-version))
266
(S-args (nth 2 this-S-version)))
267
(setq ess-s-versions-list (cdr ess-s-versions-list))
268
;; Could do error checking here, that S-defun is not defined
269
;; before, and that S-path is valid.
270
(setq beg (point))
271
(insert
272
(if S-args
273
template-args
274
template))
275
(goto-char beg)
276
(while (search-forward "S-X.Y" nil t)
277
(replace-match S-defun t t))
278
(goto-char beg)
279
(while (search-forward "S-FULL-PATH" nil t)
280
(replace-match S-path t t))
281
(when S-args
282
(goto-char beg)
283
(while (search-forward "S-MYARGS" nil t)
284
(replace-match S-args t t)))
285
(goto-char (point-max))
286
(add-to-list 'ess-s-versions-created S-defun 'append))))
287
288
;; buffer has now been created with defuns, so eval them!
289
(eval-buffer)
290
(kill-buffer eval-buf); < comment this for debugging
291
ess-s-versions-created)))
292
293
; Provide package
294
295
(provide 'ess-sp6-d)
296
297
; Local variables section
298
299
;;; This file is automatically placed in Outline minor mode.
300
;;; The file is structured as follows:
301
;;; Chapters: ^L ;
302
;;; Sections: ;;*;;
303
;;; Subsections: ;;;*;;;
304
;;; Components: defuns, defvars, defconsts
305
;;; Random code beginning with a ;;;;* comment
306
307
;;; Local variables:
308
;;; mode: emacs-lisp
309
;;; outline-minor-mode: nil
310
;;; mode: outline-minor
311
;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
312
;;; End:
313
314
;;; ess-sp6-d.el ends here
315
316