mirror of
https://github.com/NotAShelf/slides.nvim.git
synced 2024-11-01 19:11:17 +00:00
init
This commit is contained in:
commit
31dc8fde27
4 changed files with 142 additions and 0 deletions
7
.editorconfig
Normal file
7
.editorconfig
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
21
LICENSE
Normal file
21
LICENSE
Normal 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
51
README.md
Normal 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
63
lua/slides.lua
Normal 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
|
Loading…
Reference in a new issue