]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.1.1418: win_execute() is not implemented yet v8.1.1418
authorBram Moolenaar <Bram@vim.org>
Wed, 29 May 2019 19:44:40 +0000 (21:44 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 29 May 2019 19:44:40 +0000 (21:44 +0200)
Problem:    Win_execute() is not implemented yet.
Solution:   Implement it.

runtime/doc/eval.txt
runtime/doc/popup.txt
src/evalfunc.c
src/popupwin.c
src/testdir/test_execute_func.vim
src/version.c

index 15ffed343bf8ce9d8b6dd33d0f1408ae724f0467..f3aab923e31f9d38d112fd85348bb31388160547 100644 (file)
@@ -2739,6 +2739,8 @@ values({dict})                    List    values in {dict}
 virtcol({expr})                        Number  screen column of cursor or mark
 visualmode([expr])             String  last visual mode used
 wildmenumode()                 Number  whether 'wildmenu' mode is active
+win_execute({id}, {command} [, {silent}])
+                               String  execute {command} in window {id}
 win_findbuf({bufnr})           List    find windows containing {bufnr}
 win_getid([{win} [, {tab}]])   Number  get window ID for {win} in {tab}
 win_gotoid({expr})             Number  go to window with ID {expr}
@@ -4012,7 +4014,10 @@ execute({command} [, {silent}])                                  *execute()*
                To get a list of lines use |split()| on the result: >
                        split(execute('args'), "\n")
 
-<              When used recursively the output of the recursive call is not
+<              To execute a command in another window than the current one
+               use `win_execute()`.
+
+               When used recursively the output of the recursive call is not
                included in the output of the higher level call.
 
 exepath({expr})                                                *exepath()*
@@ -10310,6 +10315,12 @@ wildmenumode()                                 *wildmenumode()*
 <
                (Note, this needs the 'wildcharm' option set appropriately).
 
+win_execute({id}, {command} [, {silent}])              *win_execute()*
+               Like `execute()` but in the context of window {id}.
+               The window will temporarily be made the current window,
+               without triggering autocommands.
+               Example: >
+                       call win_execute(winid, 'syntax enable')
 
 win_findbuf({bufnr})                                   *win_findbuf()*
                Returns a list with |window-ID|s for windows that contain
index 1954754548ec6a58d8ca93a6987bafd4a20a1497..c573e773903864707053b3748798b72cd96a5c91 100644 (file)
@@ -70,6 +70,7 @@ By default the 'wrap' option is set, so that no text disappears.  However, if
 there is not enough space, some text may be invisible.
 
 
+
 TODO:
 
 Example how to use syntax highlighting of a code snippet.
@@ -242,14 +243,6 @@ popup_getposition({id})                                    *popup_getposition()*
                positioning mechanism applied.
                If popup window {id} is not found an empty Dict is returned.
 
-win_execute({id}, {command})
-               {not implemented yet}
-               Like `execute()` but in the context of window {id}.
-               The window will temporarily be made the current window,
-               without triggering autocommands.
-               Example: >
-                       call win_execute(winid, 'syntax enable')
-<
 
                                                        *:popupclear* *:popupc*
 :popupc[lear]  Emergency solution to a misbehaving plugin: close all popup
@@ -274,6 +267,10 @@ better leave them alone.
 
 The window does have a cursor position, but the cursor is not displayed.
 
+To execute a command in the context of the popup window and buffer use
+`win_execute()`.  Example: >
+       call win_execute(winid, 'syntax enable')
+
 Options can be set on the window with `setwinvar()`, e.g.: >
        call setwinvar(winid, '&wrap', 0)
 And options can be set on the buffer with `setbufvar()`, e.g.: >
index 1a0e113b16583e03cec18cd9e26bc50d14fdbbde..2abbcfe4a005274b41c0b4686c9b8bd7bcd2abfe 100644 (file)
@@ -492,6 +492,7 @@ static void f_values(typval_T *argvars, typval_T *rettv);
 static void f_virtcol(typval_T *argvars, typval_T *rettv);
 static void f_visualmode(typval_T *argvars, typval_T *rettv);
 static void f_wildmenumode(typval_T *argvars, typval_T *rettv);
+static void f_win_execute(typval_T *argvars, typval_T *rettv);
 static void f_win_findbuf(typval_T *argvars, typval_T *rettv);
 static void f_win_getid(typval_T *argvars, typval_T *rettv);
 static void f_win_gotoid(typval_T *argvars, typval_T *rettv);
@@ -1045,6 +1046,7 @@ static struct fst
     {"virtcol",                1, 1, f_virtcol},
     {"visualmode",     0, 1, f_visualmode},
     {"wildmenumode",   0, 0, f_wildmenumode},
+    {"win_execute",    2, 3, f_win_execute},
     {"win_findbuf",    1, 1, f_win_findbuf},
     {"win_getid",      0, 2, f_win_getid},
     {"win_gotoid",     1, 1, f_win_gotoid},
@@ -3519,7 +3521,7 @@ get_list_line(
  * "execute()" function
  */
     static void
-f_execute(typval_T *argvars, typval_T *rettv)
+execute_common(typval_T *argvars, typval_T *rettv, int arg_off)
 {
     char_u     *cmd = NULL;
     list_T     *list = NULL;
@@ -3535,9 +3537,9 @@ f_execute(typval_T *argvars, typval_T *rettv)
     rettv->vval.v_string = NULL;
     rettv->v_type = VAR_STRING;
 
-    if (argvars[0].v_type == VAR_LIST)
+    if (argvars[arg_off].v_type == VAR_LIST)
     {
-       list = argvars[0].vval.v_list;
+       list = argvars[arg_off].vval.v_list;
        if (list == NULL || list->lv_first == NULL)
            /* empty list, no commands, empty output */
            return;
@@ -3545,15 +3547,15 @@ f_execute(typval_T *argvars, typval_T *rettv)
     }
     else
     {
-       cmd = tv_get_string_chk(&argvars[0]);
+       cmd = tv_get_string_chk(&argvars[arg_off]);
        if (cmd == NULL)
            return;
     }
 
-    if (argvars[1].v_type != VAR_UNKNOWN)
+    if (argvars[arg_off + 1].v_type != VAR_UNKNOWN)
     {
        char_u  buf[NUMBUFLEN];
-       char_u  *s = tv_get_string_buf_chk(&argvars[1], buf);
+       char_u  *s = tv_get_string_buf_chk(&argvars[arg_off + 1], buf);
 
        if (s == NULL)
            return;
@@ -3620,6 +3622,15 @@ f_execute(typval_T *argvars, typval_T *rettv)
        msg_col = save_msg_col;
 }
 
+/*
+ * "execute()" function
+ */
+    static void
+f_execute(typval_T *argvars, typval_T *rettv)
+{
+    execute_common(argvars, rettv, 0);
+}
+
 /*
  * "exepath()" function
  */
@@ -6096,6 +6107,30 @@ f_getwininfo(typval_T *argvars, typval_T *rettv)
     }
 }
 
+/*
+ * "win_execute()" function
+ */
+    static void
+f_win_execute(typval_T *argvars, typval_T *rettv)
+{
+    int                id = (int)tv_get_number(argvars);
+    win_T      *wp = win_id2wp(id);
+    win_T      *save_curwin = curwin;
+
+    if (wp != NULL)
+    {
+       curwin = wp;
+       curbuf = curwin->w_buffer;
+       check_cursor();
+       execute_common(argvars, rettv, 1);
+       if (win_valid(save_curwin))
+       {
+           curwin = save_curwin;
+           curbuf = curwin->w_buffer;
+       }
+    }
+}
+
 /*
  * "win_findbuf()" function
  */
index 82ef27a1a951b543a802779c1f22e5eae057073f..5853c7b3b320dfa03edca31f55a926373e4d9dc6 100644 (file)
@@ -238,6 +238,7 @@ f_popup_create(typval_T *argvars, typval_T *rettv)
     buf->b_p_ul = -1;      // no undo
     buf->b_p_swf = FALSE;   // no swap file
     buf->b_p_bl = FALSE;    // unlisted buffer
+    buf->b_locked = TRUE;
 
     win_init_popup_win(wp, buf);
 
@@ -376,6 +377,7 @@ f_popup_show(typval_T *argvars, typval_T *rettv UNUSED)
     static void
 popup_free(win_T *wp)
 {
+    wp->w_buffer->b_locked = FALSE;
     if (wp->w_winrow + wp->w_height >= cmdline_row)
        clear_cmdline = TRUE;
     win_free_popup(wp);
index b84fbebe5cbc66d0ab570b222385eb8fa0dad585..78561b3a9b3f60a5e35af03c3d5f910ad85355dc 100644 (file)
@@ -78,3 +78,27 @@ func Test_execute_not_silent()
   endfor
   call assert_equal('xyz ', text2)
 endfunc
+
+func Test_win_execute()
+  let thiswin = win_getid()
+  new
+  let otherwin = win_getid()
+  call setline(1, 'the new window')
+  call win_gotoid(thiswin)
+  let line = win_execute(otherwin, 'echo getline(1)')
+  call assert_match('the new window', line)
+
+  if has('textprop')
+    let popupwin = popup_create('the popup win', {'line': 2, 'col': 3})
+    redraw
+    let line = win_execute(popupwin, 'echo getline(1)')
+    call assert_match('the popup win', line)
+
+    call assert_fails('call win_execute(popupwin, "bwipe!")', 'E937:')
+
+    call popup_close(popupwin)
+  endif
+
+  call win_gotoid(otherwin)
+  bwipe!
+endfunc
index 38b51f79e18bca5303e06a55d4ec833f66ed5027..511b28b5f0bda4b93cb22da1c415eb45355019da 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1418,
 /**/
     1417,
 /**/