vim-patch:8.2.0590: no 'backspace' value allows ignoring the insertion point

Problem:    No 'backspace' value allows ignoring the insertion point.
Solution:   Add the "nostop" and 3 values. (Christian Brabandt, closes vim/vim#5940)
aa0489e12d
This commit is contained in:
Jan Edmund Lazo
2021-01-05 00:46:06 -05:00
parent 5b897acfc1
commit 25cb2c722e
5 changed files with 63 additions and 9 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) eol allow backspacing over line breaks (join lines)
start allow backspacing over the start of insert; CTRL-W and CTRL-U start allow backspacing over the start of insert; CTRL-W and CTRL-U
stop once at the start of insert. 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. 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) 0 same as ":set backspace=" (Vi compatible)
1 same as ":set backspace=indent,eol" 1 same as ":set backspace=indent,eol"
2 same as ":set backspace=indent,eol,start" 2 same as ":set backspace=indent,eol,start"
3 same as ":set backspace=indent,eol,nostop"
*'backup'* *'bk'* *'nobackup'* *'nobk'* *'backup'* *'bk'* *'nobackup'* *'nobk'*
'backup' 'bk' boolean (default off) '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 } while (revins_on
|| (curwin->w_cursor.col > mincol || (curwin->w_cursor.col > mincol
&& (curwin->w_cursor.lnum != Insstart_orig.lnum && (can_bs(BS_NOSTOP)
|| curwin->w_cursor.col != Insstart_orig.col))); || (curwin->w_cursor.lnum != Insstart_orig.lnum
|| curwin->w_cursor.col != Insstart_orig.col))));
} }
did_backspace = true; did_backspace = true;
} }

View File

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

View File

@@ -282,9 +282,14 @@ enum {
#define WIM_BUFLASTUSED 8 #define WIM_BUFLASTUSED 8
// arguments for can_bs() // 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_INDENT 'i' // "Indent"
#define BS_EOL 'o' // "eOl" #define BS_EOL 'l' // "eoL"
#define BS_START 's' // "Start" #define BS_START 's' // "Start"
#define BS_NOSTOP 'p' // "nostoP
#define LISPWORD_VALUE \ #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" "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

@@ -19,6 +19,8 @@ func Test_backspace_option()
call assert_equal('eol', &backspace) call assert_equal('eol', &backspace)
set backspace=start set backspace=start
call assert_equal('start', &backspace) call assert_equal('start', &backspace)
set backspace=nostop
call assert_equal('nostop', &backspace)
" Add the value " Add the value
set backspace= set backspace=
set backspace=indent set backspace=indent
@@ -27,7 +29,11 @@ func Test_backspace_option()
call assert_equal('indent,eol', &backspace) call assert_equal('indent,eol', &backspace)
set backspace+=start set backspace+=start
call assert_equal('indent,eol,start', &backspace) call assert_equal('indent,eol,start', &backspace)
set backspace+=nostop
call assert_equal('indent,eol,start,nostop', &backspace)
" Delete the value " Delete the value
set backspace-=nostop
call assert_equal('indent,eol,start', &backspace)
set backspace-=indent set backspace-=indent
call assert_equal('eol,start', &backspace) call assert_equal('eol,start', &backspace)
set backspace-=start set backspace-=start
@@ -47,7 +53,9 @@ func Test_backspace_option()
call assert_equal('1', &backspace) call assert_equal('1', &backspace)
set backspace=2 set backspace=2
call assert_equal('2', &backspace) call assert_equal('2', &backspace)
call assert_false(match(Exec('set backspace=3'), '.*E474')) 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')) call assert_false(match(Exec('set backspace=10'), '.*E474'))
" Cleared when 'compatible' is set " Cleared when 'compatible' is set
@@ -101,6 +109,39 @@ func Test_backspace_ctrl_u()
\ "8 this shouldn't be deleted (not touched yet) vim7", \ "8 this shouldn't be deleted (not touched yet) vim7",
\ ""], getline(1, '$')) \ ""], 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 compatible&vim
set visualbell&vim set visualbell&vim
set backspace&vim set backspace&vim