[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/sesman 53efa0a9ca 086/100: Honor sesman-follow-symlinks in
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/sesman 53efa0a9ca 086/100: Honor sesman-follow-symlinks in path expansion and project lookup |
Date: |
Tue, 28 Dec 2021 14:06:05 -0500 (EST) |
branch: elpa/sesman
commit 53efa0a9cac112d0410279ebec94206e48e4023f
Author: Vitalie Spinu <spinuvit@gmail.com>
Commit: Vitalie Spinu <spinuvit@gmail.com>
Honor sesman-follow-symlinks in path expansion and project lookup
Close clojure-emacs/cider#2505
---
sesman-test.el | 51 +++++++++++++++++++++++++++++++++++++++++
sesman.el | 72 ++++++++++++++++++++++++++--------------------------------
2 files changed, 83 insertions(+), 40 deletions(-)
diff --git a/sesman-test.el b/sesman-test.el
index b080070d8c..d6ca445b8a 100644
--- a/sesman-test.el
+++ b/sesman-test.el
@@ -245,6 +245,57 @@
(should (= (length sesman-links-alist) 6))))
+
+;;; FILE PATHS
+
+(cl-defmethod sesman-project ((system (eql C)))
+ (directory-file-name default-directory))
+
+(ert-deftest sesman-symlinked-projects-tests ()
+ (let* ((dir1 (make-temp-file "1-" 'dir))
+ (dir2 (make-temp-file "2-" 'dir))
+ (dir1-link (format "%s/dir1" dir2 dir1)))
+ ;; dir1 link in dir2
+ (shell-command (format "ln -s %s %s" dir1 dir1-link))
+
+ (let ((sesman-follow-symlinks nil)
+ (vc-follow-symlinks t))
+ (should (equal (sesman--expand-path dir1-link)
+ dir1-link)))
+ (let ((sesman-follow-symlinks t)
+ (vc-follow-symlinks nil))
+ (should (equal (sesman--expand-path dir1-link)
+ dir1)))
+ (let ((sesman-follow-symlinks 'vc)
+ (vc-follow-symlinks t))
+ (should (equal (sesman--expand-path dir1-link)
+ dir1)))
+ (let ((sesman-follow-symlinks 'vc)
+ (vc-follow-symlinks nil))
+ (should (equal (sesman--expand-path dir1-link)
+ dir1-link)))
+
+ (let ((sesman-follow-symlinks nil)
+ (default-directory dir1-link))
+ (should (equal (sesman-context 'project 'C)
+ dir1-link)))
+ (let ((sesman-follow-symlinks t)
+ (default-directory dir1-link))
+ (should (equal (sesman-context 'project 'C)
+ dir1)))
+ (let ((sesman-follow-symlinks 'vc)
+ (vc-follow-symlinks t)
+ (default-directory dir1-link))
+ (should (equal (sesman-context 'project 'C)
+ dir1)))
+ (let ((sesman-follow-symlinks 'vc)
+ (vc-follow-symlinks nil)
+ (default-directory dir1-link))
+ (should (equal (sesman-context 'project 'C)
+ dir1-link)))
+
+ (delete-directory dir1 t)
+ (delete-directory dir2 t)))
(provide 'sesman-test)
diff --git a/sesman.el b/sesman.el
index 87106a9454..e426860e9b 100644
--- a/sesman.el
+++ b/sesman.el
@@ -66,27 +66,23 @@
:group 'sesman)
(defcustom sesman-use-friendly-sessions t
- "If non-nil consider friendly sessions when searching for the current
sessions.
+ "If non-nil consider friendly sessions when looking for current sessions.
The definition of friendly sessions is system dependent but usually means
sessions running in dependent projects."
:group 'sesman
:type 'boolean
:package-version '(sesman . "0.3.2"))
-(defcustom sesman-follow-symlinks 'auto
- "This variable determines whether symlinks should be followed.
-nil - Don't follow symlinks - use `expand-file-name' for expanding file paths.
-t - Follow symlinks - use `file-truename' for expanding file paths.
-'auto - Don't follow symlink unless it's under version control and
-`vc-follow-link' has nil value. Or `find-file-visit-truename' is non-nil."
+(defcustom sesman-follow-symlinks 'vc
+ "When non-nil, follow symlinks during the file expansion.
+When nil, don't follow symlinks. When 'vc, follow symlinks only when
+`vc-follow-symlinks' is non-nil. When t, always follow symlinks."
:group 'sesman
- :type '(choice (const :tag "Behave like `find-file'" auto)
+ :type '(choice (const :tag "Comply with `vc-follow-symlinks'" vc)
(const :tag "Don't follow symlinks" nil)
(const :tag "Follow symlinks" t))
- :package-version '(sesman . "0.3.2"))
-(put 'sesman-follow-symlinks
- 'safe-local-variable
- (lambda (x) (memq x '(auto nil t))))
+ :package-version '(sesman . "0.3.3"))
+(put 'sesman-follow-symlinks 'safe-local-variable (lambda (x) (memq x '(vc nil
t))))
;; (defcustom sesman-disambiguate-by-relevance t
;; "If t choose most relevant session in ambiguous situations, otherwise ask.
@@ -330,16 +326,6 @@ If SORT is non-nil, sort in relevance order."
(defun sesman--lnk-value (lnk)
(nth 2 lnk))
-(defun sesman--follow-symlink-p (filename)
- "FILENAME predicate that tries to predict `find-file' behavior.
-It returns t if `find-file' will follow FILENAME symlink and nil if not."
- (or find-file-visit-truename
- (and vc-follow-symlinks
- (let ((truename (file-truename filename)))
- (and truename
- (not (equal truename filename))
- (vc-backend truename))))))
-
;;; User Interface
@@ -564,8 +550,9 @@ instead."
(list :objects (cdr session)))
(cl-defgeneric sesman-project (_system)
- "Retrieve project root current directory (`default-directory') for SYSTEM.
-Return a string or nil if no project has been found." nil)
+ "Retrieve project root in current directory (`default-directory') for SYSTEM.
+Return a string or nil if no project has been found."
+ nil)
(cl-defgeneric sesman-more-relevant-p (_system session1 session2)
"Return non-nil if SESSION1 should be sorted before SESSION2.
@@ -934,18 +921,22 @@ buffers."
-1)))
(buffer-list)))))
+
;;; Contexts
-(defvar sesman--path-cache (make-hash-table :test #'equal))
;; path caching because file-truename is very slow
+(defvar sesman--path-cache (make-hash-table :test #'equal))
(defun sesman--expand-path (path)
- (if (or (eq sesman-follow-symlinks t)
- (and (eq sesman-follow-symlinks 'auto)
- (sesman--follow-symlink-p path)))
- (or (gethash path sesman--path-cache)
- (puthash path (file-truename path) sesman--path-cache))
- (expand-file-name path)))
+ (if sesman-follow-symlinks
+ (let ((true-name (or (gethash path sesman--path-cache)
+ (puthash path (file-truename path)
sesman--path-cache))))
+ (if (or (eq sesman-follow-symlinks t)
+ vc-follow-symlinks)
+ true-name
+ ;; sesman-follow-symlinks is 'vc but vc-follow-symlinks is nil
+ (expand-file-name path)))
+ (expand-file-name path)))
(cl-defgeneric sesman-context (_cxt-type _system)
"Given SYSTEM and context type CXT-TYPE return the context.")
@@ -957,16 +948,17 @@ buffers."
(sesman--expand-path default-directory))
(cl-defmethod sesman-context ((_cxt-type (eql project)) system)
"Return current project."
- (let ((proj (or
- (sesman-project (or system (sesman--system)))
- ;; Normally we would use (project-roots (project-current)) but
currently
- ;; project-roots fails on nil and doesn't work on custom `('foo
.
- ;; "path/to/project"). So, use vc as a fallback and don't use
project.el at
- ;; all for now.
- ;; NB: `vc-root-dir' doesn't work from symlinked files. Emacs
Bug?
- (vc-root-dir))))
+ (let* ((default-directory (sesman--expand-path default-directory))
+ (proj (or
+ (sesman-project (or system (sesman--system)))
+ ;; Normally we would use (project-roots (project-current)) but
currently
+ ;; project-roots fails on nil and doesn't work on custom
`('foo .
+ ;; "path/to/project"). So, use vc as a fallback and don't use
project.el at
+ ;; all for now.
+ ;; NB: `vc-root-dir' doesn't work from symlinked files. Emacs
Bug?
+ (vc-root-dir))))
(when proj
- (sesman--expand-path proj))))
+ (expand-file-name proj))))
(cl-defgeneric sesman-relevant-context-p (_cxt-type cxt)
"Non-nil if context CXT is relevant to current context of type CXT-TYPE.")
- [nongnu] elpa/sesman 5a11793697 054/100: Fix tests and checkdoc, (continued)
- [nongnu] elpa/sesman 5a11793697 054/100: Fix tests and checkdoc, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 34521cd5c2 049/100: Fix buffer lookup, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 3df33018f1 089/100: Strip trailing slash in `sesman-expand-path`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 163984c60e 059/100: Better handling of overlays and sensor, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 6b0d6e318d 062/100: New UI and API functions sesman-link-with-least-specific and sesman-link-session, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 2b5135c00a 064/100: Version 0.2.1, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 209d9966e5 008/100: Renaming, refactoring ..., ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 665721c52f 066/100: Move context faces to sesman.el and use for info display, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 5a9727ee82 072/100: Expand all paths with file-truename and cache, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 14475d8192 080/100: [Fix #10] Defalias sesman-link-session, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 53efa0a9ca 086/100: Honor sesman-follow-symlinks in path expansion and project lookup,
ELPA Syncer <=
- [nongnu] elpa/sesman 04df98807f 070/100: Change font of sesman-buffer-face, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 7fe522431e 068/100: Expand file-name because the backend might not do it, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 35d6562ad8 006/100: Add more link specific utilities, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 0d8d1bef45 022/100: Version 0.1.1, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman e341db8d97 095/100: Update menu, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 0d3d016732 023/100: Add autoloads for user level commands, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 2e4205c7d9 046/100: Fix return value of sesman-grouped-links, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman ae68b3facf 042/100: [#8] Improve session "info" infrastructure, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 9108444fd8 040/100: Better sorting and de-duplication in a number of core functions, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman ba2756caf7 063/100: Fix compilation warnings, ELPA Syncer, 2021/12/28