all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Incrementally display the Emacs command list filtered out by the input key words in real-time.
@ 2021-07-02  5:22 Hongyi Zhao
  2021-07-02  6:25 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Hongyi Zhao @ 2021-07-02  5:22 UTC (permalink / raw)
  To: help-gnu-emacs

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?

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Incrementally display the Emacs command list filtered out by the input key words in real-time.
  2021-07-02  5:22 Incrementally display the Emacs command list filtered out by the input key words in real-time Hongyi Zhao
@ 2021-07-02  6:25 ` Eli Zaretskii
  2021-07-02  7:23   ` Hongyi Zhao
  2021-07-02 14:43 ` [External] : " Drew Adams
  2021-07-03 18:49 ` Marcin Borkowski
  2 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2021-07-02  6:25 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Hongyi Zhao <hongyi.zhao@gmail.com>
> 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).

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Incrementally display the Emacs command list filtered out by the input key words in real-time.
  2021-07-02  6:25 ` Eli Zaretskii
@ 2021-07-02  7:23   ` Hongyi Zhao
  2021-07-02 12:40     ` Tassilo Horn
  0 siblings, 1 reply; 9+ messages in thread
From: Hongyi Zhao @ 2021-07-02  7:23 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Fri, Jul 2, 2021 at 2:26 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Hongyi Zhao <hongyi.zhao@gmail.com>
> > 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
<https://emacs.stackexchange.com/questions/13500/fuzzy-completion-style>,
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 <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Incrementally display the Emacs command list filtered out by the input key words in real-time.
  2021-07-02  7:23   ` Hongyi Zhao
@ 2021-07-02 12:40     ` Tassilo Horn
  2021-07-02 15:27       ` Hongyi Zhao
  0 siblings, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2021-07-02 12:40 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> I tried the following code snippet posted at
> <https://emacs.stackexchange.com/questions/13500/fuzzy-completion-style>,
> but there is no effect at all:

Emacs already has a fuzzy completion style (see the `flex' entry in
`completion-styles-alist'), no need to copy&paste some 6 year old
implementation from the internet.

> (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))

Try (setq completion-styles '(flex)).  But note that the used
`completion-styles' just defines how the input is matched against the
things to be completed, i.e., you'll see no visual difference.  See the
manual at (info "(emacs) Completion Styles").

To have a more visual UI, follow Eli's advice:

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

It is called `icomplete-mode'.

Another very nice UI is the `vertico' package from GNU ELPA.  Other
popular choices include ivy, selectrum, etc.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [External] : Incrementally display the Emacs command list filtered out by the input key words in real-time.
  2021-07-02  5:22 Incrementally display the Emacs command list filtered out by the input key words in real-time Hongyi Zhao
  2021-07-02  6:25 ` Eli Zaretskii
@ 2021-07-02 14:43 ` Drew Adams
  2021-07-02 15:40   ` Hongyi Zhao
  2021-07-03 18:49 ` Marcin Borkowski
  2 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2021-07-02 14:43 UTC (permalink / raw)
  To: Hongyi Zhao, help-gnu-emacs

> 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?

Not too sure what you're asking for.

1. You say you want to first see command-name
   matches for input `foo bar'.
2. But then you say you want command names that
   contain either `foo' or `bar' to be filtered
   out (i.e., excluded).

Those two seem contradictory.  The first seems
unnecessary - undone by the second.  But maybe
you just want to see all command names at first,
for some reason.

Anyway, if what you want is instead something
like this:

1. You see all command names initially.
2. You type something to exclude the names that
   contain either `foo' or `bar'.

Then that's trivial if you use Icicles.

1. To see all completions initially, set or bind
   variable `icicle-show-Completions-initially-flag'
   to non-nil.

2. To exclude matches of some pattern (e.g. `foo'):

   a. Type the pattern, to see _only_ its matches.
   b. Use `C-~' to get the complement, i.e., to
      subtract those matches from the previous set
      of matches. 

E.g., to exclude all matches for `foo' or `bar'
(anywhere in the command name, i.e., in any order):

1. Type `foo C-~' to see all except `foo' matches.
2. Type `bar C-~' to see all except matches for
   `foo' or `bar'.

See also:

* https://www.emacswiki.org/emacs/Icicles_-_Nutshell_View#ChippingAway

* https://www.emacswiki.org/emacs/Icicles_-_Candidate_Sets#SetOperations

If you don't really care to show all completions for
empty input (e.g. all command names), then leave
`icicle-show-Completions-initially-flag' nil.

By default, you can just use `TAB' or `S-TAB' to
initiate completion.  Doing that once suffices:
completions are then updated automatically as you
change your minibuffer input.

If you want completions to be updated automatically
whenever you change minibuffer input without having
to use `TAB' or `S-TAB', but you don't want to show
completions initially (i.e., with empty input), then
set variable `icicle-incremental-completion' to
non-nil and non-t (the default value is `t').

[You can cycle its value any time, using `C-#' during
completion: OFF, ON (initiated by `TAB' or `S-TAB'),
or eager (initiated by typing anything).]

See: https://www.emacswiki.org/emacs/Icicles_-_Icompletion#IncrementalCompletion

___

There is, BTW, no "fuzzy" matching involved in
your example of excluding `foo' and `bar' matches.
However, Icicles does support fuzzy matching -
seven kinds of fuzzy matching, in fact.

See https://www.emacswiki.org/emacs/Icicles_-_Completion_Methods_and_Styles#FuzzyCompletion

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Incrementally display the Emacs command list filtered out by the input key words in real-time.
  2021-07-02 12:40     ` Tassilo Horn
@ 2021-07-02 15:27       ` Hongyi Zhao
  0 siblings, 0 replies; 9+ messages in thread
From: Hongyi Zhao @ 2021-07-02 15:27 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

On Fri, Jul 2, 2021 at 8:51 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > I tried the following code snippet posted at
> > <https://emacs.stackexchange.com/questions/13500/fuzzy-completion-style>,
> > but there is no effect at all:
>
> Emacs already has a fuzzy completion style (see the `flex' entry in
> `completion-styles-alist'), no need to copy&paste some 6 year old
> implementation from the internet.
>
> > (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))
>
> Try (setq completion-styles '(flex)).  But note that the used
> `completion-styles' just defines how the input is matched against the
> things to be completed, i.e., you'll see no visual difference.  See the
> manual at (info "(emacs) Completion Styles").
>
> To have a more visual UI, follow Eli's advice:
>
> >> And maybe try an alternative completion mode, like icompletion-mode.
>
> It is called `icomplete-mode'.
>
> Another very nice UI is the `vertico' package from GNU ELPA.  Other
> popular choices include ivy, selectrum, etc.

Thank you very much for providing me with all kinds of information on
the packages which can achieve this aim. Based on my tries, it seems
that the ivy package, <https://github.com/abo-abo/swiper>, is one of
the most powerful one for this purpose. And the following simple
configuration can achieve the effect described here:

;;;
(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) ")
;;;

HY
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [External] : Incrementally display the Emacs command list filtered out by the input key words in real-time.
  2021-07-02 14:43 ` [External] : " Drew Adams
@ 2021-07-02 15:40   ` Hongyi Zhao
  0 siblings, 0 replies; 9+ messages in thread
From: Hongyi Zhao @ 2021-07-02 15:40 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs

On Fri, Jul 2, 2021 at 10:43 PM Drew Adams <drew.adams@oracle.com> wrote:
>
> > 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?
>
> Not too sure what you're asking for.
>
> 1. You say you want to first see command-name
>    matches for input `foo bar'.
> 2. But then you say you want command names that
>    contain either `foo' or `bar' to be filtered
>    out (i.e., excluded).
>

Sorry for my misleading/erroneous description. I mean 1. above-mentioned by you.


> Those two seem contradictory.  The first seems
> unnecessary - undone by the second.  But maybe
> you just want to see all command names at first,
> for some reason.
>
> Anyway, if what you want is instead something
> like this:
>
> 1. You see all command names initially.
> 2. You type something to exclude the names that
>    contain either `foo' or `bar'.
>
> Then that's trivial if you use Icicles.
>
> 1. To see all completions initially, set or bind
>    variable `icicle-show-Completions-initially-flag'
>    to non-nil.
>
> 2. To exclude matches of some pattern (e.g. `foo'):
>
>    a. Type the pattern, to see _only_ its matches.
>    b. Use `C-~' to get the complement, i.e., to
>       subtract those matches from the previous set
>       of matches.
>
> E.g., to exclude all matches for `foo' or `bar'
> (anywhere in the command name, i.e., in any order):
>
> 1. Type `foo C-~' to see all except `foo' matches.
> 2. Type `bar C-~' to see all except matches for
>    `foo' or `bar'.
>
> See also:
>
> * https://www.emacswiki.org/emacs/Icicles_-_Nutshell_View#ChippingAway
>
> * https://www.emacswiki.org/emacs/Icicles_-_Candidate_Sets#SetOperations
>
> If you don't really care to show all completions for
> empty input (e.g. all command names), then leave
> `icicle-show-Completions-initially-flag' nil.
>
> By default, you can just use `TAB' or `S-TAB' to
> initiate completion.  Doing that once suffices:
> completions are then updated automatically as you
> change your minibuffer input.
>
> If you want completions to be updated automatically
> whenever you change minibuffer input without having
> to use `TAB' or `S-TAB', but you don't want to show
> completions initially (i.e., with empty input), then
> set variable `icicle-incremental-completion' to
> non-nil and non-t (the default value is `t').
>
> [You can cycle its value any time, using `C-#' during
> completion: OFF, ON (initiated by `TAB' or `S-TAB'),
> or eager (initiated by typing anything).]
>
> See: https://www.emacswiki.org/emacs/Icicles_-_Icompletion#IncrementalCompletion
>
> ___
>
> There is, BTW, no "fuzzy" matching involved in
> your example of excluding `foo' and `bar' matches.
> However, Icicles does support fuzzy matching -
> seven kinds of fuzzy matching, in fact.
>
> See https://www.emacswiki.org/emacs/Icicles_-_Completion_Methods_and_Styles#FuzzyCompletion

