If you've ever been saved by an Emacs backup file, you
probably want more of them, not less of them. It is annoying
that they go in the same directory as the file you're editing,
but that is easy to change. You can make all backup files go
into a directory by putting something like the following in your
.emacs
.
(setq backup-directory-alist `(("." . "~/.saves")))
There are a number of arcane details associated with how Emacs
might create your backup files. Should it rename the original
and write out the edited buffer? What if the original is linked?
In general, the safest but slowest bet is to always make backups
by copying.
(setq backup-by-copying t)
If that's too slow for some reason you might also have a look at
backup-by-copying-when-linked
.
Since your backups are all in their own place now, you might want
more of them, rather than less of them. Have a look at the Emacs
documentation for these variables (with C-h v
).
(setq delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t)
Finally, if you absolutely must have no backup files:
(setq make-backup-files nil)
It makes me sick to think of it though.
Yes, with dired
mode, you can:
C-x d
to open dired
RET
to select directory of current file
C-x C-j
(dired-jump
to the name of the current file, in Dired)
R
to rename the file (or dired-do-rename
).
q
to go back to the (renamed) file buffer
The rename is equivalent to a shell mv
, but it will also update any open buffers, and unlike mv
it will not change the access and modify times on the file in the filesystem.
Best Answer
Sometimes
default-directory
for the current buffer may be set to something other than the current directory of the file the buffer is currently visiting, in which case the solution above wouldn't give what the asker was looking for.In such cases, you can use the
file-name-directory
method, like so:(file-name-directory buffer-file-name)
Here is a link to the docs:
http://www.gnu.org/software/emacs/manual/html_node/elisp/File-Name-Components.html