about summary refs log tree commit diff stats
path: root/lisp/acdw-org.el
diff options
context:
space:
mode:
authorCase Duckworth2021-04-13 17:45:11 -0500
committerCase Duckworth2021-04-13 17:45:11 -0500
commita64c5ff86998fa3efbff02364376ffd165caba21 (patch)
tree41bc27138a674b8c63950ff9d4d4aa205bdaa250 /lisp/acdw-org.el
parentFormatting etc. (diff)
downloademacs-a64c5ff86998fa3efbff02364376ffd165caba21.tar.gz
emacs-a64c5ff86998fa3efbff02364376ffd165caba21.zip
`org-return-dwim': work in nested lists
`org-return-dwim' now ends a list on an empty nested list item.

See the comment for details.
Diffstat (limited to 'lisp/acdw-org.el')
-rw-r--r--lisp/acdw-org.el44
1 files changed, 27 insertions, 17 deletions
diff --git a/lisp/acdw-org.el b/lisp/acdw-org.el index 7e9fecd..dc85015 100644 --- a/lisp/acdw-org.el +++ b/lisp/acdw-org.el
@@ -79,23 +79,33 @@ appropriate. In tables, insert a new row or end the table."
79 (org-insert-todo-heading nil)) 79 (org-insert-todo-heading nil))
80 80
81 ((org-in-item-p) 81 ((org-in-item-p)
82 ;; Plain list. Yes, this gets a little complicated... 82 ;; Plain list
83 (let ((context (org-element-context))) 83 (let* ((context (org-element-context))
84 (if (or (eq 'plain-list (car context)) ; First item in list 84 (first-item-p (eq 'plain-list (car context)))
85 (and (eq 'item (car context)) 85 (itemp (eq 'item (car context)))
86 (not (eq (org-element-property 86 (emptyp (eq (org-element-property :contents-begin context)
87 :contents-begin context) 87 (org-element-property :contents-end context)))
88 (org-element-property 88 (item-child-p
89 :contents-end context)))) 89 (unpackaged/org-element-descendant-of 'item context)))
90 ;; Element in list item, e.g. a link 90 (message "(or %S (and %S %S) %S)"
91 (unpackaged/org-element-descendant-of 'item context)) 91 first-item-p
92 ;; Non-empty item: Add new item. 92 itemp (not emptyp)
93 (org-insert-item) 93 item-child-p)
94 ;; Empty item: Close the list. 94 ;; The original function from unpackaged just tested the (or ...) test
95 ;; TODO: Do this with org functions rather than operating 95 ;; in this cond, in an if. However, that doesn't auto-end nested
96 ;; on the text. Can't seem to find the right function. 96 ;; lists. So I made this form a cond and added the (and...) test in
97 (delete-region (line-beginning-position) (line-end-position)) 97 ;; the first position, which is clunky (the delete-region... stuff
98 (insert "\n")))) 98 ;; comes twice) and might not be needed. More testing, obviously, but
99 ;; for now, it works well enough.
100 (cond ((and itemp emptyp)
101 (delete-region (line-beginning-position) (line-end-position))
102 (insert "\n\n"))
103 ((or first-item-p
104 (and itemp (not emptyp))
105 item-child-p)
106 (org-insert-item))
107 (t (delete-region (line-beginning-position) (line-end-position))
108 (insert "\n")))))
99 109
100 ((when (fboundp 'org-inlinetask-in-task-p) 110 ((when (fboundp 'org-inlinetask-in-task-p)
101 (org-inlinetask-in-task-p)) 111 (org-inlinetask-in-task-p))