mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-03 12:27:26 -05:00
fix(org): multiple fixes for +org--insert-item
There are multiple problems with the previous version of `+org--insert-item', e.g. the labels of ordered lists were not updated and it also made a difference if the point is before or after the bullet. This commit fixes this behavior, but uses a horrible hack. For the edge case of an empty item, it inserts a no-break space momentarily, so that `org-insert-item' does the right thing.
This commit is contained in:
committed by
GitHub
parent
48658d2136
commit
2d108e14a2
@ -30,32 +30,40 @@
|
|||||||
(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)
|
||||||
(let* ((item
|
(let ((orig-point (point)))
|
||||||
(if (eq 'item (org-element-type context))
|
;; Position determines where org-insert-todo-heading and `org-insert-item'
|
||||||
context
|
;; insert the new list item.
|
||||||
;; if the context has type `plain-list', find closest item
|
(if (eq direction 'above)
|
||||||
(let ((struct (org-element-property :structure context)))
|
(org-beginning-of-item)
|
||||||
(save-excursion
|
(end-of-line))
|
||||||
(goto-char
|
(let* ((ctx-item? (eq 'item (org-element-type context)))
|
||||||
(if (= (point) (org-element-property :begin context))
|
(ctx-cb (org-element-property :contents-begin context))
|
||||||
;; at the begin of the plain-list, we get the list and
|
;; Hack to handle edge case where the point is at the
|
||||||
;; not the item with `org-element-at-point'
|
;; beginning of the first item
|
||||||
(1+ (car (car struct)))
|
(beginning-of-list? (and (not ctx-item?)
|
||||||
(1+ (car (car (last struct))))))
|
(= ctx-cb orig-point)))
|
||||||
(org-element-at-point)))))
|
(item-context (if beginning-of-list?
|
||||||
(begin (org-element-property :begin item))
|
(org-element-context)
|
||||||
(end (org-element-property :end item))
|
context))
|
||||||
(cnts-begin (org-element-property :contents-begin item))
|
;; Horrible hack to handle edge case where the
|
||||||
(str (string-trim (buffer-substring begin (or cnts-begin end)) "\n+" "[ \t\r\n]+")))
|
;; line of the bullet is empty
|
||||||
(pcase direction
|
(ictx-cb (org-element-property :contents-begin item-context))
|
||||||
(`below
|
(empty? (and (eq direction 'below)
|
||||||
(goto-char (max (1- end) (line-end-position)))
|
;; in case contents-begin is nil, or contents-begin
|
||||||
(insert "\n" str " "))
|
;; equals the position end of the line, the item is
|
||||||
(`above
|
;; empty
|
||||||
(goto-char (line-beginning-position))
|
(or (not ictx-cb)
|
||||||
(insert str " ")
|
(= ictx-cb
|
||||||
(save-excursion (insert "\n"))))))
|
(1+ (point))))))
|
||||||
|
(pre-insert-point (point)))
|
||||||
|
;; Insert dummy content, so that `org-insert-item'
|
||||||
|
;; inserts content below this item
|
||||||
|
(when empty?
|
||||||
|
(insert " "))
|
||||||
|
(org-insert-item (org-element-property :checkbox context))
|
||||||
|
;; Remove dummy content
|
||||||
|
(when empty?
|
||||||
|
(delete-region pre-insert-point (1+ pre-insert-point))))))
|
||||||
;; Add a new table row
|
;; Add a new table row
|
||||||
((or `table `table-row)
|
((or `table `table-row)
|
||||||
(pcase direction
|
(pcase direction
|
||||||
|
Reference in New Issue
Block a user