Simplify denote--silo-p with dir-locals-find-file

This commit is contained in:
Protesilaos Stavrou 2023-02-20 08:01:11 +02:00
parent 0c64ba9853
commit 3d2e1d5aab
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA

View file

@ -514,15 +514,14 @@ things accordingly.")
(defun denote--silo-p (path)
"Return path to silo if PATH is a silo."
(when (and path (file-directory-p path))
(with-temp-buffer
(when-let* ((files (directory-files path))
((member ".dir-locals.el" files))
(val (buffer-local-value
'denote-directory
;; TODO 2023-02-12: Clean up the created buffer
(get-buffer-create (find-file-noselect path)))))
path))))
(when-let (((and path (file-directory-p path)))
(dir-locals (dir-locals-find-file path)))
(cond
((listp dir-locals)
(car dir-locals))
((stringp dir-locals)
dir-locals)
(t nil))))
(defun denote--get-silo-path (&optional file levels)
"Try to determine if FILE belongs to a silo.