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

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

Merged
merged 2 commits into from
Oct 10, 2023
Merged

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

merged 2 commits into from
Oct 10, 2023

Conversation

hgluka
Copy link
Contributor

@hgluka hgluka commented Oct 6, 2023

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

Copy link
Member

@aadcg aadcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hgluka I didn't look deep into it, but if next-source-position handles non-empty sources then next-source shouldn't need to know about it.

Don't forget to enrich the test suite with these new added functions.

prompter.lisp Outdated Show resolved Hide resolved
prompter.lisp Outdated Show resolved Hide resolved
prompter.lisp Outdated Show resolved Hide resolved
@aadcg
Copy link
Member

aadcg commented Oct 6, 2023

@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
Copy link
Contributor Author

hgluka commented Oct 6, 2023

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

Copy link
Member

@aadcg aadcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that your solution is subpar. I've pushed some commits.

Does it look good? Am I missing something?

Note that the CI is failing but it's unrelated to this PR.

@hgluka
Copy link
Contributor Author

hgluka commented Oct 10, 2023

@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.

Add new next-source-p, previous-source-p and adjacent-source.

Refactor next-source.
@aadcg aadcg merged commit b40a13a into master Oct 10, 2023
4 checks passed
@hgluka
Copy link
Contributor Author

hgluka commented Oct 10, 2023

@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 atlas-engineer/nyxt#3202, at least) we want to use these functions on all the sources in a prompt buffer, not just the current-source.

@aadcg
Copy link
Member

aadcg commented Oct 10, 2023

@hgluka you can still use adjacent-source no?

@hgluka
Copy link
Contributor Author

hgluka commented Oct 10, 2023

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

@aadcg aadcg deleted the next-source-p branch October 24, 2023 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants