Merge pull request #13689 from janlazo/vim-8.2.0050

vim-patch:8.1.{1731,1764,2111,2126},8.2.{50,590}
This commit is contained in:
Matthieu Coudron
2021-01-06 21:17:44 +01:00
committed by GitHub
8 changed files with 178 additions and 75 deletions

View File

@@ -734,6 +734,8 @@ A jump table for the options with a short description can be found at |Q_op|.
eol allow backspacing over line breaks (join lines)
start allow backspacing over the start of insert; CTRL-W and CTRL-U
stop once at the start of insert.
nostop like start, except CTRL-W and CTRL-U do not stop at the start of
insert.
When the value is empty, Vi compatible backspacing is used.
@@ -742,6 +744,7 @@ A jump table for the options with a short description can be found at |Q_op|.
0 same as ":set backspace=" (Vi compatible)
1 same as ":set backspace=indent,eol"
2 same as ":set backspace=indent,eol,start"
3 same as ":set backspace=indent,eol,nostop"
*'backup'* *'bk'* *'nobackup'* *'nobk'*
'backup' 'bk' boolean (default off)

View File

@@ -8282,8 +8282,9 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
}
} while (revins_on
|| (curwin->w_cursor.col > mincol
&& (curwin->w_cursor.lnum != Insstart_orig.lnum
|| curwin->w_cursor.col != Insstart_orig.col)));
&& (can_bs(BS_NOSTOP)
|| (curwin->w_cursor.lnum != Insstart_orig.lnum
|| curwin->w_cursor.col != Insstart_orig.col))));
}
did_backspace = true;
}

View File

@@ -777,6 +777,7 @@ void ex_delmarks(exarg_T *eap)
n = i - 'A';
}
namedfm[n].fmark.mark.lnum = 0;
namedfm[n].fmark.fnum = 0;
XFREE_CLEAR(namedfm[n].fname);
}
}

View File

