dotfiles bugabingas dorkfiles
owned by bugabinga
README Source History Refs Compare Notes Search refactor(neovim): let pivi publish key intents instead of claiming keys
f14cc9833776d2b4fe037db85b61970bfc3cb873
Oliver Krylow <o.krylow@isp-insoft.de > · 18 Sep 2026
SSH signature · not checked
Browse files Compare with HEAD
Changed files (18) 84 84 defer
'bugabinga.d2' 85 85 defer
'bugabinga.pivi' 86 86 defer
'bugabinga.pivi_status' 87 + defer
'bugabinga.pivi_keys' neovim/lua/bugabinga/options/keymaps.lua Modified 120 - description =
'Open the pi prompt' ,
122 - keys =
'<leader>pp' ,
123 - command =
'<Plug>(pivi-prompt)' ,
128 - description =
'Show the pi transcript' ,
130 - keys =
'<leader>ps' ,
131 - command =
'<Plug>(pivi-show)' ,
136 - description =
'Abort the current pi run' ,
138 - keys =
'<leader>pa' ,
139 - command =
'<Plug>(pivi-abort)' ,
144 - description =
'Toggle following the agent' ,
146 - keys =
'<leader>pf' ,
147 - command =
'<Plug>(pivi-follow)' ,
152 - description =
'Ask pi about neovim, pivi or pi' ,
154 - keys =
'<leader>ph' ,
155 - command =
':Pi help ' ,
159 - description =
'Ask pi about the project' ,
161 - keys =
'<leader>pk' ,
162 - command =
':Pi ask ' ,
166 - description =
'Ask pi about the selection' ,
168 - keys =
'<leader>pk' ,
169 - command =
':Pi ask ' ,
173 118 description =
'save' ,
174 119 category =
'file' ,
neovim/lua/bugabinga/pivi/AGENTS.md Modified 90 90 24. **A nameless buffer reads as the working directory.** `fnamemodify('', ':~:.')` returns the cwd, so an unnamed scratch buffer makes a statusline claim the user is editing a file in it, which is where `system32` came from under a launcher that starts in `C:\Windows\system32`.
91 91 Name every buffer pivi creates, floats included.
93 - 25. **Contract tests guard assumptions,** not features. They skip unless `pi` is on `PATH` and opt-in is set. When Pi changes behavior, they fail before users do.
93 + 25. **Never shadow a key whose meaning you are changing.** pivi publishes `<Plug>` intents; a configuration binds them.
94 + `tests/bugabinga/pivi/keys_spec.lua` asserts pivi claims no bare key in any of its buffers, with `/` in a prompt as the single declared exception.
95 + Accepting a completion and accepting a prompt are the same intent, so `<Plug>(pivi-accept)` yields to an open popup instead of replacing it.
97 + 26. **`std.auto` clears its group on every call.** Registering two autocmds with the same group name in two calls silently deletes the first; pass one list instead.
99 + 27. **Contract tests guard assumptions,** not features. They skip unless `pi` is on `PATH` and opt-in is set. When Pi changes behavior, they fail before users do.
132 138 | Reported change | written as the tool formatted it and highlighted with `DiffAdd`/`DiffDelete` per line; `bugabinga.pivi.diff` rebuilds the prior content from the change itself and states when the file has moved on |
133 139 | Streaming output | rewrite only the entry tail, skip per-line decoration while it runs, and never run `fold.apply` mid-stream |
134 140 | Output language | parsed as a standalone string and applied as highlight extmarks, never as a fence, so transcript text stays what the tool produced |
135 - | Keys | pivi binds buffer-locally and publishes `<Plug>` mappings; the configuration chooses the keys in `options/keymaps.lua`. `]t` and `[t` are real global maps (`:tnext`, `:tprevious`) that pivi shadows inside its own buffers only |
141 + | Keys | pivi binds no bare key and publishes `<Plug>` intents only; `lua/bugabinga/pivi_keys.lua` chooses the keys. A key is reused only where the local behaviour is the same idea as the global one, so `<CR>` activates, `K` shows information, `]]` and `[[` move by section, and folding needs no key because entries are real folds |
136 142 | Guide | `?` reads the mappings that exist in the buffer rather than a list written beside them, so it cannot drift |
neovim/lua/bugabinga/pivi/command.lua Modified 114 114 guide.bind( bufnr )
116 - vim.keymap.set( {
'n' ,
'i' , },
'<c-s>' ,
function ()
116 + local send = function ()
117 117 local lines
= vim.api.nvim_buf_get_lines( bufnr,
0 ,
- 1 ,
false )
118 118 local text
= vim.trim(
table .
concat ( lines,
'\n' ) )
119 119 if text
== '' then return end 125 125 vim.api.nvim_buf_set_lines( bufnr,
0 ,
- 1 ,
false , {
'' , } )
127 127 transcript.show( current.buffer )
128 - end, {
buffer = bufnr,
desc =
'pivi submit prompt' , } )
130 + vim.keymap.set( {
'n' ,
'i' , },
'<Plug>(pivi-submit)' , send,
131 + {
buffer = bufnr,
desc =
'pivi submit the prompt' , } )
135 + vim.keymap.set(
'i' ,
'<Plug>(pivi-accept)' ,
function ()
136 + if vim.fn.pumvisible()
== 1 then return '<C-y>' end 137 + vim.schedule( send )
139 + end , {
buffer = bufnr,
expr =
true ,
desc =
'pivi accept the completion, else the prompt' , } )
130 141 if pcall ( vim.cmd.split )
then 131 142 local win
= vim.api.nvim_get_current_win()
133 144 pcall ( vim.api.nvim_win_set_height, win,
6 )
134 145 transcript.decorate( win, current.name )
135 146 vim.wo[win].winbar
= '%#Title#π ' .. current.name
.. 136 - '%* %#Comment#<c-s> send / commands%*' 147 + '%* %#Comment#' .. ( vim.g.pivi_submit_hint
or 'send' )
.. ' / commands%*' 137 148 vim.cmd.startinsert()
neovim/lua/bugabinga/pivi/detail.lua Modified 122 122 local bind = function ( bufnr )
123 - local action = function () inspect( bufnr )
end 124 - vim.keymap.set(
'n' ,
'K' , action, {
buffer = bufnr,
desc =
'pivi inspect the entry' , } )
125 - vim.keymap.set(
'n' ,
'<Plug>(pivi-inspect-entry)' , action,
123 + vim.keymap.set(
'n' ,
'<Plug>(pivi-inspect-entry)' ,
function () inspect( bufnr )
end ,
126 124 {
buffer = bufnr,
desc =
'pivi inspect the entry' , } )
neovim/lua/bugabinga/pivi/diff.lua Modified 121 121 local bind = function ( bufnr )
122 - local action = function () open( bufnr )
end 123 - vim.keymap.set(
'n' ,
'gD' , action, {
buffer = bufnr,
desc =
'pivi compare the change of the entry' , } )
124 - vim.keymap.set(
'n' ,
'<Plug>(pivi-compare-change)' , action,
122 + vim.keymap.set(
'n' ,
'<Plug>(pivi-compare-change)' ,
function () open( bufnr )
end ,
125 123 {
buffer = bufnr,
desc =
'pivi compare the change of the entry' , } )
neovim/lua/bugabinga/pivi/fold.lua Modified 143 143 wanted[bufnr]
= nil 147 148 local bind = function ( bufnr )
148 - vim.keymap.set(
'n' ,
'<CR>' ,
function ()
149 - toggle( bufnr, vim.api.nvim_win_get_cursor(
0 )[
1 ] )
150 - end , {
buffer = bufnr,
desc =
'pivi collapse or expand the entry' , } )
152 149 vim.keymap.set(
'n' ,
'<Plug>(pivi-toggle-entry)' ,
function ()
153 150 toggle( bufnr, vim.api.nvim_win_get_cursor(
0 )[
1 ] )
154 151 end , {
buffer = bufnr,
desc =
'pivi collapse or expand the entry' , } )
neovim/lua/bugabinga/pivi/guide.lua Modified 1 1 local transcript
= require 'bugabinga.pivi.transcript' 2 2 local glyph
= require 'std.icon' 7 - local describe = function ( bufnr )
9 - for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr,
'n' ) )
do 10 - local description
= mapping.desc
or '' 11 - if description:find(
'pivi' ,
1 ,
true )
and not mapping.lhs:find(
'<Plug>' ,
1 ,
true )
then 12 - table .
insert ( found, {
keys = mapping.lhs,
what = description:gsub(
'^pivi ' ,
'' ), } )
4 + local MODES
= {
'n' ,
'i' ,
'x' , }
7 + local intents = function ( bufnr )
9 + for _, mode
in ipairs ( MODES )
do 10 + for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr, mode ) )
do 11 + local plug
= mapping.lhs:match
'^<Plug>%((pivi%-[%w%-]+)%)$' 12 + if plug
then known[plug]
= ( mapping.desc
or plug ):gsub(
'^pivi ' ,
'' )
end 22 + local describe = function ( bufnr )
23 + local known
= intents( bufnr )
27 + local collect = function ( mappings )
28 + for _, mapping
in ipairs ( mappings )
do 29 + if not mapping.lhs:find(
'<Plug>' ,
1 ,
true )
then 30 + local target
= ( mapping.rhs
or '' ):match
'<Plug>%((pivi%-[%w%-]+)%)' 31 + local what
= target
and known[target]
or nil 35 + if not what
and ( mapping.desc
or '' ):find(
'pivi' ,
1 ,
true )
then 36 + what
= mapping.desc:gsub(
'^pivi ' ,
'' )
39 + if what
and not seen[mapping.lhs]
then 40 + seen[mapping.lhs]
= true 41 + table .
insert ( found, {
keys = mapping.lhs,
what = what, } )
47 + for _, mode
in ipairs ( MODES )
do 48 + collect( vim.api.nvim_buf_get_keymap( bufnr, mode ) )
49 + collect( vim.api.nvim_get_keymap( mode ) )
15 52 table .
sort ( found,
function ( left, right )
return left.keys
< right.keys
end )
47 84 table .
insert ( written,
'' )
50 - table .
insert ( written,
'## ' .. glyph.list
.. ' elsewhere' )
87 + table .
insert ( written,
'## ' .. glyph.list
.. ' ordinary neovim' )
51 88 table .
insert ( written,
'' )
89 + table .
insert ( written,
'- `za` `zo` `zc` collapse or expand the entry under the cursor' )
52 90 table .
insert ( written,
'- `zR` / `zM` expand or collapse every entry' )
53 91 table .
insert ( written,
'- `]c` / `[c` move between changes inside a comparison' )
54 - table .
insert ( written,
'- `:help pivi` if the documentation is installed' )
92 + table .
insert ( written,
'' )
93 + table .
insert ( written,
'Entries are real folds, so no key here replaces one you already know.' )
80 119 return float, window
84 122 local bind = function ( bufnr )
85 - local action = function () show( bufnr )
end 86 - vim.keymap.set(
'n' ,
'?' , action, {
buffer = bufnr,
desc =
'pivi show this guide' , } )
87 - vim.keymap.set(
'n' ,
'<Plug>(pivi-guide)' , action, {
buffer = bufnr,
desc =
'pivi show this guide' , } )
123 + vim.keymap.set(
'n' ,
'<Plug>(pivi-guide)' ,
function () show( bufnr )
end ,
124 + {
buffer = bufnr,
desc =
'pivi show this guide' , } )
90 127 transcript.on_buffer( bind )
neovim/lua/bugabinga/pivi/navigate.lua Modified 73 73 return follow.visit( location )
77 77 local bind = function ( bufnr )
79 - {
keys =
']m' ,
plug =
'<Plug>(pivi-next-entry)' ,
kind =
nil ,
move = next_entry,
79 + {
plug =
'<Plug>(pivi-next-entry)' ,
kind =
nil ,
move = next_entry,
80 80 description =
'pivi next entry' , },
81 - {
keys =
'[m' ,
plug =
'<Plug>(pivi-previous-entry)' ,
kind =
nil ,
move = previous_entry,
81 + {
plug =
'<Plug>(pivi-previous-entry)' ,
kind =
nil ,
move = previous_entry,
82 82 description =
'pivi previous entry' , },
83 - {
keys =
']t' ,
plug =
'<Plug>(pivi-next-tool)' ,
kind =
'tool' ,
move = next_entry,
83 + {
plug =
'<Plug>(pivi-next-tool)' ,
kind =
'tool' ,
move = next_entry,
84 84 description =
'pivi next tool call' , },
85 - {
keys =
'[t' ,
plug =
'<Plug>(pivi-previous-tool)' ,
kind =
'tool' ,
move = previous_entry,
85 + {
plug =
'<Plug>(pivi-previous-tool)' ,
kind =
'tool' ,
move = previous_entry,
86 86 description =
'pivi previous tool call' , },
89 89 for _, motion
in ipairs ( motions )
do 90 - local action = function () motion.move( bufnr, motion.kind )
end 91 - vim.keymap.set(
'n' , motion.keys, action, {
buffer = bufnr,
desc = motion.description, } )
92 - vim.keymap.set(
'n' , motion.plug, action, {
buffer = bufnr,
desc = motion.description, } )
90 + vim.keymap.set(
'n' , motion.plug,
function () motion.move( bufnr, motion.kind )
end ,
91 + {
buffer = bufnr,
desc = motion.description, } )
95 - local visit = function () locate( bufnr )
end 96 - vim.keymap.set(
'n' ,
'gf' , visit, {
buffer = bufnr,
desc =
'pivi go to the location of the entry' , } )
97 - vim.keymap.set(
'n' ,
'<Plug>(pivi-goto-location)' , visit,
94 + vim.keymap.set(
'n' ,
'<Plug>(pivi-goto-location)' ,
function () locate( bufnr )
end ,
98 95 {
buffer = bufnr,
desc =
'pivi go to the location of the entry' , } )
neovim/lua/bugabinga/pivi/skills/pivi/SKILL.md Modified 48 48 - Output of a running tool appears as it arrives, and output that came from a known language is presented in it.
49 49 - Nothing here is invented: a tool that reports nothing about its own work simply names its subject.
51 - | Key in a transcript | Effect |
51 + | Intent in a transcript | Bound here to |
53 - | `<CR>` | collapse or expand the entry under the cursor |
54 - | `]m` / `[m` | move to the next or previous entry |
55 - | `]t` / `[t` | move to the next or previous tool call |
56 - | `gf` | go to the location the entry names |
57 - | `K` | inspect the entry, including tool arguments and result |
58 - | `gD` | compare a completed change as a real editor diff |
59 - | `?` | show the guide of keys and commands for this buffer |
60 - | `zR` / `zM` | expand or collapse everything, as in any buffer |
53 + | go to what the entry names | `<CR>` |
54 + | inspect the entry | `K` |
55 + | next or previous entry | `]]` / `[[` |
56 + | next or previous tool call | `<leader>pn` / `<leader>pN` |
57 + | compare the change | `<leader>pd` |
58 + | show this guide | `<leader>p?` |
59 + | collapse or expand | `za` `zo` `zc` `zR` `zM`, because entries are real folds |
62 - These keys are buffer-local, and `<Plug>(pivi-toggle-entry)`, `<Plug>(pivi-next-entry)`, `<Plug>(pivi-previous-entry)`, `<Plug>(pivi-next-tool)`, `<Plug>(pivi-previous-tool)`, `<Plug>(pivi-goto-location)`, `<Plug>(pivi-inspect-entry)` and `<Plug>(pivi-compare-change)` exist alongside them.
61 + In the prompt, `<c-y>` accepts: the completion when one is offered, the prompt otherwise. `<CR>` in normal mode sends it.
63 + pivi chooses none of these. It publishes `<Plug>(pivi-goto-location)`, `<Plug>(pivi-inspect-entry)`, `<Plug>(pivi-next-entry)`, `<Plug>(pivi-previous-entry)`, `<Plug>(pivi-next-tool)`, `<Plug>(pivi-previous-tool)`, `<Plug>(pivi-compare-change)`, `<Plug>(pivi-toggle-entry)`, `<Plug>(pivi-guide)`, `<Plug>(pivi-submit)` and `<Plug>(pivi-accept)`, and the configuration decides the keys. A key is only reused where the local behaviour is the same idea as the global one.
65 + The single key pivi binds itself is `/` in a prompt, and only at the first character, because there the behaviour *is* the key.
64 67 ##
Surfaces the user has neovim/lua/bugabinga/pivi_keys.lua Added new file mode 100644 5 + local auto
= require 'std.auto' 6 + local map
= require 'std.map' 15 + {
keys =
'<cr>' ,
intent =
'goto-location' ,
description =
'Go to what this entry names' , },
16 + {
keys =
'K' ,
intent =
'inspect-entry' ,
description =
'Inspect this entry' , },
17 + {
keys =
']]' ,
intent =
'next-entry' ,
description =
'Next entry' , },
18 + {
keys =
'[[' ,
intent =
'previous-entry' ,
description =
'Previous entry' , },
19 + {
keys =
'<leader>pd' ,
intent =
'compare-change' ,
description =
'Compare this change' , },
20 + {
keys =
'<leader>p?' ,
intent =
'guide' ,
description =
'Show the pivi guide' , },
21 + {
keys =
'<leader>pn' ,
intent =
'next-tool' ,
description =
'Next tool call' , },
22 + {
keys =
'<leader>pN' ,
intent =
'previous-tool' ,
description =
'Previous tool call' , },
30 + {
keys =
'<c-y>' ,
intent =
'accept' ,
modes = {
'i' , },
description =
'Accept the completion, else send' , },
31 + {
keys =
'<cr>' ,
intent =
'submit' ,
modes = {
'n' , },
description =
'Send the prompt' , },
32 + {
keys =
'<leader>p?' ,
intent =
'guide' ,
modes = {
'n' , },
description =
'Show the pivi guide' , },
35 + local bind = function ( bufnr, choices )
36 + for _, choice
in ipairs ( choices )
do 37 + for _, mode
in ipairs ( choice.modes
or {
'n' , } )
do 38 + vim.keymap.set( mode, choice.keys,
'<Plug>(pivi-' .. choice.intent
.. ')' , {
41 + desc =
'pi: ' .. choice.description,
51 + events =
'FileType' ,
53 + description =
'Choose the keys of a pivi transcript.' ,
54 + command =
function ( event ) bind( event.buf, TRANSCRIPT )
end ,
57 + events =
'FileType' ,
58 + pattern =
'pivi-input' ,
59 + description =
'Choose the keys of a pivi prompt.' ,
60 + command =
function ( event ) bind( event.buf, PROMPT )
end ,
65 + vim.g.pivi_submit_hint
= '<c-y> send' 68 + description =
'Open the pi prompt' ,
70 + keys =
'<leader>pp' ,
71 + command =
'<Plug>(pivi-prompt)' ,
76 + description =
'Show the pi transcript' ,
78 + keys =
'<leader>ps' ,
79 + command =
'<Plug>(pivi-show)' ,
84 + description =
'Abort the current pi run' ,
86 + keys =
'<leader>pa' ,
87 + command =
'<Plug>(pivi-abort)' ,
92 + description =
'Toggle following the agent' ,
94 + keys =
'<leader>pf' ,
95 + command =
'<Plug>(pivi-follow)' ,
100 + description =
'Ask pi about neovim, pivi or pi' ,
102 + keys =
'<leader>ph' ,
103 + command =
':Pi help ' ,
107 + description =
'Ask pi about the project' ,
109 + keys =
'<leader>pk' ,
110 + command =
':Pi ask ' ,
114 + description =
'Ask pi about the selection' ,
116 + keys =
'<leader>pk' ,
117 + command =
':Pi ask ' ,
121 + transcript = TRANSCRIPT,
neovim/tests/bugabinga/pivi/command_spec.lua Modified 48 48 assert .is_true( win
> 0 )
49 49 assert .is_true( vim.wo[win].winbar:find(
'spec' ,
1 ,
true )
~= nil )
50 - assert .is_true( vim.wo[win].winbar:find(
'c-s' ,
1 ,
true )
~= nil )
50 + assert .is_true( vim.wo[win].winbar:find(
'send' ,
1 ,
true )
~= nil )
51 51 assert .is_true( vim.api.nvim_buf_get_name( bufnr ):find(
'pivi://' ,
1 ,
true )
~= nil )
52 52 assert .equal(
'spec' , vim.b[bufnr].pivi_session )
66 66 for _, entry
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr,
'n' ) )
do 67 - if entry.lhs
== '<C-S>' then mapping
= entry
end 67 + if entry.lhs
== '<Plug>(pivi-submit)' then mapping
= entry
end 69 69 assert .is_table( mapping )
neovim/tests/bugabinga/pivi/editor/detail_spec.lua Modified 105 105 assert .is_nil( detail.inspect( bufnr,
1 ) )
108 - it(
'binds inspection in its own buffers only' ,
function ()
108 + it(
'publishes inspection as an intent' ,
function ()
110 110 for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr,
'n' ) )
do 111 - bound[mapping.lhs]
= mapping.desc
or '' 111 + if mapping.lhs
== '<Plug>(pivi-inspect-entry)' then published
= mapping
end 114 - assert .is_string( bound.K )
115 - assert .is_true( bound.K:find(
'pivi' ,
1 ,
true )
~= nil )
117 - for _, mapping
in ipairs ( vim.api.nvim_get_keymap
'n' )
do 118 - assert .is_nil( ( mapping.desc
or '' ):find(
'pivi' ,
1 ,
true ) )
114 + assert .is_table( published )
neovim/tests/bugabinga/pivi/editor/diff_spec.lua Modified 155 155 assert .equal( win, vim.api.nvim_get_current_win() )
158 - it(
'binds comparison in its own buffers only' ,
function ()
158 + it(
'publishes comparison as an intent' ,
function ()
160 160 for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr,
'n' ) )
do 161 - bound[mapping.lhs]
= mapping.desc
or '' 161 + if mapping.lhs
== '<Plug>(pivi-compare-change)' then published
= mapping
end 164 - assert .is_string( bound.gD )
165 - assert .is_true( bound.gD:find(
'pivi' ,
1 ,
true )
~= nil )
164 + assert .is_table( published )
neovim/tests/bugabinga/pivi/editor/fold_spec.lua Modified 124 124 assert .equal(
'tool' , entry.at( bufnr, first ).kind )
127 - it(
'binds a buffer-local key without claiming a global one' ,
function ()
127 + it(
'publishes collapsing as an intent and claims no key for it' ,
function ()
129 129 for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr,
'n' ) )
do 130 - if mapping.lhs
== '<CR>' then found
= mapping
end 130 + if mapping.lhs
== '<Plug>(pivi-toggle-entry)' then published
= mapping
end 133 - assert .is_table( found )
134 - for _, mapping
in ipairs ( vim.api.nvim_get_keymap
'n' )
do 135 - assert .is_nil( ( mapping.desc
or '' ):find(
'pivi' ,
1 ,
true ) )
133 + assert .is_table( published )
neovim/tests/bugabinga/pivi/editor/guide_spec.lua Modified 5 5 require 'bugabinga.pivi.navigate' 6 6 require 'bugabinga.pivi.detail' 7 7 require 'bugabinga.pivi.diff' 8 + require 'bugabinga.pivi_keys' 8 9 local guide
= require 'bugabinga.pivi.guide' 9 10 local transcript
= require 'bugabinga.pivi.transcript' 10 11 local fake
= dofile 'tests/helpers/pivi_fake.lua' 30 31 described[mapping.keys]
= mapping.what
33 - for _, keys
in ipairs {
'?' ,
'<CR>' ,
']m' ,
'[m' ,
']t' ,
'[t' ,
'gf' ,
'gD' ,
'K' , }
do 35 + for _, keys
in ipairs {
'<CR>' ,
'K' ,
']]' ,
'[[' , }
do 34 36 assert .is_string( described[keys], keys
.. ' is missing from the guide' )
53 55 it(
'explains what each key does, not only that it exists' ,
function ()
54 56 local written
= text_of( guide.lines( bufnr ) )
56 - assert .is_true( written:find(
'collapse or expand' ,
1 ,
true )
~= nil )
57 - assert .is_true( written:find(
'next entry' ,
1 ,
true )
~= nil )
58 - assert .is_true( written:find(
'compare' ,
1 ,
true )
~= nil )
58 + assert .is_true( written:lower():find(
'next entry' ,
1 ,
true )
~= nil )
59 + assert .is_true( written:lower():find(
'compare' ,
1 ,
true )
~= nil )
60 + assert .is_true( written:find(
'za' ,
1 ,
true )
~= nil )
61 63 it(
'shows itself without leaving the transcript' ,
function ()
76 - it(
'leaves a backwards search alone outside pivi' ,
function ()
78 - local ordinary
= vim.api.nvim_get_current_buf()
80 - for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( ordinary,
'n' ) )
do 78 + it(
'leaves a backwards search alone everywhere' ,
function ()
79 + for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr,
'n' ) )
do 81 80 assert .is_not.equal(
'?' , mapping.lhs )
83 82 for _, mapping
in ipairs ( vim.api.nvim_get_keymap
'n' )
do neovim/tests/bugabinga/pivi/editor/navigate_spec.lua Modified 163 163 assert .is_nil( navigate.locate( bufnr, answer.first ) )
166 - it(
'binds going to a location in its own buffers only' ,
function ()
166 + it(
'publishes going to a location as an intent' ,
function ()
168 168 for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr,
'n' ) )
do 169 - bound[mapping.lhs]
= mapping.desc
or '' 169 + if mapping.lhs
== '<Plug>(pivi-goto-location)' then published
= mapping
end 172 - assert .is_string( bound.gf )
173 - assert .is_true( bound.gf:find(
'pivi' ,
1 ,
true )
~= nil )
172 + assert .is_table( published )
232 231 assert .is_nil( navigate.before( empty,
1 ) )
235 - it(
'binds motions in its own buffers without claiming global keys' ,
function ()
234 + it(
'publishes each motion as an intent' ,
function ()
235 + local published
= {}
237 236 for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr,
'n' ) )
do 238 - bound[mapping.lhs]
= true 237 + published[mapping.lhs]
= true 241 - for _, keys
in ipairs {
']m' ,
'[m' ,
']t' ,
'[t' , }
do 242 - assert .is_true( bound[keys], keys
.. ' is not bound in the transcript' )
246 - for _, mapping
in ipairs ( vim.api.nvim_get_keymap
'n' )
do 247 - assert .is_nil( ( mapping.desc
or '' ):find(
'pivi' ,
1 ,
true ) )
240 + for _, intent
in ipairs {
241 + '<Plug>(pivi-next-entry)' ,
'<Plug>(pivi-previous-entry)' ,
242 + '<Plug>(pivi-next-tool)' ,
'<Plug>(pivi-previous-tool)' ,
244 + assert .is_true( published[intent], intent
.. ' is not published' )
neovim/tests/bugabinga/pivi/keys_spec.lua Added new file mode 100644 2 + require 'bugabinga.pivi.fold' 3 + require 'bugabinga.pivi.navigate' 4 + require 'bugabinga.pivi.detail' 5 + require 'bugabinga.pivi.diff' 6 + require 'bugabinga.pivi.guide' 7 + local command
= require 'bugabinga.pivi.command' 8 + local session
= require 'bugabinga.pivi.session' 9 + local transcript
= require 'bugabinga.pivi.transcript' 10 + local fake
= dofile 'tests/helpers/pivi_fake.lua' 12 + local MODES
= {
'n' ,
'i' ,
'x' , }
17 + local ALLOWED
= { [
'/' ] =
true , }
19 + local claimed = function ( bufnr )
21 + for _, mode
in ipairs ( MODES )
do 22 + for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr, mode ) )
do 23 + if not mapping.lhs:find(
'<Plug>' ,
1 ,
true )
and not ALLOWED[mapping.lhs]
then 24 + table .
insert ( found, mode
.. ' ' .. mapping.lhs )
31 + describe(
'pivi keys' ,
function ()
32 + after_each(
function ()
34 + transcript.forget_all()
35 + fake.close_extra_windows()
36 + vim.cmd
'silent! %bwipeout!' 39 + it(
'claims no key of its own in a transcript' ,
function ()
40 + local bufnr
= transcript.ensure
'unclaimed' 42 + assert .same( {}, claimed( bufnr ) )
45 + it(
'claims no key of its own in a prompt, beyond slash-command entry' ,
function ()
46 + local channel
= fake.new()
47 + local current
= session.create {
48 + spawn = channel.spawn,
55 + local bufnr
= command.open_prompt( current )
56 + vim.cmd.stopinsert()
58 + assert .same( {}, claimed( bufnr ) )
61 + it(
'publishes every behavior a key could want' ,
function ()
62 + local bufnr
= transcript.ensure
'published' 63 + local published
= {}
64 + for _, mode
in ipairs ( MODES )
do 65 + for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr, mode ) )
do 66 + published[mapping.lhs]
= true 70 + for _, intent
in ipairs {
71 + '<Plug>(pivi-toggle-entry)' ,
72 + '<Plug>(pivi-next-entry)' ,
73 + '<Plug>(pivi-previous-entry)' ,
74 + '<Plug>(pivi-next-tool)' ,
75 + '<Plug>(pivi-previous-tool)' ,
76 + '<Plug>(pivi-goto-location)' ,
77 + '<Plug>(pivi-inspect-entry)' ,
78 + '<Plug>(pivi-compare-change)' ,
79 + '<Plug>(pivi-guide)' ,
81 + assert .is_true( published[intent], intent
.. ' is not published' )
85 + it(
'never claims a global key' ,
function ()
86 + for _, mode
in ipairs ( MODES )
do 87 + for _, mapping
in ipairs ( vim.api.nvim_get_keymap( mode ) )
do 88 + if not mapping.lhs:find(
'<Plug>' ,
1 ,
true )
then 89 + assert .is_nil( ( mapping.desc
or '' ):find(
'pivi ' ,
1 ,
true ),
90 + mapping.lhs
.. ' was claimed globally by pivi' )
96 + it(
'yields to a completion popup before accepting a prompt' ,
function ()
97 + local channel
= fake.new()
98 + local current
= session.create {
99 + spawn = channel.spawn,
100 + name =
'accepting' ,
106 + local bufnr
= command.open_prompt( current )
107 + vim.cmd.stopinsert()
110 + for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr,
'i' ) )
do 111 + if mapping.lhs
== '<Plug>(pivi-accept)' then accept
= mapping
end 114 + assert .is_table( accept )
115 + assert .equal(
1 , accept.expr )
118 + vim.api.nvim_buf_set_lines( bufnr,
0 ,
- 1 ,
false , {
'a question' , } )
119 + assert .equal(
'' , accept.callback() )