commit 31dc8fde27082c99dc24dca81be3773ae96b48b3 Author: aspeddro Date: Wed Sep 29 18:36:17 2021 -0300 init diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f936f0e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root = true + +[*] +end_of_line = lf +charset = utf-8 +indent_style = space +indent_size = 2 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5217ec4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Pedro Castro + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d07501c --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# slides.nvim + +[Slides](https://github.com/maaslalani/slides) presentation in your Neovim. + + +## Prerequisites + +- `Neovim >= 0.5.0` +- [`Slides`](https://github.com/maaslalani/slides) + +## Installation + +### [packer.nvim](https://github.com/wbthomason/packer.nvim) + +```lua +use { + 'aspeddro/slides.nvim', + config = function () + require'slides'.setup{} + end +} +``` + +## Configuration + +```lua +require'slides'.setup{ + bin = 'slides' -- default config, path to binary +} +``` + +## Usage + +Open current buffer + +``` +:Slides +``` + +``` +:Slides [path/to/file.md] +``` + +Create a mapping: + +```lua +-- 'n' = normal mode +vim.api.nvim_set_keymap('n', "s", ":Slides", {silent = true, noremap = true}) +``` + +use `q` and `ctrl + c` to close slide diff --git a/lua/slides.lua b/lua/slides.lua new file mode 100644 index 0000000..c9a0bbb --- /dev/null +++ b/lua/slides.lua @@ -0,0 +1,63 @@ +local M = {} + +local state = { + win = nil +} + +local config = { + bin = 'slides' +} + +function M.close() + if state.win ~= nil then + vim.api.nvim_win_close(state.win, true) + end +end + +function M.setup(user_config) + config = vim.tbl_deep_extend('force', {}, config, user_config or {}) + + vim.cmd [[command! -nargs=? -complete=file Slides :lua require"slides".show('')]] +end + +function M.show(file) + local opts = { + style = "minimal", + relative = "editor", + width = vim.api.nvim_get_option("columns"), + height = vim.api.nvim_get_option("lines"), + row = 1, + col = 1, + border = "shadow", + } + + local input = string.len(file) == 0 and vim.api.nvim_get_current_buf() or file + local is_file = type(input) == 'string' + local filetype = is_file and vim.fn.fnamemodify(input, ':e'):gsub("\"", "") or vim.api.nvim_buf_get_option(input, 'filetype') + + if not vim.tbl_contains({'md', 'markdown'}, filetype) then + vim.api.nvim_err_writeln('Invalid filetype') + return + end + + if vim.fn.executable(config.bin) ~= 1 then + vim.api.nvim_err_writeln('Executable not found') + return + end + + local bufnr = vim.api.nvim_create_buf(false, true) + local win = vim.api.nvim_open_win(bufnr, true, opts) + + state.win = win + + vim.cmd('startinsert!') + + vim.fn.termopen(config.bin .. ' ' .. (is_file and input or vim.api.nvim_buf_get_name(input)), { + on_exit = function() + M.close() + end + }) + +end + +return M