Move org-roam-capture command to org-roam-capture.el (#407)

This commit is contained in:
N V
2020-04-07 01:53:22 -04:00
committed by GitHub
parent 5120f8eac3
commit c7a44b9f12
2 changed files with 23 additions and 20 deletions

View File

@@ -37,9 +37,12 @@
;; Declarations ;; Declarations
(defvar org-roam-encrypt-files) (defvar org-roam-encrypt-files)
(defvar org-roam-directory) (defvar org-roam-directory)
(declare-function org-roam--file-path-from-id "org-roam") (declare-function org-roam--get-title-path-completions "org-roam")
(declare-function org-roam--get-ref-path-completions "org-roam") (declare-function org-roam--get-ref-path-completions "org-roam")
(declare-function org-roam--file-path-from-id "org-roam")
(declare-function org-roam--format-link "org-roam") (declare-function org-roam--format-link "org-roam")
(declare-function org-roam--title-to-slug "org-roam")
(declare-function org-roam-completion--completing-read "org-roam-completion")
(defvar org-roam-capture--file-name-default "%<%Y%m%d%H%M%S>" (defvar org-roam-capture--file-name-default "%<%Y%m%d%H%M%S>"
"The default file name format for Org-roam templates.") "The default file name format for Org-roam templates.")
@@ -308,6 +311,23 @@ GOTO and KEYS argument have the same functionality as
(add-hook 'org-capture-after-finalize-hook #'org-roam-capture--cleanup-h 10) (add-hook 'org-capture-after-finalize-hook #'org-roam-capture--cleanup-h 10)
(org-capture goto keys))) (org-capture goto keys)))
;;;###autoload
(defun org-roam-capture ()
"Launches an `org-capture' process for a new or existing note.
This uses the templates defined at `org-roam-capture-templates'."
(interactive)
(when org-roam-capture--in-process
(user-error "Nested Org-roam capture processes not supported"))
(let* ((completions (org-roam--get-title-path-completions))
(title (org-roam-completion--completing-read "File: " completions))
(file-path (cdr (assoc title completions))))
(let ((org-roam-capture--info (list (cons 'title title)
(cons 'slug (org-roam--title-to-slug title))
(cons 'file file-path)))
(org-roam-capture--context 'capture))
(setq org-roam-capture-additional-template-props (list :capture-fn 'org-roam-capture))
(org-roam--capture))))
(provide 'org-roam-capture) (provide 'org-roam-capture)
;;; org-roam-capture.el ends here ;;; org-roam-capture.el ends here

View File

@@ -451,23 +451,6 @@ INFO is an alist containing additional information."
:require-match t))) :require-match t)))
(switch-to-buffer (cdr (assoc name names-and-buffers)))))) (switch-to-buffer (cdr (assoc name names-and-buffers))))))
;;;; org-roam-capture
(defun org-roam-capture ()
"Launches an org-capture process for a new or existing note.
This uses the templates defined at `org-roam-capture-templates'."
(interactive)
(when org-roam-capture--in-process
(user-error "Nested Org-roam capture processes not supported"))
(let* ((completions (org-roam--get-title-path-completions))
(title (org-roam-completion--completing-read "File: " completions))
(file-path (cdr (assoc title completions))))
(let ((org-roam-capture--info (list (cons 'title title)
(cons 'slug (org-roam--title-to-slug title))
(cons 'file file-path)))
(org-roam-capture--context 'capture))
(setq org-roam-capture-additional-template-props (list :capture-fn 'org-roam-capture))
(org-roam--capture))))
;;;; Daily notes ;;;; Daily notes
(defcustom org-roam-date-title-format "%Y-%m-%d" (defcustom org-roam-date-title-format "%Y-%m-%d"
"Format string passed to `format-time-string' for getting a date file's title." "Format string passed to `format-time-string' for getting a date file's title."