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

Trouble with ivy read and initial-input #336

Closed
justbur opened this Issue Jan 5, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@justbur
Contributor

justbur commented Jan 5, 2016

Hi, I'm enjoying using ivy so far, but I've run into a problem I can't figure out. I want to use ivy-read to read a file from the minibuffer, and I want to start the input with an automatically generated file name without the extension, like "01234.". I thought :initial-input would do this but it's not working as I expected. Here's my code which I modified from counsel-find-file

(ivy-read "Junk file: "
          'read-file-name-internal
          :initial-input rel-fname
          :action
          (lambda (x)
            (with-ivy-window
              (make-directory (or ivy--directory default-directory) t)
              (find-file (expand-file-name x ivy--directory))))
          :matcher #'counsel--find-file-matcher
          :keymap counsel-find-file-map)

rel-fname is the auto-generated name. I'm also let binding default-directory to start in a directory that may not exist, which is the reason for make-directory. What happens is I get a candidate that is preselected in the completions, but what I want is to be able to quickly type el RET and get the file name with an "el" extension. Does that make sense? Is there a variable I need to set? I can do M-i then el RET but I was hoping to eliminate that step. Thanks

@justbur

This comment has been minimized.

Show comment
Hide comment
@justbur

justbur Jan 5, 2016

Contributor

I should mention that I tried to use the initial-input argument of read-file-name with ivy-mode enabled and had the same result.

Contributor

justbur commented Jan 5, 2016

I should mention that I tried to use the initial-input argument of read-file-name with ivy-mode enabled and had the same result.

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Jan 5, 2016

Owner

I have (setq initial-input nil) specifically for 'read-file-name-internal. This is for e.g. rgrep and similar commands: they use the full path as initial-input resulting in a mess, since ivy uses relative paths for file name completion.

I can avoid setting it to nil when action is supplied. Would that be OK for you?

Owner

abo-abo commented Jan 5, 2016

I have (setq initial-input nil) specifically for 'read-file-name-internal. This is for e.g. rgrep and similar commands: they use the full path as initial-input resulting in a mess, since ivy uses relative paths for file name completion.

I can avoid setting it to nil when action is supplied. Would that be OK for you?

@justbur

This comment has been minimized.

Show comment
Hide comment
@justbur

justbur Jan 5, 2016

Contributor

Sure, that would work. Not sure if this is easier or what, but I'd also be fine with an optional initial-input argument for counsel-find-file. That's really all I'm after.

Contributor

justbur commented Jan 5, 2016

Sure, that would work. Not sure if this is easier or what, but I'd also be fine with an optional initial-input argument for counsel-find-file. That's really all I'm after.

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Jan 5, 2016

Owner

Done, have a look.

Owner

abo-abo commented Jan 5, 2016

Done, have a look.

@justbur

This comment has been minimized.

Show comment
Hide comment
@justbur

justbur Jan 5, 2016

Contributor

Thank you!

Contributor

justbur commented Jan 5, 2016

Thank you!

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