To: vim_dev@googlegroups.com Subject: Patch 9.0.0320 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0320 Problem: Command line type of CmdlineChange differs from getcmdtype(). Solution: Use the same type. (closes #11005) Files: src/ex_getln.c, src/proto/ex_getln.pro, src/testdir/test_cmdline.vim *** ../vim-9.0.0319/src/ex_getln.c 2022-08-29 15:06:46.720715534 +0100 --- src/ex_getln.c 2022-08-29 16:03:06.332094472 +0100 *************** *** 4114,4119 **** --- 4114,4143 ---- } #endif + #if defined(FEAT_EVAL) || defined(FEAT_CMDWIN) + /* + * Get the current command-line type. + * Returns ':' or '/' or '?' or '@' or '>' or '-' + * Only works when the command line is being edited. + * Returns NUL when something is wrong. + */ + static int + get_cmdline_type(void) + { + cmdline_info_T *p = get_ccline_ptr(); + + if (p == NULL) + return NUL; + if (p->cmdfirstc == NUL) + return + # ifdef FEAT_EVAL + (p->input_fn) ? '@' : + # endif + '-'; + return p->cmdfirstc; + } + #endif + #if defined(FEAT_EVAL) || defined(PROTO) /* * Get the current command line in allocated memory. *************** *** 4187,4226 **** { cmdline_info_T *p = get_ccline_ptr(); ! rettv->vval.v_number = 0; ! if (p != NULL) ! rettv->vval.v_number = p->cmdpos + 1; } /* ! * Get the command line cursor screen position. */ ! static int ! get_cmdline_screen_pos(void) { cmdline_info_T *p = get_ccline_ptr(); ! if (p == NULL) ! return -1; ! return p->cmdspos; } /* ! * "getcmdscreenpos()" function */ void ! f_getcmdscreenpos(typval_T *argvars UNUSED, typval_T *rettv) { ! rettv->vval.v_number = get_cmdline_screen_pos() + 1; } // Set the command line str to "str". // Returns 1 when failed, 0 when OK. ! int set_cmdline_str(char_u *str, int pos) { cmdline_info_T *p = get_ccline_ptr(); - int cmdline_type; int len; if (p == NULL) --- 4211,4251 ---- { cmdline_info_T *p = get_ccline_ptr(); ! rettv->vval.v_number = p != NULL ? p->cmdpos + 1 : 0; } /* ! * "getcmdscreenpos()" function */ ! void ! f_getcmdscreenpos(typval_T *argvars UNUSED, typval_T *rettv) { cmdline_info_T *p = get_ccline_ptr(); ! rettv->vval.v_number = p != NULL ? p->cmdspos + 1 : 0; } /* ! * "getcmdtype()" function */ void ! f_getcmdtype(typval_T *argvars UNUSED, typval_T *rettv) { ! rettv->v_type = VAR_STRING; ! rettv->vval.v_string = alloc(2); ! if (rettv->vval.v_string != NULL) ! { ! rettv->vval.v_string[0] = get_cmdline_type(); ! rettv->vval.v_string[1] = NUL; ! } } // Set the command line str to "str". // Returns 1 when failed, 0 when OK. ! static int set_cmdline_str(char_u *str, int pos) { cmdline_info_T *p = get_ccline_ptr(); int len; if (p == NULL) *************** *** 4237,4244 **** redrawcmd(); // Trigger CmdlineChanged autocommands. ! cmdline_type = ccline.cmdfirstc == NUL ? '-' : ccline.cmdfirstc; ! trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED); return 0; } --- 4262,4268 ---- redrawcmd(); // Trigger CmdlineChanged autocommands. ! trigger_cmd_autocmd(get_cmdline_type(), EVENT_CMDLINECHANGED); return 0; } *************** *** 4310,4357 **** } #endif - #if defined(FEAT_EVAL) || defined(FEAT_CMDWIN) - /* - * Get the current command-line type. - * Returns ':' or '/' or '?' or '@' or '>' or '-' - * Only works when the command line is being edited. - * Returns NUL when something is wrong. - */ - static int - get_cmdline_type(void) - { - cmdline_info_T *p = get_ccline_ptr(); - - if (p == NULL) - return NUL; - if (p->cmdfirstc == NUL) - return - # ifdef FEAT_EVAL - (p->input_fn) ? '@' : - # endif - '-'; - return p->cmdfirstc; - } - #endif - - #if defined(FEAT_EVAL) || defined(PROTO) - /* - * "getcmdtype()" function - */ - void - f_getcmdtype(typval_T *argvars UNUSED, typval_T *rettv) - { - rettv->v_type = VAR_STRING; - rettv->vval.v_string = alloc(2); - if (rettv->vval.v_string != NULL) - { - rettv->vval.v_string[0] = get_cmdline_type(); - rettv->vval.v_string[1] = NUL; - } - } - - #endif - /* * Return the first character of the current command line. */ --- 4334,4339 ---- *** ../vim-9.0.0319/src/proto/ex_getln.pro 2022-08-27 12:22:19.975008573 +0100 --- src/proto/ex_getln.pro 2022-08-29 16:08:59.809198844 +0100 *************** *** 34,43 **** void f_getcmdline(typval_T *argvars, typval_T *rettv); void f_getcmdpos(typval_T *argvars, typval_T *rettv); void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv); ! int set_cmdline_str(char_u *str, int pos); void f_setcmdline(typval_T *argvars, typval_T *rettv); void f_setcmdpos(typval_T *argvars, typval_T *rettv); - void f_getcmdtype(typval_T *argvars, typval_T *rettv); int get_cmdline_firstc(void); int get_list_range(char_u **str, int *num1, int *num2); char *check_cedit(void); --- 34,42 ---- void f_getcmdline(typval_T *argvars, typval_T *rettv); void f_getcmdpos(typval_T *argvars, typval_T *rettv); void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv); ! void f_getcmdtype(typval_T *argvars, typval_T *rettv); void f_setcmdline(typval_T *argvars, typval_T *rettv); void f_setcmdpos(typval_T *argvars, typval_T *rettv); int get_cmdline_firstc(void); int get_list_range(char_u **str, int *num1, int *num2); char *check_cedit(void); *** ../vim-9.0.0319/src/testdir/test_cmdline.vim 2022-08-28 17:24:59.775549192 +0100 --- src/testdir/test_cmdline.vim 2022-08-29 16:03:06.332094472 +0100 *************** *** 3264,3272 **** --- 3264,3276 ---- func Test_setcmdline() func SetText(text, pos) + autocmd CmdlineChanged * let g:cmdtype = expand('') call assert_equal(0, setcmdline(a:text)) call assert_equal(a:text, getcmdline()) call assert_equal(len(a:text) + 1, getcmdpos()) + call assert_equal(getcmdtype(), g:cmdtype) + unlet g:cmdtype + autocmd! CmdlineChanged call assert_equal(0, setcmdline(a:text, a:pos)) call assert_equal(a:text, getcmdline()) *************** *** 3282,3287 **** --- 3286,3298 ---- call feedkeys(":\=SetText('set rtp?', 2)\\", 'xt') call assert_equal('set rtp?', @:) + call feedkeys(":let g:str = input('? ')\", 't') + call feedkeys("\=SetText('foo', 4)\\", 'xt') + call assert_equal('foo', g:str) + unlet g:str + + delfunc SetText + " setcmdline() returns 1 when not editing the command line. call assert_equal(1, 'foo'->setcmdline()) *************** *** 3294,3299 **** --- 3305,3312 ---- com! -nargs=* -complete=custom,CustomComplete DoCmd : call feedkeys(":DoCmd \\\"\", 'tx') call assert_equal('"DoCmd January February Mars', @:) + delcom DoCmd + delfunc CustomComplete " Called in cnoremap a setcmdline('let foo=') *** ../vim-9.0.0319/src/version.c 2022-08-29 15:28:49.806415328 +0100 --- src/version.c 2022-08-29 16:04:24.375319577 +0100 *************** *** 709,710 **** --- 709,712 ---- { /* Add new patch number below this line */ + /**/ + 320, /**/ -- Mynd you, m00se bites Kan be pretty nasti ... "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///