[Top][All Lists]

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

Re: Incrementally display the Emacs command list filtered out by the inp

From: Hongyi Zhao
Subject: Re: Incrementally display the Emacs command list filtered out by the input key words in real-time.
Date: Fri, 2 Jul 2021 15:23:22 +0800

On Fri, Jul 2, 2021 at 2:26 PM Eli Zaretskii <> wrote:
> > From: Hongyi Zhao <>
> > Date: Fri, 2 Jul 2021 13:22:11 +0800
> >
> > Say, when I input "foo bar", the matched command list are
> > incrementally displayed immediately, and finally the ones which
> > including "foo" and "bar" in any part of the candidate commands are
> > filtered out. How do I configure my init file to implement this
> > feature?
> Explore the various completion styles, perhaps rearranging their order
> in the variable completion-styles (see its doc string and the
> documentation in the user manual for details).

I tried the following code snippet posted at
but there is no effect at all:

(defun completion-naive-fuzzy-completion (string table predicate point
                                                 &optional all-p)
  (let* ((beforepoint (substring string 0 point))
         (afterpoint (substring string point))
         (boundaries (completion-boundaries beforepoint table
predicate afterpoint))
         (prefix (substring beforepoint 0 (car boundaries)))
         (infix (concat
                 (substring beforepoint (car boundaries))
                 (substring afterpoint 0 (cdr boundaries))))
         (suffix (substring afterpoint (cdr boundaries)))
         ;; |-              string                  -|
         ;;              point^
         ;;            |-  boundaries -|
         ;; |- prefix -|-    infix    -|-  suffix   -|
         ;; Infix is the part supposed to be completed by table, AFAIKT.
         (regexp (concat "\\`"
                          (lambda (x)
                            (concat "[^" (string x) "]*?" (string x)))
         (candidates (cl-remove-if-not
                      (apply-partially 'string-match-p regexp)
                      (all-completions prefix table predicate))))
    (if all-p
        ;; Implement completion-all-completions interface
        (when candidates
          ;; Not doing this may result in an error.
          (setcdr (last candidates) (length prefix))
      ;; Implement completion-try-completions interface
       ((and (= (length candidates) 1)
             (equal infix (car candidates)))
       ((= (length candidates) 1)
        ;; Avoid quirk of double / for filename completion. I don't
        ;; know how this is *supposed* to be handled.
        (when (and (> (length (car candidates)) 0)
                   (> (length suffix) 0)
                   (char-equal (aref (car candidates)
                                     (1- (length (car candidates))))
                               (aref suffix 0)))
          (setq suffix (substring suffix 1)))
        (cons (concat prefix (car candidates) suffix)
              (length (concat prefix (car candidates)))))
       ;; Do nothing, i.e leave string as it is.
       (t (cons string point))))))

(defun completion-naive-fuzzy-try-completion (string table predicate point)
  (completion-naive-fuzzy-completion string table predicate point))
(defun completion-naive-fuzzy-all-completions (string table predicate point)
  (completion-naive-fuzzy-completion string table predicate point 'all))

(add-to-list 'completion-styles-alist
               "Simple naive-fuzzy completion, which never alters the
string to complete, unless a unique match exists."))

;; (setq-local completion-styles '(naive-fuzzy))

> And maybe try an alternative completion mode, like icompletion-mode.

Assoc. Prof. Hongyi Zhao <>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China

reply via email to

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