branch: elpa/dirvish commit 19dbbc5865d2dc8f6a014969843d8b8345033336 Author: dvzubarev <dvzuba...@yandex.ru> Commit: GitHub <nore...@github.com>
split dirvish-yank--execute into two functions (#290) It could be useful for overriding the code that creates external process for actual yank operations (rsync or copy/move). For example, I override new method (dirvish-yank--start-proc) in my fork of detached.el library. It allows me to detach execution of rsync command from the Emacs instance. Also detached.el provides better monitoring and alerting facilities. --- extensions/dirvish-yank.el | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/extensions/dirvish-yank.el b/extensions/dirvish-yank.el index d1c22ae08c..04fd1fa559 100644 --- a/extensions/dirvish-yank.el +++ b/extensions/dirvish-yank.el @@ -257,26 +257,36 @@ RANGE can be `buffer', `session', `all'." (if moving (goto-char (process-mark proc))))))))) (defun dirvish-yank--execute (cmd details &optional batch) - "Execute CMD, put DETAILS into the process. -When BATCH, execute the command using `emacs -q -batch'." - (pcase-let* ((process-connection-type nil) (name "*dirvish-yank*") - (buf (dirvish--util-buffer - (format "yank@%s" (current-time-string)) nil nil t)) - (`(,_ ,_ ,dest ,_) details) - (proc (if batch - (let* ((q (if (file-remote-p dest) "-q" "-Q")) - (c (list dirvish-emacs-bin q "-batch" "--eval" cmd))) - (make-process :name name :buffer buf :command c)) - (start-process-shell-command name buf cmd)))) - (with-current-buffer buf (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) + "Handle execution of CMD. +When BATCH, execute the command using `emacs -q -batch'. Propagate +DETAILS to the process. Remove markers when `dirvish-yank-auto-unmark' +is t." + (pcase-let* ((`(,_ ,_ ,dest ,_) details) + (command (if batch + (let ((q (if (file-remote-p dest) "-q" "-Q"))) + (list dirvish-emacs-bin q "-batch" "--eval" cmd)) + cmd))) + + (dirvish-yank--start-proc command details) (when dirvish-yank-auto-unmark (cl-loop for buf in (buffer-list) do (with-current-buffer buf (when (eq major-mode 'dired-mode) - (dired-unmark-all-marks))))) + (dired-unmark-all-marks))))))) + +(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)) + (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)) + (process-put proc 'details details) + (set-process-sentinel proc #'dirvish-yank-proc-sentinel) + (set-process-filter proc #'dirvish-yank-proc-filter) (push buf dirvish-yank-log-buffers))) (defun dirvish-yank--newbase (base-name fileset dest)