Skip to content

Commit

Permalink
feat: implement random query, feature request #19 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-halim authored Oct 15, 2023
1 parent 310e2d0 commit 24dfab1
Show file tree
Hide file tree
Showing 20 changed files with 2,142 additions and 708 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
tests:
strategy:
matrix:
neovim_version: ['nightly', 'v0.9.1']
neovim_version: ['nightly', 'v0.9.1', 'v0.9.2', 'v0.9.4']

runs-on: ubuntu-latest

Expand All @@ -24,10 +24,10 @@ jobs:
sudo apt install -y libsword-utils diatheke
export SWORD_PATH="/tmp/bibleverse/.sword"
mkdir -p "${SWORD_PATH}/mods.d"
yes "yes" | installmgr -init
yes "yes" | installmgr -sc
yes "yes" | installmgr -r CrossWire
yes "yes" | installmgr -ri CrossWire KJV
yes "yes" 2>/dev/null | installmgr -init
yes "yes" 2>/dev/null | installmgr -sc
yes "yes" 2>/dev/null | installmgr -r CrossWire
yes "yes" 2>/dev/null | installmgr -ri CrossWire KJV
- name: Run Tests
run: |
Expand Down
88 changes: 44 additions & 44 deletions lua/bible-verse/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,57 @@ M.commands = {}
--- Execute command by name
---@param cmd? string command name
function M.cmd(cmd)
if cmd and M.commands[cmd] then
M.commands[cmd]()
else
M.commands[Config.options.default_behaviour]()
end
if cmd and M.commands[cmd] then
M.commands[cmd]()
else
M.commands[Config.options.default_behaviour]()
end
end

function M.setup()
M.commands = {
query = function()
require("bible-verse.core").query_and_show()
end,
insert = function()
require("bible-verse.core").query_and_insert()
end,
}
M.commands = {
query = function()
require("bible-verse.core").query_and_show()
end,
insert = function()
require("bible-verse.core").query_and_insert()
end,
}

-- Check that config is sane
assert(
M.commands[Config.options.default_behaviour] ~= nil,
"unsupported default_behaviour|default_behaviour=" .. Config.options.default_behaviour
)
-- Check that config is sane
assert(
M.commands[Config.options.default_behaviour] ~= nil,
"unsupported default_behaviour|default_behaviour=" .. Config.options.default_behaviour
)

-- Main func
vim.api.nvim_create_user_command("BibleVerse", function(args)
local command = vim.trim(args.args or "")
M.cmd(command)
end, {
nargs = "?",
desc = "Query bible verses",
complete = function(_, line)
-- Completed word
if line:match("^%s*BibleVerse %w+ ") then
return {}
end
-- Main func
vim.api.nvim_create_user_command("BibleVerse", function(args)
local command = vim.trim(args.args or "")
M.cmd(command)
end, {
nargs = "?",
desc = "Query bible verses",
complete = function(_, line)
-- Completed word
if line:match("^%s*BibleVerse %w+ ") then
return {}
end

-- Midword
local prefix = line:match("^%s*BibleVerse (%w*)") or ""
return vim.tbl_filter(function(key)
return key:find(prefix) == 1
end, vim.tbl_keys(M.commands))
end,
})
-- Midword
local prefix = line:match("^%s*BibleVerse (%w*)") or ""
return vim.tbl_filter(function(key)
return key:find(prefix) == 1
end, vim.tbl_keys(M.commands))
end,
})

-- Sub funcs
for name in pairs(M.commands) do
local cmd = "BibleVerse" .. name:sub(1, 1):upper() .. name:sub(2)
vim.api.nvim_create_user_command(cmd, function()
M.cmd(name)
end, { desc = "BibleVerse " .. name })
end
-- Sub funcs
for name in pairs(M.commands) do
local cmd = "BibleVerse" .. name:sub(1, 1):upper() .. name:sub(2)
vim.api.nvim_create_user_command(cmd, function()
M.cmd(name)
end, { desc = "BibleVerse " .. name })
end
end

return M
8 changes: 4 additions & 4 deletions lua/bible-verse/config/diatheke.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ local M = {}

