mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(internal): remove unnecessary variables (#1244)
For captures, enforce that `:file-name` needs to be specified, and `:head` when not provided defaults to the empty string (i.e. no head)
This commit is contained in:
@ -41,9 +41,7 @@
|
|||||||
(defvar org-roam-directory)
|
(defvar org-roam-directory)
|
||||||
(defvar org-roam-mode)
|
(defvar org-roam-mode)
|
||||||
(defvar org-roam-title-to-slug-function)
|
(defvar org-roam-title-to-slug-function)
|
||||||
(defvar org-roam-dailies-directory)
|
|
||||||
(defvar org-roam-dailies-capture--file-name-default)
|
|
||||||
(defvar org-roam-dailies-capture--header-default)
|
|
||||||
(declare-function org-roam--get-title-path-completions "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--file-path-from-id "org-roam")
|
||||||
@ -52,12 +50,6 @@
|
|||||||
(declare-function org-roam-mode "org-roam")
|
(declare-function org-roam-mode "org-roam")
|
||||||
(declare-function org-roam-completion--completing-read "org-roam-completion")
|
(declare-function org-roam-completion--completing-read "org-roam-completion")
|
||||||
|
|
||||||
(defvar org-roam-capture--file-name-default "%<%Y%m%d%H%M%S>-${slug}"
|
|
||||||
"The default file-name format for Org-roam templates.")
|
|
||||||
|
|
||||||
(defvar org-roam-capture--header-default "#+title: ${title}\n"
|
|
||||||
"The default header for Org-roam templates.")
|
|
||||||
|
|
||||||
(defvar org-roam-capture--file-path nil
|
(defvar org-roam-capture--file-path nil
|
||||||
"The file path for the Org-roam capture.
|
"The file path for the Org-roam capture.
|
||||||
This variable is set during the Org-roam capture process.")
|
This variable is set during the Org-roam capture process.")
|
||||||
@ -89,8 +81,8 @@ note with the given `ref'.")
|
|||||||
(defcustom org-roam-capture-templates
|
(defcustom org-roam-capture-templates
|
||||||
`(("d" "default" plain (function org-roam-capture--get-point)
|
`(("d" "default" plain (function org-roam-capture--get-point)
|
||||||
"%?"
|
"%?"
|
||||||
:file-name ,org-roam-capture--file-name-default
|
:file-name "%<%Y%m%d%H%M%S>-${slug}"
|
||||||
:head ,org-roam-capture--header-default
|
:head "#+title: ${title}\n"
|
||||||
:unnarrowed t))
|
:unnarrowed t))
|
||||||
"Capture templates for Org-roam.
|
"Capture templates for Org-roam.
|
||||||
The Org-roam capture-templates builds on the default behaviours of
|
The Org-roam capture-templates builds on the default behaviours of
|
||||||
@ -226,17 +218,11 @@ Template string :\n%v")
|
|||||||
((const :format "%v " :table-line-pos) (string))
|
((const :format "%v " :table-line-pos) (string))
|
||||||
((const :format "%v " :kill-buffer) (const t))))))
|
((const :format "%v " :kill-buffer) (const t))))))
|
||||||
|
|
||||||
(defvar org-roam-capture-ref--file-name-default "${slug}"
|
|
||||||
"The default file-name for `org-roam-capture-ref-templates'.")
|
|
||||||
|
|
||||||
(defvar org-roam-capture-ref--header-default "#+title: ${title}\n#+roam_key: ${ref}"
|
|
||||||
"The default header for `org-roam-capture-ref-templates'.")
|
|
||||||
|
|
||||||
(defcustom org-roam-capture-ref-templates
|
(defcustom org-roam-capture-ref-templates
|
||||||
`(("r" "ref" plain (function org-roam-capture--get-point)
|
'(("r" "ref" plain #'org-roam-capture--get-point
|
||||||
"%?"
|
"%?"
|
||||||
:file-name ,org-roam-capture-ref--file-name-default
|
:file-name "${slug}"
|
||||||
:head ,org-roam-capture--header-default
|
:head "#+title: ${title}\n#+roam_key: ${ref}"
|
||||||
:unnarrowed t))
|
:unnarrowed t))
|
||||||
"The Org-roam templates used during a capture from the roam-ref protocol.
|
"The Org-roam templates used during a capture from the roam-ref protocol.
|
||||||
Details on how to specify for the template is given in `org-roam-capture-templates'."
|
Details on how to specify for the template is given in `org-roam-capture-templates'."
|
||||||
@ -402,18 +388,6 @@ The file is saved if the original value of :no-save is not t and
|
|||||||
(with-current-buffer (org-capture-get :buffer)
|
(with-current-buffer (org-capture-get :buffer)
|
||||||
(save-buffer)))))
|
(save-buffer)))))
|
||||||
|
|
||||||
(defun org-roam-capture--expand-file-name (file-name)
|
|
||||||
"Expand FILE-NAME for `org-roam-capture'.
|
|
||||||
|
|
||||||
Prepend `org-roam-dailies-directory' to the value of `:file' when
|
|
||||||
capturing a daily-note."
|
|
||||||
(when file-name
|
|
||||||
(pcase org-roam-capture--context
|
|
||||||
('dailies
|
|
||||||
(concat org-roam-dailies-directory file-name))
|
|
||||||
(_
|
|
||||||
file-name))))
|
|
||||||
|
|
||||||
(defun org-roam-capture--new-file ()
|
(defun org-roam-capture--new-file ()
|
||||||
"Return the path to the new file during an Org-roam capture.
|
"Return the path to the new file during an Org-roam capture.
|
||||||
|
|
||||||
@ -436,27 +410,12 @@ aborted, we do the following:
|
|||||||
the file if the original value of :no-save is not t and
|
the file if the original value of :no-save is not t and
|
||||||
`org-note-abort' is not t."
|
`org-note-abort' is not t."
|
||||||
(let* ((name-templ (or (org-roam-capture--get :file-name)
|
(let* ((name-templ (or (org-roam-capture--get :file-name)
|
||||||
(pcase org-roam-capture--context
|
(user-error "Template needs to specify `:file-name'")))
|
||||||
('dailies
|
|
||||||
(or (-some-> org-roam-dailies-directory
|
|
||||||
(file-name-as-directory)
|
|
||||||
(concat org-roam-dailies-capture--file-name-default))
|
|
||||||
(user-error "`org-roam-dailies-directory' cannot be nil")))
|
|
||||||
('ref
|
|
||||||
org-roam-capture-ref--file-name-default)
|
|
||||||
(_
|
|
||||||
org-roam-capture--file-name-default))))
|
|
||||||
(new-id (s-trim (org-roam-capture--fill-template
|
(new-id (s-trim (org-roam-capture--fill-template
|
||||||
name-templ)))
|
name-templ)))
|
||||||
(file-path (org-roam--file-path-from-id new-id))
|
(file-path (org-roam--file-path-from-id new-id))
|
||||||
(roam-head (or (org-roam-capture--get :head)
|
(roam-head (or (org-roam-capture--get :head)
|
||||||
(pcase org-roam-capture--context
|
""))
|
||||||
('dailies
|
|
||||||
org-roam-dailies-capture--header-default)
|
|
||||||
('ref
|
|
||||||
org-roam-capture-ref--header-default)
|
|
||||||
(_
|
|
||||||
org-roam-capture--header-default))))
|
|
||||||
(org-template (org-capture-get :template))
|
(org-template (org-capture-get :template))
|
||||||
(roam-template (concat roam-head org-template)))
|
(roam-template (concat roam-head org-template)))
|
||||||
(unless (or (file-exists-p file-path)
|
(unless (or (file-exists-p file-path)
|
||||||
|
@ -47,12 +47,6 @@
|
|||||||
(declare-function org-roam--find-file "org-roam")
|
(declare-function org-roam--find-file "org-roam")
|
||||||
(declare-function org-roam-mode "org-roam")
|
(declare-function org-roam-mode "org-roam")
|
||||||
|
|
||||||
(defvar org-roam-dailies-capture--file-name-default "%<%Y-%m-%d>"
|
|
||||||
"The default file-name for `org-roam-dailies-capture-templates'.")
|
|
||||||
|
|
||||||
(defvar org-roam-dailies-capture--header-default "#+title: %<%Y-%m-%d>\n"
|
|
||||||
"The default header for `org-roam-dailies-capture-templates'.")
|
|
||||||
|
|
||||||
;;;; Customizable variables
|
;;;; Customizable variables
|
||||||
(defcustom org-roam-dailies-directory "daily/"
|
(defcustom org-roam-dailies-directory "daily/"
|
||||||
"Path to daily-notes."
|
"Path to daily-notes."
|
||||||
|
Reference in New Issue
Block a user