reddit / emacs
What is the desired behaviour of C-x C-s in a dired buffer?
tomatoaway · 2022-11-24 16:24
This defaults to `save-buffer`, but unless I'm not understand something, this feels like a forgotten common binding that should do something more meaningful than just writing a directory buffer somewhere to file
HM0880 · 2022-11-24 16:31
What do YOU want the keybinding to do in DirEd? Figure out the behavior you want, and map the keybinding. Done.
tomatoaway · 2022-11-24 16:37
I feel like "zip the entire contents" would be the answer here, and yes very easy to set up a binding for it.
I just feel like I'm missing out on some desired behaviour here. Is it useful somehow to write a dired buffer to file? Can you restore filenames in a directory by reloading a previously saved buffer?
chmouelb · 2022-11-24 16:54
depend if you are in wdired mode or not, if you are then it will do just the right thing :) but you may want to read the manual first https://www.gnu.org/software/emacs/manual/html_node/emacs/Wdired.html
00-11 · 2022-11-24 17:01
1. It can pretty much *always* be useful to write *any* buffer to a file. Depends on the use envisioned for such a file.
2. You can bind `C-x C-s` to any command you like in `dired-mode-map`.
3. If you load `dired-aux.el` (standard library) then `c` is bound to command `dired-do-compress-to`, which compresses selected files and directories to an archive.
----
> `dired-do-compress-to` is an interactive autoloaded compiled Lisp
function in `dired-aux.el`.
>
> `(dired-do-compress-to)`
>
> Compress selected files and directories to an archive.
>
> Prompt for the archive file name.
Choose the archiving command based on the archive file-name extension
and `dired-compress-files-alist`.
----
> `dired-compress-files-alist` is a variable defined in `dired-aux.el`.
>
> Its value is
>
(("\\.tar\\.gz\\'" . "tar -cf - %i | gzip -c9 > %o")
("\\.tar\\.bz2\\'" . "tar -cf - %i | bzip2 -c9 > %o")
("\\.tar\\.xz\\'" . "tar -cf - %i | xz -c9 > %o")
("\\.zip\\'" . "zip %o -r --filesync %i"))
>
> Documentation:
>
> Control the compression shell command for `dired-do-compress-to`.
>
> Each element is `(REGEXP . CMD)`, where `REGEXP` is the name of the
archive to which you want to compress, and `CMD` is the
corresponding command.
>
> Within `CMD`, `%i` denotes the input file(s), and `%o` denotes the
output file. `%i` path(s) are relative, while `%o` is absolute.
onearmedphil · 2022-11-24 17:41
Maybe because it’s such a common command in text editing it is a good idea to keep it a harmless/useless command.
organic-bookworm · 2022-11-24 18:35
There's [`dired-virtual-mode`](https://www.gnu.org/software/emacs/manual/html_node/dired-x/Virtual-Dired.html) for managing arbitrary (e.g. obtained from remote machine) `ls`-like listings. One way to obtain such a listing is saving Dired buffer.
noman_032018 · 2022-11-24 19:18
Personally I've found such a listing saving to be useful. I'd rather `t` (`dired-toggle-marks`) + `&` (`dired-do-async-shell-command`) to create archives, compressed or not, when I specifically want to do that since the choice of archive format & compression settings will depend greatly on the intended destination.
Understanding their interaction with `?` and `*` also helps making [dired-do-*shell-command](https://www.gnu.org/software/emacs/manual/html_node/emacs/Shell-Commands-in-Dired.html) commands a lot more useful.
duck1123 · 2022-11-24 20:49
I've accidentally hit save so many times in a dired buffer that I would be upset if it did anything costly.
gwern · 2022-11-24 21:09
`save-buffer` serializing a listing of the directory to a text file strikes me as a little odd. Intuitively, I would expect it to execute any changes I've made to the dired buffer - deleting, renaming etc.
arthurno1 · 2022-11-24 22:09
It depends on how you use Dired. If you inserrt other directories with 'i' keypress, being able to save your dired buffer can be a time saver. Also notice that you can remove some lines from the dired (without removing files from the folder), and suddenly you have some customized buffer which you don't want to rework again in case you would like to continue in another session.
I don't use dired that way personally, but I can imagine the intended use-case. I certainly don't think it was a "forgotten" remaining as someone else suggested.
arthurno1 · 2022-11-24 22:09
That is reserved for wdired.
RichieHHam · 2022-11-25 11:34
What an awful answer. Maybe he's asking WHY it's why it is and can maybe then alter his workflow or usage. More often than not, there is a GOOD reason for Emacs keybindings.