(bugfix): fix unintuitive behaviour of capture insertion (#293)

Ref #285
This commit is contained in:
Jethro Kuan
2020-03-13 18:13:04 +08:00
committed by GitHub
parent 62ed117eb6
commit d28a83c992
2 changed files with 18 additions and 5 deletions

View File

@@ -9,6 +9,9 @@
* [#289][gh-289] Add customizable `org-roam-fuzzy-match` to allow fuzzy-matching of candidates * [#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 * [#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) ## 1.0.0-rc1 (06-03-2020)
This is a pre-release before the push to MELPA. It contains large 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-284]: https://github.com/jethrokuan/org-roam/pull/284
[gh-289]: https://github.com/jethrokuan/org-roam/pull/289 [gh-289]: https://github.com/jethrokuan/org-roam/pull/289
[gh-290]: https://github.com/jethrokuan/org-roam/pull/290 [gh-290]: https://github.com/jethrokuan/org-roam/pull/290
[gh-293]: https://github.com/jethrokuan/org-roam/pull/293
# Local Variables: # Local Variables:
# eval: (auto-fill-mode -1) # eval: (auto-fill-mode -1)

View File

@@ -870,7 +870,8 @@ If PREFIX, downcase the title before insertion."
(insert (format "[[%s][%s]]" (insert (format "[[%s][%s]]"
link-location link-location
description)) 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 () (defun org-roam--capture-advance-point ()
"Advances the point if it is updated. "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'." `org-capture-after-finalize-hook'."
(when org-roam--capture-insert-point (when org-roam--capture-insert-point
(goto-char org-roam--capture-insert-point) (goto-char org-roam--capture-insert-point)
(setq org-roam--capture-insert-point nil))) (setq org-roam--capture-insert-point nil))
(remove-hook 'org-capture-after-finalize-hook #'org-roam--capture-advance-point))
(add-hook 'org-capture-after-finalize-hook #'org-roam--capture-advance-point)
;;;; org-roam-find-file ;;;; org-roam-find-file
(defun org-roam--get-title-path-completions () (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)))) file-path) res))))
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) (defun org-roam-find-file (&optional initial-prompt)
"Find and open an Org-roam file. "Find and open an Org-roam file.
INITIAL-PROMPT is the initial title prompt." 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) (let* ((org-roam--capture-info (list (cons 'title title)
(cons 'slug (org-roam--title-to-slug title)))) (cons 'slug (org-roam--title-to-slug title))))
(org-roam--capture-context '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 ;;;; org-roam-find-ref
(defun org-roam--get-ref-path-completions () (defun org-roam--get-ref-path-completions ()