---@type BibleVerseDiathekeConfig
M.defaults = {
-- (MANDATORY) translation: diatheke module to be used.
translation = "",
-- locale: locale as locales in the machine.
locale = "en",
-- (MANDATORY) translation: diatheke module to be used.
translation = "",
-- locale: locale as locales in the machine.
locale = "en",
}

return M
50 changes: 25 additions & 25 deletions lua/bible-verse/config/formatter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ local M = {}

---@type BibleVerseFmtConfig
M.defaults = {
---@type BibleVerseFmtMarkdownConfig
markdown = {
-- separator: text to be used as separator between chapters. Set to empty string to disable.
separator = "---",
-- quote_block: put the formatted text within a quote block.
quote_block = true,
-- omit_translation_footnote: omit translation name from the markdown text.
omit_translation_footnote = false,
},

---@type BibleVerseFmtPlainConfig
plain = {
-- header_delimiter: text to be used to separate between the content of verse and the verse.
header_delimiter = " ",
-- omit_translation_footnote: omit translation name from the plain text.
omit_translation_footnote = true,
},

---@type BibleVerseFmtBibleVerseConfig
bibleverse = {
-- separator: text to be used as separator between chapters. Set to empty string to disable.
separator = "",
-- omit_translation_footnote: omit translation name from the BibleVerse text.
omit_translation_footnote = false,
},
---@type BibleVerseFmtMarkdownConfig
markdown = {
-- separator: text to be used as separator between chapters. Set to empty string to disable.
separator = "---",
-- quote_block: put the formatted text within a quote block.
quote_block = true,
-- omit_translation_footnote: omit translation name from the markdown text.
omit_translation_footnote = false,
},

---@type BibleVerseFmtPlainConfig
plain = {
-- header_delimiter: text to be used to separate between the content of verse and the verse.
header_delimiter = " ",
-- omit_translation_footnote: omit translation name from the plain text.
omit_translation_footnote = true,
},

---@type BibleVerseFmtBibleVerseConfig
bibleverse = {
-- separator: text to be used as separator between chapters. Set to empty string to disable.
separator = "",
-- omit_translation_footnote: omit translation name from the BibleVerse text.
omit_translation_footnote = false,
},
}

return M
62 changes: 31 additions & 31 deletions lua/bible-verse/config/highlighter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ local M = {}

---@type BibleVerseHLConfig
M.defaults = {
-- To see all highlight groups that are currently active,
-- :so $VIMRUNTIME/syntax/hitest.vim
-- see :h highlight
-- To see all highlight groups that are currently active,
-- :so $VIMRUNTIME/syntax/hitest.vim
-- see :h highlight

-- highlighting for bibleverse text
bibleverse = {
-- highlighting for book and chapter of the output e.g. John 1
book_chapter = {
pattern = "",
hlgroup = "Title", -- Highlight group to use to highlight the text
},
-- highlighting for verse number the output
verse_number = { pattern = "", hlgroup = "Number" },
-- highlighting for translation used in the output
translation = { pattern = "", hlgroup = "ModeMsg" },
-- highlighting for separator between book chapters used in the output
separator = { pattern = "", hlgroup = "NonText" },
},
-- highlighting for bibleverse text
bibleverse = {
-- highlighting for book and chapter of the output e.g. John 1
book_chapter = {
pattern = "",
hlgroup = "Title", -- Highlight group to use to highlight the text
},
-- highlighting for verse number the output
verse_number = { pattern = "", hlgroup = "Number" },
-- highlighting for translation used in the output
translation = { pattern = "", hlgroup = "ModeMsg" },
-- highlighting for separator between book chapters used in the output
separator = { pattern = "", hlgroup = "NonText" },
},
}

