Mercurial > vim
comparison src/userfunc.c @ 26792:30d8377ea1b1 v8.2.3924
patch 8.2.3924: Vim9: no error if something follows :enddef
Commit: https://github.com/vim/vim/commit/7473a84cf935f64ddd4ea7fe7eee0f9c51c50b60
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Dec 28 17:55:26 2021 +0000
patch 8.2.3924: Vim9: no error if something follows :enddef
Problem: Vim9: no error if something follows :enddef in a nested function.
Solution: Give an error. Move common code to a function.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 28 Dec 2021 19:00:05 +0100 |
parents | 83b35c75c21a |
children | f40798bc2a50 |
comparison
equal
deleted
inserted
replaced
26791:43989ce10dd1 | 26792:30d8377ea1b1 |
---|---|
161 ((char_u **)argtypes->ga_data)[argtypes->ga_len++] = type; | 161 ((char_u **)argtypes->ga_data)[argtypes->ga_len++] = type; |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 return p; | 165 return p; |
166 } | |
167 | |
168 /* | |
169 * Handle line continuation in function arguments or body. | |
170 * Get a next line, store it in "eap" if appropriate and use "line_to_free" to | |
171 * handle freeing the line later. | |
172 */ | |
173 static char_u * | |
174 get_function_line( | |
175 exarg_T *eap, | |
176 char_u **line_to_free, | |
177 getline_opt_T getline_options, | |
178 int indent) | |
179 { | |
180 char_u *theline; | |
181 | |
182 if (eap->getline == NULL) | |
183 theline = getcmdline(':', 0L, indent, getline_options); | |
184 else | |
185 theline = eap->getline(':', eap->cookie, indent, getline_options); | |
186 if (theline != NULL) | |
187 { | |
188 if (*eap->cmdlinep == *line_to_free) | |
189 *eap->cmdlinep = theline; | |
190 vim_free(*line_to_free); | |
191 *line_to_free = theline; | |
192 } | |
193 | |
194 return theline; | |
166 } | 195 } |
167 | 196 |
168 /* | 197 /* |
169 * Get function arguments. | 198 * Get function arguments. |
170 * "argp" should point to just after the "(", possibly to white space. | 199 * "argp" should point to just after the "(", possibly to white space. |
210 while (*p != endchar) | 239 while (*p != endchar) |
211 { | 240 { |
212 while (eap != NULL && eap->getline != NULL | 241 while (eap != NULL && eap->getline != NULL |
213 && (*p == NUL || (VIM_ISWHITE(*whitep) && *p == '#'))) | 242 && (*p == NUL || (VIM_ISWHITE(*whitep) && *p == '#'))) |
214 { | 243 { |
215 char_u *theline; | |
216 | |
217 // End of the line, get the next one. | 244 // End of the line, get the next one. |
218 theline = eap->getline(':', eap->cookie, 0, TRUE); | 245 char_u *theline = get_function_line(eap, line_to_free, 0, TRUE); |
246 | |
219 if (theline == NULL) | 247 if (theline == NULL) |
220 break; | 248 break; |
221 vim_free(*line_to_free); | |
222 if (*eap->cmdlinep == *line_to_free) | |
223 *eap->cmdlinep = theline; | |
224 *line_to_free = theline; | |
225 whitep = (char_u *)" "; | 249 whitep = (char_u *)" "; |
226 p = skipwhite(theline); | 250 p = skipwhite(theline); |
227 } | 251 } |
228 | 252 |
229 if (mustend && *p != endchar) | 253 if (mustend && *p != endchar) |
718 line_arg = p + 1; | 742 line_arg = p + 1; |
719 } | 743 } |
720 } | 744 } |
721 else | 745 else |
722 { | 746 { |
723 if (eap->getline == NULL) | 747 theline = get_function_line(eap, line_to_free, indent, |
724 theline = getcmdline(':', 0L, indent, getline_options); | |
725 else | |
726 theline = eap->getline(':', eap->cookie, indent, | |
727 getline_options); | 748 getline_options); |
728 if (*eap->cmdlinep == *line_to_free) | |
729 *eap->cmdlinep = theline; | |
730 vim_free(*line_to_free); | |
731 *line_to_free = theline; | |
732 } | 749 } |
733 if (KeyTyped) | 750 if (KeyTyped) |
734 lines_left = Rows - 1; | 751 lines_left = Rows - 1; |
735 if (theline == NULL) | 752 if (theline == NULL) |
736 { | 753 { |
825 && (vim9_function || p_verbose > 0)) | 842 && (vim9_function || p_verbose > 0)) |
826 { | 843 { |
827 SOURCING_LNUM = sourcing_lnum_top | 844 SOURCING_LNUM = sourcing_lnum_top |
828 + newlines->ga_len + 1; | 845 + newlines->ga_len + 1; |
829 if (eap->cmdidx == CMD_def) | 846 if (eap->cmdidx == CMD_def) |
830 semsg(_(e_text_found_after_enddef_str), p); | 847 semsg(_(e_text_found_after_str_str), "enddef", p); |
831 else | 848 else |
832 give_warning2((char_u *) | 849 give_warning2((char_u *) |
833 _("W22: Text found after :endfunction: %s"), | 850 _("W22: Text found after :endfunction: %s"), |
834 p, TRUE); | 851 p, TRUE); |
835 } | 852 } |