7

In org-mode, the link-following behaviour of RET, that should be present when org-return-follows-link is set, doesn't work in evil-mode.

MWE from emacs -q:

  1. Load an org buffer containing a link. Note that RET is bound to org-ret, but doesn't follow links. [Expected]
  2. Set org-return-follows-link. Hit RET when point is over a link. Emacs follows the link. [Expected]
  3. Enable evil-mode. Note that RET is now bound to evil-ret, and no longer follows links. [Not what I expected]

It makes no difference if evil-mode is enabled before or after we enter org-mode or set org-return-follows-link.

I also tried it with evil-org-mode from https://github.com/Somelauw/evil-org-mode, but that didn't make any difference either. I did notice some code in there that seems to optionally customise the behaviour of the return key according to a "keymap theme", but I didn't seem to be able to make any difference either by playing with that.

So, any idea how I can follow links in org-mode with evil-mode enabled, using RET? I suppose one option is just to override the mapping of RET to be org-ret, but I get the feeling that that will interfere with other uses of the key that evil relies on. Is there a smarter way that these two behaviours should be integrated?

Thanks.

1
  • unbinding RET makes RET, when in normal mode and the point is not on a link, to insert a new line, which is very unexpected. it seems that binding RET to the code below seems to render a more as expected behavior. But I'm not really sure. Anyone suggesting a different approach? (defun foo () (interactive) (if (string= (car (org-thing-at-point)) "link") (org-return) (evil-ret)))
    – ramestica
    Mar 19, 2020 at 1:07

1 Answer 1

6

The easy way out is to unbind RET for Evil as it isn't bound to a useful command anyway. This will let Emacs look it up in keymaps with less priority. You can do the same with SPC and TAB (keep in mind that this is the same as C-i, so maybe not). The following is lifted from my personal setup:

(with-eval-after-load 'evil-maps
  (define-key evil-motion-state-map (kbd "SPC") nil)
  (define-key evil-motion-state-map (kbd "RET") nil)
  (define-key evil-motion-state-map (kbd "TAB") nil))

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.