branch: elpa/dirvish commit 9f440435bf146ce23939a20cc06a1f73ff71d017 Author: Alex Lu <hellosimon1...@hotmail.com> Commit: Alex Lu <hellosimon1...@hotmail.com>
refactor: add `dirvish--switch-to-buffer` helper --- dirvish-extras.el | 2 +- dirvish.el | 13 ++++++++++--- extensions/dirvish-fd.el | 11 ++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dirvish-extras.el b/dirvish-extras.el index d30a4c95be..b7be70d3b4 100644 --- a/dirvish-extras.el +++ b/dirvish-extras.el @@ -228,7 +228,7 @@ possibly one or more parent windows." (with-selected-window (dv-root-window dv) (quit-window))) (setcar (dv-layout dv) new-layout) (with-selected-window (dirvish--create-root-window dv) - (switch-to-buffer buf) + (dirvish--switch-to-buffer buf) (dirvish--init-session dv)))) ;;;###autoload diff --git a/dirvish.el b/dirvish.el index 733243a86a..e8c974747f 100644 --- a/dirvish.el +++ b/dirvish.el @@ -396,6 +396,13 @@ ALIST is window arguments passed to `window--display-buffer'." (new-window (split-window-no-error nil size side))) (window--display-buffer buffer new-window 'window alist))) +(defun dirvish--switch-to-buffer (buffer) + "Switch to BUFFER with window undedicated." + (let ((dedicated (window-dedicated-p)) (win (selected-window))) + (set-window-dedicated-p win nil) + (prog1 (switch-to-buffer buffer) + (set-window-dedicated-p win dedicated)))) + (defun dirvish--kill-buffer (buffer) "Kill BUFFER without side effects." (and (buffer-live-p buffer) @@ -641,7 +648,7 @@ buffer, it defaults to filename under the cursor when it is nil." ((string-suffix-p "/" entry) (user-error (concat entry " is not a valid directory")))))) - (if buffer (switch-to-buffer buffer) + (if buffer (dirvish--switch-to-buffer buffer) (let* ((ext (downcase (or (file-name-extension entry) ""))) (file (expand-file-name entry)) (process-connection-type nil) @@ -677,7 +684,7 @@ buffer, it defaults to filename under the cursor when it is nil." (when-let* ((dv dirvish--this) ((dv-preview-window dv))) (dirvish--init-session dv) (with-selected-window (dv-preview-window dv) - (switch-to-buffer image-dired-thumbnail-buffer))) + (dirvish--switch-to-buffer image-dired-thumbnail-buffer))) (let ((buf (funcall fn)) (fun (lambda () (let ((buf (get-text-property (point) 'associated-dired-buffer))) @@ -785,7 +792,7 @@ When FORCE, ensure the preview get refreshed." (let* ((w (frame-selected-window)) (b (window-buffer w)) (dv (dirvish-curr))) (cond ((and dv (minibufferp (window-buffer dirvish--selected-window))) (with-selected-window (dirvish--create-root-window dv) - (switch-to-buffer b) + (dirvish--switch-to-buffer b) (dirvish--init-session dv))) ((active-minibuffer-window)) (t (setq dirvish--this dv))) diff --git a/extensions/dirvish-fd.el b/extensions/dirvish-fd.el index 20eee8c7b1..2c5b617efd 100644 --- a/extensions/dirvish-fd.el +++ b/extensions/dirvish-fd.el @@ -197,13 +197,6 @@ Raise an error if fd executable is not available." ("r" dirvish-fd--search-pattern-infix) ("RET" "Apply switches" dirvish-fd--apply-switches)]]) -(defun dirvish-fd-switch-to-buffer (buffer) - "Switch to BUFFER with window undedicated." - (let ((dedicated (window-dedicated-p)) (win (selected-window))) - (set-window-dedicated-p win nil) - (prog1 (switch-to-buffer buffer) - (set-window-dedicated-p win dedicated)))) - (defun dirvish-fd--argparser (args) "Parse fd args to a list of flags from ARGS." (let* ((globp (member "--glob" args)) @@ -347,7 +340,7 @@ value 16, let the user choose the root directory of their search." (message "`fd' process terminated"))) (with-selected-window (dv-root-window dv) (unless (eq (current-buffer) buf) - (dirvish-fd-switch-to-buffer buf))) + (dirvish--switch-to-buffer buf))) (with-current-buffer buf (setq-local dirvish-fd--input input dirvish-fd--output (dirvish-fd--parse-output) @@ -459,7 +452,7 @@ The command run is essentially: (set-process-sentinel proc #'dirvish-fd-proc-sentinel) (dirvish-fd--argparser (split-string (or fd-switches ""))) (process-put proc 'info (list pattern dir dv)))) - (dirvish-fd-switch-to-buffer buffer))) + (dirvish--switch-to-buffer buffer))) ;;;###autoload