Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2701 views
1
;;; ess-sp4-d.el --- S-PLUS 4.x customization
2
3
;; Copyright (C) 1998--2002 Richard M. Heiberger <[email protected]>
4
;; Copyright (C) 2003--2004 A.J. Rossini, Richard M. Heiberger, Martin
5
;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
6
7
;; Author: Richard M. Heiberger <[email protected]>
8
;; Created: December 1998
9
;; Maintainer: ESS-core <[email protected]>
10
11
;; Keywords: languages
12
13
;; This file is part of ESS.
14
15
;; This file is free software; you can redistribute it and/or modify
16
;; it under the terms of the GNU General Public License as published by
17
;; the Free Software Foundation; either version 2, or (at your option)
18
;; any later version.
19
20
;; This file is distributed in the hope that it will be useful,
21
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
;; GNU General Public License for more details.
24
25
;; A copy of the GNU General Public License is available at
26
;; http://www.r-project.org/Licenses/
27
28
;;; Commentary:
29
30
;; This file defines all the S-PLUS 4.x customizations for ess-mode
31
;; with ddeclient.
32
33
;;; Code:
34
35
;;; Requires and Autoloads:
36
37
(require 'ess-s-l)
38
;;NO: this is autoloaded from other places (require 'ess-dde)
39
40
(autoload 'inferior-ess "ess-inf" "Run an ESS process.")
41
(autoload 'ess-mode "ess-mode" "Edit an ESS process.")
42
43
(defvar S+4-dialect-name "S+4"
44
"Name of 'dialect' for S-PLUS 4.x.");easily changeable in a user's .emacs
45
46
(defvar inferior-S+4-multipleinstances "/MULTIPLEINSTANCES"
47
"Default \"/MULTIPLEINSTANCES\" opens up a new instance of S+4 in a
48
GUI window and connects it to the '(ddeESS [S+4])' window. The
49
alternative nil uses an existing S+4 GUI (if there is one) and
50
connects it to the '(ddeESS [S+4])' window.")
51
52
(defvar S+4-customize-alist
53
(append
54
'((ess-local-customize-alist . 'S+4-customize-alist)
55
(ess-dialect . S+4-dialect-name)
56
(ess-loop-timeout . ess-S-loop-timeout);fixme: dialect spec.
57
(ess-object-name-db-file . "ess-sp4-namedb.el" )
58
(inferior-ess-program . inferior-S+4-program-name)
59
(inferior-ess-help-command . "help(\"%s\")\n")
60
(inferior-ess-help-filetype . "chm")
61
62
(inferior-ess-start-file . nil) ;"~/.ess-S+4")
63
(inferior-ess-start-args . (concat
64
inferior-S+4-multipleinstances " "
65
inferior-S+4-print-command
66
" S_PROJ="
67
(directory-file-name default-directory)))
68
;; (inferior-ess-ddeclient . "ddeclient")
69
;; (inferior-ess-client-name . "S-PLUS")
70
;; (inferior-ess-client-command . "SCommand")
71
(ess-STERM . "ddeESS")
72
)
73
S+common-cust-alist)
74
75
"Variables to customize for S+4")
76
77
(defvar Sqpe+4-customize-alist
78
(append
79
'((ess-local-customize-alist . 'Sqpe+4-customize-alist)
80
(ess-dialect . S+4-dialect-name)
81
(ess-loop-timeout . 500000 );fixme: dialect specific custom.v
82
(ess-object-name-db-file . "ess-sp4-namedb.el" )
83
(inferior-ess-program . inferior-Sqpe+4-program-name)
84
(inferior-ess-help-command . "help(\"%s\")\n")
85
(inferior-ess-help-filetype . "chm")
86
(inferior-ess-search-list-command . "searchPaths()\n")
87
(inferior-ess-start-file . nil) ;"~/.ess-S+4")
88
(inferior-ess-language-start . (concat
89
"options("
90
"STERM='" ess-STERM "'"
91
(if ess-editor
92
(concat ", editor='" ess-editor "'"))
93
(if ess-pager
94
(concat ", pager='" ess-pager "'"))
95
")"))
96
(ess-STERM . "iESS")
97
)
98
S+common-cust-alist)
99
100
"Variables to customize for Sqpe+4.")
101
102
103
;;; There are extra complications in S+4 (compared to S+3) because
104
;;;
105
;;; (1) The StatSci supplied Splus.exe doesn't work in an emacs
106
;;; buffer. It works as as a GUI window and we must send commands
107
;;; to it through ddeclient. Nonetheless, we need to give it a
108
;;; process name and be sure that that there is a valid running
109
;;; process in the '(ddeESS [S+4])' buffer. Therefore we create an
110
;;; ESS process in the buffer as a placeholder and start a shell
111
;;; in the ESS buffer. From the shell we start Splus. Once Splus
112
;;; finishes initializing and kills the original shell, we start
113
;;; another shell. We have a buffer-local variable
114
;;; inferior-ess-ddeclient, initialized to nil. When there is a
115
;;; non-nil value of inferior-ess-ddeclient we send lines to
116
;;; inferior-ess-ddeclient rather than to the Splus process.
117
;;; (2) There is no Splus process running in the '(ddeESS [S+4])'
118
;;; buffer. Therefore inferior-ess will never see a prompt,
119
;;; unless we first change it to the null prompt "^". Then once
120
;;; the process has started, we change it back.
121
;;; (3) When M-x S+4 starts Splus by a shell command, then Splus is an
122
;;; independent process and will be survive if the '(ddeESS [S+4])'
123
;;; buffer is killed (or emacs is quit). The '(ddeESS [S+4])' is
124
;;; made read-only and a warning is placed in it saying that "You
125
;;; can't type anything here." Actually, if the standalone Splus
126
;;; is killed and the '(ddeESS [S+4])' is made writable (C-x C-q),
127
;;; then '(ddeESS [S+4])' becomes a shell buffer.
128
;;;
129
(defun S+4 (&optional proc-name)
130
"Call 'S-PLUS 4.x', the 'GUI Thing' from StatSci. Put S-Plus in an
131
independent MS-Window (Splus persists even if the '(ddeESS [S+4])'
132
window is killed in emacs). Do this by creating a comint process that
133
calls sh. Send a shell command in that sh buffer to call Splus. When
134
it completes set up a shell as a placeholder in the '(ddeESS [S+4])'
135
buffer. The S-Plus options are correctly set. In particular, the
136
S-Plus Commands window is opened if the Options/General
137
Settings/Startup menu says it should be. There is a 30 second delay
138
during startup in which the screen will not be refreshed. This delay
139
is here to allow slow disks to start the Splus program."
140
(interactive)
141
(save-excursion
142
(setq ess-customize-alist S+4-customize-alist)
143
(ess-write-to-dribble-buffer
144
(format "\n(S+4): ess-dialect=%s, buf=%s\n" ess-dialect
145
(current-buffer)))
146
(setq ess-customize-alist ; change inferior-ess-program
147
(append ess-customize-alist '((inferior-ess-program . "sh"))))
148
(setq ess-customize-alist ; change inferior-ess-primary-prompt
149
(append ess-customize-alist '((inferior-ess-primary-prompt . "^"))))
150
(setq ess-customize-alist ; change inferior-ess-start-args
151
(append ess-customize-alist '((inferior-ess-start-args . "-i"))))
152
(let ((s-proj (getenv "S_PROJ"))
153
(manpath (getenv "MANPATH")))
154
(cd (w32-short-file-name (directory-file-name default-directory)))
155
(setenv "S_PROJ" default-directory)
156
;; I don't know why this PATH/MANPATH game is needed,
157
;; except that it doesn't work without it.
158
(setenv "MANPATH" (getenv "PATH"))
159
(inferior-ess)
160
(sleep-for 2) ; need to wait, else working too fast! The Splus
161
; command in '(ddeESS [S+4])' should follow the "$"
162
; prompt. If not, then increase the sleep-for time!
163
(setenv "MANPATH" manpath)
164
(setenv "S_PROJ" s-proj))
165
(setq ess-customize-alist S+4-customize-alist)
166
(ess-setq-vars-local ess-customize-alist)
167
;;; the next three lines belong in customize-alist, but can't be there
168
;;; because of the broken ess-setq-vars-default usage in ess-inf.el
169
(setq inferior-ess-ddeclient "ddeclient")
170
(setq inferior-ess-client-name "S-PLUS")
171
(setq inferior-ess-client-command "SCommand")
172
;;; end of what belongs in customize-alist
173
(setq comint-process-echoes nil)
174
(setq comint-input-sender 'comint-simple-send)
175
(goto-char (point-max))
176
(insert (concat inferior-S+4-program-name " "
177
inferior-ess-start-args)) ; Note: there is no final "&".
178
;; Without the "&", the results of !system.command come to '(ddeESS [S+4])'
179
;; With the "&", the results of !system.command in S get lost.
180
(inferior-ess-send-input)
181
(sleep-for 30) ; Need to wait, else working too fast!
182
; If the ess-current-process-name doesn't appear in the
183
; Splus Commands window increase the sleep-for time!
184
(setq ess-local-process-name ess-current-process-name)
185
(ess-eval-linewise (concat "#" ess-current-process-name))
186
(goto-char (point-min))
187
(insert
188
"This is a placeholder buffer. You can't type anything here.
189
Use `C-x b RET' to return to your file.\n
190
Anything sent to this process from an S-mode buffer goes
191
directly to the associated Splus Commands window.\n
192
The S-Plus Commands window must be visible.
193
You may need to open the S-Plus Commands window manually (by clicking on
194
Splus/Window/Commands Window).\n
195
Any results of the !system.command typed at the S prompt in the
196
Splus Commands window appear in this buffer.\n\n")
197
(goto-char (point-max)) ; comint-mode-map makes '(ddeESS [S+4])'
198
;; (use-local-map comint-mode-map) ;a shell buffer after Splus is finished.
199
(set-buffer-process-coding-system 'raw-text-dos 'raw-text-unix)
200
(setq buffer-read-only t) ; force buffer to be read-only
201
(setq mode-name "ddeESS")
202
;; (ess-eval-linewise inferior-S+4-editor-pager-command)
203
(if inferior-ess-language-start
204
(ess-eval-linewise inferior-ess-language-start))
205
))
206
207
208
209
210
(defun S+4-existing (&optional proc-name)
211
"Call 'S-PLUS 4.x', the 'GUI Thing' from StatSci. Do so by finding
212
an existing S-Plus in an independent MS-Window (if there is one) and
213
set up a '(ddeESS [S+4])' buffer in emacs. If there is no existing
214
S-Plus, then a new one will be opened in the default directory,
215
usually something like c:/Program Files/spls45se/users/yourname.
216
If you have a HOME environment variable, it will open it there."
217
(interactive)
218
(let* ((inferior-S+4-multipleinstances " & # ")) ; Note: there is a final "&".
219
;; Without the "&", there is a core dump.
220
;; With the "&", the results of !system.command in S get lost.
221
;; We are picking up an existing S-Plus process for sending to.
222
;; It doesn't know about us, so nothing comes back.
223
(S+4 proc-name))
224
(with-current-buffer (car (buffer-list)) ; get the ESS buffer just created
225
(setq buffer-read-only nil) ; permit writing in ESS buffer
226
(goto-char (point-max))
227
(beginning-of-line)
228
(forward-line -1)
229
(insert
230
"This is S+4-existing.
231
Results of the !system.command typed at the S prompt in the
232
Splus Commands window blink a DOS window and you won't see them.\n\n")
233
(setq buffer-read-only t) ; restore ESS buffer to be read-only
234
))
235
236
237
;;; There are extra complications in Sqpe+4 (compared to S+3) because
238
;;; (1) The StatSci supplied Sqpe.exe won't work without SHOME as an
239
;;; environment variable and Sqpe does not take command line
240
;;; arguments and
241
;;; (2) Sqpe.exe comes up with options(interactive=F), which means it
242
;;; doesn't provide prompts by default, and we must change it to T so
243
;;; it will provide prompts.
244
;;;
245
(defun Sqpe+4 (&optional proc-name)
246
"Call 'Sqpe' from 'S-PLUS 4.x', the 'Real Thing' from StatSci."
247
(interactive)
248
(setq ess-customize-alist Sqpe+4-customize-alist)
249
(let* ((shome-nil-p (equal (getenv "SHOME") nil)))
250
(if shome-nil-p (setenv "SHOME" inferior-Sqpe+4-SHOME-name))
251
(ess-write-to-dribble-buffer
252
(format "\n(Sqpe+4): ess-dialect=%s, buf=%s\n" ess-dialect
253
(current-buffer)))
254
(setq ess-customize-alist ; change inferior-ess-primary-prompt
255
(append ess-customize-alist '((inferior-ess-primary-prompt . "^"))))
256
(inferior-ess)
257
(setq ess-customize-alist Sqpe+4-customize-alist) ; restore i-e-p-p in alist
258
(ess-setq-vars-local ess-customize-alist) ; restore i-e-p-p in buffer
259
(setq inferior-ess-prompt ; define with correct i-e-p-p
260
;; Do not anchor to bol with `^' ; (copied from ess-inf.el)
261
(concat "\\("
262
inferior-ess-primary-prompt
263
"\\|"
264
inferior-ess-secondary-prompt
265
"\\)"))
266
(setq comint-prompt-regexp (concat "^" inferior-ess-prompt))
267
; define with correct i-e-p-p
268
(setq comint-input-sender 'inferior-ess-input-sender)
269
(add-hook 'comint-output-filter-functions 'shell-strip-ctrl-m nil t)
270
(goto-char (point-max))
271
(insert "options(interactive=T)")
272
(inferior-ess-send-input)
273
(setq mode-name "iESS(Sqpe)")
274
;; (ess-eval-linewise inferior-S+4-editor-pager-command)
275
(if inferior-ess-language-start
276
(ess-eval-linewise inferior-ess-language-start))
277
(if shome-nil-p (setenv "SHOME" nil))))
278
279
280
281
(defun S+4-mode (&optional proc-name)
282
"Major mode for editing S+4 source. See `ess-mode' for more help."
283
(interactive)
284
(setq ess-customize-alist S+4-customize-alist)
285
(ess-mode S+4-customize-alist proc-name)
286
(if ess-imenu-use-S (ess-imenu-S)))
287
288
(defun S+4-transcript-mode ()
289
"S-PLUS 4.x transcript mode."
290
(interactive)
291
(ess-transcript-mode S+4-customize-alist))
292
293
294
(defun S+4-msdos (&optional proc-name)
295
"Call 'S-PLUS 4.x', the 'GUI Thing' from StatSci. Put S-Plus in an
296
independent MS-Window (Splus persists even if the '(ddeESS [S+4])'
297
window is killed in emacs). Do this by creating a comint process that
298
calls sh. Send a shell command in that sh buffer to call Splus. When
299
it completes set up a shell as a placeholder in the '(ddeESS [S+4])'
300
buffer. The S-Plus options are correctly set. In particular, the
301
S-Plus Commands window is opened if the Options/General
302
Settings/Startup menu says it should be. There is a 30 second delay
303
during startup in which the screen will not be refreshed. This delay
304
is here to allow slow disks to start the Splus program."
305
(interactive)
306
(save-excursion
307
(setq ess-customize-alist S+4-customize-alist)
308
(ess-write-to-dribble-buffer
309
(format "\n(S+4): ess-dialect=%s, buf=%s\n" ess-dialect
310
(current-buffer)))
311
(setq ess-customize-alist ; change inferior-ess-program
312
(append ess-customize-alist '((inferior-ess-program
313
. (getenv "COMSPEC")))))
314
(setq ess-customize-alist ; change inferior-ess-primary-prompt
315
(append ess-customize-alist '((inferior-ess-primary-prompt . "^"))))
316
(setq ess-customize-alist ; change inferior-ess-start-args
317
(append ess-customize-alist '((inferior-ess-start-args . ""))))
318
(let ((s-proj (getenv "S_PROJ")))
319
(cd (w32-short-file-name (directory-file-name default-directory)))
320
(setenv "S_PROJ" default-directory)
321
(inferior-ess)
322
(sleep-for 2) ; need to wait, else working too fast! The Splus
323
; command in '(ddeESS [S+4])' should follow the "$"
324
; prompt. If not, then increase the sleep-for time!
325
(setenv "S_PROJ" s-proj))
326
(setq ess-customize-alist S+4-customize-alist)
327
(ess-setq-vars-local ess-customize-alist)
328
;;; the next three lines belong in customize-alist, but can't be there
329
;;; because of the broken ess-setq-vars-default usage in ess-inf.el
330
(setq inferior-ess-ddeclient "ddeclient")
331
(setq inferior-ess-client-name "S-PLUS")
332
(setq inferior-ess-client-command "SCommand")
333
;;; end of what belongs in customize-alist
334
(setq comint-input-sender 'comint-simple-send)
335
(setq comint-process-echoes nil)
336
(set-buffer-process-coding-system 'raw-text-dos 'raw-text-dos)
337
(goto-char (point-max))
338
(insert (concat inferior-S+4-program-name " "
339
inferior-ess-start-args)) ; Note: there is no final "&".
340
; Without the "&", the results of !system.command come to '(ddeESS [S+4])'
341
; With the "&", the results of !system.command in S get lost.
342
(inferior-ess-send-input)
343
(sleep-for 30) ; Need to wait, else working too fast!
344
; If the ess-current-process-name doesn't appear in the
345
; Splus Commands window increase the sleep-for time!
346
;;; from msdos-minor-mode
347
(setq comint-process-echoes t)
348
(add-hook 'comint-output-filter-functions 'shell-strip-ctrl-m nil t)
349
;;; end from msdos-minor-mode
350
(setq ess-local-process-name ess-current-process-name)
351
(ess-eval-linewise (concat "#" ess-current-process-name))
352
(goto-char (point-min))
353
(insert
354
"This is a placeholder buffer. You can't type anything here.
355
Use 'C-x b RET' to return to your file.\n
356
Anything sent to this process from an S-mode buffer goes
357
directly to the associated Splus Commands window.\n
358
The S-Plus Commands window must be visible.
359
You may need to open the S-Plus Commands window manually
360
(by clicking on Splus/Window/Commands Window).\n There is a 30
361
second delay when this program starts during which the emacs
362
screen will be partially blank.\n Remember to `q()' from S-Plus
363
and then C-x C-q exit from the `'(ddeESS [S+4])'' buffer, or take
364
the risk of not being able to shut down your computer and
365
suffering through scandisk.\n Any results of the !system.command
366
typed at the S prompt in the Splus Commands window (are supposed
367
to) appear in this buffer.\n\n")
368
(goto-char (point-max)) ; comint-mode-map makes '(ddeESS [S+4])'
369
(use-local-map comint-mode-map) ; a shell buffer after Splus is finished.
370
(setq buffer-read-only t) ; force buffer to be read-only
371
(setq mode-name "ddeESS")
372
;; (ess-eval-linewise inferior-S+4-editor-pager-command)
373
(if inferior-ess-language-start
374
(ess-eval-linewise inferior-ess-language-start))
375
))
376
377
(defun S+4-msdos-existing (&optional proc-name)
378
"Call 'S-PLUS 4.x', the 'GUI Thing' from StatSci. Do so by finding
379
an existing S-Plus in an independent MS-Window (if there is one) and
380
set up a '(ddeESS [S+4])' buffer in emacs. If there is no existing
381
S-Plus, then a new one will be opened in the default directory,
382
usually something like c:/Program Files/spls45se/users/yourname.
383
If you have a HOME environment variable, it will open it there."
384
(interactive)
385
(let* ((inferior-S+4-multipleinstances ""))
386
(S+4-msdos proc-name))
387
(save-excursion
388
(set-buffer (car (buffer-list))) ; get the ESS buffer just created
389
(setq buffer-read-only nil) ; permit writing in ESS buffer
390
(goto-char (point-max))
391
(beginning-of-line)
392
(forward-line -1)
393
(insert
394
"This is S+4-msdos-existing.
395
Results of the !system.command typed at the S prompt in the
396
Splus Commands window blink a DOS window and you won't see them.\n\n")
397
(setq buffer-read-only t) ; restore ESS buffer to be read-only
398
))
399
400
; Provide package
401
402
(provide 'ess-sp4-d)
403
404
; Local variables section
405
406
;;; This file is automatically placed in Outline minor mode.
407
;;; The file is structured as follows:
408
;;; Chapters: ^L ;
409
;;; Sections: ;;*;;
410
;;; Subsections: ;;;*;;;
411
;;; Components: defuns, defvars, defconsts
412
;;; Random code beginning with a ;;;;* comment
413
414
;;; Local variables:
415
;;; mode: emacs-lisp
416
;;; outline-minor-mode: nil
417
;;; mode: outline-minor
418
;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
419
;;; End:
420
421
;;; ess-sp4-d.el ends here
422
423