mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
pass node around instead
This commit is contained in:
@ -40,7 +40,6 @@
|
|||||||
|
|
||||||
;; Declarations
|
;; Declarations
|
||||||
(defvar org-roam-directory)
|
(defvar org-roam-directory)
|
||||||
(defvar org-roam-title-to-slug-function)
|
|
||||||
|
|
||||||
(defvar org-roam-capture--info nil
|
(defvar org-roam-capture--info nil
|
||||||
"A property-list of additional information passed to the Org-roam template.
|
"A property-list of additional information passed to the Org-roam template.
|
||||||
@ -186,21 +185,17 @@ This function is to be called in the Org-capture finalization process."
|
|||||||
"Expand the template STR, returning the string.
|
"Expand the template STR, returning the string.
|
||||||
This is an extension of org-capture's template expansion.
|
This is an extension of org-capture's template expansion.
|
||||||
|
|
||||||
First, it expands ${var} occurrences in STR, using `org-roam-capture--info'.
|
First, it expands ${var} occurrences in STR, using the node in
|
||||||
If there is a ${var} with no matching var in the alist, the value
|
`org-roam-capture--info'. Next, it expands the remaining template
|
||||||
of var is prompted for via `completing-read'.
|
string using `org-capture-fill-template'."
|
||||||
|
(let ((node (plist-get org-roam-capture--info :node)))
|
||||||
Next, it expands the remaining template string using
|
(org-capture-fill-template
|
||||||
`org-capture-fill-template'."
|
(s-format str
|
||||||
(org-capture-fill-template
|
(lambda (key)
|
||||||
(s-format str
|
(let ((fn (intern (concat "org-roam-node-" key))))
|
||||||
(lambda (key)
|
(if (fboundp fn)
|
||||||
(let ((plist-key (intern (concat ":" key))))
|
(funcall fn node)
|
||||||
(or (plist-get org-roam-capture--info plist-key)
|
(completing-read (format "%s: " key) nil))))))))
|
||||||
(when-let ((val (completing-read (format "%s: " key) nil)))
|
|
||||||
(setq org-roam-capture--info
|
|
||||||
(plist-put org-roam-capture--info plist-key val))
|
|
||||||
val)))))))
|
|
||||||
|
|
||||||
(defun org-roam-capture--save-file-maybe ()
|
(defun org-roam-capture--save-file-maybe ()
|
||||||
"Save the file conditionally.
|
"Save the file conditionally.
|
||||||
@ -310,18 +305,17 @@ you can catch it with `condition-case'."
|
|||||||
"Return exact point to file for org-capture-template.
|
"Return exact point to file for org-capture-template.
|
||||||
This function is used solely in Org-roam's capture templates: see
|
This function is used solely in Org-roam's capture templates: see
|
||||||
`org-roam-capture-templates'."
|
`org-roam-capture-templates'."
|
||||||
(when-let ((time (plist-get org-roam-capture--info :time)))
|
(let* ((node (plist-get org-roam-capture--info :node))
|
||||||
(org-capture-put :default-time time))
|
(file-path
|
||||||
(let ((file-path
|
(cond ((plist-get org-roam-capture--info :ref)
|
||||||
(cond ((plist-get org-roam-capture--info :file)
|
(or (caar (org-roam-db-query [:select [file]
|
||||||
(plist-get org-roam-capture--info :file))
|
:from refs
|
||||||
((plist-get org-roam-capture--info :ref)
|
:where (= ref $s1)
|
||||||
(or (caar (org-roam-db-query [:select [file]
|
:limit 1]
|
||||||
:from refs
|
(plist-get org-roam-capture--info :ref)))
|
||||||
:where (= ref $s1)
|
|
||||||
:limit 1]
|
|
||||||
(plist-get org-roam-capture--info :ref)))
|
|
||||||
(org-roam-capture--new-file)))
|
(org-roam-capture--new-file)))
|
||||||
|
((org-roam-node-file node)
|
||||||
|
(org-roam-node-file node))
|
||||||
(t
|
(t
|
||||||
(org-roam-capture--new-file)))))
|
(org-roam-capture--new-file)))))
|
||||||
(org-capture-put :template
|
(org-capture-put :template
|
||||||
@ -383,9 +377,6 @@ TEMPLATES is a list of org-roam templates."
|
|||||||
(mapcar (lambda (t)
|
(mapcar (lambda (t)
|
||||||
(org-roam-capture--convert-template t props))
|
(org-roam-capture--convert-template t props))
|
||||||
(or templates org-roam-capture-templates)))
|
(or templates org-roam-capture-templates)))
|
||||||
(info (plist-put info :slug
|
|
||||||
(funcall org-roam-title-to-slug-function
|
|
||||||
(plist-get info :title))))
|
|
||||||
(org-roam-capture--info info))
|
(org-roam-capture--info info))
|
||||||
(when (and (not keys)
|
(when (and (not keys)
|
||||||
(= (length org-capture-templates) 1))
|
(= (length org-capture-templates) 1))
|
||||||
@ -401,8 +392,7 @@ Arguments GOTO and KEYS see `org-capture'."
|
|||||||
(let ((node (org-roam-node-read)))
|
(let ((node (org-roam-node-read)))
|
||||||
(org-roam-capture- :goto goto
|
(org-roam-capture- :goto goto
|
||||||
:keys keys
|
:keys keys
|
||||||
:info (list :title (org-roam-node-title node)
|
:info (list :node node)
|
||||||
:file (org-roam-node-file node))
|
|
||||||
:props '(:immediate-finish nil))))
|
:props '(:immediate-finish nil))))
|
||||||
|
|
||||||
(provide 'org-roam-capture)
|
(provide 'org-roam-capture)
|
||||||
|
@ -98,13 +98,9 @@ If FILE is not specified, use the current buffer's file-path."
|
|||||||
"Capture an entry in a daily-note for TIME, creating it if necessary.
|
"Capture an entry in a daily-note for TIME, creating it if necessary.
|
||||||
|
|
||||||
When GOTO is non-nil, go the note without creating an entry."
|
When GOTO is non-nil, go the note without creating an entry."
|
||||||
(let ((org-roam-capture-templates (--> org-roam-dailies-capture-templates
|
(org-roam-capture- :goto (when goto '(4))
|
||||||
(if goto (list (car it)) it)))
|
:templates org-roam-dailies-capture-templates
|
||||||
(org-roam-capture--info (list (cons 'time time)))
|
:props (list :default-time time)))
|
||||||
(org-roam-capture--context 'dailies))
|
|
||||||
(org-roam-capture- :goto (when goto '(4))
|
|
||||||
:info (list (cons 'time time))
|
|
||||||
:context 'dailies)))
|
|
||||||
|
|
||||||
;;;; Commands
|
;;;; Commands
|
||||||
;;; Today
|
;;; Today
|
||||||
|
@ -77,8 +77,10 @@ It opens or creates a note with the given ref.
|
|||||||
(raise-frame)
|
(raise-frame)
|
||||||
(org-roam-capture-
|
(org-roam-capture-
|
||||||
:keys (plist-get info :template)
|
:keys (plist-get info :template)
|
||||||
:info info
|
:info (list :node (org-roam-node-create :title (plist-get info :title))
|
||||||
:props `(:ref ,(plist-get info :ref))
|
:ref (plist-get info :ref)
|
||||||
|
:body (plist-get info :body))
|
||||||
|
:props (list :ref (plist-get info :ref))
|
||||||
:templates org-roam-capture-ref-templates)
|
:templates org-roam-capture-ref-templates)
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
|
@ -448,6 +448,10 @@ OLD-FILE is cleared from the database, and NEW-FILE-OR-DIR is added."
|
|||||||
id file level point todo priority scheduled deadline title
|
id file level point todo priority scheduled deadline title
|
||||||
tags aliases refs)
|
tags aliases refs)
|
||||||
|
|
||||||
|
(cl-defmethod org-roam-node-slug ((node org-roam-node))
|
||||||
|
"Return the slug of NODE."
|
||||||
|
(funcall org-roam-title-to-slug-function (org-roam-node-title node)))
|
||||||
|
|
||||||
(defvar org-roam-node-map
|
(defvar org-roam-node-map
|
||||||
(let ((map (make-sparse-keymap)))
|
(let ((map (make-sparse-keymap)))
|
||||||
(set-keymap-parent map org-roam-mode-map)
|
(set-keymap-parent map org-roam-mode-map)
|
||||||
@ -688,7 +692,7 @@ If OTHER-WINDOW, visit the NODE in another window."
|
|||||||
(if (org-roam-node-file node)
|
(if (org-roam-node-file node)
|
||||||
(org-roam-node-visit node other-window)
|
(org-roam-node-visit node other-window)
|
||||||
(org-roam-capture-
|
(org-roam-capture-
|
||||||
:info `(:title ,(org-roam-node-title node))
|
:info (list :node node)
|
||||||
:props '(:finalize find-file)))))
|
:props '(:finalize find-file)))))
|
||||||
|
|
||||||
(defun org-roam-node-insert (&optional filter-fn)
|
(defun org-roam-node-insert (&optional filter-fn)
|
||||||
@ -720,7 +724,7 @@ which takes as its argument an alist of path-completions."
|
|||||||
(concat "id:" (org-roam-node-id node))
|
(concat "id:" (org-roam-node-id node))
|
||||||
description)))
|
description)))
|
||||||
(org-roam-capture-
|
(org-roam-capture-
|
||||||
:info `(:title ,(org-roam-node-title node))
|
:info (list :node node)
|
||||||
:props (list :region (when (and beg end)
|
:props (list :region (when (and beg end)
|
||||||
(cons beg end))
|
(cons beg end))
|
||||||
:insert-at (point-marker)
|
:insert-at (point-marker)
|
||||||
|
Reference in New Issue
Block a user