2

I have an existing directory called ~/app_scripts and a buffer open with a file I would like to save. I want to save it to ~/scripts/script.py, but the ~/scripts dir does not yet exist. When I hit C-x C-s to save, I try to type ~/scripts/ but it keeps autocompleting to ~/app_scripts. How do I make it stop over-autocorrecting and let me choose a file name? I cannot use C-M-j because that will immediately save the file at ~/scripts (with no filename), instead of allowing me to continue to type the path I want.

Note: I'm not sure if this problem is Ivy-related or not, but I think it might be relevant to the problem.

marked as duplicate by Basil, Stefan, Drew, tarsius, zck Sep 17 '18 at 22:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

I cannot use C-M-j because that will immediately save the file at ~/scripts (with no filename), instead of allowing me to continue to type the path I want.

Both vanilla Emacs and Ivy let you save to non-existing files within non-existing directories by specifying literal /-delimited file names without completion.

The problem in this case is that Ivy interprets / specially by default. Namely, typing / during Ivy file name completion will descend into the currently selected directory candidate, if one exists.

Thankfully, Ivy provides a user option to control this behaviour:

ivy-magic-slash-non-match-action is a variable defined in ‘ivy.el’.
Its value is ‘ivy-magic-slash-non-match-cd-selected’

Documentation:
Action to take when a slash is added to the end of a non existing directory.
Possible choices are ’ivy-magic-slash-non-match-cd-selected,
’ivy-magic-slash-non-match-create, or nil

You can customize this variable.

The default, ivy-magic-slash-non-match-cd-selected, will descend into the currently selected directory candidate, as mentioned above. ivy-magic-slash-non-match-create will, upon typing /, create a directory with a name corresponding to the current minibuffer input. nil is like vanilla Emacs in that it does not handle / specially.

So, for example, you can:

(setq ivy-magic-slash-non-match-action nil)

followed by C-xC-s~/scripts/script.pyRETy.

I'm not sure if this problem is Ivy-related or not

It is, as you can confirm by disabling ivy-mode.


See also https://github.com/abo-abo/swiper/issues/1532.

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