From 9dfdc1aa28947e66c9c15bf081a4aec9f0813a23 Mon Sep 17 00:00:00 2001 From: Correl Date: Thu, 24 Jun 2021 14:30:25 -0400 Subject: [PATCH] [emacs] Update org roam directory cache behavior --- .doom.d/config.org | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/.doom.d/config.org b/.doom.d/config.org index 4028187..d396699 100644 --- a/.doom.d/config.org +++ b/.doom.d/config.org @@ -1014,26 +1014,32 @@ When we visit a buffer in a different slip box (different =org-roam-directory=) than we were visiting previously, ensure the cache is updated. #+begin_src emacs-lisp - (defvar my/org-roam-directory-cache (list (expand-file-name org-roam-directory) - (expand-file-name org-roam-db-location))) + (defvar my/org-roam-directory-cache (list + (cons (expand-file-name org-roam-directory) + (expand-file-name org-roam-db-location)))) (after! savehist (add-to-list 'savehist-additional-variables 'my/org-roam-directory-cache)) + (defun my/org-roam-directory--lookup (path) + (alist-get path my/org-roam-directory-cache nil nil #'s-equals?)) + (defun my/org-roam-directory--update () - (plist-put! my/org-roam-directory-cache - org-roam-directory - org-roam-db-location)) + (setq my/org-roam-directory-cache + (cons (cons org-roam-directory org-roam-db-location) + (seq-filter + (lambda (x) (not (s-equals? org-roam-directory (car x)))) + my/org-roam-directory-cache)))) (add-hook! 'org-roam-buffer-prepare-hook #'my/org-roam-directory--update) (defun my/org-roam-find-in-directory () (interactive) (let* ((org-roam-directory (completing-read "Roam Directory" - (plist-get-keys my/org-roam-directory-cache))) - (org-roam-db-location (plist-get my/org-roam-directory-cache - org-roam-directory))) + (mapcar #'car my/org-roam-directory-cache))) + (org-roam-db-location (my/org-roam-directory--lookup + org-roam-directory))) (org-roam-find-file))) (map! :leader