This commit is contained in:
aspeddro 2021-09-29 18:36:17 -03:00
commit 31dc8fde27
No known key found for this signature in database
GPG key ID: 0C09619EB1B7A7CD
4 changed files with 142 additions and 0 deletions

7
.editorconfig Normal file
View file

@ -0,0 +1,7 @@
root = true
[*]
end_of_line = lf
charset = utf-8
indent_style = space
indent_size = 2

21
LICENSE Normal file
View file

@ -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.

51
README.md Normal file
View file

@ -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', "<leader>s", ":Slides<CR>", {silent = true, noremap = true})
```
use `q` and `ctrl + c` to close slide

63
lua/slides.lua Normal file
View file

@ -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('<f-args>')]]
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