From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?B?SmFyb3PFgmF3IFJ6ZXN6w7N0a28=?= Newsgroups: gmane.emacs.devel Subject: Rename, delete and move current buffer and file Date: Mon, 7 May 2018 15:58:53 +0200 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000f7c6ca056b9e11e8" X-Trace: blaine.gmane.org 1525701448 6825 195.159.176.226 (7 May 2018 13:57:28 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 7 May 2018 13:57:28 +0000 (UTC) To: "emacs-devel@gnu.org" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 07 15:57:24 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fFgdn-0001hc-Ib for ged-emacs-devel@m.gmane.org; Mon, 07 May 2018 15:57:23 +0200 Original-Received: from localhost ([::1]:46463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fFgfu-0001Yb-KI for ged-emacs-devel@m.gmane.org; Mon, 07 May 2018 09:59:34 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fFgfM-0001YV-5U for emacs-devel@gnu.org; Mon, 07 May 2018 09:59:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fFgfH-0003LU-M1 for emacs-devel@gnu.org; Mon, 07 May 2018 09:59:00 -0400 Original-Received: from mail-yb0-x22c.google.com ([2607:f8b0:4002:c09::22c]:45508) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fFgfH-0003LG-DY for emacs-devel@gnu.org; Mon, 07 May 2018 09:58:55 -0400 Original-Received: by mail-yb0-x22c.google.com with SMTP id r13-v6so9947139ybm.12 for ; Mon, 07 May 2018 06:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=Yp9EuGjk98SSeynpBiGU+o2/xQHjFKDLeMyQXGC1LqY=; b=dBCH8Z27WnQEF9hBoKkjkV2DU69Ms+NbPAd9/xU3awE/5oGO5nF+13IKcovlb76DoC Qrc2YsoB743Vpg3QBHhh5vmQWOrVXwa5U5pTtaNwr+PVZ4CPS3S/roT7bDwonbQAHwtE rjfQJ2wA7HpjOoz97TQPr3xIHUM0Z3jS+YJQr8FLv5PdsV9klhmTaER6a75qq7gezajE U8f47VYCOUfqsMFn0qzmKqmp5CSmuJKnA9ymyiLiNbWqkXgKKbK2XCX/y6Y9GaulyoXN 2JofNGm2+e6bmyyBHkaLuSvYVzCBlkm+C3A6HM4RrLoVCqrRU8HbIZj0VMl0HdbLtAB5 7pWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Yp9EuGjk98SSeynpBiGU+o2/xQHjFKDLeMyQXGC1LqY=; b=dmq9nYn0ZNLnruptDdzhfhji3hZRimH7Lw5UdrMgy9W9WQkjA9CwGJn3sB3ORGcGSw wrxBMo4jNyALIWP2qjezB44QF5xI1g+p1TN0/231hJLucoxa/Rih2NgSSu1P7Fs6XiYW T9bTr6SghLCmncZT4uclFF83xW7dZTVh6Qi/cAMx8sdWx9E1e4sXfrmA7wVGgKkTlR5M h30nfLQoQCoCPq+e/RvY99Sr2sioN/sVE6c61NCnmLxISbOq9E1syegNYqpS08q9a+aL 8FvDuUBJNLBJwg+GG3c+u4lmouSoLvCuITmVcO2GPacvvrHiL9mH44MN9FjqSPLw8ZmW Re4A== X-Gm-Message-State: ALKqPwcmcImxnExmmhHrSP23HJoUdZztcMLPu2nl7w32idCK/1/6Rxih 2EQrm05aReTYZE9RsONyYPtz7KEzMdjdQkbZmP8PXA== X-Google-Smtp-Source: AB8JxZqwcz4GouSdxumkqe2jCezWaycopv5HDYLZgOUaoHL/MemhP0CsPq+o+OlV2yk0WEKm4oiv7whgzTq/FpmCjIo= X-Received: by 2002:a25:1304:: with SMTP id 4-v6mr2664566ybt.484.1525701534007; Mon, 07 May 2018 06:58:54 -0700 (PDT) Original-Received: by 2002:a5b:b08:0:0:0:0:0 with HTTP; Mon, 7 May 2018 06:58:53 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4002:c09::22c X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:225112 Archived-At: --000000000000f7c6ca056b9e11e8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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-em= acs.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=C5=82aw Rzesz=C3=B3tko --000000000000f7c6ca056b9e11e8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
It is surprisingly hard to do this in Emacs, and I think i= t is a common problem, as evidenced by e.g.:

http://rejeep.githu= b.io/emacs/elisp/2010/03/26/rename-file-and-buffer-in-emacs.html

You can use dired, but I p= ersonally find it to be a distraction for this use case.=C2=A0=

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, r= ename is different from move

A very similar relate= d pain point is that it is hard to get the path and directory of the curren= t buffers visited file. There exist ways to do it, but this is a pair of re= lated use cases and the handling is completely different: for the path you = have default-directory, an elisp variable, and pwd, a command capable of di= splaying 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 rela= ted use cases, handled very differently, I by now looked those up like 10 t= imes 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 wou= ld create three distinct commands:
rena= me-visited-file-with-buffer
move= -visited-file-with-buffer
delete= -visited-file-with-buffer
Those names make the function= s easy to discover if you are using something like ivy or ido for M-x, whil= e they are still precise from the standpoint of Emacs concepts. It s= eems good to me to separate rename, which should prefill the minibuffer pro= mpt with the current name, and ask only for a new filename, WITHOUT directo= ry selection, from move, which should prompt for a full new path,=C2=A0WITH= directory selection.

For the current buffers file= and directory name, I think aliasing default-directory as visited-file-nam= e-directory, and introducing visited-file-name is one option. Another optio= n: introduce buffer-directory-name as a complement to the existing buffer-f= ile-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 hea= r if I am mistaken, but today this behavior is rather unexpected and I woul= d be very surprised to see somebody switching buffers this way. On the othe= r hand it looks like a nice place for a menu where all the operations menti= oned 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.=C2=A0

Maybe someone has some more, or better, ide= as for this.

Finally, while we are discussing func= tions everyone re-implements in their .emacs, please lets make transpose-wi= ndows happen as an Emacs builtin :)

Cheers,
<= div>Jaros=C5=82aw Rzesz=C3=B3tko
--000000000000f7c6ca056b9e11e8--