Mercurial > vim
comparison src/ex_docmd.c @ 21939:8350bdbdbb28 v8.2.1519
patch 8.2.1519: Vim9: Ex command default range is not set
Commit: https://github.com/vim/vim/commit/c2af0afff5c44969ad7611ec2d47d0f52087fa7f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 23 21:06:02 2020 +0200
patch 8.2.1519: Vim9: Ex command default range is not set
Problem: Vim9: Ex command default range is not set.
Solution: When range is not given use default. (closes https://github.com/vim/vim/issues/6779)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 23 Aug 2020 21:15:04 +0200 |
parents | b931df03adcc |
children | 6941d3205be9 |
comparison
equal
deleted
inserted
replaced
21938:9131ebc53d38 | 21939:8350bdbdbb28 |
---|---|
64 #endif | 64 #endif |
65 #if !defined(FEAT_QUICKFIX) || !defined(FEAT_EVAL) | 65 #if !defined(FEAT_QUICKFIX) || !defined(FEAT_EVAL) |
66 # define ex_cexpr ex_ni | 66 # define ex_cexpr ex_ni |
67 #endif | 67 #endif |
68 | 68 |
69 static linenr_T default_address(exarg_T *eap); | |
69 static linenr_T get_address(exarg_T *, char_u **, cmd_addr_T addr_type, int skip, int silent, int to_other_file, int address_count); | 70 static linenr_T get_address(exarg_T *, char_u **, cmd_addr_T addr_type, int skip, int silent, int to_other_file, int address_count); |
71 static void address_default_all(exarg_T *eap); | |
70 static void get_flags(exarg_T *eap); | 72 static void get_flags(exarg_T *eap); |
71 #if !defined(FEAT_PERL) \ | 73 #if !defined(FEAT_PERL) \ |
72 || !defined(FEAT_PYTHON) || !defined(FEAT_PYTHON3) \ | 74 || !defined(FEAT_PYTHON) || !defined(FEAT_PYTHON3) \ |
73 || !defined(FEAT_TCL) \ | 75 || !defined(FEAT_TCL) \ |
74 || !defined(FEAT_RUBY) \ | 76 || !defined(FEAT_RUBY) \ |
1878 #endif | 1880 #endif |
1879 } | 1881 } |
1880 | 1882 |
1881 ea.cmd = cmd; | 1883 ea.cmd = cmd; |
1882 #ifdef FEAT_EVAL | 1884 #ifdef FEAT_EVAL |
1883 if (may_have_range) | 1885 if (!may_have_range) |
1886 ea.line1 = ea.line2 = default_address(&ea); | |
1887 else | |
1884 #endif | 1888 #endif |
1885 if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL) | 1889 if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL) |
1886 goto doend; | 1890 goto doend; |
1887 | 1891 |
1888 /* | 1892 /* |
2280 } | 2284 } |
2281 } | 2285 } |
2282 } | 2286 } |
2283 | 2287 |
2284 if ((ea.argt & EX_DFLALL) && ea.addr_count == 0) | 2288 if ((ea.argt & EX_DFLALL) && ea.addr_count == 0) |
2285 { | 2289 address_default_all(&ea); |
2286 buf_T *buf; | |
2287 | |
2288 ea.line1 = 1; | |
2289 switch (ea.addr_type) | |
2290 { | |
2291 case ADDR_LINES: | |
2292 case ADDR_OTHER: | |
2293 ea.line2 = curbuf->b_ml.ml_line_count; | |
2294 break; | |
2295 case ADDR_LOADED_BUFFERS: | |
2296 buf = firstbuf; | |
2297 while (buf->b_next != NULL && buf->b_ml.ml_mfp == NULL) | |
2298 buf = buf->b_next; | |
2299 ea.line1 = buf->b_fnum; | |
2300 buf = lastbuf; | |
2301 while (buf->b_prev != NULL && buf->b_ml.ml_mfp == NULL) | |
2302 buf = buf->b_prev; | |
2303 ea.line2 = buf->b_fnum; | |
2304 break; | |
2305 case ADDR_BUFFERS: | |
2306 ea.line1 = firstbuf->b_fnum; | |
2307 ea.line2 = lastbuf->b_fnum; | |
2308 break; | |
2309 case ADDR_WINDOWS: | |
2310 ea.line2 = LAST_WIN_NR; | |
2311 break; | |
2312 case ADDR_TABS: | |
2313 ea.line2 = LAST_TAB_NR; | |
2314 break; | |
2315 case ADDR_TABS_RELATIVE: | |
2316 ea.line2 = 1; | |
2317 break; | |
2318 case ADDR_ARGUMENTS: | |
2319 if (ARGCOUNT == 0) | |
2320 ea.line1 = ea.line2 = 0; | |
2321 else | |
2322 ea.line2 = ARGCOUNT; | |
2323 break; | |
2324 case ADDR_QUICKFIX_VALID: | |
2325 #ifdef FEAT_QUICKFIX | |
2326 ea.line2 = qf_get_valid_size(&ea); | |
2327 if (ea.line2 == 0) | |
2328 ea.line2 = 1; | |
2329 #endif | |
2330 break; | |
2331 case ADDR_NONE: | |
2332 case ADDR_UNSIGNED: | |
2333 case ADDR_QUICKFIX: | |
2334 iemsg(_("INTERNAL: Cannot use EX_DFLALL with ADDR_NONE, ADDR_UNSIGNED or ADDR_QUICKFIX")); | |
2335 break; | |
2336 } | |
2337 } | |
2338 | 2290 |
2339 // accept numbered register only when no count allowed (:put) | 2291 // accept numbered register only when no count allowed (:put) |
2340 if ( (ea.argt & EX_REGSTR) | 2292 if ( (ea.argt & EX_REGSTR) |
2341 && *ea.arg != NUL | 2293 && *ea.arg != NUL |
2342 // Do not allow register = for user commands | 2294 // Do not allow register = for user commands |
3009 | 2961 |
3010 // Repeat for all ',' or ';' separated addresses. | 2962 // Repeat for all ',' or ';' separated addresses. |
3011 for (;;) | 2963 for (;;) |
3012 { | 2964 { |
3013 eap->line1 = eap->line2; | 2965 eap->line1 = eap->line2; |
3014 switch (eap->addr_type) | 2966 eap->line2 = default_address(eap); |
3015 { | |
3016 case ADDR_LINES: | |
3017 case ADDR_OTHER: | |
3018 // Default is the cursor line number. Avoid using an invalid | |
3019 // line number though. | |
3020 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3021 eap->line2 = curbuf->b_ml.ml_line_count; | |
3022 else | |
3023 eap->line2 = curwin->w_cursor.lnum; | |
3024 break; | |
3025 case ADDR_WINDOWS: | |
3026 eap->line2 = CURRENT_WIN_NR; | |
3027 break; | |
3028 case ADDR_ARGUMENTS: | |
3029 eap->line2 = curwin->w_arg_idx + 1; | |
3030 if (eap->line2 > ARGCOUNT) | |
3031 eap->line2 = ARGCOUNT; | |
3032 break; | |
3033 case ADDR_LOADED_BUFFERS: | |
3034 case ADDR_BUFFERS: | |
3035 eap->line2 = curbuf->b_fnum; | |
3036 break; | |
3037 case ADDR_TABS: | |
3038 eap->line2 = CURRENT_TAB_NR; | |
3039 break; | |
3040 case ADDR_TABS_RELATIVE: | |
3041 case ADDR_UNSIGNED: | |
3042 eap->line2 = 1; | |
3043 break; | |
3044 case ADDR_QUICKFIX: | |
3045 #ifdef FEAT_QUICKFIX | |
3046 eap->line2 = qf_get_cur_idx(eap); | |
3047 #endif | |
3048 break; | |
3049 case ADDR_QUICKFIX_VALID: | |
3050 #ifdef FEAT_QUICKFIX | |
3051 eap->line2 = qf_get_cur_valid_idx(eap); | |
3052 #endif | |
3053 break; | |
3054 case ADDR_NONE: | |
3055 // Will give an error later if a range is found. | |
3056 break; | |
3057 } | |
3058 eap->cmd = skipwhite(eap->cmd); | 2967 eap->cmd = skipwhite(eap->cmd); |
3059 lnum = get_address(eap, &eap->cmd, eap->addr_type, eap->skip, silent, | 2968 lnum = get_address(eap, &eap->cmd, eap->addr_type, eap->skip, silent, |
3060 eap->addr_count == 0, address_count++); | 2969 eap->addr_count == 0, address_count++); |
3061 if (eap->cmd == NULL) // error detected | 2970 if (eap->cmd == NULL) // error detected |
3062 return FAIL; | 2971 return FAIL; |
3671 else | 3580 else |
3672 emsg(_(e_invrange)); | 3581 emsg(_(e_invrange)); |
3673 } | 3582 } |
3674 | 3583 |
3675 /* | 3584 /* |
3585 * Return the default address for an address type. | |
3586 */ | |
3587 static linenr_T | |
3588 default_address(exarg_T *eap) | |
3589 { | |
3590 linenr_T lnum = 0; | |
3591 | |
3592 switch (eap->addr_type) | |
3593 { | |
3594 case ADDR_LINES: | |
3595 case ADDR_OTHER: | |
3596 // Default is the cursor line number. Avoid using an invalid | |
3597 // line number though. | |
3598 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3599 lnum = curbuf->b_ml.ml_line_count; | |
3600 else | |
3601 lnum = curwin->w_cursor.lnum; | |
3602 break; | |
3603 case ADDR_WINDOWS: | |
3604 lnum = CURRENT_WIN_NR; | |
3605 break; | |
3606 case ADDR_ARGUMENTS: | |
3607 lnum = curwin->w_arg_idx + 1; | |
3608 if (lnum > ARGCOUNT) | |
3609 lnum = ARGCOUNT; | |
3610 break; | |
3611 case ADDR_LOADED_BUFFERS: | |
3612 case ADDR_BUFFERS: | |
3613 lnum = curbuf->b_fnum; | |
3614 break; | |
3615 case ADDR_TABS: | |
3616 lnum = CURRENT_TAB_NR; | |
3617 break; | |
3618 case ADDR_TABS_RELATIVE: | |
3619 case ADDR_UNSIGNED: | |
3620 lnum = 1; | |
3621 break; | |
3622 case ADDR_QUICKFIX: | |
3623 #ifdef FEAT_QUICKFIX | |
3624 lnum = qf_get_cur_idx(eap); | |
3625 #endif | |
3626 break; | |
3627 case ADDR_QUICKFIX_VALID: | |
3628 #ifdef FEAT_QUICKFIX | |
3629 lnum = qf_get_cur_valid_idx(eap); | |
3630 #endif | |
3631 break; | |
3632 case ADDR_NONE: | |
3633 // Will give an error later if a range is found. | |
3634 break; | |
3635 } | |
3636 return lnum; | |
3637 } | |
3638 | |
3639 /* | |
3676 * Get a single EX address. | 3640 * Get a single EX address. |
3677 * | 3641 * |
3678 * Set ptr to the next character after the part that was interpreted. | 3642 * Set ptr to the next character after the part that was interpreted. |
3679 * Set ptr to NULL when an error is encountered. | 3643 * Set ptr to NULL when an error is encountered. |
3680 * This may set the last used search pattern. | 3644 * This may set the last used search pattern. |
4030 | 3994 |
4031 error: | 3995 error: |
4032 *ptr = cmd; | 3996 *ptr = cmd; |
4033 return lnum; | 3997 return lnum; |
4034 } | 3998 } |
3999 | |
4000 /* | |
4001 * Set eap->line1 and eap->line2 to the whole range. | |
4002 * Used for commands with the EX_DFLALL flag and no range given. | |
4003 */ | |
4004 static void | |
4005 address_default_all(exarg_T *eap) | |
4006 { | |
4007 eap->line1 = 1; | |
4008 switch (eap->addr_type) | |
4009 { | |
4010 case ADDR_LINES: | |
4011 case ADDR_OTHER: | |
4012 eap->line2 = curbuf->b_ml.ml_line_count; | |
4013 break; | |
4014 case ADDR_LOADED_BUFFERS: | |
4015 { | |
4016 buf_T *buf = firstbuf; | |
4017 | |
4018 while (buf->b_next != NULL && buf->b_ml.ml_mfp == NULL) | |
4019 buf = buf->b_next; | |
4020 eap->line1 = buf->b_fnum; | |
4021 buf = lastbuf; | |
4022 while (buf->b_prev != NULL && buf->b_ml.ml_mfp == NULL) | |
4023 buf = buf->b_prev; | |
4024 eap->line2 = buf->b_fnum; | |
4025 } | |
4026 break; | |
4027 case ADDR_BUFFERS: | |
4028 eap->line1 = firstbuf->b_fnum; | |
4029 eap->line2 = lastbuf->b_fnum; | |
4030 break; | |
4031 case ADDR_WINDOWS: | |
4032 eap->line2 = LAST_WIN_NR; | |
4033 break; | |
4034 case ADDR_TABS: | |
4035 eap->line2 = LAST_TAB_NR; | |
4036 break; | |
4037 case ADDR_TABS_RELATIVE: | |
4038 eap->line2 = 1; | |
4039 break; | |
4040 case ADDR_ARGUMENTS: | |
4041 if (ARGCOUNT == 0) | |
4042 eap->line1 = eap->line2 = 0; | |
4043 else | |
4044 eap->line2 = ARGCOUNT; | |
4045 break; | |
4046 case ADDR_QUICKFIX_VALID: | |
4047 #ifdef FEAT_QUICKFIX | |
4048 eap->line2 = qf_get_valid_size(eap); | |
4049 if (eap->line2 == 0) | |
4050 eap->line2 = 1; | |
4051 #endif | |
4052 break; | |
4053 case ADDR_NONE: | |
4054 case ADDR_UNSIGNED: | |
4055 case ADDR_QUICKFIX: | |
4056 iemsg(_("INTERNAL: Cannot use EX_DFLALL with ADDR_NONE, ADDR_UNSIGNED or ADDR_QUICKFIX")); | |
4057 break; | |
4058 } | |
4059 } | |
4060 | |
4035 | 4061 |
4036 /* | 4062 /* |
4037 * Get flags from an Ex command argument. | 4063 * Get flags from an Ex command argument. |
4038 */ | 4064 */ |
4039 static void | 4065 static void |