atlas-engineer / prompter

Live-narrowing, fuzzy-matching, extensible prompt framework.
BSD 3-Clause "New" or "Revised" License
13 stars 1 forks source link

Add `next-source-p` and `previous-source-p`. #24

Closed hgluka closed 1 year ago

hgluka commented 1 year ago

Description

This PR adds next-source-p and previous-source-p as exported functions. I did this by making a next-source-position function that next-source-p and next-source can have in common.

Discussion

The implementation might be inefficient, because of the repeated (remove-if #'empty-source-p (sources prompter)) calls, but it seemed like the most elegant way to do it.

CC @aadcg

aadcg commented 1 year ago

@hgluka I still think that this solution is subpar. I think everything would become easier if next-source-position returned a source object instead of an index. Then next/previous-source-p would only check whether (next-source-position prompter {1,-1} source) returns non-nil.

hgluka commented 1 year ago

Ah, good point, I didn't think of that. Thanks for the help @aadcg!

hgluka commented 1 year ago

@aadcg Thanks, it looks a lot better! The only nitpick I have is the name adjacent-source, since it only really makes sense for the case when (= steps 1). Still, that's not a big deal so I think this can be merged.

hgluka commented 1 year ago

@aadcg I just realized that we need next-source-p and previous-source-p to have a source argument. Slipped my mind when I looked at it earlier, but in Nyxt (in https://github.com/atlas-engineer/nyxt/pull/3202, at least) we want to use these functions on all the sources in a prompt buffer, not just the current-source.

aadcg commented 1 year ago

@hgluka you can still use adjacent-source no?

hgluka commented 1 year ago

Oh, adjacent-source is exported as well, so yes I can.