Mercurial > vim
comparison src/optionstr.c @ 31752:3365a601e73b v9.0.1208
patch 9.0.1208: code is indented more than necessary
Commit: https://github.com/vim/vim/commit/a41e221935edab62672a15123af48f4f14ac1c7d
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Mon Jan 16 18:19:05 2023 +0000
patch 9.0.1208: 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 #11819)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 16 Jan 2023 19:30:04 +0100 |
parents | db72745d328c |
children | 5614e76f3dee |
comparison
equal
deleted
inserted
replaced
31751:997105f91449 | 31752:3365a601e73b |
---|---|
153 char_u *oldval_l, | 153 char_u *oldval_l, |
154 char_u *oldval_g, | 154 char_u *oldval_g, |
155 char_u *newval) | 155 char_u *newval) |
156 { | 156 { |
157 // Don't do this recursively. | 157 // Don't do this recursively. |
158 if (oldval != NULL && newval != NULL | 158 if (oldval == NULL || newval == NULL |
159 && *get_vim_var_str(VV_OPTION_TYPE) == NUL) | 159 || *get_vim_var_str(VV_OPTION_TYPE) != NUL) |
160 { | 160 return; |
161 char_u buf_type[7]; | 161 |
162 | 162 char_u buf_type[7]; |
163 sprintf((char *)buf_type, "%s", | 163 |
164 sprintf((char *)buf_type, "%s", | |
164 (opt_flags & OPT_LOCAL) ? "local" : "global"); | 165 (opt_flags & OPT_LOCAL) ? "local" : "global"); |
165 set_vim_var_string(VV_OPTION_OLD, oldval, -1); | 166 set_vim_var_string(VV_OPTION_OLD, oldval, -1); |
166 set_vim_var_string(VV_OPTION_NEW, newval, -1); | 167 set_vim_var_string(VV_OPTION_NEW, newval, -1); |
167 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); | 168 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); |
168 if (opt_flags & OPT_LOCAL) | 169 if (opt_flags & OPT_LOCAL) |
169 { | 170 { |
170 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1); | 171 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1); |
171 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1); | 172 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1); |
172 } | 173 } |
173 if (opt_flags & OPT_GLOBAL) | 174 if (opt_flags & OPT_GLOBAL) |
174 { | 175 { |
175 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1); | 176 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1); |
176 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1); | 177 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1); |
177 } | 178 } |
178 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) | 179 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
179 { | 180 { |
180 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1); | 181 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1); |
181 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1); | 182 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1); |
182 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1); | 183 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1); |
183 } | 184 } |
184 if (opt_flags & OPT_MODELINE) | 185 if (opt_flags & OPT_MODELINE) |
185 { | 186 { |
186 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1); | 187 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1); |
187 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1); | 188 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1); |
188 } | 189 } |
189 apply_autocmds(EVENT_OPTIONSET, | 190 apply_autocmds(EVENT_OPTIONSET, |
190 get_option_fullname(opt_idx), NULL, FALSE, | 191 get_option_fullname(opt_idx), NULL, FALSE, |
191 NULL); | 192 NULL); |
192 reset_v_option_vars(); | 193 reset_v_option_vars(); |
193 } | |
194 } | 194 } |
195 #endif | 195 #endif |
196 | 196 |
197 static char * | 197 static char * |
198 illegal_char(char *errbuf, int c) | 198 illegal_char(char *errbuf, int c) |
385 | 385 |
386 if (is_hidden_option(idx)) // can't set hidden option | 386 if (is_hidden_option(idx)) // can't set hidden option |
387 return; | 387 return; |
388 | 388 |
389 s = vim_strsave(val); | 389 s = vim_strsave(val); |
390 if (s != NULL) | 390 if (s == NULL) |
391 { | 391 return; |
392 varp = (char_u **)get_option_varp_scope(idx, | 392 |
393 both ? OPT_LOCAL : opt_flags); | 393 varp = (char_u **)get_option_varp_scope(idx, |
394 if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED)) | 394 both ? OPT_LOCAL : opt_flags); |
395 free_string_option(*varp); | 395 if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED)) |
396 *varp = s; | 396 free_string_option(*varp); |
397 | 397 *varp = s; |
398 // For buffer/window local option may also set the global value. | 398 |
399 if (both) | 399 // For buffer/window local option may also set the global value. |
400 set_string_option_global(idx, varp); | 400 if (both) |
401 | 401 set_string_option_global(idx, varp); |
402 set_option_flag(idx, P_ALLOCED); | 402 |
403 | 403 set_option_flag(idx, P_ALLOCED); |
404 // When setting both values of a global option with a local value, | 404 |
405 // make the local value empty, so that the global value is used. | 405 // When setting both values of a global option with a local value, |
406 if (is_global_local_option(idx) && both) | 406 // make the local value empty, so that the global value is used. |
407 { | 407 if (is_global_local_option(idx) && both) |
408 free_string_option(*varp); | 408 { |
409 *varp = empty_option; | 409 free_string_option(*varp); |
410 } | 410 *varp = empty_option; |
411 } | |
411 # ifdef FEAT_EVAL | 412 # ifdef FEAT_EVAL |
412 if (set_sid != SID_NONE) | 413 if (set_sid != SID_NONE) |
413 { | 414 { |
414 sctx_T script_ctx; | 415 sctx_T script_ctx; |
415 | 416 |
416 if (set_sid == 0) | 417 if (set_sid == 0) |
417 script_ctx = current_sctx; | 418 script_ctx = current_sctx; |
418 else | 419 else |
419 { | 420 { |
420 script_ctx.sc_sid = set_sid; | 421 script_ctx.sc_sid = set_sid; |
421 script_ctx.sc_seq = 0; | 422 script_ctx.sc_seq = 0; |
422 script_ctx.sc_lnum = 0; | 423 script_ctx.sc_lnum = 0; |
423 script_ctx.sc_version = 1; | 424 script_ctx.sc_version = 1; |
424 } | 425 } |
425 set_option_sctx_idx(idx, opt_flags, script_ctx); | 426 set_option_sctx_idx(idx, opt_flags, script_ctx); |
426 } | 427 } |
427 # endif | 428 # endif |
428 } | |
429 } | 429 } |
430 | 430 |
431 /* | 431 /* |
432 * Like set_string_option_direct(), but for a window-local option in "wp". | 432 * Like set_string_option_direct(), but for a window-local option in "wp". |
433 * Blocks autocommands to avoid the old curwin becoming invalid. | 433 * Blocks autocommands to avoid the old curwin becoming invalid. |
505 | 505 |
506 if (is_hidden_option(opt_idx)) // don't set hidden option | 506 if (is_hidden_option(opt_idx)) // don't set hidden option |
507 return NULL; | 507 return NULL; |
508 | 508 |
509 s = vim_strsave(value == NULL ? (char_u *)"" : value); | 509 s = vim_strsave(value == NULL ? (char_u *)"" : value); |
510 if (s != NULL) | 510 if (s == NULL) |
511 { | 511 return NULL; |
512 varp = (char_u **)get_option_varp_scope(opt_idx, | 512 |
513 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 | 513 varp = (char_u **)get_option_varp_scope(opt_idx, |
514 ? (is_global_local_option(opt_idx) | 514 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 |
515 ? OPT_GLOBAL : OPT_LOCAL) | 515 ? (is_global_local_option(opt_idx) |
516 : opt_flags); | 516 ? OPT_GLOBAL : OPT_LOCAL) |
517 oldval = *varp; | 517 : opt_flags); |
518 oldval = *varp; | |
518 #if defined(FEAT_EVAL) | 519 #if defined(FEAT_EVAL) |
519 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) | 520 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) |
520 { | 521 { |
521 oldval_l = *(char_u **)get_option_varp_scope(opt_idx, OPT_LOCAL); | 522 oldval_l = *(char_u **)get_option_varp_scope(opt_idx, OPT_LOCAL); |
522 oldval_g = *(char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL); | 523 oldval_g = *(char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL); |
523 } | 524 } |
524 #endif | 525 #endif |
525 *varp = s; | 526 *varp = s; |
526 | 527 |
527 #if defined(FEAT_EVAL) | 528 #if defined(FEAT_EVAL) |
528 if (!starting | 529 if (!starting |
529 # ifdef FEAT_CRYPT | 530 # ifdef FEAT_CRYPT |
530 && !is_crypt_key_option(opt_idx) | 531 && !is_crypt_key_option(opt_idx) |
531 # endif | 532 # endif |
532 ) | 533 ) |
533 { | 534 { |
534 if (oldval_l != NULL) | 535 if (oldval_l != NULL) |
535 saved_oldval_l = vim_strsave(oldval_l); | 536 saved_oldval_l = vim_strsave(oldval_l); |
536 if (oldval_g != NULL) | 537 if (oldval_g != NULL) |
537 saved_oldval_g = vim_strsave(oldval_g); | 538 saved_oldval_g = vim_strsave(oldval_g); |
538 saved_oldval = vim_strsave(oldval); | 539 saved_oldval = vim_strsave(oldval); |
539 saved_newval = vim_strsave(s); | 540 saved_newval = vim_strsave(s); |
540 } | 541 } |
541 #endif | 542 #endif |
542 if ((errmsg = did_set_string_option(opt_idx, varp, oldval, NULL, | 543 if ((errmsg = did_set_string_option(opt_idx, varp, oldval, NULL, |
543 opt_flags, &value_checked)) == NULL) | 544 opt_flags, &value_checked)) == NULL) |
544 did_set_option(opt_idx, opt_flags, TRUE, value_checked); | 545 did_set_option(opt_idx, opt_flags, TRUE, value_checked); |
545 | 546 |
546 #if defined(FEAT_EVAL) | 547 #if defined(FEAT_EVAL) |
547 // call autocommand after handling side effects | 548 // call autocommand after handling side effects |
548 if (errmsg == NULL) | 549 if (errmsg == NULL) |
549 trigger_optionset_string(opt_idx, opt_flags, | 550 trigger_optionset_string(opt_idx, opt_flags, |
550 saved_oldval, saved_oldval_l, | 551 saved_oldval, saved_oldval_l, |
551 saved_oldval_g, saved_newval); | 552 saved_oldval_g, saved_newval); |
552 vim_free(saved_oldval); | 553 vim_free(saved_oldval); |
553 vim_free(saved_oldval_l); | 554 vim_free(saved_oldval_l); |
554 vim_free(saved_oldval_g); | 555 vim_free(saved_oldval_g); |
555 vim_free(saved_newval); | 556 vim_free(saved_newval); |
556 #endif | 557 #endif |
557 } | |
558 return errmsg; | 558 return errmsg; |
559 } | 559 } |
560 | 560 |
561 /* | 561 /* |
562 * Return TRUE if "val" is a valid 'filetype' name. | 562 * Return TRUE if "val" is a valid 'filetype' name. |