Change org-roam-node-display-template temporarily

Hi,

I have several first level sub directories in my org-roam-directory.

I am configuring bindings to invoke ‘pre-filtered’ versions of org-roam-node-find to search for nodes in directory subsets.

I am using this function from the org-roam project wiki, and it works pretty well. The function is quite long, and I don’t think it is central to my issue, so I decided to keep it out of the thread for clarity and simply reference it with a link. It might help understand the snippets below to specify that I kept the original function name my/org-roam-node-find-in-selected-dirs.

I will simplify my use case also to make it easier to read; let’s say I have two subdirectories, notes and archives and I want two functions to search in each folder separately. Here is the code I use:

(defun +org-roam-find-in-notes ()
  (interactive)
  (my/org-roam-node-find-in-selected-dirs
   (list "notes")))

(defun +org-roam-find-in-archives ()
  (interactive)
  (my/org-roam-node-find-in-selected-dirs
   (list "archives")))

This works exactly as I want to. Now, I want to remove tags from the ‘archives search’ function. I tried the following:

(defun +org-roam-find-in-archives ()
  (interactive)
  (setq org-roam-node-display-template
       (concat
        "${my-type:30}"
        "${my-title:*}"
        ))
  (my/org-roam-node-find-in-selected-dirs
   (list "archives")))

This does the job, but now, if I invoke +org-roam-find-in-notes, the display-template has been set globally, and I do not have my tags anymore. So I tried replacing setq with setq-local, but the result is the same.

Looking for an answer, I found this code from Nobiot on this forum. So I tried to use let as the link suggests:

(defun +org-roam-find-in-archives ()
  (interactive)
  (let ((org-roam-node-display-template
       (concat
        "${my-type:30}"
        "${my-title:*}"
        ))
  (my/org-roam-node-find-in-selected-dirs
   (list "archives")))))

I struggled through a lot of errors to get the right amount of parenthesis that lets me reload my Doom config. But with the code above I got no error which is good, but it does nothing which is less good :slight_smile:

I do not understand well how elisp works yet, so I wondered if maybe the code inside (let()) does not have access to my custom org-roam-display-templates accessors (my-type and my-title in the example above).

I might also be completely wrong about the source of the problem, so simplifying my code for the sake of a clearer example might be a mistake, in which case I can post the full version. I just removed a bunch of propertize and 'face settings from my original org-roam-display-template.

Thanks in advance for your help.

Try this. Your code is missing a pair of parentheses to properly close the let.

(defun +org-roam-find-in-archives ()
  (interactive)
  (let ((org-roam-node-display-template
         (concat
          "${my-type:30}"
          "${my-title:*}"
          )))
    (my/org-roam-node-find-in-selected-dirs
     (list "archives"))))

Thank you, it works fine now.

I had the amount of prentheses right, but not in the right place. The way elisp uses parenthesis is not easy to read for me. All I found so far is using evil-jump-item to make sure that all pairs are closed as they should. Obviously it is not enough, sorry about that.

While Emacs is already improving tremendously my productivity, I fear that elisp will be the end of the ‘glasses free’ part of my life :slight_smile: