emacs-ess / ESS

Emacs Speaks Statistics: ESS
https://ess.r-project.org/
GNU General Public License v3.0
617 stars 162 forks source link

Activating emacs-mode [Evil] in inferior-ess-mode fails #365

Closed gujiaxi closed 8 years ago

gujiaxi commented 8 years ago

I use Evil in most modes but I want to use its emacs-state in inferior-ess-mode. For this purpose, I add the following code in my .emacs file as usual:

(evil-set-initial-state 'inferior-ess-mode 'emacs)

Unfortunately, it doesn't work. It is still evil-state, i.e. vim style bindings, in inferior-ess-mode. Is evil invoked inside ESS? How can I enable Emacs state in ESS?

dellison commented 8 years ago

If you kill the inferior ESS buffer and restart it (after evaluating that code), is it still in normal state?

In my .emacs, I do it this way:

(let ((initial-state-emacs-modes '(...
                                   ess-help-mode
                                   inferior-ess-mode
                                   ...)))
  (mapc (lambda (m)
      (evil-set-initial-state m 'emacs))
    initial-state-emacs-modes))

...and that seems to work. But I seem to remember that it only appears to set the evil state you specify when a buffer in that mode is created, and not when you switch to one that already exists.

gujiaxi commented 8 years ago

If you kill the inferior ESS buffer and restart it (after evaluating that code), is it still in normal state?

Yes, it is still in normal state. As comparison, I can easily get into emacs state in inferior-python-mode using the similar method.

Steps to reproduce

  1. In .emacs:

    ;; evil
    (require 'evil)
    (evil-mode t)
    (evil-set-initial-state 'inferior-ess-mode 'emacs)
    ;; ess
    (require 'ess)
    (add-to-list 'auto-mode-alist '("\\.[rR]\\'" . R-mode))
  2. Run Emacs and do M-x R to start a inferior-ess-mode buffer.
  3. It is in evil normal state instead of emacs state in this buffer.
lionel- commented 8 years ago

That's because ESS is not written in terms of proper modes. So the mode initialisation does not follow Emacs conventions because everything is done manually. In particular, after-change-major-mode-hook is not run.

There is a long-term plan to rewrite ESS with derived modes. We could add the proper run-hooks at the end of inferior-ess-mode though. Do you see any unintended side effects to this @vspinu?

In the meantime, one workaround for your problem is to add comint to the Emacs initial state. May I ask why you don't keep it in Evil state? With these hooked in inferior-ess-mode-hook, I personally think Evil is more usable:

 (setq-local comint-use-prompt-regexp nil)
 (setq-local inhibit-field-text-motion nil)
gujiaxi commented 8 years ago

@lionel- Thanks, comint way works like a charm.