Thank you again for letting me know there are so many choices to
achieve this aim. Based on another hint/suggestion given by
Tassilo Horn <tsdh@gnu.org>, I'm currently using the following
settings to obtain this effect:

;;;
(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) ")
;;;

Regards
--
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Incrementally display the Emacs command list filtered out by the input key words in real-time.
  2021-07-02  5:22 Incrementally display the Emacs command list filtered out by the input key words in real-time Hongyi Zhao
  2021-07-02  6:25 ` Eli Zaretskii
  2021-07-02 14:43 ` [External] : " Drew Adams
@ 2021-07-03 18:49 ` Marcin Borkowski
  2021-07-03 23:39   ` Hongyi Zhao
  2 siblings, 1 reply; 9+ messages in thread
From: Marcin Borkowski @ 2021-07-03 18:49 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs


On 2021-07-02, at 07:22, Hongyi Zhao <hongyi.zhao@gmail.com> wrote:

> 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?

Install Ivy?

Hth,

-- 
Marcin Borkowski
http://mbork.pl



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Incrementally display the Emacs command list filtered out by the input key words in real-time.
  2021-07-03 18:49 ` Marcin Borkowski
@ 2021-07-03 23:39   ` Hongyi Zhao
  0 siblings, 0 replies; 9+ messages in thread
From: Hongyi Zhao @ 2021-07-03 23:39 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: help-gnu-emacs

On Sun, Jul 4, 2021 at 2:49 AM Marcin Borkowski <mbork@mbork.pl> wrote:
>
>
> On 2021-07-02, at 07:22, Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> > 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?
>
> Install Ivy?

Yes. It does the trick, as I've posted here. But what about helm for
this purpose?

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-07-03 23:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-02  5:22 Incrementally display the Emacs command list filtered out by the input key words in real-time Hongyi Zhao
2021-07-02  6:25 ` Eli Zaretskii
2021-07-02  7:23   ` Hongyi Zhao
2021-07-02 12:40     ` Tassilo Horn
2021-07-02 15:27       ` Hongyi Zhao
2021-07-02 14:43 ` [External] : " Drew Adams
2021-07-02 15:40   ` Hongyi Zhao
2021-07-03 18:49 ` Marcin Borkowski
2021-07-03 23:39   ` Hongyi Zhao

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.