Mercurial > vim
comparison src/autocmd.c @ 30465:b3367a7a3914 v9.0.0568
patch 9.0.0568: autocmd code is indented more than needed
Commit: https://github.com/vim/vim/commit/e9dcf13a3007d4f603e007e0526b0005fd026bc5
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Sat Sep 24 11:30:41 2022 +0100
patch 9.0.0568: autocmd code is indented more than needed
Problem: Autocmd code is indented more than needed.
Solution: Break out sooner. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/11208)
Also in user function code.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 24 Sep 2022 12:45:03 +0200 |
parents | 27cb0eed6aef |
children | 74043ee52030 |
comparison
equal
deleted
inserted
replaced
30464:00e127edb23a | 30465:b3367a7a3914 |
---|---|
318 msg_col = 4; | 318 msg_col = 4; |
319 msg_outtrans(ap->pat); | 319 msg_outtrans(ap->pat); |
320 | 320 |
321 for (ac = ap->cmds; ac != NULL; ac = ac->next) | 321 for (ac = ap->cmds; ac != NULL; ac = ac->next) |
322 { | 322 { |
323 if (ac->cmd != NULL) // skip removed commands | 323 if (ac->cmd == NULL) // skip removed commands |
324 { | 324 continue; |
325 if (msg_col >= 14) | 325 |
326 msg_putchar('\n'); | 326 if (msg_col >= 14) |
327 msg_col = 14; | 327 msg_putchar('\n'); |
328 msg_col = 14; | |
329 if (got_int) | |
330 return; | |
331 msg_outtrans(ac->cmd); | |
332 #ifdef FEAT_EVAL | |
333 if (p_verbose > 0) | |
334 last_set_msg(ac->script_ctx); | |
335 #endif | |
336 if (got_int) | |
337 return; | |
338 if (ac->next != NULL) | |
339 { | |
340 msg_putchar('\n'); | |
328 if (got_int) | 341 if (got_int) |
329 return; | 342 return; |
330 msg_outtrans(ac->cmd); | |
331 #ifdef FEAT_EVAL | |
332 if (p_verbose > 0) | |
333 last_set_msg(ac->script_ctx); | |
334 #endif | |
335 if (got_int) | |
336 return; | |
337 if (ac->next != NULL) | |
338 { | |
339 msg_putchar('\n'); | |
340 if (got_int) | |
341 return; | |
342 } | |
343 } | 343 } |
344 } | 344 } |
345 } | 345 } |
346 | 346 |
347 /* | 347 /* |
490 au_new_group(char_u *name) | 490 au_new_group(char_u *name) |
491 { | 491 { |
492 int i; | 492 int i; |
493 | 493 |
494 i = au_find_group(name); | 494 i = au_find_group(name); |
495 if (i == AUGROUP_ERROR) // the group doesn't exist yet, add it | 495 if (i != AUGROUP_ERROR) |
496 { | 496 return i; |
497 // First try using a free entry. | 497 |
498 for (i = 0; i < augroups.ga_len; ++i) | 498 // the group doesn't exist yet, add it. First try using a free entry. |
499 if (AUGROUP_NAME(i) == NULL) | 499 for (i = 0; i < augroups.ga_len; ++i) |
500 break; | |
501 if (i == augroups.ga_len && ga_grow(&augroups, 1) == FAIL) | |
502 return AUGROUP_ERROR; | |
503 | |
504 AUGROUP_NAME(i) = vim_strsave(name); | |
505 if (AUGROUP_NAME(i) == NULL) | 500 if (AUGROUP_NAME(i) == NULL) |
506 return AUGROUP_ERROR; | 501 break; |
507 if (i == augroups.ga_len) | 502 if (i == augroups.ga_len && ga_grow(&augroups, 1) == FAIL) |
508 ++augroups.ga_len; | 503 return AUGROUP_ERROR; |
509 } | 504 |
505 AUGROUP_NAME(i) = vim_strsave(name); | |
506 if (AUGROUP_NAME(i) == NULL) | |
507 return AUGROUP_ERROR; | |
508 if (i == augroups.ga_len) | |
509 ++augroups.ga_len; | |
510 | 510 |
511 return i; | 511 return i; |
512 } | 512 } |
513 | 513 |
514 static void | 514 static void |
515 au_del_group(char_u *name) | 515 au_del_group(char_u *name) |
516 { | 516 { |
517 int i; | 517 int i; |
518 event_T event; | |
519 AutoPat *ap; | |
520 int in_use = FALSE; | |
521 | |
518 | 522 |
519 i = au_find_group(name); | 523 i = au_find_group(name); |
520 if (i == AUGROUP_ERROR) // the group doesn't exist | 524 if (i == AUGROUP_ERROR) // the group doesn't exist |
525 { | |
521 semsg(_(e_no_such_group_str), name); | 526 semsg(_(e_no_such_group_str), name); |
522 else if (i == current_augroup) | 527 return; |
528 } | |
529 if (i == current_augroup) | |
530 { | |
523 emsg(_(e_cannot_delete_current_group)); | 531 emsg(_(e_cannot_delete_current_group)); |
532 return; | |
533 } | |
534 | |
535 for (event = (event_T)0; (int)event < NUM_EVENTS; | |
536 event = (event_T)((int)event + 1)) | |
537 { | |
538 FOR_ALL_AUTOCMD_PATTERNS(event, ap) | |
539 if (ap->group == i && ap->pat != NULL) | |
540 { | |
541 give_warning((char_u *)_("W19: Deleting augroup that is still in use"), TRUE); | |
542 in_use = TRUE; | |
543 event = NUM_EVENTS; | |
544 break; | |
545 } | |
546 } | |
547 vim_free(AUGROUP_NAME(i)); | |
548 if (in_use) | |
549 AUGROUP_NAME(i) = get_deleted_augroup(); | |
524 else | 550 else |
525 { | 551 AUGROUP_NAME(i) = NULL; |
526 event_T event; | |
527 AutoPat *ap; | |
528 int in_use = FALSE; | |
529 | |
530 for (event = (event_T)0; (int)event < NUM_EVENTS; | |
531 event = (event_T)((int)event + 1)) | |
532 { | |
533 FOR_ALL_AUTOCMD_PATTERNS(event, ap) | |
534 if (ap->group == i && ap->pat != NULL) | |
535 { | |
536 give_warning((char_u *)_("W19: Deleting augroup that is still in use"), TRUE); | |
537 in_use = TRUE; | |
538 event = NUM_EVENTS; | |
539 break; | |
540 } | |
541 } | |
542 vim_free(AUGROUP_NAME(i)); | |
543 if (in_use) | |
544 AUGROUP_NAME(i) = get_deleted_augroup(); | |
545 else | |
546 AUGROUP_NAME(i) = NULL; | |
547 } | |
548 } | 552 } |
549 | 553 |
550 /* | 554 /* |
551 * Find the ID of an autocmd group name. | 555 * Find the ID of an autocmd group name. |
552 * Return its ID. Returns AUGROUP_ERROR (< 0) for error. | 556 * Return its ID. Returns AUGROUP_ERROR (< 0) for error. |
766 { | 770 { |
767 char_u *new_ei; | 771 char_u *new_ei; |
768 char_u *save_ei; | 772 char_u *save_ei; |
769 | 773 |
770 save_ei = vim_strsave(p_ei); | 774 save_ei = vim_strsave(p_ei); |
771 if (save_ei != NULL) | 775 if (save_ei == NULL) |
772 { | 776 return NULL; |
773 new_ei = vim_strnsave(p_ei, STRLEN(p_ei) + STRLEN(what)); | 777 |
774 if (new_ei != NULL) | 778 new_ei = vim_strnsave(p_ei, STRLEN(p_ei) + STRLEN(what)); |
775 { | 779 if (new_ei == NULL) |
776 if (*what == ',' && *p_ei == NUL) | 780 { |
777 STRCPY(new_ei, what + 1); | 781 vim_free(save_ei); |
778 else | 782 return NULL; |
779 STRCAT(new_ei, what); | 783 } |
780 set_string_option_direct((char_u *)"ei", -1, new_ei, | 784 |
781 OPT_FREE, SID_NONE); | 785 if (*what == ',' && *p_ei == NUL) |
782 vim_free(new_ei); | 786 STRCPY(new_ei, what + 1); |
783 } | 787 else |
784 } | 788 STRCAT(new_ei, what); |
789 set_string_option_direct((char_u *)"ei", -1, new_ei, | |
790 OPT_FREE, SID_NONE); | |
791 vim_free(new_ei); | |
785 return save_ei; | 792 return save_ei; |
786 } | 793 } |
787 | 794 |
788 void | 795 void |
789 au_event_restore(char_u *old_ei) | 796 au_event_restore(char_u *old_ei) |
906 } | 913 } |
907 | 914 |
908 cmd = skipwhite(cmd); | 915 cmd = skipwhite(cmd); |
909 for (i = 0; i < 2; i++) | 916 for (i = 0; i < 2; i++) |
910 { | 917 { |
911 if (*cmd != NUL) | 918 if (*cmd == NUL) |
919 continue; | |
920 | |
921 // Check for "++once" flag. | |
922 if (STRNCMP(cmd, "++once", 6) == 0 && VIM_ISWHITE(cmd[6])) | |
912 { | 923 { |
913 // Check for "++once" flag. | 924 if (once) |
914 if (STRNCMP(cmd, "++once", 6) == 0 && VIM_ISWHITE(cmd[6])) | 925 semsg(_(e_duplicate_argument_str), "++once"); |
926 once = TRUE; | |
927 cmd = skipwhite(cmd + 6); | |
928 } | |
929 | |
930 // Check for "++nested" flag. | |
931 if ((STRNCMP(cmd, "++nested", 8) == 0 && VIM_ISWHITE(cmd[8]))) | |
932 { | |
933 if (nested) | |
915 { | 934 { |
916 if (once) | 935 semsg(_(e_duplicate_argument_str), "++nested"); |
917 semsg(_(e_duplicate_argument_str), "++once"); | 936 return; |
918 once = TRUE; | |
919 cmd = skipwhite(cmd + 6); | |
920 } | 937 } |
921 | 938 nested = TRUE; |
922 // Check for "++nested" flag. | 939 cmd = skipwhite(cmd + 8); |
923 if ((STRNCMP(cmd, "++nested", 8) == 0 && VIM_ISWHITE(cmd[8]))) | 940 } |
941 | |
942 // Check for the old "nested" flag in legacy script. | |
943 if (STRNCMP(cmd, "nested", 6) == 0 && VIM_ISWHITE(cmd[6])) | |
944 { | |
945 if (in_vim9script()) | |
924 { | 946 { |
925 if (nested) | 947 // If there ever is a :nested command this error should |
926 { | 948 // be removed and "nested" accepted as the start of the |
927 semsg(_(e_duplicate_argument_str), "++nested"); | 949 // command. |
928 return; | 950 emsg(_(e_invalid_command_nested_did_you_mean_plusplus_nested)); |
929 } | 951 return; |
930 nested = TRUE; | |
931 cmd = skipwhite(cmd + 8); | |
932 } | 952 } |
933 | 953 if (nested) |
934 // Check for the old "nested" flag in legacy script. | |
935 if (STRNCMP(cmd, "nested", 6) == 0 && VIM_ISWHITE(cmd[6])) | |
936 { | 954 { |
937 if (in_vim9script()) | 955 semsg(_(e_duplicate_argument_str), "nested"); |
938 { | 956 return; |
939 // If there ever is a :nested command this error should | |
940 // be removed and "nested" accepted as the start of the | |
941 // command. | |
942 emsg(_(e_invalid_command_nested_did_you_mean_plusplus_nested)); | |
943 return; | |
944 } | |
945 if (nested) | |
946 { | |
947 semsg(_(e_duplicate_argument_str), "nested"); | |
948 return; | |
949 } | |
950 nested = TRUE; | |
951 cmd = skipwhite(cmd + 6); | |
952 } | 957 } |
958 nested = TRUE; | |
959 cmd = skipwhite(cmd + 6); | |
953 } | 960 } |
954 } | 961 } |
955 | 962 |
956 /* | 963 /* |
957 * Find the start of the commands. | 964 * Find the start of the commands. |
1405 * buffers or windows... | 1412 * buffers or windows... |
1406 */ | 1413 */ |
1407 FOR_ALL_BUFFERS(buf) | 1414 FOR_ALL_BUFFERS(buf) |
1408 { | 1415 { |
1409 // Only do loaded buffers and skip the current buffer, it's done last. | 1416 // Only do loaded buffers and skip the current buffer, it's done last. |
1410 if (buf->b_ml.ml_mfp != NULL && buf != curbuf) | 1417 if (buf->b_ml.ml_mfp == NULL || buf == curbuf) |
1411 { | 1418 continue; |
1412 // find a window for this buffer and save some values | 1419 |
1413 aucmd_prepbuf(&aco, buf); | 1420 // find a window for this buffer and save some values |
1414 set_bufref(&bufref, buf); | 1421 aucmd_prepbuf(&aco, buf); |
1415 | 1422 set_bufref(&bufref, buf); |
1416 // execute the autocommands for this buffer | 1423 |
1417 retval = do_doautocmd(arg, FALSE, &did_aucmd); | 1424 // execute the autocommands for this buffer |
1418 | 1425 retval = do_doautocmd(arg, FALSE, &did_aucmd); |
1419 if (call_do_modelines && did_aucmd) | 1426 |
1420 // Execute the modeline settings, but don't set window-local | 1427 if (call_do_modelines && did_aucmd) |
1421 // options if we are using the current window for another | 1428 // Execute the modeline settings, but don't set window-local |
1422 // buffer. | 1429 // options if we are using the current window for another |
1423 do_modelines(curwin == aucmd_win ? OPT_NOWIN : 0); | 1430 // buffer. |
1424 | 1431 do_modelines(curwin == aucmd_win ? OPT_NOWIN : 0); |
1425 // restore the current window | 1432 |
1426 aucmd_restbuf(&aco); | 1433 // restore the current window |
1427 | 1434 aucmd_restbuf(&aco); |
1428 // stop if there is some error or buffer was deleted | 1435 |
1429 if (retval == FAIL || !bufref_valid(&bufref)) | 1436 // stop if there is some error or buffer was deleted |
1430 { | 1437 if (retval == FAIL || !bufref_valid(&bufref)) |
1431 retval = FAIL; | 1438 { |
1432 break; | 1439 retval = FAIL; |
1433 } | 1440 break; |
1434 } | 1441 } |
1435 } | 1442 } |
1436 | 1443 |
1437 // Execute autocommands for the current buffer last. | 1444 // Execute autocommands for the current buffer last. |
1438 if (retval == OK) | 1445 if (retval == OK) |