unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Rename, delete and move current buffer and file
@ 2018-05-07 13:58 Jarosław Rzeszótko
  2018-05-07 14:53 ` Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: Jarosław Rzeszótko @ 2018-05-07 13:58 UTC (permalink / raw)
  To: emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 3268 bytes --]

It is surprisingly hard to do this in Emacs, and I think it is a common
problem, as evidenced by e.g.:

https://stackoverflow.com/questions/384284/how-do-i-rename-an-open-file-in-emacs
http://emacsredux.com/blog/2013/05/04/rename-file-and-buffer/
http://rejeep.github.io/emacs/elisp/2010/03/26/rename-file-and-buffer-in-emacs.html

You can use dired, but I personally find it to be a distraction for this
use case.

There is set-visited-file-name, but:
a) it creates a copy of the file by default
b) the name is not intuitive and I doubt many people looking to rename a
file will find it
c) the best UI/UX is IMO different for different use cases, rename is
different from move

A very similar related pain point is that it is hard to get the path and
directory of the current buffers visited file. There exist ways to do it,
but this is a pair of related use cases and the handling is completely
different: for the path you have default-directory, an elisp variable, and
pwd, a command capable of displaying the path in minibuffer or yanking it
at point. For file name I am only aware of the elisp function:
buffer-file-name. Again, two closely related use cases, handled very
differently, I by now looked those up like 10 times and every time I forget
how to get this info because the names are so far from what you would
expect.

How can we fix or improve those issues?

For rename/delete/move I would create three distinct commands:
rename-visited-file-with-buffer
move-visited-file-with-buffer
delete-visited-file-with-buffer

Those names make the functions easy to discover if you are using something
like ivy or ido for M-x, while they are still precise from the standpoint
of Emacs concepts. It seems good to me to separate rename, which should
prefill the minibuffer prompt with the current name, and ask only for a new
filename, WITHOUT directory selection, from move, which should prompt for a
full new path, WITH directory selection.

For the current buffers file and directory name, I think aliasing
default-directory as visited-file-name-directory, and introducing
visited-file-name is one option. Another option: introduce
buffer-directory-name as a complement to the existing buffer-file-name
function. That would cleanup the elisp part, and then at least the names
are something you can remember, and with M-: you can kill, insert or
display those.

Question remains how to fix those things also on an user interface level. I
think it's a pity clicking on the filename in the modeline changes the
current buffer, I am happy to hear if I am mistaken, but today this
behavior is rather unexpected and I would be very surprised to see somebody
switching buffers this way. On the other hand it looks like a nice place
for a menu where all the operations mentioned could be triggered (rename,
move and delete file+buffer, display/kill/insert directory name or file
name). Providing default key bindings under a common prefix for them could
be nice too.

Maybe someone has some more, or better, ideas for this.

Finally, while we are discussing functions everyone re-implements in their
.emacs, please lets make transpose-windows happen as an Emacs builtin :)

Cheers,
Jarosław Rzeszótko

[-- Attachment #2: Type: text/html, Size: 6754 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2018-05-11 16:14 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-07 13:58 Rename, delete and move current buffer and file Jarosław Rzeszótko
2018-05-07 14:53 ` Stefan Monnier
2018-05-07 16:20   ` Jarosław Rzeszótko
2018-05-07 17:01     ` Stefan Monnier
2018-05-07 17:47       ` Jarosław Rzeszótko
2018-05-08  1:28         ` Stefan Monnier
2018-05-08  7:05           ` Jarosław Rzeszótko
2018-05-09 12:28             ` Stefan Monnier
2018-05-09 18:12               ` Radon Rosborough
2018-05-09 22:44                 ` Stefan Monnier
2018-05-10 17:01                   ` Radon Rosborough
2018-05-10 21:49                     ` Stefan Monnier
2018-05-11  7:31                       ` Andreas Schwab
2018-05-11 15:33                         ` Stefan Monnier
2018-05-11 15:45                           ` Paul Eggert
2018-05-11 16:06                             ` Clément Pit-Claudel
2018-05-11 16:14                             ` Stefan Monnier
2018-05-09 23:50               ` Van L
2018-05-10  5:37                 ` Jarosław Rzeszótko
2018-05-10 13:18                   ` Van L
2018-05-10  8:20               ` Amit Ramon
2018-05-10  8:59                 ` Phil Sainty
2018-05-10 16:04                 ` Eli Zaretskii
2018-05-07 18:20     ` Andreas Schwab
2018-05-08  1:28       ` Stefan Monnier
2018-05-07 15:28 ` Yuri Khan
2018-05-07 16:20   ` Jarosław Rzeszótko
2018-05-09 11:46   ` Tino Calancha
2018-05-07 15:29 ` Andreas Röhler
2018-05-07 15:38   ` Andreas Röhler
2018-05-10  0:46   ` net june
2018-05-11  6:26     ` Andreas Röhler
2018-05-11 16:10       ` net june

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).