Mercurial > vim
comparison src/eval.c @ 29062:036b4d49c4a0 v8.2.5053
patch 8.2.5053: cannot have a comment halfway an expression in a block
Commit: https://github.com/vim/vim/commit/75ebd2aab0f009049561f60424d521ba5f80063a
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jun 3 17:39:46 2022 +0100
patch 8.2.5053: cannot have a comment halfway an expression in a block
Problem: Cannot have a comment halfway an expression in an autocmd command
block.
Solution: When skipping over the NL also skip over comments. (closes #10519)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 03 Jun 2022 18:45:05 +0200 |
parents | c98fc7a4dde4 |
children | 949e8978ea43 |
comparison
equal
deleted
inserted
replaced
29061:420b1439214e | 29062:036b4d49c4a0 |
---|---|
2134 } | 2134 } |
2135 return ret; | 2135 return ret; |
2136 } | 2136 } |
2137 | 2137 |
2138 /* | 2138 /* |
2139 * After a NL, skip over empty lines and comment-only lines. | |
2140 */ | |
2141 static char_u * | |
2142 newline_skip_comments(char_u *arg) | |
2143 { | |
2144 char_u *p = arg + 1; | |
2145 | |
2146 for (;;) | |
2147 { | |
2148 p = skipwhite(p); | |
2149 | |
2150 if (*p == NUL) | |
2151 break; | |
2152 if (vim9_comment_start(p)) | |
2153 { | |
2154 char_u *nl = vim_strchr(p, NL); | |
2155 | |
2156 if (nl == NULL) | |
2157 break; | |
2158 p = nl; | |
2159 } | |
2160 if (*p != NL) | |
2161 break; | |
2162 ++p; // skip another NL | |
2163 } | |
2164 return p; | |
2165 } | |
2166 | |
2167 /* | |
2139 * Get the next line source line without advancing. But do skip over comment | 2168 * Get the next line source line without advancing. But do skip over comment |
2140 * lines. | 2169 * lines. |
2141 * Only called for Vim9 script. | 2170 * Only called for Vim9 script. |
2142 */ | 2171 */ |
2143 static char_u * | 2172 static char_u * |
2182 || (vim9_comment_start(p) && VIM_ISWHITE(p[-1])))) | 2211 || (vim9_comment_start(p) && VIM_ISWHITE(p[-1])))) |
2183 { | 2212 { |
2184 char_u *next; | 2213 char_u *next; |
2185 | 2214 |
2186 if (*p == NL) | 2215 if (*p == NL) |
2187 next = p + 1; | 2216 next = newline_skip_comments(p); |
2188 else if (evalarg->eval_cookie != NULL) | 2217 else if (evalarg->eval_cookie != NULL) |
2189 next = getline_peek_skip_comments(evalarg); | 2218 next = getline_peek_skip_comments(evalarg); |
2190 else | 2219 else |
2191 next = peek_next_line_from_context(evalarg->eval_cctx); | 2220 next = peek_next_line_from_context(evalarg->eval_cctx); |
2192 | 2221 |
2210 char_u *line; | 2239 char_u *line; |
2211 | 2240 |
2212 if (arg != NULL) | 2241 if (arg != NULL) |
2213 { | 2242 { |
2214 if (*arg == NL) | 2243 if (*arg == NL) |
2215 return skipwhite(arg + 1); | 2244 return newline_skip_comments(arg); |
2216 // Truncate before a trailing comment, so that concatenating the lines | 2245 // Truncate before a trailing comment, so that concatenating the lines |
2217 // won't turn the rest into a comment. | 2246 // won't turn the rest into a comment. |
2218 if (*skipwhite(arg) == '#') | 2247 if (*skipwhite(arg) == '#') |
2219 *arg = NUL; | 2248 *arg = NUL; |
2220 } | 2249 } |