ESS[SAS]: somebody forgot about the SUM statement (probably me)
[ess.git] / lisp / ess-dde.el
blobd6de4c0a1194b3e82a405a3f7a5fe72863f5878f
1 ;;; essd-dde.el --- ESS customization for ddeclients under Windows 9x/NT
3 ;; Copyright (C) 1998--1999 Richard M. Heiberger <rmh@fisher.stat.temple.edu>
4 ;; Copyright (C) 2000--2006 A.J. Rossini, Rich M. Heiberger, Martin
5 ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
7 ;; Original Author: Richard M. Heiberger <rmh@fisher.stat.temple.edu>
8 ;; Created: 9 Dec 1998
9 ;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
11 ;; This file is part of ESS
13 ;; This file is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
18 ;; This file is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 ;;; Commentary:
29 ;; Code for dealing with running external processes on Windows 9x/NT
30 ;; through ddeclient.
31 ;; =========
33 ;;; Code:
36 ;; *NO* Requires and autoloads
38 ;; C-c C-r
39 (defun ess-eval-region-ddeclient (start end even-empty)
40 "Loop through lines in region and send them to ESS via ddeclient."
41 (setq ;; set the following variables for the current ddeESS process.
42 inferior-ess-ddeclient (ess-get-process-variable
43 ess-current-process-name 'inferior-ess-ddeclient)
44 inferior-ess-client-name (ess-get-process-variable
45 ess-current-process-name 'inferior-ess-client-name)
46 inferior-ess-client-command (ess-get-process-variable
47 ess-current-process-name 'inferior-ess-client-command))
48 (narrow-to-region start end)
49 (goto-char (point-min))
50 (let ((beg))
51 (while (or (< (point) (point-max))
52 (and (= 1 (point-max)) even-empty))
53 (setq beg (point))
54 (end-of-line)
55 ;; call-process-region won't send over a 0-character line.
56 ;; We go outside the loop to create a 1-character line " " in the
57 ;; *ESS-temporary* buffer
58 (if (= beg (point)) ;; do empty line outside loop
59 (ess-eval-linewise-ddeclient " " nil 'eob t)
60 ;;(call-process-region start end
61 ;; "ddeclient" nil nil nil "S-PLUS" "SCommand")
62 (call-process-region
63 beg (point)
64 inferior-ess-ddeclient nil nil nil
65 inferior-ess-client-name inferior-ess-client-command))
66 (forward-line 1))
67 (widen)))
69 ;; C-c C-n
70 (defun ess-eval-linewise-ddeclient (text-withtabs &optional
71 invisibly eob even-empty
72 sleep-sec)
73 (save-excursion
74 (set-buffer (get-buffer-create "*ESS-temporary*"))
75 (ess-setq-vars-local ess-customize-alist (current-buffer))
76 (erase-buffer)
77 (insert text-withtabs)
78 (ess-eval-region-ddeclient (point-min) (point-max) even-empty))
79 (if (numberp sleep-sec)
80 (sleep-for sleep-sec))); in addition to timeout-ms
82 ;; C-c C-v
83 (defun ess-display-help-on-object-ddeclient (object)
84 "Display the ESS documentation for OBJECT in another window.
85 If prefix arg is given, forces a query of the ESS process for the help
86 file. Otherwise just pops to an existing buffer if it exists."
87 (ess-force-buffer-current "Process to load into: ")
88 (ess-eval-linewise-ddeclient (concat "help(" object ")")))
91 ;; C-c C-l
92 (defun ess-load-file-ddeclient (filename)
93 "Load an S source file into an inferior ESS process; alternate behavior for
94 `ess-load-file', required with S-Plus GUI for Windows: Sends the S-Plus command
95 source(\"filename\") to S. This version does not guarantee to save .Last.value,
96 nor offer alternate buffers or editing capability."
97 (let ((source-buffer (get-file-buffer filename)))
98 (if (ess-check-source filename)
99 (error "Buffer %s has not been saved" (buffer-name source-buffer))
100 ;; Find the process to load into
101 (if source-buffer
102 (save-excursion
103 (set-buffer source-buffer)
104 (ess-force-buffer-current "Process to load into: ")
105 ;; (ess-check-modifications) ;;; not possible with ddeclient
106 ;; it calls ess-command which requires two-way communication
107 ;; with the S-Plus process
109 (ess-eval-linewise-ddeclient (format inferior-ess-load-command filename)))
110 (widen))
113 ;; C-c C-d
114 (defun ess-dump-object-ddeclient (object filename)
115 "Dump the ESS object OBJECT into file FILENAME."
116 (ess-force-buffer-current "Process to load into: ")
117 (ess-eval-linewise-ddeclient (concat "dump('" object "','" filename "')"))
118 (sleep-for 5)
119 (find-file filename)
120 (widen))
123 (defun ess-dput-expression-ddeclient (object filename)
124 "Dump the ESS object found by evaluating OBJECT into file FILENAME."
125 (ess-force-buffer-current "Process to load into: ")
126 (ess-eval-linewise-ddeclient (concat "dput(" object ",'" filename "')"))
127 (sleep-for 2)
128 (find-file filename))
130 (defun ess-command-ddeclient-proposed (com &optional buf sleep)
131 "ddeclient version of real `ess-command'.
132 Send the ESS process command COM and redirect its output to the
133 temporary file named BUF. The temporary filename is constructed
134 in emacs, not in the ESS process. The default name for the
135 temporary buffer is \"ess-temp.st\". The function waits
136 SLEEP (which defaults to 1) seconds and then brings the temporary
137 file into an emacs buffer and displays it."
138 (let (filename bufname)
139 (if (not buf) (setq buf "ess-temp.st"))
140 (if (not sleep) (setq sleep 1))
141 (setq filename (concat (file-name-as-directory (getenv "TEMP")) buf))
142 (ess-eval-linewise-ddeclient
143 (concat ".old.Last.value <- .Last.value; sink('"
144 filename
145 "'); print("
147 "); sink(); .Last.value <- .old.Last.value"))
148 (setq bufname (ess-get-file-or-buffer filename)) ;; must follow the eval
149 (sleep-for sleep)
150 (if (not bufname)
151 (find-file filename)
152 (switch-to-buffer bufname))
153 (revert-buffer t t) ;; this allows the user to reuse the BUF name
156 ;; previous version (ESS-5.2.12 and earlier)
157 (defun ess-command-ddeclient (com &optional buf sleep)
158 "ddeclient bypass of real ess-command"
159 (ess-eval-linewise com))
161 (provide 'ess-dde)
163 \f ; Local variables section
165 ;;; This file is automatically placed in Outline minor mode.
166 ;;; The file is structured as follows:
167 ;;; Chapters: ^L ;
168 ;;; Sections: ;;*;;
169 ;;; Subsections: ;;;*;;;
170 ;;; Components: defuns, defvars, defconsts
171 ;;; Random code beginning with a ;;;;* comment
173 ;;; Local variables:
174 ;;; mode: emacs-lisp
175 ;;; mode: outline-minor
176 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
177 ;;; End:
179 ;;; ess-dde.el ends here