Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-platform support and a workaround for consult chars outside unicode in native module #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions hotfuzz.el
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,57 @@
(add-face-text-property i (1+ i) 'completions-common-part nil haystack))))
haystack)

(defmacro hotfuzz--dash-each (list &rest body)
"Evaluate BODY for each element of LIST and return nil.
Each element of LIST in turn is bound to `it' and its index
within LIST to `it-index' before evaluating BODY.
This is the anaphoric counterpart to `-each'.

Shamelessly lifted from dash: https://github.com/magnars/dash.el"
(let ((l (make-symbol "list"))
(i (make-symbol "i")))
`(let ((,l ,list)
(,i 0))
(while ,l
(let ((it (pop ,l)) (it-index ,i))
(ignore it it-index)
,@body)
(setq ,i (1+ ,i))))))

(defmacro hotfuzz--dash-keep (form list)
"Eval FORM for each item in LIST and return the non-nil results.
Like `--filter', but returns the non-nil results of FORM instead
of the corresponding elements of LIST. Each element of LIST in
turn is bound to `it' and its index within LIST to `it-index'
before evaluating FORM.
This is the anaphoric counterpart to `-keep'.

Shamelessly lifted from dash: https://github.com/magnars/dash.el"
(let ((r (make-symbol "result"))
(m (make-symbol "mapped")))
`(let (,r)
(hotfuzz--dash-each ,list (let ((,m ,form)) (when ,m (push ,m ,r))))
(nreverse ,r))))

(defun hotfuzz--fix-tofu-chars (orig-fun string candidates &optional ignore-case)
"Workaround tofu chars (in e.g. consult) for native module filtering."
(let*
((table (make-hash-table :test #'eq :size (length candidates)))

Check warning on line 158 in hotfuzz.el

View check run for this annotation

Codecov / codecov/patch

hotfuzz.el#L157-L158

Added lines #L157 - L158 were not covered by tests
(cands
(hotfuzz--dash-keep

Check warning on line 160 in hotfuzz.el

View check run for this annotation

Codecov / codecov/patch

hotfuzz.el#L160

Added line #L160 was not covered by tests
(when (stringp it)
(let ((encoded (encode-coding-string it 'no-conversion 'nocopy)))
(setf (gethash encoded table) it)
(and (< (length encoded) hotfuzz--max-haystack-len) encoded)))
candidates))
(raw-str (encode-coding-string string 'no-conversion 'nocopy))

Check warning on line 166 in hotfuzz.el

View check run for this annotation

Codecov / codecov/patch

hotfuzz.el#L165-L166

Added lines #L165 - L166 were not covered by tests
(ans
(let
((gc-cons-threshold most-positive-fixnum)

Check warning on line 169 in hotfuzz.el

View check run for this annotation

Codecov / codecov/patch

hotfuzz.el#L168-L169

Added lines #L168 - L169 were not covered by tests
(gc-cons-percentage 1.0))
(funcall orig-fun raw-str cands ignore-case))))
(hotfuzz--dash-keep (gethash it table) ans)))

Check warning on line 172 in hotfuzz.el

View check run for this annotation

Codecov / codecov/patch

hotfuzz.el#L171-L172

Added lines #L171 - L172 were not covered by tests

;;;###autoload
(defun hotfuzz-all-completions (string table &optional pred point)
"Get hotfuzz-completions of STRING in TABLE.
Expand Down