emacs-ess / ESS

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

Trivial issue with cursor in the inferior mode and evil-mode #1137

Open ghost opened 3 years ago

ghost commented 3 years ago

Hi,

A rather trivial issue with cursor going "backward" when exiting from insert mode to normal if the line is empty. It works as expected in non-empty lines. I have this in my init file:

(add-hook 'inferior-ess-r-mode-hook
          (lambda () (setq-local evil-move-cursor-back nil)))
jabranham commented 3 years ago

@lionel- you use evil-mode, right? Can you reproduce?

ghost commented 3 years ago
Emacs version: GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.14) of 2020-03-26, modified by Debian
Operating System: Ubuntu 20.04.2 LTS (Focal Fossa)
Evil version: 1.14.0
ESS version: 18.10.3
Evil, ESS installation type: using straight

Yes, I use the evil-mode, I'll be honest not sure how to reproduce. Above are details of the installation. Other than that, I run R, go to the inferior mode window, go into the insert mode and type and then Escape. I noticed one thing. It doesn't seem to be about whether the line is empty or not as in my original post, but about whether there is space after the cursor. So, if there is no space then cursor goes back, but if there is space then cursor stays put as I go to the normal mode. So, if I type ls() and the cursor is between the brackets, after escaping it stays where it is, but if the cursor is after the last, closing bracket then escaping makes the cursor jump back. If the line is empty, I can't insert spaces anyway, so escaping makes the cursor jump back and occupy the space between ">" prompt and the "insertable area". So, if I press "i" (go into insert mode) then the cursor is right after ">"; although when I start typing it automatically inserts space after ">". This doesn't happen in shell. I noticed this change in cursor behaviour after one of the updates (not sure which it was, the evil or the ess), a while ago.

lionel- commented 3 years ago

I have the following hooked in inferior-ess-mode-hook. I think this should fix the problem.

;; Set field boundaries in comint
;; See https://stat.ethz.ch/pipermail/ess-help/2001-July/000575.html
(setq-local comint-use-prompt-regexp nil)

;; FIXME: iESS initialises this to `t` for modes configured with `comint-use-prompt-regexp'
(setq-local inhibit-field-text-motion nil)

Maybe we should detect evil usage and set this if detected? Personally I think it should even be the default because it makes iESS behave and feel like a real terminal. Advanced users who want full editability of the process buffer can set comint-use-prompt-regexp to t.

ghost commented 3 years ago

Yep, that fixed it! Thank you so much! Although, it is just aesthetics, it was still a tad annoying :).

lionel- commented 3 years ago

It's not just aesthetics, the default behaviour gets in the way of all linewise operations such as replace-line or copy-line.