-
Notifications
You must be signed in to change notification settings - Fork 1
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
feature: add random verse querying #20
feature: add random verse querying #20
Conversation
Hi, thank you for the PR! I have reviewed your changes and I got the general idea. Given that the feature essentially adds a new command lua/bible-verse/core/init.lua To keep it consistent with other commands, you can add a new function that handles querying random verses e.g. The lua/bible-verse/commands.lua On Lastly, purely optional, you can move the random-verse.lua into core folder :) Again, thank you for your contribution and it looks great! |
Hey Anthony, thanks for the review! :) Do I have to do something else to make it work as insert or show? |
You can refer to I'm not sure whether there is a good use case of inserting or showing random verses though; returning the random verse as is would better fulfill #19 as user would be able to call the API and integrate the output to other plugins more easily e.g. on splash screen. |
I just applied your comments, I hope all is good, it was a long day :) |
@@ -6,6 +6,7 @@ local Utils = require("bible-verse.utils") | |||
local Diatheke = require("bible-verse.core.diatheke") | |||
local Ui = require("bible-verse.core.ui") | |||
local Highlight = require("bible-verse.core.highlight") | |||
local random_verse = require("bible-verse.core.random-verse") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to RandomVerse
) | ||
local popup_max_height = math.ceil(relative_size.height * popup_conf.size.max_height_percentage) | ||
|
||
local query_result = M.random_query() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to pass in the popup_width
such that the outputted format is correctly shown. Prefer to simply call process_query(...)
instead of calling M.random_query()
to avoid dependencies between public functions.
@@ -110,4 +111,32 @@ function M.query_and_insert() | |||
Ui:input(input_conf, on_submit) | |||
end | |||
|
|||
--- Returns a random verse | |||
function M.random_query() | |||
return process_query(random_verse(), Config.options.query_format, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether it would be easy to use M.random_query()
if the format is using Config.options.query_format
🤔
A user who has set Config.options.query_format=bibleverse
to get highlighting on the pop up will get difficult to read/use output from M.random_query()
.
Do you think it would be better to create a separate Config.options
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's true, I haven't played enough with the config to know about this. I'll let you be the judge, it's probably a good idea :)
@@ -39,7 +46,7 @@ function M.setup() | |||
local command = vim.trim(args.args or "") | |||
M.cmd(command) | |||
end, { | |||
nargs = "?", | |||
nargs = "*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem that any of the new commands need to accept >1 arguments 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I forgot to change it back
Hi @ZyriabDsgn, sorry for the late reply - life has been hectic for a bit. Resuming the discussion, I think it is better to keep the feature focused on returning raw random verses (thus behaving almost like a library) and let user to extend from there. For example, user can integrate it as part of the splash screen, showing it as a Noice notification, or as a pop-up like what you intended. Do you mind to revert the changes on pop-up with random verse? Again, thank you so much for your contribution! P.S I would be happy to continue where you left off if you are too busy. The random verse do come in handy as a feature :) |
Hey @anthony-halim, sorry as well for the late answer and thanks for the heads up, life if pretty hectic over here as well! Take care and I hop all is well in your part of the world! |
Cool, I will get to it during the weekend 👍 |
Hi, the feature has been merged on #21. I will add a follow up PR to update the README for the documentation. Now public APIs accepts optional parameter: New API: Query require("bible-verse").query(query_opt?: { query: string, random: true })
-- Sample usage: returns a random Verse[]
require("bible-verse").query({ random = true }) Query and Show require("bible-verse").query_and_show(query_opt?: { query: string, random: true })
-- Sample usage: display random verse to the screen
require("bible-verse").query_and_show({ random = true }) Query and Insert require("bible-verse").query_and_insert(query_opt?: { query: string, random: true })
-- Sample usage: insert random verse to current buffer
require("bible-verse").query_and_insert({ random = true }) Cheers! |
You rock :) |
Hey, as we talked about in #19 :)
You can just append
random
behind any supported command like:BibleVerse random
BibleVerseInsert random
BibleVerse query random
etc...
I'm not really familiar with Lua so I'm sorry in advance if my code seems a bit weird!
It's all based on the KJV but I checked the behavior of the plugin and it should work without problem, even if the selected translation has less books or verses. If it has more, though (so called Apocryphe), they wont be selected.
I decided to use a file-scoped variable in order to keep my general modifications as small and clean as possible.
I think that, given the reduced size of the file and all that, it's perfectly okay to use a "global" here, feel free to contest in your review. 😛
Also, it seems that the diff affects the entire file, do you program on Windows? It's possible that our end of line character is not the same (programmed this on a Linux machine), sorry about that... I'm new to Neovim so I don't know how to check and how to fix that but if you have any info about that, I'll be happy to fix.Other than that I set my editor to 3 tabs and used British English ("sanitise") in order to stay consistent with your style.
EDIT: Seems like I was mistaken and that you don't use 3 tabs! I set my editor to tabs of 4, all good now
Tell me if I missed anything.
Take care :)