• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revisionf0033a10b613a18caa3cbc5735bb8b558ce2ddae (tree)
Zeit2020-02-14 22:45:04
AutorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.0257: cannot recognize a terminal in a popup window

Commit: https://github.com/vim/vim/commit/00f3b4e007af07870168bf044cecc9d544483953
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Feb 14 14:32:22 2020 +0100

patch 8.2.0257: cannot recognize a terminal in a popup window
Problem: Cannot recognize a terminal in a popup window.
Solution: Add the win_gettype() function.

Ändern Zusammenfassung

Diff

diff -r 826264ce48ff -r f0033a10b613 runtime/doc/eval.txt
--- a/runtime/doc/eval.txt Fri Feb 14 13:30:05 2020 +0100
+++ b/runtime/doc/eval.txt Fri Feb 14 14:45:04 2020 +0100
@@ -10328,6 +10328,23 @@
1032810328 Can also be used as a |method|: >
1032910329 GetWinnr()->win_getid()
1033010330
10331+
10332+win_gettype([{nr}]) *win_gettype()*
10333+ Return the type of the window:
10334+ "popup" popup window |popup|
10335+ "command" command-line window |cmdwin|
10336+ (empty) normal window
10337+ "unknown" window {nr} not found
10338+
10339+ When {nr} is omitted return the type of the current window.
10340+ When {nr} is given return the type of this window by number or
10341+ |window-ID|.
10342+
10343+ Also see the 'buftype' option. When running a terminal in a
10344+ popup window then 'buftype' is "terminal" and win_gettype()
10345+ returns "popup".
10346+
10347+
1033110348 win_gotoid({expr}) *win_gotoid()*
1033210349 Go to window with ID {expr}. This may also change the current
1033310350 tabpage.
diff -r 826264ce48ff -r f0033a10b613 src/evalfunc.c
--- a/src/evalfunc.c Fri Feb 14 13:30:05 2020 +0100
+++ b/src/evalfunc.c Fri Feb 14 14:45:04 2020 +0100
@@ -86,7 +86,6 @@
8686 static void f_get(typval_T *argvars, typval_T *rettv);
8787 static void f_getchangelist(typval_T *argvars, typval_T *rettv);
8888 static void f_getcharsearch(typval_T *argvars, typval_T *rettv);
89-static void f_getcmdwintype(typval_T *argvars, typval_T *rettv);
9089 static void f_getenv(typval_T *argvars, typval_T *rettv);
9190 static void f_getfontname(typval_T *argvars, typval_T *rettv);
9291 static void f_getjumplist(typval_T *argvars, typval_T *rettv);
@@ -845,6 +844,7 @@
845844 {"win_execute", 2, 3, FEARG_2, &t_string, f_win_execute},
846845 {"win_findbuf", 1, 1, FEARG_1, &t_list_number, f_win_findbuf},
847846 {"win_getid", 0, 2, FEARG_1, &t_number, f_win_getid},
847+ {"win_gettype", 0, 1, FEARG_1, &t_string, f_win_gettype},
848848 {"win_gotoid", 1, 1, FEARG_1, &t_number, f_win_gotoid},
849849 {"win_id2tabwin", 1, 1, FEARG_1, &t_list_number, f_win_id2tabwin},
850850 {"win_id2win", 1, 1, FEARG_1, &t_number, f_win_id2win},
@@ -2920,24 +2920,6 @@
29202920 }
29212921
29222922 /*
2923- * "getcmdwintype()" function
2924- */
2925- static void
2926-f_getcmdwintype(typval_T *argvars UNUSED, typval_T *rettv)
2927-{
2928- rettv->v_type = VAR_STRING;
2929- rettv->vval.v_string = NULL;
2930-#ifdef FEAT_CMDWIN
2931- rettv->vval.v_string = alloc(2);
2932- if (rettv->vval.v_string != NULL)
2933- {
2934- rettv->vval.v_string[0] = cmdwin_type;
2935- rettv->vval.v_string[1] = NUL;
2936- }
2937-#endif
2938-}
2939-
2940-/*
29412923 * "getenv()" function
29422924 */
29432925 static void
diff -r 826264ce48ff -r f0033a10b613 src/evalwindow.c
--- a/src/evalwindow.c Fri Feb 14 13:30:05 2020 +0100
+++ b/src/evalwindow.c Fri Feb 14 14:45:04 2020 +0100
@@ -840,6 +840,54 @@
840840 }
841841
842842 /*
843+ * "win_gettype(nr)" function
844+ */
845+ void
846+f_win_gettype(typval_T *argvars, typval_T *rettv)
847+{
848+ win_T *wp = curwin;
849+
850+ rettv->v_type = VAR_STRING;
851+ rettv->vval.v_string = NULL;
852+ if (argvars[0].v_type != VAR_UNKNOWN)
853+ {
854+ wp = find_win_by_nr_or_id(&argvars[0]);
855+ if (wp == NULL)
856+ {
857+ rettv->vval.v_string = vim_strsave((char_u *)"unknown");
858+ return;
859+ }
860+ }
861+#ifdef FEAT_PROP_POPUP
862+ if (WIN_IS_POPUP(wp))
863+ rettv->vval.v_string = vim_strsave((char_u *)"popup");
864+ else
865+#endif
866+#ifdef FEAT_CMDWIN
867+ if (wp == curwin && cmdwin_type != 0)
868+ rettv->vval.v_string = vim_strsave((char_u *)"command");
869+#endif
870+}
871+
872+/*
873+ * "getcmdwintype()" function
874+ */
875+ void
876+f_getcmdwintype(typval_T *argvars UNUSED, typval_T *rettv)
877+{
878+ rettv->v_type = VAR_STRING;
879+ rettv->vval.v_string = NULL;
880+#ifdef FEAT_CMDWIN
881+ rettv->vval.v_string = alloc(2);
882+ if (rettv->vval.v_string != NULL)
883+ {
884+ rettv->vval.v_string[0] = cmdwin_type;
885+ rettv->vval.v_string[1] = NUL;
886+ }
887+#endif
888+}
889+
890+/*
843891 * "winbufnr(nr)" function
844892 */
845893 void
diff -r 826264ce48ff -r f0033a10b613 src/proto/evalwindow.pro
--- a/src/proto/evalwindow.pro Fri Feb 14 13:30:05 2020 +0100
+++ b/src/proto/evalwindow.pro Fri Feb 14 14:45:04 2020 +0100
@@ -20,6 +20,8 @@
2020 void f_win_id2win(typval_T *argvars, typval_T *rettv);
2121 void f_win_screenpos(typval_T *argvars, typval_T *rettv);
2222 void f_win_splitmove(typval_T *argvars, typval_T *rettv);
23+void f_win_gettype(typval_T *argvars, typval_T *rettv);
24+void f_getcmdwintype(typval_T *argvars, typval_T *rettv);
2325 void f_winbufnr(typval_T *argvars, typval_T *rettv);
2426 void f_wincol(typval_T *argvars, typval_T *rettv);
2527 void f_winheight(typval_T *argvars, typval_T *rettv);
diff -r 826264ce48ff -r f0033a10b613 src/testdir/dumps/Test_terminal_popup_1.dump
--- a/src/testdir/dumps/Test_terminal_popup_1.dump Fri Feb 14 13:30:05 2020 +0100
+++ b/src/testdir/dumps/Test_terminal_popup_1.dump Fri Feb 14 14:45:04 2020 +0100
@@ -8,8 +8,8 @@
88 |7| @12|║+0#0000001#ffd7ff255|~+0#4040ff13#ffffff0| @43|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13
99 |8| @12|║+0#0000001#ffd7ff255|~+0#4040ff13#ffffff0| @43|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13
1010 |9| @12|║+0#0000001#ffd7ff255|~+0#4040ff13#ffffff0| @43|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13
11-|1|0| @11|║+0#0000001#ffd7ff255|"+0#0000000#ffffff0|X|t|e|x|t|"| |3|L|,| |3|6|C| @11|1|,|1| @10|A|l@1| |║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13
11+|1|0| @11|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@26|1|,|1| @10|A|l@1| |║+0#0000001#ffd7ff255| +0#0000000#ffffff0@13
1212 |1@1| @11|╚+0#0000001#ffd7ff255|═@44|⇲| +0#0000000#ffffff0@13
1313 |1|2| @72
1414 |1|3| @72
15-@57|0|,|0|-|1| @8|A|l@1|
15+|t|e|r|m|i|n|a|l| |p|o|p|u|p| @42|0|,|0|-|1| @8|A|l@1|
diff -r 826264ce48ff -r f0033a10b613 src/testdir/test_cmdline.vim
--- a/src/testdir/test_cmdline.vim Fri Feb 14 13:30:05 2020 +0100
+++ b/src/testdir/test_cmdline.vim Fri Feb 14 14:45:04 2020 +0100
@@ -894,12 +894,14 @@
894894 let g:cmd_wintype = ''
895895 func CmdWinType()
896896 let g:cmd_wintype = getcmdwintype()
897+ let g:wintype = win_gettype()
897898 return ''
898899 endfunc
899900
900901 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
901902 echo input('')
902903 call assert_equal('@', g:cmd_wintype)
904+ call assert_equal('command', g:wintype)
903905
904906 set cedit&vim
905907 delfunc CmdWinType
diff -r 826264ce48ff -r f0033a10b613 src/testdir/test_terminal.vim
--- a/src/testdir/test_terminal.vim Fri Feb 14 13:30:05 2020 +0100
+++ b/src/testdir/test_terminal.vim Fri Feb 14 14:45:04 2020 +0100
@@ -2333,6 +2333,7 @@
23332333 call writefile(text, 'Xtext')
23342334 let cmd = GetVimCommandCleanTerm()
23352335 let lines = [
2336+ \ 'set t_u7=',
23362337 \ 'call setline(1, range(20))',
23372338 \ 'hi PopTerm ctermbg=grey',
23382339 \ 'func OpenTerm(setColor)',
@@ -2346,6 +2347,9 @@
23462347 \ 'func HidePopup()',
23472348 \ ' call popup_hide(s:winid)',
23482349 \ 'endfunc',
2350+ \ 'sleep 10m',
2351+ \ 'redraw',
2352+ \ 'echo getwinvar(s:winid, "&buftype") win_gettype(s:winid)',
23492353 \ ]
23502354 call writefile(lines, 'XtermPopup')
23512355 let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15})
diff -r 826264ce48ff -r f0033a10b613 src/version.c
--- a/src/version.c Fri Feb 14 13:30:05 2020 +0100
+++ b/src/version.c Fri Feb 14 14:45:04 2020 +0100
@@ -743,6 +743,8 @@
743743 static int included_patches[] =
744744 { /* Add new patch number below this line */
745745 /**/
746+ 257,
747+/**/
746748 256,
747749 /**/
748750 255,
Show on old repository browser