reddit / emacs

How do you replicate Doom's tab key behavior using Evil in Org-Mode

dargscisyhp · 2022-05-23 16:28
When I'm editing an Org file using Doom Emacs in insert mode and my cursor is on the line of a heading, the Tab key seems to demote the heading while Shift-Tab seems to promote the heading. On the other hand, in my personal config the Tab key in insert mode on a heading line seems to have behavior that is context dependent. For instance, if I have a single heading and nothing else in my org document the tab key seems to do nothing in insert mode. On the other hand, if I have multiple headings the tab key seems to cycle through several different heading levels, from one deeper than my previous deepest level, all the way up to the outermost level. In both my personal config and my Doom config, tab seems to be bound to org-cycle in insert mode. The values for the variables org-cycle-level-after-item/entry-creation and org-cycle-emulate-tab are identical for both my personal session and my doom session. I don't really understand how to dig deeper into what might be causing this discrepancy in behavior between the two different sessions of Emacs. I really like Doom's tab behavior, and would like to replicate it in my personal config. If anyone has any ideas on how I should go about understanding this better and achieving my desired config I'd appreciate it.
HeyItsLP · 2022-05-23 19:18
I suggest trying the Doom Emacs [discord server.](https://discord.gg/qvGgnVx)
TunaCowboy · 2022-05-23 19:27
I don't use doom, and I'm too lazy to try and reproduce your issue, but have you looked here (comment on line 836 specifically)? https://github.com/doomemacs/doomemacs/blob/master/modules/lang/org/config.el [Sage advice from the `gawk` manual.] (https://www.gnu.org/software/gawk/manual/html_node/Undocumented.html#Undocumented)
[deleted] · 2022-05-23 19:34
[deleted]
dargscisyhp · 2022-05-23 19:35
I did check there, and Tab was indeed bound to org-cycle. Helpful-key shows org-cycle being invoked in both sessions of Emacs.
TunaCowboy · 2022-05-23 19:44
Just throwing this at the wall, have you added the hook on line 828 to your personal config? If you haven't already you might consider reviewing doom further for org/tab related configs and/or debugging each config and look for org related discrepancies. https://orgmode.org/worg/doc.html > Hook for functions to attach themselves to TAB. See `org-ctrl-c-ctrl-c-hook` for more information. This hook runs as the first action when TAB is pressed, even before `org-cycle` messes around with the `outline-regexp` to cater for inline tasks and plain list item folding. If any function in this hook returns t, any other actions that would have been caused by TAB (such as table field motion or visibility cycling) will not occur. If it was me I'd throw a question in the discord as /u/HeyItsLP suggested and dig around in doom.
dargscisyhp · 2022-05-23 21:09
I'm embarrassed to admit that this is exactly what it was, as it was just a half-dozen lines above where I was looking. Thanks for pointing this out. For future reference, if I don't know that a hook exists for something like pressing tab, how would I know to look for it? Is there a systematic way to go about diagnosing this kind of thing?
_viz_ · 2022-05-24 06:32
The apropos family of commands is useful for finding things when you have a vague idea. Or, you can just read the source code of the command that TAB runs and see if it runs a hook at any point.
bartalemous · 2022-06-20 13:36
I had the same issue and it was bothering me. Based on u/TunaCowboy detective work, I found out the culprit for the behaviour is indeed `org-tab-first-hook`. `describe-symbol` on `org-tab-first-hook` returns `+org-yas-expand-maybe-h +org-indent-maybe-h org-babel-hide-result-toggle-maybe org-babel-header-arg-expand +org-clear-babel-results-h +org-cycle-only-current-subtree-h` Second in the list is a `+org-indent-maybe-h` and that is the one. If you `(setq org-tab-first-hook '(.......)'` without it, you will notice the TAB functions normally.