[ESS] request for comments: completion within .R buffers

Stephen Eglen S.J.Eglen at damtp.cam.ac.uk
Tue Jun 22 15:00:25 CEST 2010


Rodney recently kindly polled ess-help, and a summary of the results can
be seen in the SVN sources at:

https://svn.r-project.org/ESS/trunk/rsn.txt

One thing that came up was (thanks Ista Zhan):

  Function/variable completion in script files (maybe this already is
  supposed to work, but for me completion only works in interactive
  sessions).

Below is some suggested code to implement this, based on a hint from
Deepayan.  If you press TAB at the start of the line, you still get
standard indentation, but if you are already typing something, e.g.
 write.t

then hitting TAB will complete to write.table

Hitting TAB again, will then bring up a *Completions* window showing
(for me):

Possible completions are:
write.table
write.table0

I don't like the *Completions* window hanging around, but apart from
that, is that the sort of completion people would like?  Erik Iverson
mentioned something related:

  I think ESS is very feature complete at this point.  The only thing
  I've looked at that seems interesting is some sort of 'intellisense'
  feature that uses R's built-in completion mechanism to temporarily
  display available completions using something like company-mode,
  autocomplete, or completion-ui.  I had at one point something that
  almost worked, but I believe the library it was built in,
  company-mode, has now changed significantly.

but I've not explored those options.

Code/ideas welcome!

Stephen

----------------------------------------------------------------------

(defun ess-indent-or-complete (&optional whole-exp)
  (interactive "P")
  "Function bound to TAB key in R mode buffers.
If at the start of the line, or numeric prefix provided, call
`ess-indent-command', otherwise try to complete object at point."
  (if (or whole-exp
	   (save-excursion
	     (skip-chars-backward " \t")
	     (bolp)))
      (ess-indent-command whole-exp)
    (ess-complete-object-name)))

(add-hook 'ess-mode-hook
	  '(lambda ()   (local-set-key "\t" 'ess-indent-or-complete)))



More information about the ESS-help mailing list