From 2e94f55cc58f6dce2772a6f33521eb5afcf67265 Mon Sep 17 00:00:00 2001 From: Julian Flake Date: Sun, 14 Jan 2024 20:41:46 +0100 Subject: [PATCH] (node) add optional NOCASE parameter to org-roam-node-from-title-or-alias (#2403) * (node) add NOCASE parameter to org-roam-node-from-title-or-alias * fixed docstring of org-roam-node-from-title-or-alias. --- org-roam-node.el | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/org-roam-node.el b/org-roam-node.el index 720c3a0..f5c1bd0 100644 --- a/org-roam-node.el +++ b/org-roam-node.el @@ -256,18 +256,22 @@ Return nil if a node with ID does not exist." id)) 0) (org-roam-populate (org-roam-node-create :id id)))) -(defun org-roam-node-from-title-or-alias (s) +(defun org-roam-node-from-title-or-alias (s &optional nocase) "Return an `org-roam-node' for the node with title or alias S. Return nil if the node does not exist. -Throw an error if multiple choices exist." +Throw an error if multiple choices exist. + +If NOCASE is non-nil, the query is case insensitive. It is case sensitive otherwise." (let ((matches (seq-uniq (append - (org-roam-db-query [:select [id] :from nodes - :where (= title $s1)] - s) - (org-roam-db-query [:select [node-id] :from aliases - :where (= alias $s1)] - s))))) + (org-roam-db-query (vconcat [:select [id] :from nodes + :where (= title $s1)] + (if nocase [ :collate NOCASE ])) + s) + (org-roam-db-query (vconcat [:select [node-id] :from aliases + :where (= alias $s1)] + (if nocase [ :collate NOCASE ])) + s))))) (cond ((seq-empty-p matches) nil)