org-insert-drawer: Make sure that point is left inside drawer

* lisp/org.el (org-insert-drawer): Leave and reveal point inside
drawer even when we insert property drawer or drawer around region, as
advertised by the docstring.
This commit is contained in:
Ihor Radchenko 2023-08-02 15:42:53 +03:00
parent 83575624ab
commit 345d4e09b5
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 15 additions and 2 deletions

View File

@ -13109,7 +13109,17 @@ Point is left between drawer's boundaries."
(or drawer (read-from-minibuffer "Drawer: ")))))
(cond
;; With C-u, fall back on `org-insert-property-drawer'
(arg (org-insert-property-drawer))
(arg
(org-insert-property-drawer)
(org-back-to-heading-or-point-min t)
;; Move inside.
(re-search-forward org-property-end-re)
(forward-line 0)
(unless (org-element-contents-begin (org-element-at-point))
;; Empty drawer.
(insert "\n")
(forward-char -1))
(org-reveal))
;; Check validity of suggested drawer's name.
((not (string-match-p org-drawer-regexp (format ":%s:" drawer)))
(user-error "Invalid drawer name"))
@ -13146,7 +13156,10 @@ Point is left between drawer's boundaries."
(insert "\n:END:")
(deactivate-mark t)
(indent-for-tab-command)
(unless (eolp) (insert "\n")))
(unless (eolp) (insert "\n"))
;; Leave point inside drawer boundaries.
(search-backward ":END:")
(forward-char -1))
;; Clear marker, whatever the outcome of insertion is.
(set-marker rend nil)))))))