Skip to content

Trouble with ivy read and initial-input #336

@justbur

Description

@justbur

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions