fix(org): parity for headlines & items in +org--insert-item
This commit is contained in:
parent
4cc82bb32a
commit
26040c6fc1
1 changed files with 25 additions and 14 deletions
|
@ -30,20 +30,31 @@
|
||||||
(pcase (org-element-type context)
|
(pcase (org-element-type context)
|
||||||
;; Add a new list item (carrying over checkboxes if necessary)
|
;; Add a new list item (carrying over checkboxes if necessary)
|
||||||
((or `item `plain-list)
|
((or `item `plain-list)
|
||||||
;; Position determines where org-insert-todo-heading and org-insert-item
|
(let* ((item
|
||||||
;; insert the new list item.
|
(if (eq 'item (org-element-type context))
|
||||||
(if (eq direction 'above)
|
context
|
||||||
(org-beginning-of-item)
|
;; if the context has type `plain-list', find closest item
|
||||||
(org-end-of-item)
|
(let ((struct (org-element-property :structure context)))
|
||||||
(backward-char))
|
(save-excursion
|
||||||
(org-insert-item (org-element-property :checkbox context))
|
(goto-char
|
||||||
;; Handle edge case where current item is empty and bottom of list is
|
(if (= (point) (org-element-property :begin context))
|
||||||
;; flush against a new heading.
|
;; at the begin of the plain-list, we get the list and
|
||||||
(when (and (eq direction 'below)
|
;; not the item with `org-element-at-point'
|
||||||
(eq (org-element-property :contents-begin context)
|
(1+ (car (car struct)))
|
||||||
(org-element-property :contents-end context)))
|
(1+ (car (car (last struct))))))
|
||||||
(org-end-of-item)
|
(org-element-at-point)))))
|
||||||
(org-end-of-line)))
|
(begin (org-element-property :begin item))
|
||||||
|
(end (org-element-property :end item))
|
||||||
|
(cnts-begin (org-element-property :contents-begin item))
|
||||||
|
(str (string-trim (buffer-substring begin (or cnts-begin end)) "\n+" "[ \t\r\n]+")))
|
||||||
|
(pcase direction
|
||||||
|
(`below
|
||||||
|
(goto-char (max (1- end) (line-end-position)))
|
||||||
|
(insert "\n" str " "))
|
||||||
|
(`above
|
||||||
|
(goto-char (line-beginning-position))
|
||||||
|
(insert str " ")
|
||||||
|
(save-excursion (insert "\n"))))))
|
||||||
|
|
||||||
;; Add a new table row
|
;; Add a new table row
|
||||||
((or `table `table-row)
|
((or `table `table-row)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue