[ESS] History Expansion

Stephen Eglen S.J.Eglen at damtp.cam.ac.uk
Tue Jun 22 14:09:01 CEST 2010

Stephen Eglen <S.J.Eglen at damtp.cam.ac.uk> wrote:

> hi Martin,
> it used to work (many years ago) and is documented in 
> our manual:
> 4.6 References to historical commands

Yes, this is a bug related to the new completion facilities.  If you

(setq ess-use-R-completion nil)

and then in R, do

> x = 20

and then type at the next prompt

> !x SPC TAB

you should see 

> x = 20 


The fix is that ess-R-complete-object-name should return nil if
there are no possible completions; so that other functions listed in 
comint-dynamic-complete-functions (in this case,
comint-replace-by-expanded-history) can work.  Here is a revised
version, that I've checked in to SVN (see last comment at end of

Deepayan: does this look okay to you?  Is the special version of 'none
that you return required by any function?


;; From Jim (James W.) MacDonald, based on code by Deepayan Sarkar,
;; originally named  'alt-ess-complete-object-name'.
;; Use rcompgen in ESS
;; Can be activated by something like
;; (define-key inferior-ess-mode-map "\t" 'ess-R-complete-object-name)
(defun ess-R-complete-object-name ()
  "Completion in R via R's completion utilities (formerly 'rcompgen').
To be used instead of ESS' completion engine for R versions >= 2.5.0
 (or slightly older versions of R with an attached and working 'rcompgen' package)."
  (let* ((comint-completion-addsuffix nil)
	 (beg-of-line (save-excursion (comint-bol nil) (point)))
	 (end-of-line (point-at-eol))
	 (line-buffer (buffer-substring beg-of-line end-of-line))
	 (NS (if (ess-current-R-at-least '2.7.0)
	 (token-string ;; setup, including computation of the token
	     (format (concat NS ".assignLinebuffer('%s')\n") line-buffer))
	    (ess-command (format (concat NS ".assignEnd(%d)\n")
				 (- (point) beg-of-line)))
	    (car (ess-get-words-from-vector
		  (concat NS ".guessTokenFromLine()\n")))))

	 (possible-completions ;; compute and retrieve possible completions
	    (ess-command (concat NS ".completeToken()\n"))
	     (concat NS ".retrieveCompletions()\n")))))

    ;; If there are no possible-completions, should return nil, so
    ;; that when this function is called from
    ;; comint-dynamic-complete-functions, other functions can then be
    ;; tried.
    (if (null possible-completions)
      (or (comint-dynamic-simple-complete token-string

More information about the ESS-help mailing list