branch: elpa/dirvish commit 913922ea2af1c38928f8303be914187adc54993e Author: Alex Lu <hellosimon1...@hotmail.com> Commit: Alex Lu <hellosimon1...@hotmail.com>
refactor: rename `dirvish-new/kill` --- dirvish.el | 38 +++++++++++++++++++------------------- extensions/dirvish-peek.el | 4 ++-- extensions/dirvish-side.el | 6 +++--- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/dirvish.el b/dirvish.el index a953311760..47e1ec5e96 100644 --- a/dirvish.el +++ b/dirvish.el @@ -487,16 +487,7 @@ If INHIBIT-HIDING is non-nil, do not hide the buffer." (index () :documentation "is the current (cwd-str . buffer-obj) cons within ROOT-WINDOW.") (roots () :documentation "is all the history INDEX entries in DV.")) -(defun dirvish--find-reusable (&optional type) - "Return the first matched reusable session with TYPE." - (when dirvish-reuse-session - (cl-loop with scopes = (dirvish--scopes) - for dv in (hash-table-values dirvish--session-hash) - when (and (eq type (dv-type dv)) - (equal (dv-scopes dv) scopes)) - collect dv))) - -(defun dirvish-new (&rest args) +(defun dirvish--new (&rest args) "Create and save a new dirvish struct to `dirvish--session-hash'. ARGS is a list of keyword arguments for `dirvish' struct." (let (slots new) @@ -506,8 +497,17 @@ ARGS is a list of keyword arguments for `dirvish' struct." (dirvish--check-deps) (dirvish--create-root-window new) new)) -(defun dirvish-kill (dv) - "Kill the dirvish instance DV." +(defun dirvish--find-reusable (&optional type) + "Return the first matched reusable session with TYPE." + (when dirvish-reuse-session + (cl-loop with scopes = (dirvish--scopes) + for dv in (hash-table-values dirvish--session-hash) + when (and (eq type (dv-type dv)) + (equal (dv-scopes dv) scopes)) + collect dv))) + +(defun dirvish--clear-session (dv) + "Reset DV's slot and kill its buffers." (let ((index (cdr (dv-index dv)))) (if (not (dv-curr-layout dv)) (cl-loop for (_d . b) in (dv-roots dv) @@ -669,7 +669,7 @@ buffer, it defaults to filename under the cursor when it is nil." (if ex (apply #'start-process "" nil "nohup" (cl-substitute file "%f" ex :test 'string=)) (let* ((dv (dirvish-curr)) (fn (dv-open-file-fn dv))) - (if fn (funcall fn) (dirvish-kill dv))) + (if fn (funcall fn) (dirvish--clear-session dv))) (find-file file)))))) (defun dirvish-insert-subdir-a (dirname &rest _) @@ -705,8 +705,8 @@ buffer, it defaults to filename under the cursor when it is nil." (let* ((dir (if (consp dir-or-list) (car dir-or-list) dir-or-list)) (key (file-name-as-directory (expand-file-name dir))) (this dirvish--this) - (dv (if (and this (eq this-command 'dired-other-frame)) (dirvish-new) - (or this (car (dirvish--find-reusable)) (dirvish-new)))) + (dv (if (and this (eq this-command 'dired-other-frame)) (dirvish--new) + (or this (car (dirvish--find-reusable)) (dirvish--new)))) (bname buffer-file-name) (remote (file-remote-p dir)) (flags (or flags (dv-ls-switches dv))) @@ -990,7 +990,7 @@ If HEADER, set the `dirvish--header-line-fmt' instead." (setq str-r (format-mode-line (funcall expand ',right) nil nil buf)) (setq len-r (string-width str-r))) (concat - (dirvish--bar-image fullframe-p ,header) + (dirvish--mode-line-bar-img fullframe-p ,header) (if (< (+ (string-width str-l) len-r) win-width) str-l (let ((trim (1- (- win-width len-r)))) @@ -1003,7 +1003,7 @@ If HEADER, set the `dirvish--header-line-fmt' instead." str-r))))) ;; Thanks to `doom-modeline'. -(defun dirvish--bar-image (fullframe-p header) +(defun dirvish--mode-line-bar-img (fullframe-p header) "Create a bar image with height of `dirvish-mode-line-height'. If FULLFRAME-P, use the `cdr' of the value as height, otherwise use `car'. If HEADER, use `dirvish-header-line-height' instead." @@ -1272,7 +1272,7 @@ Run `dirvish-setup-hook' afterwards when SETUP is non-nil." (if (or path (not (eq dirvish-reuse-session 'resume))) dir (car (dv-index dv)))) (dirvish--init-session dv))) - (t (dirvish-new :curr-layout layout) + (t (dirvish--new :curr-layout layout) (dirvish-find-entry-a dir))))) (define-derived-mode dirvish-directory-view-mode @@ -1292,7 +1292,7 @@ the selected window are buried." (interactive) (let ((dv (dirvish-curr)) (ct 0) (lst (window-list)) (win (selected-window)) (frame (selected-frame))) - (dirvish-kill dv) + (dirvish--clear-session dv) (while (and (dirvish-curr) (eq (selected-window) win) (<= (cl-incf ct) (length lst))) (quit-window)) diff --git a/extensions/dirvish-peek.el b/extensions/dirvish-peek.el index 2843d1b7ab..1ec9a9805e 100644 --- a/extensions/dirvish-peek.el +++ b/extensions/dirvish-peek.el @@ -68,7 +68,7 @@ one of categories in `dirvish-peek-categories'." (add-hook 'post-command-hook #'dirvish-peek-update-h 90 t) (add-hook 'minibuffer-exit-hook #'dirvish-peek-exit-h nil t) (unless (and dirvish--this (dv-preview-window dirvish--this)) - (setq new-dv (dirvish-new :type 'peek)) + (setq new-dv (dirvish--new :type 'peek)) (setf (dv-preview-window new-dv) (or (minibuffer-selected-window) (next-window))))))) @@ -93,7 +93,7 @@ one of categories in `dirvish-peek-categories'." "Hook for `minibuffer-exit-hook' to destroy peek session." (dolist (dv (hash-table-values dirvish--session-hash)) (when (eq (dv-type dv) 'peek) - (dirvish-kill dv) + (dirvish--clear-session dv) (remhash (dv-name dv) dirvish--session-hash)))) ;;;###autoload diff --git a/extensions/dirvish-side.el b/extensions/dirvish-side.el index ee962f3219..f8ebfb57e3 100644 --- a/extensions/dirvish-side.el +++ b/extensions/dirvish-side.el @@ -62,9 +62,9 @@ filename until the project root when opening a side session." "Called before opening a file in side sessions." (let* ((dv (dirvish-curr)) (layout (dv-curr-layout dv)) (mru (get-mru-window nil nil t))) - (if layout (dirvish-kill dv) + (if layout (dirvish--clear-session dv) (when dirvish-side-auto-close - (dirvish-kill dv) + (dirvish--clear-session dv) (when dirvish-reuse-session (quit-window))) (select-window (cond ((functionp dirvish-side-open-file-action) (funcall dirvish-side-open-file-action)) @@ -127,7 +127,7 @@ filename until the project root when opening a side session." "Open a side session in PATH." (let* ((bname buffer-file-name) (dv (or (car (dirvish--find-reusable 'side)) - (dirvish-new + (dirvish--new :type 'side :size-fixed 'width :dedicated t