branch: elpa/dirvish commit b5004f80934e4ce92f5aedce67a773a58e69dda7 Author: Alex Lu <hellosimon1...@hotmail.com> Commit: Alex Lu <hellosimon1...@hotmail.com>
fix(subtree): raise error with out-of-scope expanding target (#327) - *dirvish-subtree-expand-to* should not attempt to expand a target that is not a leaf node in the subdirectory tree. - *dirvish-side* should handle errors from *dirvish-subtree-expand-to*. --- extensions/dirvish-side.el | 22 +++++++++++++--------- extensions/dirvish-subtree.el | 9 +++++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/extensions/dirvish-side.el b/extensions/dirvish-side.el index fee0d92b07..47641485c6 100644 --- a/extensions/dirvish-side.el +++ b/extensions/dirvish-side.el @@ -123,12 +123,16 @@ filename until the project root when opening a side session." ((not (equal prev curr)))) (with-selected-window win (let (buffer-list-update-hook window-buffer-change-functions) - (dirvish--find-entry 'find-alternate-file dir)) + (or (cl-loop for (d . _) in dired-subdir-alist + if (string-prefix-p d (expand-file-name dir)) + return (dired-goto-subdir d)) + (dirvish--find-entry 'find-alternate-file dir))) ;; delay the running of this hook to eliminate race condition (dirvish-winbuf-change-h win) - (if dirvish-side-auto-expand (dirvish-subtree-expand-to curr) - (dired-goto-file curr)) - (dirvish--redisplay)))) + (unwind-protect (if dirvish-side-auto-expand + (dirvish-subtree-expand-to curr) + (dired-goto-file curr)) + (dirvish--redisplay))))) (defun dirvish-side--new (path) "Open a side session in PATH." @@ -145,11 +149,11 @@ filename until the project root when opening a side session." (setq r-win (dirvish--create-root-window dv)) (with-selected-window r-win (dirvish--find-entry 'find-alternate-file path) - (cond ((not bname) nil) - (dirvish-side-auto-expand - (dirvish-subtree-expand-to bname)) - (t (dired-goto-file bname))) - (dirvish--redisplay)))) + (unwind-protect (cond ((not bname) nil) + (dirvish-side-auto-expand + (dirvish-subtree-expand-to bname)) + (t (dired-goto-file bname))) + (dirvish--redisplay))))) ;;;###autoload (define-minor-mode dirvish-side-follow-mode diff --git a/extensions/dirvish-subtree.el b/extensions/dirvish-subtree.el index 5c35d16de6..6439d170c6 100644 --- a/extensions/dirvish-subtree.el +++ b/extensions/dirvish-subtree.el @@ -337,10 +337,11 @@ See `dirvish-subtree-file-viewer' for details" ;; TARGET is either not exist or being hidden (#135) (when (dirvish-subtree--move-to-file next depth) (dirvish-subtree-expand-to target)))) - ((string-prefix-p (expand-file-name default-directory) dir) - (goto-char (dired-subdir-min)) - (goto-char (next-single-property-change (point) 'dired-filename)) - (dirvish-subtree-expand-to target))))) + ((cl-loop for (d . _) in dired-subdir-alist + if (string-prefix-p d target) + return (dired-goto-subdir d)) + (dirvish-subtree-expand-to target)) + (t (user-error "[ %s ] does not belong to any subdir" target))))) ;;;###autoload (defun dirvish-subtree-up ()