syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.64k stars 4.89k forks source link

Giving directory as a rename target uses directory as buffer-name #9266

Closed shanavas786 closed 4 years ago

shanavas786 commented 7 years ago

Description :octocat:

Giving directory as a rename target uses directory as buffer-name

Reproduction guide :beetle:

Observed behaviour: :eyes: :broken_heart:

Expected behaviour: :heart: :smile:

System Info :computer:

Backtrace :paw_prints:

d12frosted commented 7 years ago

I observe slightly different behaviour.

File a.txt visits tmp/a.txt instead of tmp2/a.txt. Also I see very funny message: File ’’ successfully renamed to ’tmp2’.

To be honest I am not sure that rename-file should accept directories. But there should separate function for directories that

What do you think?

shanavas786 commented 7 years ago

On July 27, 2017 10:47:11 PM GMT+03:00, Boris notifications@github.com wrote:

I observe slightly different behaviour.

File a.txt visits tmp/a.txt instead of tmp2/a.txt. Also I see very funny message: File ’’ successfully renamed to ’tmp2’.

Let me check it once more.

To be honest I am not sure that rename-file should accept directories.

I feel rename could be thought like mv command, and accepting directory targets makes sense then.

Or we can prompt the user target is a directory, do you want to move <file> to it ?

But there should separate function for directories that

  • renames directory
  • fixes all buffers visiting files in that directory
  • invalidates projectile cache
  • updates recentf list What do you think?

Well, that doesn't help if the user wants to move a single file out of the directory. -- ഷാനവാസ് Sent from my Android device with K-9 Mail.

d12frosted commented 7 years ago

I feel rename could be thought like mv command, and accepting directory targets makes sense then.

Agree. And since there are other commands with 'file' in their name, that works on directories, we should improve rename as well.

Well, that doesn't help if the user wants to move a single file out of the directory.

I am talking only about moving directories, not files.

shanavas786 commented 7 years ago

And since there are other commands with 'file' in their name, that works on directories, we should improve rename as well.

Yes, #9267 now handles renaming file to directory. Let me try to handle directory - directory renaming too.

d12frosted commented 5 years ago

I've also proposed a PR satisfying all the points I've mentioned: https://github.com/syl20bnr/spacemacs/pull/11470

@shanavas786 can you please try using it? Would like to have your feedback on this.

d12frosted commented 5 years ago

I've merged #11470. Any feedback would be valuable.

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

nicobao commented 4 years ago

Hi for info, I am using the development branch and I am experiencing the exact same behaviour as @shanavas786 who first initiated this issue.

As a consequence I cannot modify a directory within Spacemacs. It is really cumbersome if you have already a file open in the folder. If you rename the folder using the bash "mv" command, it doesn't edit the buffer of your opened file. Then, when you try to save your file, it prompts you to create a new directory with the old name...

Any solutions?

Emacs version 26.3 Spacemacs version 0.300.0

duianto commented 4 years ago

I'm seeing the expected behavior:

The buffer shows: a.txt and it's located in: c:/tmp2/a.txt

Windows 1903
#### System Info :computer:
- OS: windows-nt
- Emacs: 26.3
- Spacemacs: 0.300.0
- Spacemacs branch: develop (rev. 83fbc7a13)
- Graphic display: t
- Distribution: spacemacs
- Editing style: vim
- Completion: helm
- Layers:
```elisp
(autohotkey command-log emacs-lisp git helm imenu-list javascript
            (markdown :variables markdown-live-preview-engine 'vmd markdown-command "vmd")
            multiple-cursors org pdf python
            (shell :variables shell-default-shell 'shell shell-default-height 30 shell-default-position 'bottom)
            spell-checking syntax-checking treemacs version-control)
```
- System configuration features: XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS THREADS LCMS2


Regarding the second issue.

Renaming a directory with an external tool, when Spacemacs is visiting a file in that directory, doesn't change the open file buffers directory association, because Spacemacs has no way of knowing what the directory was renamed to.

If the directory is renamed in for example a dired buffer: SPC a d (or M-x dired RET) then the open file buffers associated directories also update.

But your right, when trying to save a file buffer that's associated with a directory that doesn't exist anymore. Then it currently just asks:

Directory 'c:/buffersAssociatedDirectory/' does not exist; create? (y or n)

It would probably be better to open a prompt where one can navigate to a new target directory.

It's not limited to Spacemacs. It also happens with just Emacs without any additional packages.

It can be reproduced like this: When Spacemacs is installed, then Emacs can be started without loading any configurations: runemacs --quick (in non-Windows OSs it might just be: emacs --quick)

Feel free to report this upstream to the Emacs maintainers, then non-Spacemacs users also will benefit from the fix.

nicobao commented 4 years ago

Thanks. Indeed, for the first "error", I guess I was not typing the right commands... Regarding the second issue, I just sent a report to the Emacs bug-related mailing list.