[ESS] Yet another indentation question: indentation after parenthese

Mathieu Basille basille at ase-research.org
Sat Dec 17 18:53:01 CET 2011


Thanks Vitalie, I love this function! :)

Mathieu.


Le 17/12/2011 12:15, Vitalie Spinu a écrit :
> 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.

-- 

~$ whoami
Mathieu Basille, Post-Doc

~$ locate
Laboratoire d'Écologie Comportementale et de Conservation de la Faune
+ Centre d'Étude de la Forêt
Département de Biologie
Université Laval, Québec

~$ info
http://ase-research.org/basille

~$ fortune
``If you can't win by reason, go for volume.''
Calvin, by Bill Watterson.



More information about the ESS-help mailing list