Hi everyone,
I started the afternoon thinking I’d contribute a feature request (and potentially a PR if my Issue was well received) to org-roam. However, I think I need some help with the codebase before I can do that.
I’ve spent a few hours testing everything and reading the docs and writing Lisp, but can’t get it to work: I think I’m too green in terms of my knowledge of Lisp and org-roam’s codebase to be able to search effectively, which is why I’m asking here. Because it’s not a bug nor a feature request (yet), I thought it was better to ask on Discourse.
TLDR
I’m getting Symbol's function definition is void: org-roam-node-read-sort-by-title
when calling that function, even though I’ve created the org-roam-node-read-sort-by-title
function in org-roam-node.el
.
I’m on Doom Emacs, up-to-date, org-roam V2.
Feature I’m trying to implement
The feature I’m trying to implement is the following: when I do org-roam-node-insert
, I’d like to have the nodes sorted in the alphabetical order. I think it might be especially helpful to those who have large files with IDs for each heading (which seems to be relatively common given the amount of Issues I’ve seen over the last months when trying to solve my own issues).
For example, in a file like the following (imagine that each heading has an ID property):
* B Heading
** Thing of interest
* A Heading
** Heading
*** Thing of interest
I’d like to have the following prompt when doing org-roam-node-insert THI
:
> A Heading / Heading / Thing of interest
> B Heading / Thing of interest
or, for org-roam-node-insert HEAD
:
> A Heading
> A Heading / Heading
> A Heading / Heading / Thing
> B Heading
> B Heading / Thing
As of right now, the sorting is done depending on either file-mtime
or file-atime
.
Implementation
I had a look at the codebase and quickly saw that I needed to do the following:
1. Add the following function to org-roam-node.el
(based on org-roam-node-read-sort-by-file-mtime
):
(defun org-roam-node-read-sort-by-title (completion-a completion-b)
"Sort nodes in alphabetical order.
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-lessp (org-roam-node-title node-b)
(org-roam-node-title node-a))))
2. Add the following choice to org-roam-default-sort
:
(defcustom org-roam-node-default-sort 'file-mtime
"Default sort order for Org-roam node completions."
:type '(choice
(const :tag "none" nil)
# add this line
(const :tag "title" title)
(const :tag "file-mtime" file-mtime))
(const :tag "file-atime" file-atime))
:group 'org-roam)
I don’t understand what this is doing though, as it doesn’t seem to affect anything.
3. Add (setq org-roam-node-default-sort 'title
in my config.el.
Error
Every time I call org-roam-node-insert
, I keep getting:
Symbol's function definition is void: org-roam-node-read-sort-by-title
.
I’ve tried using other node properties (priority
, file-hash
, id
, etc.) instead of title
, I’ve tried changing cdr completion-a
to car completion-a
(because the COMPLETION is a list that starts with node-title
anyway), I’ve tried only doing step 2, I’ve tried turning everything off and on, but still keep getting this error. Even when org-roam-node-read-sort-by-title
has the same exact content as org-roam-node-read-sort-by-file-mtime
.
What am I not understanding here?