To: vim_dev@googlegroups.com Subject: Patch 8.2.1653 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1653 Problem: Expand('') does not include the final line number. Solution: Add the line nuber. (closes #6927) Files: src/vim.h, src/scriptfile.c, src/proto/scriptfile.pro, src/debugger.c, src/ex_docmd.c, src/ex_eval.c, src/message.c, src/testing.c, src/testdir/test_expand_func.vim *** ../vim-8.2.1652/src/vim.h 2020-08-23 14:28:24.107838497 +0200 --- src/vim.h 2020-09-10 19:03:04.040325047 +0200 *************** *** 2097,2104 **** # define USE_PRINTF_FORMAT_ATTRIBUTE #endif ! typedef enum ! { ASSERT_EQUAL, ASSERT_NOTEQUAL, ASSERT_MATCH, --- 2097,2103 ---- # define USE_PRINTF_FORMAT_ATTRIBUTE #endif ! typedef enum { ASSERT_EQUAL, ASSERT_NOTEQUAL, ASSERT_MATCH, *************** *** 2128,2133 **** --- 2127,2139 ---- USEPOPUP_HIDDEN // use info popup initially hidden } use_popup_T; + // Argument for estack_sfile(). + typedef enum { + ESTACK_NONE, + ESTACK_SFILE, + ESTACK_STACK + } estack_arg_T; + // Flags for assignment functions. #define LET_IS_CONST 1 // ":const" #define LET_NO_COMMAND 2 // "var = expr" without ":let" or ":const" *** ../vim-8.2.1652/src/scriptfile.c 2020-08-29 13:39:12.578557657 +0200 --- src/scriptfile.c 2020-09-10 18:53:01.950224042 +0200 *************** *** 111,120 **** /* * Get the current value for in allocated memory. ! * "is_sfile" is TRUE for itself. */ char_u * ! estack_sfile(int is_sfile UNUSED) { estack_T *entry; #ifdef FEAT_EVAL --- 111,120 ---- /* * Get the current value for in allocated memory. ! * "which" is ESTACK_SFILE for and ESTACK_STACK for . */ char_u * ! estack_sfile(estack_arg_T which UNUSED) { estack_T *entry; #ifdef FEAT_EVAL *************** *** 127,133 **** entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; #ifdef FEAT_EVAL ! if (is_sfile && entry->es_type != ETYPE_UFUNC) #endif { if (entry->es_name == NULL) --- 127,133 ---- entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; #ifdef FEAT_EVAL ! if (which == ESTACK_SFILE && entry->es_type != ETYPE_UFUNC) #endif { if (entry->es_name == NULL) *************** *** 144,149 **** --- 144,151 ---- entry = ((estack_T *)exestack.ga_data) + idx; if (entry->es_name != NULL) { + long lnum = 0; + len = STRLEN(entry->es_name) + 15; type_name = ""; if (entry->es_type != last_type) *************** *** 159,173 **** len += STRLEN(type_name); if (ga_grow(&ga, (int)len) == FAIL) break; ! if (idx == exestack.ga_len - 1 || entry->es_lnum == 0) ! // For the bottom entry: do not add the line number, it is used ! // in . Also leave it out when the number is not set. vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s%s", type_name, entry->es_name, idx == exestack.ga_len - 1 ? "" : ".."); else vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s[%ld]..", ! type_name, entry->es_name, entry->es_lnum); ga.ga_len += (int)STRLEN((char *)ga.ga_data + ga.ga_len); } } --- 161,180 ---- len += STRLEN(type_name); if (ga_grow(&ga, (int)len) == FAIL) break; ! if (idx == exestack.ga_len - 1) ! lnum = which == ESTACK_STACK ? SOURCING_LNUM : 0; ! else ! lnum = entry->es_lnum; ! if (lnum == 0) ! // For the bottom entry of : do not add the line number, ! // it is used in . Also leave it out when the number is ! // not set. vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s%s", type_name, entry->es_name, idx == exestack.ga_len - 1 ? "" : ".."); else vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s[%ld]..", ! type_name, entry->es_name, lnum); ga.ga_len += (int)STRLEN((char *)ga.ga_data + ga.ga_len); } } *** ../vim-8.2.1652/src/proto/scriptfile.pro 2020-08-20 15:02:38.536534973 +0200 --- src/proto/scriptfile.pro 2020-09-10 18:54:17.113989660 +0200 *************** *** 4,10 **** estack_T *estack_push_ufunc(ufunc_T *ufunc, long lnum); int estack_top_is_ufunc(ufunc_T *ufunc, long lnum); estack_T *estack_pop(void); ! char_u *estack_sfile(int is_sfile); void ex_runtime(exarg_T *eap); int do_in_path(char_u *path, char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie); int do_in_runtimepath(char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie); --- 4,10 ---- estack_T *estack_push_ufunc(ufunc_T *ufunc, long lnum); int estack_top_is_ufunc(ufunc_T *ufunc, long lnum); estack_T *estack_pop(void); ! char_u *estack_sfile(estack_arg_T which); void ex_runtime(exarg_T *eap); int do_in_path(char_u *path, char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie); int do_in_runtimepath(char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie); *** ../vim-8.2.1652/src/debugger.c 2020-07-26 15:36:12.963172976 +0200 --- src/debugger.c 2020-09-10 18:50:25.054709380 +0200 *************** *** 105,111 **** vim_free(debug_newval); debug_newval = NULL; } ! sname = estack_sfile(FALSE); if (sname != NULL) msg((char *)sname); vim_free(sname); --- 105,111 ---- vim_free(debug_newval); debug_newval = NULL; } ! sname = estack_sfile(ESTACK_NONE); if (sname != NULL) msg((char *)sname); vim_free(sname); *************** *** 344,350 **** } else { ! char_u *sname = estack_sfile(FALSE); int max = get_maxbacktrace_level(sname); if (debug_backtrace_level > max) --- 344,350 ---- } else { ! char_u *sname = estack_sfile(ESTACK_NONE); int max = get_maxbacktrace_level(sname); if (debug_backtrace_level > max) *************** *** 365,371 **** int i = 0; int max; ! sname = estack_sfile(FALSE); max = get_maxbacktrace_level(sname); if (sname != NULL) { --- 365,371 ---- int i = 0; int max; ! sname = estack_sfile(ESTACK_NONE); max = get_maxbacktrace_level(sname); if (sname != NULL) { *** ../vim-8.2.1652/src/ex_docmd.c 2020-09-08 22:45:31.113504961 +0200 --- src/ex_docmd.c 2020-09-10 18:51:05.982583357 +0200 *************** *** 8389,8394 **** --- 8389,8395 ---- * '' to C-expression under the cursor * '' to path name under the cursor * '' to sourced file name + * '' to call stack * '' to sourced file line number * '' to file name for autocommand * '' to buffer number for autocommand *************** *** 8606,8612 **** case SPEC_SFILE: // file name for ":so" command case SPEC_STACK: // call stack ! result = estack_sfile(spec_idx == SPEC_SFILE); if (result == NULL) { *errormsg = spec_idx == SPEC_SFILE --- 8607,8614 ---- case SPEC_SFILE: // file name for ":so" command case SPEC_STACK: // call stack ! result = estack_sfile(spec_idx == SPEC_SFILE ! ? ESTACK_SFILE : ESTACK_STACK); if (result == NULL) { *errormsg = spec_idx == SPEC_SFILE *** ../vim-8.2.1652/src/ex_eval.c 2020-07-26 15:36:12.963172976 +0200 --- src/ex_eval.c 2020-09-10 18:51:35.098493433 +0200 *************** *** 290,296 **** // Get the source name and lnum now, it may change before // reaching do_errthrow(). ! elem->sfile = estack_sfile(FALSE); elem->slnum = SOURCING_LNUM; } } --- 290,296 ---- // Get the source name and lnum now, it may change before // reaching do_errthrow(). ! elem->sfile = estack_sfile(ESTACK_NONE); elem->slnum = SOURCING_LNUM; } } *************** *** 549,555 **** } else { ! excp->throw_name = estack_sfile(FALSE); if (excp->throw_name == NULL) excp->throw_name = vim_strsave((char_u *)""); if (excp->throw_name == NULL) --- 549,555 ---- } else { ! excp->throw_name = estack_sfile(ESTACK_NONE); if (excp->throw_name == NULL) excp->throw_name = vim_strsave((char_u *)""); if (excp->throw_name == NULL) *** ../vim-8.2.1652/src/message.c 2020-09-06 21:47:39.323041533 +0200 --- src/message.c 2020-09-10 18:51:46.818457177 +0200 *************** *** 461,467 **** if (SOURCING_NAME != NULL && other_sourcing_name()) { ! char_u *sname = estack_sfile(FALSE); char_u *tofree = sname; if (sname == NULL) --- 461,467 ---- if (SOURCING_NAME != NULL && other_sourcing_name()) { ! char_u *sname = estack_sfile(ESTACK_NONE); char_u *tofree = sname; if (sname == NULL) *** ../vim-8.2.1652/src/testing.c 2020-09-06 22:26:53.418275627 +0200 --- src/testing.c 2020-09-10 18:53:11.318194891 +0200 *************** *** 22,28 **** prepare_assert_error(garray_T *gap) { char buf[NUMBUFLEN]; ! char_u *sname = estack_sfile(FALSE); ga_init2(gap, 1, 100); if (sname != NULL) --- 22,28 ---- prepare_assert_error(garray_T *gap) { char buf[NUMBUFLEN]; ! char_u *sname = estack_sfile(ESTACK_NONE); ga_init2(gap, 1, 100); if (sname != NULL) *** ../vim-8.2.1652/src/testdir/test_expand_func.vim 2020-08-01 20:45:06.928096141 +0200 --- src/testdir/test_expand_func.vim 2020-09-10 19:14:29.402134650 +0200 *************** *** 39,47 **** func Test_expand_sfile_and_stack() call assert_match('test_expand_func\.vim$', s:sfile) ! let expected = 'script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack$' ! call assert_match(expected , expand('')) ! call assert_match(expected , expand('')) " Call in script-local function call assert_match('script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack\[7\]\.\.\d\+_expand_sfile$', s:expand_sfile()) --- 39,47 ---- func Test_expand_sfile_and_stack() call assert_match('test_expand_func\.vim$', s:sfile) ! let expected = 'script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack' ! call assert_match(expected .. '$', expand('')) ! call assert_match(expected .. '\[4\]' , expand('')) " Call in script-local function call assert_match('script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack\[7\]\.\.\d\+_expand_sfile$', s:expand_sfile()) *************** *** 53,63 **** " Use from sourced script. let lines =<< trim END let g:stack_value = expand('') END call writefile(lines, 'Xstack') source Xstack ! call assert_match('\ from sourced script. let lines =<< trim END + " comment here let g:stack_value = expand('') END call writefile(lines, 'Xstack') source Xstack ! call assert_match('\