Mercurial > vim
comparison src/usercmd.c @ 25382:b80e4e9c4988 v8.2.3228
patch 8.2.3228: cannot use a simple block for the :command argument
Commit: https://github.com/vim/vim/commit/5d7c2df536c17db4a9c61e0760bdcf78d0db7330
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jul 27 21:17:32 2021 +0200
patch 8.2.3228: cannot use a simple block for the :command argument
Problem: Cannot use a simple block for the :command argument. (Maarten
Tournoij)
Solution: Recognize a simple {} block. (issue #8623)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 27 Jul 2021 21:30:08 +0200 |
parents | a9ea83a3659a |
children | 05f9e8f2016c |
comparison
equal
deleted
inserted
replaced
25381:d5abf60e9872 | 25382:b80e4e9c4988 |
---|---|
113 {ADDR_OTHER, "other", "?"}, | 113 {ADDR_OTHER, "other", "?"}, |
114 {ADDR_NONE, NULL, NULL} | 114 {ADDR_NONE, NULL, NULL} |
115 }; | 115 }; |
116 | 116 |
117 #define UC_BUFFER 1 // -buffer: local to current buffer | 117 #define UC_BUFFER 1 // -buffer: local to current buffer |
118 #define UC_VIM9 2 // {} argument: Vim9 syntax. | |
118 | 119 |
119 /* | 120 /* |
120 * Search for a user command that matches "eap->cmd". | 121 * Search for a user command that matches "eap->cmd". |
121 * Return cmdidx in "eap->cmdidx", flags in "eap->argt", idx in "eap->useridx". | 122 * Return cmdidx in "eap->cmdidx", flags in "eap->argt", idx in "eap->useridx". |
122 * Return a pointer to just after the command. | 123 * Return a pointer to just after the command. |
870 garray_T *gap; | 871 garray_T *gap; |
871 | 872 |
872 replace_termcodes(rep, &rep_buf, 0, NULL); | 873 replace_termcodes(rep, &rep_buf, 0, NULL); |
873 if (rep_buf == NULL) | 874 if (rep_buf == NULL) |
874 { | 875 { |
875 // Can't replace termcodes - try using the string as is | 876 // can't replace termcodes - try using the string as is |
876 rep_buf = vim_strsave(rep); | 877 rep_buf = vim_strsave(rep); |
877 | 878 |
878 // Give up if out of memory | 879 // give up if out of memory |
879 if (rep_buf == NULL) | 880 if (rep_buf == NULL) |
880 return FAIL; | 881 return FAIL; |
881 } | 882 } |
882 | 883 |
883 // get address of growarray: global or in curbuf | 884 // get address of growarray: global or in curbuf |
953 cmd->uc_rep = rep_buf; | 954 cmd->uc_rep = rep_buf; |
954 cmd->uc_argt = argt; | 955 cmd->uc_argt = argt; |
955 cmd->uc_def = def; | 956 cmd->uc_def = def; |
956 cmd->uc_compl = compl; | 957 cmd->uc_compl = compl; |
957 cmd->uc_script_ctx = current_sctx; | 958 cmd->uc_script_ctx = current_sctx; |
959 if (flags & UC_VIM9) | |
960 cmd->uc_script_ctx.sc_version = SCRIPT_VERSION_VIM9; | |
958 #ifdef FEAT_EVAL | 961 #ifdef FEAT_EVAL |
959 cmd->uc_script_ctx.sc_lnum += SOURCING_LNUM; | 962 cmd->uc_script_ctx.sc_lnum += SOURCING_LNUM; |
960 cmd->uc_compl_arg = compl_arg; | 963 cmd->uc_compl_arg = compl_arg; |
961 #endif | 964 #endif |
962 cmd->uc_addr_type = addr_type; | 965 cmd->uc_addr_type = addr_type; |
1035 else | 1038 else |
1036 give_warning_with_source( | 1039 give_warning_with_source( |
1037 (char_u *)_(e_complete_used_without_nargs), TRUE, TRUE); | 1040 (char_u *)_(e_complete_used_without_nargs), TRUE, TRUE); |
1038 } | 1041 } |
1039 else | 1042 else |
1043 { | |
1044 char_u *tofree = NULL; | |
1045 | |
1046 if (*p == '{' && ends_excmd2(eap->arg, skipwhite(p + 1)) | |
1047 && eap->getline != NULL) | |
1048 { | |
1049 garray_T ga; | |
1050 char_u *line = NULL; | |
1051 | |
1052 ga_init2(&ga, sizeof(char_u *), 10); | |
1053 if (ga_add_string(&ga, p) == FAIL) | |
1054 return; | |
1055 | |
1056 // Read lines between '{' and '}'. Does not support nesting or | |
1057 // here-doc constructs. | |
1058 // | |
1059 for (;;) | |
1060 { | |
1061 vim_free(line); | |
1062 if ((line = eap->getline(':', eap->cookie, | |
1063 0, GETLINE_CONCAT_CONTBAR)) == NULL) | |
1064 { | |
1065 emsg(_(e_missing_rcurly)); | |
1066 break; | |
1067 } | |
1068 if (ga_add_string(&ga, line) == FAIL) | |
1069 break; | |
1070 if (*skipwhite(line) == '}') | |
1071 break; | |
1072 } | |
1073 vim_free(line); | |
1074 p = tofree = ga_concat_strings(&ga, "\n"); | |
1075 ga_clear_strings(&ga); | |
1076 flags |= UC_VIM9; | |
1077 } | |
1078 | |
1040 uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg, | 1079 uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg, |
1041 addr_type_arg, eap->forceit); | 1080 addr_type_arg, eap->forceit); |
1081 vim_free(tofree); | |
1082 } | |
1042 } | 1083 } |
1043 | 1084 |
1044 /* | 1085 /* |
1045 * ":comclear" implementation | 1086 * ":comclear" implementation |
1046 * Clear all user commands, global and for current buffer. | 1087 * Clear all user commands, global and for current buffer. |