(require 'ess-s-l)
(autoload 'inferior-ess "ess-inf" "Run an ESS process.")
(autoload 'ess-mode "ess-mode" "Edit an ESS process.")
(defvar S+4-dialect-name "S+4"
"Name of 'dialect' for S-PLUS 4.x.")
(defvar inferior-S+4-multipleinstances "/MULTIPLEINSTANCES"
"Default \"/MULTIPLEINSTANCES\" opens up a new instance of S+4 in a
GUI window and connects it to the '(ddeESS [S+4])' window. The
alternative nil uses an existing S+4 GUI (if there is one) and
connects it to the '(ddeESS [S+4])' window.")
(defvar S+4-customize-alist
(append
'((ess-local-customize-alist . 'S+4-customize-alist)
(ess-dialect . S+4-dialect-name)
(ess-loop-timeout . ess-S-loop-timeout)
(ess-object-name-db-file . "ess-sp4-namedb.el" )
(inferior-ess-program . inferior-S+4-program-name)
(inferior-ess-help-command . "help(\"%s\")\n")
(inferior-ess-help-filetype . "chm")
(inferior-ess-start-file . nil)
(inferior-ess-start-args . (concat
inferior-S+4-multipleinstances " "
inferior-S+4-print-command
" S_PROJ="
(directory-file-name default-directory)))
(ess-STERM . "ddeESS")
)
S+common-cust-alist)
"Variables to customize for S+4")
(defvar Sqpe+4-customize-alist
(append
'((ess-local-customize-alist . 'Sqpe+4-customize-alist)
(ess-dialect . S+4-dialect-name)
(ess-loop-timeout . 500000 )
(ess-object-name-db-file . "ess-sp4-namedb.el" )
(inferior-ess-program . inferior-Sqpe+4-program-name)
(inferior-ess-help-command . "help(\"%s\")\n")
(inferior-ess-help-filetype . "chm")
(inferior-ess-search-list-command . "searchPaths()\n")
(inferior-ess-start-file . nil)
(inferior-ess-language-start . (concat
"options("
"STERM='" ess-STERM "'"
(if ess-editor
(concat ", editor='" ess-editor "'"))
(if ess-pager
(concat ", pager='" ess-pager "'"))
")"))
(ess-STERM . "iESS")
)
S+common-cust-alist)
"Variables to customize for Sqpe+4.")
(defun S+4 (&optional proc-name)
"Call 'S-PLUS 4.x', the 'GUI Thing' from StatSci. Put S-Plus in an
independent MS-Window (Splus persists even if the '(ddeESS [S+4])'
window is killed in emacs). Do this by creating a comint process that
calls sh. Send a shell command in that sh buffer to call Splus. When
it completes set up a shell as a placeholder in the '(ddeESS [S+4])'
buffer. The S-Plus options are correctly set. In particular, the
S-Plus Commands window is opened if the Options/General
Settings/Startup menu says it should be. There is a 30 second delay
during startup in which the screen will not be refreshed. This delay
is here to allow slow disks to start the Splus program."
(interactive)
(save-excursion
(setq ess-customize-alist S+4-customize-alist)
(ess-write-to-dribble-buffer
(format "\n(S+4): ess-dialect=%s, buf=%s\n" ess-dialect
(current-buffer)))
(setq ess-customize-alist
(append ess-customize-alist '((inferior-ess-program . "sh"))))
(setq ess-customize-alist
(append ess-customize-alist '((inferior-ess-primary-prompt . "^"))))
(setq ess-customize-alist
(append ess-customize-alist '((inferior-ess-start-args . "-i"))))
(let ((s-proj (getenv "S_PROJ"))
(manpath (getenv "MANPATH")))
(cd (w32-short-file-name (directory-file-name default-directory)))
(setenv "S_PROJ" default-directory)
(setenv "MANPATH" (getenv "PATH"))
(inferior-ess)
(sleep-for 2)
(setenv "MANPATH" manpath)
(setenv "S_PROJ" s-proj))
(setq ess-customize-alist S+4-customize-alist)
(ess-setq-vars-local ess-customize-alist)
(setq inferior-ess-ddeclient "ddeclient")
(setq inferior-ess-client-name "S-PLUS")
(setq inferior-ess-client-command "SCommand")
(setq comint-process-echoes nil)
(setq comint-input-sender 'comint-simple-send)
(goto-char (point-max))
(insert (concat inferior-S+4-program-name " "
inferior-ess-start-args))
(inferior-ess-send-input)
(sleep-for 30)
(setq ess-local-process-name ess-current-process-name)
(ess-eval-linewise (concat "#" ess-current-process-name))
(goto-char (point-min))
(insert
"This is a placeholder buffer. You can't type anything here.
Use `C-x b RET' to return to your file.\n
Anything sent to this process from an S-mode buffer goes
directly to the associated Splus Commands window.\n
The S-Plus Commands window must be visible.
You may need to open the S-Plus Commands window manually (by clicking on
Splus/Window/Commands Window).\n
Any results of the !system.command typed at the S prompt in the
Splus Commands window appear in this buffer.\n\n")
(goto-char (point-max))
(set-buffer-process-coding-system 'raw-text-dos 'raw-text-unix)
(setq buffer-read-only t)
(setq mode-name "ddeESS")
(if inferior-ess-language-start
(ess-eval-linewise inferior-ess-language-start))
))
(defun S+4-existing (&optional proc-name)
"Call 'S-PLUS 4.x', the 'GUI Thing' from StatSci. Do so by finding
an existing S-Plus in an independent MS-Window (if there is one) and
set up a '(ddeESS [S+4])' buffer in emacs. If there is no existing
S-Plus, then a new one will be opened in the default directory,
usually something like c:/Program Files/spls45se/users/yourname.
If you have a HOME environment variable, it will open it there."
(interactive)
(let* ((inferior-S+4-multipleinstances " & # "))
(S+4 proc-name))
(with-current-buffer (car (buffer-list))
(setq buffer-read-only nil)
(goto-char (point-max))
(beginning-of-line)
(forward-line -1)
(insert
"This is S+4-existing.
Results of the !system.command typed at the S prompt in the
Splus Commands window blink a DOS window and you won't see them.\n\n")
(setq buffer-read-only t)
))
(defun Sqpe+4 (&optional proc-name)
"Call 'Sqpe' from 'S-PLUS 4.x', the 'Real Thing' from StatSci."
(interactive)
(setq ess-customize-alist Sqpe+4-customize-alist)
(let* ((shome-nil-p (equal (getenv "SHOME") nil)))
(if shome-nil-p (setenv "SHOME" inferior-Sqpe+4-SHOME-name))
(ess-write-to-dribble-buffer
(format "\n(Sqpe+4): ess-dialect=%s, buf=%s\n" ess-dialect
(current-buffer)))
(setq ess-customize-alist
(append ess-customize-alist '((inferior-ess-primary-prompt . "^"))))
(inferior-ess)
(setq ess-customize-alist Sqpe+4-customize-alist)
(ess-setq-vars-local ess-customize-alist)
(setq inferior-ess-prompt
(concat "\\("
inferior-ess-primary-prompt
"\\|"
inferior-ess-secondary-prompt
"\\)"))
(setq comint-prompt-regexp (concat "^" inferior-ess-prompt))
(setq comint-input-sender 'inferior-ess-input-sender)
(add-hook 'comint-output-filter-functions 'shell-strip-ctrl-m nil t)
(goto-char (point-max))
(insert "options(interactive=T)")
(inferior-ess-send-input)
(setq mode-name "iESS(Sqpe)")
(if inferior-ess-language-start
(ess-eval-linewise inferior-ess-language-start))
(if shome-nil-p (setenv "SHOME" nil))))
(defun S+4-mode (&optional proc-name)
"Major mode for editing S+4 source. See `ess-mode' for more help."
(interactive)
(setq ess-customize-alist S+4-customize-alist)
(ess-mode S+4-customize-alist proc-name)
(if ess-imenu-use-S (ess-imenu-S)))
(defun S+4-transcript-mode ()
"S-PLUS 4.x transcript mode."
(interactive)
(ess-transcript-mode S+4-customize-alist))
(defun S+4-msdos (&optional proc-name)
"Call 'S-PLUS 4.x', the 'GUI Thing' from StatSci. Put S-Plus in an
independent MS-Window (Splus persists even if the '(ddeESS [S+4])'
window is killed in emacs). Do this by creating a comint process that
calls sh. Send a shell command in that sh buffer to call Splus. When
it completes set up a shell as a placeholder in the '(ddeESS [S+4])'
buffer. The S-Plus options are correctly set. In particular, the
S-Plus Commands window is opened if the Options/General
Settings/Startup menu says it should be. There is a 30 second delay
during startup in which the screen will not be refreshed. This delay
is here to allow slow disks to start the Splus program."
(interactive)
(save-excursion
(setq ess-customize-alist S+4-customize-alist)
(ess-write-to-dribble-buffer
(format "\n(S+4): ess-dialect=%s, buf=%s\n" ess-dialect
(current-buffer)))
(setq ess-customize-alist
(append ess-customize-alist '((inferior-ess-program
. (getenv "COMSPEC")))))
(setq ess-customize-alist
(append ess-customize-alist '((inferior-ess-primary-prompt . "^"))))
(setq ess-customize-alist
(append ess-customize-alist '((inferior-ess-start-args . ""))))
(let ((s-proj (getenv "S_PROJ")))
(cd (w32-short-file-name (directory-file-name default-directory)))
(setenv "S_PROJ" default-directory)
(inferior-ess)
(sleep-for 2)
(setenv "S_PROJ" s-proj))
(setq ess-customize-alist S+4-customize-alist)
(ess-setq-vars-local ess-customize-alist)
(setq inferior-ess-ddeclient "ddeclient")
(setq inferior-ess-client-name "S-PLUS")
(setq inferior-ess-client-command "SCommand")
(setq comint-input-sender 'comint-simple-send)
(setq comint-process-echoes nil)
(set-buffer-process-coding-system 'raw-text-dos 'raw-text-dos)
(goto-char (point-max))
(insert (concat inferior-S+4-program-name " "
inferior-ess-start-args))
(inferior-ess-send-input)
(sleep-for 30)
(setq comint-process-echoes t)
(add-hook 'comint-output-filter-functions 'shell-strip-ctrl-m nil t)
(setq ess-local-process-name ess-current-process-name)
(ess-eval-linewise (concat "#" ess-current-process-name))
(goto-char (point-min))
(insert
"This is a placeholder buffer. You can't type anything here.
Use 'C-x b RET' to return to your file.\n
Anything sent to this process from an S-mode buffer goes
directly to the associated Splus Commands window.\n
The S-Plus Commands window must be visible.
You may need to open the S-Plus Commands window manually
(by clicking on Splus/Window/Commands Window).\n There is a 30
second delay when this program starts during which the emacs
screen will be partially blank.\n Remember to `q()' from S-Plus
and then C-x C-q exit from the `'(ddeESS [S+4])'' buffer, or take
the risk of not being able to shut down your computer and
suffering through scandisk.\n Any results of the !system.command
typed at the S prompt in the Splus Commands window (are supposed
to) appear in this buffer.\n\n")
(goto-char (point-max))
(use-local-map comint-mode-map)
(setq buffer-read-only t)
(setq mode-name "ddeESS")
(if inferior-ess-language-start
(ess-eval-linewise inferior-ess-language-start))
))
(defun S+4-msdos-existing (&optional proc-name)
"Call 'S-PLUS 4.x', the 'GUI Thing' from StatSci. Do so by finding
an existing S-Plus in an independent MS-Window (if there is one) and
set up a '(ddeESS [S+4])' buffer in emacs. If there is no existing
S-Plus, then a new one will be opened in the default directory,
usually something like c:/Program Files/spls45se/users/yourname.
If you have a HOME environment variable, it will open it there."
(interactive)
(let* ((inferior-S+4-multipleinstances ""))
(S+4-msdos proc-name))
(save-excursion
(set-buffer (car (buffer-list)))
(setq buffer-read-only nil)
(goto-char (point-max))
(beginning-of-line)
(forward-line -1)
(insert
"This is S+4-msdos-existing.
Results of the !system.command typed at the S prompt in the
Splus Commands window blink a DOS window and you won't see them.\n\n")
(setq buffer-read-only t)
))
(provide 'ess-sp4-d)