docs: docgen

This commit is contained in:
Folke Lemaitre 2025-01-14 11:56:46 +01:00
parent ee322226af
commit 5b026e96af
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
11 changed files with 476 additions and 220 deletions

View file

@ -10,7 +10,11 @@ Table of Contents *snacks-layout-table-of-contents*
- Snacks.layout.new() |snacks-layout-module-snacks.layout.new()|
- layout:close() |snacks-layout-module-layout:close()|
- layout:each() |snacks-layout-module-layout:each()|
- layout:is_enabled() |snacks-layout-module-layout:is_enabled()|
- layout:is_hidden() |snacks-layout-module-layout:is_hidden()|
- layout:maximize() |snacks-layout-module-layout:maximize()|
- layout:show() |snacks-layout-module-layout:show()|
- layout:toggle() |snacks-layout-module-layout:toggle()|
- layout:valid() |snacks-layout-module-layout:valid()|
==============================================================================
@ -37,11 +41,13 @@ Table of Contents *snacks-layout-table-of-contents*
>lua
---@class snacks.layout.Config
---@field win? snacks.words.Config|{}
---@field wins table<string, snacks.win>
---@field layout snacks.layout.Box
---@field fullscreen? boolean open in fullscreen
---@field hidden? string[] list of windows that will be excluded from the layout
---@field on_update? fun(layout: snacks.layout)
{
win = {
layout = {
width = 0.6,
height = 0.6,
zindex = 50,
@ -54,31 +60,13 @@ Table of Contents *snacks-layout-table-of-contents*
3. Types *snacks-layout-types*
>lua
---@class snacks.layout.Dim: snacks.win.Dim
---@field depth number
<
>lua
---@class snacks.layout.Base
---@field width? number
---@field min_width? number
---@field max_width? number
---@field height? number
---@field min_height? number
---@field max_height? number
---@field col? number
---@field row? number
---@field border? string
---@class snacks.layout.Win: snacks.win.Config,{}
---@field depth? number
<
>lua
---@class snacks.layout.Win: snacks.layout.Base, snacks.win.Config,{}
---@field win string
<
>lua
---@class snacks.layout.Box: snacks.layout.Base
---@class snacks.layout.Box: snacks.layout.Win,{}
---@field box "horizontal" | "vertical"
---@field id? number
---@field [number] snacks.layout.Win | snacks.layout.Box
@ -95,10 +83,11 @@ Table of Contents *snacks-layout-table-of-contents*
>lua
---@class snacks.layout
---@field opts snacks.layout.Config
---@field win snacks.win
---@field root snacks.win
---@field wins table<string, snacks.win|{enabled?:boolean}>
---@field box_wins snacks.win[]
---@field win_opts table<string, snacks.win.Config>
---@field closed? boolean
Snacks.layout = {}
<
@ -114,19 +103,45 @@ Table of Contents *snacks-layout-table-of-contents*
LAYOUT:CLOSE() *snacks-layout-module-layout:close()*
>lua
layout:close()
---@param opts? {wins?: boolean}
layout:close(opts)
<
LAYOUT:EACH() *snacks-layout-module-layout:each()*
>lua
---@param cb fun(widget: snacks.layout.Widget)
---@param opts? {wins?:boolean, boxes?:boolean}
---@param cb fun(widget: snacks.layout.Widget, parent?: snacks.layout.Box)
---@param opts? {wins?:boolean, boxes?:boolean, box?:snacks.layout.Box}
layout:each(cb, opts)
<
LAYOUT:IS_ENABLED() *snacks-layout-module-layout:is_enabled()*
>lua
---@param w string
layout:is_enabled(w)
<
LAYOUT:IS_HIDDEN() *snacks-layout-module-layout:is_hidden()*
>lua
---@param win string
layout:is_hidden(win)
<
LAYOUT:MAXIMIZE() *snacks-layout-module-layout:maximize()*
Toggle fullscreen
>lua
layout:maximize()
<
LAYOUT:SHOW() *snacks-layout-module-layout:show()*
>lua
@ -134,6 +149,14 @@ LAYOUT:SHOW() *snacks-layout-module-layout:show()*
<
LAYOUT:TOGGLE() *snacks-layout-module-layout:toggle()*
>lua
---@param win string
layout:toggle(win)
<
LAYOUT:VALID() *snacks-layout-module-layout:valid()*
>lua

View file

@ -5,6 +5,7 @@ Table of Contents *snacks-meta-table-of-contents*
1. Types |snacks-meta-types|
2. Module |snacks-meta-module|
- Snacks.meta.file() |snacks-meta-module-snacks.meta.file()|
- Snacks.meta.get() |snacks-meta-module-snacks.meta.get()|
Meta functions for Snacks
@ -38,6 +39,13 @@ Meta functions for Snacks
2. Module *snacks-meta-module*
`Snacks.meta.file()` *Snacks.meta.file()*
>lua
Snacks.meta.file(name)
<
`Snacks.meta.get()` *Snacks.meta.get()*
Get the metadata for all snacks plugins

View file

@ -15,20 +15,21 @@ Table of Contents *snacks-picker-table-of-contents*
5. snacks.picker.core.picker |snacks-picker-snacks.picker.core.picker|
- picker:action() |snacks-picker-snacks.picker.core.picker-picker:action()|
- picker:close() |snacks-picker-snacks.picker.core.picker-picker:close()|
- picker:count() |snacks-picker-snacks.picker.core.picker-picker:count()|
- picker:current()|snacks-picker-snacks.picker.core.picker-picker:current()|
- picker:debug() |snacks-picker-snacks.picker.core.picker-picker:debug()|
- picker:filter() |snacks-picker-snacks.picker.core.picker-picker:filter()|
- picker:find() |snacks-picker-snacks.picker.core.picker-picker:find()|
- picker:hist() |snacks-picker-snacks.picker.core.picker-picker:hist()|
- picker:hist_record()|snacks-picker-snacks.picker.core.picker-picker:hist_record()|
- picker:is_active()|snacks-picker-snacks.picker.core.picker-picker:is_active()|
- picker:items() |snacks-picker-snacks.picker.core.picker-picker:items()|
- picker:progress()|snacks-picker-snacks.picker.core.picker-picker:progress()|
- picker:iter() |snacks-picker-snacks.picker.core.picker-picker:iter()|
- picker:match() |snacks-picker-snacks.picker.core.picker-picker:match()|
- picker:selected()|snacks-picker-snacks.picker.core.picker-picker:selected()|
- picker:set_layout()|snacks-picker-snacks.picker.core.picker-picker:set_layout()|
- picker:show() |snacks-picker-snacks.picker.core.picker-picker:show()|
- picker:show_preview()|snacks-picker-snacks.picker.core.picker-picker:show_preview()|
- picker:update() |snacks-picker-snacks.picker.core.picker-picker:update()|
- picker:update_titles()|snacks-picker-snacks.picker.core.picker-picker:update_titles()|
- picker:word() |snacks-picker-snacks.picker.core.picker-picker:word()|
==============================================================================
1. Setup *snacks-picker-setup*
@ -55,12 +56,12 @@ Table of Contents *snacks-picker-table-of-contents*
>lua
---@class snacks.picker.Config
---@field prompt? string
---@field pattern? string|fun():string Pattern used to filter items by the matcher
---@field search? string|fun():string Initial search string used by finders
---@field pattern? string|fun(picker:snacks.Picker):string Pattern used to filter items by the matcher
---@field search? string|fun(picker:snacks.Picker):string Initial search string used by finders
---@field cwd? string
---@field live? boolean
---@field limit? number when set, the finder will stop after finding this number of items. useful for live searches
---@field ui_select? boolean
---@field preset? string|string[]
---@field auto_confirm? boolean Automatically confirm if there is only one item
---@field format? snacks.picker.Formatter|string
---@field items? snacks.picker.finder.Item[]
@ -69,15 +70,25 @@ Table of Contents *snacks-picker-table-of-contents*
---@field sorter? snacks.matcher.sorter
---@field actions? table<string, snacks.picker.Action.spec>
---@field win? snacks.picker.win.Config
---@field layout? snacks.layout.Config|{}
---@field layout? snacks.picker.Layout|{}|fun(source:string):snacks.picker.Layout
---@field preview? snacks.picker.preview.Config
---@field previewer? snacks.picker.Previewer|string
---@field sources? snacks.picker.sources.Config|{}
---@field icons? snacks.picker.icons
---@field source? string
---@field on_change? fun(picker:snacks.Picker, item:snacks.picker.Item) called when the cursor changes
---@field on_show? fun(picker:snacks.Picker) called when the picker is shown
---@field layouts? table<string, snacks.picker.Layout>
---@field main? snacks.picker.main.Config
{
prompt = " ",
sources = {},
layout = {
cycle = true,
preset = function()
return vim.o.columns >= 120 and "default" or "vertical"
end,
},
ui_select = true, -- replace `vim.ui.select` with the snacks picker
preview = {
file = {
@ -115,18 +126,24 @@ Table of Contents *snacks-picker-table-of-contents*
["<c-k>"] = "list_up",
["<c-n>"] = "list_down",
["<c-p>"] = "list_up",
["<a-w>"] = "cycle_win",
["<Esc>"] = "close",
},
},
input = {
keys = {
["<esc>"] = "close",
["<Esc>"] = "close",
["G"] = "list_bottom",
["gg"] = "list_top",
["j"] = "list_down",
["k"] = "list_up",
["/"] = "toggle_focus",
["q"] = "close",
["<C-w>"] = { "<c-s-w>", mode = { "i" }, expr = true },
["?"] = "toggle_help",
["<a-m>"] = { "toggle_maximize", mode = { "i", "n" } },
["<a-p>"] = { "toggle_preview", mode = { "i", "n" } },
["<a-w>"] = { "cycle_win", mode = { "i", "n" } },
["<C-w>"] = { "<c-s-w>", mode = { "i" }, expr = true, desc = "delete word" },
["<C-Up>"] = { "history_back", mode = { "i", "n" } },
["<C-Down>"] = { "history_forward", mode = { "i", "n" } },
["<Tab>"] = { "select_and_next", mode = { "i", "n" } },
@ -146,58 +163,50 @@ Table of Contents *snacks-picker-table-of-contents*
["<ScrollWheelUp>"] = { "list_scroll_wheel_up", mode = { "i", "n" } },
["<c-v>"] = { "edit_vsplit", mode = { "i", "n" } },
["<c-s>"] = { "edit_split", mode = { "i", "n" } },
["<c-q>"] = { "qf", mode = { "i", "n" } },
["<a-q>"] = { "qf_all", mode = { "i", "n" } },
["<c-q>"] = { "qflist", mode = { "i", "n" } },
["<a-i>"] = { "toggle_ignored", mode = { "i", "n" } },
["<a-h>"] = { "toggle_hidden", mode = { "i", "n" } },
},
b = {
minipairs_disable = true,
},
},
preview = {
minimal = false,
wo = {
cursorline = false,
colorcolumn = "",
},
keys = {
["<Esc>"] = "close",
["q"] = "close",
["i"] = "focus_input",
["<ScrollWheelDown>"] = "list_scroll_wheel_down",
["<ScrollWheelUp>"] = "list_scroll_wheel_up",
["<a-w>"] = "cycle_win",
},
},
},
layout = {
win = {
width = 0.8,
height = 0.8,
zindex = 50,
-- border = "rounded",
},
layout = {
box = "horizontal",
{
box = "vertical",
border = "rounded",
title = "{source} {live}",
title_pos = "center",
width = 0.5,
{ win = "input", height = 1, border = "bottom" },
{ win = "list", border = "none" },
},
{ win = "preview", border = "rounded" },
},
},
---@class snacks.picker.icons
icons = {
indent = {
top = "│ ",
middle = "├╴",
last = "└╴",
},
ui = {
live = "󰐰 ",
selected = "● ",
live = "󰐰 ",
selected = "● ",
-- selected = " ",
},
git = {
commit = "󰜘 ",
},
diagnostics = {
Error = " ",
Warn = " ",
Hint = " ",
Info = " ",
Warn = " ",
Hint = " ",
Info = " ",
},
kinds = {
Array = " ",
@ -247,13 +256,6 @@ Table of Contents *snacks-picker-table-of-contents*
==============================================================================
3. Types *snacks-picker-types*
>lua
---@class snacks.picker.Last
---@field opts snacks.picker.Config
---@field selected snacks.picker.Item[]
---@field filter snacks.picker.Filter
<
>lua
---@alias snacks.picker.Extmark vim.api.keyset.set_extmark|{col:number}
---@alias snacks.picker.Text {[1]:string, [2]:string?, virtual?:boolean}
@ -309,17 +311,29 @@ Generic filter used by finders to pre-filter items
<
>lua
---@class snacks.picker.list.Config: snacks.win.Config
---@field reverse? boolean
---@class snacks.picker.Layout
---@field layout snacks.layout.Box
---@field reverse? boolean when true, the list will be reversed (bottom-up)
---@field fullscreen? boolean open in fullscreen
---@field cycle? boolean cycle through the list
---@field preview? boolean|"main" show preview window in the picker or the main window
---@field preset? string|fun(source:string):string
<
>lua
---@class snacks.picker.win.Config
---@field input? snacks.win.Config|{}
---@field list? snacks.picker.list.Config|{}
---@field list? snacks.win.Config|{}
---@field preview? snacks.win.Config|{}
<
>lua
---@class snacks.picker.Last
---@field opts snacks.picker.Config
---@field selected snacks.picker.Item[]
---@field filter snacks.picker.Filter
<
==============================================================================
4. Module *snacks-picker-module*
@ -392,9 +406,10 @@ Generic filter used by finders to pre-filter items
---@field format snacks.picker.Formatter
---@field input snacks.picker.input
---@field layout snacks.layout
---@field resolved_layout snacks.picker.Layout
---@field list snacks.picker.list
---@field matcher snacks.picker.Matcher
---@field parent_win number
---@field main number
---@field preview snacks.picker.Preview
---@field shown? boolean
---@field sorter snacks.matcher.sorter
@ -404,12 +419,15 @@ Generic filter used by finders to pre-filter items
---@field closed? boolean
---@field hist_idx number
---@field hist_cursor number
---@field visual? snacks.picker.Visual
local M = {}
<
PICKER:ACTION() *snacks-picker-snacks.picker.core.picker-picker:action()*
Execute the given action(s)
>lua
---@param actions string|string[]
picker:action(actions)
@ -418,13 +436,26 @@ PICKER:ACTION() *snacks-picker-snacks.picker.core.picker-picker:action()*
PICKER:CLOSE() *snacks-picker-snacks.picker.core.picker-picker:close()*
Close the picker
>lua
picker:close()
<
PICKER:COUNT() *snacks-picker-snacks.picker.core.picker-picker:count()*
Total number of items in the picker
>lua
picker:count()
<
PICKER:CURRENT() *snacks-picker-snacks.picker.core.picker-picker:current()*
Get the current item at the cursor
>lua
picker:current()
<
@ -441,6 +472,8 @@ PICKER:DEBUG() *snacks-picker-snacks.picker.core.picker-picker:debug()*
PICKER:FILTER() *snacks-picker-snacks.picker.core.picker-picker:filter()*
Get the active filter
>lua
picker:filter()
<
@ -448,28 +481,28 @@ PICKER:FILTER() *snacks-picker-snacks.picker.core.picker-picker:filter()*
PICKER:FIND() *snacks-picker-snacks.picker.core.picker-picker:find()*
Clear the list and run the finder and matcher
>lua
picker:find()
---@param opts? {on_done?: fun()}
picker:find(opts)
<
PICKER:HIST() *snacks-picker-snacks.picker.core.picker-picker:hist()*
Move the history cursor
>lua
---@param forward? boolean
picker:hist(forward)
<
PICKER:HIST_RECORD()*snacks-picker-snacks.picker.core.picker-picker:hist_record()*
>lua
picker:hist_record()
<
PICKER:IS_ACTIVE()*snacks-picker-snacks.picker.core.picker-picker:is_active()*
Check if the finder or matcher is running
>lua
picker:is_active()
<
@ -477,27 +510,56 @@ PICKER:IS_ACTIVE()*snacks-picker-snacks.picker.core.picker-picker:is_active()*
PICKER:ITEMS() *snacks-picker-snacks.picker.core.picker-picker:items()*
Get all finder items
>lua
---@return fun():snacks.picker.Item?
picker:items()
<
PICKER:PROGRESS() *snacks-picker-snacks.picker.core.picker-picker:progress()*
PICKER:ITER() *snacks-picker-snacks.picker.core.picker-picker:iter()*
Returns an iterator over the items in the picker. Items will be in sorted
order.
>lua
picker:progress(ms)
---@return fun():snacks.picker.Item?
picker:iter()
<
PICKER:MATCH() *snacks-picker-snacks.picker.core.picker-picker:match()*
Run the matcher with the current pattern. May also trigger a new find if the
search string has changed, like during live searches.
>lua
picker:match()
<
PICKER:SELECTED() *snacks-picker-snacks.picker.core.picker-picker:selected()*
Get the selected items. If `fallback=true` and there is no selection, return
the current item.
>lua
---@param opts? {fallback?: boolean} If fallback is true (default), then return current item if no selected items
---@param opts? {fallback?: boolean} default is `false`
picker:selected(opts)
<
PICKER:SET_LAYOUT()*snacks-picker-snacks.picker.core.picker-picker:set_layout()*
Set the picker layout. Can be either the name of a preset layout or a custom
layout configuration.
>lua
---@param layout? string|snacks.picker.Layout
picker:set_layout(layout)
<
PICKER:SHOW() *snacks-picker-snacks.picker.core.picker-picker:show()*
>lua
@ -512,17 +574,12 @@ PICKER:SHOW_PREVIEW()*snacks-picker-snacks.picker.core.picker-picker:show_previe
<
PICKER:UPDATE() *snacks-picker-snacks.picker.core.picker-picker:update()*
PICKER:WORD() *snacks-picker-snacks.picker.core.picker-picker:word()*
Get the word under the cursor or the current visual selection
>lua
picker:update()
<
PICKER:UPDATE_TITLES()*snacks-picker-snacks.picker.core.picker-picker:update_titles()*
>lua
picker:update_titles()
picker:word()
<
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>

View file

@ -8,6 +8,7 @@ Table of Contents *snacks-styles-table-of-contents*
- blame_line |snacks-styles-styles-blame_line|
- dashboard |snacks-styles-styles-dashboard|
- float |snacks-styles-styles-float|
- help |snacks-styles-styles-help|
- input |snacks-styles-styles-input|
- lazygit |snacks-styles-styles-lazygit|
- minimal |snacks-styles-styles-minimal|
@ -116,6 +117,20 @@ FLOAT *snacks-styles-styles-float*
<
HELP *snacks-styles-styles-help*
>lua
{
position = "float",
backdrop = false,
border = "top",
row = -1,
width = 0,
height = 0.3,
}
<
INPUT *snacks-styles-styles-input*
>lua
@ -171,6 +186,7 @@ MINIMAL *snacks-styles-styles-minimal*
cursorcolumn = false,
cursorline = false,
cursorlineopt = "both",
colorcolumn = "",
fillchars = "eob: ,lastline:…",
list = false,
listchars = "extends:…,tab: ",

View file

@ -8,6 +8,7 @@ Table of Contents *snacks-win-table-of-contents*
3. Config |snacks-win-config|
4. Styles |snacks-win-styles|
- float |snacks-win-styles-float|
- help |snacks-win-styles-help|
- minimal |snacks-win-styles-minimal|
- split |snacks-win-styles-split|
5. Types |snacks-win-types|
@ -29,6 +30,7 @@ Table of Contents *snacks-win-table-of-contents*
- win:line() |snacks-win-module-win:line()|
- win:lines() |snacks-win-module-win:lines()|
- win:on() |snacks-win-module-win:on()|
- win:on_resize() |snacks-win-module-win:on_resize()|
- win:parent_size() |snacks-win-module-win:parent_size()|
- win:redraw() |snacks-win-module-win:redraw()|
- win:scratch() |snacks-win-module-win:scratch()|
@ -38,6 +40,7 @@ Table of Contents *snacks-win-table-of-contents*
- win:size() |snacks-win-module-win:size()|
- win:text() |snacks-win-module-win:text()|
- win:toggle() |snacks-win-module-win:toggle()|
- win:toggle_help() |snacks-win-module-win:toggle_help()|
- win:update() |snacks-win-module-win:update()|
- win:valid() |snacks-win-module-win:valid()|
- win:win_valid() |snacks-win-module-win:win_valid()|
@ -117,6 +120,7 @@ Easily create and manage floating windows or splits
---@field fixbuf? boolean don't allow other buffers to be opened in this window
---@field text? string|string[]|fun():(string[]|string) Initial lines to set in the buffer
---@field actions? table<string, snacks.win.Action.spec> Actions that can be used in key mappings
---@field resize? boolean Automatically resize the window when the editor is resized
{
show = true,
fixbuf = true,
@ -155,6 +159,20 @@ FLOAT *snacks-win-styles-float*
<
HELP *snacks-win-styles-help*
>lua
{
position = "float",
backdrop = false,
border = "top",
row = -1,
width = 0,
height = 0.3,
}
<
MINIMAL *snacks-win-styles-minimal*
>lua
@ -163,6 +181,7 @@ MINIMAL *snacks-win-styles-minimal*
cursorcolumn = false,
cursorline = false,
cursorlineopt = "both",
colorcolumn = "",
fillchars = "eob: ,lastline:…",
list = false,
listchars = "extends:…,tab: ",
@ -193,17 +212,6 @@ SPLIT *snacks-win-styles-split*
==============================================================================
5. Types *snacks-win-types*
>lua
---@class snacks.win.Event.callback.args
---@field id number
---@field event string
---@field group number?
---@field match string
---@field buf number
---@field file string
---@field data any
<
>lua
---@class snacks.win.Keys: vim.api.keyset.keymap
---@field [1]? string
@ -215,7 +223,7 @@ SPLIT *snacks-win-styles-split*
---@class snacks.win.Event: vim.api.keyset.create_autocmd
---@field buf? true
---@field win? true
---@field callback? fun(self: snacks.win, ev: snacks.win.Event.callback.args)
---@field callback? fun(self: snacks.win, ev:vim.api.keyset.create_autocmd.callback_args):boolean?
<
>lua
@ -259,6 +267,7 @@ SPLIT *snacks-win-styles-split*
---@field keys snacks.win.Keys[]
---@field events (snacks.win.Event|{event:string|string[]})[]
---@field meta table<string, string>
---@field closed? boolean
Snacks.win = {}
<
@ -391,12 +400,19 @@ WIN:ON() *snacks-win-module-win:on()*
>lua
---@param event string|string[]
---@param cb fun(self: snacks.win)
---@param cb fun(self: snacks.win, ev:vim.api.keyset.create_autocmd.callback_args):boolean?
---@param opts? snacks.win.Event
win:on(event, cb, opts)
<
WIN:ON_RESIZE() *snacks-win-module-win:on_resize()*
>lua
win:on_resize()
<
WIN:PARENT_SIZE() *snacks-win-module-win:parent_size()*
>lua
@ -467,6 +483,14 @@ WIN:TOGGLE() *snacks-win-module-win:toggle()*
<
WIN:TOGGLE_HELP() *snacks-win-module-win:toggle_help()*
>lua
---@param opts? {col_width?: number, key_width?: number, win?: snacks.win.Config}
win:toggle_help(opts)
<
WIN:UPDATE() *snacks-win-module-win:update()*
>lua

View file

@ -23,11 +23,13 @@
```lua
---@class snacks.layout.Config
---@field win? snacks.words.Config|{}
---@field wins table<string, snacks.win>
---@field layout snacks.layout.Box
---@field fullscreen? boolean open in fullscreen
---@field hidden? string[] list of windows that will be excluded from the layout
---@field on_update? fun(layout: snacks.layout)
{
win = {
layout = {
width = 0.6,
height = 0.6,
zindex = 50,
@ -38,31 +40,13 @@
## 📚 Types
```lua
---@class snacks.layout.Dim: snacks.win.Dim
---@field depth number
```
```lua
---@class snacks.layout.Base
---@field width? number
---@field min_width? number
---@field max_width? number
---@field height? number
---@field min_height? number
---@field max_height? number
---@field col? number
---@field row? number
---@field border? string
---@class snacks.layout.Win: snacks.win.Config,{}
---@field depth? number
```
```lua
---@class snacks.layout.Win: snacks.layout.Base, snacks.win.Config,{}
---@field win string
```
```lua
---@class snacks.layout.Box: snacks.layout.Base
---@class snacks.layout.Box: snacks.layout.Win,{}
---@field box "horizontal" | "vertical"
---@field id? number
---@field [number] snacks.layout.Win | snacks.layout.Box
@ -77,10 +61,11 @@
```lua
---@class snacks.layout
---@field opts snacks.layout.Config
---@field win snacks.win
---@field root snacks.win
---@field wins table<string, snacks.win|{enabled?:boolean}>
---@field box_wins snacks.win[]
---@field win_opts table<string, snacks.win.Config>
---@field closed? boolean
Snacks.layout = {}
```
@ -94,23 +79,53 @@ Snacks.layout.new(opts)
### `layout:close()`
```lua
layout:close()
---@param opts? {wins?: boolean}
layout:close(opts)
```
### `layout:each()`
```lua
---@param cb fun(widget: snacks.layout.Widget)
---@param opts? {wins?:boolean, boxes?:boolean}
---@param cb fun(widget: snacks.layout.Widget, parent?: snacks.layout.Box)
---@param opts? {wins?:boolean, boxes?:boolean, box?:snacks.layout.Box}
layout:each(cb, opts)
```
### `layout:is_enabled()`
```lua
---@param w string
layout:is_enabled(w)
```
### `layout:is_hidden()`
```lua
---@param win string
layout:is_hidden(win)
```
### `layout:maximize()`
Toggle fullscreen
```lua
layout:maximize()
```
### `layout:show()`
```lua
layout:show()
```
### `layout:toggle()`
```lua
---@param win string
layout:toggle(win)
```
### `layout:valid()`
```lua

View file

@ -29,6 +29,12 @@ Meta functions for Snacks
## 📦 Module
### `Snacks.meta.file()`
```lua
Snacks.meta.file(name)
```
### `Snacks.meta.get()`
Get the metadata for all snacks plugins

View file

@ -24,12 +24,12 @@
```lua
---@class snacks.picker.Config
---@field prompt? string
---@field pattern? string|fun():string Pattern used to filter items by the matcher
---@field search? string|fun():string Initial search string used by finders
---@field pattern? string|fun(picker:snacks.Picker):string Pattern used to filter items by the matcher
---@field search? string|fun(picker:snacks.Picker):string Initial search string used by finders
---@field cwd? string
---@field live? boolean
---@field limit? number when set, the finder will stop after finding this number of items. useful for live searches
---@field ui_select? boolean
---@field preset? string|string[]
---@field auto_confirm? boolean Automatically confirm if there is only one item
---@field format? snacks.picker.Formatter|string
---@field items? snacks.picker.finder.Item[]
@ -38,15 +38,25 @@
---@field sorter? snacks.matcher.sorter
---@field actions? table<string, snacks.picker.Action.spec>
---@field win? snacks.picker.win.Config
---@field layout? snacks.layout.Config|{}
---@field layout? snacks.picker.Layout|{}|fun(source:string):snacks.picker.Layout
---@field preview? snacks.picker.preview.Config
---@field previewer? snacks.picker.Previewer|string
---@field sources? snacks.picker.sources.Config|{}
---@field icons? snacks.picker.icons
---@field source? string
---@field on_change? fun(picker:snacks.Picker, item:snacks.picker.Item) called when the cursor changes
---@field on_show? fun(picker:snacks.Picker) called when the picker is shown
---@field layouts? table<string, snacks.picker.Layout>
---@field main? snacks.picker.main.Config
{
prompt = " ",
sources = {},
layout = {
cycle = true,
preset = function()
return vim.o.columns >= 120 and "default" or "vertical"
end,
},
ui_select = true, -- replace `vim.ui.select` with the snacks picker
preview = {
file = {
@ -84,18 +94,24 @@
["<c-k>"] = "list_up",
["<c-n>"] = "list_down",
["<c-p>"] = "list_up",
["<a-w>"] = "cycle_win",
["<Esc>"] = "close",
},
},
input = {
keys = {
["<esc>"] = "close",
["<Esc>"] = "close",
["G"] = "list_bottom",
["gg"] = "list_top",
["j"] = "list_down",
["k"] = "list_up",
["/"] = "toggle_focus",
["q"] = "close",
["<C-w>"] = { "<c-s-w>", mode = { "i" }, expr = true },
["?"] = "toggle_help",
["<a-m>"] = { "toggle_maximize", mode = { "i", "n" } },
["<a-p>"] = { "toggle_preview", mode = { "i", "n" } },
["<a-w>"] = { "cycle_win", mode = { "i", "n" } },
["<C-w>"] = { "<c-s-w>", mode = { "i" }, expr = true, desc = "delete word" },
["<C-Up>"] = { "history_back", mode = { "i", "n" } },
["<C-Down>"] = { "history_forward", mode = { "i", "n" } },
["<Tab>"] = { "select_and_next", mode = { "i", "n" } },
@ -115,58 +131,50 @@
["<ScrollWheelUp>"] = { "list_scroll_wheel_up", mode = { "i", "n" } },
["<c-v>"] = { "edit_vsplit", mode = { "i", "n" } },
["<c-s>"] = { "edit_split", mode = { "i", "n" } },
["<c-q>"] = { "qf", mode = { "i", "n" } },
["<a-q>"] = { "qf_all", mode = { "i", "n" } },
["<c-q>"] = { "qflist", mode = { "i", "n" } },
["<a-i>"] = { "toggle_ignored", mode = { "i", "n" } },
["<a-h>"] = { "toggle_hidden", mode = { "i", "n" } },
},
b = {
minipairs_disable = true,
},
},
preview = {
minimal = false,
wo = {
cursorline = false,
colorcolumn = "",
},
keys = {
["<Esc>"] = "close",
["q"] = "close",
["i"] = "focus_input",
["<ScrollWheelDown>"] = "list_scroll_wheel_down",
["<ScrollWheelUp>"] = "list_scroll_wheel_up",
["<a-w>"] = "cycle_win",
},
},
},
layout = {
win = {
width = 0.8,
height = 0.8,
zindex = 50,
-- border = "rounded",
},
layout = {
box = "horizontal",
{
box = "vertical",
border = "rounded",
title = "{source} {live}",
title_pos = "center",
width = 0.5,
{ win = "input", height = 1, border = "bottom" },
{ win = "list", border = "none" },
},
{ win = "preview", border = "rounded" },
},
},
---@class snacks.picker.icons
icons = {
indent = {
top = "│ ",
middle = "├╴",
last = "└╴",
},
ui = {
live = "󰐰 ",
selected = "● ",
live = "󰐰 ",
selected = "● ",
-- selected = " ",
},
git = {
commit = "󰜘 ",
},
diagnostics = {
Error = " ",
Warn = " ",
Hint = " ",
Info = " ",
Warn = " ",
Hint = " ",
Info = " ",
},
kinds = {
Array = " ",
@ -214,13 +222,6 @@
## 📚 Types
```lua
---@class snacks.picker.Last
---@field opts snacks.picker.Config
---@field selected snacks.picker.Item[]
---@field filter snacks.picker.Filter
```
```lua
---@alias snacks.picker.Extmark vim.api.keyset.set_extmark|{col:number}
---@alias snacks.picker.Text {[1]:string, [2]:string?, virtual?:boolean}
@ -276,17 +277,29 @@ Generic filter used by finders to pre-filter items
```
```lua
---@class snacks.picker.list.Config: snacks.win.Config
---@field reverse? boolean
---@class snacks.picker.Layout
---@field layout snacks.layout.Box
---@field reverse? boolean when true, the list will be reversed (bottom-up)
---@field fullscreen? boolean open in fullscreen
---@field cycle? boolean cycle through the list
---@field preview? boolean|"main" show preview window in the picker or the main window
---@field preset? string|fun(source:string):string
```
```lua
---@class snacks.picker.win.Config
---@field input? snacks.win.Config|{}
---@field list? snacks.picker.list.Config|{}
---@field list? snacks.win.Config|{}
---@field preview? snacks.win.Config|{}
```
```lua
---@class snacks.picker.Last
---@field opts snacks.picker.Config
---@field selected snacks.picker.Item[]
---@field filter snacks.picker.Filter
```
## 📦 Module
```lua
@ -341,6 +354,8 @@ Snacks.picker.pick(source, opts)
Snacks.picker.select(...)
```
## 📦 `snacks.picker.core.picker`
```lua
@ -350,9 +365,10 @@ Snacks.picker.select(...)
---@field format snacks.picker.Formatter
---@field input snacks.picker.input
---@field layout snacks.layout
---@field resolved_layout snacks.picker.Layout
---@field list snacks.picker.list
---@field matcher snacks.picker.Matcher
---@field parent_win number
---@field main number
---@field preview snacks.picker.Preview
---@field shown? boolean
---@field sorter snacks.matcher.sorter
@ -362,11 +378,14 @@ Snacks.picker.select(...)
---@field closed? boolean
---@field hist_idx number
---@field hist_cursor number
---@field visual? snacks.picker.Visual
local M = {}
```
### `picker:action()`
Execute the given action(s)
```lua
---@param actions string|string[]
picker:action(actions)
@ -374,12 +393,24 @@ picker:action(actions)
### `picker:close()`
Close the picker
```lua
picker:close()
```
### `picker:count()`
Total number of items in the picker
```lua
picker:count()
```
### `picker:current()`
Get the current item at the cursor
```lua
picker:current()
```
@ -394,55 +425,86 @@ picker:debug(name, start)
### `picker:filter()`
Get the active filter
```lua
picker:filter()
```
### `picker:find()`
Clear the list and run the finder and matcher
```lua
picker:find()
---@param opts? {on_done?: fun()}
picker:find(opts)
```
### `picker:hist()`
Move the history cursor
```lua
---@param forward? boolean
picker:hist(forward)
```
### `picker:hist_record()`
```lua
picker:hist_record()
```
### `picker:is_active()`
Check if the finder or matcher is running
```lua
picker:is_active()
```
### `picker:items()`
Get all finder items
```lua
---@return fun():snacks.picker.Item?
picker:items()
```
### `picker:progress()`
### `picker:iter()`
Returns an iterator over the items in the picker.
Items will be in sorted order.
```lua
picker:progress(ms)
---@return fun():snacks.picker.Item?
picker:iter()
```
### `picker:match()`
Run the matcher with the current pattern.
May also trigger a new find if the search string has changed,
like during live searches.
```lua
picker:match()
```
### `picker:selected()`
Get the selected items.
If `fallback=true` and there is no selection, return the current item.
```lua
---@param opts? {fallback?: boolean} If fallback is true (default), then return current item if no selected items
---@param opts? {fallback?: boolean} default is `false`
picker:selected(opts)
```
### `picker:set_layout()`
Set the picker layout. Can be either the name of a preset layout
or a custom layout configuration.
```lua
---@param layout? string|snacks.picker.Layout
picker:set_layout(layout)
```
### `picker:show()`
```lua
@ -455,16 +517,10 @@ picker:show()
picker:show_preview()
```
### `picker:update()`
### `picker:word()`
Get the word under the cursor or the current visual selection
```lua
picker:update()
picker:word()
```
### `picker:update_titles()`
```lua
picker:update_titles()
```

View file

@ -93,6 +93,19 @@ The other options are used with `:lua Snacks.dashboard()`
}
```
### `help`
```lua
{
position = "float",
backdrop = false,
border = "top",
row = -1,
width = 0,
height = 0.3,
}
```
### `input`
```lua
@ -146,6 +159,7 @@ The other options are used with `:lua Snacks.dashboard()`
cursorcolumn = false,
cursorline = false,
cursorlineopt = "both",
colorcolumn = "",
fillchars = "eob: ,lastline:…",
list = false,
listchars = "extends:…,tab: ",

View file

@ -72,6 +72,7 @@ Snacks.win({
---@field fixbuf? boolean don't allow other buffers to be opened in this window
---@field text? string|string[]|fun():(string[]|string) Initial lines to set in the buffer
---@field actions? table<string, snacks.win.Action.spec> Actions that can be used in key mappings
---@field resize? boolean Automatically resize the window when the editor is resized
{
show = true,
fixbuf = true,
@ -105,6 +106,19 @@ docs for more information on how to customize these styles
}
```
### `help`
```lua
{
position = "float",
backdrop = false,
border = "top",
row = -1,
width = 0,
height = 0.3,
}
```
### `minimal`
```lua
@ -113,6 +127,7 @@ docs for more information on how to customize these styles
cursorcolumn = false,
cursorline = false,
cursorlineopt = "both",
colorcolumn = "",
fillchars = "eob: ,lastline:…",
list = false,
listchars = "extends:…,tab: ",
@ -140,17 +155,6 @@ docs for more information on how to customize these styles
## 📚 Types
```lua
---@class snacks.win.Event.callback.args
---@field id number
---@field event string
---@field group number?
---@field match string
---@field buf number
---@field file string
---@field data any
```
```lua
---@class snacks.win.Keys: vim.api.keyset.keymap
---@field [1]? string
@ -162,7 +166,7 @@ docs for more information on how to customize these styles
---@class snacks.win.Event: vim.api.keyset.create_autocmd
---@field buf? true
---@field win? true
---@field callback? fun(self: snacks.win, ev: snacks.win.Event.callback.args)
---@field callback? fun(self: snacks.win, ev:vim.api.keyset.create_autocmd.callback_args):boolean?
```
```lua
@ -204,6 +208,7 @@ docs for more information on how to customize these styles
---@field keys snacks.win.Keys[]
---@field events (snacks.win.Event|{event:string|string[]})[]
---@field meta table<string, string>
---@field closed? boolean
Snacks.win = {}
```
@ -319,11 +324,17 @@ win:lines(from, to)
```lua
---@param event string|string[]
---@param cb fun(self: snacks.win)
---@param cb fun(self: snacks.win, ev:vim.api.keyset.create_autocmd.callback_args):boolean?
---@param opts? snacks.win.Event
win:on(event, cb, opts)
```
### `win:on_resize()`
```lua
win:on_resize()
```
### `win:parent_size()`
```lua
@ -385,6 +396,13 @@ win:text(from, to)
win:toggle()
```
### `win:toggle_help()`
```lua
---@param opts? {col_width?: number, key_width?: number, win?: snacks.win.Config}
win:toggle_help(opts)
```
### `win:update()`
```lua

View file

@ -199,6 +199,8 @@ function M:word()
return self.visual and self.visual.text or vim.fn.expand("<cword>")
end
--- Update title templates
---@private
function M:update_titles()
local data = {
source = self.source_name,
@ -216,6 +218,7 @@ function M:update_titles()
end
end
--- Resume the last picker
---@private
function M.resume()
local last = M.last
@ -267,8 +270,10 @@ function M:show()
end
end
--- Returns an iterator over the items in the picker.
--- Items will be in sorted order.
---@return fun():snacks.picker.Item?
function M:items()
function M:iter()
local i = 0
local n = self.finder:count()
return function()
@ -279,11 +284,19 @@ function M:items()
end
end
--- Get all finder items
function M:items()
return self.finder.items
end
--- Get the current item at the cursor
function M:current()
return self.list:current()
end
---@param opts? {fallback?: boolean} If fallback is true (default), then return current item if no selected items
--- Get the selected items.
--- If `fallback=true` and there is no selection, return the current item.
---@param opts? {fallback?: boolean} default is `false`
function M:selected(opts)
opts = opts or {}
local ret = vim.deepcopy(self.list.selected)
@ -293,10 +306,12 @@ function M:selected(opts)
return ret
end
-- Total number of items in the picker
function M:count()
return self.finder:count()
end
--- Close the picker
function M:close()
if self.closed then
return
@ -321,10 +336,12 @@ function M:close()
end)
end
--- Check if the finder or matcher is running
function M:is_active()
return self.finder:running() or self.matcher:running()
end
---@private
function M:progress(ms)
if self.updater:is_active() then
return
@ -339,6 +356,7 @@ function M:progress(ms)
end, ms or 10)
end
---@hide
function M:update()
if self.closed then
return
@ -369,7 +387,6 @@ function M:update()
self:close()
return
elseif count == 1 and self.opts.auto_confirm then
self:debug("auto_confirm")
-- auto confirm if only one result
self:action("confirm")
self:close()
@ -378,11 +395,9 @@ function M:update()
-- show the picker if we have results
self.list:unpause()
self:show()
self:debug("show")
end
elseif list_count > 1 or (list_count == 1 and not self.opts.auto_confirm) then -- show the picker if we have results
self:show()
self:debug("show")
end
end
@ -398,6 +413,7 @@ function M:update()
end
end
--- Execute the given action(s)
---@param actions string|string[]
function M:action(actions)
return self.input.win:execute(actions)
@ -415,6 +431,8 @@ function M:find(opts)
self:progress()
end
--- Add current filter to history
---@private
function M:hist_record()
M.history[self.hist_idx] = {
pattern = self.input.filter.pattern,
@ -423,6 +441,7 @@ function M:hist_record()
}
end
--- Move the history cursor
---@param forward? boolean
function M:hist(forward)
self:hist_record()
@ -469,7 +488,7 @@ function M:match()
self:progress()
end
--- Get the current filter
--- Get the active filter
function M:filter()
return self.input.filter:clone()
end