lang/org: fix M-RET not adjusting number bullets #390
This commit is contained in:
parent
e0fd1b9043
commit
53b7297c6d
1 changed files with 30 additions and 15 deletions
|
@ -174,26 +174,41 @@ I use this instead of `org-insert-item' or `org-insert-heading' which are too
|
||||||
opinionated and perform this simple task incorrectly (e.g. whitespace in the
|
opinionated and perform this simple task incorrectly (e.g. whitespace in the
|
||||||
wrong places)."
|
wrong places)."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((context (org-element-lineage
|
(let* ((context
|
||||||
(org-element-context)
|
(save-excursion
|
||||||
'(table table-row headline inlinetask item plain-list)
|
(when (bolp)
|
||||||
t))
|
(back-to-indentation)
|
||||||
|
(forward-char))
|
||||||
|
(org-element-lineage
|
||||||
|
(org-element-context)
|
||||||
|
'(table table-row headline inlinetask item plain-list)
|
||||||
|
t)))
|
||||||
(type (org-element-type context)))
|
(type (org-element-type context)))
|
||||||
(cond ((memq type '(item plain-list))
|
(cond ((memq type '(item plain-list))
|
||||||
(let ((marker (org-element-property :bullet context))
|
(let ((marker (org-element-property :bullet context))
|
||||||
(pad (save-excursion
|
(pad (save-excursion
|
||||||
(back-to-indentation)
|
(back-to-indentation)
|
||||||
(- (point) (line-beginning-position)))))
|
(- (point) (line-beginning-position))))
|
||||||
(pcase direction
|
afterp)
|
||||||
('below
|
(save-match-data
|
||||||
(org-end-of-item)
|
(pcase direction
|
||||||
(goto-char (line-beginning-position))
|
('below
|
||||||
(insert (make-string pad 32) (or marker ""))
|
(org-end-of-item)
|
||||||
(save-excursion (insert "\n")))
|
(backward-char)
|
||||||
('above
|
(org-end-of-line)
|
||||||
(goto-char (line-beginning-position))
|
(if (and marker (string-match "\\([0-9]+\\)\\([).] *\\)" marker))
|
||||||
(insert (make-string pad 32) (or marker ""))
|
(let ((l (line-number-at-pos)))
|
||||||
(save-excursion (insert "\n")))))
|
(org-insert-item)
|
||||||
|
(when (= l (line-number-at-pos))
|
||||||
|
(org-next-item)
|
||||||
|
(org-end-of-line)))
|
||||||
|
(insert "\n" (make-string pad 32) (or marker ""))))
|
||||||
|
('above
|
||||||
|
(goto-char (line-beginning-position))
|
||||||
|
(if (and marker (string-match-p "[0-9]+[).]" marker))
|
||||||
|
(org-insert-item)
|
||||||
|
(insert (make-string pad 32) (or marker ""))
|
||||||
|
(save-excursion (insert "\n")))))))
|
||||||
(when (org-element-property :checkbox context)
|
(when (org-element-property :checkbox context)
|
||||||
(insert "[ ] ")))
|
(insert "[ ] ")))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue