[ESS] Easy argument list: r-autoyas

Vitalie Spinu spinuvit.list at gmail.com
Mon Mar 14 13:16:12 CET 2011

"Sven Hartenstein" <lists at svenhartenstein.de> writes:

> Hi Vitalie,
> thanks again for your ideas and contribution to r-autoyas!

Pleased to be useful :), don't have much time to think about improvements
though, but will try to keep an eye on what you do over there.

As one minor comment it might be already useful to pack the code in a
package.  For this you need to just place (provide 'r-autoyas) at the end of
the autoyas.el file. The users will have to download the file and place
(require 'r-autoyas) in .emacs. See
for more details.

(add-hook 'ess-mode-hook
          '(lambda ()
             (load "~/.emacs.d/plugins/r-autoyas.el")))

is not a very standard way of doing it, the hook might be executed hundreds
of times during the session, loading autoyas each time.

You also might consider just telling the users to paste the code in their
.emacs, so they won't have to mess with additional files and loads at all.

>> First, it would be probably more convenient if "(" key would
>> directly invoke the yas/expand.
> Yes, good point. I have changed it now so that the parentheses are not
> part of the snippet. r-autoyas-expand has argument paren (instead of
> no-paren as you suggested) and if it is t parentheses will be
> inserted.
> (Your version was very skeleton-pair friendly, but would delete the
> closing parenthesis if skeleton-pair was not used.)

Yes, that was my way of doing it. In general the following might be more

(define-key ess-mode-map (kbd "(") '(lambda () (interactive)
                                      (insert "(")
                                      (r-autoyas-expand nil t))))

But in this case the closed parenthesis is not automatically inserted.

I think the ideal case would be if r-autoyas-expand would check internally
for "(" and ")" and insert them if needed. And may be
r-autoyas-exit-snippet-delete-remaining to check for closing ")".

>> Second, it is nice to have C-g to delete all the remaining arguments
>> (as you've already suggested on your site). The easiest way I could
>> find is to advise yas/abort-snippet. Please see below.
> Absolutely great! Included in the update.
>> Third, it is inconvenient to maintain both .emacs and .Rprofile, one
>> way of avoiding it is to "inject" the necessary commands each time
>> R-session starts by means of ess-post-run-hook.

One addition here, on slow machines there might be some problems with the
default code  what ess inserts after the  hook (.help.ESS for example). The
following seems to work more reliably:

(defun r-autoyas-inject-commands ()
   "r.autoyas.esc <- function(str) {
   str <- paste('(',str,')', sep='')
   t nil nil t)

> Also perfect! I was actually wondering whether something like this was
> possible and you answered the question before I even asked. Included
> in the update.
> I gratefully mention your full name in the Changelog. How is this for
> you? Would you prefer it any different?

No worries at all, it's open-source isn't it :)

And welcome to the lisp which is amassing and so beautiful language. I am sure
this project will bring you a lot of joy and knowledge.


More information about the ESS-help mailing list