minad / corfu

:desert_island: corfu.el - COmpletion in Region FUnction
GNU General Public License v3.0
1.13k stars 44 forks source link

New approach for quitting on field boundary #119

Closed minad closed 2 years ago

minad commented 2 years ago

OK, I have a corfu-auto + orderless setup that works very well for me. Happy to put it on the wiki if it isn't too esoteric. The idea is:

This works really well in practice. All I have to do is remember to M-SPC instead of SPC with corfu the first time only when I want to use multiple orderless filters. And the default quit-on-boundary basically eliminates all the false-positives, e.g. defining new variables, random words in strings or comments that my cape-ified dabbrev-enabled capf throws, etc. But still lets you use full orderless power with regexps, etc. in buffer. The only small drawback is the potential for unicode chars to persist in your buffer (if you C-g with a multi-component filter), hence my interest in a quick undo-and-quit, above.

Thoughts? Suggesting an advice is obviously not ideal for the wiki. Is there a predicate config option you are considering which might work instead for this corfu--post-command :around advice?

  (defun my/corfu-disable-quit-with-orderless-advice (func)
    (let ((corfu-quit-at-boundary
       (not (seq-contains (car corfu--input)
                  my/orderless-unicode-separator))))
      (funcall func)))

Originally posted by @jdtsmith in https://github.com/minad/corfu/issues/109#issuecomment-1030686690

minad commented 2 years ago

See discussion following in #109 https://github.com/minad/corfu/issues/109#issuecomment-1030688695

jdtsmith commented 2 years ago

Here's another nice unicode option (#x00b7, MIDDLE DOT):

image
minad commented 2 years ago

Why not just use space? If we dynamically turn off the boundary check for M-SPC we can do that.

jdtsmith commented 2 years ago

OK, yeah, better; so also check the command keys for disabling boundary check? We of course still want a normally-typed space to quit. And then for any further spaces entered, you'd also be checking for existing spaces in the input, so that'd work.

minad commented 2 years ago

Yes, sure. It would require you to configure two things: 1. The separator corfu-separator-char and 2. bind a new command corfu-insert-separator to a key of your choice.

Cletip commented 1 year ago

Hello !

I thought the workflow for using corfu effectively, and discovered (or just find one time again after someone else ?) something very nice (I think), with the following behaviour:

Here's the code that should normally work:

(setq corfu-separator 32)

  ;; highly recommanded to use corfu-separator with "32" (space)
    (define-key corfu-map (kbd "SPC")
      (lambda ()
    (interactive)
    (if current-prefix-arg
        ;;we suppose that we want leave the word like that, so do a space
        (progn 
          (corfu-quit)
          (insert " "))
      (if (and (= (char-before) corfu-separator)
           (or
            (= (char-after) ?\s)
            (= (char-after) ?\n)))
          (progn
        (corfu-insert)
        (insert " "))
        (corfu-insert-separator)))))

We can now type "spc" to insert a separator (and using orderless), and "spc spc" to insert the current candidate.

What do you think about this ?

minad commented 1 year ago

@Cletip Thanks, feel free to add your code to the Corfu wiki. I don't see much of a difference to the current approach:

Cletip commented 1 year ago

Ok thanks The problem was that I wanted the same key to insert the separator and insert the candidate, I feel that much more natural.

minad commented 1 year ago

Ok thanks The problem was that I wanted the same key to insert the separator and insert the candidate, I feel that much more natural.

Sure, there is nothing wrong to use this in your user configuration. Please also add it to the wiki for other users. To me it does not look more natural, considering how Emacs usually works. Emacs uses many different keys and keys with modifiers.