(bugfix): throw an error on nested org-roam capture processes (#329)

This commit is contained in:
Jethro Kuan
2020-03-20 20:17:56 +08:00
committed by GitHub
parent 919d08732c
commit 63b2eaaf86

View File

@@ -925,15 +925,17 @@ If PREFIX, downcase the title before insertion."
(when region ;; Remove previously selected text. (when region ;; Remove previously selected text.
(delete-region (car region) (cdr region))) (delete-region (car region) (cdr region)))
(insert (org-roam--format-link target-file-path link-description))) (insert (org-roam--format-link target-file-path link-description)))
(let* ((org-roam--capture-info (list (cons 'title title) (if (> org-roam--capture-nesting-count 0)
(cons 'slug (org-roam--title-to-slug title)))) (user-error "Nested Org-roam capture processes not supported")
(org-roam--capture-context 'title)) (let ((org-roam--capture-info (list (cons 'title title)
(add-hook 'org-capture-after-finalize-hook #'org-roam--capture-insert-link-h) (cons 'slug (org-roam--title-to-slug title))))
(incf org-roam--capture-nesting-count) (org-roam--capture-context 'title))
(setq org-roam--additional-template-props (list :region region (add-hook 'org-capture-after-finalize-hook #'org-roam--capture-insert-link-h)
:link-description link-description (incf org-roam--capture-nesting-count)
:capture-fn 'org-roam-insert)) (setq org-roam--additional-template-props (list :region region
(org-roam-capture))))) :link-description link-description
:capture-fn 'org-roam-insert))
(org-roam-capture))))))
(defun org-roam--capture-insert-link-h () (defun org-roam--capture-insert-link-h ()
"Inserts the link into the original buffer, after the capture process is done. "Inserts the link into the original buffer, after the capture process is done.
@@ -979,11 +981,13 @@ INITIAL-PROMPT is the initial title prompt."
(file-path (cdr (assoc title completions)))) (file-path (cdr (assoc title completions))))
(if file-path (if file-path
(find-file file-path) (find-file file-path)
(let* ((org-roam--capture-info (list (cons 'title title) (if (> org-roam--capture-nesting-count 0)
(cons 'slug (org-roam--title-to-slug title)))) (user-error "Org-roam capture in process")
(org-roam--capture-context 'title)) (let ((org-roam--capture-info (list (cons 'title title)
(add-hook 'org-capture-after-finalize-hook #'org-roam--capture-find-file-h) (cons 'slug (org-roam--title-to-slug title))))
(org-roam-capture))))) (org-roam--capture-context 'title))
(add-hook 'org-capture-after-finalize-hook #'org-roam--capture-find-file-h)
(org-roam-capture))))))
;;;; org-roam-find-ref ;;;; org-roam-find-ref
(defun org-roam--get-ref-path-completions () (defun org-roam--get-ref-path-completions ()