[ESS] History Expansion

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue Jun 22 21:04:31 CEST 2010


On Tue, Jun 22, 2010 at 5:09 AM, Stephen Eglen
<S.J.Eglen at damtp.cam.ac.uk> wrote:
> 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
> set:
>
> (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
>
> appear.
>
> 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
> function).
>
> Deepayan: does this look okay to you?  Is the special version of 'none
> that you return required by any function?

If it seems to work, it should be fine. I must have just copied this
(without understanding the logic) from ess-complete-object-name (in
ess-inf.el), which ends with

        ;; always return a non-nil value to prevent history expansions
        (or (comint-dynamic-simple-complete  pattern components) 'none))))

-Deepayan


>
> Stephen
>
>
> ;; 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)."
>  (interactive)
>  (ess-make-buffer-current)
>  (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)
>                 "utils:::"
>               "rcompgen:::"))
>         (token-string ;; setup, including computation of the token
>          (progn
>            (ess-command
>             (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
>          (progn
>            (ess-command (concat NS ".completeToken()\n"))
>            (ess-get-words-from-vector
>             (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)
>        nil
>      (or (comint-dynamic-simple-complete token-string
>                                          possible-completions)
>          'none))))
>



More information about the ESS-help mailing list