radian-software / prescient.el

☄️ Simple but effective sorting and filtering for Emacs.
MIT License
604 stars 25 forks source link

Custom filter method? #69

Closed zbelial closed 2 years ago

zbelial commented 3 years ago

Hi, thanks for this great package.

I know that prescient supports several filter methods, but it will be better if users can add customized filter method(e.g. Chinese users may use pinyin to filter candidates).

Here is my thought:

  1. add a new choice custom to prescient-filter-method
  2. add a new defcustom, like prescient-custom-filter-function, which users can customize
  3. modify prescient-filter-regexps to handle custom

Does this way sound decent? If so, I guess I can make a PR.

raxod502 commented 3 years ago

I feel like it would be better to instead make the mapping from e.g. initialism to prescient--initials-regexp into a public user option, and make all of the built-in regexp functions public. We do this, for example, to address the same problem in CTRLF:

https://github.com/raxod502/ctrlf/blob/2279f684f8d75a75f6b98ddaa908182f08c0d877/ctrlf.el#L77-L111

(defcustom ctrlf-style-alist
  '((literal      . (:prompt "literal"
                             :translator regexp-quote
                             :case-fold ctrlf-no-uppercase-literal-p))
    (regexp       . (:prompt "regexp"
                             :translator identity
                             :case-fold ctrlf-no-uppercase-regexp-p))
    (fuzzy        . (:prompt "fuzzy"
                             :translator ctrlf-translate-fuzzy-literal
                             :case-fold ctrlf-no-uppercase-literal-p))
    (fuzzy-regexp . (:prompt "fuzzy regexp"
                             :translator ctrlf-translate-fuzzy-regexp
                             :case-fold ctrlf-no-uppercase-regexp-p))
    (symbol       . (:prompt "symbol"
                             :translator ctrlf-translate-symbol
                             :case-fold ctrlf-no-uppercase-literal-p)))
  "Alist of CTRLF search styles.
Each search style defines a different way to interpret your
query, for example as a literal string or as a regexp. The keys
are unique identifying symbols which can be passed to
`ctrlf-forward' and `ctrlf-backward'. The values are property
lists with the following keys (all mandatory):
- `:prompt': string to be displayed in minibuffer prompt after
  \"CTRLF\".
- `:translator': function which takes your query string and
  returns a regexp, e.g. `regexp-quote' for a literal search.
- `:case-fold': function which takes your query string and
  returns a value for `case-fold-search' to use by default (for
  example, non-nil only if the query does not contain any
  uppercase letters)."
  :type '(alist
          :key-type symbol
          :value-type (list (const :prompt) string
                            (const :translator) function
                            (const :case-fold) function)))

Do you think that would also satisfy your use case? I agree it's not ideal that there is no extensibility currently.

zbelial commented 3 years ago

Thanks. Yes, that would satisfy my use case, and I agree that it's better.

okamsn commented 2 years ago

This was implemented over a year ago, so I'm closing this issue.

Please see prescient-filter-method and the added prescient-filter-alist.