branch: elpa/dirvish commit b3bd1c1831c3488c11fa455f34ed69fb9c2131a3 Author: Alex Lu <hellosimon1...@hotmail.com> Commit: Alex Lu <hellosimon1...@hotmail.com>
refactor: keep track of special buffers --- dirvish-tramp.el | 4 +-- dirvish-widgets.el | 8 ++--- dirvish.el | 90 +++++++++++++++++++++++----------------------- extensions/dirvish-fd.el | 3 +- extensions/dirvish-peek.el | 2 +- extensions/dirvish-side.el | 4 +-- extensions/dirvish-vc.el | 4 +-- extensions/dirvish-yank.el | 56 ++++++++++++++--------------- 8 files changed, 81 insertions(+), 90 deletions(-) diff --git a/dirvish-tramp.el b/dirvish-tramp.el index df9e21a229..00e5b0095b 100644 --- a/dirvish-tramp.el +++ b/dirvish-tramp.el @@ -92,7 +92,7 @@ means DIR is in a remote host. Run `dirvish-setup-hook' after data parsing unless INHIBIT-SETUP is non-nil." (when (dirvish-tramp--async-p (dirvish-prop :tramp)) (let* ((process-connection-type nil) - (buf (dirvish--util-buffer (make-temp-name "dir-tramp-"))) + (buf (get-buffer-create (make-temp-name "tramp-data-"))) (cmd (format "ls -1lahi %s" (file-local-name dir))) (proc (start-file-process-shell-command (buffer-name buf) buf cmd))) (process-put proc 'meta (list dir buffer inhibit-setup)) @@ -105,7 +105,7 @@ parsing unless INHIBIT-SETUP is non-nil." '(info . "File preview is not supported in current connection") (let ((process-connection-type nil) (localname (file-remote-p file 'localname)) - (buf (dirvish--util-buffer 'preview dv nil t)) proc) + (buf (dirvish--special-buffer 'preview dv t)) proc) (when-let* ((proc (get-buffer-process buf))) (delete-process proc)) (setq proc (start-file-process-shell-command (buffer-name buf) buf diff --git a/dirvish-widgets.el b/dirvish-widgets.el index 41fdd0173b..3ded3d3b7a 100644 --- a/dirvish-widgets.el +++ b/dirvish-widgets.el @@ -284,7 +284,7 @@ A new directory is created unless NO-MKDIR." (pop dirvish-media--cache-pool))) (when path (setq proc (apply #'start-process procname - (dirvish--util-buffer "img-cache") cmd args)) + (get-buffer-create "*img-cache*") cmd args)) (process-put proc 'path path) (set-process-sentinel proc #'dirvish-media--cache-sentinel)))))) @@ -568,7 +568,7 @@ GROUP-TITLES is a list of group titles." (cl-defmethod dirvish-preview-dispatch ((recipe (head img)) dv) "Insert RECIPE as an image at preview window of DV." - (with-current-buffer (dirvish--util-buffer 'preview dv nil t) + (with-current-buffer (dirvish--special-buffer 'preview dv t) (let ((img (cdr recipe)) buffer-read-only) (erase-buffer) (remove-overlays) (insert " ") (add-text-properties 1 2 `(display ,img rear-nonsticky t keymap ,image-map)) @@ -601,14 +601,14 @@ GROUP-TITLES is a list of group titles." (cl-defmethod dirvish-preview-dispatch ((recipe (head cache)) dv) "Generate cache image according to RECIPE and session DV." (let* ((path (dirvish-prop :index)) - (buf (dirvish--util-buffer 'preview dv nil t)) + (buf (dirvish--special-buffer 'preview dv t)) (name (format "%s-%s-img-cache" path (window-width (dv-preview-window dv))))) (unless (get-process name) (setq dirvish-media--cache-pool (delete (assoc name dirvish-media--cache-pool) dirvish-media--cache-pool)) (let ((proc (apply #'start-process - name (dirvish--util-buffer "img-cache") + name (get-buffer-create "*img-cache*") (cadr recipe) (cddr recipe)))) (process-put proc 'path path) (set-process-sentinel proc #'dirvish-media--cache-sentinel))) diff --git a/dirvish.el b/dirvish.el index 65e44d12c5..3c4b393faa 100644 --- a/dirvish.el +++ b/dirvish.el @@ -234,7 +234,7 @@ runtime. Set it to nil disables this feature." :group 'dirvish :type '(alist :key-type (repeat :tag "File extensions" string) :value-type (repeat :tag "External command and args" string))) -(defcustom dirvish-reuse-session t +(defcustom dirvish-reuse-session 'open "Whether to keep the latest session index buffer for later reuse. The valid values are: - t: keep index buffer on both `dirvish-quit' and file open @@ -491,13 +491,11 @@ When NOTE is non-nil, append it the next line." 'display '(space :align-to right)) (propertize (if note (concat "\n" note) "") 'face 'font-lock-doc-face)))) -(defun dirvish--util-buffer (type &optional dv no-create inhibit-hiding) - "Return session DV's utility buffer of TYPE (defaults to `temp'). -If NO-CREATE is non-nil, do not create the buffer. +(defun dirvish--special-buffer (type dv &optional inhibit-hiding) + "Return session DV's utility buffer of TYPE. If INHIBIT-HIDING is non-nil, do not hide the buffer." - (let* ((id (if dv (format "-%s*" (dv-id dv)) "*")) - (name (format "%s*Dirvish-%s%s" (if inhibit-hiding "" " ") type id))) - (if no-create (get-buffer name) (get-buffer-create name)))) + (get-buffer-create + (format "%s*dirvish-%s@%s*" (if inhibit-hiding "" " ") type (dv-id dv)))) (defun dirvish--make-proc (form sentinel buffer-or-name &rest puts) "Make process for shell or batch FORM in BUFFER-OR-NAME. @@ -526,13 +524,14 @@ Set process's SENTINEL and PUTS accordingly." (ff-layout dirvish-default-layout :documentation "is a full-frame layout recipe.") (reuse () :documentation "indicates if DV has been reused.") (ls-switches dired-listing-switches :documentation "is the directory listing switches.") - (mode-line () :documentation "is the `mode-line-format' used by this DV.") + (mode-line () :documentation "is the `mode-line-format' used by DV.") (header-line () :documentation "is the `header-line-format' used by DV.") (preview-dispatchers () :documentation "is the working preview methods of DV.") (preview-hash (dirvish--ht) :documentation "is a hash-table to record content of preview files.") (parent-hash (dirvish--ht) :documentation "is a hash-table to record content of parent directories.") (attributes () :documentation "is the working attributes of DV.") (preview-buffers () :documentation "holds all file preview buffers of DV.") + (special-buffers () :documentation "holds all special buffers of DV e.g. mode-line buffer.") (preview-window () :documentation "is the window to display preview buffer.") (winconf () :documentation "is a saved window configuration.") (index () :documentation "is the (cwd-str . buf-obj) cons within ROOT-WINDOW.") @@ -583,9 +582,7 @@ FROM-QUIT is used to signify the calling command." when (not (eq b index)) do (kill-buffer b)) (when-let* ((wconf (dv-winconf dv))) (set-window-configuration wconf))) (mapc #'dirvish--kill-buffer (dv-preview-buffers dv)) - (cl-loop for b in (buffer-list) for bn = (buffer-name b) when - (string-match-p (format " ?\\*Dirvish-.*-%s\\*" (dv-id dv)) bn) - do (dirvish--kill-buffer b)) + (mapc #'dirvish--kill-buffer (dv-special-buffers dv)) (setf (dv-preview-hash dv) (dirvish--ht) (dv-parent-hash dv) (dirvish--ht) (dv-preview-buffers dv) nil (dv-winconf dv) nil) (when (or (null dirvish-reuse-session) @@ -738,7 +735,6 @@ buffer, it defaults to filename under the cursor when it is nil." (ansi-color-apply-on-region (goto-char pos) (progn (forward-line (frame-height)) (point))))) - (defun dirvish-update-body-h () "Update UI of Dirvish." (when-let* ((dv (dirvish-curr)) ((null (derived-mode-p 'wdired-mode)))) @@ -752,8 +748,8 @@ buffer, it defaults to filename under the cursor when it is nil." (dirvish--render-attrs) (when-let* ((filename (dired-get-filename nil t))) (dirvish-prop :index filename) - (let ((h-buf (dirvish--util-buffer 'header dv t)) - (f-buf (dirvish--util-buffer 'footer dv t))) + (let ((h-buf (dirvish--special-buffer 'header dv)) + (f-buf (dirvish--special-buffer 'footer dv))) (dirvish-debounce nil (when (dv-curr-layout dv) (when (buffer-live-p f-buf) @@ -787,10 +783,9 @@ buffer, it defaults to filename under the cursor when it is nil." (wconf (dv-winconf dv)) ((eq buf (window-buffer (selected-window))))) (set-window-configuration wconf)) - (remhash (dv-id dv) dirvish--session-hash) - (cl-loop for b in (buffer-list) for bn = (buffer-name b) when - (string-match-p (format " ?\\*Dirvish-.*-%s\\*" (dv-id dv)) bn) - do (dirvish--kill-buffer b))))) + (mapc #'dirvish--kill-buffer (dv-preview-buffers dv)) + (mapc #'dirvish--kill-buffer (dv-special-buffers dv)) + (remhash (dv-id dv) dirvish--session-hash)))) (defun dirvish-winbuf-change-h (window) "Rebuild layout once buffer in WINDOW changed." @@ -829,7 +824,7 @@ buffer, it defaults to filename under the cursor when it is nil." "Return preview buffer of FILE with SIZE in DV." (when (>= (length (dv-preview-buffers dv)) dirvish-preview-buffers-max-count) (dirvish--kill-buffer (frame-parameter nil 'dv-preview-last))) - (with-current-buffer (dirvish--util-buffer "temp") + (with-current-buffer (get-buffer-create "*preview-temp*") (let ((text (gethash file (dv-preview-hash dv))) info jka-compr-verbose) (with-silent-modifications (setq buffer-read-only t) @@ -915,14 +910,14 @@ buffer, it defaults to filename under the cursor when it is nil." (cl-defmethod dirvish-preview-dispatch ((recipe (head info)) dv) "Insert info string from RECIPE into DV's preview buffer." - (let ((buf (dirvish--util-buffer 'preview dv nil t))) + (let ((buf (dirvish--special-buffer 'preview dv t))) (with-current-buffer buf (let (buffer-read-only) (erase-buffer) (remove-overlays) (insert "\n\n " (cdr recipe)) buf)))) (cl-defmethod dirvish-preview-dispatch ((recipe (head buffer)) dv) "Use payload of RECIPE as preview buffer of DV directly." - (let ((p-buf (dirvish--util-buffer 'preview dv nil t))) + (let ((p-buf (dirvish--special-buffer 'preview dv t))) (with-current-buffer p-buf (let (buffer-read-only) (erase-buffer) (remove-overlays) (cdr recipe))))) @@ -932,10 +927,10 @@ When PROC finishes, fill preview buffer with process result." (when-let* ((dv (dirvish-curr)) (cmd-type (process-get proc 'cmd-info)) (str (with-current-buffer (process-buffer proc) (buffer-string)))) (if (eq cmd-type 'shell) - (with-current-buffer (dirvish--util-buffer 'shell dv nil t) + (with-current-buffer (dirvish--special-buffer 'shell dv t) (let (buffer-read-only) (erase-buffer) (remove-overlays) (insert str)) (dirvish-apply-ansicolor-h nil (point-min))) - (with-current-buffer (dirvish--util-buffer 'dired dv nil t) + (with-current-buffer (dirvish--special-buffer 'dired dv t) (let (buffer-read-only) (erase-buffer) (remove-overlays) (insert str)) (setq-local dired-subdir-alist (list (cons (car (dv-index dv)) (point-min-marker)))))) @@ -944,13 +939,13 @@ When PROC finishes, fill preview buffer with process result." (defun dirvish--run-shell-for-preview (dv recipe) "Dispatch shell cmd with RECIPE for session DV." (let ((proc (get-buffer-process (get-buffer " *dirvish-sh*"))) - (buf (dirvish--util-buffer (car recipe) dv nil t))) + (buf (dirvish--special-buffer (car recipe) dv t))) (when proc (delete-process proc)) (dirvish--make-proc (cdr recipe) 'dirvish-shell-preview-proc-s " *dirvish-sh*" 'cmd-info (car recipe)) (with-current-buffer buf - (let (buffer-read-only) (erase-buffer) (remove-overlays) buf)))) + (let (buffer-read-only) (erase-buffer) buf)))) (cl-defmethod dirvish-preview-dispatch ((recipe (head shell)) dv) "Fill DV's preview buffer with output of sh command from RECIPE." @@ -1127,7 +1122,7 @@ use `car'. If HEADER, use `dirvish-header-line-height' instead." ((and fullframe-p (not dirvish-use-header-line))) (fullframe-p (with-current-buffer idx-buf (setq header-line-format nil)) - (with-current-buffer (dirvish--util-buffer 'header dv) + (with-current-buffer (dirvish--special-buffer 'header dv) (setq header-line-format hl))) (dirvish-use-header-line (with-current-buffer idx-buf (setq header-line-format hl)))) @@ -1135,7 +1130,7 @@ use `car'. If HEADER, use `dirvish-header-line-height' instead." ((and fullframe-p (not dirvish-use-mode-line))) (fullframe-p (with-current-buffer idx-buf (setq mode-line-format nil)) - (with-current-buffer (dirvish--util-buffer 'footer dv) + (with-current-buffer (dirvish--special-buffer 'footer dv) (setq mode-line-format ml))) (dirvish-use-mode-line (with-current-buffer idx-buf (setq mode-line-format ml)))))) @@ -1208,7 +1203,7 @@ Dirvish sets `revert-buffer-function' to this function." "Create parent buffer at DIR in DV selecting file INDEX. LEVEL is the depth of current window." (let* ((index (directory-file-name index)) - (buf (dirvish--util-buffer (format "parent-%s" level) dv nil t)) + (buf (dirvish--special-buffer (format "parent-%s" level) dv t)) (str (or (gethash dir (dv-parent-hash dv)) (let ((flags dired-actual-switches)) (with-temp-buffer (dired-insert-directory dir flags) @@ -1218,6 +1213,7 @@ LEVEL is the depth of current window." (icon (cond ((memq 'all-the-icons attrs) '(all-the-icons)) ((memq 'nerd-icons attrs) '(nerd-icons)) ((memq 'vscode-icon attrs) '(vscode-icon))))) + (cl-pushnew buf (dv-special-buffers dv)) (with-current-buffer buf (dirvish-directory-view-mode) (dirvish-prop :dv (dv-id dv)) @@ -1256,19 +1252,21 @@ LEVEL is the depth of current window." for w = (display-buffer b `(dirvish--display-buffer . ,args)) do (with-selected-window w (set-window-dedicated-p w t)))))) -(defun dirvish--init-util-buffers (dv) - "Initialize util buffers for DV." - (with-current-buffer (dirvish--util-buffer 'preview dv nil t) - (dirvish-special-preview-mode)) - (with-current-buffer (dirvish--util-buffer 'shell dv nil t) - (dirvish-special-preview-mode) - (add-hook 'window-scroll-functions #'dirvish-apply-ansicolor-h nil t)) - (with-current-buffer (dirvish--util-buffer 'dired dv nil t) - (dirvish-directory-view-mode)) - (with-current-buffer (dirvish--util-buffer 'header dv) - (dirvish-misc-mode) (dirvish-prop :dv (dv-id dv))) - (with-current-buffer (dirvish--util-buffer 'footer dv) - (dirvish-misc-mode) (dirvish-prop :dv (dv-id dv)))) +(defun dirvish--init-special-buffers (dv) + "Initialize special buffers for DV." + (let ((dired (dirvish--special-buffer 'dired dv t)) + (regular (dirvish--special-buffer 'preview dv t)) + (shell (dirvish--special-buffer 'shell dv t)) + (head (dirvish--special-buffer 'header dv)) + (foot (dirvish--special-buffer 'footer dv))) + (with-current-buffer dired (dirvish-directory-view-mode)) + (with-current-buffer regular (dirvish-special-preview-mode)) + (with-current-buffer shell + (dirvish-special-preview-mode) + (add-hook 'window-scroll-functions #'dirvish-apply-ansicolor-h nil t)) + (with-current-buffer head (dirvish-misc-mode) (dirvish-prop :dv (dv-id dv))) + (with-current-buffer foot (dirvish-misc-mode) (dirvish-prop :dv (dv-id dv))) + (setf (dv-special-buffers dv) (list dired regular shell head foot)))) (defun dirvish--dir-data-async (dir buffer &optional inhibit-setup) "Asynchronously fetch metadata for DIR, stored locally in BUFFER. @@ -1334,7 +1332,7 @@ INHIBIT-SETUP is non-nil." (footer (side . below) (window-height . -2) (window-parameters . ((no-other-window . t)))))) (w-order (and layout (dirvish--window-split-order))) util-windows) - (dirvish--init-util-buffers dv) + (dirvish--init-special-buffers dv) (dirvish--setup-mode-line dv) (when w-order (let ((ignore-window-parameters t)) (delete-other-windows))) (dirvish-prop :fringe nil) @@ -1343,7 +1341,7 @@ INHIBIT-SETUP is non-nil." (when (or (dv-curr-layout dv) (dv-dedicated dv)) (set-window-dedicated-p nil t)) (dolist (pane w-order) - (let* ((buf (dirvish--util-buffer pane dv nil (eq pane 'preview))) + (let* ((buf (dirvish--special-buffer pane dv (eq pane 'preview))) (args (alist-get pane w-args)) (win (display-buffer buf `(dirvish--display-buffer . ,args)))) (cond ((eq pane 'preview) (setf (dv-preview-window dv) win)) @@ -1386,7 +1384,7 @@ INHIBIT-SETUP is non-nil." ;;;; Major modes -(define-derived-mode dirvish-directory-view-mode special-mode +(define-derived-mode dirvish-directory-view-mode special-mode "Dirvish DIRview" "Major mode for parent directory and directory preview buffer." (setq mode-line-format nil header-line-format nil font-lock-defaults @@ -1394,12 +1392,12 @@ INHIBIT-SETUP is non-nil." (font-lock-mode 1) :group 'dirvish :interactive nil) -(define-derived-mode dirvish-special-preview-mode special-mode +(define-derived-mode dirvish-special-preview-mode special-mode "Dirvish Special" "Major mode for info, shell command output and non-text file preview buffer." (setq mode-line-format nil header-line-format nil) :group 'dirvish :interactive nil) -(define-derived-mode dirvish-misc-mode special-mode +(define-derived-mode dirvish-misc-mode special-mode "Dirvish Misc" "Major mode for mode/header-line and other special buffers." (setq face-remapping-alist '((header-line-inactive header-line) (mode-line-inactive mode-line)) diff --git a/extensions/dirvish-fd.el b/extensions/dirvish-fd.el index b938236c72..08dd2795c5 100644 --- a/extensions/dirvish-fd.el +++ b/extensions/dirvish-fd.el @@ -424,7 +424,7 @@ The command run is essentially: (progn (dirvish dir) (dirvish--get-session 'type 'default)))) (fd-switches (or (dirvish-prop :fd-switches) dirvish-fd-switches "")) (ls-switches (or dired-actual-switches (dv-ls-switches dv))) - (buffer (dirvish--util-buffer 'fd dv nil t))) + (buffer (get-buffer-create (format "*fd@%s*" (current-time-string))))) (dirvish--kill-buffer (get-buffer (dirvish-fd--bufname pattern dir dv))) (with-current-buffer buffer (erase-buffer) @@ -462,7 +462,6 @@ The command run is essentially: (process-put proc 'info (list pattern dir dv)))) (dirvish-save-dedication (switch-to-buffer buffer)))) - ;;;###autoload (defun dirvish-fd-ask (dir pattern) "The same as `dirvish-fd' but ask initial DIR and PATTERN via prompt." diff --git a/extensions/dirvish-peek.el b/extensions/dirvish-peek.el index 77a8637117..097d4e7000 100644 --- a/extensions/dirvish-peek.el +++ b/extensions/dirvish-peek.el @@ -70,7 +70,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) (setq new-dv (dirvish--new :type 'peek)) - (dirvish--init-util-buffers new-dv) + (dirvish--init-special-buffers new-dv) ;; `dirvish-image-dp' needs this. (setf (dv-index new-dv) (cons default-directory (current-buffer))) (setf (dv-preview-window new-dv) diff --git a/extensions/dirvish-side.el b/extensions/dirvish-side.el index 3528775e57..e9b0be039e 100644 --- a/extensions/dirvish-side.el +++ b/extensions/dirvish-side.el @@ -87,7 +87,7 @@ filename until the project root when opening a side session." (defun dirvish-side-root-window-fn () "Create root window according to `dirvish-side-display-alist'." (let ((win (display-buffer-in-side-window - (dirvish--util-buffer "temp") + (get-buffer-create "*side-temp*") (append '((dedicated . t)) dirvish-side-display-alist)))) (cl-loop for (key . value) in dirvish-side-window-parameters do (set-window-parameter win key value)) @@ -149,7 +149,7 @@ filename until the project root when opening a side session." ;; so set the prop to let `dired-noselect' get `dirvish-curr' correctly (dirvish-prop :dv (dv-id dv)) (dirvish-find-entry-a path) - (kill-buffer (dirvish--util-buffer "temp")) ; remove `:dv' prop in it + (kill-buffer (get-buffer "*side-temp*")) ; remove `:dv' prop in it (cond ((not bname) nil) (dirvish-side-auto-expand (dirvish-subtree-expand-to bname)) diff --git a/extensions/dirvish-vc.el b/extensions/dirvish-vc.el index 52dbfce97d..df45ef4ca1 100644 --- a/extensions/dirvish-vc.el +++ b/extensions/dirvish-vc.el @@ -216,7 +216,6 @@ This attribute only works on graphic displays." "Use output of `vc-annotate' (file) or `vc-dir' (dir) as preview." (when-let* ((bk (dirvish-prop :vc-backend)) ((symbolp bk)) - (orig-buflist (buffer-list)) (display-buffer-alist '(("\\*\\(Annotate \\|vc-dir\\).*\\*" (display-buffer-same-window))))) @@ -231,8 +230,7 @@ This attribute only works on graphic displays." file)) (f-buf (cdr (dirvish--find-file-temporarily file))) ((bufferp f-buf))) - (unless (memq f-buf orig-buflist) - (push f-buf (dv-preview-buffers dv))) + (cl-pushnew f-buf (dv-preview-buffers dv)) (with-selected-window preview-window (with-current-buffer f-buf (cl-letf (((symbol-function 'message) #'ignore)) diff --git a/extensions/dirvish-yank.el b/extensions/dirvish-yank.el index cb14244493..76e5070e42 100644 --- a/extensions/dirvish-yank.el +++ b/extensions/dirvish-yank.el @@ -146,28 +146,25 @@ RANGE can be `buffer', `session', `all'." (when (memq status '(exit signal)) (if (and success (not dirvish-yank-keep-success-log)) (kill-buffer proc-buf) - (let ((comp-buffer (dirvish--util-buffer "complete-yank-log" nil nil t))) - (with-current-buffer comp-buffer - (goto-char (point-max)) - (insert "\n\n" (format "%s" method) - " finished @ " (current-time-string) "\n") - (insert-buffer-substring proc-buf) - (kill-buffer proc-buf) - ;; truncate old logs - (save-excursion - (delete-region - (point-min) - (let ((max (point-max))) - (if (< max 20000) - (point-min) - (goto-char max) - (dotimes (_n 40) (backward-paragraph)) - (point))))) - (unless success - (message "Yank finished with an error: see buffer %s for details" - comp-buffer) - (pop-to-buffer comp-buffer))))) - (setq dirvish-yank-log-buffers (remove proc-buf dirvish-yank-log-buffers)) + (with-current-buffer (get-buffer-create "*dirvish-yank-log*") + (goto-char (point-max)) + (insert "\n\n" (format "%s" method) + " finished @ " (current-time-string) "\n") + (insert-buffer-substring proc-buf) + (kill-buffer proc-buf) + ;; truncate old logs + (save-excursion + (delete-region + (point-min) + (let ((max (point-max))) + (if (< max 20000) + (point-min) + (goto-char max) + (dotimes (_n 40) (backward-paragraph)) + (point))))) + (unless success + (message "Task FAILED with exit code %s" (process-exit-status proc)) + (pop-to-buffer (current-buffer))))) (when (eq buffer (current-buffer)) (with-current-buffer buffer (revert-buffer) (dirvish-update-body-h)))))) @@ -213,14 +210,16 @@ is t." (defun dirvish-yank--start-proc (cmd details) "Start a new process for CMD, put DETAILS into the process." - (let* ((process-connection-type nil) - (name "*dirvish-yank*") - (buf (dirvish--util-buffer - (format "yank@%s" (current-time-string)) nil nil t)) + (let* ((process-connection-type nil) (name "*dirvish-yank*") + (buf (get-buffer-create (format "*yank@%s*" (current-time-string)))) + (fn (lambda () (setq dirvish-yank-log-buffers + (delete buf dirvish-yank-log-buffers)))) (proc (if (listp cmd) (make-process :name name :buffer buf :command cmd) (start-process-shell-command name buf cmd)))) - (with-current-buffer buf (dirvish-prop :yank-details details)) + (with-current-buffer buf + (add-hook 'kill-buffer-hook fn nil t) ; user may kill yank buffers + (dirvish-prop :yank-details details)) (process-put proc 'details details) (set-process-sentinel proc #'dirvish-yank-proc-sentinel) (set-process-filter proc #'dirvish-yank-proc-filter) @@ -351,9 +350,6 @@ It sets the value for every variable matching INCLUDE-REGEXP." (dirvish-define-mode-line yank "Progress of yank tasks." - (setq dirvish-yank-log-buffers - (cl-remove-if-not ; user may kill yank buffers - (lambda (buf) (buffer-live-p buf)) dirvish-yank-log-buffers)) (let ((number-of-tasks (length dirvish-yank-log-buffers))) (cond ((= number-of-tasks 0)) ((= number-of-tasks 1)