[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/dirvish a854e2b901 5/5: fix(subtree): race condition on `w
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/dirvish a854e2b901 5/5: fix(subtree): race condition on `window-buffer-change-functions` |
Date: |
Mon, 17 Mar 2025 22:00:57 -0400 (EDT) |
branch: elpa/dirvish
commit a854e2b90176a158c774ff03a5772af7749b63bc
Author: Alex Lu <hellosimon1103@hotmail.com>
Commit: Alex Lu <hellosimon1103@hotmail.com>
fix(subtree): race condition on `window-buffer-change-functions`
---
docs/CUSTOMIZING.org | 15 ++++++++-------
extensions/dirvish-side.el | 38 +++++++++++++++++---------------------
extensions/dirvish-subtree.el | 17 +++++------------
3 files changed, 30 insertions(+), 40 deletions(-)
diff --git a/docs/CUSTOMIZING.org b/docs/CUSTOMIZING.org
index acce1812ac..a21c5ea5b3 100644
--- a/docs/CUSTOMIZING.org
+++ b/docs/CUSTOMIZING.org
@@ -136,14 +136,14 @@ providing additional information about each file.
For now Dirvish offers these attributes:
-+ ~subtree-state~: A indicator for directory expanding state.
-+ ~nerd-icon~ | ~all-the-icons~ | ~vscode-icon~: File icons provided by
various backends.
++ ~subtree-state~: a indicator for directory expanding state.
++ ~nerd-icon~ | ~all-the-icons~ | ~vscode-icon~: file icons provided by
various backends.
+ ~collapse~: append unique nested paths to the end of filename.
-+ ~git-msg~: Append git commit message to filename.
-+ ~vc-state~: The version control state at left fringe.
-+ ~file-size~: Show file size or directories file count at right fringe.
-+ ~file-time~: Show file modification time
-+ ~file-modes~: Show file modes (*-rw-r--rwx*)
++ ~git-msg~: short git commit log.
++ ~vc-state~: version control state at left fringe.
++ ~file-size~: file size or directories file counts.
++ ~file-time~: file modification time
++ ~file-modes~: file modes (*-rw-r--rwx*)
Here is an overview of how does these attributes look like:
@@ -443,6 +443,7 @@ you don't have to require them explicitly if you installed
dirvish from MELPA or
'(("h" "~/" "Home")
("d" "~/Downloads/" "Downloads")
("m" "/mnt/" "Drives")
+ ("s" "/ssh:my-server") "SSH server"
("t" "~/.local/share/Trash/files/" "TrashCan")))
:config
;; (dirvish-peek-mode) ; Preview files in minibuffer
diff --git a/extensions/dirvish-side.el b/extensions/dirvish-side.el
index 3ef0ab90d7..242b432e30 100644
--- a/extensions/dirvish-side.el
+++ b/extensions/dirvish-side.el
@@ -118,27 +118,23 @@ filename until the project root when opening a side
session."
(defun dirvish-side--auto-jump ()
"Select latest buffer file in the visible `dirvish-side' session."
- ;; some commands such as `consult-buffer' that uses minibuffer somehow causes
- ;; a delay on `current-buffer' updating, so we wait for 0.01s here to ensure
- ;; the latest buffer is correctly grabbed. (#264)
- (run-with-timer
- 0.01 nil
- (lambda ()
- (when-let* (((not (dirvish-curr)))
- ((not (active-minibuffer-window)))
- (win (dirvish-side--session-visible-p))
- (dv (with-current-buffer (window-buffer win) (dirvish-curr)))
- (dir (or (dirvish--get-project-root) default-directory))
- (prev (with-selected-window win (dirvish-prop :index)))
- (curr buffer-file-name)
- ((not (string-suffix-p "COMMIT_EDITMSG" curr)))
- ((not (equal prev curr))))
- (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 t)
- (dired-goto-file curr))
- (dirvish--redisplay))))))
+ (when-let* (((not (dirvish-curr)))
+ ((not (active-minibuffer-window)))
+ (win (dirvish-side--session-visible-p))
+ (dv (with-current-buffer (window-buffer win) (dirvish-curr)))
+ (dir (or (dirvish--get-project-root) default-directory))
+ (prev (with-selected-window win (dirvish-prop :index)))
+ (curr buffer-file-name)
+ ((not (string-suffix-p "COMMIT_EDITMSG" curr)))
+ ((not (equal prev curr))))
+ (with-selected-window win
+ (let (buffer-list-update-hook window-buffer-change-functions)
+ (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))))
(defun dirvish-side--new (path)
"Open a side session in PATH."
diff --git a/extensions/dirvish-subtree.el b/extensions/dirvish-subtree.el
index 26bf775d8d..5c35d16de6 100644
--- a/extensions/dirvish-subtree.el
+++ b/extensions/dirvish-subtree.el
@@ -310,9 +310,8 @@ See `dirvish-subtree-file-viewer' for details"
(setq stop t)))
stop))
-(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."
+(defun dirvish-subtree-expand-to (target)
+ "Go to line describing TARGET and expand its parent directories."
(interactive
(list (directory-file-name (expand-file-name
(read-file-name "Expand to file: "
@@ -328,26 +327,20 @@ 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 sit))))
+ (dirvish-subtree-expand-to target))))
((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)
- ;; 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 sit))))
+ (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 sit)))))
+ (dirvish-subtree-expand-to target)))))
;;;###autoload
(defun dirvish-subtree-up ()