diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2014-12-14 13:42:10 -0500 | 
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2014-12-14 13:42:10 -0500 | 
| commit | ec6afbf4e621bfcfde903d15744dc0c61f80097d (patch) | |
| tree | 94fd08577b5eed003b6f7eb3a7bcafcac7f20a66 /src/nvim/buffer.c | |
| parent | 64a32d55c59188f1e922ca438fdb2d65caa06665 (diff) | |
| parent | 0bc40e660c0a74776ace86ad5e393755523c3803 (diff) | |
| download | rneovim-ec6afbf4e621bfcfde903d15744dc0c61f80097d.tar.gz rneovim-ec6afbf4e621bfcfde903d15744dc0c61f80097d.tar.bz2 rneovim-ec6afbf4e621bfcfde903d15744dc0c61f80097d.zip  | |
Merge pull request #1661 from philix/early_exit
Reduce indentation level by early returning or continuing loop
Diffstat (limited to 'src/nvim/buffer.c')
| -rw-r--r-- | src/nvim/buffer.c | 149 | 
1 files changed, 75 insertions, 74 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index ec10a826c7..f84e25cdfb 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -238,25 +238,27 @@ open_buffer (    }    apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, &retval); -  if (retval != FAIL) { -    /* -     * The autocommands may have changed the current buffer.  Apply the -     * modelines to the correct buffer, if it still exists and is loaded. -     */ -    if (buf_valid(old_curbuf) && old_curbuf->b_ml.ml_mfp != NULL) { -      aco_save_T aco; +  if (retval == FAIL) { +    return FAIL; +  } -      /* Go to the buffer that was opened. */ -      aucmd_prepbuf(&aco, old_curbuf); -      do_modelines(0); -      curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); +  /* +   * The autocommands may have changed the current buffer.  Apply the +   * modelines to the correct buffer, if it still exists and is loaded. +   */ +  if (buf_valid(old_curbuf) && old_curbuf->b_ml.ml_mfp != NULL) { +    aco_save_T aco; + +    /* Go to the buffer that was opened. */ +    aucmd_prepbuf(&aco, old_curbuf); +    do_modelines(0); +    curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); -      apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, -          &retval); +    apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, +        &retval); -      /* restore curwin/curbuf and a few other things */ -      aucmd_restbuf(&aco); -    } +    /* restore curwin/curbuf and a few other things */ +    aucmd_restbuf(&aco);    }    return retval; @@ -2103,14 +2105,10 @@ void get_winopts(buf_T *buf)   */  pos_T *buflist_findfpos(buf_T *buf)  { -  wininfo_T   *wip;    static pos_T no_position = INIT_POS_T(1, 0, 0); -  wip = find_wininfo(buf, FALSE); -  if (wip != NULL) -    return &(wip->wi_fpos); -  else -    return &no_position; +  wininfo_T *wip = find_wininfo(buf, FALSE); +  return (wip == NULL) ? &no_position : &(wip->wi_fpos);  }  /* @@ -4091,66 +4089,69 @@ chk_modeline (      prev = *s;    } -  if (*s) { -    do                                  /* skip over "ex:", "vi:" or "vim:" */ -      ++s; -    while (s[-1] != ':'); +  if (!*s) { +    return retval; +  } -    s = linecopy = vim_strsave(s);      /* copy the line, it will change */ +  do                                  /* skip over "ex:", "vi:" or "vim:" */ +    ++s; +  while (s[-1] != ':'); -    save_sourcing_lnum = sourcing_lnum; -    save_sourcing_name = sourcing_name; -    sourcing_lnum = lnum;               /* prepare for emsg() */ -    sourcing_name = (char_u *)"modelines"; +  s = linecopy = vim_strsave(s);      /* copy the line, it will change */ -    end = FALSE; -    while (end == FALSE) { -      s = skipwhite(s); -      if (*s == NUL) -        break; +  save_sourcing_lnum = sourcing_lnum; +  save_sourcing_name = sourcing_name; +  sourcing_lnum = lnum;               /* prepare for emsg() */ +  sourcing_name = (char_u *)"modelines"; -      /* -       * Find end of set command: ':' or end of line. -       * Skip over "\:", replacing it with ":". -       */ -      for (e = s; *e != ':' && *e != NUL; ++e) -        if (e[0] == '\\' && e[1] == ':') -          STRMOVE(e, e + 1); -      if (*e == NUL) -        end = TRUE; +  end = FALSE; +  while (end == FALSE) { +    s = skipwhite(s); +    if (*s == NUL) +      break; -      /* -       * If there is a "set" command, require a terminating ':' and -       * ignore the stuff after the ':'. -       * "vi:set opt opt opt: foo" -- foo not interpreted -       * "vi:opt opt opt: foo" -- foo interpreted -       * Accept "se" for compatibility with Elvis. -       */ -      if (STRNCMP(s, "set ", (size_t)4) == 0 -          || STRNCMP(s, "se ", (size_t)3) == 0) { -        if (*e != ':')                  /* no terminating ':'? */ -          break; -        end = TRUE; -        s = vim_strchr(s, ' ') + 1; -      } -      *e = NUL;                         /* truncate the set command */ - -      if (*s != NUL) {                  /* skip over an empty "::" */ -        save_SID = current_SID; -        current_SID = SID_MODELINE; -        retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags); -        current_SID = save_SID; -        if (retval == FAIL)                     /* stop if error found */ -          break; -      } -      s = e + 1;                        /* advance to next part */ +    /* +     * Find end of set command: ':' or end of line. +     * Skip over "\:", replacing it with ":". +     */ +    for (e = s; *e != ':' && *e != NUL; ++e) +      if (e[0] == '\\' && e[1] == ':') +        STRMOVE(e, e + 1); +    if (*e == NUL) +      end = TRUE; + +    /* +     * If there is a "set" command, require a terminating ':' and +     * ignore the stuff after the ':'. +     * "vi:set opt opt opt: foo" -- foo not interpreted +     * "vi:opt opt opt: foo" -- foo interpreted +     * Accept "se" for compatibility with Elvis. +     */ +    if (STRNCMP(s, "set ", (size_t)4) == 0 +        || STRNCMP(s, "se ", (size_t)3) == 0) { +      if (*e != ':')                  /* no terminating ':'? */ +        break; +      end = TRUE; +      s = vim_strchr(s, ' ') + 1; +    } +    *e = NUL;                         /* truncate the set command */ + +    if (*s != NUL) {                  /* skip over an empty "::" */ +      save_SID = current_SID; +      current_SID = SID_MODELINE; +      retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags); +      current_SID = save_SID; +      if (retval == FAIL)                     /* stop if error found */ +        break;      } +    s = e + 1;                        /* advance to next part */ +  } -    sourcing_lnum = save_sourcing_lnum; -    sourcing_name = save_sourcing_name; +  sourcing_lnum = save_sourcing_lnum; +  sourcing_name = save_sourcing_name; + +  free(linecopy); -    free(linecopy); -  }    return retval;  }  | 
