0

I try to get a practical development environment for R in Emacs, hoping to get auto-completion working as shown in http://www.emacswiki.org/emacs/ESSAuto-complete.

However, even in a minimal configuration, I can't get it working.

See what I get on http://screencast.com/t/qcyVwkECX. In fact, while AC does work (see completion menu appearing), it's like if there was no info from the R language itself, while ac-source-R is WELL added to ac-sources.

Do you understand what's happening?

Best regards.

PS- Here is my minimal Emacs configuration file for the demo:

;; Auto Completion
(add-to-list 'load-path "~/.emacs.d/elpa/auto-complete-20140824.1658/")
(add-to-list 'load-path "~/.emacs.d/elpa/popup-20140815.629/")
(when (require 'auto-complete-config)

(ac-config-default)

;; use `C-n/C-p' to select candidates
(setq ac-use-menu-map t)
(define-key ac-menu-map (kbd "C-n") 'ac-next)
(define-key ac-menu-map (kbd "C-p") 'ac-previous)

;; unbind some keys (inconvenient in iESS buffers)
(define-key ac-completing-map (kbd "M-n") nil)
(define-key ac-completing-map (kbd "M-p") nil)

;; set default sources
(setq ac-sources
      (append '(ac-source-features
        ac-source-functions
        ac-source-yasnippet
        ac-source-variables
        ac-source-symbols)
          ac-sources))

(setq ac-delay 0)               ; faster than default 0.1
(setq ac-auto-show-menu 0.2)
(setq ac-quick-help-delay 0.5)
(setq ac-quick-help-height 10)
(setq ac-candidate-limit 100)

;; completion by TAB
(define-key ac-completing-map
  (kbd "<tab>") 'ac-complete)

;; avoid Flyspell processes when auto completion is being started
(ac-flyspell-workaround))

;; ESS: Emacs Speaks Statistics
(add-to-list 'load-path "~/.emacs.d/elpa/ess-20140824.1452/lisp/")

  (setq shell-file-name "zsh.exe")

(add-to-list 'auto-mode-alist '("\\.[rR]\\'" . R-mode))

(autoload 'R "ess-site" "Call 'R', the 'GNU S' system from the R Foundation." t)
(autoload 'R-mode "ess-site" "Major mode for editing R source." t)

(setq ess-ask-for-ess-directory nil)
(setq inferior-ess-same-window nil)
(setq ess-default-style 'DEFAULT)

(with-eval-after-load "ess-site"

  ;; use eldoc to report R function names
  (require 'ess-eldoc)
  (add-hook 'inferior-ess-mode-hook 'ess-use-eldoc))

PPS- In fact, ElDoc does not seem to work either!

UPDATE

  1. I just discovered it almost works when the iESS buffer gets created, not when just editing R code in its own buffer. See http://screencast.com/t/fKRjLmIC6K0.

    What would explain that iESS must be run first before it finally works?

  2. Still, something that does not work is the completion on function arguments (like with the cat function on the page http://www.emacswiki.org/emacs/ESSAuto-complete).

    Why does that not work?

user3341592
  • 1,419
  • 1
  • 17
  • 36
  • ess-use-auto-complete is t (by default). – user3341592 Aug 27 '14 at 12:07
  • Do you have an R process running and associated with the buffer you're editing? Anything in *Messages*? – otsaw Aug 27 '14 at 12:47
  • No, as written in the UPDATE, I did not have an iESS buffer. – user3341592 Aug 27 '14 at 13:46
  • Though, even if this is a feature, that still leaves me with the problem #2. – user3341592 Aug 27 '14 at 13:46
  • Are you sure you have `ac-source-R-args` in `ac-sources`? – otsaw Aug 27 '14 at 14:31
  • `ac-source-R-args` is not necessary; `ac-source-R` should do the job. In order to see a completion you must first type something. In case of 'cat' type 'fi' to get "file = ' completion. You should be able to see all the arguments in the minibufer anyways. – VitoshKa Aug 27 '14 at 16:39
  • OK if I type the first characters of the argument. This is not what I thought when looking at the first screenshot of http://www.emacswiki.org/emacs/ESSAuto-complete (there, you have completion after the first paren). Thanks a lot for your help! – user3341592 Aug 28 '14 at 20:02
  • Sub-question: do you know how to param the fact that the completion will be "file=..." (as on http://www.emacswiki.org/emacs/ESSAuto-complete) instead of "file = ..."? – user3341592 Aug 28 '14 at 20:02

1 Answers1

0

After opening a R file with emacs, if you have this mode described into your emacs status bar:

(ESS[S] [none] ElDoc AS)

You can run this shortcut C-c C-s to attach a R session to you ESS[S] editor mode.

If you already have one or some R session open, emacs will ask you to choose the R session you want to use. Otherwise if you have not already open a R session then emacs will open a new one for you.

Next, you should have this information inside your status bar:

(ESS[S] [R db -] ElDoc AS)

and the completion should work.