From b03e790cddd19b57fa91f4fbfcc30c28f3c173bf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 17 Dec 2024 11:34:30 +0800 Subject: vim-patch:9.1.0934: hard to view an existing buffer in the preview window (#31605) Problem: hard to view an existing buffer in the preview window Solution: add the :pbuffer command (Yinzuo Jiang) Similar as `:pedit` and `:buffer` command. `:pbuffer` edits buffer [N] from the buffer list in the preview window. `:pbuffer` can also open special buffer, for example terminal buffer. closes: vim/vim#16222 https://github.com/vim/vim/commit/a2a2fe841ed2efdbb1f8055f752a3a4d0988ae9d Cherry-pick Test_popup_and_previewwindow_dump() changes from patch 9.0.0625. Cherry-pick Run_noroom_for_newwindow_test() changes from patches 8.2.0432 and 9.0.0363. Co-authored-by: Yinzuo Jiang --- src/nvim/ex_cmds.lua | 6 ++++++ src/nvim/ex_docmd.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua index c8574c805c..0cdc397e9c 100644 --- a/src/nvim/ex_cmds.lua +++ b/src/nvim/ex_cmds.lua @@ -1946,6 +1946,12 @@ M.cmds = { addr_type = 'ADDR_NONE', func = 'ex_packloadall', }, + { + command = 'pbuffer', + flags = bit.bor(BANG, RANGE, BUFNAME, BUFUNL, COUNT, EXTRA, CMDARG, TRLBAR), + addr_type = 'ADDR_BUFFERS', + func = 'ex_pbuffer', + }, { command = 'pclose', flags = bit.bor(BANG, TRLBAR), diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index b32a8b867f..052bf3b9f7 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -4501,6 +4501,12 @@ static void ex_bunload(exarg_T *eap) /// :[N]buffer [N] to buffer N /// :[N]sbuffer [N] to buffer N static void ex_buffer(exarg_T *eap) +{ + do_exbuffer(eap); +} + +/// ":buffer" command and alike. +static void do_exbuffer(exarg_T *eap) { if (*eap->arg) { eap->errmsg = ex_errmsg(e_trailing_arg, eap->arg); @@ -7002,14 +7008,35 @@ static void ex_ptag(exarg_T *eap) static void ex_pedit(exarg_T *eap) { win_T *curwin_save = curwin; + prepare_preview_window(); + + // Edit the file. + do_exedit(eap, NULL); + + back_to_current_window(curwin_save); +} + +/// ":pbuffer" +static void ex_pbuffer(exarg_T *eap) +{ + win_T *curwin_save = curwin; + prepare_preview_window(); + + // Go to the buffer. + do_exbuffer(eap); + back_to_current_window(curwin_save); +} + +static void prepare_preview_window(void) +{ // Open the preview window or popup and make it the current window. g_do_tagpreview = (int)p_pvh; prepare_tagpreview(true); +} - // Edit the file. - do_exedit(eap, NULL); - +static void back_to_current_window(win_T *curwin_save) +{ if (curwin != curwin_save && win_valid(curwin_save)) { // Return cursor to where we were validate_cursor(curwin); -- cgit