vim-patch:8.1.1822: confusing error message when range is not allowed

Problem:    Confusing error message when range is not allowed.
Solution:   With ADDR_NONE give e_norange.  Change e_invaddr to e_invrange for
            consistency.
0acae7acc4
This commit is contained in:
Jan Edmund Lazo 2021-01-02 04:06:18 -05:00
parent cb5ba225f8
commit 215aa83b2a
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15
3 changed files with 28 additions and 9 deletions

View File

@ -3729,6 +3729,15 @@ char_u *skip_range(
return (char_u *)cmd; return (char_u *)cmd;
} }
static void addr_error(cmd_addr_T addr_type)
{
if (addr_type == ADDR_NONE) {
EMSG(_(e_norange));
} else {
EMSG(_(e_invrange));
}
}
// Get a single EX address // Get a single EX address
// //
// Set ptr to the next character after the part that was interpreted. // Set ptr to the next character after the part that was interpreted.
@ -3778,10 +3787,10 @@ static linenr_T get_address(exarg_T *eap,
case ADDR_TABS: case ADDR_TABS:
lnum = CURRENT_TAB_NR; lnum = CURRENT_TAB_NR;
break; break;
case ADDR_TABS_RELATIVE:
case ADDR_NONE: case ADDR_NONE:
case ADDR_TABS_RELATIVE:
case ADDR_UNSIGNED: case ADDR_UNSIGNED:
EMSG(_(e_invrange)); addr_error(addr_type);
cmd = NULL; cmd = NULL;
goto error; goto error;
break; break;
@ -3823,10 +3832,10 @@ static linenr_T get_address(exarg_T *eap,
case ADDR_TABS: case ADDR_TABS:
lnum = LAST_TAB_NR; lnum = LAST_TAB_NR;
break; break;
case ADDR_TABS_RELATIVE:
case ADDR_NONE: case ADDR_NONE:
case ADDR_TABS_RELATIVE:
case ADDR_UNSIGNED: case ADDR_UNSIGNED:
EMSG(_(e_invrange)); addr_error(addr_type);
cmd = NULL; cmd = NULL;
goto error; goto error;
break; break;
@ -3851,7 +3860,7 @@ static linenr_T get_address(exarg_T *eap,
goto error; goto error;
} }
if (addr_type != ADDR_LINES) { if (addr_type != ADDR_LINES) {
EMSG(_(e_invaddr)); addr_error(addr_type);
cmd = NULL; cmd = NULL;
goto error; goto error;
} }
@ -3879,7 +3888,7 @@ static linenr_T get_address(exarg_T *eap,
case '?': /* '/' or '?' - search */ case '?': /* '/' or '?' - search */
c = *cmd++; c = *cmd++;
if (addr_type != ADDR_LINES) { if (addr_type != ADDR_LINES) {
EMSG(_(e_invaddr)); addr_error(addr_type);
cmd = NULL; cmd = NULL;
goto error; goto error;
} }
@ -3926,7 +3935,7 @@ static linenr_T get_address(exarg_T *eap,
case '\\': /* "\?", "\/" or "\&", repeat search */ case '\\': /* "\?", "\/" or "\&", repeat search */
++cmd; ++cmd;
if (addr_type != ADDR_LINES) { if (addr_type != ADDR_LINES) {
EMSG(_(e_invaddr)); addr_error(addr_type);
cmd = NULL; cmd = NULL;
goto error; goto error;
} }
@ -7863,7 +7872,7 @@ static void ex_copymove(exarg_T *eap)
* move or copy lines from 'eap->line1'-'eap->line2' to below line 'n' * move or copy lines from 'eap->line1'-'eap->line2' to below line 'n'
*/ */
if (n == MAXLNUM || n < 0 || n > curbuf->b_ml.ml_line_count) { if (n == MAXLNUM || n < 0 || n > curbuf->b_ml.ml_line_count) {
EMSG(_(e_invaddr)); EMSG(_(e_invrange));
return; return;
} }

View File

@ -866,7 +866,6 @@ EXTERN char_u e_failed[] INIT(= N_("E472: Command failed"));
EXTERN char_u e_internal[] INIT(= N_("E473: Internal error")); EXTERN char_u e_internal[] INIT(= N_("E473: Internal error"));
EXTERN char_u e_intern2[] INIT(= N_("E685: Internal error: %s")); EXTERN char_u e_intern2[] INIT(= N_("E685: Internal error: %s"));
EXTERN char_u e_interr[] INIT(= N_("Interrupted")); EXTERN char_u e_interr[] INIT(= N_("Interrupted"));
EXTERN char_u e_invaddr[] INIT(= N_("E14: Invalid address"));
EXTERN char_u e_invarg[] INIT(= N_("E474: Invalid argument")); EXTERN char_u e_invarg[] INIT(= N_("E474: Invalid argument"));
EXTERN char_u e_invarg2[] INIT(= N_("E475: Invalid argument: %s")); EXTERN char_u e_invarg2[] INIT(= N_("E475: Invalid argument: %s"));
EXTERN char_u e_invargval[] INIT(= N_("E475: Invalid value for argument %s")); EXTERN char_u e_invargval[] INIT(= N_("E475: Invalid value for argument %s"));

View File

@ -9,6 +9,17 @@ func Test_ex_delete()
call assert_equal(['a', 'c'], getline(1, 2)) call assert_equal(['a', 'c'], getline(1, 2))
endfunc endfunc
func Test_range_error()
call assert_fails(':.echo 1', 'E481:')
call assert_fails(':$echo 1', 'E481:')
call assert_fails(':1,2echo 1', 'E481:')
call assert_fails(':+1echo 1', 'E481:')
call assert_fails(':/1/echo 1', 'E481:')
call assert_fails(':\/echo 1', 'E481:')
normal vv
call assert_fails(":'<,'>echo 1", 'E481:')
endfunc
func Test_buffers_lastused() func Test_buffers_lastused()
edit bufc " oldest edit bufc " oldest