[ESS] Yet another indentation question: indentation after parenthese
Vitalie Spinu
spinuvit at gmail.com
Sat Dec 17 18:15:21 CET 2011
Mathieu Basille <basille at ase-research.org> writes:
> Dear Vitalie,
>
> This is brilliant! I just tested it on simple or more complex lines of
> code, and it works perfectly and smoothly! I don't know yet what are the
> limits or drawbacks of this function, but I really think I will use it a
> lot on functions I write! And it works beautifully in both R and Rnw files,
> as long as a R process is associated with the buffer. By the way, on my
> system, 'indent-region' is bound to 'C-M-\' (not 'C-M-/').
>
Sure, I was confused, it's C-M-\ .
> One last questions, would it be possible to have the function actually
> launch R if no process is available?
>
Yap, here it is:
(defun ess-indent-region-as-R-function (beg end)
(let ((string (replace-regexp-in-string
"\"" "\\\\\\&"
(replace-regexp-in-string ;; how to avoid this double matching?
"\\\\\"" "\\\\\\&" (buffer-substring-no-properties beg end))))
(buf (get-buffer-create "*ess-command-output*")))
(ess-force-buffer-current "Process to load into:")
(ess-command (format "local({oo<-options(keep.source=FALSE);
cat('\n',paste(deparse(parse(text=\"%s\")[[1L]]),collapse='\n'),'\n',sep='')
options(oo)})\n" string) buf)
(with-current-buffer buf
(goto-char (point-max))
;; (skip-chars-backward "\n")
(let ((end (point)))
(goto-char (point-min))
(goto-char (1+ (point-at-eol)))
(setq string (buffer-substring-no-properties (point) end))
))
(delete-region beg end)
(insert string)
))
Cheers,
Vitalie.
More information about the ESS-help
mailing list