0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-29 21:37:50 +00:00

Fix capturing plain text with :unnarrowed property and no "%?" marker

* lisp/org-capture.el (org-capture-narrow): Remove undocumented point
move.
(org-capture--position-cursor): New function.
(org-capture-place-entry):
(org-capture-place-item):
(org-capture-place-table-line):
(org-capture-place-plain-text): Use new function.
* testing/lisp/test-org-capture.el (test-org-capture/plain): Add test.

Reported-by: No Wayman <iarchivedmywholelife@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2020-05/msg00095.html>
This commit is contained in:
Nicolas Goaziou 2020-05-07 22:35:13 +02:00
parent f4fed7ea0c
commit 09086b7e75
2 changed files with 23 additions and 14 deletions

View file

@ -1152,9 +1152,7 @@ may have been stored before."
(unless (org-at-heading-p) (outline-next-heading))
(org-capture-mark-kill-region origin (point))
(org-capture-narrow beg (point))
(when (or (search-backward "%?" beg t)
(search-forward "%?" nil t))
(replace-match ""))))))
(org-capture--position-cursor beg (point))))))
(defun org-capture-place-item ()
"Place the template as a new plain list item."
@ -1266,9 +1264,7 @@ may have been stored before."
;; not narrow at the beginning of the next line, possibly
;; altering its structure (e.g., when it is a headline).
(org-capture-narrow beg (1- end))
(when (or (search-backward "%?" beg t)
(search-forward "%?" end t))
(replace-match ""))))))
(org-capture--position-cursor beg end)))))
(defun org-capture-place-table-line ()
"Place the template as a table line."
@ -1350,9 +1346,7 @@ may have been stored before."
;; TEXT is guaranteed to end with a newline character. Ignore
;; it when narrowing so as to not alter data on the next line.
(org-capture-narrow beg (1- end))
(when (or (search-backward "%?" beg t)
(search-forward "%?" end t))
(replace-match ""))))))
(org-capture--position-cursor beg (1- end))))))
(defun org-capture-place-plain-text ()
"Place the template plainly.
@ -1387,9 +1381,7 @@ Of course, if exact position has been required, just put it there."
(org-capture-empty-lines-after)
(org-capture-mark-kill-region origin (point))
(org-capture-narrow beg end)
(when (or (search-backward "%?" beg t)
(search-forward "%?" end t))
(replace-match ""))))))
(org-capture--position-cursor beg end)))))
(defun org-capture-mark-kill-region (beg end)
"Mark the region that will have to be killed when aborting capture."
@ -1435,8 +1427,15 @@ Of course, if exact position has been required, just put it there."
(defun org-capture-narrow (beg end)
"Narrow, unless configuration says not to narrow."
(unless (org-capture-get :unnarrowed)
(narrow-to-region beg end)
(goto-char beg)))
(narrow-to-region beg end)))
(defun org-capture--position-cursor (beg end)
"Move point to first \"%?\" location or at start of template.
BEG and END are buffer positions at the begging and end position
of the template."
(goto-char beg)
(when (search-forward "%?" end t)
(replace-match "")))
(defun org-capture-empty-lines-before (&optional n)
"Set the correct number of empty lines before the insertion point.

View file

@ -742,6 +742,16 @@
`(("t" "Text" plain (file ,file) ""
:immediate-finish t))))
(org-capture nil "t")
(buffer-string)))))
;; Test :unnarrowed property without a "%?" marker.
(should
(equal "SUCCESS\n"
(org-test-with-temp-text-in-file ""
(let* ((file (buffer-file-name))
(org-capture-templates
`(("t" "Text" plain (file ,file) "SUCCESS"
:unnarrowed t :immediate-finish t))))
(org-capture nil "t")
(buffer-string))))))
(provide 'test-org-capture)