From d28a83c99263c70d4de3968469cbcfc5b9076182 Mon Sep 17 00:00:00 2001 From: Jethro Kuan Date: Fri, 13 Mar 2020 18:13:04 +0800 Subject: [PATCH] (bugfix): fix unintuitive behaviour of capture insertion (#293) Ref #285 --- CHANGELOG.md | 4 ++++ org-roam.el | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45181c8..1712860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ * [#289][gh-289] Add customizable `org-roam-fuzzy-match` to allow fuzzy-matching of candidates * [#290][gh-290] Add `org-roam-date-title-format` and `org-roam-date-filename-format` for customizing Org-roam's date files +## Bugfixes +* [#293][gh-293] Fix capture templates not working as expected for `org-roam-find-file` + ## 1.0.0-rc1 (06-03-2020) This is a pre-release before the push to MELPA. It contains large @@ -137,6 +140,7 @@ Mostly a documentation/cleanup release. [gh-284]: https://github.com/jethrokuan/org-roam/pull/284 [gh-289]: https://github.com/jethrokuan/org-roam/pull/289 [gh-290]: https://github.com/jethrokuan/org-roam/pull/290 +[gh-293]: https://github.com/jethrokuan/org-roam/pull/293 # Local Variables: # eval: (auto-fill-mode -1) diff --git a/org-roam.el b/org-roam.el index 009550c..811b403 100644 --- a/org-roam.el +++ b/org-roam.el @@ -870,7 +870,8 @@ If PREFIX, downcase the title before insertion." (insert (format "[[%s][%s]]" link-location description)) - (setq org-roam--capture-insert-point (point)))))) + (setq org-roam--capture-insert-point (point)))) + (add-hook 'org-capture-after-finalize-hook #'org-roam--capture-advance-point))) (defun org-roam--capture-advance-point () "Advances the point if it is updated. @@ -881,9 +882,8 @@ point moves some characters forward. This is added as a hook to `org-capture-after-finalize-hook'." (when org-roam--capture-insert-point (goto-char org-roam--capture-insert-point) - (setq org-roam--capture-insert-point nil))) - -(add-hook 'org-capture-after-finalize-hook #'org-roam--capture-advance-point) + (setq org-roam--capture-insert-point nil)) + (remove-hook 'org-capture-after-finalize-hook #'org-roam--capture-advance-point)) ;;;; org-roam-find-file (defun org-roam--get-title-path-completions () @@ -900,6 +900,14 @@ point moves some characters forward. This is added as a hook to file-path) res)))) res)) +(defun org-roam--capture-find-file () + "Opens the newly created template file. +This is added as a hook to `org-capture-after-finalize-hook'." + (when org-roam--capture-file-path + (find-file org-roam--capture-file-path) + (setq org-roam--capture-file-path nil)) + (remove-hook 'org-capture-after-finalize-hook #'org-roam--capture-find-file)) + (defun org-roam-find-file (&optional initial-prompt) "Find and open an Org-roam file. INITIAL-PROMPT is the initial title prompt." @@ -913,7 +921,8 @@ INITIAL-PROMPT is the initial title prompt." (let* ((org-roam--capture-info (list (cons 'title title) (cons 'slug (org-roam--title-to-slug title)))) (org-roam--capture-context 'title)) - (org-roam-capture '(4)))))) + (setq org-roam--capture-file-path (org-roam-capture)) + (add-hook 'org-capture-after-finalize-hook #'org-roam--capture-find-file))))) ;;;; org-roam-find-ref (defun org-roam--get-ref-path-completions ()