Finish the dired setup and its documentation

* Describe a dired based work-flow for inserting image file org-mode
  links.
* Finish the dired and wdired customization.
* Add dired key-bindings to open files in eww and to copy marked files
  to local or remote directories by means of rsync.
This commit is contained in:
Gerard Vermeulen 2022-02-06 13:03:59 +01:00
parent fc2a31d20c
commit 5f3a52bc96
1 changed files with 82 additions and 1 deletions

View File

@ -342,6 +342,30 @@ background.
:CUSTOM_ID: sec:file-manager
:END:
[[info:emacs#Dired][Dired (info)]] and the [[https://github.com/ranger/ranger#readme][ranger]] file manager offer similar capabilities for copying,
deleting, opening, renaming, and viewing files and directories, but the
integration of [[info:emacs#Dired][dired (info)]] in Emacs is obviously much better than the
integration of [[https://github.com/ranger/ranger#readme][ranger]] in Emacs.
For instance, this setup allows to insert an =org-mode= link to an poorly
identified file containing a specific image into an =org-mode= buffer by means
of the facilities of [[info:emacs#Dired][dired (info)]] as follows:
1. Type {{{kbd(C-x d)}}} to open the directory containing the pooly identified
file with the specific image in a =dired-mode= buffer.
2. Start searching for the specific image by navigating to the name of any image
file.
3. Type {{{kbd(v)}}} to switch to view the file in an =image-mode= buffer.
4. In the =image-mode= buffer, continue searching for the specific image by
typing:
- {{{kbd(n)}}} to view the next image in the =dired-mode= buffer,
- {{{kbd(p)}}} to view the previous image in the =dired-mode= buffer, and
- {{{kbd(q)}}} to quit the =image-mode= buffer and to go back to the
=dired-mode= buffer.
5. After finding the specific image, use {{{kbd(C-c l)}}} in the =image-mode=
buffer or the =dired-mode= buffer to store the =org-link=.
6. Switch to the =org-mode= buffer and use {{{kbd(C-c C-l)}}} to insert the
=org-link= into the buffer.
Listing [[lst:customize-dired]] makes the directory editor sort entries
alphabetically after grouping the directories before grouping the files by
extension.
@ -352,6 +376,7 @@ extension.
#+begin_src emacs-lisp
(with-eval-after-load 'dired
(custom-set-variables
'(dired-dwim-target t)
;; | switch | action |
;; |--------+----------------------------------------|
;; | -a | also list hidden entries |
@ -359,15 +384,71 @@ extension.
;; | -X | sort alphabetically by entry extension |
;; | -G | skip long listing format group names |
;; | -1 | list one entry per line |
'(dired-listing-switches "-alGX1 --group-directories-first")))
'(dired-listing-switches "-alGX1 --group-directories-first")
'(dired-recursive-copies 'always)
'(dired-recursive-deletes 'always)))
(with-eval-after-load 'files
(custom-set-variables
;; Ensure the use of `GNU-ls' from `coreutils' on darwin.
'(insert-directory-program (or (executable-find "gls")
(executable-find "ls")))))
(with-eval-after-load 'wdired
(custom-set-variables
'(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.
#+caption[Extra =dired= key bindings]:
#+caption: Extra =dired= key bindings.
#+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))))
;; 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'.
(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)))))
#+end_src
* [[info:emacs#Package Installation][Install the selected packages (info)]]
:PROPERTIES:
:CUSTOM_ID: sec:install-selected-packages