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

Respect `DEFAULT-FILENAME' argument of `read-file-name' #1170

Closed
Alexander-Shukaev opened this issue Aug 22, 2017 · 9 comments

Comments

@Alexander-Shukaev
Copy link

commented Aug 22, 2017

The read-file-name function offers the DEFAULT-FILENAME argument. I would have expected that whenever I run an interactive command that asks to supply a file path and utilizes this argument internally to guess the default (usually displayed in parentheses of the prompt), that file would be selected initially so that I can just tap RET and be done with it. Am I missing some configuration for this to be available or is this not implemented (yet)?

@Alexander-Shukaev

This comment has been minimized.

Copy link
Author

commented Aug 22, 2017

By the way, when using rgrep, on the second prompt, I see for example:

Search for "..." in files (default *.gz): /.../

and *.gz is already selected by ivy as the default so I can just tap RET to continue. This is good but why the same does not happen for read-file-name?

@Alexander-Shukaev

This comment has been minimized.

Copy link
Author

commented Aug 22, 2017

Furthermore, this is also somewhat related to #1142, where in case of rgrep there used to be all completion candidate and is not there anymore after one of the upgrades.

@darkfeline

This comment has been minimized.

Copy link

commented Sep 23, 2017

I experience this bug as well, this other bug provides a workaround that I would be satisfied with: #1209

@darkfeline

This comment has been minimized.

Copy link

commented Sep 27, 2017

For what it's worth, I've figured out why read-file-name-default with ivy-mode doesn't respect the default.

        (if (and default-filename
                 (string-equal val (if (consp insdef) (car insdef) insdef)))
            (setq val default-filename))
        (setq val (substitute-in-file-name val))

This fragment in read-file-name-default is responsible for replacing the "inserted default" value with the "real" default.

For example, if you're running read-abbrev-file from your home directory, read-file-name-default inserts "~/" into the minibuffer initially. If you press RET, read-file-name-default will then replace the inserted default "~/" with the "read" default "~/.emacs.d/abbrev_defs".

However, ivy-mode makes the completing-read return "/home/bob/" instead of "~/". read-file-name-default doesn't know that this is actually the initial value and thus doesn't swap it out for the "real" default.

This also means that read-abbrev-file will correctly read the default value if you're not inside your home directory, for example if you're in /. completing-read would then return "/" and read-file-name-default would swap it out with the "real" default.

@abo-abo

This comment has been minimized.

Copy link
Owner

commented Sep 27, 2017

@darkfeline Thanks for the info. It will take some work to reconcile things:

  1. I don't want ivy-read to replicate all the quirks of completing-read-default.
  2. I don't want the "incompatibility" to cause major issues for the users.

If you'd like to help, I'd appreciate a PR in this direction.

@darkfeline

This comment has been minimized.

Copy link

commented Sep 28, 2017

My instinct would be to define a ivy-read-file-name to replace read-file-name-default when ivy-mode is enabled. The issue here is strictly a mismatch between ivy-completing-read API and the completing-read API that read-file-name-default expects.

However, that API mismatch concerns me. I don't intend on touching ivy-read of course, but perhaps ivy-completing-read should be fixed to comply with completing-read-default.

@abo-abo

This comment has been minimized.

Copy link
Owner

commented Sep 28, 2017

but perhaps ivy-completing-read should be fixed to comply with completing-read-default.

This is the way to go, I think.

nxtr added a commit to nxtr/swiper that referenced this issue Aug 16, 2018
ivy.el (ivy-immediate-done): Exit with unchanged initial input
This change makes ivy-immediate-done (without any editing) to exit
completing-read with return value in same (abbreviated) form and value
as the initial input.

This fix functions read-file-name and read-directory-name to return the
default-filename with ivy-immediate-done, instead of current
input (expanded).

Fixes abo-abo#1170
@nxtr

This comment has been minimized.

Copy link
Contributor

commented Aug 16, 2018

Hey, I took another route with a ivy-immediate-done exit fix, check the PR above

@nxtr

This comment has been minimized.

Copy link
Contributor

commented Aug 17, 2018

Another related fix to choose the caller default etc. with an empty input exit.
May be radical with a prefix, but this is an explicit use case and previously not possible to enter empty string, as far as I know.

nxtr added a commit to nxtr/swiper that referenced this issue Aug 25, 2018
ivy.el (ivy-immediate-done): Exit with empty input
* Use prefix arg and ivy-immediate-done to let the user explicitly exit
  with empty input, i.e. the caller default.
* Fix `completing-read' compat
* ivy-test.el: Add relevant positive tests
* ivy.el (ivy-alt-done): Update docstring

Related to abo-abo#1170
Fixes  abo-abo#1526

@abo-abo abo-abo closed this in 8119969 Nov 19, 2018

abo-abo added a commit that referenced this issue Jul 17, 2019
ivy.el (ivy-immediate-done): Improve make-directory
1. Don't modify (ivy-state-def ivy-last).
2. "C-M-j" with no input should return (ivy-state-def ivy-last).
3. Update the test, since `read-file-name-default' will detect that
the same (eq) string was returned and return "" instead of the file
name.
4. Add a test that `ivy-read' actually returned the file name.

Re #1170
Re #1719
Fixes #2139
abo-abo added a commit that referenced this issue Jul 24, 2019
ivy.el (ivy-immediate-done): Add copy-sequence to fix read-directory-…
…name

`read-directory-name' returns "" when the completion function passes
it back the DEF argument. This is a highly questionable behavior that
some old functions depend on.

Looks like it's better to break those old functions, rather than break
the more important functions that have no idea why
`read-directory-name' returns "".

* ivy-test.el (ivy-read-file-name-in-buffer-visiting-file): Now fails.
(ivy-read-directory-name): Add test.

Fixes #2165
Fixes #2149
Re #1170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.