[ESS] First steps

tyler tyler.smith at mail.mcgill.ca
Fri Jun 26 15:57:39 CEST 2009


baptiste auguie <bapt4510 at googlemail.com> writes:

> I apologize for the really basic questions, but I'm completely new to
> emacs.

Not a problem, but do take a look at the ess manual, which explains some
of these things. From within emacs, you can open the help system (called
info), with `Ctrl-h i'. From there you should see an entry for ESS, or
you can open it directly with `m ess <enter>'.

> i) how do you type the assignment operator <- more efficiently than
> with the 4 keystrokes I just used? (space on both sides)

The underscore key has been rebound to serve this purpose. If you want
an actual underscore, just type two underscores in a row to change the
` <- ' into a `_'. 

> ii) with a comma-separated list (e.g. seq( 1, 3, by=0.1) is there a
> way to get automatic spacing after the commas whilst typing?

One way to do this would be adding the following lines to your .emacs:

(defun my-ess-comma-hook ()
  (local-set-key "," (lambda () (interactive) (insert ", "))))
(add-hook 'ess-mode-hook 'my-ess-comma-hook)
(add-hook 'inferior-ess-mode-hook 'my-ess-comma-hook)

This will replace `,' with `, ' when you're using ESS. It's not very
sophisticated: if you ever want to enter a comma without a space, you'll
have to backspace over the space yourself. I can't think of a time in
ESS that I don't want a space after a comma though, so maybe this is
enough.

> iii) is there a trick to get automatic pairing of open brackets? (say,
> if i type "plot(" i'd like automatic completion with the closing
> bracket ")".

Along the same lines as the code above, you could use this:

(defun my-ess-parens-hook ()
    (local-set-key "(" (lambda () (interactive) 
    		     (insert "(  )")
		     (forward-char -2)))))

(add-hook 'ess-mode-hook 'my-ess-parens-hook)
(add-hook 'inferior-ess-mode-hook 'my-ess-parens-hook)

I'm sure someone else has already created a better way to do this, and
if you use both ideas it would be easier to put them into the same hook,
but you get the idea.

Cheers,

Tyler

-- 
What is wanted is not the will to believe, but the will to find out,
which is the exact opposite.           --Bertrand Russell



More information about the ESS-help mailing list