reddit / emacs
Evil and org tables - what am I missing?
cgrabenstein · 2022-09-06 12:30
A while ago I discovered that my emacs was hanging when trying to edit tables in org-mode. I did some investigation, created a stackoverflow issue ([https://emacs.stackexchange.com/q/72769/38541](https://emacs.stackexchange.com/q/72769/38541)), got help from the org-mode mailing list and eventually created a bug in the evil-repository for what I guess is the root issue for the behaviour ([https://github.com/emacs-evil/evil/issues/1642](https://github.com/emacs-evil/evil/issues/1642)).
It's been a bit more than a month now, and nothing has happened, yet the problem persist for me, even with the latest versions of evil and org-mode. However I can imagine that a lot of users use both, evil and tables in org-mode. And as a consequence, more people should stumble upon "my" issue and report or support it. So that makes me wonder if there is indeed something wrong in my configuration.
As you can see in the stackoverflow issue, there is not a lot minimal configuration needed to reproduce the issue. But could there be any other package, configuration, switch, whatsoever that I could add in my configuration that would solve the issue?
So my question is: **Am I missing something here? Is this actually a problem on my side? Or do other people suffer the same problem, but it has not caught traction yet?**
wasamasa · 2022-09-06 13:03
It's misleading to assume a lot of people have the same environment you do. I'm using built-in Org on Emacs 28.1, so I'm on version 9.5.2 and therefore do not run into the issue.
To not have to ask yourself whether it's a configuration issue on your side, you should always hand in bugs with minimal reproduction instructions. For example this can be done by using a Git checkout of evil, running `make emacs` in it, declining the test suite prompt, loading up Org, then doing the steps in question
From what I've seen your repro is not minimal because it involves evil-leader. Please spend effort on minimizing it so that you can be positive it's indeed an interaction between evil and Org. This includes use-package and straight as well.
edit: Here's how a minimal repro looks like:
- Build Org from Git
- `cd evil`
- `make emacs`
- Answer n
- Evaluate `(add-to-list 'load-path "path/to/org-mode/lisp")` in scratch buffer
- Evaluate `(require 'org)` in scratch buffer
- Verify you're on latest Org with `M-x org-version` (says release_9.5.5-766-ge73c5b for me)
- Switch to a new buffer
- Enable Org with `M-x org-mode`
- Insert the table from https://emacs.stackexchange.com/questions/72769/org-mode-tables-slowed-down-by-evil-mode
- Put cursor on the slash
- Enter insert mode with `i`
- Press `RET`
No hang for me. Do the same and see how it behaves for you. Maybe it's an issue fixed in Org git. Maybe it's an issue in one of the other packages. Maybe you overlooked something, I dunno.
cgrabenstein · 2022-09-06 13:50
Thanks for looking into it. I will try to refine the repro and see if I can find anything else. Having your repro as a blueprint helps a lot!
cgrabenstein · 2022-09-06 16:30
Alright, here's how to reproduce the issue:
* build org from git
* build evil-leader from git
* `cd evil`
* `make emacs`
* answer `n`
* evaluate `(add-to-list 'load-path "path/to/org-mode/lisp")` in scratch buffer
* evaluate `(add-to-list 'load-path "path/to/evil-leader")` in scratch buffer
* evaluate `(require 'org)` in scratch buffer
* evaluate `(require 'evil-leader)` in scratch buffer
* evaluate `(global-evil-leader-mode)` in scratch buffer
* verify you are on latest org with `M-x org-version` (Org mode version 9.5.5 (release\_9.5.5-767-gfe90ca as of writing this)
* switch to a new buffer
* enable org mode with `M-x org-mode`
* enter insert mode with `i`
* write `| 1 | 23 |`
* place your cursor between the 2 and 3
* press `RET`
Hangs for me.
So, my takeaways are:
* the culprit is evil-leader, not evil. Since evil-leader seems rather inactive judging by the latest commits and latest (resolved) issues, I probably got to cut the losses here and move on to general.el or something similar.
* my minimal reproduction on stackoverflow was in fact minimal (despite straight and use-package, but that did not make a difference here). However after confirming with the org mailing list that it was not org-mode that caused the problem, I jumped straight onto evil, ignoring that evil-leader was required for reproduction. In hindsight this should have been a red flag all along, but well.
* And finally another big thank you to u/wasamasa, trying to reproduce the issue, failing and thereby nudging me to having another, even more detailed look into it.
bgcartman · 2022-09-06 17:02
I've always have been having problems with evil and org-tables, this issue sums up the problem pretty nicely [https://github.com/emacs-evil/evil/issues/1623](https://github.com/emacs-evil/evil/issues/1623)
I've tested with pure emacs 27/28 on Linux and Windows with ONLY evil added both from melpa and directly from github , no evil-leader, no general.el. After the maintainer said he "does not have the time/inclination to look into right now" I've even tried bisecting and rolling back evil with the help of git back to commits multiple versions ago with no success.
Currently I'm trying to stick to emacs keyingings but it's really hard (I sprinkle :wq and :q and /s in documents like a madman :) )
wasamasa · 2022-09-06 17:10
Honestly, I do not understand why people use evil-leader in the first place. If you don't mind hardcoding the leader key, just use that key in key bindings as is. If you do mind, you can use `<leader>` in your key bindings and `evil-set-leader` (the documentation explains the details).
Greenskid · 2022-09-06 21:22
Ouch. It would be painful for me to switch from Evil for editing in general. Every now and again I switch to Emacs binding but usually to do a single command. I would rather avoid super long org tables, but hopefully someone will take a look at the issue report and fix things.
yantar92 · 2022-09-07 03:19
See the new comment in the issue. Hope it can help evil devs to fix the problem.
cgrabenstein · 2022-09-07 11:54
Spacemacs uses evil-leader, so when I migrated from spacemacs to my custom config, I adopted it. I don't mind at all hardcoding the key, thanks for that suggestion.
bravosierrasierra · 2022-09-09 17:52
my solution/workaround (see orgtbl-ret call part)
```
(define-key org-mode-map (kbd "<return>") 'bss/my-org-return)
(define-key org-mode-map (kbd "C-m") 'bss/my-org-return)
(defun bss/my-org-return ()
"Insert newline if we at beginng or end of line"
(interactive)
(deactivate-mark)
(cond
(;; ret in org tables
(and (equal major-mode 'org-mode)
(org-at-table-p))
(call-interactively 'orgtbl-ret))
((and (equal major-mode 'org-mode) (org-in-src-block-p))
(org-babel-do-key-sequence-in-edit-buffer (kbd "RET")))
((eq major-mode 'org-mode)
(if (evil-normal-state-p)
(progn ;;we in evil mode
(setq need-return t)
(setq pos (point))
(end-of-line)
(if (> 2 (- (point) pos))
(progn
(evil-open-below 1)
(evil-normal-state)
(setq need-return nil)))
(beginning-of-line)
(if (and (> 1 (- pos (point) )) need-return)
(progn
(evil-open-above 1)
(evil-normal-state)
(setq need-return nil)))
(goto-char pos)
(if need-return (org-return)))
(if (or
(eolp)
(bolp)
)
;; (newline-and-indent)
(newline)
(org-return))))
(t (newline-and-indent))))
```