Skip to content

Instantly share code, notes, and snippets.

@liesnikov
Created February 3, 2023 14:58
Show Gist options
  • Save liesnikov/c1e4b7ad834447c32f02faec7a8bede3 to your computer and use it in GitHub Desktop.
Save liesnikov/c1e4b7ad834447c32f02faec7a8bede3 to your computer and use it in GitHub Desktop.
Org-meta-return that is aware of checkboxes and todo headings
(defun org-smart-meta-return (&optional ignore)
"Add new list item, heading or table row with RET."
(interactive "P")
(if ignore
(org-meta-return)
(cond
;; checkboxes
((org-at-item-checkbox-p)
(org-insert-todo-heading nil))
;; lists end with two blank lines, so we need to make sure we are also not
;; at the beginning of a line to avoid a loop where a new entry gets
;; created with only one blank line.
((org-in-item-p)
(if (save-excursion (beginning-of-line) (org-element-property :contents-begin (org-element-context)))
(org-insert-heading)
(beginning-of-line)
(delete-region (line-beginning-position) (line-end-position))
(org-meta-return)))
;; fall-through case
(t
(org-meta-return)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment