From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help 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 Message-ID: References: <83mtr5jkpb.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36037"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: Eli Zaretskii Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jul 02 09:24:25 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lzDXE-0009Bz-Vx for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 02 Jul 2021 09:24:25 +0200 Original-Received: from localhost ([::1]:42712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lzDXE-0005iW-1K for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 02 Jul 2021 03:24:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lzDWU-0005de-LR for help-gnu-emacs@gnu.org; Fri, 02 Jul 2021 03:23:39 -0400 Original-Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]:38806) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lzDWS-0004yz-SR; Fri, 02 Jul 2021 03:23:38 -0400 Original-Received: by mail-lj1-x22d.google.com with SMTP id x20so12063962ljc.5; Fri, 02 Jul 2021 00:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UHTabmsm8ux22F+sOw47eDv124xjDAKNx9lBTpE55c4=; b=Obu9IUsvCeCZ8J7P0dDiVyk9xiDazSUR7ji0Vkf326JfqwquztLz3wenBRpugnyRFJ F3QtTMIlqkXhkCxo/hB73BbIj5xQ9x1MgNOxZR6xsV6skJ1jO+9hiNnfxk2SLgqNw2pm VmxU0ySuO8TqrQJpb8Tvye0Goc3+4gzqWRroTh06V6MEM+NCiyLSa5VgNwLnYwKsqml6 k1U31XamG6PmwiasPtQz4wVQEUf//SuNbEivKM8GLdRvLoPpvfVYdGkHmEKuWYzy3+N9 yWuuysCdJqjKZp8LJSP7TF3op1hMZoZpsLEBfw9A2JD6J7sGSecGbx91H3omM2Y4jwzj BlAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UHTabmsm8ux22F+sOw47eDv124xjDAKNx9lBTpE55c4=; b=DhWbxKfrFtd6U0lmUgAlHuXAQBceemy5TkY8nKpgVrCS4JyNJa1smUy71JcfuNQU6b lrnCY50/8ZZKA2poFTYy/GxCfoUTW+SK/sZ+/C5p0F80+ZJyTTRPIvZVdnUDNUI357yl 8EuSR8x5XiUGz4Ap9jVIG2h/oB3pRG3ItVlc6gHmT8a7cWOrNOjI/hIv+uLlG3LGkdBi PU7gD+kvpBP8Cse+dc7Sad3jmnSIyu3Hga65+j8Zz5Th9K0sRKgkgyNfhGFl20ceRdvG uStsopIIlGjsuID3RuNtYoq+Rls8hY1bZ/DfWeeDvOmKt/iZb5ATgFtYH5HVNxVFeDMw 1p/w== X-Gm-Message-State: AOAM5336ujXBPhyt6Ry74Ch2ALOSwuq5nBG45LzVEVoVIwn4yUs/TtJJ nQwqBZ358EnhrxQwoJSap/9N6nYf3pGjCPMcvuZL3r1z13MNXOXqoJ0= X-Google-Smtp-Source: ABdhPJzYoYSTnTnmgSz/IP4F1Qon5rLqHVjbRmoanFmFxx9VXwflV5g1WxqhqG8YCaHvFx47GqJeXFfzQWf/MOtageY= X-Received: by 2002:a2e:97cf:: with SMTP id m15mr2813106ljj.246.1625210614327; Fri, 02 Jul 2021 00:23:34 -0700 (PDT) In-Reply-To: <83mtr5jkpb.fsf@gnu.org> Received-SPF: pass client-ip=2a00:1450:4864:20::22d; envelope-from=hongyi.zhao@gmail.com; helo=mail-lj1-x22d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:131378 Archived-At: 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 "\\`" (mapconcat (lambda (x) (concat "[^" (string x) "]*?" (string x))) infix "") ".*\\'")) (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)) candidates) ;; Implement completion-try-completions interface (cond ((and (= (length candidates) 1) (equal infix (car candidates))) t) ((= (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 '(naive-fuzzy completion-naive-fuzzy-try-completion completion-naive-fuzzy-all-completions "Simple naive-fuzzy completion, which never alters the string to complete, unless a unique match exists.")) ;; (setq-local completion-styles '(naive-fuzzy)) HY > > 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