Mercurial > vim
comparison src/ex_docmd.c @ 27970:212c5894b8b1 v8.2.4510
patch 8.2.4510: Vim9: shortening commands leads to confusing script
Commit: https://github.com/vim/vim/commit/204852ae2adfdde10c656ca7f14e5b4207a69172
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 5 12:56:44 2022 +0000
patch 8.2.4510: Vim9: shortening commands leads to confusing script
Problem: Vim9: shortening commands leads to confusing script.
Solution: In Vim9 script require at least ":cont" for ":continue", "const"
instead of "cons", "break" instead of "brea", "catch" instead of
"cat", "else" instead of "el" "elseif" instead of "elsei" "endfor"
instead of "endfo" "endif" instead of "en" "endtry" instead of
"endt", "finally" instead of "fina", "throw" instead of "th",
"while" instead of "wh".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 05 Mar 2022 14:00:03 +0100 |
parents | 2485bf68de34 |
children | 442ca2007bec |
comparison
equal
deleted
inserted
replaced
27969:0e58183b329e | 27970:212c5894b8b1 |
---|---|
3743 eap->cmdidx = (cmdidx_T)((int)eap->cmdidx + 1)) | 3743 eap->cmdidx = (cmdidx_T)((int)eap->cmdidx + 1)) |
3744 if (STRNCMP(cmdnames[(int)eap->cmdidx].cmd_name, (char *)eap->cmd, | 3744 if (STRNCMP(cmdnames[(int)eap->cmdidx].cmd_name, (char *)eap->cmd, |
3745 (size_t)len) == 0) | 3745 (size_t)len) == 0) |
3746 { | 3746 { |
3747 #ifdef FEAT_EVAL | 3747 #ifdef FEAT_EVAL |
3748 if (full != NULL | 3748 if (full != NULL && cmdnames[eap->cmdidx].cmd_name[len] == NUL) |
3749 && cmdnames[(int)eap->cmdidx].cmd_name[len] == NUL) | |
3750 *full = TRUE; | 3749 *full = TRUE; |
3751 #endif | 3750 #endif |
3752 break; | 3751 break; |
3753 } | 3752 } |
3754 | 3753 |
3755 // :Print and :mode are not supported in Vim9 script | 3754 // :Print and :mode are not supported in Vim9 script. |
3756 if (vim9 && (eap->cmdidx == CMD_mode || eap->cmdidx == CMD_Print)) | 3755 // Some commands cannot be shortened in Vim9 script. |
3757 eap->cmdidx = CMD_SIZE; | 3756 // ":continue" needs at least ":cont", since ":con" looks weird. |
3757 if (vim9 && eap->cmdidx != CMD_SIZE) | |
3758 { | |
3759 if (eap->cmdidx == CMD_mode || eap->cmdidx == CMD_Print) | |
3760 eap->cmdidx = CMD_SIZE; | |
3761 else if (((cmdnames[eap->cmdidx].cmd_argt & EX_WHOLE) | |
3762 && len < (int)STRLEN(cmdnames[eap->cmdidx].cmd_name)) | |
3763 || (eap->cmdidx == CMD_continue && len < 4)) | |
3764 { | |
3765 semsg(_(e_command_cannot_be_shortened), eap->cmd); | |
3766 eap->cmdidx = CMD_SIZE; | |
3767 } | |
3768 } | |
3758 | 3769 |
3759 // Do not recognize ":*" as the star command unless '*' is in | 3770 // Do not recognize ":*" as the star command unless '*' is in |
3760 // 'cpoptions'. | 3771 // 'cpoptions'. |
3761 if (eap->cmdidx == CMD_star && vim_strchr(p_cpo, CPO_STAR) == NULL) | 3772 if (eap->cmdidx == CMD_star && vim_strchr(p_cpo, CPO_STAR) == NULL) |
3762 p = eap->cmd; | 3773 p = eap->cmd; |
3773 } | 3784 } |
3774 if (p == NULL || p == eap->cmd) | 3785 if (p == NULL || p == eap->cmd) |
3775 eap->cmdidx = CMD_SIZE; | 3786 eap->cmdidx = CMD_SIZE; |
3776 } | 3787 } |
3777 | 3788 |
3778 // ":fina" means ":finally" for backwards compatibility. | 3789 // ":fina" means ":finally" in legacy script, for backwards compatibility. |
3779 if (eap->cmdidx == CMD_final && p - eap->cmd == 4) | 3790 if (eap->cmdidx == CMD_final && p - eap->cmd == 4 && !vim9) |
3780 eap->cmdidx = CMD_finally; | 3791 eap->cmdidx = CMD_finally; |
3781 | 3792 |
3782 #ifdef FEAT_EVAL | 3793 #ifdef FEAT_EVAL |
3783 if (eap->cmdidx < CMD_SIZE | 3794 if (eap->cmdidx < CMD_SIZE |
3784 && vim9 | 3795 && vim9 |