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

Ivy will trigger insert-char error: C-x 8 RET c will input ^F instead of ^L. #2888

Closed
hongyi-zhao opened this issue Jul 6, 2021 · 7 comments
Labels

Comments

@hongyi-zhao
Copy link

hongyi-zhao commented Jul 6, 2021

On Ubuntu 20.04, I'm using git master version of Emacs and swiper with the following configuration:

 (straight-use-package
 `(swiper :type git :host github :repo "abo-abo/swiper"
    :pre-build (
               ;("bash" "-c" "cd ~/.emacs.d/straight/repos/swiper")
               ;https://github.com/abo-abo/swiper/issues/2886#issuecomment-860605327
               ("make" "deps")
               ("make" "compile")
               )))
                    
(require 'ivy)
(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
(setq ivy-count-format "(%d/%d) ")

I found the above configuration will trigger the insert-char error: C-x 8 RET c will input ^F instead of ^L, see the screenshot below for more detailed info:

image

If I don't use the above configuration, the result will look like follows:

image

It's well known that the second should be the expected character input by the corresponding typesetting sequence.

Any hints for this problem will be highly appreciated.

Regards,
HY

@basil-conto
Copy link
Collaborator

I don't think there's anything Ivy can do about this, i.e. as far as I'm concerned it's a pilot error arising from a known limitation of eager interactive completion systems like that of Ivy.

C-x 8 RET (insert-char) reads user input using the function read-char-by-name, which unconditionally calls completing-read.

In vanilla Emacs, no completion actually takes place until the user asks for it by typing e.g. TAB. So read-char-by-name actually behaves differently depending on whether you perform completion: you can enter either a hex codepoint like c (ASCII ^L), or the equivalent Unicode name FORM FEED (FF).

With Ivy, the completion happens straight away, so typing c just filters the set of Unicode names to those containing the character c. The first such result just happens to be ACKNOWLEDE (ASCII ^F).

So the solution is to exit completion without selecting the current candidate, i.e. type C-M-j (ivy-immediate-done) instead of RET (ivy-done). See (info "(ivy) Key bindings for single selection action then exit minibuffer").

@hongyi-zhao
Copy link
Author

Got it. Thank you very much for your insightful analysis.

@basil-conto
Copy link
Collaborator

You're welcome, glad it helped.

By the way: if you have counsel installed you can also use the command counsel-unicode-char as an alternative or in addition to insert-char. It wouldn't really help in your ^L scenario, but it has the benefit of including the codepoint, Unicode name, and a character preview all in one.

By the way part two: a faster way of inserting ^L is C-q C-l (C-q causes any subsequent character sequence to be inserted literally).

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Jul 6, 2021

Thank you very much for your additional comments.

Out of curiosity, I tried this configuration, and it gives the following fancy representations when I hit C-x 8 RET:

image

Any comments/hints/suggestions with this style?

Regards,
HY

@basil-conto
Copy link
Collaborator

Any comments/hints/suggestions with this style?

Not sure what you're looking for - AFAICT that config uses Vertico, Consult, Marginalia, and Selectrum instead of Ivy and Counsel. I suggest you go with whichever set of packages works best for you.

@hongyi-zhao
Copy link
Author

Thank you again for your advice.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Jul 6, 2021

By the way: if you have counsel installed you can also use the command counsel-unicode-char as an alternative or in addition to insert-char.

Thanks. I adopted the key binding suggested here:

("C-x 8 RET" . counsel-unicode-char)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants