ensure "%?" is present in the template string (#330)

* ensure "%?" is present in the template string

- addresses #298
- fixes `org-capture-place-plain-text` throwing 'invalid search bound'
  when both :unnarowed t and "%?" is missing from the template string

* ensure "%?" is present in the template string

- if "%?" is missing, add it at the end of the template
This commit is contained in:
Mykhailo Shevchuk
2020-03-21 13:56:20 +01:00
committed by GitHub
parent 8b37135aa2
commit 1352809451

View File

@@ -810,15 +810,21 @@ the file if the original value of :no-save is not t and
(new-id (s-trim (org-roam--fill-template (new-id (s-trim (org-roam--fill-template
name-templ name-templ
org-roam--capture-info))) org-roam--capture-info)))
(file-path (org-roam--file-path-from-id new-id))) (file-path (org-roam--file-path-from-id new-id))
(roam-head (or (org-capture-get :head)
org-roam--capture-header-default))
(org-template (org-capture-get :template))
(roam-template (concat roam-head org-template)))
(when (file-exists-p file-path) (when (file-exists-p file-path)
(error (format "File exists at %s, aborting" file-path))) (error (format "File exists at %s, aborting" file-path)))
(org-capture-put :orig-no-save (org-capture-get :no-save)) (org-capture-put :orig-no-save (org-capture-get :no-save))
(org-capture-put :template (org-capture-put :template
(concat ;; Fixes org-capture-place-plain-text throwing 'invalid search bound'
(or (org-capture-get :head) ;; when both :unnarowed t and "%?" is missing from the template string;
org-roam--capture-header-default) ;; may become unnecessary when the upstream bug is fixed
(org-capture-get :template)) (if (s-contains-p "%?" roam-template)
roam-template
(concat roam-template "%?"))
:roam-new-file t :roam-new-file t
:type 'plain :type 'plain
:no-save t) :no-save t)