---NOTE: pattern: must capture the following:
Expand All @@ -36,20 +36,20 @@ M.defaults = {
---@type BibleVerseHLConfig
---@diagnostic disable:missing-fields
M._default_override = {
bibleverse = {
book_chapter = {
pattern = "()bc{([%w ]+)}()",
},
verse_number = {
pattern = "()vn{([%S]+)}()",
},
translation = {
pattern = "()t{([%w ]+)}()",
},
separator = {
pattern = "()sp{([%S ]+)}()",
},
},
bibleverse = {
book_chapter = {
pattern = "()bc{([%w ]+)}()",
},
verse_number = {
pattern = "()vn{([%S]+)}()",
},
translation = {
pattern = "()t{([%w ]+)}()",
},
separator = {
pattern = "()sp{([%S ]+)}()",
},
},
}

return M
64 changes: 32 additions & 32 deletions lua/bible-verse/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ local M = {}

---@type BibleVerseConfig
M.defaults = {
-- default_behaviour: behaviour to be used on empty command arg, i.e. :BibleVerse. Defaults to query.
-- Options: "query" - on verse query, display the result on the screen as a popup.
-- "insert" - on verse query, insert the result below the cursor of the current buffer.
default_behaviour = "query",
-- default_behaviour: behaviour to be used on empty command arg, i.e. :BibleVerse. Defaults to query.
-- Options: "query" - on verse query, display the result on the screen as a popup.
-- "insert" - on verse query, insert the result below the cursor of the current buffer.
default_behaviour = "query",

-- query_format: text format on 'query' behaviour.
-- Options: "bibleverse" - query as bibleverse formatted text.
-- "plain" - query as plain text.
query_format = "bibleverse",
-- query_format: text format on 'query' behaviour.
-- Options: "bibleverse" - query as bibleverse formatted text.
-- "plain" - query as plain text.
query_format = "bibleverse",

-- insert_format: text format on 'insert' behaviour.
-- Options: "markdown" - insert as markdown formatted text.
-- "plain" - insert as plain text.
insert_format = "markdown",
-- insert_format: text format on 'insert' behaviour.
-- Options: "markdown" - insert as markdown formatted text.
-- "plain" - insert as plain text.
insert_format = "markdown",

-- Forbid plugin on the following buffer filetypes
exclude_buffer_filetypes = { "neo-tree", "NvimTree" },
-- Forbid plugin on the following buffer filetypes
exclude_buffer_filetypes = { "neo-tree", "NvimTree" },

diatheke = require("bible-verse.config.diatheke").defaults,
formatter = require("bible-verse.config.formatter").defaults,
highlighter = require("bible-verse.config.highlighter").defaults,
ui = require("bible-verse.config.ui").defaults,
diatheke = require("bible-verse.config.diatheke").defaults,
formatter = require("bible-verse.config.formatter").defaults,
highlighter = require("bible-verse.config.highlighter").defaults,
ui = require("bible-verse.config.ui").defaults,
}

---@type BibleVerseConfig
Expand All @@ -43,22 +43,22 @@ M.options = {}

---@param opts? table options to override.
function M.setup(opts)
opts = opts or {}
M.options = vim.tbl_deep_extend("force", M.defaults, opts)
M.options.highlighter =
vim.tbl_deep_extend("force", M.options.highlighter, require("bible-verse.config.highlighter")._default_override)
opts = opts or {}
M.options = vim.tbl_deep_extend("force", M.defaults, opts)
M.options.highlighter =
vim.tbl_deep_extend("force", M.options.highlighter, require("bible-verse.config.highlighter")._default_override)

-- Assert config is sane
assert(
vim.tbl_contains({ "bibleverse", "plain" }, M.options.query_format),
"unsupported_opts|query_format=" .. M.options.query_format
)
assert(
vim.tbl_contains({ "markdown", "plain" }, M.options.insert_format),
"unsupported_opts|insert_format=" .. M.options.insert_format
)
-- Assert config is sane
assert(
vim.tbl_contains({ "bibleverse", "plain" }, M.options.query_format),
"unsupported_opts|query_format=" .. M.options.query_format
)
assert(
vim.tbl_contains({ "markdown", "plain" }, M.options.insert_format),
"unsupported_opts|insert_format=" .. M.options.insert_format
)

M.ns = vim.api.nvim_create_namespace("bible-verse-ns")
M.ns = vim.api.nvim_create_namespace("bible-verse-ns")
end

return M
Loading

0 comments on commit 24dfab1

Please sign in to comment.