Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions doc/SCNvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ implementation, for example the code for indent and syntax highlighting.
SETUP *scnvim-setup*

Enable the plugin by calling the setup function in your *init.lua*
>
>lua
local scnvim = require('scnvim')
scnvim.setup()
<
Expand All @@ -46,7 +46,7 @@ KEYMAPS *scnvim-keymaps*
No keymaps are defined by default. Use the `scnvim.setup` function to set
your mappings. The *keywordprg* option is set by scnvim, use `K` to open
documentation for the word under the cursor.
>
>lua
local map = scnvim.map
scnvim.setup {
keymaps = {
Expand Down Expand Up @@ -81,7 +81,7 @@ The following modules can be used to create a keymap from a string:
* `signature`

String example~
>
>lua
['<CR>'] = scnvim.map('postwin.toggle')
<
This will create a keymap for `<CR>` for the `toggle` function from the
Expand All @@ -94,20 +94,20 @@ Function example~

If the `map` helper receives a function it will execute that function when
pressing the key.
>
>lua
['<leader>st'] = scnvim.map(scnvim.start)
<
Here we're using the `scnvim.start` function. But its also possible to map
arbitrary functions.
>
>lua
['<F1>'] = scnvim.map(function()
vim.cmd('SCNvimGenerateAssets')
end)

Map expressions~

The `map_expr` helper let's you map SuperCollider code.
>
>lua
local map_expr = scnvim.map_expr
['<F2>'] = map_expr('s.meter')
<
Expand Down Expand Up @@ -142,22 +142,22 @@ and display the result inside nvim. In order to do so, the scnvim help system
needs a program to convert HTML help files into plain text e.g. `pandoc[1]`

Set the path to your converter program in the config passed to `scnvim.setup`
>
>lua
scnvim.setup{
documentation = {
cmd = '/opt/homebrew/bin/pandoc',
},
}
<

Customization~
Customization ~

The help system is configured to use `pandoc` by default. To use another
program you will also need to supply the command line arguments needed to
perform the HTML to plain text conversion. The example below is for the
`html2text` program. `$1` is a placeholder for the *input file* and `$2` is a
placeholder for the *output file*, these are replaced automatically.
>
>lua
scnvim.setup{
documentation = {
cmd = '/usr/local/bin/html2text',
Expand Down Expand Up @@ -190,7 +190,7 @@ You can also view an up-to-date HTML version of the documentation by visiting
this link: https://davidgranstrom.github.io/scnvim/modules/scnvim.config.html

Example configuration~
>
>lua
scnvim.setup {
mapping = {
['<M-e>'] = scnvim.map.send_line({'i', 'n'}),
Expand Down
2 changes: 2 additions & 0 deletions lua/scnvim/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ local default = {
--- string $1 will be replaced with the input file path and $2 will be replaced
--- with the output file path.
---
---@field tab (default: false) If true open the help window in a new tab
---@field horizontal (default: true) Open the help window as a horizontal split
---@field direction (default: 'top') Direction of the split: 'top', 'right', 'bot', 'left'
---@field keymaps (default: true) If true apply user keymaps to the help
--- window. Use a table value for explicit mappings.
documentation = {
cmd = nil,
args = { '$1', '--from', 'html', '--to', 'plain', '-o', '$2' },
tab = false,
horizontal = true,
direction = 'top',
keymaps = true,
Expand Down
26 changes: 17 additions & 9 deletions lua/scnvim/help.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,26 @@ M.on_open = action.new(function(err, uri, pattern)
if is_open then
vim.cmd(expr)
else
local horizontal = config.documentation.horizontal
local direction = config.documentation.direction
if direction == 'top' or direction == 'left' then
direction = 'leftabove'
elseif direction == 'right' or direction == 'bot' then
direction = 'rightbelow'
if config.documentation.tab then
local win_cmd = string.format('tabnew | %s', expr)
vim.cmd(win_cmd)
else
error '[scnvim] invalid config.documentation.direction'
local horizontal = config.documentation.horizontal
local direction = config.documentation.direction
if direction == 'top' or direction == 'left' then
direction = 'leftabove'
elseif direction == 'right' or direction == 'bot' then
direction = 'rightbelow'
else
error '[scnvim] invalid config.documentation.direction'
end
local win_cmd = string.format('%s %s | %s', direction, horizontal and 'split' or 'vsplit', expr)
vim.cmd(win_cmd)
end
local win_cmd = string.format('%s %s | %s', direction, horizontal and 'split' or 'vsplit', expr)
vim.cmd(win_cmd)
win_id = vim.fn.win_getid()
vim.opt_local.number = false
vim.opt_local.relativenumber = false
vim.opt_local.wrap = false
end
end)

Expand Down
Loading