all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Andreas Röhler" <andreas.roehler@online.de>
To: emacs-devel@gnu.org
Cc: net june <netjune@outlook.com>
Subject: Re: Rename, delete and move current buffer and file
Date: Fri, 11 May 2018 08:26:56 +0200	[thread overview]
Message-ID: <81031169-8e1d-48b6-9501-1f371a30aff2@online.de> (raw)
In-Reply-To: <SINPR04MB177448C258B696A043C9D9B2B7980@SINPR04MB1774.apcprd04.prod.outlook.com>

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 <https://aka.ms/ghei36>
> 
> ------------------------------------------------------------------------
> *From:* Emacs-devel <emacs-devel-bounces+netjune=outlook.com@gnu.org> on 
> behalf of Andreas Röhler <andreas.roehler@online.de>
> *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
> 



  reply	other threads:[~2018-05-11  6:26 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2018-05-11 16:10       ` net june

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81031169-8e1d-48b6-9501-1f371a30aff2@online.de \
    --to=andreas.roehler@online.de \
    --cc=emacs-devel@gnu.org \
    --cc=netjune@outlook.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.