Skip to content
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
Closed

Trouble with ivy read and initial-input #336

justbur opened this issue Jan 5, 2016 · 5 comments

Comments

@justbur
Copy link
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
Copy link
Contributor Author

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
Copy link
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
Copy link
Contributor Author

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
Copy link
Owner

abo-abo commented Jan 5, 2016

Done, have a look.

@justbur
Copy link
Contributor Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants