GithubHelp home page GithubHelp logo

In eshell's completion-at-point, consult-completion-in-region places the minibuffer point in the middle of the completion string about consult HOT 19 CLOSED

minad avatar minad commented on August 19, 2024
In eshell's completion-at-point, consult-completion-in-region places the minibuffer point in the middle of the completion string

from consult.

Comments (19)

minad avatar minad commented on August 19, 2024 2

If it is not our bug, I would not fix it here. As long as we are sure we did everything alright.

from consult.

tomfitzhenry avatar tomfitzhenry commented on August 19, 2024 1

Workaround: Remove this clause:

consult/consult.el

Lines 627 to 632 in b5cbc61

(if (eq category 'file)
(read-file-name "Completion: "
(file-name-directory initial)
initial t
(file-name-nondirectory initial)
predicate)

More practical workaround:

(add-hook 'eshell-mode-hook
          (lambda ()
            (setq-local completion-in-region-function 'completion--in-region)))

from consult.

oantolin avatar oantolin commented on August 19, 2024 1

Exploiting the undefined behavior seems to work just fine, and it really isn't likely to change any time soon. I'll make a pull request.

from consult.

minad avatar minad commented on August 19, 2024

@oantolin ideas?

from consult.

oantolin avatar oantolin commented on August 19, 2024

Huh. Like @tomfitzhenry pointed out, it's read-file-name that's doing that! I don't know why, but it chooses to put point before the argument initial rather than at the end of the minibuffer. That doesn't seem like a very good default. We could just not use read-file-name, but it is nice to have your special keybindings from minibuffer-local-filename-completion-map present.

How about just forcing the move to the end of line? We can wrap the call to read-file-name in (minibuffer-with-setup-hook #'end-of-line _____).

from consult.

minad avatar minad commented on August 19, 2024

@tomfitzhenry are you using selectrum or icomplete btw?

from consult.

tomfitzhenry avatar tomfitzhenry commented on August 19, 2024

@tomfitzhenry are you using selectrum or icomplete btw?

I can reproduce this issue with emacs -q (so not even icomplete is enabled), and with icomplete. I haven't tried selectrum.

from consult.

oantolin avatar oantolin commented on August 19, 2024

It's definitely something that read-file-name-default does. Selectrum uses its own setting for read-file-name-function, so it's possible it behaves differently.

from consult.

tomfitzhenry avatar tomfitzhenry commented on August 19, 2024

Huh. Like @tomfitzhenry pointed out, it's read-file-name that's doing that! I don't know why, but it chooses to put point before the argument initial rather than at the end of the minibuffer. That doesn't seem like a very good default.

I'll try to reproduce this using just read-file-name, and raise that issue upstream. Working around bugs long-term isn't sustainable.

from consult.

tomfitzhenry avatar tomfitzhenry commented on August 19, 2024

The steps to reproduce are simple. I'll raise this upstream.

(read-file-name-default "Read File: " nil nil nil "Initial" nil)

from consult.

minad avatar minad commented on August 19, 2024

Regarding the initial value - this has been deprecated for the completing-read API, but for the read-file-name API it is fine? The docs only say "Please note: we recommend using default rather than initial in most cases". See https://www.gnu.org/software/emacs/manual/html_node/elisp/Reading-File-Names.html.

from consult.

tomfitzhenry avatar tomfitzhenry commented on August 19, 2024

Further, that page says "If you specify initial, that is an initial file name to insert in the buffer (after directory, if that is inserted). In this case, point goes at the beginning of initial."

That is, the behaviour we observe is the expected behaviour. I can't tell why that is desirable behaviour (even given the described example of find-alternate-file).

I won't raise this upstream: it's working as intended.

Our options:
i. don't use read-file-name
ii. figure out a way to do this via default. I can't see how we would. default appears to be used for when selection fails, not as a means of pre-populating the minibuffer UI (it doesn't).
iii. It looks like we can include the file name in the dir argument: (read-file-name-default "Read File: " "~/foo" nil nil nil nil) does put point where we expect, and matches file "~/foobar". This appears to be undefined behaviour.
iv. Advise, as in #48 (comment)

from consult.

tomfitzhenry avatar tomfitzhenry commented on August 19, 2024

I lean towards (i) since:

  1. It's cleanest.
  2. It's easier to add read-file-name later (if we figure out a clean way to do it), than to remove it later when people may depend on it, if supporting this unclean solution proves too burdensome.

it is nice to have your special keybindings from minibuffer-local-filename-completion-map present

How important is this usecase? Are there file-specific bindings that people would want during a completion-at-point?

from consult.

minad avatar minad commented on August 19, 2024

Why not raise it upstream, if you think it is bad behavior? Option (i) would revert the special behavior for files, which has been done for consistency with how selectrum. It and it also makes sense to use read-file for the file category, I think. But I was not really involved the design of this function, @oantolin made it and we got some feedback by @clemera.

from consult.

tomfitzhenry avatar tomfitzhenry commented on August 19, 2024

I think I've found a way to avoid using read-file-name, but keep minibuffer-local-filename-completion-map bindings. It looks like we can set minibuffer-completing-file-name to t to tell the minibuffer to treat this as a filename.

Update: This works, but prompts with a relative path (and so doesn't look like a prompt for a filename). Try to make that an absolute prompt, and then results are absolute. Fixing that partly amounts to reimplementing read-file-name!

from consult.

minad avatar minad commented on August 19, 2024

@tomfitzhenry Since this already has issues and it won't work nicely with recursive minibuffer I think it would be better to keep using read-file-name or not use it at all. But this has to be discussed. See #31 for the original discussion.

from consult.

oantolin avatar oantolin commented on August 19, 2024

Personally, I'd go with @tomfitzhenry's option (iii), use the directory argument: even if this behavior is not documented it seems unlikely to change.

from consult.

minad avatar minad commented on August 19, 2024

Haha, the undefined behavior. I am fine with it as long as it works. If at some point it stops working we can file a bugreport to upstream 🙈

from consult.

minad avatar minad commented on August 19, 2024

Closed by #63

from consult.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.