私のEmacs設定 (Dired)
My Emacs Configuration (Dired) (eugene-andrienko.com)
要約
この記事は、Emacsのファイルブラウザ機能であるDiredの設定と日常的な使い方について解説しています。コマンドラインツールやMidnight Commanderからの移行、Diredの起動方法、ファイル操作(マーク、フラグ、リネーム)、外部プログラム連携、テスト方法などが詳細に説明されています。
全文翻訳
My Emacs configuration (Dired)
A calendar icon
05 Jul 2026
Table of Contents
- Preamble
- Calling the Dired
- File operations
- External programs
- Dired and photos/images
- Emacs-specific things
- Configuration overview
- Download
- Notes
This blog post is a part of the series of posts about my Emacs configuration. Previous posts:
Here I will be dedicated to the configuration, and my habits, and usual actions during the Dired usage. I decided not to just describe configuration and that's all — you could read a lot of likewise blogposts already. Instead of it I also would like to describe how I am using Dired every day.
Little explanation about Dired for readers, who didn't use it before. It is a program for Emacs which works as a powerful file browser, which treats your precious files and directories as an (almost) usual Emacs buffer — so you can navigate through and work with you catalogs using the same "emacs-habits".
[画像: Emacs with two Dired windows opened. There are list of catalogs with my blogposts about it in the left window, and the window with catalogs and file for all my blogposts about photography.]
Figure 1: Two Dired windows opened in the Emacs.
Preamble
Since, I tend to use a kinda minimalist environment for computing — first, I used a CLI (bash then zsh) for the most of the operations with files and catalogs. It works well, but I wanted to have some interactivity — copy/move some files from one catalog to another catalog without issuing multiple cp commands1, view contents of one directory while browsing another catalogs, like in Midnight Commander, etc.
Some time I used the mentioned mc and it went well. But I wanted more — preview images, etc — and the Midnight Commander was unable to help me with this, since it doesn't have plugins like Far. Yes, it has a good menu, binded to F2 key, able to display various commands for various file types. But it wasn't enough for me.
So, by the way, I decided to give Dired a try — since it is already installed with almost every Emacs distribution. And things went so well, that I'm staying with the Dired now.
Calling the Dired
Usually I'm invoking the Dired in two ways. First, if I'm working with some project2, I press C-x p d hotkey and type some letters to jump into the desired catalog inside the project.
E.g. if I work with my dotfiles and want to open directory configs I type:
C-x p d configs <RET>
[画像: Emacs minibuffer with autocompletion of "configs" string with path "utils/emacs/.emacs.d/configs/"]
And fall into the desired catalog:
[画像: Directory "~/git_repos/dotfiles/utils/emacs/.emacs.d/configs/" opened in the Dired.]
If I want just to open the root catalog of the project — I use C-x p D keybinding instead.
Second, my beloved, method — the C-x C-j keybinding3. It opens the Dired buffer in the current working directory. For example, if I want to work with files for my blogpost, while I'm editing the post itself — I just press C-x C-j and buffer with article's Org file and images opens:
[画像: Emacs Dired buffer after pressing C-x C-j while editing article.org file]
Figure 2: After C-x C-j press while editing the article.org file
Of course, there are some other methods to invoke the Dired, which I'm using. For example the default C-x d keybinding, which I rebinded to C-x C-d for convenience:
(keymap-global-set "C-x C-d" 'dired)
[画像: Emacs asks about path in the minibuffer after pressing C-x C-d. There are some autocompletion, suggesting catalogs in the "~/git_repos/" for me.]
I'm using this keybinding most of the time, when I want just to open some directory, local or remote (with the help of TRAMP). E.g. this is how I could open bin catalog on the not so remote server server.example.com with the username user account:
C-x C-d /ssh:username@server.example.com:~/bin
^
- After entering this colon, the GnuGP will ask me about my
password for private key, to decipher ~/.authinfo.gpg with
username's password for server.example.com.
Also, in my system the Emacs frame with Dired buffer could be opened from any program which could open the file manager — e.g. after downloading file in Librewolf, I could press the folder icon in the "Downloads" drop-down menu and the Emacs frame with Dired buffer for directory with my downloaded file will be opened:
[画像: File, downloaded via Librewolf and it's location opened in Emacs]
I already described how to setup Emacs as a default file manager here: Emacs Dired as a default file manager.
File operations
Usual file operations: copying, moving or removing sets of files — are pretty simple. "Just" mark some files with m keybinding and copy/move them (see the 32.7 Operating on Files in the Emacs Manual).
[画像: Dired buffer with 5 files, 3 files are marked and has purple bold face.]
I placed just in the quotes, because there is not only m keybinding to mark files. There are a lot of ways to do so — look at the 32.6 Dired Marks vs. Flags section from Emacs manual. Most of the time I'm using the next ways to mark some files:
| Keybinding | Description |
|---|---|
| * s | Mark all files and catalogs |
| * . | Mark files with the specified extension |
| % m | Mark files with names matched by regexp |
| U | Remove all marks |
| t | Toggle marks |
For example, I'm using * . to mark unwanted files by it's extension and delete them. E.g. to delete all web-pee images: * . webp RET D y RET. Neat thing: if cursor already on the line with WEBP image, then the * . RET D y RET is enough, the webp part is preselected by default.
By the way, these long "keybindings" are not real — there are two separate keybindings (. * and D), my answer for the prompt about file extension to select, and answer for the file deletion confirmation.
Or another example: if I want to convert all WEBP images to the JPG (I dislike WEBP as a corporate image format, to be honest), then I'll do it in the next way:
- Press
* .on the line with the WEBP image, and pressRET. - At this point all WEBP files in the directory are selected.
- Then I press
!and pressM-nfew time to scroll to the mine (previously saved) special commands for images. - When the
gm convert ? `?`.jpgcommand is selected — I press Enter - And after some waiting, all WEBP files converted to JPEG with GraphicsMagick. Unwanted WEBP files could be deleted as described above.
[画像: The slideshow with the process of files selection and calling gm convert for them in Dired.]
You may wonder — how I define gm convert command for image files? The answer is in the External programs section.
Another favorite keybinding is the % m — with the power of regular expressions I'm finally able to select any files in some catalog in a very tricky way — this is a thing that I was missing while using CLI or mc for file operations. IIRC, the mc allows to select files by regexp, but in Dired this feature a way richer.
Here the synthetic example, where I'm selecting image files starting from e6f substring and ending with .webp or .webp.SOME_3_LETTER_EXTEN — with the help of ^e6f.+\.webp\.?([a-z]\\{3\\})? regexp:
[画像: The slideshow with the process of file selection based on regexp in the Dired.]
Separately from described marks, files also could be flagged for deletion — mark and flags are different inside Dired, so I able to mark some files to copy them to another place; and simultaneously flag another files to delete them. These flagged files will have another face than the marked files — e.g. if marked files have purple face (see the screenshot above), then the flagged files will have the red one:
[画像: Dired buffer with 5 files, 3 files are flagged for deletion and has red face.]
To flag by hand there is a d hotkey. And to delete flagged files the hotkey x could be used. And of course, there are much more keybindings, which I'm using to flag files for deletion:
| Keybinding | Description |
|---|---|
| % & | Flag garbage files |
| % d | Flag files by regexp |
The "garbage files" defined by the dired-garbage-files-regexp variable. E.g. in my configuration the artifacts from LaTeX build are considered "garbage":
;; Regexp for garbage files.
;; These files could be flagged
;; with "% &"
(setopt dired-garbage-files-regexp
"\\(?:\\.\\(?:aux\\|bak\\|dvi\\|log\\|o\\|orig\\|rej\\|toc\\)\\|\)\'")
So, when I press % &, then all LaTeX build artifacts will be selected in the current directory for deletion.
The % d works like % m keybinding, but it flags files instead of marking them.
Powerful rename
Let's look to the one of the most powerful Dired features. Since directory listing just a buffer in the Emacs — it could be edited as a usual text? Of course!
This is that the WDired mode does — it makes Dired buffer writable. So the filenames could be edited as usual text: with the help of isearch-query-replace-regexp, macros and other cool Emacs features.
To enter WDired mode the C-x C-q keybinding could be used. And the C-c C-c keybinding will return to the usual Dired mode with all the changes applied. With the C-c C-k keybinding to return to the usual Dired mode with all the changes discarded.
I often use WDired mode to strip unwanted text from filenames. E.g. I want to remove .fb2 part from a lot of filenames like:
some-interesting-book.fb2.epub
In this situation I just perform the next things:
- Press
C-x C-qto go to the WDired mod - Enter
C-s .fb2 M-% RET !— and all.fb2suffixes are gone! Basically, here the 3 commands:- Search for
.fb2substring withC-s - Call the
query-replacewithM-%keybinding - Tell the Emacs that the replacement string is empty by not entering any string to replace and just pressing the
RETkey. - Tell the Emacs that it should replace any occurrences in the buffer without any further questions by pressing
!
- Search for
- Press
C-c C-cto apply changes.
Another good example (without regular expressions). Here, I have audio files from "Regular Expressions" (Регулярные выражения) podcast:
[画像: Dired buffer in the Emacs with the list of podcast episodes in it.]
As you can see, the files are badly named: months, days and hours don't have the prepending 0 for numbers less than 10, so the files sorted in the wrong way. I can fix it by renaming everything in the Dired buffer:
[画像: Dired buffer in Emacs with example of manual file renaming via the WDired.]
Of course, some automation with regular expression could be also performed here, but I just want to show that WDired buffer could be edited literally as a text.
By default, WDired allows to change only filenames. But it also able to edit Unix access rights with r, w and x buttons with the next line in the configuration:
(setopt wdired-allow-to-change-permissions t)
If dired-hide-details-mode is disabled in the Dired buffer (it could be done by the pressing to the ( key), then access rights will be visible and could be changed with the next keys:
r: set read modew: set write modex: set executable mode-: remove mode under the cursor.
Copy/move files like in mc (or Far)
[画像: Two vertical windows with Dired buffers inside.]
Basically, there is nothing Dired-specific — just create two vertical windows and open Dired buffers in each of them.
But, there is one caveat exists — with default settings you will not be able to mimic the common thing from mc: copy files between two directories with substituted path to the destination directory, like mc or Far does.
To fix it, I just set the next option:
(setopt dired-dwim-target t)
And after pressing C (copy) or R (rename/move) the path for destination is substituted from the second Dired window.
Search for something
Common search operations could be performed as usual, like in any other Emacs buffer (e.g. with C-s). I already provided some not so easy examples above.
There is one Dired-related variable, which I changed to search only for filenames (and skip catalogs) with C-s hotkey:
(setopt dired-isearch-filenames t)
Another common hotkey, which I'm using, is a j. It allows to move cursor to the desired file or directory in the Dired buffer just by entering it's name:
[画像: Jumping to the 2026-04-28-emacs-dired-marked-files.png with the j hotkey.]
But, of course, there are much more commands to use. There are two notable and very useful commands:
- find-name-dired
- find-grep-dired
I don't know what's up in the Linux world, but in the BSD world there are the next settings necessary to use these commands and see the nice output in the Emacs, since the Dired defaults are for Linux coreutils but not for the BSD coreutils:
(setopt find-grep-options "-q")
(setopt find-ls-option '("-ls" . "-dils"))
find-name-dired
First cool command is M-x find-name-dired. It searches for files with given filename (wildcards allowed) in the given catalog. The found files are shown in the nice Dired buffer with all Dired-related features, mentioned above and below.
For example, the result of M-x find-name-dired RET /bin RET c* RET:
[画像: Emacs Dired buffer with results of find-name-dired command.]
Basically, it is just an interface for find DIR -name NAME command, with Dired buffer attached. So I'm using it mostly to search for some files, e.g. for some Java files when I'm know only the class name.
find-grep-dired
Second cool command is the M-x find-grep-dired. It searches for files with given content (regexp not only allowed but strongly recommended!) in the specified catalog. The found files also shown in the newly opened Dired buffer.
E.g. the result of M-x find-grep-dired RET ~/rsync/blog/articles/it/ RET [Ee]macs RET:
[画像: Emacs Dired buffer with results of find-grep-dired command.]
This command is just an Emacsified version of grep -r '[Rr]egex' *, so it is used in the same way — when I need to search for some text in files. Of course, the buffer with results is just an usual Dired buffer.
External programs
Now it's time to speak about external programs, which could be called from inside Dired.
By default, the Emacs tries to open any file inside itself, if user presses RET on the file in the Dired buffer. But, it may be convenient to open some files with external programs, for example open videos with MPlayer or open an image with nSxiv. And the variable dired-open-extensions could help with that!
It is just a list of conses4, where the car is the file extension and the cdr is the program (from $PATH in my case) which should open all the files with such extension:
(setopt dired-open-extensions '(("png" . "sxiv")
("PNG" . "sxiv")
("jpeg" . "sxiv")
("jpg" . "sxiv")
("JPEG" . "sxiv")
("JPG" . "sxiv")
("gif" . "sxiv")
("GIF" . "sxiv")
("webp" . "sxiv")
("WEBP" . "sxiv")
("avi" . "mplayer")
("m4a" . "mplayer")
("mkv" . "mplayer")
("mp3" . "mplayer")
("flac" . "mplayer")
("mp4" . "mplayer")
("webm" . "mplayer")
("eps" . "gv")))
I think, this part of configuration is self-explanatory — it instructs Dired to open all images with sxiv command, and all videos with mplayer command.
Let's look to another way to launch specific programs for specific files in the Dired. I'm speaking about dired-guess-shell-alist-user variable and the ! or & hotkeys in the Dired buffer.
First thing, you (as a reader) should know, The ! hotkey in the Dired buffer will run entered command synchronously — so Emacs will lock itself, while the command is running. Sometimes, when the command (like gm convert) will exit very fast, it is OK and I could wait some small time while my files are transforming. But, some commands take a lot of time, so there the & is to the rescue. It will run the entered command asynchronously, so the Emacs will not be locked while the command is running. It is useful for e.g. converting some video files from WEBM to MP4, etc.
Of course, the entered command will be applied to the file under the cursor or to the marked files in the Dired buffer.
Second thing: after your press one of the before-mentioned keybindings, then the Dired will show you the prompt in the minibuffer, like this:
[画像: Emacs Dired prompting for command to launch on the 2026-01-24-emacs-dired-C-x-C-d.png file.]
And there are two important keybindings:
M-pshows you the commands which you entered before in this prompt.M-nshows the predefined commands.
Emacs Dired allows to define a lot of commands, depending on the filename extension, so for the images the M-n will show one set of predefined commands and for videos it will show another set of commands. The variable dired-guess-shell-alist-user allows to define these commands, like this:
dired-guess-shell-alist-user
'(("\\.\\([Jj][Pp][Ee]?[Gg]\\|[Pp][Nn][Gg]\\|[Tt][Ii][Ff]\\{2\\}\\|[Ww][Ee][Bb][Pp]\\)$"
"sxiv -t * "
"sxiv -o * | xargs rm -f"
"sxiv -o * | xargs dragon"
"sxiv -o * | xargs gimp"
"gm convert ? -resize 1080x1080^ resized_`?`"
"gm convert ? -resize 2560x2560^ resized_`?`"
"pngquant --speed 1 --strip --skip-if-larger --force * "
"jpegoptim -m 80 --auto-mode -s * ")
("\\.ORF$"
"rawtherapee * ")
("\\.[Gg][Pp][Xx]$"
"qmapshack * "))
This variable is just a list of lists, where the each inner list should contain two things:
- Regular expression which selects the file extension. For this extension (or these extensions) the next written command(s) will be displayed after pressing
M-n. - The next items of inner list is just a strings with commands, which should be launched for the files with extensions from item #1.
So, in the example, provided above, there are:
- Some commands:
sxiv,gm,pngquantandjpegoptim— were assigned to the common extensions for images, like: JPG, PNG, TIFF and WEBP images. - Command to launch RawTherapee for
*.orffiles. - Command to launch QMapShack for
*.gpxfiles.
Note, that where a various wildcard symbols in these command: *, ? and `?`. For example (and for my further explanation), lets assume what we have the next files in the catalog, opened in Dired:
- 01.jpg
- 02.jpg
- 03.jpg
The command like this: rm * — issued from Dired with the help of ! or & keys will be landed to the shell in the next form:
rm 01.jpg 02.jpg 03.jpg
But, if you type the rm ? instead — then the Dired will issue three commands:
rm 01.jpg
rm 02.jpg
rm 03.jpg
And for the mv ? `?`.test the next three commands will be issued:
mv 01.jpg 01.jpg.test
mv 02.jpg 02.jpg.test
mv 03.jpg 03.jpg.test
How these tricks with *, ? and `?` could be used? The first one is self-explanatory — just use it, if need to apply some command to the all selected files.
The ? and `?` are more tricky. E.g., they could be used for image conversion via GraphicsMagick — when you don't want to lost the original filename. Here the `?` comes to the rescue — with back-quotes it is possible to add some text before or after the original filename, because both * and ? should be surrounded by spaces or Dired will not understand it5. So with e.g. gm convert ? `?`.png the next three commands will be executed by the Emacs:
gm convert 01.jpg 01.jpg.png
gm convert 02.jpg 02.jpg.png
gm convert 03.jpg 03.jpg.png
And the next command won't do anything meaningful:
gm convert ? ?.png
First, it will ask user about:
1 occurrence of ‘?’ will not be substituted. Proceed? (y, n, ?)
And if user answers y, then the next non-desired commands will be executed:
gm convert 01.jpg ?.png
gm convert 02.jpg ?.png
gm convert 03.jpg ?.png
Dired and photos/images
Let's delve6 into the photography topic much more.
Usually, my photos land to the some catalog, named with pattern: date of event
-name of the event. And I'm using Dired to work with these photos, intensively:
-
Copying the photos from camera with
C-x d /media/exfat/Olymp/DCIM/100OLYMPin one window andC-x d ~/pictures/date-nameon the other window, then press* sto mark all new photos and pressrto copy them with the help of openrsync. -
With the help of before-mentioned
dired-guess-shell-alist-userI'm first selecting some (usually 30-50%) photos for deletion. The commandsxiv -o * | xargs rm -fallows me to mark some bad photos withmkey, so their filenames will be sent to the input ofrm -f, when I quit from nSxiv image viewer.[画像: Two vertical WM frames with nSxiv on the left and Emacs with Dired opened for catalog with GRiD compass photos on the right]
-
Then, I use the same command:
sxiv -o * | xargs gimp— to open marked images in the Gimp for some edits.
Another few tricks which I'm using to connect photography and Dired. First of all, there is a C-t t hotkey to display thumbnails for selected images right in the Dired buffer. This looks like this:
[画像: Emacs Dired buffer with list of photos. 4 marked photos has the thumbnails on the left of it.]
The same hotkey could be used to hide thumbnails for selected images. It is extremely useful when I want just copy specific images to the (e.g.) friend's USB-drive.
The next convenient hotkey is a C-t o. It displays a separate Image Dired buffer with thumbnails (and customizable information bar) for selected images and some useful hotkeys, to rotate pictures, open them in Gimp, etc. I didn't use it much enough, but it convenient to operate with photos like it happens with usual file browser within a fat DE; or to select the photo with necessary DPI and size.
[画像: Emacs Image Dired buffer opened for few photos. The buffer has an information bar on the top with the photo resolution, DPI, file size and compression level.]
The information bar is not the default — it is customizable and of course it was customized. The contents of this bar is generated in the image-dired-format-properties-string function and (in my case) I just override it with my function via advice-add:
(advice-add 'image-dired-format-properties-string :around #'evgandr/image-dired-enrich-properties)
The custom function evgandr/image-dired-enrich-properties looks like this:
;;;###autoload
(defun evgandr/image-dired-enrich-properties (original-fun buf file image-count props comment)
"Advice for `image-dired-format-properties-string'.
This advice adds image resolution to the image description in the
`image-dired' buffer. The arguments are almost the same as for the
`image-dired-format-properties-string' function: BUF is a Dired buffer,
FILE is an original image file, IMAGE-COUNT is an overall count of
images as a string, PROPS is a stringified list of tags, COMMENT is a
comment for image file.
One new argument is an ORIGINAL-FUN which is an original
`image-dired-format-properties-string' function."
(let ((original-str (apply original-fun (list buf file image-count props comment)))
(size (evgandr/image-size file)))
(concat original-str " " size)))
This function just wraps around original function and add some string from evgandr/image-size function to the default contents of the bar: number of file in the list, file name and size. The default contents is taken from the original function (look at the original-fun parameter).
The evgandr/image-size function retrieves the information about given image file via gm indetify (it is a GraphicsMagick, since ImageMagick embraced LLM slop in the codebase7):
(defun evgandr/image-size (file)
"Return image resolution.
FILE is an image file."
(with-temp-buffer
(call-process "gm" nil t nil "identify"
"-format" "%wx%h dpi:%xx%y compression:%Q" file)
(string-chop-newline (buffer-string))))
The general idea of all of these modifications is not mine — it was taken from the Extending image-dired blogpost.
Emacs-specific things
Here just an one thing, which I'm using. Since all my Emacs configuration is byte-compiled, I'm using Dired to byte-compile changed .el files from my configuration. There are 3 simple steps:
- Open the necessary catalog with the help of
C-x p p dotfiles RET d emacs.d/config RET. - Select all
*.elfiles in the directory with my Emacs configuration files with* s. - Press
Bto Byte-compile the selected files.
[画像: Emacs Dired with a list of *.el files, all marked and there is a side window asking about byte compilation of selected 14 files.]
Configuration overview
Let's go to the last chapter — to the ELisp code with which I configure Dired. As I wrote before, I don't use use-package and use simple old ways to write my Emacs configuration with require, provide and so on.
With Dired I'm using the next few external packages:
delightto hide some minor modes from the modeline.dired-rsyncto use rsync (I'm using openrsync, since rsync is the LLM-slop8 too) to copy files between catalogs.dired-subtreeto open catalogs in the Dired as subcatalogs in the same buffer with aTABkey.dired-xfordired-omit-modeusage. This mode hides some uninteresting files in the Dired buffers (like*.elcfiles, etc).nerd-icons-diredto have a nice icons, like you already have seen on the screenshots above. Obviously the Nerd Icons andnerd-iconsplugin should be installed first.
1: ;;; rc-dired.el --- Dired configuration --- -*- lexical-binding: t -*-
2: ;;; Commentary:
3:
4: ;;; Code:
5:
6: (require 'delight)
7: (require 'dired)
8: (require 'dired-hide-dotfiles)
9: (require 'dired-open)
10: (require 'dired-rsync)
11: (require 'dired-subtree)
12: (require 'dired-x)
13: (require 'image-dired)
14: (require 'nerd-icons-dired)
Then, I'm disabling some minor modes from displaying them in the modeline with the help of delight:
16: (delight 'auto-revert-mode nil "autorevert")
17: (delight 'nerd-icons-dired-mode nil "nerd-icons-dired")
18: (delight 'dired-hide-dotfiles-mode nil "dired-hide-dotfiles")
19: (delight 'dired-omit-mode nil "dired-x")
Also, I added this line to enable dired-find-alternate-file9. It works in conjunction with dired-kill-when-opening-new-dired-buffer variable, described below and helps me to maintain amount of opened Dired buffer at low level:
207: (put 'dired-find-alternate-file 'disabled nil)
Keybindings
Some custom keybindings is in use. First:
21: (keymap-global-set "C-x C-d" 'dired)
The default one is C-x d but I want to use C-x C-d since it is uniform with C-x C-f.
Next keybinding is to create something:
22: (define-key dired-mode-map (kbd "+") 'evgandr/dired-create-file-or-directory)
By default, the + could be used to create a new directory. But I want not to just create a new catalog, but also a new empty file with the same keybinding. So, the custom evgandr/dired-create-file-or-directory function helps here:
79: ;;;###autoload
80: (defun evgandr/dired-create-file-or-directory (path)
81: "Create file or directory in the current working directory.
82:
83: Create file or directory using PATH as a path to the new file or
84: directory. The directory path should contain trailing slash at the end."
85: (interactive "GCreate new file or directory: ")
86: (if (or (file-exists-p path)
87: (file-directory-p path))
88: (message "Error: '%s' already exists." path))
89: (if (string-match "/$" path)
90: (dired-create-directory path)
91: (dired-create-empty-file path)))
The idea of this function is not mine, but I lost the URL of blogpost where it was introduced :-(. The function works pretty simple: if path ends with / then user wants to create a new catalog and it will be created. Otherwise, the new empty file will be created.
Third, I defined some keybindings especially for dired-mode-map to simplify usage of some plugins:
35: ; Keybindings for
36: ; `dired-hide-dotfiles',
37: ; `dired-rsync' and
38: ; `dired-subtree'
39: (add-hook 'dired-mode-hook
40: (lambda ()
41: (keymap-set dired-mode-map "H" 'dired-hide-dotfiles-mode)
42: (keymap-set dired-mode-map "r" 'dired-rsync)
43: (keymap-set dired-mode-map "<tab>" 'dired-subtree-toggle)
44: (keymap-set dired-mode-map "TAB" 'dired-subtree-toggle)
45: (keymap-set dired-mode-map "<backtab>" 'dired-subtree-remove)
46: (keymap-set dired-mode-map "S-TAB" 'dired-subtree-remove)))
There are the next keys:
Hkey to hide/show dotfiles in the catalog.rto invokeopenrsyncfor files/directories copying.TABto display subcatalog contents as a subtree.S-TABto hide the subtree.
[画像: The Emacs Dired buffer where some catalogs and files form a tree with their inner contents.]
Figure 3: This is how the expanded subcatalogs looks like in the Dired buffer.
Hooks
To enable some helper minor modes there are some hooks are in use:
24: ; Enable some helper modes in
25: ; Dired
26: (add-hook 'dired-mode-hook 'dired-omit-mode)
27: (add-hook 'dired-mode-hook 'dired-hide-details-mode)
28: (add-hook 'dired-mode-hook 'dired-hide-dotfiles-mode)
29: (add-hook 'dired-mode-hook 'hl-line-mode)
30: (add-hook 'dired-mode-hook 'nerd-icons-dired-mode)
31: ; Use Dired to attach files in
32: ; mail client
33: (add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode)
34: ; Auto refresh dired buffer
35: (add-hook 'dired-mode-hook 'auto-revert-mode)
These minor modes enables some pretty things:
The dired-omit-mode, dired-hide-details-mode and dired-hide-dotfiles-mode
Just hide dotfiles, . and .. catalogs, and don't display file attributes by default. If I need to look at the hidden files, I just press H; and if I need to view to file attributes I could just press ( key.
The hl-line-mode
I need to highlight the whole line, where the cursor stays, in the Dired buffers — it helps me to see where is my cursor at all.
The nerd-icons-dired-mode
This mode just enables nice Nerd Icons in the Dired buffers (if they were installed first).
The turn-on-gnus-dired-mode
There is a knob to enable gnus-dired-mode — a special mode to work with e-mail attachments. With it, I can mark some files and then press C-c RET C-a to attach these files to the e-mail.
The auto-revert-mode
It is used in the same way as in other buffers — to revert buffer if underlying contents were changed. In case of Dired: if files/catalogs in the opened directory are added/deleted — then the Dired buffer will be automatically updated.
Dired-related variables
This section will be a looooong one :-). If code comment for some variable is self-explanatory — I will skip the unnecessary repeating.
If I marked some files and want to create an archive with the help of Z button, then the resulting TAR archive will be compressed with zstd:
93: ; Compress to the `.tar.zst`
94: ; by default
95: (setopt dired-compress-directory-default-suffix ".tar.zst")
The next Dired setting is a very convenient. I can specify a lot of non-existent catalogs in the path, where I want to copy file — and Dired will create all of these catalogs by itself:
96: ; Create non-existent
97: ; destination directories on
98: ; copying/moving files
99: dired-create-destination-dirs 'always
100: ; old -> new/ will copy old
101: ; inside the new/. old -> new
102: ; will renamed old to the new.
103: dired-create-destination-dirs-on-trailing-dirsep t
104: ; Suggest already opened Dired
105: ; buffers for file operations
106: dired-dwim-target t
107: ; Don't wrap long filenames,
108: ; truncate them
109: dired-filename-display-length 'window
110: ; Don't show free space line
111: dired-free-space nil
112: ; Regexp for garbage files.
113: ; These files could be flagged
114: ; with "% &"
115: dired-garbage-files-regexp "\\(?:\\.\\(?:aux\\|bak\\|dvi\\|log\\|o\\|orig\\|rej\\|toc\\)\\|\)\'"
116: ; Special commands for files
117: ; with specified extensions
118: dired-guess-shell-alist-user
119: '(("\\.\\([Jj][Pp][Ee]?[Gg]\\|[Pp][Nn][Gg]\\|[Tt][Ii][Ff]\\{2\\}\\|[Ww][Ee][Bb][Pp]\\)$"
120: "sxiv -t * "
121: "sxiv -o * | xargs rm -f"
122: "sxiv -o * | xargs dragon"
123: "sxiv -o * | xargs gimp"
124: "gm convert ? -resize 1080x1080^ resized_`?`"
125: "gm convert ? -resize 2560x2560^ resized_`?`"
126: "pngquant --speed 1 --strip --skip-if-larger --force * "
127: "jpegoptim -m 80 --auto-mode -s * ")
128: ("\\.ORF$"
129: "rawtherapee * ")
130: ("\\.[Gg][Pp][Xx]$"
131: "qmapshack * "))
Since I'm using GNU Stow to manage my dotfiles, these files in $HOME are just symlinks. And I'm too lazy to press ( every time when I need to see the destination of the symlink. So, I have this:
132: ; Show symlink targets if all
133: ; other details are hidden
134: dired-hide-details-hide-symlink-targets nil
[画像: Emacs Dired buffer with some dotfiles from $HOME. Dotfiles are symlinks, pointing to some files in the ~/git_repos/dotfiles/.]
135: ; ISearch will search only for
136: ; filenames
137: dired-isearch-filenames t
By default (IIRC) the Dired will open a new buffer for each opened subdirectory. So, when I'm browsing e.g. some Maven projects, I'll get a long list of unnecessary for me buffers. To avoid this, the variable dired-kill-when-opening-new-dired-buffer exists — it instructs Dired to kill the buffer with parent directory when I go to deeper in the file hierarchy. There is always a ^ button to go back.
138: ; Only one Dired buffer
139: dired-kill-when-opening-new-dired-buffer t
140: ; Extensions of LaTeX files to
141: ; clean them with
142: ; `dired-clean-tex'
143: dired-latex-unclean-extensions '(".fdb_latexmk" ".fls" ".glo"
144: ".idx" ".lof" ".log" ".lot"
145: ".nav" ".out" ".snm" ".synctex.gz"
146: ".vrb")
147: ; Display human-readable files
148: ; sizes
149: dired-listing-switches "-alh"
150: ; Enable mouse dragging to
151: ; another apps
152: dired-mouse-drag-files t
153: ; Skip empty lines
154: dired-movement-style 'bounded
155: ; Don't show messages from
156: ; dired-omit
157: dired-omit-verbose nil
158: ; How to open some files
159: dired-open-extensions '(("png" . "sxiv")
160: ("PNG" . "sxiv")
161: ("jpeg" . "sxiv")
162: ("jpg" . "sxiv")
163: ("JPEG" . "sxiv")
164: ("JPG" . "sxiv")
165: ("gif" . "sxiv")
166: ("GIF" . "sxiv")
167: ("webp" . "sxiv")
168: ("WEBP" . "sxiv")
169: ("avi" . "mplayer")
170: ("m4a" . "mplayer")
171: ("mkv" . "mplayer")
172: ("mp3" . "mplayer")
173: ("flac" . "mplayer")
174: ("mp4" . "mplayer")
175: ("webm" . "mplayer")
176: ("eps" . "gv"))
177: ; Copy recursively
178: dired-recursive-copies 'always
179: ; Delete recursively, ask once
180: dired-recursive-deletes 'top
The next two variables are necessary to instruct dired-rsync to use openrsync:
181: dired-rsync-command "/usr/local/bin/openrsync"
182: dired-rsync-options "-a"
By default, the dired-subtree plugin uses a very strange set of colors — aka not matching with my Solarized Light theme — in the background face for files and catalogs in the subtree. So the next variable set to nil disables this behavior:
183: ; Use default background face
184: ; in the directory listings
185: dired-subtree-use-backgrounds nil
186: ; Grep options for "M-x
187: ; find-grep-dired"
188: find-grep-options "-q"
189: ; Find options for "M-x
190: ; find-grep-dired"
191: find-ls-option '("-ls" . "-dils")
192: ; External viewer for images
193: image-dired-external-viewer "nsxiv"
194: ; Margin between thumbnails
195: image-dired-thumb-margin 5
196: ; Use 256x256 size for
197: ; thumbnails
198: image-dired-thumb-size 256
199: ; Store thumbnail at
200: ; `~/.cache/thumbnails`
201: image-dired-thumbnail-storage 'standard-large
202: ; Use Emacs Lisp realization
203: ; of ls
204: ls-lisp-use-insert-directory-program nil
205: ls-lisp-dirs-first t
206: ; Change permissions in WDired
207: wdired-allow-to-change-permissions t)
Faces customization
There are not so much customization I've made. Just changed colors of blue header with current path on the top of Dired buffer and color of directory — so they match with my Solarized Light color scheme:
210: (custom-set-faces
211: `(dired-directory ((t (:foreground "#268bd2"))))
212: `(dired-header ((t (:background
213: "#268bd2"
214: :foreground
215: "#eee8d5"))))
Notes
Footnotes:
E.g. I have a catalog with some JPEG and MP4 files — without consistency in filenames — and want to copy or move only some of the JPEG and some of the MP4 files, interactively selecting them.
Sadly, the Emacs Jabber using the same keybinding (C-x C-j) as a prefix key. So, if you are using Emacs Jabber, then no C-x C-j :-(, while you don't change the default keybinding.
Obviously, this blogpost and other posts in my blog written only by me and no LLM were involved }:->. The word above is just a smirk to the direction of people, who believe that:
- a lot of
- non-numbered
- or numbered
- lists
with some em-dashes like this one — is a - direct and 100% robust sign of slop — like no one
- writer before were using these things in their text(s) :-)
- lists
Also, consider this: I'm Kenyan. I Don't Write Like ChatGPT. ChatGPT Writes Like Me.
Look at this commit in the ImageMagick repository, which was "co-authored" by Claude LLM. Or at this attempt to receive some policy about LLM usage in project from the main developers (unsuccessful).
See the output of F1 f dired-find-alternate-file RET.