emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] (icomplete-vertical-mode): Add support for affixations and,


From: João Távora
Subject: Re: [PATCH] (icomplete-vertical-mode): Add support for affixations and, annotations
Date: Wed, 26 May 2021 19:12:56 +0100

> > Icomplete already should somehow work as a
> > `completion-in-region-function`, but I think it is a bit brittle.
> I have a vague recollection that Someone Somewhere (tm) in one of my
> extensions over at GitHub tried it out and found it could mostly work
> with some tweaks.  Will search for it.

Found it, it was in https://github.com/joaotavora/eglot/issues/577,
and the author,
Daniel Semyonov, is using `completing-read` directly. IOW it's not specific
to icomplete at all.  Here is his code.

In that issue he states that Eglot's completion table is problematic, and
he's probably right, but the general idea of making a
completion-in-region-function
from completing-read is very interesting.  It would in principle mean that every
completing-read frontend could also be used in many other places.

João

(defun init-ui-completing-read-in-region (start end col &optional pred)
  "Completion in region function utilizing `completing-read'."
  (if (minibufferp) (completion--in-region start end col pred)
    (let* ((buffer (current-buffer))
           (pos (list start end))
           (init (buffer-substring-no-properties start end))
           (all (all-completions init col pred))
           (try (try-completion init col pred)))
      (setq this-command #'completion-at-point)
      (cond ((or (eq try t) ; Sole completion.
                 (and (= (length all) 1)
                      (string= (car all) try)))
             (choose-completion-string (car all) buffer pos)
             t)
            ;; Commented out since try-completion erroneously returns nil.
            ;; ((and (null try) ; No completions.
            ;;       (> (length init) 0))
            ;;  (message "No completion")
            ;;  nil)
            (t ; Some completions.
             (choose-completion-string
              (completing-read "Completion: " col pred t init) buffer pos)
             t)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]