diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2023-01-12 12:33:30 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2023-01-12 12:33:30 +0000 |
commit | 0233bdfa2b487c392dc4fd1a29113e08fbace334 (patch) | |
tree | 83551e09979e7baa762cd11a65ddff2153883e4e /src/if_ruby.c | |
parent | 043d7b2c84cda275354aa023b5769660ea70a168 (diff) | |
download | vim-git-0233bdfa2b487c392dc4fd1a29113e08fbace334.tar.gz |
patch 9.0.1183: code is indented more than necessaryv9.0.1183
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes #11805)
Diffstat (limited to 'src/if_ruby.c')
-rw-r--r-- | src/if_ruby.c | 149 |
1 files changed, 75 insertions, 74 deletions
diff --git a/src/if_ruby.c b/src/if_ruby.c index b157bb83d..8f9b35623 100644 --- a/src/if_ruby.c +++ b/src/if_ruby.c @@ -866,44 +866,44 @@ ex_rubydo(exarg_T *eap) linenr_T i; buf_T *was_curbuf = curbuf; - if (ensure_ruby_initialized()) + if (!ensure_ruby_initialized()) + return; + + if (u_save(eap->line1 - 1, eap->line2 + 1) != OK) + return; + for (i = eap->line1; i <= eap->line2; i++) { - if (u_save(eap->line1 - 1, eap->line2 + 1) != OK) - return; - for (i = eap->line1; i <= eap->line2; i++) + VALUE line; + + if (i > curbuf->b_ml.ml_line_count) + break; + line = vim_str2rb_enc_str((char *)ml_get(i)); + rb_lastline_set(line); + eval_enc_string_protect((char *) eap->arg, &state); + if (state) + { + error_print(state); + break; + } + if (was_curbuf != curbuf) + break; + line = rb_lastline_get(); + if (!NIL_P(line)) { - VALUE line; - - if (i > curbuf->b_ml.ml_line_count) - break; - line = vim_str2rb_enc_str((char *)ml_get(i)); - rb_lastline_set(line); - eval_enc_string_protect((char *) eap->arg, &state); - if (state) + if (TYPE(line) != T_STRING) { - error_print(state); - break; + emsg(_(e_dollar_must_be_an_instance_of_string)); + return; } - if (was_curbuf != curbuf) - break; - line = rb_lastline_get(); - if (!NIL_P(line)) - { - if (TYPE(line) != T_STRING) - { - emsg(_(e_dollar_must_be_an_instance_of_string)); - return; - } - ml_replace(i, (char_u *) StringValuePtr(line), 1); - changed(); + ml_replace(i, (char_u *) StringValuePtr(line), 1); + changed(); #ifdef SYNTAX_HL - syn_changed(i); // recompute syntax hl. for this line + syn_changed(i); // recompute syntax hl. for this line #endif - } } - check_cursor(); - update_curbuf(UPD_NOT_VALID); } + check_cursor(); + update_curbuf(UPD_NOT_VALID); } static VALUE @@ -918,73 +918,74 @@ ex_rubyfile(exarg_T *eap) { int state; - if (ensure_ruby_initialized()) - { - VALUE file_to_load = rb_str_new2((const char *)eap->arg); - rb_protect(rb_load_wrap, file_to_load, &state); - if (state) - error_print(state); - } + if (!ensure_ruby_initialized()) + return; + + VALUE file_to_load = rb_str_new2((const char *)eap->arg); + rb_protect(rb_load_wrap, file_to_load, &state); + if (state) + error_print(state); } void ruby_buffer_free(buf_T *buf) { - if (buf->b_ruby_ref) - { - rb_hash_aset(objtbl, rb_obj_id((VALUE) buf->b_ruby_ref), Qnil); - RDATA(buf->b_ruby_ref)->data = NULL; - } + if (buf->b_ruby_ref == NULL) + return; + + rb_hash_aset(objtbl, rb_obj_id((VALUE) buf->b_ruby_ref), Qnil); + RDATA(buf->b_ruby_ref)->data = NULL; } void ruby_window_free(win_T *win) { - if (win->w_ruby_ref) - { - rb_hash_aset(objtbl, rb_obj_id((VALUE) win->w_ruby_ref), Qnil); - RDATA(win->w_ruby_ref)->data = NULL; - } + if (win->w_ruby_ref == NULL) + return; + + rb_hash_aset(objtbl, rb_obj_id((VALUE) win->w_ruby_ref), Qnil); + RDATA(win->w_ruby_ref)->data = NULL; } static int ensure_ruby_initialized(void) { - if (!ruby_initialized) - { + if (ruby_initialized) + return ruby_initialized; + #ifdef DYNAMIC_RUBY - if (ruby_enabled(TRUE)) + if (ruby_enabled(TRUE)) #endif - { + { #ifdef MSWIN - // suggested by Ariya Mizutani - int argc = 1; - char *argv[] = {"gvim.exe"}; - char **argvp = argv; - ruby_sysinit(&argc, &argvp); + // suggested by Ariya Mizutani + int argc = 1; + char *argv[] = {"gvim.exe"}; + char **argvp = argv; + ruby_sysinit(&argc, &argvp); #endif - { - ruby_init_stack(ruby_stack_start); - ruby_init(); - } - { - int dummy_argc = 2; - char *dummy_argv[] = {"vim-ruby", "-e_=0"}; - ruby_options(dummy_argc, dummy_argv); - } - ruby_script("vim-ruby"); - ruby_io_init(); - ruby_vim_init(); - ruby_initialized = 1; + { + ruby_init_stack(ruby_stack_start); + ruby_init(); } -#ifdef DYNAMIC_RUBY - else { - emsg(_(e_sorry_this_command_is_disabled_the_ruby_library_could_not_be_loaded)); - return 0; + int dummy_argc = 2; + char *dummy_argv[] = {"vim-ruby", "-e_=0"}; + ruby_options(dummy_argc, dummy_argv); } -#endif + ruby_script("vim-ruby"); + ruby_io_init(); + ruby_vim_init(); + ruby_initialized = 1; } +#ifdef DYNAMIC_RUBY + else + { + emsg(_(e_sorry_this_command_is_disabled_the_ruby_library_could_not_be_loaded)); + return 0; + } +#endif + return ruby_initialized; } |