From 0e2ffd584aafdd4cf256bcdf2473f01c3aaaed55 Mon Sep 17 00:00:00 2001 From: Amin Bandali Date: Thu, 23 Aug 2018 12:42:39 -0400 Subject: [PATCH] [emacs] work around org source block indentation issue with evil MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit happens due to (setq org-src-tab-acts-natively t) another less-elegant workaround is to unbind TAB: (define-key evil-motion-state-map (kbd "TAB") nil) --- excerpt of conversation with wasamasa on #evil-mode about the issue: │12:15:00 aminb | wasamasa: mannaged to pinpoint the cause: │12:15:05 aminb | i had (setq org-src-tab-acts-natively t) in my config │12:15:22 wasamasa | what does that do? │12:15:23 aminb | which, for some reason, messes with indentation, and it only happens when evil is enabled │12:15:26 aminb | give it a shot │12:15:43 aminb | Documentation: │12:15:43 aminb | If non-nil, the effect of TAB in a code block is as if it were │12:15:43 aminb | issued in the language major mode buffer. │12:15:57 wasamasa | sounds magic │12:16:11 aminb | i can't notice any difference, at least not with emacs-lisp blocks │12:16:23 aminb | except that it fucks with evil somehow │12:19:12 wasamasa | ah, now I get fun behavior │12:19:19 wasamasa | unless I unbind C-i :P │12:20:56 aminb | wasamasa: :p so if you unbind C-i, indentation works fine even with that var set? │12:21:28 wasamasa | I suspect that's why it works normally in my customized session, as opposed to the minimal one (where the block is indented with two spaces for each line) │12:21:57 aminb | hmm │12:22:11 wasamasa | ok, it's a bit more complicated │12:22:35 wasamasa | org looks up the command for the pressed key (evil-jump-forward), executes that in the buffer, then does reformatting │12:22:56 wasamasa | evil-jump-forward does no indentation, but the reformatting adds indentation unless you customized that │12:23:10 wasamasa | which I did │12:23:16 aminb | ha │12:23:20 aminb | is there anyway to 'fix' this? │12:23:22 wasamasa | I also unbound TAB and bound C-i separately from that │12:23:24 wasamasa | well, not really │12:23:49 aminb | hm okay │12:23:49 wasamasa | org tries to do the smart thing, but didn't anticipate there's evil where keybindings resolve to something different depending on the state │12:24:14 aminb | right │12:26:02 wasamasa | try (define-key evil-motion-state-map (kbd "TAB") nil) │12:26:29 wasamasa | but as noted, that will kill C-i │12:27:47 aminb | wasamasa: yup, that seems to do it │12:27:50 wasamasa | looking at the source of org-babel-do-in-edit-buffer you could do some hack so that the edit buffer comes up in insert state │12:28:04 wasamasa | then TAB would be looked up correctly │12:29:10 aminb | i see │12:42:41 wasamasa | well indeed, try (add-hook 'org-src-mode-hook 'evil-insert-state) (excerpt included with permission) --- init.org | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/init.org b/init.org index c7181f4..2374cac 100644 --- a/init.org +++ b/init.org @@ -639,7 +639,8 @@ customizing it. #+begin_src emacs-lisp (use-package evil :demand t - :hook (view-mode . evil-motion-state) + :hook ((view-mode . evil-motion-state) + (org-src-mode . evil-insert-state)) :init (setq evil-want-integration nil) :config (evil-mode 1) -- 2.20.1