@@ -306,7 +306,7 @@ static char *(p_buftype_values[]) = { "nofile", "nowrite", "quickfix",
static char *(p_bufhidden_values[]) = { "hide", "unload", "delete",
"wipe", NULL };
static char *(p_bs_values[]) = { "indent", "eol", "start", NULL };
static char *(p_bs_values[]) = { "indent", "eol", "start", "nostop", NULL };
static char *(p_fdm_values[]) = { "manual", "expr", "marker", "indent",
"syntax", "diff", NULL };
static char *(p_fcl_values[]) = { "all", NULL };
@@ -1366,6 +1366,10 @@ int do_set(
*(char_u **)varp = vim_strsave(
(char_u *)"indent,eol,start");
break;
case 3:
*(char_u **)varp = vim_strsave(
(char_u *)"indent,eol,nostop");
break;
}
xfree(oldval);
if (origval == oldval) {
@@ -2939,7 +2943,7 @@ ambw_end:
}
} else if (varp == &p_bs) { // 'backspace'
if (ascii_isdigit(*p_bs)) {
if (*p_bs >'2' || p_bs[1] != NUL) {
if (*p_bs > '3' || p_bs[1] != NUL) {
errmsg = e_invarg;
}
} else if (check_opt_strings(p_bs, p_bs_values, true) != OK) {
@@ -6801,15 +6805,15 @@ static int check_opt_wim(void)
}
/// Check if backspacing over something is allowed.
/// The parameter what is one of the following: whatBS_INDENT, BS_EOL
/// or BS_START
/// @param what BS_INDENT, BS_EOL, BS_START, or BS_NOSTOP
bool can_bs(int what)
{
if (what == BS_START && bt_prompt(curbuf)) {
return false;
}
switch (*p_bs) {
case '2': return true;
case '3': return true;
case '2': return what != BS_NOSTOP;
case '1': return what != BS_START;
case '0': return false;
}

View File

@@ -282,9 +282,14 @@ enum {
#define WIM_BUFLASTUSED 8
// arguments for can_bs()
// each defined char should be unique over all values
// except for BS_START, that intentionally also matches BS_NOSTOP
// because BS_NOSTOP behaves exactly the same except it
// does not stop at the start of the insert point
#define BS_INDENT 'i' // "Indent"
#define BS_EOL 'o' // "eOl"
#define BS_EOL 'l' // "eoL"
#define BS_START 's' // "Start"
#define BS_NOSTOP 'p' // "nostoP
#define LISPWORD_VALUE \
"defun,define,defmacro,set!,lambda,if,case,let,flet,let*,letrec,do,do*,define-syntax,let-syntax,letrec-syntax,destructuring-bind,defpackage,defparameter,defstruct,deftype,defvar,do-all-symbols,do-external-symbols,do-symbols,dolist,dotimes,ecase,etypecase,eval-when,labels,macrolet,multiple-value-bind,multiple-value-call,multiple-value-prog1,multiple-value-setq,prog1,progv,typecase,unless,unwind-protect,when,with-input-from-string,with-open-file,with-open-stream,with-output-to-string,with-package-iterator,define-condition,handler-bind,handler-case,restart-bind,restart-case,with-simple-restart,store-value,use-value,muffle-warning,abort,continue,with-slots,with-slots*,with-accessors,with-accessors*,defclass,defmethod,print-unreadable-object"

View File

@@ -0,0 +1,151 @@
" Tests for 'backspace' settings
func Exec(expr)
let str=''
try
exec a:expr
catch /.*/
let str=v:exception
endtry
return str
endfunc
func Test_backspace_option()
set backspace=
call assert_equal('', &backspace)
set backspace=indent
call assert_equal('indent', &backspace)
set backspace=eol
call assert_equal('eol', &backspace)
set backspace=start
call assert_equal('start', &backspace)
set backspace=nostop
call assert_equal('nostop', &backspace)
" Add the value
set backspace=
set backspace=indent
call assert_equal('indent', &backspace)
set backspace+=eol
call assert_equal('indent,eol', &backspace)
set backspace+=start
call assert_equal('indent,eol,start', &backspace)
set backspace+=nostop
call assert_equal('indent,eol,start,nostop', &backspace)
" Delete the value
set backspace-=nostop
call assert_equal('indent,eol,start', &backspace)
set backspace-=indent
call assert_equal('eol,start', &backspace)
set backspace-=start
call assert_equal('eol', &backspace)
set backspace-=eol
call assert_equal('', &backspace)
" Check the error
call assert_equal(0, match(Exec('set backspace=ABC'), '.*E474'))
call assert_equal(0, match(Exec('set backspace+=def'), '.*E474'))
" NOTE: Vim doesn't check following error...
"call assert_equal(0, match(Exec('set backspace-=ghi'), '.*E474'))
" Check backwards compatibility with version 5.4 and earlier
set backspace=0
call assert_equal('0', &backspace)
set backspace=1
call assert_equal('1', &backspace)
set backspace=2
call assert_equal('2', &backspace)
set backspace=3
call assert_equal('3', &backspace)
call assert_false(match(Exec('set backspace=4'), '.*E474'))
call assert_false(match(Exec('set backspace=10'), '.*E474'))
" Cleared when 'compatible' is set
" set compatible
" call assert_equal('', &backspace)
set nocompatible viminfo+=nviminfo
endfunc
" Test with backspace set to the non-compatible setting
func Test_backspace_ctrl_u()
new
call append(0, [
\ "1 this shouldn't be deleted",
\ "2 this shouldn't be deleted",
\ "3 this shouldn't be deleted",
\ "4 this should be deleted",
\ "5 this shouldn't be deleted",
\ "6 this shouldn't be deleted",
\ "7 this shouldn't be deleted",
\ "8 this shouldn't be deleted (not touched yet)"])
call cursor(2, 1)
" set compatible
set backspace=2
exe "normal Avim1\<C-U>\<Esc>\<CR>"
exe "normal Avim2\<C-G>u\<C-U>\<Esc>\<CR>"
set cpo-=<
inoremap <c-u> <left><c-u>
exe "normal Avim3\<C-U>\<Esc>\<CR>"
iunmap <c-u>
exe "normal Avim4\<C-U>\<C-U>\<Esc>\<CR>"
" Test with backspace set to the compatible setting
set backspace= visualbell
exe "normal A vim5\<Esc>A\<C-U>\<C-U>\<Esc>\<CR>"
exe "normal A vim6\<Esc>Azwei\<C-G>u\<C-U>\<Esc>\<CR>"
inoremap <c-u> <left><c-u>
exe "normal A vim7\<C-U>\<C-U>\<Esc>\<CR>"
call assert_equal([
\ "1 this shouldn't be deleted",
\ "2 this shouldn't be deleted",
\ "3 this shouldn't be deleted",
\ "4 this should be deleted3",
\ "",
\ "6 this shouldn't be deleted vim5",
\ "7 this shouldn't be deleted vim6",
\ "8 this shouldn't be deleted (not touched yet) vim7",
\ ""], getline(1, '$'))
" Reset values
set compatible&vim
set visualbell&vim
set backspace&vim
" Test new nostop option
%d_
let expected = "foo bar foobar"
call setline(1, expected)
call cursor(1, 8)
exe ":norm! ianotherone\<c-u>"
call assert_equal(expected, getline(1))
call cursor(1, 8)
exe ":norm! ianothertwo\<c-w>"
call assert_equal(expected, getline(1))
let content = getline(1)
for value in ['indent,nostop', 'eol,nostop', 'indent,eol,nostop', 'indent,eol,start,nostop']
exe ":set bs=".. value
%d _
call setline(1, content)
let expected = " foobar"
call cursor(1, 8)
exe ":norm! ianotherone\<c-u>"
call assert_equal(expected, getline(1), 'CTRL-U backspace value: '.. &bs)
let expected = "foo foobar"
call setline(1, content)
call cursor(1, 8)
exe ":norm! ianothertwo\<c-w>"
call assert_equal(expected, getline(1), 'CTRL-W backspace value: '.. &bs)
endfor
" Reset options
set compatible&vim
set visualbell&vim
set backspace&vim
close!
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -171,6 +171,11 @@ func Test_delmarks()
" Deleting an already deleted mark should not fail.
delmarks x
" getpos() should return all zeros after deleting a filemark.
norm mA
delmarks A
call assert_equal([0, 0, 0, 0], getpos("'A"))
" Test deleting a range of marks.
norm ma
norm mb

View File

@@ -1,67 +0,0 @@
local helpers = require('test.functional.helpers')(after_each)
local call, clear = helpers.call, helpers.clear
local source, eq, nvim = helpers.source, helpers.eq, helpers.meths
describe("test 'backspace' settings", function()
before_each(function()
clear()
source([[
func Exec(expr)
let str=''
try
exec a:expr
catch /.*/
let str=v:exception
endtry
return str
endfunc
func Test_backspace_option()
set backspace=
call assert_equal('', &backspace)
set backspace=indent
call assert_equal('indent', &backspace)
set backspace=eol
call assert_equal('eol', &backspace)
set backspace=start
call assert_equal('start', &backspace)
" Add the value
set backspace=
set backspace=indent
call assert_equal('indent', &backspace)
set backspace+=eol
call assert_equal('indent,eol', &backspace)
set backspace+=start
call assert_equal('indent,eol,start', &backspace)
" Delete the value
set backspace-=indent
call assert_equal('eol,start', &backspace)
set backspace-=start
call assert_equal('eol', &backspace)
set backspace-=eol
call assert_equal('', &backspace)
" Check the error
call assert_equal(0, match(Exec('set backspace=ABC'), '.*E474'))
call assert_equal(0, match(Exec('set backspace+=def'), '.*E474'))
" NOTE: Vim doesn't check following error...
"call assert_equal(0, match(Exec('set backspace-=ghi'), '.*E474'))
" Check backwards compatibility with version 5.4 and earlier
set backspace=0
call assert_equal('0', &backspace)
set backspace=1
call assert_equal('1', &backspace)
set backspace=2
call assert_equal('2', &backspace)
call assert_false(match(Exec('set backspace=3'), '.*E474'))
call assert_false(match(Exec('set backspace=10'), '.*E474'))
endfunc
]])
end)
it('works', function()
call('Test_backspace_option')
eq({}, nvim.get_vvar('errors'))
end)
end)