[ESS] Path completion

James W. MacDonald jmacdon at med.umich.edu
Fri Jul 13 15:50:44 CEST 2007


Thanks Deepayan! That's exactly what I wanted.

Best,

Jim

Deepayan Sarkar wrote:
> On 7/11/07, James MacDonald <jmacdon at med.umich.edu> wrote:
>> Hi,
>>
>>  Using Emacs 22.1 and ESS-5.3.5 on Windows XP, file name completion
>> doesn't work if there are spaces in the path. I see that this issue
>> was raised back in 2005 by Vaidotas Zemlys with no response
>> (https://stat.ethz.ch/pipermail/ess-help/2005-September/002882.html),
>> and also discussed re Debian Sarge
>> (https://stat.ethz.ch/pipermail/ess-help/2005-March/002498.html).
>>
>> So, here is what I am seeing:
>>
>> When editing an *.R file if there are no spaces in the path, Esc Tab
>> will complete the filename. If there are spaces, I get path
>> completion up to where I have typed and an error in the minibuffer
>> saying e.g., 'No completions of Settings/J' when I was trying to
>> complete the path C:/Documents and Settings/Jim. My druthers here
>> would be for Tab to do the completion without having to hit Esc
>> first (and we all know that M-Tab isn't gonna work on Windoze...).
>
> But wouldn't you rather have Tab indent? C-c Tab generally causes object
> completion in an ESS editor buffer (and file completion inside qoutes).
>
>> In an *R* buffer with no spaces in the working directory path, a
>> simple Tab will complete the file name. If there are spaces in the
>> path to the working directory I get the same results as when editing
>> an *.R file.
>>
>> Note that path completion works without problem using
>> ESS/Xemacs. Also, the 'Complete ==> Complete File Name menu item
>> will do the path completion in Emacs (in an inferior R buffer), but
>> if I wanted to keep grabbing my mouse, I would be using Word ;-D.
>>
>> Any suggestions?
>
> A non-ESS solution is to bypass ESS's completion and use rcompgen
> instead.  Since R 2.5.0 rcompgen supports file completion using R's
> Sys.glob() (used on the Windows GUI but disabled on UNIX be default).
> To use it, put the following in your .emacs (after loading ESS):
>
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> ;; use rcompgen in ESS
>
> (defun alt-ess-complete-object-name ()
>
>  (interactive)
>  (ess-make-buffer-current)
>  (let* ((comint-completion-addsuffix nil)
>         (beg-of-line (save-excursion (comint-bol) (point)))
>         (end-of-line (point-at-eol))
>         (line-buffer (buffer-substring beg-of-line end-of-line))
>         (token-string ;; setup, including computation of the token
>          (progn
>            (ess-command (format
> "rcompgen:::.assignLinebuffer('%s')\n" line-buffer))
>            (ess-command (format "rcompgen:::.assignEnd(%d)\n" (-
> (point) beg-of-line)))
>            (car (ess-get-words-from-vector
> "rcompgen:::.guessTokenFromLine()\n"))))
>         (possible-completions ;; compute and retrieve possible 
> completions
>          (progn
>            (ess-command "rcompgen:::.completeToken()\n")
>            (ess-get-words-from-vector 
> "rcompgen:::.retrieveCompletions()\n"))))
>    (or (comint-dynamic-simple-complete token-string
> possible-completions) 'none)))
>
>
> (define-key inferior-ess-mode-map "\t" 'alt-ess-complete-object-name)
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
> and enable file completion in rcompgen, e.g. by putting
>
> rcompgen::rc.settings(file = TRUE)
>
> in your ~/.Rprofile.  This takes over completion with TAB in a *R*
> buffer and C-c TAB in a *.R editor buffer (M-TAB will still force Emacs'
> completion).
>
>
> This should also get rid of the path expansion (for both relative
> paths and ones beginning with ~), which like Ronaldo I find very
> irritating.
>
> -Deepayan



**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues.




More information about the ESS-help mailing list