From 59562a0d3dd48615446479bbd6a5d95acb097748 Mon Sep 17 00:00:00 2001 From: Gerard Vermeulen Date: Mon, 22 Jan 2024 13:07:17 +0100 Subject: [PATCH] Tweak `dired': try switching to `dired-async' --- README.org | 48 ++++++++++++------------------------------------ 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/README.org b/README.org index e337bca..ab6fc25 100644 --- a/README.org +++ b/README.org @@ -991,13 +991,11 @@ extension. (setopt wdired-allow-to-change-permissions t)) #+end_src -Listing [[lst:extra-dired-key-bindings]] adds new key bindings to =dired-mode-map= to: -1. Open files with the [[https://en.wikipedia.org/wiki/Eww_(web_browser)][Emacs Web Wowser]] inside Emacs. -2. Let [[https://en.wikipedia.org/wiki/Rsync][rsync]] copy marked files outside Emacs to a local or remote directory. -The link [[https://truongtx.me/tmtxt-dired-async.html][asynchoronous execution library for Emacs Dired]] is the original source -for the idea of using [[https://en.wikipedia.org/wiki/Rsync][rsync]] and the blog articles [[https://oremacs.com/2016/02/24/dired-rsync/][using rsync in dired]] and -[[https://vxlabs.com/2018/03/30/asynchronous-rsync-with-emacs-dired-and-tramp/][asynchronous rsync with Emacs, dired and tramp]] are vivid recommendations written -by experienced Emacs users. +Listing [[lst:extra-dired-key-bindings]] adds a new key binding to =dired-mode-map= +to open files with the [[https://en.wikipedia.org/wiki/Eww_(web_browser)][Emacs Web Wowser]] inside Emacs and implements asynchronous +file copying using the src_emacs-lisp{(find-library "dired-async")} library +under the hood. *NOTE:* [[https://github.com/stsquad/dired-rsync#dired-rsync--asynchronous-rsync-from-dired][asynchronous rsync from dired]] may be a better +alternative. #+caption[Extra =dired= key bindings]: #+caption: Extra =dired= key bindings. @@ -1012,36 +1010,14 @@ by experienced Emacs users. (eww-open-file file) (error "Eww rejects `%s', since it is not a regular file" file)))) - ;; https://truongtx.me/tmtxt-dired-async.html - (defun dired-rsync (target) - "Copy marked files with `rsync' to TARGET directory." - (interactive - (list (expand-file-name - (read-file-name "Rsync to:" (dired-dwim-target-directory))))) - ;; Store all marked files into the `files' list and intialize - ;; the `rsync-command'. - (let ((files (dired-get-marked-files nil current-prefix-arg)) - (rsync-command "rsync -av --progress ")) - ;; Add all marked files as arguments to the `rsync-command'. - (dolist (file files) - (setq rsync-command - (concat rsync-command - (if (string-match "^/ssh:\\(.*\\)$" file) - (format " -e ssh %s" (match-string 1 file)) - (shell-quote-argument file)) " "))) - ;; Append the destination directory to the `rsync-command'. - (setq rsync-command - (concat rsync-command - (if (string-match "^/ssh:\\(.*\\)$" target) - (format " -e ssh %s" (match-string 1 target)) - (shell-quote-argument target)))) - ;; Run the async shell command. - (async-shell-command rsync-command) - ;; Finally, switch to that window. - (other-window 1))) + (keymap-set dired-mode-map "E" #'dired-eww-open-file)) - (keymap-set dired-mode-map "E" #'dired-eww-open-file) - (keymap-set dired-mode-map "Y" #'dired-rsync)) +(when (require 'dired-async nil 'noerror) + ;; Does this fails? Or is it too fast? + ;; Fix this later, but rsync works from zsh. + ;; https://www.emacs.dyerdwelling.family/emacs/ + ;; https://www.reddit.com/r/emacs/comments/g0jkkj/using_dired_asynchronously/ + (setopt dired-async-small-file-max 5000000)) #+end_src * [[info:emacs#Completion Styles][Minibuffer completion styles (info)]]