branch: elpa/dirvish commit ed4a2938ad63cf2a5de2c6e38cac6b2a615df58a Author: Alex Lu <hellosimon1...@hotmail.com> Commit: Alex Lu <hellosimon1...@hotmail.com>
refactor(subtree): only use the `sit-for` hack when necessary --- extensions/dirvish-side.el | 2 +- extensions/dirvish-subtree.el | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/extensions/dirvish-side.el b/extensions/dirvish-side.el index 290e0a5317..6df3bca012 100644 --- a/extensions/dirvish-side.el +++ b/extensions/dirvish-side.el @@ -134,7 +134,7 @@ filename until the project root when opening a side session." (with-selected-window win (let (buffer-list-update-hook) (dirvish--find-entry 'find-alternate-file dir)) - (if dirvish-side-auto-expand (dirvish-subtree-expand-to curr) + (if dirvish-side-auto-expand (dirvish-subtree-expand-to curr t) (dired-goto-file curr)) (dirvish--update-display)))))) diff --git a/extensions/dirvish-subtree.el b/extensions/dirvish-subtree.el index 4ec6297301..df6a5114d8 100644 --- a/extensions/dirvish-subtree.el +++ b/extensions/dirvish-subtree.el @@ -310,8 +310,9 @@ See `dirvish-subtree-file-viewer' for details" (setq stop t))) stop)) -(defun dirvish-subtree-expand-to (target) - "Go to line describing TARGET and expand its parent directories." +(defun dirvish-subtree-expand-to (target &optional sit) + "Go to line describing TARGET and expand its parent directories. +`sit-for' 0.01 before inserting subtrees if SIT." (interactive (list (directory-file-name (expand-file-name (read-file-name "Expand to file: " @@ -327,26 +328,26 @@ See `dirvish-subtree-file-viewer' for details" (next (car (split-string (substring target (1+ (length file))) "/")))) (when (dirvish-subtree--move-to-file next depth) - (dirvish-subtree-expand-to target)))) + (dirvish-subtree-expand-to target sit)))) ((string-prefix-p dir target) (let ((depth (dirvish-subtree--depth)) (next (car (split-string (substring target (length dir)) "/")))) (goto-char (dired-subdir-min)) (goto-char (next-single-property-change (point) 'dired-filename)) (forward-line -1) - ;; Without this `sit-for', the following movement may stop at a - ;; "strange" point where the file name belongs to a subtree that is - ;; not expanded yet. This can occur when reopening a path - ;; immediately after the original buffer visiting that path is - ;; killed, affecting functions like `dirvish-side--auto-jump'. - (sit-for 0.01) + ;; HACK! Without this `sit-for', the following movement may stop + ;; at a incorrect point where the file name belongs to a subtree + ;; that is inserted in a wrong position. This can occur when + ;; reopening a path immediately after the original buffer visiting + ;; that path is killed, e.g. `dirvish-side--auto-jump'. + (if sit (sit-for 0.01)) ;; TARGET is either not exist or being hidden (#135) (when (dirvish-subtree--move-to-file next depth) - (dirvish-subtree-expand-to target)))) + (dirvish-subtree-expand-to target sit)))) ((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))))) + (dirvish-subtree-expand-to target sit))))) ;;;###autoload (defun dirvish-subtree-up ()