Revisiting Window Cut / Copy Files with DWIM
I previously wrote about wanting the ability in emacs to copy and paste files from one window to another just like a linux GUI file manager and after a little hunting around and experimentation I settled on putting together some elisp:
This worked pretty well for a while although there were a couple of side effects that I hadn’t bargained for!
The first was the bypassing of the trash/wastebasket, of course this can be easily remedied by for example installing trash-put as part of my copy but that is starting to add more lines to the elisp and I didn’t want to complicate things too much.
Also the single rename functionality in dired now didn’t work as I essentially remapped the basic functionality of the R key to set up a flag for a paste operation and I have come to realise that I use the rename often as I would do in a GUI file explorer.
All I want to do is to copy/move files from one emacs window to another, is that too much to ask?, and no, no it isn’t, as there is a much simpler way to achieve this without any of the foibles listed above.
Dired tries to guess a default target directory
So just open a couple of dired windows, mark and operate and the directory dired suggests is the second or destination window dired directory.
Now you may think my previous efforts were wasted but I would disagree with this assumption, I have started to get to grips with elisp, managed to get some elisp working and continued reconsidering my general emacs workflow which as we know will save me time in the long run.
Oh and another thing, the power of writing a blog and trying to articulate what I think I know means that I have read further into the Help for dired-dwim-target. This helps to clarify a few things as sometimes I get a little muddled with renaming files and which window/buffer dired is actually being used, here is a Help snippet:
You can customize it to prefer either the next window with a Dired buffer, or the most recently used window with a Dired buffer, or to use any other function. When the value is a function, it will be called with no arguments and is expected to return a list of directories which will be used as defaults (i.e. default target and "future history") (though, ‘dired-dwim-target-defaults’ might modify it a bit). The value t prefers the next windows on the same frame.
This is very much something I shall be looking into at a future date, but for now I have something that works and reduces the size of my .emacs file.