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: Fri, 11 May 2018 08:26:56 +0200 Message-ID: <81031169-8e1d-48b6-9501-1f371a30aff2@online.de> 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 1526019869 17844 195.159.176.226 (11 May 2018 06:24:29 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 11 May 2018 06:24:29 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 Cc: net june To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 11 08:24: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 1fH1Tb-0004Uj-BH for ged-emacs-devel@m.gmane.org; Fri, 11 May 2018 08:24:23 +0200 Original-Received: from localhost ([::1]:36953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH1Vb-0004q9-Gt for ged-emacs-devel@m.gmane.org; Fri, 11 May 2018 02:26:27 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH1Ut-0004n1-96 for emacs-devel@gnu.org; Fri, 11 May 2018 02:25:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH1Uq-0005cp-4S for emacs-devel@gnu.org; Fri, 11 May 2018 02:25:43 -0400 Original-Received: from mout.kundenserver.de ([217.72.192.74]:56785) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fH1Up-0005bq-RG for emacs-devel@gnu.org; Fri, 11 May 2018 02:25:40 -0400 Original-Received: from [192.168.178.35] ([88.75.57.253]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MGz2I-1f4Juc0OzC-00Dm2J; Fri, 11 May 2018 08:25:36 +0200 In-Reply-To: Content-Language: en-US X-Provags-ID: V03:K1:8TQ4Cw8Ao5i2SsJjsmCRU/x+m5swKY1uvz2z3HIQAGQUINsI2gF F9eOGBY2wB5L8FE1YE0NgtNeciYU5NpLfUeO/0mskPQlbCtHm19+rEZDYIOsXIasFafWfmX nefjv1GJJPv9KURlMZDTgQgy3Cbys2gibv2FSxXqNhiHH+fkHiHbl+3ZAFmd59QxHcaVKuO FXkr84C0qVOn5cNeNxr0g== X-UI-Out-Filterresults: notjunk:1;V01:K0:IEmH3OzzU9w=:MIlVaoVANNpOBtU3bSViPN hD0tQtr+TyGVdv9XLMVDpaA6PCfMwnKLl0XnMMRfNaQtO/e6wB6qe1UtNF4wz5A3h0dg03Ajr jMCTFgLX0J+ZNssQ8RGI573D86zmuj4YqUy2MTVc1VYa7XKOE7YM/W5qvSVT5EEPvXCpoybLz 41J5JNyKpH494V8XZbIP21vTWjlVVJHhixt4QWRSPmO5duMBugVIvBKzxnFm391JGEaGPe+pT vQOIgW349jx+2zPtJOuqtFZl5ROCr6qSeNBy4Vg9ldzLh1J8XUpej+YIkuEPc1U18OWx2mxJ7 KPIJCSarIj36EUjem16Mvf3AQpHpiWXM1QX8xlLRNtzNrgyyoS/w0NTGjSPN2TR1QnKN7pm4m RMDXFqYoZu7VHKGs8l3ZKoHSteaLekY7e6j8Y3LMB8bXqfJ7vrp78Qd/dTuk44n+tCsGtPOY4 aRDlq6En8+qm1WaSVMERfMAG2mssGCuwJxxJ0ho0AK4bH+n8Cmrt9LiciRw7b+qCdXarKAk9B Dd7FkUPWMzTcRD0cf1Gf37IVz5SsSRX23ZfkwZcPGwUvYX5vSk7hW2Qd2ddzw0ErjHlQXIN5g pzNJ//bEzczCquEqWtKXdJydtuh+EbKSdV9pDXUYv/4cipwXeE4d6CrLQTvCqFpezyQp7pw2U hyIfhuKfPAouABqaLevdcxZ0fpuUQRryhej9CXi3vf3OySI/oPrR02Y/QHr1fB2HpTZbyCIsf olNu1yXe2kVaWSwG X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 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:225220 Archived-At: Sound cool and should save a keystroke WRT dired-jump and friends. May you post the code? On 10.05.2018 02:46, net june wrote: > I have a command my-rename-file for my own use for long time. It does > thing as following: > 1. When run with no prefix arg, rename the the visiting file in its > directory, prompting for new name(read-string) with the old name as > init input. > 2. in 1, if user input an empty string, delete the file on disk. > 3. when run with prefix arg, rename the visiting file to anywhere user > choose, prompting for new file path(read-file-name) > > 获取 Outlook for Android > > ------------------------------------------------------------------------ > *From:* Emacs-devel on > behalf of Andreas Röhler > *Sent:* Monday, May 7, 2018 11:29:50 PM > *To:* emacs-devel@gnu.org > *Subject:* Re: Rename, delete and move current buffer and file > > > 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 >