Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2701 views
1
;;; ess-bugs-l.el --- ESS[BUGS] languages
2
3
;; Copyright (C) 2006-2011 Rodney Sparapani
4
5
;; Author: Rodney Sparapani
6
;; Created: 16 August 2006
7
;; Maintainer: ESS-help <[email protected]>
8
9
;; This file is part of ESS
10
11
;; This file is free software; you can redistribute it and/or modify
12
;; it under the terms of the GNU General Public License as published by
13
;; the Free Software Foundation; either version 2, or (at your option)
14
;; any later version.
15
;;
16
;; This file is distributed in the hope that it will be useful,
17
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
;; GNU General Public License for more details.
20
;;
21
;; A copy of the GNU General Public License is available at
22
;; http://www.r-project.org/Licenses/
23
24
25
;;; Code:
26
27
(require 'font-lock)
28
(require 'comint)
29
(require 'ess-compat)
30
31
(defgroup ess-bugs nil
32
"ESS: BUGS."
33
:group 'ess
34
:prefix "ess-")
35
36
(defcustom ess-bugs-batch-method
37
(if ess-microsoft-p (if (w32-shell-dos-semantics) 'dos 'sh) 'sh)
38
"Method used by `ess-bugs-batch'.
39
The default is based on the value of the emacs variable `system-type'
40
and, on Windows machines, the function `w32-shell-dos-semantics'.
41
'sh if *shell* runs a Bourne-like or a C-like Unix shell
42
'dos if *shell* runs a DOS-like Windows shell
43
44
Unix users will get 'sh by default.
45
46
Windows users running a DOS-like *shell* will get 'dos by default,
47
while those running a Unix-like *shell* will get 'sh by default.
48
49
Users whose default is not 'sh, but are accessing a remote machine with
50
`telnet' or `ssh', should have the following in their init file:
51
(setq-default ess-bugs-batch-method 'sh)"
52
:group 'ess-bugs
53
)
54
55
(defcustom ess-bugs-batch-post-command
56
(if (equal ess-bugs-batch-method 'sh) "&" " ")
57
"*ESS[BUGS]: Modifiers at the end of the batch BUGS command line."
58
:group 'ess-bugs
59
:type 'string
60
)
61
62
(defcustom ess-bugs-batch-pre-command
63
(if (equal ess-bugs-batch-method 'sh) "nohup nice time"
64
(if ess-microsoft-p "start"))
65
"*ESS[BUGS]: Modifiers at the beginning of the batch BUGS command line."
66
:group 'ess-bugs
67
:type 'string
68
)
69
70
71
(defcustom ess-bugs-default-burn-in "500"
72
"ESS[BUGS]: Burn-in iterations to discard."
73
:group 'ess-bugs
74
:type 'string
75
)
76
77
(defcustom ess-bugs-default-update "1000"
78
"ESS[BUGS]: Iterations to store."
79
:group 'ess-bugs
80
:type 'string
81
)
82
83
(defvar ess-bugs-batch-command ";"
84
"*ESS[BUGS]: The name of the command to run BUGS in batch mode."
85
)
86
87
(defvar ess-bugs-file "."
88
"ESS[BUGS]: BUGS file with PATH.")
89
90
(defvar ess-bugs-file-root "."
91
"ESS[BUGS]: Root of BUGS file.")
92
93
(defvar ess-bugs-file-suffix "."
94
"ESS[BUGS]: Suffix of BUGS file.")
95
96
(defvar ess-bugs-file-dir "."
97
"ESS[BUGS]: Directory of BUGS file.")
98
99
(defvar ess-bugs-file-data "..."
100
"ESS[BUGS]: BUGS data file.")
101
102
(defcustom ess-bugs-inits-suffix ".in"
103
"ESS[BUGS]: BUGS init file suffix."
104
:group 'ess-bugs
105
:type 'string
106
)
107
108
(defcustom ess-bugs-data-suffix ".dat"
109
"ESS[BUGS]: BUGS data file suffix."
110
:group 'ess-bugs
111
:type 'string
112
)
113
114
(defcustom ess-bugs-mode-hook nil
115
"*ESS[BUGS]: List of functions to call upon entering mode."
116
:group 'ess-bugs
117
:type 'hook)
118
119
(defvar ess-bugs-monitor-vars " "
120
"ESS[BUGS]: List of BUGS variables to be written out to a file.")
121
122
(defvar ess-bugs-stats-vars " "
123
"ESS[BUGS]: List of BUGS variables to be summarized with statistics.")
124
125
(defvar ess-bugs-mode-map nil
126
"ESS[BUGS]: Keymap for mode.")
127
128
(if ess-bugs-mode-map nil (setq ess-bugs-mode-map (make-keymap)))
129
(define-key ess-bugs-mode-map (quote [f2]) 'ess-revert-wisely)
130
;(define-key ess-bugs-mode-map (quote [f12]) 'ess-bugs-next-action)
131
(define-key ess-bugs-mode-map "\C-c\C-c" 'ess-bugs-next-action)
132
(define-key ess-bugs-mode-map "=" 'ess-bugs-hot-arrow)
133
(define-key ess-bugs-mode-map "_" 'ess-bugs-hot-arrow)
134
135
(defvar ess-bugs-syntax-table nil
136
"ESS[BUGS]: Syntax table for mode.")
137
138
(if ess-bugs-syntax-table nil (setq ess-bugs-syntax-table (make-syntax-table)))
139
(modify-syntax-entry ?\\ "." ess-bugs-syntax-table)
140
(modify-syntax-entry ?# "<" ess-bugs-syntax-table)
141
(modify-syntax-entry ?\n ">" ess-bugs-syntax-table)
142
(modify-syntax-entry ?( "()" ess-bugs-syntax-table)
143
(modify-syntax-entry ?) ")(" ess-bugs-syntax-table)
144
(modify-syntax-entry ?. "w" ess-bugs-syntax-table)
145
146
(defun ess-bugs-file ()
147
"ESS[BUGS]: Set internal variables dealing with BUGS files.
148
Set `ess-bugs-file', `ess-bugs-file-root', `ess-bugs-file-suffix'
149
and `ess-bugs-file-dir'."
150
(let ((ess-bugs-temp-string (buffer-name)))
151
(setq ess-bugs-file (expand-file-name ess-bugs-temp-string))
152
(setq ess-bugs-file-dir
153
(convert-standard-filename (file-name-directory ess-bugs-file)))
154
(setq ess-bugs-file-root
155
(file-name-nondirectory (file-name-sans-extension ess-bugs-file)))
156
157
(if (fboundp 'file-name-extension)
158
(setq ess-bugs-file-suffix (file-name-extension ess-bugs-temp-string))
159
;;else
160
(setq ess-bugs-file-suffix (car (last (split-string ess-bugs-temp-string "[.]")))))
161
162
(setq ess-bugs-file-suffix
163
(downcase (car (split-string (concat "." ess-bugs-file-suffix) "[<]"))))
164
165
(setq ess-bugs-file (concat ess-bugs-file-dir ess-bugs-file-root ess-bugs-file-suffix))
166
)
167
)
168
169
(defun ess-bugs-exit-notify-sh (string)
170
"ESS[BUGS]: Detect completion or failure of submitted job and notify the user."
171
(let* ((exit-done "\\[[0-9]+\\]\\ *\\+*\\ *\\(Exit\\|Done\\)[^\r\n]*")
172
(beg (string-match exit-done string)))
173
(if beg (message (substring string beg (match-end 0))))))
174
175
(defun ess-bugs-hot-arrow ()
176
"*ESS[BUGS]: Substitute <- for = key press"
177
(interactive)
178
(insert " <- "))
179
180
(defun ess-bugs-next-action ()
181
"ESS[BUGS/JAGS]: Perform the appropriate next action."
182
(interactive)
183
(ess-bugs-file)
184
185
(cond ((equal ".bug" ess-bugs-file-suffix) (ess-bugs-na-bug))
186
((equal ".jag" ess-bugs-file-suffix) (ess-jags-na-bug))
187
((equal ".bmd" ess-bugs-file-suffix)
188
(ess-save-and-set-local-variables)
189
(ess-bugs-na-bmd ess-bugs-command ess-bugs-chains))
190
((equal ".jmd" ess-bugs-file-suffix)
191
(ess-save-and-set-local-variables)
192
(ess-jags-na-jmd ess-jags-command ess-jags-chains)))
193
)
194
195
(defun ess-bugs-sci-to-round-4-dp ()
196
"ESS[BUGS]: round output from +/-0.000E+/-0 to 4 decimal places."
197
(interactive)
198
(setq buffer-read-only nil)
199
(save-excursion (goto-char 0)
200
(save-match-data (let ((ess-bugs-replacement-string nil)
201
(ess-bugs-replacement-9 0)
202
(ess-bugs-replacement-diff 0))
203
(while (search-forward-regexp "-?[0-9][.][0-9][0-9][0-9]E[+-][0-9]" nil t)
204
(setq ess-bugs-replacement-string
205
(int-to-string (string-to-number (match-string 0))))
206
(setq ess-bugs-replacement-diff (- (match-end 0) (match-beginning 0)))
207
(save-match-data
208
(setq ess-bugs-replacement-9
209
(string-match "99999999999$" ess-bugs-replacement-string))
210
211
(if (not ess-bugs-replacement-9)
212
(setq ess-bugs-replacement-9
213
(string-match "000000000001$" ess-bugs-replacement-string))))
214
215
(if ess-bugs-replacement-9
216
(setq ess-bugs-replacement-string
217
(substring ess-bugs-replacement-string 0 ess-bugs-replacement-9)))
218
219
(setq ess-bugs-replacement-diff
220
(- ess-bugs-replacement-diff (string-width ess-bugs-replacement-string)))
221
222
(while (> ess-bugs-replacement-diff 0)
223
(setq ess-bugs-replacement-string (concat ess-bugs-replacement-string " "))
224
(setq ess-bugs-replacement-diff (- ess-bugs-replacement-diff 1)))
225
226
(replace-match ess-bugs-replacement-string))))))
227
228
;;; ESS[BUGS-Shell] for running BUGS interactively
229
(defgroup ess-bugs-shell nil
230
"ESS: BUGS-Shell."
231
:group 'ess-bugs
232
:prefix "ess-")
233
234
(defcustom ess-bugs-shell-buffer-name "BUGS"
235
"*ESS[BUGS-Shell]: The name of the BUGS-Shell buffer."
236
:group 'ess-bugs-shell
237
:type 'string)
238
239
(defcustom ess-bugs-shell-command "OpenBUGS"
240
"*ESS[BUGS-Shell]: The name of the command to run BUGS interactively.
241
242
Set to the name of the batch BUGS script that comes with ESS or
243
to the name of BUGS command. Make sure it is in your PATH or
244
add path to the command name."
245
:group 'ess-bugs-shell
246
:type 'string)
247
248
(defcustom ess-bugs-shell-default-output-file-root "bugs"
249
"*ESS[BUGS-Shell]: Default value for the root of output files."
250
:group 'ess-bugs-shell
251
:type 'string)
252
253
(defcustom ess-bugs-shell-mode-hook nil
254
"*ESS[BUGS-Shell]: List of functions to call upon entering mode."
255
:group 'ess-bugs-shell
256
:type 'hook)
257
258
(defun ess-bugs-shell ()
259
"Create a buffer with BUGS running as a subprocess."
260
(interactive)
261
(require 'shell)
262
(switch-to-buffer (concat "*" ess-bugs-shell-buffer-name "*"))
263
(make-comint ess-bugs-shell-buffer-name ess-bugs-shell-command nil
264
ess-bugs-default-bins ess-bugs-shell-default-output-file-root)
265
(comint-mode)
266
(setq shell-dirtrackp t
267
major-mode 'bugs-shell-mode
268
mode-name "ESS[BUGS-Shell]"
269
comint-prompt-regexp "^Bugs> *")
270
(make-local-variable 'font-lock-defaults)
271
(setq font-lock-defaults '(ess-bugs-font-lock-keywords nil t))
272
(run-hooks 'ess-bugs-shell-mode-hook)
273
)
274
275
(provide 'ess-bugs-l)
276
277
;;; ess-bugs-l.el ends here
278
279