Skip to content

Instantly share code, notes, and snippets.

@cuprum
Created January 31, 2023 09:12
Show Gist options
  • Save cuprum/20af58bc1f09460e552baf4726662c4f to your computer and use it in GitHub Desktop.
Save cuprum/20af58bc1f09460e552baf4726662c4f to your computer and use it in GitHub Desktop.
Sort daily from dir alphabetically
(defun org-roam-node-read-sort-by-olp-title (completion-a completion-b)
;; https://org-roam.discourse.group/t/symbols-function-definition-is-void-when-trying-to-implement-a-feature-in-org-roam-node-el/2220/3
"Sort files alphabetically.
COMPLETION-A and COMPLETION-B are items in the form of (node-title org-roam-node-struct)"
(let ((node-a (cdr completion-a))
(node-b (cdr completion-b)))
(string-greaterp (concat (string-join (org-roam-node-olp node-b)
" / ")
" / "
(org-roam-node-title node-b))
(concat (string-join (org-roam-node-olp node-a)
" / ")
" / "
(org-roam-node-title node-a)))))
(cl-defun yr/orm-filter-by-folder (node &optional folder)
"Filter org-roam-node by folders."
(let* ((file-path (org-roam-node-file node))
(rel-file-path (file-relative-name file-path
org-roam-directory))
(parent-directories (butlast (split-string rel-file-path
"/"))))
(if (and folder (not (cl-intersection folder
parent-directories
:test #'string=)))
nil
t)))
(cl-defun yr/orm-node-find-preview (&optional other-window
initial-input
filter-fn
sort-fn)
(interactive current-prefix-arg)
(let ((node (consult-org-roam-node-read initial-input
filter-fn
sort-fn)))
(if (org-roam-node-file node)
(org-roam-node-visit node
other-window))))
(cl-defun yr/orm-node-find-wrapper ()
"Modded org-roam-node-find which filters nodes using folders and sorts alphabetically."
(interactive)
(yr/orm-node-find-preview nil
nil
(lambda (node) (yr/orm-filter-by-folder node
'("daily")))
(lambda (a b) (org-roam-node-read-sort-by-olp-title b
a))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment