[Top][All Lists]

[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: Stefan Monnier
Subject: Re: [elpa] externals/typo 88522ea4c8 1/2: Handle hash-tables with symbols as keys
Date: Sat, 22 Jul 2023 10:28:52 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

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

Oh, yes, I forgot to filter based on `word`, sorry.  Luckily, you did
understand the main idea.

> IIRC I tried something like this at some point, but was not sure if
> `all-completions' would re-use `completion-styles'.

`all-completions` is a lower-level API, not affected by `completion-styles`.

> One potential issue, is PRED always non-nil?

I'd ask the package's author :-)

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

IIRC the pred argument to `all-completions` can receive either a string,
or a symbol, or a cons cell (whose car is either a string or a symbol),
or two arguments.

But I guess you could do:

    (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."
      (all-completions "" collection
                       (lambda (key &optional _)
                         (if (consp key) (setq key (car key)))
                         (if (symbolp key) (setq key (symbol-name key)))
                         (and (if pred (funcall pred key) t)
                              (typo--test word key)))))

-- Stefan

reply via email to

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