Mercurial > vim
comparison src/fileio.c @ 9653:01c9630e80e0 v7.4.2103
commit https://github.com/vim/vim/commit/e99e84497b89e5f91df519790802770920ecf4fe
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jul 26 20:43:40 2016 +0200
patch 7.4.2103
Problem: Can't have "augroup END" right after ":au!".
Solution: Check for the bar character before the command argument.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 26 Jul 2016 20:45:06 +0200 |
parents | fd9727ae3c49 |
children | a98607bb756c |
comparison
equal
deleted
inserted
replaced
9652:1869038e346b | 9653:01c9630e80e0 |
---|---|
8098 { | 8098 { |
8099 char_u *p; | 8099 char_u *p; |
8100 int i; | 8100 int i; |
8101 int len; | 8101 int len; |
8102 | 8102 |
8103 /* the event name ends with end of line, a blank or a comma */ | 8103 /* the event name ends with end of line, '|', a blank or a comma */ |
8104 for (p = start; *p && !vim_iswhite(*p) && *p != ','; ++p) | 8104 for (p = start; *p && !vim_iswhite(*p) && *p != ',' && *p != '|'; ++p) |
8105 ; | 8105 ; |
8106 for (i = 0; event_names[i].name != NULL; ++i) | 8106 for (i = 0; event_names[i].name != NULL; ++i) |
8107 { | 8107 { |
8108 len = (int)STRLEN(event_names[i].name); | 8108 len = (int)STRLEN(event_names[i].name); |
8109 if (len == p - start && STRNICMP(event_names[i].name, start, len) == 0) | 8109 if (len == p - start && STRNICMP(event_names[i].name, start, len) == 0) |
8151 } | 8151 } |
8152 pat = arg + 1; | 8152 pat = arg + 1; |
8153 } | 8153 } |
8154 else | 8154 else |
8155 { | 8155 { |
8156 for (pat = arg; *pat && !vim_iswhite(*pat); pat = p) | 8156 for (pat = arg; *pat && *pat != '|' && !vim_iswhite(*pat); pat = p) |
8157 { | 8157 { |
8158 if ((int)event_name2nr(pat, &p) >= (int)NUM_EVENTS) | 8158 if ((int)event_name2nr(pat, &p) >= (int)NUM_EVENTS) |
8159 { | 8159 { |
8160 if (have_group) | 8160 if (have_group) |
8161 EMSG2(_("E216: No such event: %s"), pat); | 8161 EMSG2(_("E216: No such event: %s"), pat); |
8284 * :autocmd * *.c show all autocommands for *.c files. | 8284 * :autocmd * *.c show all autocommands for *.c files. |
8285 * | 8285 * |
8286 * Mostly a {group} argument can optionally appear before <event>. | 8286 * Mostly a {group} argument can optionally appear before <event>. |
8287 */ | 8287 */ |
8288 void | 8288 void |
8289 do_autocmd(char_u *arg, int forceit) | 8289 do_autocmd(char_u *arg_in, int forceit) |
8290 { | 8290 { |
8291 char_u *arg = arg_in; | |
8291 char_u *pat; | 8292 char_u *pat; |
8292 char_u *envpat = NULL; | 8293 char_u *envpat = NULL; |
8293 char_u *cmd; | 8294 char_u *cmd; |
8294 event_T event; | 8295 event_T event; |
8295 int need_free = FALSE; | 8296 int need_free = FALSE; |
8296 int nested = FALSE; | 8297 int nested = FALSE; |
8297 int group; | 8298 int group; |
8298 | 8299 |
8299 /* | 8300 if (*arg == '|') |
8300 * Check for a legal group name. If not, use AUGROUP_ALL. | 8301 { |
8301 */ | 8302 arg = (char_u *)""; |
8302 group = au_get_grouparg(&arg); | 8303 group = AUGROUP_ALL; /* no argument, use all groups */ |
8303 if (arg == NULL) /* out of memory */ | 8304 } |
8304 return; | 8305 else |
8306 { | |
8307 /* | |
8308 * Check for a legal group name. If not, use AUGROUP_ALL. | |
8309 */ | |
8310 group = au_get_grouparg(&arg); | |
8311 if (arg == NULL) /* out of memory */ | |
8312 return; | |
8313 } | |
8305 | 8314 |
8306 /* | 8315 /* |
8307 * Scan over the events. | 8316 * Scan over the events. |
8308 * If we find an illegal name, return here, don't do anything. | 8317 * If we find an illegal name, return here, don't do anything. |
8309 */ | 8318 */ |
8310 pat = find_end_event(arg, group != AUGROUP_ALL); | 8319 pat = find_end_event(arg, group != AUGROUP_ALL); |
8311 if (pat == NULL) | 8320 if (pat == NULL) |
8312 return; | 8321 return; |
8313 | 8322 |
8314 /* | |
8315 * Scan over the pattern. Put a NUL at the end. | |
8316 */ | |
8317 pat = skipwhite(pat); | 8323 pat = skipwhite(pat); |
8318 cmd = pat; | 8324 if (*pat == '|') |
8319 while (*cmd && (!vim_iswhite(*cmd) || cmd[-1] == '\\')) | 8325 { |
8320 cmd++; | 8326 pat = (char_u *)""; |
8321 if (*cmd) | 8327 cmd = (char_u *)""; |
8322 *cmd++ = NUL; | 8328 } |
8323 | 8329 else |
8324 /* Expand environment variables in the pattern. Set 'shellslash', we want | 8330 { |
8325 * forward slashes here. */ | 8331 /* |
8326 if (vim_strchr(pat, '$') != NULL || vim_strchr(pat, '~') != NULL) | 8332 * Scan over the pattern. Put a NUL at the end. |
8327 { | 8333 */ |
8334 cmd = pat; | |
8335 while (*cmd && (!vim_iswhite(*cmd) || cmd[-1] == '\\')) | |
8336 cmd++; | |
8337 if (*cmd) | |
8338 *cmd++ = NUL; | |
8339 | |
8340 /* Expand environment variables in the pattern. Set 'shellslash', we want | |
8341 * forward slashes here. */ | |
8342 if (vim_strchr(pat, '$') != NULL || vim_strchr(pat, '~') != NULL) | |
8343 { | |
8328 #ifdef BACKSLASH_IN_FILENAME | 8344 #ifdef BACKSLASH_IN_FILENAME |
8329 int p_ssl_save = p_ssl; | 8345 int p_ssl_save = p_ssl; |
8330 | 8346 |
8331 p_ssl = TRUE; | 8347 p_ssl = TRUE; |
8332 #endif | 8348 #endif |
8333 envpat = expand_env_save(pat); | 8349 envpat = expand_env_save(pat); |
8334 #ifdef BACKSLASH_IN_FILENAME | 8350 #ifdef BACKSLASH_IN_FILENAME |
8335 p_ssl = p_ssl_save; | 8351 p_ssl = p_ssl_save; |
8336 #endif | 8352 #endif |
8337 if (envpat != NULL) | 8353 if (envpat != NULL) |
8338 pat = envpat; | 8354 pat = envpat; |
8339 } | 8355 } |
8340 | 8356 |
8341 /* | 8357 /* |
8342 * Check for "nested" flag. | 8358 * Check for "nested" flag. |
8343 */ | 8359 */ |
8344 cmd = skipwhite(cmd); | 8360 cmd = skipwhite(cmd); |
8345 if (*cmd != NUL && STRNCMP(cmd, "nested", 6) == 0 && vim_iswhite(cmd[6])) | 8361 if (*cmd != NUL && STRNCMP(cmd, "nested", 6) == 0 && vim_iswhite(cmd[6])) |
8346 { | 8362 { |
8347 nested = TRUE; | 8363 nested = TRUE; |
8348 cmd = skipwhite(cmd + 6); | 8364 cmd = skipwhite(cmd + 6); |
8349 } | 8365 } |
8350 | 8366 |
8351 /* | 8367 /* |
8352 * Find the start of the commands. | 8368 * Find the start of the commands. |
8353 * Expand <sfile> in it. | 8369 * Expand <sfile> in it. |
8354 */ | 8370 */ |
8355 if (*cmd != NUL) | 8371 if (*cmd != NUL) |
8356 { | 8372 { |
8357 cmd = expand_sfile(cmd); | 8373 cmd = expand_sfile(cmd); |
8358 if (cmd == NULL) /* some error */ | 8374 if (cmd == NULL) /* some error */ |
8359 return; | 8375 return; |
8360 need_free = TRUE; | 8376 need_free = TRUE; |
8377 } | |
8361 } | 8378 } |
8362 | 8379 |
8363 /* | 8380 /* |
8364 * Print header when showing autocommands. | 8381 * Print header when showing autocommands. |
8365 */ | 8382 */ |
8372 /* | 8389 /* |
8373 * Loop over the events. | 8390 * Loop over the events. |
8374 */ | 8391 */ |
8375 last_event = (event_T)-1; /* for listing the event name */ | 8392 last_event = (event_T)-1; /* for listing the event name */ |
8376 last_group = AUGROUP_ERROR; /* for listing the group name */ | 8393 last_group = AUGROUP_ERROR; /* for listing the group name */ |
8377 if (*arg == '*' || *arg == NUL) | 8394 if (*arg == '*' || *arg == NUL || *arg == '|') |
8378 { | 8395 { |
8379 for (event = (event_T)0; (int)event < (int)NUM_EVENTS; | 8396 for (event = (event_T)0; (int)event < (int)NUM_EVENTS; |
8380 event = (event_T)((int)event + 1)) | 8397 event = (event_T)((int)event + 1)) |
8381 if (do_autocmd_event(event, pat, | 8398 if (do_autocmd_event(event, pat, |
8382 nested, cmd, forceit, group) == FAIL) | 8399 nested, cmd, forceit, group) == FAIL) |
8383 break; | 8400 break; |
8384 } | 8401 } |
8385 else | 8402 else |
8386 { | 8403 { |
8387 while (*arg && !vim_iswhite(*arg)) | 8404 while (*arg && *arg != '|' && !vim_iswhite(*arg)) |
8388 if (do_autocmd_event(event_name2nr(arg, &arg), pat, | 8405 if (do_autocmd_event(event_name2nr(arg, &arg), pat, |
8389 nested, cmd, forceit, group) == FAIL) | 8406 nested, cmd, forceit, group) == FAIL) |
8390 break; | 8407 break; |
8391 } | 8408 } |
8392 | 8409 |
8407 char_u *group_name; | 8424 char_u *group_name; |
8408 char_u *p; | 8425 char_u *p; |
8409 char_u *arg = *argp; | 8426 char_u *arg = *argp; |
8410 int group = AUGROUP_ALL; | 8427 int group = AUGROUP_ALL; |
8411 | 8428 |
8412 p = skiptowhite(arg); | 8429 for (p = arg; *p && !vim_iswhite(*p) && *p != '|'; ++p) |
8430 ; | |
8413 if (p > arg) | 8431 if (p > arg) |
8414 { | 8432 { |
8415 group_name = vim_strnsave(arg, (int)(p - arg)); | 8433 group_name = vim_strnsave(arg, (int)(p - arg)); |
8416 if (group_name == NULL) /* out of memory */ | 8434 if (group_name == NULL) /* out of memory */ |
8417 return AUGROUP_ERROR; | 8435 return AUGROUP_ERROR; |