4

I've got auto-complete package working for functions for *.R files, but now I'm struggling with auto-complete for file paths.

I've bound the "TAB" key to:

(global-set-key (kbd "TAB") 'ac-complete-filename)

And it does work after "/" symbol as suggested here. However it works only on new line. As in:

/

And it does not work from within a function such as:

read.table("/...")

Placing pointer after "/" when anything precedes it does not do anything. Any suggestions?

Update:

Changing binding to ess-mode instead of global fixed it. Why? No idea...

(define-key ess-mode-map (kbd "TAB") 'ac-complete-filename)
4
  • Could there have been a pre-existing key-binding for tab in ess-mode? That would have overridden the global key-binding.
    – InHarmsWay
    Aug 16, 2015 at 13:35
  • ac-complete-filename is sort of conditional keybind, that works only after "/" symbol. I wonder how it interferes with other bindings? And after some more struggle with setting up auto-complete, I'm still far off my initial goal. Trying to mimic auto-complete feature as in RStudio. Otherwise switching to emacs will not make any sense.
    – statespace
    Aug 16, 2015 at 15:31
  • Thanks. This solution also worked for me. Now, after typing the "/" symbol, auto complete brings up the file directories. Interestingly, when I'm in the R session within emacs, e.g. iESS [R], file completion works using the standard emacs file completion, but auto-complete also works for functions (this works with or without (define-key ess-mode-map (kbd "TAB") 'ac-complete-filename). This seems to be the best of both worlds. It would be great if someone with a deeper knowledge of ESS could shed some light on how to get this formulation to work for *.R files as well.
    – chandler
    Dec 14, 2016 at 9:37
  • ESS r-mode comes with file-name completion built-in. You shouldn't have to bind ac-complete-filename to anything, as by default ess modifies completion-at-point-functions to work as you want without further configuration. That is, tab completes R objects in code, and completes filenames inside strings, which is what you'd normally want.
    – Tyler
    Jan 13, 2017 at 15:11

1 Answer 1

2

Just in case someone comes across this question; I was able to do this by essentially turning on tab completion from R as follows:

(require 'auto-complete-config)
(ac-config-default)
(define-key ac-completing-map (kbd "M-h") 'ac-quick-help)
;; Get tab completion in R script files
;; See this page here
;; https://stat.ethz.ch/pipermail/ess-help/2013-March/008719.html
;; Make sure that this is after the auto-complete package initialization
(setq  ess-tab-complete-in-script t)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.