Fix template copy mechanism when template is in other buffer

Forgot to switch buffer when marker in other buffer is given.
This commit is contained in:
Daniel - 2022-10-03 10:11:17 +02:00
parent 12b001221c
commit bc3ab8b901
No known key found for this signature in database
GPG Key ID: 784AA8DF0CCDF625
1 changed files with 20 additions and 19 deletions

View File

@ -924,25 +924,26 @@ it. Adds newline before and after the template."
(save-mark-and-excursion
(let ((template-element (org-with-point-at pom
(org-element-at-point))))
(let ((content-end (org-element-property :contents-end template-element))
current-element
content-begin)
;; Start finding the beginning of the template contents from the top …
(goto-char (org-element-property :contents-begin template-element))
;; … but skip any drawers we may find.
(setq current-element (org-element-at-point))
(while (memq (org-element-type current-element)
'(drawer property-drawer))
(goto-char (org-element-property :end current-element))
(setq current-element (org-element-at-point)))
;; Now we are at the beginning of the contents, let's copy
;; that, but only if it exists and is not empty.
(setq content-begin (org-element-property :begin current-element))
(unless (and content-begin
(< content-begin content-end))
(user-error "Cannot find content in template, or content is empty"))
(string-trim-right
(buffer-substring-no-properties content-begin content-end))))))))
(with-current-buffer (if (markerp pom) (marker-buffer pom) (current-buffer))
(let ((content-end (org-element-property :contents-end template-element))
current-element
content-begin)
;; Start finding the beginning of the template contents from the top …
(goto-char (org-element-property :contents-begin template-element))
;; … but skip any drawers we may find.
(setq current-element (org-element-at-point))
(while (memq (org-element-type current-element)
'(drawer property-drawer))
(goto-char (org-element-property :end current-element))
(setq current-element (org-element-at-point)))
;; Now we are at the beginning of the contents, let's copy
;; that, but only if it exists and is not empty.
(setq content-begin (org-element-property :begin current-element))
(unless (and content-begin
(< content-begin content-end))
(user-error "Cannot find content in template, or content is empty"))
(string-trim-right
(buffer-substring-no-properties content-begin content-end)))))))))
(insert "\n")
(insert body)
(insert "\n")