Skip to content

Commit

Permalink
Merge pull request #4 from sotte/configure_buffer_options
Browse files Browse the repository at this point in the history
feat: allow user to configure slide buffer options
  • Loading branch information
sotte authored Dec 31, 2023
2 parents 8beef0c + b0a9316 commit d350958
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
12 changes: 7 additions & 5 deletions doc/presenting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ Default values:
["<CR>"] = function() Presenting.next() end,
["<BS>"] = 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()*
Expand All @@ -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()*
Expand Down Expand Up @@ -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)`

Expand Down
12 changes: 7 additions & 5 deletions lua/presenting/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -63,11 +62,14 @@ Presenting.config = {
["<CR>"] = function() Presenting.next() end,
["<BS>"] = 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
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit d350958

Please sign in to comment.