reddit / emacs
State of ESS+eglot
cat-head · 2022-11-07 11:01
Recently, I decided to give ESS+eglot another go and was quite surprised by how much better it is than 2 years ago. It mostly just works if I call 'eglot' when working on an R file, and the linting is great (for the most part). There are two things missing, though:
* Automatic file name completion (I can trigger it manually, but it's annoying)
* Variable name completion after $, this one does not seem to work at all
Does anyone know how to fix this?
randdis · 2022-11-07 13:11
I was wondering, is there no conflict between ess and eglot?
cat-head · 2022-11-07 15:54
Other than those two points, non that I can see. So far I'm happy.
Zwzhhh · 2022-11-07 16:44
If you are using company-mode, you can easily get variable name completion by wrting a custom company-backend and add it to your company-backends. Here is what I did ([https://github.com/zhenhua-wang/emacs.d/blob/a045e49faf8f80e1447721726fc1b17b0744051f/lisp/zw-company.el#L94](https://github.com/zhenhua-wang/emacs.d/blob/a045e49faf8f80e1447721726fc1b17b0744051f/lisp/zw-company.el#L94))
For file name completion, you can simply add company-file to your company-backends
Zwzhhh · 2022-11-07 16:48
And make sure your ess-r process is running.
cat-head · 2022-11-07 18:28
when I call eglot, it overwrites the backends and only show company-capf, how do I change this?
Zwzhhh · 2022-11-07 18:32
Ah, that's where I don't like Eglot. You may add hooks to eglot--managed-mode-hook to set up your backends. Or you just use lsp-mode
cat-head · 2022-11-07 18:42
I should have googled `(setq eglot-stay-out-of '(company))` solves it. Thanks for the capf-with-r-objects, it works great!
Zwzhhh · 2022-11-07 18:43
Glad it helped!
JDRiverRun · 2022-11-07 23:03
I use [eglot with corfu](https://github.com/minad/corfu/wiki#configuring-corfu-for-eglot) and [configure additional completion-at-point-functions](https://github.com/minad/corfu/wiki#using-cape-to-tweak-and-combine-capfs), such as cape-file, to give great in-buffer file completion. I also enjoy adding current buffer dabbrev results to completion too.
FreeAd7233 · 2022-11-08 01:29
if you are using cape (together with corfu and corfu-terminal) which can merge different completion at point functions, you can make capf provided sources from both eglot and ESS.
You can `C-h v completion-at-point-functions` to see what is the capf backend provided by eglot and merge them together.
Here is my config to do the similar thing:
https://github.com/milanglacier/.emacs.d/blob/1627d629af4b569974c4928d7d37611607d1cd77/config.el#L586
luiggi_oasis · 2022-11-08 12:36
Is there any guide to get ess and eglot for R up and running? I'm more than happy to drop rstudio for good
cat-head · 2022-11-08 13:21
This is the relevant part of my .emacs.d/init.el:
```
(use-package eglot
:defer t
:commands (eglot eglot-ensure)
:hook
((c-mode . eglot-ensure)
(c++-mode . eglot-ensure)
(ess-mode . eglot-ensure))
:config
(setq eglot-stay-out-of '(company))
(add-to-list 'eglot-server-programs '((c-mode c++-mode) "clangd-10"))
)
(defun company-R-objects--prefix ()
(unless (ess-inside-string-or-comment-p)
(let ((start (ess-symbol-start)))
(when start
(buffer-substring-no-properties start (point))))))
(defun company-R-objects--candidates (arg)
(let ((proc (ess-get-next-available-process)))
(when proc
(with-current-buffer (process-buffer proc)
(all-completions arg (ess--get-cached-completions arg))))))
(defun company-capf-with-R-objects--check-prefix (prefix)
(cl-search "$" prefix))
(defun company-capf-with-R-objects (command &optional arg &rest ignored)
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-R-objects))
(prefix (company-R-objects--prefix))
(candidates (if (company-capf-with-R-objects--check-prefix arg)
(company-R-objects--candidates arg)
(company-capf command arg)))
(annotation (if (company-capf-with-R-objects--check-prefix arg)
"R-object"
(company-capf command arg)))
(kind (if (company-capf-with-R-objects--check-prefix arg)
'field
(company-capf command arg)))
(doc-buffer (company-capf command arg))))
(use-package ess
:ensure nil
:defer t
:commands (list R julia)
:load-path ("/home/matias/Programas/ESS/lisp")
:bind (:map ess-mode-map
("<C-tab>" . company-files)
("<M-tab>" . company-complete-common)
("M-P" . my/add-pipe)
("M-h" . company-show-doc-buffer))
:init
(require 'ess-site)
(setq
ess-nuke-trailing-whitespace-p t
ess-toggle-underscore nil
ess-toggle-S-assign nil
ess-disable-underscore-assign t
;; ess-use-flymake nil
)
(company-posframe-mode 0)
(add-hook 'ess-mode-hook
(lambda()
(make-local-variable 'company-backends)
(setq company-backends '(company-files company-capf-with-R-objects))))
:config
(progn (defalias 'ess-smart-S-assign 'self-insert-command)))
(defun my/add-pipe ()
"Adds a pipe operator %>% with one space to the left and right"
(interactive)
(just-one-space 1)
(insert "%>%")
(just-one-space 1))
```
cat-head · 2022-11-08 13:22
I like it more than rstudio for two reasons. First, I have all my keybindings. Second, I always thought that rstudio has a lot of wasted screen space in the plot section and the objects section, idk, never felt well structured.
CosmicSpittle · 2022-11-21 22:33
Which version of emacs are you using? I am using 28.1 and I get this error:
`Error (use-package): ess/:init: Wrong number of arguments: (3 . 4), 2`
Any idea where to start looking for the issue? (new to emacs and elisp)
cat-head · 2022-11-22 08:53
Which Ess version do you have? The latest version works out of the box with eglot.
CosmicSpittle · 2022-11-22 12:22
ESS 18.10.2
I haven't been able to get it working with 28.1.
cat-head · 2022-11-22 12:53
Try the devel version, it is working fine for me with 28.1. You might need to compile [ESS from source](https://ess.r-project.org/Manual/ess.html#Installing-from-source). Also, share the relevant config for ESS+R in your init.
CosmicSpittle · 2022-11-23 12:33
I'll try the dev version. I added the ESS/R segment of what you posted above to my init.el....I didn't have anything else related to ESS or R. I'll try stripping other packages.
Thanks!