Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2701 views
1
;;; ess-r-gui.el --- Run Rgui on Windows as an inferior Emacs process
2
3
;; Copyright (C) 2008 A.J. Rossini, Richard M. Heiberger, Martin
4
;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
5
6
;; Author: Richard M. Heiberger <[email protected]>
7
;; Created: 10 Mar 2008
8
;; Maintainer: ESS-core <[email protected]>
9
10
;; This file is part of ESS
11
12
;; This file is free software; you can redistribute it and/or modify
13
;; it under the terms of the GNU General Public License as published by
14
;; the Free Software Foundation; either version 2, or (at your option)
15
;; any later version.
16
17
;; This file is distributed in the hope that it will be useful,
18
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
;; GNU General Public License for more details.
21
22
;; A copy of the GNU General Public License is available at
23
;; http://www.r-project.org/Licenses/
24
25
;;; Commentary:
26
27
;In Rgui:
28
;> library(tcltk2) ## >= 1.0-6
29
;> .ess.command <- function() source("c:/temp/ess-tempfile.R", echo=TRUE)
30
;> tclFun(.ess.command)
31
;[1] "R_call 0203A04C"
32
33
;;; Code:
34
35
(require 'ess-dde) ;; needed here because we override several definitions
36
37
(defun ess-ddeclient-p ()
38
"Returns the name of the ddeclient iff `ess-local-process-name'
39
is associated with an `inferior-ess-ddeclient', and nil if the
40
ess-process is running as an ordinary inferior process. Alway
41
nil on Unix machines."
42
(interactive)
43
(if ess-microsoft-p
44
(let ((ess-ddeclient (ess-get-process-variable 'inferior-ess-ddeclient)))
45
(if (not (equal ess-ddeclient (default-value 'inferior-ess-ddeclient)))
46
ess-ddeclient))))
47
48
(defun ess-eval-region-execdde (start end even-empty)
49
"Loop through lines in region and send them to ESS via execdde."
50
(setq ;; set the following variables for the current ddeESS process.
51
inferior-ess-ddeclient (ess-get-process-variable 'inferior-ess-ddeclient)
52
)
53
(write-region start end ess-command-file nil nil 'no-message)
54
(call-process-shell-command
55
(concat inferior-ess-execdde ess-rgui-command))
56
)
57
58
59
(if (not (getenv "R_HOME")) (setenv "R_HOME" "c:/progra~1/R/R-2.6.1"))
60
;; ^^^^^^^^^ FIXME! do something better
61
(defvar inferior-Rgui-program-name "cmd" "Rgui program name")
62
(defvar Rgui-pager "emacsclientw.exe" "Rgui pager program")
63
(defvar ess-command-file "c:/temp/ess-tempfile.R"
64
"file name for communication with Rgui")
65
(defvar inferior-ess-execdde
66
(concat (getenv "R_HOME") "/site-library/tcltk2/bin/execdde.exe")
67
"Full pathname to execdde executable")
68
(defvar ess-rgui-command " -s TclEval -t R -c .ess.command > NUL"
69
"command to inferior-ess-execdde that will make Rgui read the command file")
70
(defvar inferior-ess-language-start-rgui
71
"options(chmhelp=FALSE, htmlhelp=FALSE, help_type='text'); require(tcltk2)"
72
"additional arguments to rgui")
73
74
(defun ess-eval-region-ddeclient (start end even-empty)
75
"Loop through lines in region and send them to ESS via ddeclient."
76
(setq ;; set the following variables for the current ddeESS process.
77
inferior-ess-ddeclient (ess-get-process-variable 'inferior-ess-ddeclient)
78
inferior-ess-client-name (ess-get-process-variable 'inferior-ess-client-name)
79
inferior-ess-client-command (ess-get-process-variable 'inferior-ess-client-command))
80
(narrow-to-region start end)
81
(goto-char (point-min))
82
83
(if (equal inferior-ess-ddeclient "execdde")
84
(ess-eval-region-execdde start end even-empty)
85
86
(let ((beg))
87
(while (or (< (point) (point-max))
88
(and (= 1 (point-max)) even-empty))
89
(setq beg (point))
90
(end-of-line)
91
;; call-process-region won't send over a 0-character line.
92
;; We go outside the loop to create a 1-character line " " in the
93
;; *ESS-temporary* buffer
94
(if (= beg (point)) ;; do empty line outside loop
95
(ess-eval-linewise-ddeclient " " nil 'eob t)
96
(call-process-region
97
beg (point)
98
inferior-ess-ddeclient nil nil nil
99
inferior-ess-client-name inferior-ess-client-command))
100
(forward-line 1))))
101
(widen))
102
103
104
105
(defvar Rgui-customize-alist
106
(append
107
'((ess-local-customize-alist . 'Rgui-customize-alist)
108
(ess-dialect . "R")
109
(ess-suffix . "R")
110
(ess-dump-filename-template . (ess-replace-regexp-in-string
111
"S$" ess-suffix ; in the one from custom:
112
ess-dump-filename-template-proto))
113
(ess-mode-syntax-table . R-syntax-table)
114
(ess-mode-editing-alist . R-editing-alist)
115
(ess-change-sp-regexp . ess-R-change-sp-regexp)
116
(ess-help-sec-regex . ess-help-R-sec-regex)
117
(ess-help-sec-keys-alist . ess-help-R-sec-keys-alist)
118
(ess-loop-timeout . ess-S-loop-timeout);fixme: dialect spec.
119
(ess-cmd-delay . ess-R-cmd-delay)
120
(ess-function-pattern . ess-R-function-pattern)
121
(ess-object-name-db-file . "ess-r-namedb.el" )
122
(inferior-ess-program . inferior-Rgui-program-name)
123
(inferior-ess-objects-command . inferior-R-objects-command)
124
(inferior-ess-font-lock-keywords . 'inferior-R-font-lock-keywords)
125
(inferior-ess-search-list-command . "search()\n")
126
(inferior-ess-help-command . "help(\"%s\")\n")
127
(inferior-ess-help-filetype . nil) ;; "chm") ;;?
128
(inferior-ess-exit-command . "q()")
129
(inferior-ess-exit-prompt . "Save workspace image? [y/n/c]: ")
130
(inferior-ess-primary-prompt . "\\([A-Z/][][A-Za-z0-9./]*\\)*[>$] ")
131
(inferior-ess-secondary-prompt . "+ ?")
132
;;harmful for shell-mode's C-a: -- but "necessary" for ESS-help?
133
(inferior-ess-start-file . nil) ;; "~/.ess-R"
134
(inferior-ess-start-args . "")
135
(inferior-ess-ddeclient . "execdde")
136
(ess-STERM . "ddeSS")
137
(ess-editor . R-editor)
138
(ess-pager . Rgui-pager)
139
)
140
S-common-cust-alist)
141
"Variables to customize for Rgui")
142
143
144
(defun Rgui (&optional proc-name)
145
"Call 'Rgui for Windows'. Put R in an independent MS-Window (R
146
persists even if the '(ddeESS [R])' window is killed in emacs).
147
Do this by creating a comint process that calls cmd. This is a
148
placeholder buffer with mode '(ddeESS [R])'. Commands sent from
149
an (ESS[S] [R]) buffer to this process will be sourced into the
150
independent Rgui R Console."
151
(interactive)
152
(save-excursion
153
(setq ess-customize-alist Rgui-customize-alist)
154
(ess-write-to-dribble-buffer
155
(format "\n(Rgui): ess-dialect=%s, buf=%s\n" ess-dialect
156
(current-buffer)))
157
(setq ess-customize-alist ; change inferior-ess-primary-prompt
158
(append ess-customize-alist '((inferior-ess-primary-prompt . "^"))))
159
(let ((default-ddeclient (default-value 'inferior-ess-ddeclient)))
160
(cd (w32-short-file-name (directory-file-name default-directory)))
161
;; (setenv "S_PROJ" default-directory)
162
(setq-default inferior-ess-ddeclient "execdde")
163
(inferior-ess)
164
(setq-default inferior-ess-ddeclient default-ddeclient)
165
(sleep-for 2) ; need to wait, else working too fast!
166
)
167
(setq comint-process-echoes nil)
168
169
;; *R* buffer
170
(goto-char (point-min))
171
(insert
172
"This is a placeholder buffer. You can't type anything here.\n
173
You may ignore the 'options' error in this buffer.\n\n")
174
(goto-char (point-max))
175
(set-buffer-process-coding-system 'raw-text-dos 'raw-text-unix)
176
(setq buffer-read-only t) ; force buffer to be read-only
177
(setq mode-name "ddeESS")
178
179
;; initialization
180
(set-buffer (find-file-noselect ess-command-file 'nowarn))
181
(erase-buffer)
182
(setq ;; set the following variables for the current ddeESS process.
183
inferior-ess-language-start (ess-get-process-variable 'inferior-ess-language-start))
184
(if inferior-ess-language-start
185
(insert inferior-ess-language-start))
186
(if inferior-ess-language-start-rgui
187
(insert (concat "\n" inferior-ess-language-start-rgui)))
188
(save-buffer 0)
189
(call-process-shell-command
190
(concat inferior-ess-execdde ess-rgui-command))
191
))
192
193
;;; ess-r-gui.el ends here
194
195