Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2701 views
1
;;; ess-dde.el --- ESS customization for ddeclients under Windows 9x/NT
2
3
;; Copyright (C) 1998--1999 Richard M. Heiberger <[email protected]>
4
;; Copyright (C) 2000--2006 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: 9 Dec 1998
9
;; Maintainer: ESS-core <[email protected]>
10
11
;; This file is part of ESS
12
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.
17
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.
22
23
;; A copy of the GNU General Public License is available at
24
;; http://www.r-project.org/Licenses/
25
26
27
;;; Commentary:
28
29
;; Code for dealing with running external processes on Windows 9x/NT
30
;; through ddeclient.
31
32
;;; Code:
33
34
35
;; *NO* Requires and autoloads
36
37
;; C-c C-r
38
(defun ess-eval-region-ddeclient (start end even-empty)
39
"Loop through lines in region and send them to ESS via ddeclient."
40
(setq ;; set the following variables for the current ddeESS process.
41
inferior-ess-ddeclient (ess-get-process-variable 'inferior-ess-ddeclient)
42
inferior-ess-client-name (ess-get-process-variable 'inferior-ess-client-name)
43
inferior-ess-client-command (ess-get-process-variable 'inferior-ess-client-command))
44
(narrow-to-region start end)
45
(goto-char (point-min))
46
(let ((beg))
47
(while (or (< (point) (point-max))
48
(and (= 1 (point-max)) even-empty))
49
(setq beg (point))
50
(end-of-line)
51
;; call-process-region won't send over a 0-character line.
52
;; We go outside the loop to create a 1-character line " " in the
53
;; *ESS-temporary* buffer
54
(if (= beg (point)) ;; do empty line outside loop
55
(ess-eval-linewise-ddeclient " " nil 'eob t)
56
;;(call-process-region start end
57
;; "ddeclient" nil nil nil "S-PLUS" "SCommand")
58
(call-process-region
59
beg (point)
60
inferior-ess-ddeclient nil nil nil
61
inferior-ess-client-name inferior-ess-client-command))
62
(forward-line 1))
63
(widen)))
64
65
;; C-c C-n
66
(defun ess-eval-linewise-ddeclient (text-withtabs &optional
67
invisibly eob even-empty
68
sleep-sec)
69
(with-current-buffer (get-buffer-create "*ESS-temporary*")
70
(ess-setq-vars-local ess-customize-alist (current-buffer))
71
(erase-buffer)
72
(insert text-withtabs)
73
(ess-eval-region-ddeclient (point-min) (point-max) even-empty))
74
(if (numberp sleep-sec)
75
(sleep-for sleep-sec))); in addition to timeout-ms
76
77
;; C-c C-v
78
(defun ess-display-help-on-object-ddeclient (object)
79
"Display the ESS documentation for OBJECT in another window.
80
If prefix arg is given, forces a query of the ESS process for the help
81
file. Otherwise just pops to an existing buffer if it exists."
82
(ess-force-buffer-current "Process to load into: ")
83
(ess-eval-linewise-ddeclient (concat "help(" object ")")))
84
85
86
;; C-c C-l
87
(defun ess-load-file-ddeclient (filename)
88
"Load an S source file into an inferior ESS process; alternate behavior for
89
`ess-load-file', required with S-Plus GUI for Windows: Sends the S-Plus command
90
source(\"filename\") to S. This version does not guarantee to save .Last.value,
91
nor offer alternate buffers or editing capability."
92
(let ((source-buffer (get-file-buffer filename)))
93
(if (ess-check-source filename)
94
(error "Buffer %s has not been saved" (buffer-name source-buffer))
95
;; Find the process to load into
96
(if source-buffer
97
(with-current-buffer source-buffer
98
(ess-force-buffer-current "Process to load into: ")
99
;; (ess-check-modifications) ;;; not possible with ddeclient
100
;; it calls ess-command which requires two-way communication
101
;; with the S-Plus process
102
)))
103
(ess-eval-linewise-ddeclient (format ess-load-command filename)))
104
(widen))
105
106
107
;; C-c C-d
108
(defun ess-dump-object-ddeclient (object filename)
109
"Dump the ESS object OBJECT into file FILENAME."
110
(ess-force-buffer-current "Process to load into: ")
111
(ess-eval-linewise-ddeclient (concat "dump('" object "','" filename "')"))
112
(sleep-for 5)
113
(find-file filename)
114
(widen))
115
116
117
(defun ess-dput-expression-ddeclient (object filename)
118
"Dump the ESS object found by evaluating OBJECT into file FILENAME."
119
(ess-force-buffer-current "Process to load into: ")
120
(ess-eval-linewise-ddeclient (concat "dput(" object ",'" filename "')"))
121
(sleep-for 2)
122
(find-file filename))
123
124
(defun ess-command-ddeclient-proposed (com &optional buf sleep)
125
"ddeclient version of real `ess-command'.
126
Send the ESS process command COM and redirect its output to the
127
temporary file named BUF. The temporary filename is constructed
128
in emacs, not in the ESS process. The default name for the
129
temporary buffer is \"ess-temp.st\". The function waits
130
SLEEP (which defaults to 1) seconds and then brings the temporary
131
file into an emacs buffer and displays it."
132
(let (filename bufname)
133
(if (not buf) (setq buf "ess-temp.st"))
134
(if (not sleep) (setq sleep 1))
135
(setq filename (concat (file-name-as-directory (getenv "TEMP")) buf))
136
(ess-eval-linewise-ddeclient
137
(concat ".old.Last.value <- .Last.value; sink('"
138
filename
139
"'); print("
140
com
141
"); sink(); .Last.value <- .old.Last.value"))
142
(setq bufname (ess-get-file-or-buffer filename)) ;; must follow the eval
143
(sleep-for sleep)
144
(if (not bufname)
145
(find-file filename)
146
(switch-to-buffer bufname))
147
(revert-buffer t t) ;; this allows the user to reuse the BUF name
148
))
149
150
;; previous version (ESS-5.2.12 and earlier)
151
(defun ess-command-ddeclient (com &optional buf sleep)
152
"ddeclient bypass of real ess-command"
153
(ess-eval-linewise com))
154
155
(provide 'ess-dde)
156
157
; Local variables section
158
159
;;; This file is automatically placed in Outline minor mode.
160
;;; The file is structured as follows:
161
;;; Chapters: ^L ;
162
;;; Sections: ;;*;;
163
;;; Subsections: ;;;*;;;
164
;;; Components: defuns, defvars, defconsts
165
;;; Random code beginning with a ;;;;* comment
166
167
;;; Local variables:
168
;;; mode: emacs-lisp
169
;;; mode: outline-minor
170
;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
171
;;; End:
172
173
;;; ess-dde.el ends here
174
175