From a953b5cf4f291875b805262eebd361e502de8c92 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Thu, 10 Sep 2020 14:25:25 +0200 Subject: [PATCH 01/50] patch 8.2.1652: cannot translate lines in the options window Problem: Cannot translate lines in the options window. Solution: Use the AddOption() function to split descriptions where indicated by a line break. (issue #6800) --- runtime/optwin.vim | 64 ++++++++++++++++++++++++++-------------------- src/version.c | 2 ++ 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/runtime/optwin.vim b/runtime/optwin.vim index dd3a1e515e..ab8d35cbdb 100644 --- a/runtime/optwin.vim +++ b/runtime/optwin.vim @@ -1,7 +1,7 @@ " These commands create the option window. " " Maintainer: Bram Moolenaar -" Last Change: 2020 aug 30 +" Last Change: 2020 Sep 10 " If there already is an option window, jump to that one. let buf = bufnr('option-window') @@ -20,7 +20,7 @@ let s:cpo_save = &cpo set cpo&vim " function to be called when is hit in the option-window -fun! CR() +func CR() " If on a continued comment line, go back to the first comment line let lnum = search("^[^\t]", 'bWcn') @@ -47,10 +47,10 @@ fun! CR() elseif match(line, '^ \=[0-9]') >= 0 exe "norm! /" . line . "\zt" endif -endfun +endfunc " function to be called when is hit in the option-window -fun! Space() +func Space() let lnum = line(".") let line = getline(lnum) @@ -67,14 +67,14 @@ fun! Space() endif endif -endfun +endfunc let s:local_to_window = gettext('(local to window)') let s:local_to_buffer = gettext('(local to buffer)') " find the window in which the option applies " returns 0 for global option, 1 for local option, -1 for error -fun! Find(lnum) +func Find(lnum) let line = getline(a:lnum - 1) if line =~ s:local_to_window || line =~ s:local_to_buffer let local = 1 @@ -95,10 +95,10 @@ fun! Find(lnum) let local = -1 endif return local -endfun +endfunc " Update a "set" line in the option window -fun! Update(lnum, line, local, thiswin) +func Update(lnum, line, local, thiswin) " get the new value of the option and update the option window line if match(a:line, "=") >= 0 let name = substitute(a:line, '^ \tset \([^=]*\)=.*', '\1', "") @@ -123,7 +123,7 @@ fun! Update(lnum, line, local, thiswin) endif endif set nomodified -endfun +endfunc " Reset 'title' and 'icon' to make it work faster. " Reset 'undolevels' to avoid undo'ing until the buffer is empty. @@ -159,35 +159,45 @@ call append(6, gettext('" Hit on a "set" line to refresh it.')) " These functions are called often below. Keep them fast! +" Add an option name and explanation. The text can contain "\n" characters +" where a line break is to be inserted. +func AddOption(name, text) + let lines = split(a:text, "\n") + call append("$", a:name .. "\t" .. lines[0]) + for line in lines[1:] + call append("$", "\t" .. line) + endfor +endfunc + " Init a local binary option -fun! BinOptionL(name) +func BinOptionL(name) let val = getwinvar(winnr('#'), '&' . a:name) call append("$", substitute(substitute(" \tset " . val . a:name . "\t" . \!val . a:name, "0", "no", ""), "1", "", "")) -endfun +endfunc " Init a global binary option -fun! BinOptionG(name, val) +func BinOptionG(name, val) call append("$", substitute(substitute(" \tset " . a:val . a:name . "\t" . \!a:val . a:name, "0", "no", ""), "1", "", "")) -endfun +endfunc " Init a local string option -fun! OptionL(name) +func OptionL(name) let val = escape(getwinvar(winnr('#'), '&' . a:name), " \t\\\"|") call append("$", " \tset " . a:name . "=" . val) -endfun +endfunc " Init a global string option -fun! OptionG(name, val) +func OptionG(name, val) call append("$", " \tset " . a:name . "=" . escape(a:val, " \t\\\"|")) -endfun +endfunc let s:idx = 1 let s:lnum = line("$") call append("$", "") -fun! Header(text) +func Header(text) let line = s:idx . " " . a:text if s:idx < 10 let line = " " . line @@ -198,15 +208,15 @@ fun! Header(text) call append(s:lnum, line) let s:idx = s:idx + 1 let s:lnum = s:lnum + 1 -endfun +endfunc " Get the value of 'pastetoggle'. It could be a special key. -fun! PTvalue() +func PTvalue() redir @a silent set pt redir END return substitute(@a, '[^=]*=\(.*\)', '\1', "") -endfun +endfunc " Restore the previous value of 'cpoptions' here, it's used below. let &cpo = s:cpo_save @@ -240,8 +250,7 @@ call OptionG("hf", &hf) call Header("moving around, searching and patterns") call append("$", "whichwrap\tlist of flags specifying which commands wrap to another line") call OptionG("ww", &ww) -call append("$", "startofline\tmany jump commands move the cursor to the first non-blank") -call append("$", "\tcharacter of a line") +call AddOption("startofline", gettext("many jump commands move the cursor to the first non-blank\ncharacter of a line")) call BinOptionG("sol", &sol) call append("$", "paragraphs\tnroff macro names that separate paragraphs") call OptionG("para", ¶) @@ -286,15 +295,14 @@ endif call Header("tags") -call append("$", "tagbsearch\tuse binary searching in tags files") +call AddOption("tagbsearch", gettext("use binary searching in tags files")) call BinOptionG("tbs", &tbs) call append("$", "taglength\tnumber of significant characters in a tag name or zero") call append("$", " \tset tl=" . &tl) call append("$", "tags\tlist of file names to search for tags") call append("$", "\t(global or local to buffer)") call OptionG("tag", &tag) -call append("$", "tagcase\thow to handle case when searching in tags files:") -call append("$", "\t\"followic\" to follow 'ignorecase', \"ignore\" or \"match\"") +call AddOption("tagcase", gettext("how to handle case when searching in tags files:\n\"followic\" to follow 'ignorecase', \"ignore\" or \"match\"")) call append("$", "\t(global or local to buffer)") call OptionG("tc", &tc) call append("$", "tagrelative\tfile names in a tags file are relative to the tags file") @@ -1446,7 +1454,7 @@ augroup optwin \ call unload() | delfun unload augroup END -fun! unload() +func unload() delfun CR delfun Space delfun Find @@ -1457,7 +1465,7 @@ fun! unload() delfun BinOptionG delfun Header au! optwin -endfun +endfunc " Restore the previous value of 'title' and 'icon'. let &title = s:old_title diff --git a/src/version.c b/src/version.c index 10366426cb..9159209f38 100644 --- a/src/version.c +++ b/src/version.c @@ -750,6 +750,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1652, /**/ 1651, /**/ From 4f25b1aba050b85fa97ca2316aa04dd4b0b22530 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Thu, 10 Sep 2020 19:25:05 +0200 Subject: [PATCH 02/50] patch 8.2.1653: expand('') does not include the final line number Problem: Expand('') does not include the final line number. Solution: Add the line nuber. (closes #6927) --- src/debugger.c | 6 +++--- src/ex_docmd.c | 4 +++- src/ex_eval.c | 4 ++-- src/message.c | 2 +- src/proto/scriptfile.pro | 2 +- src/scriptfile.c | 21 ++++++++++++++------- src/testdir/test_expand_func.vim | 9 +++++---- src/testing.c | 2 +- src/version.c | 2 ++ src/vim.h | 10 ++++++++-- 10 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/debugger.c b/src/debugger.c index 00fb9c8f8b..f745761f10 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -105,7 +105,7 @@ do_debug(char_u *cmd) vim_free(debug_newval); debug_newval = NULL; } - sname = estack_sfile(FALSE); + sname = estack_sfile(ESTACK_NONE); if (sname != NULL) msg((char *)sname); vim_free(sname); @@ -344,7 +344,7 @@ do_checkbacktracelevel(void) } else { - char_u *sname = estack_sfile(FALSE); + char_u *sname = estack_sfile(ESTACK_NONE); int max = get_maxbacktrace_level(sname); if (debug_backtrace_level > max) @@ -365,7 +365,7 @@ do_showbacktrace(char_u *cmd) int i = 0; int max; - sname = estack_sfile(FALSE); + sname = estack_sfile(ESTACK_NONE); max = get_maxbacktrace_level(sname); if (sname != NULL) { diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 1d3cfcdcd0..6495db6e83 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -8389,6 +8389,7 @@ find_cmdline_var(char_u *src, int *usedlen) * '' 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,7 +8607,8 @@ eval_vars( case SPEC_SFILE: // file name for ":so" command case SPEC_STACK: // call stack - result = estack_sfile(spec_idx == SPEC_SFILE); + result = estack_sfile(spec_idx == SPEC_SFILE + ? ESTACK_SFILE : ESTACK_STACK); if (result == NULL) { *errormsg = spec_idx == SPEC_SFILE diff --git a/src/ex_eval.c b/src/ex_eval.c index 58088a0706..cbdf82e893 100644 --- a/src/ex_eval.c +++ b/src/ex_eval.c @@ -290,7 +290,7 @@ cause_errthrow( // Get the source name and lnum now, it may change before // reaching do_errthrow(). - elem->sfile = estack_sfile(FALSE); + elem->sfile = estack_sfile(ESTACK_NONE); elem->slnum = SOURCING_LNUM; } } @@ -549,7 +549,7 @@ throw_exception(void *value, except_type_T type, char_u *cmdname) } else { - excp->throw_name = estack_sfile(FALSE); + excp->throw_name = estack_sfile(ESTACK_NONE); if (excp->throw_name == NULL) excp->throw_name = vim_strsave((char_u *)""); if (excp->throw_name == NULL) diff --git a/src/message.c b/src/message.c index a9851efab0..059835af0d 100644 --- a/src/message.c +++ b/src/message.c @@ -461,7 +461,7 @@ get_emsg_source(void) if (SOURCING_NAME != NULL && other_sourcing_name()) { - char_u *sname = estack_sfile(FALSE); + char_u *sname = estack_sfile(ESTACK_NONE); char_u *tofree = sname; if (sname == NULL) diff --git a/src/proto/scriptfile.pro b/src/proto/scriptfile.pro index 52df2ca82e..cbb9253c52 100644 --- a/src/proto/scriptfile.pro +++ b/src/proto/scriptfile.pro @@ -4,7 +4,7 @@ estack_T *estack_push(etype_T type, char_u *name, long lnum); 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); +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); diff --git a/src/scriptfile.c b/src/scriptfile.c index e075236953..75182ca511 100644 --- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -111,10 +111,10 @@ estack_pop(void) /* * Get the current value for in allocated memory. - * "is_sfile" is TRUE for itself. + * "which" is ESTACK_SFILE for and ESTACK_STACK for . */ char_u * -estack_sfile(int is_sfile UNUSED) +estack_sfile(estack_arg_T which UNUSED) { estack_T *entry; #ifdef FEAT_EVAL @@ -127,7 +127,7 @@ estack_sfile(int is_sfile UNUSED) entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; #ifdef FEAT_EVAL - if (is_sfile && entry->es_type != ETYPE_UFUNC) + if (which == ESTACK_SFILE && entry->es_type != ETYPE_UFUNC) #endif { if (entry->es_name == NULL) @@ -144,6 +144,8 @@ estack_sfile(int is_sfile UNUSED) 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,15 +161,20 @@ estack_sfile(int is_sfile UNUSED) 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. + 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, entry->es_lnum); + type_name, entry->es_name, lnum); ga.ga_len += (int)STRLEN((char *)ga.ga_data + ga.ga_len); } } diff --git a/src/testdir/test_expand_func.vim b/src/testdir/test_expand_func.vim index 42aa8e01bc..a63cc04e1f 100644 --- a/src/testdir/test_expand_func.vim +++ b/src/testdir/test_expand_func.vim @@ -39,9 +39,9 @@ endfunc 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('')) + 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,11 +53,12 @@ func Test_expand_sfile_and_stack() " Use from sourced script. let lines =<< trim END + " comment here let g:stack_value = expand('') END call writefile(lines, 'Xstack') source Xstack - call assert_match('\