* Re: [elpa] externals/typo 88522ea4c8 1/2: Handle hash-tables with symbols as keys
[not found] ` <20230722075902.960A7C138F3@vcs2.savannah.gnu.org>
@ 2023-07-22 13:22 ` Stefan Monnier
2023-07-22 14:10 ` Philip Kaludercic
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2023-07-22 13:22 UTC (permalink / raw)
To: emacs-devel; +Cc: Philip Kaludercic
> 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?
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`).
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [elpa] externals/typo 88522ea4c8 1/2: Handle hash-tables with symbols as keys
2023-07-22 13:22 ` [elpa] externals/typo 88522ea4c8 1/2: Handle hash-tables with symbols as keys Stefan Monnier
@ 2023-07-22 14:10 ` Philip Kaludercic
2023-07-22 14:28 ` Stefan Monnier
0 siblings, 1 reply; 3+ messages in thread
From: Philip Kaludercic @ 2023-07-22 14:10 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [elpa] externals/typo 88522ea4c8 1/2: Handle hash-tables with symbols as keys
2023-07-22 14:10 ` Philip Kaludercic
@ 2023-07-22 14:28 ` Stefan Monnier
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2023-07-22 14:28 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: emacs-devel
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-22 14:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <169001274227.13639.17462635050444662711@vcs2.savannah.gnu.org>
[not found] ` <20230722075902.960A7C138F3@vcs2.savannah.gnu.org>
2023-07-22 13:22 ` [elpa] externals/typo 88522ea4c8 1/2: Handle hash-tables with symbols as keys Stefan Monnier
2023-07-22 14:10 ` Philip Kaludercic
2023-07-22 14:28 ` Stefan Monnier
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).