Skip to content

Instantly share code, notes, and snippets.

@alexozer
Last active November 1, 2018 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexozer/3ed6f09fadf55423ac0d8931b86715e2 to your computer and use it in GitHub Desktop.
Save alexozer/3ed6f09fadf55423ac0d8931b86715e2 to your computer and use it in GitHub Desktop.
(defun ozer/new-org-heading (default-enter)
(if (org-at-heading-p)
;; Enter once will make new heading, twice will clear
(if (eq (org-entry-get nil "ITEM") "")
(evil-change (line-beginning-position) (line-end-position))
;; Insert a new TODO if we're on a TODO
(if (org-get-todo-state)
(org-insert-todo-heading-respect-content)
(org-insert-heading-respect-content)
)
(evil-append 1)
)
;; Do whatever enter normally does
(funcall default-enter)
)
)
(evil-define-key 'normal org-mode-map
(kbd "RET") (lambda () (interactive) (ozer/new-org-heading 'org-open-at-point))
)
(evil-define-key 'insert org-mode-map
(kbd "RET") (lambda () (interactive) (ozer/new-org-heading 'org-return))
)
@alexozer
Copy link
Author

alexozer commented Nov 1, 2018

This makes creating heading pretty easy for someone who doesn't like to press ctrl like me and wants something more closely resembling the ease of bulleted outlines in word processors.

Pressing Enter (in normal or insert mode) while on a heading will insert a new one below. If Enter is pressed again, it will be equivalent to having pressed Enter once with default behavior. If Enter is pressed on a heading with a TODO status, a new TODO heading will be created.

The other org functionality of Enter is left intact (opening links, new table rows, etc).

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