comparison src/popupwin.c @ 17225:09fa437d33d8 v8.1.1612

patch 8.1.1612: cannot show an existing buffer in a popup window commit https://github.com/vim/vim/commit/5b8cfedfbd19a71a30c73cf44b0aec3da7fc1a24 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 30 22:16:10 2019 +0200 patch 8.1.1612: cannot show an existing buffer in a popup window Problem: Cannot show an existing buffer in a popup window. Solution: Support buffer number argument in popup_create().
author Bram Moolenaar <Bram@vim.org>
date Sun, 30 Jun 2019 22:30:05 +0200
parents 5169811b3044
children e9ebf3f27af6
comparison
equal deleted inserted replaced
17224:e92df9dfef0f 17225:09fa437d33d8
995 popup_create(typval_T *argvars, typval_T *rettv, create_type_T type) 995 popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
996 { 996 {
997 win_T *wp; 997 win_T *wp;
998 tabpage_T *tp = NULL; 998 tabpage_T *tp = NULL;
999 int tabnr; 999 int tabnr;
1000 buf_T *buf; 1000 int new_buffer;
1001 buf_T *buf = NULL;
1001 dict_T *d; 1002 dict_T *d;
1002 int nr; 1003 int nr;
1003 int i; 1004 int i;
1004 1005
1005 // Check arguments look OK. 1006 // Check arguments look OK.
1006 if (!(argvars[0].v_type == VAR_STRING && argvars[0].vval.v_string != NULL) 1007 if (argvars[0].v_type == VAR_NUMBER)
1007 && !(argvars[0].v_type == VAR_LIST && argvars[0].vval.v_list != NULL)) 1008 {
1009 buf = buflist_findnr( argvars[0].vval.v_number);
1010 if (buf == NULL)
1011 {
1012 semsg(_(e_nobufnr), argvars[0].vval.v_number);
1013 return NULL;
1014 }
1015 }
1016 else if (!(argvars[0].v_type == VAR_STRING
1017 && argvars[0].vval.v_string != NULL)
1018 && !(argvars[0].v_type == VAR_LIST
1019 && argvars[0].vval.v_list != NULL))
1008 { 1020 {
1009 emsg(_(e_listreq)); 1021 emsg(_(e_listreq));
1010 return NULL; 1022 return NULL;
1011 } 1023 }
1012 if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) 1024 if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL)
1036 wp = win_alloc_popup_win(); 1048 wp = win_alloc_popup_win();
1037 if (wp == NULL) 1049 if (wp == NULL)
1038 return NULL; 1050 return NULL;
1039 rettv->vval.v_number = wp->w_id; 1051 rettv->vval.v_number = wp->w_id;
1040 wp->w_popup_pos = POPPOS_TOPLEFT; 1052 wp->w_popup_pos = POPPOS_TOPLEFT;
1041 1053 wp->w_popup_flags = POPF_IS_POPUP;
1042 buf = buflist_new(NULL, NULL, (linenr_T)0, BLN_NEW|BLN_LISTED|BLN_DUMMY); 1054
1043 if (buf == NULL) 1055 if (buf != NULL)
1044 return NULL; 1056 {
1045 ml_open(buf); 1057 // use existing buffer
1046 1058 new_buffer = FALSE;
1047 win_init_popup_win(wp, buf); 1059 wp->w_buffer = buf;
1048 1060 ++buf->b_nwindows;
1049 set_local_options_default(wp); 1061 buffer_ensure_loaded(buf);
1050 set_string_option_direct_in_buf(buf, (char_u *)"buftype", -1, 1062 }
1063 else
1064 {
1065 // create a new buffer associated with the popup
1066 new_buffer = TRUE;
1067 buf = buflist_new(NULL, NULL, (linenr_T)0,
1068 BLN_NEW|BLN_LISTED|BLN_DUMMY);
1069 if (buf == NULL)
1070 return NULL;
1071 ml_open(buf);
1072
1073 win_init_popup_win(wp, buf);
1074
1075 set_local_options_default(wp);
1076 set_string_option_direct_in_buf(buf, (char_u *)"buftype", -1,
1051 (char_u *)"popup", OPT_FREE|OPT_LOCAL, 0); 1077 (char_u *)"popup", OPT_FREE|OPT_LOCAL, 0);
1052 set_string_option_direct_in_buf(buf, (char_u *)"bufhidden", -1, 1078 set_string_option_direct_in_buf(buf, (char_u *)"bufhidden", -1,
1053 (char_u *)"hide", OPT_FREE|OPT_LOCAL, 0); 1079 (char_u *)"hide", OPT_FREE|OPT_LOCAL, 0);
1054 buf->b_p_ul = -1; // no undo 1080 buf->b_p_ul = -1; // no undo
1055 buf->b_p_swf = FALSE; // no swap file 1081 buf->b_p_swf = FALSE; // no swap file
1056 buf->b_p_bl = FALSE; // unlisted buffer 1082 buf->b_p_bl = FALSE; // unlisted buffer
1057 buf->b_locked = TRUE; 1083 buf->b_locked = TRUE;
1058 wp->w_p_wrap = TRUE; // 'wrap' is default on 1084 wp->w_p_wrap = TRUE; // 'wrap' is default on
1059 1085
1060 // Avoid that 'buftype' is reset when this buffer is entered. 1086 // Avoid that 'buftype' is reset when this buffer is entered.
1061 buf->b_p_initialized = TRUE; 1087 buf->b_p_initialized = TRUE;
1088 }
1062 1089
1063 if (tp != NULL) 1090 if (tp != NULL)
1064 { 1091 {
1065 // popup on specified tab page 1092 // popup on specified tab page
1066 wp->w_next = tp->tp_first_popupwin; 1093 wp->w_next = tp->tp_first_popupwin;
1086 prev = prev->w_next; 1113 prev = prev->w_next;
1087 prev->w_next = wp; 1114 prev->w_next = wp;
1088 } 1115 }
1089 } 1116 }
1090 1117
1091 popup_set_buffer_text(buf, argvars[0]); 1118 if (new_buffer)
1119 popup_set_buffer_text(buf, argvars[0]);
1092 1120
1093 if (type == TYPE_ATCURSOR) 1121 if (type == TYPE_ATCURSOR)
1094 { 1122 {
1095 wp->w_popup_pos = POPPOS_BOTLEFT; 1123 wp->w_popup_pos = POPPOS_BOTLEFT;
1096 setcursor_mayforce(TRUE); 1124 setcursor_mayforce(TRUE);
1454 static win_T * 1482 static win_T *
1455 find_popup_win(int id) 1483 find_popup_win(int id)
1456 { 1484 {
1457 win_T *wp = win_id2wp(id); 1485 win_T *wp = win_id2wp(id);
1458 1486
1459 if (wp != NULL && !bt_popup(wp->w_buffer)) 1487 if (wp != NULL && !WIN_IS_POPUP(wp))
1460 { 1488 {
1461 semsg(_("E993: window %d is not a popup window"), id); 1489 semsg(_("E993: window %d is not a popup window"), id);
1462 return NULL; 1490 return NULL;
1463 } 1491 }
1464 return wp; 1492 return wp;
1522 int id = (int)tv_get_number(&argvars[0]); 1550 int id = (int)tv_get_number(&argvars[0]);
1523 win_T *wp = find_popup_win(id); 1551 win_T *wp = find_popup_win(id);
1524 1552
1525 if (wp != NULL) 1553 if (wp != NULL)
1526 { 1554 {
1527 popup_set_buffer_text(wp->w_buffer, argvars[1]); 1555 if (argvars[1].v_type != VAR_STRING && argvars[1].v_type != VAR_LIST)
1528 popup_adjust_position(wp); 1556 semsg(_(e_invarg2), tv_get_string(&argvars[1]));
1557 else
1558 {
1559 popup_set_buffer_text(wp->w_buffer, argvars[1]);
1560 popup_adjust_position(wp);
1561 }
1529 } 1562 }
1530 } 1563 }
1531 1564
1532 static void 1565 static void
1533 popup_free(win_T *wp) 1566 popup_free(win_T *wp)
1878 } 1911 }
1879 1912
1880 int 1913 int
1881 error_if_popup_window() 1914 error_if_popup_window()
1882 { 1915 {
1883 if (bt_popup(curwin->w_buffer)) 1916 if (WIN_IS_POPUP(curwin))
1884 { 1917 {
1885 emsg(_("E994: Not allowed in a popup window")); 1918 emsg(_("E994: Not allowed in a popup window"));
1886 return TRUE; 1919 return TRUE;
1887 } 1920 }
1888 return FALSE; 1921 return FALSE;