From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Andreas_R=c3=b6hler?= Newsgroups: gmane.emacs.devel Subject: Re: Rename, delete and move current buffer and file Date: Mon, 7 May 2018 17:29:50 +0200 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1525706854 15380 195.159.176.226 (7 May 2018 15:27:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 7 May 2018 15:27:34 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 07 17:27:30 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 1fFi2z-0003u4-Nt for ged-emacs-devel@m.gmane.org; Mon, 07 May 2018 17:27:29 +0200 Original-Received: from localhost ([::1]:46811 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fFi56-0003Tk-M6 for ged-emacs-devel@m.gmane.org; Mon, 07 May 2018 11:29:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40767) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fFi4B-0003Sj-OB for emacs-devel@gnu.org; Mon, 07 May 2018 11:28:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fFi47-00079W-MY for emacs-devel@gnu.org; Mon, 07 May 2018 11:28:43 -0400 Original-Received: from mout.kundenserver.de ([212.227.126.133]:40395) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fFi47-00077e-CT for emacs-devel@gnu.org; Mon, 07 May 2018 11:28:39 -0400 Original-Received: from [192.168.178.35] ([188.103.18.182]) by mrelayeu.kundenserver.de (mreue005 [212.227.15.167]) with ESMTPSA (Nemesis) id 0MV0vp-1eoNdx0ZC9-00YN8o for ; Mon, 07 May 2018 17:28:36 +0200 In-Reply-To: Content-Language: en-US X-Provags-ID: V03:K1:NScvm1siCKZW+ELPc1U791wiZi86SYm6Px/mdBe7nXDS/7I+gj5 47ZaugzeC4Zdwdj0XXLLRbxe4lHcg5636QQyNnC5J67u6y79ebrS1JI3JbJ/ihZZSX1zBZt MxeCKvE62ahepPNRd8YC68/yieVL2S5g20PaPHCqgFwcgGcu47odeFVa6v1dtyIXCZ3FwzD 6mLoCVp+X3e1SxUB0pAjQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:78axsohYSgU=:2B4RSnBzkGDIuuTKJACWiO AWliFxo7MB3yCv40n3vjJ+M0hxvVBCyi6R0s4liMlodf+2hhLJZzl9ppQwNlubloBcOWxJ+6r rnVwB7J9FdNf6cOIXyj8V6xL9QPcpUzSxK0RqLGgUnEA7Acy4oH60v9yr/vC6mDiWlWD4IJO1 xATodjNFAHwIQ8SQ1S6Ms7UczRYjjwx9t4Qdrsr23zPNGBC0ir7BeOV/MWxhXL0T6DnAS4JMl /O12BJ59V5q7i6bLgiEaD5WNdYkhUvpYwc4Yh3MMlXV/t8wkPO2akXp369gHZa0DvY0rqZ6s0 dh2q2dXSvLUxbaCegL5oxtQwPKqM8IIfF4cvYisJuDDSFBJ1En/PFnPOuFDC291pwXn+MBvLp N9uR7DaEN+ZLhqP9YZpO28qlFM8N5k6SnSLsUHw2NOij3BFgnAGB29qbo5zfKV+TnKYocanKP ghOScfjTsr0976v/O5pD3Nyr7lLHGXHnmUH6OwBF2zWNNg4c7TSThaFDzUIPS6enpIrrJa6VJ nY7TMwQn5LOY+Aqe8jcyYQCVKEse7w/0N3kxDXIOSejhTM6Y+jv/lyaCGowtg9+meuh7sJ+Ws 9qgjrXgacd48ejqc+VOhCw7zsnSzTBElOjSMJqfIelYPpvEu8smoVjeVzm8xwVAD4wT13RZk3 KD+nSK+l21Va+IQNtze1G0+bINIFky51Q2xahkaslRL+/yE1+5dOOUoayPLCp2swlwFCiyIEt v3sX7WgMaJlUE9rE X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.133 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:225117 Archived-At: On 07.05.2018 15:58, Jarosław Rzeszótko wrote: > 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 Good question. My workflow is the following: [(control a)] ;; Store the buffer-name in kill-ring, code see below [(control x) (d)] ;; dired, commonly the wanted working dir [(control s)(meta y)] ;; yank the buffer-name as argument to ;; isearch-forward [(control c) (w)] ;; or M-x wdired-change-to-wdired-mode RET ;; then edit, save. (defun puffername-an-car-killring () "Store buffer-name at first place in ‘kill-ring’." (interactive) (let* ((name-raw (split-string (buffer-name) "<")) (name (car name-raw))) (kill-new name) (message "%s" name))) Best, Andreas