akashpal-21 / org-roam-utilities

Some utilities to use alongside org-roam
GNU General Public License v3.0
0 stars 1 forks source link

org-roam-directory-name #1

Open dmgerman opened 3 weeks ago

dmgerman commented 3 weeks ago

the value of this binding is the basename of org-roam (e.g. "roam")

the format +org-roam-node-display-template would fail is the that name exists in a previous directory:

assume the org-roam dir is "/Users/dmg/roam/org/roam/"

(if (string-match
     (format "/%s/\\([^/]+\\)/" "roam")
     "/Users/dmg/roam/org/roam/refs/faq_git.org")
    (match-string 1 "/Users/dmg/roam/org/roam/refs/faq_git.org"))

would return org instead of refs

use the full path instead.

akashpal-21 commented 3 weeks ago

Good observation - generally using any function from the files.el is expensive and the hack was really to reduce the number of times any such function is needed to be called.

We should instead check from the right hand side - using the full path will just take a lot of space.

dmgerman commented 3 weeks ago

Use the entire path in the string match. No need to use the file system functions.

akashpal-21 commented 3 weeks ago

ideally i want this for the dir component

"/home/akash/roam/org/roam/refs/faq_git.org" should return "org/../refs"
"/home/akash/roam/refs/faq_git.org"          should return "refs"
"/home/akash/roam/"                          should return "/"

exploring some options - the code needs to be extremely fast.

Also I will remove the variable org-roam-directory-name we have all the ingredients because we already define the path in org-roam-directory

dmgerman commented 3 weeks ago

this is what I would do:

  1. split the path into dir and basename
  2. write a function that shortens the path
  3. memoize it

The memory cost will be tiny, but the gains tremendous.