None of the answers met my needs. So it can help other people. I wanted Tab jump to the beginning of the line if I'm in the normal Evil mode (basically: this means everywhere in Emacs), but instead I wanted it to switch between the org item states if I had an org-mode document.
One option was to combine with individual bindings and a constant binding binding when I switched buffers (because evil allows only one binding on a key in its normal state).
But a more efficient option was to make Tab run my own code, which runs the required function based on the main mode that uses the current buffer. Therefore, if I am in the org buffer, this code runs org-cycle , and otherwise it runs evil-first-non-blank (go to the first evil-first-non-blank character in the string).
The technique used here can also be used by calling your user-defined function via global-set-key instead for people who use regular non-evil Emacs.
For those who don’t know Emacs lisp, the first line after the if statement is a true action, and the line after that is a false action. Therefore, if major-mode is equal to org-mode , we run org-cycle , otherwise we run evil-first-non-blank in all other modes:
(defun my/tab-jump-or-org-cycle () "jumps to beginning of line in all modes except org mode, where it cycles" (interactive) (if (equal major-mode 'org-mode) (org-cycle) (evil-first-non-blank)) ) (define-key evil-normal-state-map (kbd "<tab>") 'my/tab-jump-or-org-cycle)
buggy3 Dec 10 '16 at 20:31 2016-12-10 20:31
source share