Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanding inside org-mode code blocks (in evil-mode) #1017

Open
DiogoFerrari opened this issue Jul 30, 2019 · 9 comments
Open

Expanding inside org-mode code blocks (in evil-mode) #1017

DiogoFerrari opened this issue Jul 30, 2019 · 9 comments

Comments

@DiogoFerrari
Copy link

Is it possible to make it work inside org-mode code blocks, and use the native (code block language) expansion?

@npostavs
Copy link
Collaborator

npostavs commented Aug 1, 2019

Yes, it's possible. However it currently doesn't work in text-mode blocks for org 9 and above.

#852 (comment)

@DiogoFerrari
Copy link
Author

DiogoFerrari commented Aug 1, 2019

I found out why it isn't expanding. I use evil-mode. If I turn it off, then it works ok and expands natively. If I enable evil-mode, then it stops working. Any clue about how to fix this?

@npostavs
Copy link
Collaborator

npostavs commented Aug 2, 2019

Oh, I'm not sure. All three packages are doing some fancy stuff with the keybindings, so having them interact correctly is tricky.

@jonlee836
Copy link

@DiogoFerrari

evil-mode uses

(indent-according-to-mode) which causes all sorts of unwanted behavior while used in org-mode

https://github.com/emacs-evil/evil/blob/874beba2cb243c325eca08fb7badff567f3c9494/evil-commands.el

@npostavs npostavs changed the title Expanding inside org-mode code blocks Expanding inside org-mode code blocks (in evil-mode) Aug 14, 2019
@mohkale
Copy link

mohkale commented Jan 20, 2020

@DiogoFerrari I'm using evil and I haven't faced any issues. Are you expanding from evil-normal-state or evil-insert-state and could you share what command is run when you press enter?

If it's evil-ret-and-indent try rebinding it to evil-ret or simply nil. In my case return runs newline-and-indent.

@DiogoFerrari
Copy link
Author

Somehow, tab within code blocks triggers org-cycle. If I run yas-expand within the code block, it does nothing, it does not matter the evil state (normal, insert).

When I press enter, it runs evil-ret.

@mohkale
Copy link

mohkale commented Jan 20, 2020

Well the default binding for tab in org-mode is org-cycle; though evil generally overrides it with state based bindings. Though I don't think evil binds anything on the tab key, so it doesn't override it for your states. You may be able to force evil to use yas-expand in insert state by setting <insert-state> <tab>.

for example, with general:

(general-define-key
  :states 'insert
  "<tab>" 'yas-expand)

overrides my global binding of tab and also my org-mode binding of tab.

Alternatively you could consider binding another (less popular) key to yas-expand. I've got it bound to C-i with M-i bound to aya-expand and C-M-i bound to ivy-yasnippet.

If your having issues with the available snippets in org code blocks, you can run org-edit-special to open the block in a new buffer in the same mode as the code being edited. This should guarantee the correct snippets are available (& I believe is the recommended way of editing code blocks).

@mohkale
Copy link

mohkale commented Jan 20, 2020

Can you share a GIF of the issue your having and how running in emacs state doesn't have such an issue. I'm still not quite sure what the problem is.

@jinheebaek
Copy link

jinheebaek commented Feb 5, 2022

I recently had the same issue. I found that tab within code blocks triggered org-cycle, which in turn executes a tab-binded command in org-edit-special buffer. In my case, the problem was that, in this buffer, evil state was changed to the default evil-normal-state, which probably shifted the position of point.

I could fix the issue either by modifying org-babel-do-in-edit-buffer macro to run a command in evil-insert-state, or simply by setting evil-default-state to insert for org-src-mode with (add-hook 'org-src-mode-hook 'evil-insert-state)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants