comparison src/syntax.c @ 31809:543153d582d5 v9.0.1237

patch 9.0.1237: code is indented more than necessary Commit: https://github.com/vim/vim/commit/6ec66660476562e643deceb7c325cd0e8c903663 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Mon Jan 23 20:46:21 2023 +0000 patch 9.0.1237: code is indented more than necessary Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11858)
author Bram Moolenaar <Bram@vim.org>
date Mon, 23 Jan 2023 22:00:04 +0100
parents 53c3df37a2b0
children e16361210675
comparison
equal deleted inserted replaced
31808:e1d9d84d0eba 31809:543153d582d5
853 } 853 }
854 854
855 static void 855 static void
856 save_chartab(char_u *chartab) 856 save_chartab(char_u *chartab)
857 { 857 {
858 if (syn_block->b_syn_isk != empty_option) 858 if (syn_block->b_syn_isk == empty_option)
859 { 859 return;
860 mch_memmove(chartab, syn_buf->b_chartab, (size_t)32); 860
861 mch_memmove(syn_buf->b_chartab, syn_win->w_s->b_syn_chartab, 861 mch_memmove(chartab, syn_buf->b_chartab, (size_t)32);
862 (size_t)32); 862 mch_memmove(syn_buf->b_chartab, syn_win->w_s->b_syn_chartab, (size_t)32);
863 }
864 } 863 }
865 864
866 static void 865 static void
867 restore_chartab(char_u *chartab) 866 restore_chartab(char_u *chartab)
868 { 867 {
878 { 877 {
879 regmmatch_T regmatch; 878 regmmatch_T regmatch;
880 int r; 879 int r;
881 char_u buf_chartab[32]; // chartab array for syn iskyeyword 880 char_u buf_chartab[32]; // chartab array for syn iskyeyword
882 881
883 if (syn_block->b_syn_linecont_prog != NULL) 882 if (syn_block->b_syn_linecont_prog == NULL)
884 { 883 return FALSE;
885 // use syntax iskeyword option 884
886 save_chartab(buf_chartab); 885 // use syntax iskeyword option
887 regmatch.rmm_ic = syn_block->b_syn_linecont_ic; 886 save_chartab(buf_chartab);
888 regmatch.regprog = syn_block->b_syn_linecont_prog; 887 regmatch.rmm_ic = syn_block->b_syn_linecont_ic;
889 r = syn_regexec(&regmatch, lnum, (colnr_T)0, 888 regmatch.regprog = syn_block->b_syn_linecont_prog;
890 IF_SYN_TIME(&syn_block->b_syn_linecont_time)); 889 r = syn_regexec(&regmatch, lnum, (colnr_T)0,
891 syn_block->b_syn_linecont_prog = regmatch.regprog; 890 IF_SYN_TIME(&syn_block->b_syn_linecont_time));
892 restore_chartab(buf_chartab); 891 syn_block->b_syn_linecont_prog = regmatch.regprog;
893 return r; 892 restore_chartab(buf_chartab);
894 } 893 return r;
895 return FALSE;
896 } 894 }
897 895
898 /* 896 /*
899 * Prepare the current state for the start of a line. 897 * Prepare the current state for the start of a line.
900 */ 898 */
1028 static void 1026 static void
1029 syn_stack_free_block(synblock_T *block) 1027 syn_stack_free_block(synblock_T *block)
1030 { 1028 {
1031 synstate_T *p; 1029 synstate_T *p;
1032 1030
1033 if (block->b_sst_array != NULL) 1031 if (block->b_sst_array == NULL)
1034 { 1032 return;
1035 FOR_ALL_SYNSTATES(block, p) 1033
1036 clear_syn_state(p); 1034 FOR_ALL_SYNSTATES(block, p)
1037 VIM_CLEAR(block->b_sst_array); 1035 clear_syn_state(p);
1038 block->b_sst_first = NULL; 1036 VIM_CLEAR(block->b_sst_array);
1039 block->b_sst_len = 0; 1037 block->b_sst_first = NULL;
1040 } 1038 block->b_sst_len = 0;
1041 } 1039 }
1042 /* 1040 /*
1043 * Free b_sst_array[] for buffer "buf". 1041 * Free b_sst_array[] for buffer "buf".
1044 * Used when syntax items changed to force resyncing everywhere. 1042 * Used when syntax items changed to force resyncing everywhere.
1045 */ 1043 */
5435 { 5433 {
5436 char_u *name; 5434 char_u *name;
5437 int id = 0; 5435 int id = 0;
5438 5436
5439 name = vim_strnsave(linep, len); 5437 name = vim_strnsave(linep, len);
5440 if (name != NULL) 5438 if (name == NULL)
5441 { 5439 return 0;
5442 id = syn_scl_name2id(name); 5440
5443 vim_free(name); 5441 id = syn_scl_name2id(name);
5444 } 5442 vim_free(name);
5445 return id; 5443 return id;
5446 } 5444 }
5447 5445
5448 /* 5446 /*
5449 * Find syntax cluster name in the table and return its ID. 5447 * Find syntax cluster name in the table and return its ID.
6254 6252
6255 // isolate subcommand name 6253 // isolate subcommand name
6256 for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end) 6254 for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end)
6257 ; 6255 ;
6258 subcmd_name = vim_strnsave(arg, subcmd_end - arg); 6256 subcmd_name = vim_strnsave(arg, subcmd_end - arg);
6259 if (subcmd_name != NULL) 6257 if (subcmd_name == NULL)
6260 { 6258 return;
6261 if (eap->skip) // skip error messages for all subcommands 6259
6262 ++emsg_skip; 6260 if (eap->skip) // skip error messages for all subcommands
6263 for (i = 0; ; ++i) 6261 ++emsg_skip;
6264 { 6262 for (i = 0; ; ++i)
6265 if (subcommands[i].name == NULL) 6263 {
6266 { 6264 if (subcommands[i].name == NULL)
6267 semsg(_(e_invalid_syntax_subcommand_str), subcmd_name); 6265 {
6268 break; 6266 semsg(_(e_invalid_syntax_subcommand_str), subcmd_name);
6269 } 6267 break;
6270 if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0) 6268 }
6271 { 6269 if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0)
6272 eap->arg = skipwhite(subcmd_end); 6270 {
6273 (subcommands[i].func)(eap, FALSE); 6271 eap->arg = skipwhite(subcmd_end);
6274 break; 6272 (subcommands[i].func)(eap, FALSE);
6275 } 6273 break;
6276 } 6274 }
6277 vim_free(subcmd_name); 6275 }
6278 if (eap->skip) 6276 vim_free(subcmd_name);
6279 --emsg_skip; 6277 if (eap->skip)
6280 } 6278 --emsg_skip;
6281 } 6279 }
6282 6280
6283 void 6281 void
6284 ex_ownsyntax(exarg_T *eap) 6282 ex_ownsyntax(exarg_T *eap)
6285 { 6283 {
6382 expand_what = EXP_SUBCMD; 6380 expand_what = EXP_SUBCMD;
6383 xp->xp_pattern = arg; 6381 xp->xp_pattern = arg;
6384 include_link = 0; 6382 include_link = 0;
6385 include_default = 0; 6383 include_default = 0;
6386 6384
6385 if (*arg == NUL)
6386 return;
6387
6387 // (part of) subcommand already typed 6388 // (part of) subcommand already typed
6388 if (*arg != NUL) 6389 p = skiptowhite(arg);
6389 { 6390 if (*p == NUL)
6390 p = skiptowhite(arg); 6391 return;
6391 if (*p != NUL) // past first word 6392
6392 { 6393 // past first word
6393 xp->xp_pattern = skipwhite(p); 6394 xp->xp_pattern = skipwhite(p);
6394 if (*skiptowhite(xp->xp_pattern) != NUL) 6395 if (*skiptowhite(xp->xp_pattern) != NUL)
6395 xp->xp_context = EXPAND_NOTHING; 6396 xp->xp_context = EXPAND_NOTHING;
6396 else if (STRNICMP(arg, "case", p - arg) == 0) 6397 else if (STRNICMP(arg, "case", p - arg) == 0)
6397 expand_what = EXP_CASE; 6398 expand_what = EXP_CASE;
6398 else if (STRNICMP(arg, "spell", p - arg) == 0) 6399 else if (STRNICMP(arg, "spell", p - arg) == 0)
6399 expand_what = EXP_SPELL; 6400 expand_what = EXP_SPELL;
6400 else if (STRNICMP(arg, "sync", p - arg) == 0) 6401 else if (STRNICMP(arg, "sync", p - arg) == 0)
6401 expand_what = EXP_SYNC; 6402 expand_what = EXP_SYNC;
6402 else if (STRNICMP(arg, "list", p - arg) == 0) 6403 else if (STRNICMP(arg, "list", p - arg) == 0)
6403 { 6404 {
6404 p = skipwhite(p); 6405 p = skipwhite(p);
6405 if (*p == '@') 6406 if (*p == '@')
6406 expand_what = EXP_CLUSTER; 6407 expand_what = EXP_CLUSTER;
6407 else 6408 else
6408 xp->xp_context = EXPAND_HIGHLIGHT; 6409 xp->xp_context = EXPAND_HIGHLIGHT;
6409 } 6410 }
6410 else if (STRNICMP(arg, "keyword", p - arg) == 0 6411 else if (STRNICMP(arg, "keyword", p - arg) == 0
6411 || STRNICMP(arg, "region", p - arg) == 0 6412 || STRNICMP(arg, "region", p - arg) == 0
6412 || STRNICMP(arg, "match", p - arg) == 0) 6413 || STRNICMP(arg, "match", p - arg) == 0)
6413 xp->xp_context = EXPAND_HIGHLIGHT; 6414 xp->xp_context = EXPAND_HIGHLIGHT;
6414 else 6415 else
6415 xp->xp_context = EXPAND_NOTHING; 6416 xp->xp_context = EXPAND_NOTHING;
6416 }
6417 }
6418 } 6417 }
6419 6418
6420 /* 6419 /*
6421 * Function given to ExpandGeneric() to obtain the list syntax names for 6420 * Function given to ExpandGeneric() to obtain the list syntax names for
6422 * expansion. 6421 * expansion.