emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/sesman 5a9727ee82 072/100: Expand all paths with file-true


From: ELPA Syncer
Subject: [nongnu] elpa/sesman 5a9727ee82 072/100: Expand all paths with file-truename and cache
Date: Tue, 28 Dec 2021 14:06:04 -0500 (EST)

branch: elpa/sesman
commit 5a9727ee82a74035fa6aee1e4b94829bd4260f0c
Author: Vitalie Spinu <spinuvit@gmail.com>
Commit: Vitalie Spinu <spinuvit@gmail.com>

    Expand all paths with file-truename and cache
    
      fixes clojure-emacs/cider#2433
---
 sesman.el | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/sesman.el b/sesman.el
index 9d8a86b1f0..42c5e617be 100644
--- a/sesman.el
+++ b/sesman.el
@@ -868,6 +868,13 @@ buffers."
 
 
 ;;; Contexts
+
+(defvar sesman--path-cache (make-hash-table :test #'equal))
+;; path caching because file-truename is very slow
+(defun sesman--expand-path (path)
+  (or (gethash path sesman--path-cache)
+      (puthash path (file-truename path) sesman--path-cache)))
+
 (cl-defgeneric sesman-context (_cxt-type _system)
   "Given SYSTEM and context type CXT-TYPE return the context.")
 (cl-defmethod sesman-context ((_cxt-type (eql buffer)) _system)
@@ -875,7 +882,7 @@ buffers."
   (current-buffer))
 (cl-defmethod sesman-context ((_cxt-type (eql directory)) _system)
   "Return current directory."
-  default-directory)
+  (sesman--expand-path default-directory))
 (cl-defmethod sesman-context ((_cxt-type (eql project)) system)
   "Return current project."
   (let ((proj (or
@@ -886,7 +893,7 @@ buffers."
                ;; all for now.
                (vc-root-dir))))
     (when proj
-      (expand-file-name proj))))
+      (sesman--expand-path proj))))
 
 (cl-defgeneric sesman-relevant-context-p (_cxt-type cxt)
   "Non-nil if context CXT is relevant to current context of type CXT-TYPE.")
@@ -896,12 +903,13 @@ buffers."
 (cl-defmethod sesman-relevant-context-p ((_cxt-type (eql directory)) dir)
   "Non-nil if DIR is the parent or equals the `default-directory'."
   (when (and dir default-directory)
-    (string-match-p (concat "^" dir) (expand-file-name default-directory))))
+    (string-match-p (concat "^" (sesman--expand-path dir))
+                    (sesman--expand-path default-directory))))
 (cl-defmethod sesman-relevant-context-p ((_cxt-type (eql project)) proj)
   "Non-nil if PROJ is the parent or equal to the `default-directory'."
   (when (and proj default-directory)
-    (string-match-p (concat "^" proj)
-                    (expand-file-name default-directory))))
+    (string-match-p (concat "^" (sesman--expand-path proj))
+                    (sesman--expand-path default-directory))))
 
 (defun sesman-relevant-link-p (link &optional cxt-types)
   "Return non-nil if LINK is relevant to the current context.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]