mirror of
https://github.com/neovim/neovim.git
synced 2026-07-30 04:18:02 +00:00
feat(cmdwin): implement cmdwin as a normal buf+win
Problem:
cmdwin (the `:q` cmdline buffer) has various limitations which require
special-casing all over the codebase.
Besides complicating the code, it also breaks async plugins if they try
to create buffers/windows after some work is done, if the user happens
to open cmdwin at the wrong the moment:
Lua callback: …/guh.nvim/lua/guh/util.lua:531:
E11: Invalid in command-line window; <CR> executes, CTRL-C quits
stack traceback:
[C]: in function 'nvim_buf_delete'
…/guh.nvim/lua/guh/util.lua:531: in function <…/guh.nvim/lua/guh/util.lua:526>
Solution:
Just say no to "inception". Reimplement cmdwin as a normal buffer+window.
All of the cmdwin contortions (in both core, and innocent plugins) exist
literally only to support "inception": recursive
cmdwin-in-cmdline-things, like `<c-r>=`, `/`, search-during-substitute,
`:input()`, etc. So we just won't support that (though I have
a potential plan for that later, which I call "modal parking lot").
The benefit is that plugins, and core, no longer have to care about
cmdwin.
BONUS:
- mouse-drag on vertical separators works (it only worked for
horizontal/statusline before)
- inccommand-in-cmdwin now works correctly, for free (thus don't need
#40077).
POTENTIAL FOLLOWUPS
- Drop `CHECK_CMDWIN` ("E11: Invalid in command-line window"), allow chaos.
- Unify `BUFLOCK_OK` / `LOCK_OK` ?
DESIGN:
- Eliminate lots of C globals, `EX_CMDWIN`, etc.
- `text_locked()` no longer reports true for cmdwin.
- cmdwin = a normal window with 'winfixbuf', 'bufhidden=wipe',
'buftype=nofile'. Invariants come from those options rather than
special cases throughout the codebase.
- `nv_record` for q:/q//q? calls Lua
`nlua_call_vimfn("vim._core.cmdwin", …)`. No `K_CMDWIN`
/ cmdline-reader detour.
- `cedit_key` (`c_CTRL-F`) schedules a deferred event that calls
`vim._core.cmdwin.open(type, content, pos)` and returns `Ctrl_C` so
the in-flight cmdline cancels. Reader state is not serialized; instead
the captured `(type, line, col)` is replayed via
`nvim_feedkeys(type..line.."<CR>", "nt", …)` after user confirms.
- On confirm/cancel: `<CR>` / `<C-C>` calls into Lua which closes the
window and re-feeds the cmdline.
BREAKING CHANGES:
- Expression-register cmdline (`<C-R>=` from insert-mode) no longer
supports cmdwin. Same applies to `input()` / `inputlist()` (already
covered by `text_locked`).
- Usage of cmdwin in macros/mappings will probably break (assuming they
ever worked).
This commit is contained in:
10
runtime/lua/vim/_meta/api.gen.lua
generated
10
runtime/lua/vim/_meta/api.gen.lua
generated
@@ -24,6 +24,14 @@ function vim.api.nvim__buf_debug_extmarks(buf, keys, dot) end
|
||||
--- @return table<string,any>
|
||||
function vim.api.nvim__buf_stats(buf) end
|
||||
|
||||
--- WARNING: This feature is experimental/unstable.
|
||||
---
|
||||
--- Records the cmdwin scratchbuf and type, or clears both when type="" / buf=0. Internal use only.
|
||||
---
|
||||
--- @param type string ':', '/', '?' (first char only); empty to clear.
|
||||
--- @param buf integer cmdwin buffer id, or 0 to clear.
|
||||
function vim.api.nvim__cmdwin_set(type, buf) end
|
||||
|
||||
--- WARNING: This feature is experimental/unstable.
|
||||
---
|
||||
--- Sets info for the completion item at the given index. If the info text was shown in a window,
|
||||
@@ -967,12 +975,10 @@ function vim.api.nvim_create_autocmd(event, opts) end
|
||||
|
||||
--- Creates a new, empty, unnamed buffer.
|
||||
---
|
||||
--- @see buf_open_scratch
|
||||
--- @param listed boolean Sets 'buflisted'
|
||||
--- @param scratch boolean Creates a "throwaway" `scratch-buffer` for temporary work
|
||||
--- (always 'nomodified'). Also sets 'nomodeline' on the buffer.
|
||||
--- @return integer # Buffer id, or 0 on error
|
||||
---
|
||||
function vim.api.nvim_create_buf(listed, scratch) end
|
||||
|
||||
--- Creates a new namespace or gets an existing one. [namespace]()
|
||||
|
||||
Reference in New Issue
Block a user