emacs-devel
[Top][All Lists]
Advanced

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

Re: [elpa] externals/typo 88522ea4c8 1/2: Handle hash-tables with symbol


From: Philip Kaludercic
Subject: Re: [elpa] externals/typo 88522ea4c8 1/2: Handle hash-tables with symbols as keys
Date: Sat, 22 Jul 2023 14:10:16 +0000

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>     Handle hash-tables with symbols as keys
>
> How 'bout
>
>     (defun typo-edits (word collection pred)
>       "Generate a list of all multi-edit typos of WORD.
>     Only words that are in the COLLECTION and satisfy PRED will be
>     returned.  The variable `typo-level' specifies how many
>     single-letter typos are searched."
>       (seq-filter pred (all-completions "" collection)))
>
> Instead?

Isn't that the "identity" completion style?  If anything, it would have
to be something like

--8<---------------cut here---------------start------------->8---
(defun typo-edits (word collection pred)
  "Generate a list of all multi-edit typos of WORD.
Only words that are in the COLLECTION and satisfy PRED will be
returned.  The variable `typo-level' specifies how many
single-letter typos are searched."
  (let (completions)
    (dolist (comp (all-completions "" collection))
      (when (and (funcall pred comp) (typo--test word comp))
        (push comp completions)))
    completions))
--8<---------------cut here---------------end--------------->8---

IIRC I tried something like this at some point, but was not sure if
`all-completions' would re-use `completion-styles'.  But looking at the
source code right now, it seems it would be safe, and the code seems to
work.

One potential issue, is PRED always non-nil?

> BTW, this is a good example of the problem with the `predicate` argument
> of `all-completions` (which can't be used here, because it gets called
> differently depending on the type of `collection`).

What would the issue be?  I tried it out, and everything still seemed to
do the right thing.

>         Stefan



reply via email to

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