From b0a93166a8a7b4d5f099e071d740b29baa52e5e2 Mon Sep 17 00:00:00 2001 From: Stefan Otte Date: Sun, 31 Dec 2023 11:45:50 +0100 Subject: [PATCH] feat: allow user to configure slide buffer options Just supply a function that configures the buffer. --- CHANGELOG.md | 1 + doc/presenting.txt | 12 +++++++----- lua/presenting/init.lua | 12 +++++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0e591c..a1a9c48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- Support configuration of the slide buffer via lua functions - Support lua functions to for keymaps - Allow to disable existing keymaps by setting them to `nil` diff --git a/doc/presenting.txt b/doc/presenting.txt index 156e8c7..b8ce7ff 100644 --- a/doc/presenting.txt +++ b/doc/presenting.txt @@ -53,13 +53,15 @@ Default values: [""] = function() Presenting.next() end, [""] = function() Presenting.prev() end, }, + -- A function that configures the slide buffer. + -- If you want custom settings write your own function that accepts a buffer id as argument. + configure_slide_buffer = function(buf) H.configure_slide_buffer(buf) end, } < -# Options ~ ------------------------------------------------------------------------------ ============================================================================== -Core functionality +# Core functionality ------------------------------------------------------------------------------ *Presenting.toggle()* @@ -73,7 +75,7 @@ Parameters ~ `Presenting.start`({separator}) Start presenting the current buffer. Parameters ~ -{separator} `(string|nil)` +{separator} `(string|nil)` Overwrite the default separator if specified. ------------------------------------------------------------------------------ *Presenting.quit()* @@ -151,8 +153,8 @@ Return ~ `(table)` ------------------------------------------------------------------------------ - *H.set_slide_buffer_options()* - `H.set_slide_buffer_options`({buf}) + *H.configure_slide_buffer()* + `H.configure_slide_buffer`({buf}) Parameters ~ {buf} `(integer)` diff --git a/lua/presenting/init.lua b/lua/presenting/init.lua index 7a4fc50..a529178 100644 --- a/lua/presenting/init.lua +++ b/lua/presenting/init.lua @@ -36,7 +36,6 @@ end --- --- Default values: ---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section) ----@text # Options ~ Presenting.config = { options = { -- The width of the slide buffer. @@ -63,11 +62,14 @@ Presenting.config = { [""] = function() Presenting.next() end, [""] = function() Presenting.prev() end, }, + -- A function that configures the slide buffer. + -- If you want custom settings write your own function that accepts a buffer id as argument. + configure_slide_buffer = function(buf) H.configure_slide_buffer(buf) end, } --minidoc_afterlines_end --- ============================================================================== ---- Core functionality +--- # Core functionality --- Toggle presenting mode on/off for the current buffer. ---@param separator string|nil @@ -80,7 +82,7 @@ Presenting.toggle = function(separator) end --- Start presenting the current buffer. ----@param separator string|nil +---@param separator string|nil Overwrite the default separator if specified. Presenting.start = function(separator) if H.in_presenting_mode() then vim.notify("Already presenting") @@ -282,7 +284,7 @@ H.create_slide_view = function(state) state.slide_buf = vim.api.nvim_create_buf(false, true) state.slide_win = vim.api.nvim_open_win(state.slide_buf, true, window_config.slide) - H.set_slide_buffer_options(Presenting._state.slide_buf) + Presenting.config.configure_slide_buffer(state.slide_buf) H.set_slide_keymaps(state.slide_buf, Presenting.config.keymaps) H.set_slide_content(state, 1) @@ -308,7 +310,7 @@ H.parse_slides = function(lines, separator) end ---@param buf integer -H.set_slide_buffer_options = function(buf) +H.configure_slide_buffer = function(buf) -- TODO: make this configurable via config vim.api.nvim_buf_set_option(buf, "buftype", "nofile") vim.api.nvim_buf_set_option(buf, "filetype", Presenting._state.filetype)