1
1
;;; essl-bug.el -- ESS BUGS customization
3
3
;; Copyright (C) 2001 Rodney Sparapani
4
;; Copyright (C) 2002--2004 Free Software Foundation, Inc.
5
;; Copyright (C) 2002--2004 A.J. Rossini, Rich M. Heiberger, Martin
6
;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
5
;; Author: Rodney Sparapani <rsparapa@mcw.edu>
6
;; Maintainer: A.J. Rossini <rossini@biostat.washington.edu>
8
;; Original Author: Rodney Sparapani <rsparapa@mcw.edu>
7
9
;; Created: 27 February 2001
8
;; Modified: $Date: 2002/01/24 15:00:44 $
9
;; Version: $Revision: 1.20 $
10
;; RCS: $Id: essl-bug.el,v 1.20 2002/01/24 15:00:44 rsparapa Exp $/ini
10
;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
12
12
;; Keywords: BUGS, bugs, BACKBUGS, backbugs.
64
69
Unix users will get 'sh by default.
66
Users whose default is not 'sh, but are accessing a remote machine with
71
Users whose default is not 'sh, but are accessing a remote machine with
67
72
`telnet', `rlogin', or `ssh', should have the following in ~/.emacs
68
73
(setq-default ess-bugs-batch-method 'sh)"
72
(defcustom ess-bugs-batch-command "backbugs"
73
;; (convert-standard-filename
74
;; (concat ess-lisp-directory "/../etc/"
75
;; (if (w32-shell-dos-semantics) "backbugs.bat" "backbugs")))
76
"*ESS[BUGS]: Set to the name of the batch BUGS script that comes with ESS.
77
It allows the user to modify settings in a cross-platform manner. Make sure
83
(defcustom ess-bugs-batch-post-command
84
(if (equal ess-bugs-batch-method 'sh) "&" " ")
85
"*ESS[BUGS]: Modifiers at the end of the batch BUGS command line."
90
(defcustom ess-bugs-batch-pre-command
91
(if (equal ess-bugs-batch-method 'sh) "nohup"
77
(defcustom ess-bugs-batch-version "0.6"
78
"*ESS[BUGS]: The batch BUGS version to use."
83
;; SJE Thu 13 May 2004
84
;; The "backbugs" scripts can be found in ess-etc-directory, so maybe we
85
;; can use ess-etc-directory here too.
86
(defcustom ess-bugs-batch-command
87
(if (equal ess-bugs-batch-version "0.6") "backbugs" "backbug5")
88
"*ESS[BUGS]: The name of the command to run BUGS in batch mode.
90
Set to the name of the batch BUGS script that comes with ESS or
91
to the name of BUGS command. Make sure it is in your PATH or
92
add path to the command name."
97
(defcustom ess-bugs-batch-post-command
98
(if (equal ess-bugs-batch-method 'sh) "&" " ")
99
"*ESS[BUGS]: Modifiers at the end of the batch BUGS command line."
104
(defcustom ess-bugs-batch-pre-command
105
(if (equal ess-bugs-batch-method 'sh) "test -f nohup.out && rm -f nohup.out || true; nohup"
92
106
(if ess-microsoft-p "start"))
93
"*ESS[BUGS]: Modifiers at the beginning of the batch BUGS command line."
107
"*ESS[BUGS]: Modifiers at the beginning of the batch BUGS command line."
98
112
(defcustom ess-bugs-default-bins "32"
99
"ESS[BUGS]: number of bins to use in the Griddy algorithm (Metropolis sampling)."
113
"ESS[BUGS]: Number of bins to use in the Griddy algorithm (Metropolis sampling)."
104
118
(defcustom ess-bugs-default-burn-in "500"
105
"ESS[BUGS]: burn-in iterations to discard."
119
"ESS[BUGS]: Burn-in iterations to discard."
110
124
(defcustom ess-bugs-default-update "1000"
111
"ESS[BUGS]: iterations to store."
125
"ESS[BUGS]: Iterations to store."
116
130
(defcustom ess-bugs-default-checkpoint "100"
117
"ESS[BUGS]: make a snapshot every this many iterations."
131
"ESS[BUGS]: Make a snapshot every this many iterations."
122
136
(defvar ess-bugs-file "."
123
"ESS[BUGS]: BUGS file with PATH.")
137
"ESS[BUGS]: BUGS file with PATH.")
125
139
(defvar ess-bugs-file-root "."
126
"ESS[BUGS]: Root of BUGS file.")
140
"ESS[BUGS]: Root of BUGS file.")
128
142
(defvar ess-bugs-file-suffix "."
129
"ESS[BUGS]: Suffix of BUGS file.")
143
"ESS[BUGS]: Suffix of BUGS file.")
131
145
(defvar ess-bugs-file-dir "."
132
"ESS[BUGS]: Directory of BUGS file.")
146
"ESS[BUGS]: Directory of BUGS file.")
134
148
(defvar ess-bugs-file-data "..."
135
"ESS[BUGS]: BUGS data file.")
149
"ESS[BUGS]: BUGS data file.")
137
151
(defcustom ess-bugs-inits-suffix ".in"
138
"ESS[BUGS]: BUGS init file suffix."
152
"ESS[BUGS]: BUGS init file suffix."
143
157
(defcustom ess-bugs-data-suffix ".dat"
144
"ESS[BUGS]: BUGS data file suffix."
158
"ESS[BUGS]: BUGS data file suffix."
149
(defcustom ess-bugs-suffix-regexp
163
(defcustom ess-bugs-suffix-regexp
150
164
(concat "[.]\\([bB][oOuU][gG]\\|[bB][mM][dD]\\|"
151
(if ess-bugs-inits-suffix (concat
165
(if ess-bugs-inits-suffix (concat
152
166
"\\|" (downcase ess-bugs-inits-suffix) "\\|" (upcase ess-bugs-inits-suffix)))
153
(if ess-bugs-data-suffix (concat
167
(if ess-bugs-data-suffix (concat
154
168
"\\|" (downcase ess-bugs-data-suffix) "\\|" (upcase ess-bugs-data-suffix)))
156
"*Regular expression for BUGS suffixes."
170
"*ESS[BUGS]: Regular expression for BUGS suffixes."
175
(defcustom ess-bugs-mode-hook nil
176
"*ESS[BUGS]: List of functions to call upon entering mode."
161
180
(defvar ess-bugs-monitor-vars " "
162
"ESS[BUGS]: List of BUGS variables to be written out to a file.")
181
"ESS[BUGS]: List of BUGS variables to be written out to a file.")
164
183
(defvar ess-bugs-stats-vars " "
165
"ESS[BUGS]: List of BUGS variables to be summarized with statistics.")
167
(defvar ess-bugs-mode-hook nil
168
"ESS[BUGS]: List of functions to call upon entering mode.")
184
"ESS[BUGS]: List of BUGS variables to be summarized with statistics.")
171
186
(defvar ess-bugs-mode-map nil
172
"ESS[BUGS]: Keymap for mode.")
187
"ESS[BUGS]: Keymap for mode.")
174
189
(if ess-bugs-mode-map nil
175
190
(setq ess-bugs-mode-map (make-keymap))
224
239
;;(cons (concat "\\<\\(c\\|list\\)[ \t\n]*(")
225
240
;; font-lock-function-name-face)
227
"ESS[BUGS]: Font lock keywords."
242
"ESS[BUGS]: Font lock keywords."
231
246
(defun ess-bugs-file ()
232
"ESS[BUGS]: Set `ess-bugs-file', `ess-bugs-file-root', `ess-bugs-file-suffix' and `ess-bugs-file-dir'."
247
"ESS[BUGS]: Set internal variables dealing with BUGS files.
248
Set `ess-bugs-file', `ess-bugs-file-root', `ess-bugs-file-suffix'
249
and `ess-bugs-file-dir'."
235
250
(let ((ess-bugs-temp-string (buffer-name)))
236
251
(setq ess-bugs-file (expand-file-name ess-bugs-temp-string))
237
(setq ess-bugs-file-dir
252
(setq ess-bugs-file-dir
238
253
(convert-standard-filename (file-name-directory ess-bugs-file)))
239
(setq ess-bugs-file-root
254
(setq ess-bugs-file-root
240
255
(file-name-nondirectory (file-name-sans-extension ess-bugs-file)))
242
(if (fboundp 'file-name-extension)
257
(if (fboundp 'file-name-extension)
243
258
(setq ess-bugs-file-suffix (file-name-extension ess-bugs-temp-string))
245
260
(setq ess-bugs-file-suffix (car (last (split-string ess-bugs-temp-string "[.]")))))
247
(setq ess-bugs-file-suffix
262
(setq ess-bugs-file-suffix
248
263
(downcase (car (split-string (concat "." ess-bugs-file-suffix) "[<]"))))
250
265
(setq ess-bugs-file (concat ess-bugs-file-dir ess-bugs-file-root ess-bugs-file-suffix))
269
284
(insert " for (i in 1:N) {\n \n")
274
(if (equal ".bmd" suffix) (progn
275
(insert (concat "compile(\"" ess-bugs-file-dir ess-bugs-file-root ".bug\")\n"))
276
(insert (concat "save(\"" ess-bugs-file-dir ess-bugs-file-root ".in0\")\n"))
289
(if (equal ".bmd" suffix) (let
290
((tmp-bugs-file-dir (if (equal ess-bugs-batch-version "0.6") ess-bugs-file-dir)))
291
(insert (concat "compile(\"" tmp-bugs-file-dir ess-bugs-file-root ".bug\")\n"))
292
(insert (concat "save(\"" tmp-bugs-file-dir ess-bugs-file-root ".in0\")\n"))
277
293
(insert (concat "update(" ess-bugs-default-burn-in ")\n"))
278
(insert (concat "save(\"" ess-bugs-file-dir ess-bugs-file-root ".in1\")\n"))
294
(insert (concat "save(\"" tmp-bugs-file-dir ess-bugs-file-root ".in1\")\n"))
279
295
(insert "#%MONITOR\n\n#%MONITOR\n")
280
(insert (concat "checkpoint(" ess-bugs-default-checkpoint ")\n"))
296
(if (equal ess-bugs-batch-version "0.6")
297
(insert (concat "checkpoint(" ess-bugs-default-checkpoint ")\n")))
281
298
(insert (concat "update(" ess-bugs-default-update ")\n"))
282
(insert (concat "save(\"" ess-bugs-file-dir ess-bugs-file-root ".in2\")\n"))
299
(insert (concat "save(\"" tmp-bugs-file-dir ess-bugs-file-root ".in2\")\n"))
283
300
(insert "#%STATS\n\n#%STATS\n")
285
302
;;(insert "q(\"" ess-bugs-file-dir ess-bugs-file-root ".bog\")\n")
290
307
(defun ess-exit-notify-sh (string)
291
308
"Detect completion or failure of submitted job and notify the user."
292
309
(let* ((exit-done "\\[[0-9]+\\]\\ *\\+*\\ *\\(Exit\\|Done\\).*$")
322
339
(comint-send-input)
324
341
(insert (concat ess-bugs-batch-pre-command " " ess-bugs-batch-command " "
325
ess-bugs-default-bins " " ess-bugs-file-root " " ess-bugs-file " "
326
ess-bugs-batch-post-command))
342
(if (equal ess-bugs-batch-version "0.6") ess-bugs-default-bins)
343
" " ess-bugs-file-root " "
344
(if (equal ess-bugs-batch-version "0.6")
345
ess-bugs-file (concat ess-bugs-file-root ".bmd"))
346
" " ess-bugs-batch-post-command))
328
348
(comint-send-input)
332
352
(defun ess-bugs-na-bug ()
333
"ESS[BUGS]: Perform Next-Action for .bug"
353
"ESS[BUGS]: Perform Next-Action for .bug"
335
355
(if (equal 0 (buffer-size)) (ess-switch-to-suffix ".bug")
357
((tmp-bugs-file-dir (if (equal ess-bugs-batch-version "0.6") ess-bugs-file-dir)))
337
358
(goto-char (point-min))
339
(if (search-forward "%MODEL" nil t)
360
(if (search-forward "%MODEL" nil t)
340
361
(replace-match ess-bugs-file-root t t))
342
363
(if (search-forward "%DATA" nil t) (progn
343
(setq ess-bugs-file-data
344
(concat ess-bugs-file-dir ess-bugs-file-root ess-bugs-data-suffix))
364
(setq ess-bugs-file-data
365
(concat tmp-bugs-file-dir ess-bugs-file-root ess-bugs-data-suffix))
345
366
(replace-match ess-bugs-file-data t t))
347
368
(if (search-forward-regexp "data.+in[ \t\n]+\"\\(.*\\)\"" nil t)
388
408
(goto-char (point-min))
390
(if (search-forward-regexp "%MONITOR[ \t]+" nil t)
410
(if (search-forward-regexp "%MONITOR[ \t]+" nil t)
391
411
(setq ess-bugs-search-min (point))
393
413
(setq ess-bugs-search-min (search-forward "var"))
396
416
(setq ess-bugs-search-max (search-forward-regexp ";"))
398
418
(goto-char ess-bugs-search-min)
399
419
(setq ess-bugs-monitor-vars "")
401
421
(while (search-forward-regexp ess-bugs-search-vars ess-bugs-search-max t)
403
(setq ess-bugs-monitor-vars
404
(concat ess-bugs-monitor-vars "monitor("
423
(setq ess-bugs-monitor-vars
424
(concat ess-bugs-monitor-vars "monitor("
405
425
(match-string 1) (match-string 3) (match-string 4) (match-string 5) ")\n"))
408
(setq ess-bugs-monitor-vars
428
(setq ess-bugs-monitor-vars
409
429
(concat "#%MONITOR\n" ess-bugs-monitor-vars "#%MONITOR\n"))
411
431
(goto-char (point-min))
430
450
;; replace-in-string may not be available, work-around necessary; see below
431
;; (setq ess-bugs-stats-vars
451
;; (setq ess-bugs-stats-vars
432
452
;; (replace-in-string ess-bugs-monitor-vars "#%MONITOR" "#%STATS"))
433
;; (setq ess-bugs-stats-vars
453
;; (setq ess-bugs-stats-vars
434
454
;; (replace-in-string ess-bugs-stats-vars "monitor" "stats" t))
437
457
(setq ess-bugs-stats-vars ess-bugs-monitor-vars)
439
459
(while (string-match "#%MONITOR" ess-bugs-stats-vars)
440
(setq ess-bugs-stats-vars
460
(setq ess-bugs-stats-vars
441
461
(replace-match "#%STATS" t t ess-bugs-stats-vars)))
443
463
(while (string-match "monitor" ess-bugs-stats-vars)
444
(setq ess-bugs-stats-vars
464
(setq ess-bugs-stats-vars
445
465
(replace-match "stats" t t ess-bugs-stats-vars)))
453
473
(ess-switch-to-suffix ".bmd")
478
498
(setq font-lock-defaults '(ess-bugs-font-lock-keywords nil t))
479
499
(run-hooks 'ess-bugs-mode-hook)
481
(if (not (w32-shell-dos-semantics))
501
(if (not (w32-shell-dos-semantics))
482
502
(add-hook 'comint-output-filter-functions 'ess-exit-notify-sh))
507
;;; ESS[BUGS-Shell] for running BUGS interactively
508
(defgroup ess-bugs-shell nil
513
(defcustom ess-bugs-shell-buffer-name "BUGS"
514
"*ESS[BUGS-Shell]: The name of the BUGS-Shell buffer."
515
:group 'ess-bugs-shell
518
(defcustom ess-bugs-shell-command "bugs"
519
"*ESS[BUGS-Shell]: The name of the command to run BUGS interactively.
521
Set to the name of the batch BUGS script that comes with ESS or
522
to the name of BUGS command. Make sure it is in your PATH or
523
add path to the command name."
524
:group 'ess-bugs-shell
527
(defcustom ess-bugs-shell-default-output-file-root "bugs"
528
"*ESS[BUGS-Shell]: Default value for the root of output files."
529
:group 'ess-bugs-shell
532
(defcustom ess-bugs-shell-mode-hook nil
533
"*ESS[BUGS-Shell]: List of functions to call upon entering mode."
534
:group 'ess-bugs-shell
537
(defun ess-bugs-shell ()
538
"Create a buffer with BUGS running as a subprocess."
541
(switch-to-buffer (concat "*" ess-bugs-shell-buffer-name "*"))
542
(make-comint ess-bugs-shell-buffer-name ess-bugs-shell-command nil
543
ess-bugs-default-bins ess-bugs-shell-default-output-file-root)
545
(setq shell-dirtrackp t
546
major-mode 'bugs-shell-mode
547
mode-name "ESS[BUGS-Shell]"
548
comint-prompt-regexp "^Bugs> *")
549
(make-local-variable 'font-lock-defaults)
550
(setq font-lock-defaults '(ess-bugs-font-lock-keywords nil t))
551
(run-hooks 'ess-bugs-shell-mode-hook)
486
554
(provide 'essl-bug)