From f3b9f4a4fa754aa09517345cfcafb7e2937ffa77 Mon Sep 17 00:00:00 2001 From: Gerard Vermeulen Date: Tue, 3 May 2022 09:34:20 +0200 Subject: [PATCH] Cleanup my extra key bindings for dired code --- README.org | 66 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/README.org b/README.org index 002aeb5..47d6272 100644 --- a/README.org +++ b/README.org @@ -447,42 +447,44 @@ by experienced Emacs users. #+name: lst:extra-dired-key-bindings #+begin_src emacs-lisp (with-eval-after-load 'dired - (define-key - dired-mode-map (kbd "E") - (defun my-dired-eww-find-file () - "Visit dired file with eww." - (interactive) - (eww-open-file (dired-get-file-for-visit)))) + (defun dired-eww-open-file () + "In Dired, open the regular file named on this line with eww" + (interactive) + (let ((file (dired-get-file-for-visit))) + (if (file-regular-p file) + (eww-open-file file) + (error "Eww rejects `%s', since it is not a regular file" file)))) ;; https://truongtx.me/tmtxt-dired-async.html - (define-key - dired-mode-map (kbd "Y") - (defun my-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'. + (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:\\(.*\\)$" 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))))) + (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))) + + (define-key dired-mode-map (kbd "E") #'dired-eww-open-file) + (define-key dired-mode-map (kbd "Y") #'dired-rsync)) #+end_src ** [[info:elisp#Processes][Processes (info)]]