Skip to content

Commit

Permalink
Support function as the value of prescient-filter-method (#110)
Browse files Browse the repository at this point in the history
* Support function as the value of prescient-filter-method

Fixes #83

* Handle prescient-filter-method function when toggling with selectrum

* Update CHANGELOG.md

Co-authored-by: Radon Rosborough <[email protected]>
  • Loading branch information
peterstuart and raxod502 authored Jul 24, 2021
1 parent 54b19cf commit 027c213
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ The format is based on [Keep a Changelog].
will immediately forget a candidate ([#109]).

### Enhancements
* `prescient-filter-method` accepts a function which returns the
desired filter methods ([#110]).
* `selectrum-prescient.el`: Match faces are now combined with faces
that might be already present on candidates instead of replacing
them which gives better visual results in these cases ([#101],
Expand Down Expand Up @@ -66,6 +68,7 @@ The format is based on [Keep a Changelog].
[#105]: https://github.com/raxod502/prescient.el/pull/105
[#106]: https://github.com/raxod502/prescient.el/pull/106
[#109]: https://github.com/raxod502/prescient.el/pull/109
[#110]: https://github.com/raxod502/prescient.el/pull/110

## 5.1 (released 2021-02-26)
### Enhancements
Expand Down
8 changes: 7 additions & 1 deletion prescient.el
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ is similar to `prefix', but allows for less typing.
Value can also be a list of any of the above methods, in which
case each method will be applied in order until one matches.
Value can also be a function which returns any of the allowable
values documented above.
For backwards compatibility, the value of this variable can also
be `literal+initialism', which equivalent to the list (`literal'
`initialism')."
Expand Down Expand Up @@ -561,7 +564,10 @@ enclose literal substrings with capture groups."
(message
"No function in `prescient-filter-alist' for method: %s"
method)))
(pcase prescient-filter-method
(pcase
(if (functionp prescient-filter-method)
(funcall prescient-filter-method)
prescient-filter-method)
;; We support `literal+initialism' for backwards
;; compatibility.
(`literal+initialism '(literal initialism))
Expand Down
10 changes: 8 additions & 2 deletions selectrum-prescient.el
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,14 @@ buffer. It does not affect the default behavior (determined by
;; be a list of only one filter type.
(setq prescient-filter-method '(,filter-type))

;; Otherwise, if we need to add or remove from the list,
;; make sure it's actually a list and not just a symbol.
;; Otherwise, if the current setting is a function,
;; evaluate it to get the value.
(when (functionp prescient-filter-method)
(setq prescient-filter-method
(funcall prescient-filter-method)))

;; If we need to add or remove from the list, make sure
;; it's actually a list and not just a symbol.
(when (symbolp prescient-filter-method)
(setq prescient-filter-method
(list prescient-filter-method)))
Expand Down

0 comments on commit 027c213

Please sign in to comment.