0

In spacemacs I find that two ways to get a new copy of a file with a slightly different filename both suffer from the same completion problem:

  1. C-x C-w (write-file)
  2. dired-aux's dired-do-rename (bound to R in spacemacs in dired)

Either way, if I type the initial part of the existing filename, hoping to get a completion, and then TAB to complete, I get the completion to the existing file name that I was after. However, also, the rename operation is actually run immediately when I hit TAB, which always fails with Cannot move to same file: /path/of/very_long_file_name_indeed.something.something. What I want is to get just the completion, so that I can edit the new filename to say very_long_file_name_indeed_renamed.something.something, without typing out the full original filename first.

I expect probably what I want here is to ask something (ivy? counsel? dired-aux? dired?) to only complete, not execute the rename.

How do I complete the filename so that I can edit it before emacs tries to rename the file?

2
  • I don't see this (or perhaps your recipe isn't clear enough? - consider giving a step-by-step recipe, starting from emacs -Q). For me, TAB just completes - it doesn't also start renaming/moving the file. Do you see the same problem if you start Emacs with emacs -Q (no init file)? If not, bisect your init file to find the culprit.
    – Drew
    Nov 13, 2022 at 16:24
  • @Drew It looks like the 'completion behavior' when selecting the filename directly is different from when selecting the filename by/after 'typing first'. Also, I'm not sure, but maybe Spacemacs modifies default Ivy behavior. Nov 13, 2022 at 17:08

1 Answer 1

1

I see what you mean. I know that Ivy's completion behavior can be configured to behave differently, so if you really want to, then you can check its documentation.

However, if you just want to get a copy with a slightly different name, then you can achieve that, from a buffer visiting the file to be renamed (not from dired), by pressing SPC u SPC f c (SPC f c is for copying the file, and by passing the universal argument SPC u the original filename already gets inserted for you). Then in Ivy you should select the input line by moving up using C-k (or the arrow up key). Now you can modify the name and press RET when finished.

3
  • For me the file path that gets inserted is (following my original example) /path/of/of -- i.e. the filename of the directory itself is appended to the directory path, instead of filename of the regular file whose name I want to edit. I tried that on the latest commit on spacemacs develop. Nov 13, 2022 at 18:15
  • Did you press SPC u SPC f c? It seems unlikely to me that the path of the original file is getting inserted, as the code that is used for reading the filename is the following: (read-file-name "Save buffer as: " nil nil nil (buffer-name)). So, when you call it correctly, then it should just insert the (buffer-name). Otherwise, can you upload an image/screenshot? Nov 13, 2022 at 19:00
  • 1
    Ahh, sorry you're suggesting doing that from a buffer visiting the file, I thought you were suggesting doing that from dired. That works! Edited the answer to make that explicit Nov 13, 2022 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.