(defun ess-eval-region-ddeclient (start end even-empty)
"Loop through lines in region and send them to ESS via ddeclient."
(setq
inferior-ess-ddeclient (ess-get-process-variable 'inferior-ess-ddeclient)
inferior-ess-client-name (ess-get-process-variable 'inferior-ess-client-name)
inferior-ess-client-command (ess-get-process-variable 'inferior-ess-client-command))
(narrow-to-region start end)
(goto-char (point-min))
(let ((beg))
(while (or (< (point) (point-max))
(and (= 1 (point-max)) even-empty))
(setq beg (point))
(end-of-line)
(if (= beg (point))
(ess-eval-linewise-ddeclient " " nil 'eob t)
(call-process-region
beg (point)
inferior-ess-ddeclient nil nil nil
inferior-ess-client-name inferior-ess-client-command))
(forward-line 1))
(widen)))
(defun ess-eval-linewise-ddeclient (text-withtabs &optional
invisibly eob even-empty
sleep-sec)
(with-current-buffer (get-buffer-create "*ESS-temporary*")
(ess-setq-vars-local ess-customize-alist (current-buffer))
(erase-buffer)
(insert text-withtabs)
(ess-eval-region-ddeclient (point-min) (point-max) even-empty))
(if (numberp sleep-sec)
(sleep-for sleep-sec)))
(defun ess-display-help-on-object-ddeclient (object)
"Display the ESS documentation for OBJECT in another window.
If prefix arg is given, forces a query of the ESS process for the help
file. Otherwise just pops to an existing buffer if it exists."
(ess-force-buffer-current "Process to load into: ")
(ess-eval-linewise-ddeclient (concat "help(" object ")")))
(defun ess-load-file-ddeclient (filename)
"Load an S source file into an inferior ESS process; alternate behavior for
`ess-load-file', required with S-Plus GUI for Windows: Sends the S-Plus command
source(\"filename\") to S. This version does not guarantee to save .Last.value,
nor offer alternate buffers or editing capability."
(let ((source-buffer (get-file-buffer filename)))
(if (ess-check-source filename)
(error "Buffer %s has not been saved" (buffer-name source-buffer))
(if source-buffer
(with-current-buffer source-buffer
(ess-force-buffer-current "Process to load into: ")
)))
(ess-eval-linewise-ddeclient (format ess-load-command filename)))
(widen))
(defun ess-dump-object-ddeclient (object filename)
"Dump the ESS object OBJECT into file FILENAME."
(ess-force-buffer-current "Process to load into: ")
(ess-eval-linewise-ddeclient (concat "dump('" object "','" filename "')"))
(sleep-for 5)
(find-file filename)
(widen))
(defun ess-dput-expression-ddeclient (object filename)
"Dump the ESS object found by evaluating OBJECT into file FILENAME."
(ess-force-buffer-current "Process to load into: ")
(ess-eval-linewise-ddeclient (concat "dput(" object ",'" filename "')"))
(sleep-for 2)
(find-file filename))
(defun ess-command-ddeclient-proposed (com &optional buf sleep)
"ddeclient version of real `ess-command'.
Send the ESS process command COM and redirect its output to the
temporary file named BUF. The temporary filename is constructed
in emacs, not in the ESS process. The default name for the
temporary buffer is \"ess-temp.st\". The function waits
SLEEP (which defaults to 1) seconds and then brings the temporary
file into an emacs buffer and displays it."
(let (filename bufname)
(if (not buf) (setq buf "ess-temp.st"))
(if (not sleep) (setq sleep 1))
(setq filename (concat (file-name-as-directory (getenv "TEMP")) buf))
(ess-eval-linewise-ddeclient
(concat ".old.Last.value <- .Last.value; sink('"
filename
"'); print("
com
"); sink(); .Last.value <- .old.Last.value"))
(setq bufname (ess-get-file-or-buffer filename))
(sleep-for sleep)
(if (not bufname)
(find-file filename)
(switch-to-buffer bufname))
(revert-buffer t t)
))
(defun ess-command-ddeclient (com &optional buf sleep)
"ddeclient bypass of real ess-command"
(ess-eval-linewise com))
(provide 'ess-dde)