New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add variable to customize behavior of the magic slash on non-existing directories #998

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
3 participants
@gilbertw1
Contributor

gilbertw1 commented May 11, 2017

Added variable ivy-magic-slash that controls whether or not the 'magic slash' is applied when selecting files. If non-nil (default) the magic slash will be applied, if set to nil then the magic slash will not be applied.

The personal pain point this solved for me is creating files in non-existing directories. As an example, with the 'magic-slash' enabled I found it impossible to create ~/docs/todo.org when the folder ~/docs did not exist and the folder ~/Documents did exist. Adding the / after docs resulted in ivy--cd being called with the Documents directory.

@abo-abo

This comment has been minimized.

Owner

abo-abo commented May 11, 2017

I don't see the need to disable the feature altogether. You can turn off just the 5th cond branch of ivy--magic-file-slash.

You can even add more magic: the slash could create a directory if it doesn't exist.

@gilbertw1

This comment has been minimized.

Contributor

gilbertw1 commented May 11, 2017

Is it possible to prompt the user from the ivy minibuffer? I.e. if a user were to enter docs and then add a /, ivy could prompt the user with something like: create directory 'docs' (y/n).

If we could do that, then I would be in favor of the magic solution. However, I don't think it'd be a great idea to create directories behind the scenes if a slash is added. If that is the case I'll just add a configuration to prevent the magic slash functionality on non-matches (case 5).

@gilbertw1

This comment has been minimized.

Contributor

gilbertw1 commented May 12, 2017

@abo-abo I've updated this pull request to allow the magic slash behavior to be customized when added to the end of a non-existing directory.

I've added the variable: ivy-magic-slash-non-match-action, which has the possible values:

  • ivy-magic-slash-non-match-use-selected - cd into the currently selected directory or add the / literally if there are no matches (current behavior)
  • ivy-magic-slash-non-match-create - create the non existing directory and cd into it
  • nil - do nothing and just add the slash literally

The setting defaults to the current behavior (ivy-magic-slash-non-match-use-selected), and allows the user to pick which behavior they prefer. Let me know what you think of this solution, and if you think the naming of these settings are okay.

Also, tried out adding a y/n prompt on creating the directory, but it resulted in a pretty poor user experience. The auto creation of directories works out pretty nicely.

Thanks!

@gilbertw1 gilbertw1 changed the title from add variable 'ivy-magic-slash' that adds ability to disable magic slash to add variable to customize behavior of the magic slash on non-existing directories May 12, 2017

@abo-abo

This comment has been minimized.

Owner

abo-abo commented May 13, 2017

Thanks, looks good. For changes over 15 lines you need an Emacs Copyright Assignment. If you want to get it, see README.org for more info.

@gilbertw1

This comment has been minimized.

Contributor

gilbertw1 commented May 13, 2017

Cool, I'll get that done asap

@gilbertw1

This comment has been minimized.

Contributor

gilbertw1 commented May 15, 2017

I've completed the copyright assignment ... you can find a copy of it here:

http://drop.bryan.codes/Gilbert.1162228.EMACS.pdf

Thanks!

@abo-abo abo-abo closed this in 7621e5f May 15, 2017

@abo-abo

This comment has been minimized.

Owner

abo-abo commented May 15, 2017

Thanks.

@braham-snyder

This comment has been minimized.

Contributor

braham-snyder commented May 16, 2017

think there's a small naming bug: #1009

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment