[ESS] iESS[Stata] quirks
Rodney Sparapani
rsparapa at mcw.edu
Thu Oct 16 17:22:48 CEST 2008
Brendan Halpin wrote:
>
> My practice with Stata is to execute the current command or region by
> (1) writing it to a file (2) prepending it with "#delimit ;" if
> necessary and (3) sending a "do file.do" command to Stata. It works
> reasonably well, but is a bit more simplistic than your suggestion of
> parsing the input and translating it on the fly to the interactive
> format (what is missing but implicit in your description is the notion
> that multi-line commands need to be put on a single line).
>
> For the record, this is in my ess-local.el:
>
> (defun delimit-do (clear &optional b e)
> "Send the region (or B to E) to the Stata process, via a do file.
> If \"#delimit ;\" occurs in the current buffer above the start of the region,
> wrap the commands in \"#delimit ;\"/\"#delimit cr\".
>
> Stata treats code in a do-file differently from interactive code;
> this mode allows \"/* ... */\" style comments as well as changing
> the delimiters."
> (interactive "P")
> (ess-force-buffer-current "Process to load into: ")
> (if (null b) (setq b (region-beginning)))
> (if (null e) (setq e (region-end)))
> (save-excursion
> (let ((commands (buffer-substring-no-properties b e))
> (delimit-do-filename (concat
> (file-name-directory (buffer-file-name (current-buffer)))
> delimit-do-file))
> delimit)
> (goto-char b)
> (setq delimit (re-search-backward "^#delimit +;" nil t))
> (set-buffer (find-file-noselect delimit-do-filename))
> (delete-region (point-min) (point-max))
> (if clear (insert "clear\n"))
> (if delimit (insert "#delimit ;\n"
> commands
> "\n#delimit cr\n")
> (insert commands "\n"))
> (write-file delimit-do-filename nil)
> (process-send-string
> (get-ess-process ess-current-process-name)
> (format "do %s \n" delimit-do-file)))))
>
> It works for me, but it is a bit fragile -- notably it is pretty naive
> about how it tests whether "#delimit ;" is in effect. Also, the
> inclusion of the trailing "#delimit cr" is superfluous.
>
> Brendan
Hi Brendan:
I'm wondering if it is even worth watching for the '#delimit ;' command.
For example, you may not be running the whole buffer, rather, you may
be selecting certain lines to run. And, if you come across a ';' that
is not part of a string literal, then it must be a line ending, right?
Thanks,
Rodney
More information about the ESS-help
mailing list