gmj-insert-item-or-heading.el 894 B

123456789101112131415161718192021222324252627
  1. ;; This buffer is for text that is not saved, and for Lisp evaluation.
  2. ;; To create a file, visit it with ‘C-o’ and enter text in its buffer.
  3. (defun my-org-insert-item-or-heading ()
  4. "Insert a new item or heading
  5. Insert a new item if currently on a line that starts an item,
  6. else insert a new heading.
  7. "
  8. (interactive)
  9. (beginning-of-line)
  10. (skip-chars-forward " \t")
  11. (if (or (looking-at "-") (looking-at "+"))
  12. ;; this handles the case where we are on a line that starts
  13. ;; an item. Ideally, it should detect if we are inside a list,
  14. ;; to allow multi-line list elements.
  15. (progn
  16. (end-of-line)
  17. (if (org-at-item-checkbox-p)
  18. (org-insert-item '(checkbox))
  19. (org-insert-item))
  20. )
  21. (org-insert-heading-respect-content)))
  22. ;; Bind it to something useful
  23. (global-set-key (kbd "C-c i") 'my-org-insert-item-or-heading)