diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-01-03 14:55:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 14:55:00 +0800 |
commit | 4dd793a256fefb481159f9f93bf7572391e266de (patch) | |
tree | 0a4a2c512f38b1e734fdb22650c2929fcd516c65 /src/nvim/buffer.c | |
parent | 3a519d86bf4d5ef3ff5623ad925ed856266d80de (diff) | |
download | rneovim-4dd793a256fefb481159f9f93bf7572391e266de.tar.gz rneovim-4dd793a256fefb481159f9f93bf7572391e266de.tar.bz2 rneovim-4dd793a256fefb481159f9f93bf7572391e266de.zip |
vim-patch:9.0.1132: code is indented more than needed (#21626)
Problem: Code is indented more than needed.
Solution: Use an early return to reduce indentation. (Yegappan Lakshmanan,
closes vim/vim#11769)
https://github.com/vim/vim/commit/dc4daa3a3915fba11ac87d27977240d9a5e0d47d
Omit expand_autoload_callback(): only applies to Vim9 script.
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r-- | src/nvim/buffer.c | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 0c74ccf0f4..239f2aa8ba 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -178,15 +178,17 @@ static int read_buffer(int read_stdin, exarg_T *eap, int flags) /// Ensure buffer "buf" is loaded. Does not trigger the swap-exists action. void buffer_ensure_loaded(buf_T *buf) { - if (buf->b_ml.ml_mfp == NULL) { - aco_save_T aco; - - // Make sure the buffer is in a window. - aucmd_prepbuf(&aco, buf); - swap_exists_action = SEA_NONE; - open_buffer(false, NULL, 0); - aucmd_restbuf(&aco); + if (buf->b_ml.ml_mfp != NULL) { + return; } + + aco_save_T aco; + + // Make sure the buffer is in a window. + aucmd_prepbuf(&aco, buf); + swap_exists_action = SEA_NONE; + open_buffer(false, NULL, 0); + aucmd_restbuf(&aco); } /// Open current buffer, that is: open the memfile and read the file into @@ -2903,18 +2905,20 @@ int setfname(buf_T *buf, char *ffname_arg, char *sfname_arg, bool message) void buf_set_name(int fnum, char *name) { buf_T *buf = buflist_findnr(fnum); - if (buf != NULL) { - if (buf->b_sfname != buf->b_ffname) { - xfree(buf->b_sfname); - } - xfree(buf->b_ffname); - buf->b_ffname = xstrdup(name); - buf->b_sfname = NULL; - // Allocate ffname and expand into full path. Also resolves .lnk - // files on Win32. - fname_expand(buf, &buf->b_ffname, &buf->b_sfname); - buf->b_fname = buf->b_sfname; + if (buf == NULL) { + return; } + + if (buf->b_sfname != buf->b_ffname) { + xfree(buf->b_sfname); + } + xfree(buf->b_ffname); + buf->b_ffname = xstrdup(name); + buf->b_sfname = NULL; + // Allocate ffname and expand into full path. Also resolves .lnk + // files on Win32. + fname_expand(buf, &buf->b_ffname, &buf->b_sfname); + buf->b_fname = buf->b_sfname; } /// Take care of what needs to be done when the name of buffer "buf" has changed. @@ -4138,13 +4142,15 @@ char *buf_get_fname(const buf_T *buf) /// Set 'buflisted' for curbuf to "on" and trigger autocommands if it changed. void set_buflisted(int on) { - if (on != curbuf->b_p_bl) { - curbuf->b_p_bl = on; - if (on) { - apply_autocmds(EVENT_BUFADD, NULL, NULL, false, curbuf); - } else { - apply_autocmds(EVENT_BUFDELETE, NULL, NULL, false, curbuf); - } + if (on == curbuf->b_p_bl) { + return; + } + + curbuf->b_p_bl = on; + if (on) { + apply_autocmds(EVENT_BUFADD, NULL, NULL, false, curbuf); + } else { + apply_autocmds(EVENT_BUFDELETE, NULL, NULL, false, curbuf); } } |