diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2014-08-19 23:49:25 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-08-19 23:49:25 -0400 |
commit | e1c330a486c184152cb48d637c6d04caba5290bd (patch) | |
tree | b2379cae30ea446456681d1dc62d80ef95345f69 | |
parent | 0b7bff5bb71ddc2e9c41863ec41b9aea74d0fe75 (diff) | |
parent | 888a31ba454cf9c054527a26459c112593efa54b (diff) | |
download | rneovim-e1c330a486c184152cb48d637c6d04caba5290bd.tar.gz rneovim-e1c330a486c184152cb48d637c6d04caba5290bd.tar.bz2 rneovim-e1c330a486c184152cb48d637c6d04caba5290bd.zip |
Merge pull request #1024 from war1025/dev/for_all_buffers
Add FOR_ALL_BUFFERS helper
-rw-r--r-- | src/nvim/buffer.c | 73 | ||||
-rw-r--r-- | src/nvim/edit.c | 5 | ||||
-rw-r--r-- | src/nvim/eval.c | 24 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 23 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 47 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 3 | ||||
-rw-r--r-- | src/nvim/fileio.c | 6 | ||||
-rw-r--r-- | src/nvim/globals.h | 3 | ||||
-rw-r--r-- | src/nvim/main.c | 6 | ||||
-rw-r--r-- | src/nvim/mark.c | 20 | ||||
-rw-r--r-- | src/nvim/memfile.c | 15 | ||||
-rw-r--r-- | src/nvim/memline.c | 25 | ||||
-rw-r--r-- | src/nvim/misc1.c | 4 | ||||
-rw-r--r-- | src/nvim/option.c | 7 | ||||
-rw-r--r-- | src/nvim/spell.c | 4 | ||||
-rw-r--r-- | src/nvim/window.c | 11 |
16 files changed, 145 insertions, 131 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 8bcb5934dc..77bed67d5f 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -115,9 +115,15 @@ open_buffer ( * If we can't create one for the current buffer, take another buffer */ close_buffer(NULL, curbuf, 0, FALSE); - for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next) - if (curbuf->b_ml.ml_mfp != NULL) + + curbuf = NULL; + FOR_ALL_BUFFERS(buf) { + if (buf->b_ml.ml_mfp != NULL) { + curbuf = buf; break; + } + } + /* * if there is no memfile at all, exit * This is OK, since there are no changes to lose. @@ -260,11 +266,11 @@ open_buffer ( */ int buf_valid(buf_T *buf) { - buf_T *bp; - - for (bp = firstbuf; bp != NULL; bp = bp->b_next) - if (bp == buf) + FOR_ALL_BUFFERS(bp) { + if (bp == buf) { return TRUE; + } + } return FALSE; } @@ -946,9 +952,13 @@ do_buffer ( * If deleting the last (listed) buffer, make it empty. * The last (listed) buffer cannot be unloaded. */ - for (bp = firstbuf; bp != NULL; bp = bp->b_next) - if (bp->b_p_bl && bp != buf) + bp = NULL; + FOR_ALL_BUFFERS(bp2) { + if (bp2->b_p_bl && bp2 != buf) { + bp = bp2; break; + } + } if (bp == NULL && buf == curbuf) return empty_curbuf(TRUE, forceit, action); @@ -1047,9 +1057,12 @@ do_buffer ( if (buf == NULL) /* No loaded buffer, use unloaded one */ buf = bp; if (buf == NULL) { /* No loaded buffer, find listed one */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) - if (buf->b_p_bl && buf != curbuf) + FOR_ALL_BUFFERS(buf2) { + if (buf2->b_p_bl && buf2 != curbuf) { + buf = buf2; break; + } + } } if (buf == NULL) { /* Still no buffer, just take one */ if (curbuf->b_next != NULL) @@ -1670,9 +1683,7 @@ buf_T *buflist_findname(char_u *ffname) static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id, bool file_id_valid) { - buf_T *buf; - - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { if ((buf->b_flags & BF_DUMMY) == 0 && !otherfile_buf(buf, ffname, file_id, file_id_valid)) { return buf; @@ -1695,7 +1706,6 @@ buflist_findpat ( int curtab_only /* find buffers in current tab only */ ) { - buf_T *buf; regprog_T *prog; int match = -1; int find_listed; @@ -1746,7 +1756,7 @@ buflist_findpat ( return -1; } - for (buf = firstbuf; buf != NULL; buf = buf->b_next) + FOR_ALL_BUFFERS(buf) { if (buf->b_p_bl == find_listed && (!diffmode || diff_mode_buf(buf)) && buflist_match(prog, buf) != NULL) { @@ -1767,6 +1777,7 @@ buflist_findpat ( } match = buf->b_fnum; /* remember first match */ } + } vim_regfree(prog); if (match >= 0) /* found one match */ @@ -1799,7 +1810,6 @@ buflist_findpat ( int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) { int count = 0; - buf_T *buf; int round; char_u *p; int attempt; @@ -1837,7 +1847,7 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) */ for (round = 1; round <= 2; ++round) { count = 0; - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { if (!buf->b_p_bl) /* skip unlisted buffers */ continue; p = buflist_match(prog, buf); @@ -1921,13 +1931,15 @@ static char_u *fname_match(regprog_T *prog, char_u *name) */ buf_T *buflist_findnr(int nr) { - buf_T *buf; - - if (nr == 0) + if (nr == 0) { nr = curwin->w_alt_fnum; - for (buf = firstbuf; buf != NULL; buf = buf->b_next) - if (buf->b_fnum == nr) + } + + FOR_ALL_BUFFERS(buf) { + if (buf->b_fnum == nr) { return buf; + } + } return NULL; } @@ -2344,9 +2356,7 @@ int buflist_add(char_u *fname, int flags) */ void buflist_slash_adjust(void) { - buf_T *bp; - - for (bp = firstbuf; bp != NULL; bp = bp->b_next) { + FOR_ALL_BUFFERS(bp) { if (bp->b_ffname != NULL) slash_adjust(bp->b_ffname); if (bp->b_sfname != NULL) @@ -4192,7 +4202,6 @@ int read_viminfo_bufferlist(vir_T *virp, int writing) void write_viminfo_bufferlist(FILE *fp) { - buf_T *buf; win_T *win; tabpage_T *tp; char_u *line; @@ -4213,7 +4222,7 @@ void write_viminfo_bufferlist(FILE *fp) } fputs(_("\n# Buffer list:\n"), fp); - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { if (buf->b_fname == NULL || !buf->b_p_bl || bt_quickfix(buf) @@ -4488,13 +4497,11 @@ void buf_delete_signs(buf_T *buf) */ void buf_delete_all_signs(void) { - buf_T *buf; /* buffer we are checking for signs */ - - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { - if (buf->b_signlist != NULL) { - buf_delete_signs(buf); - } + FOR_ALL_BUFFERS(buf) { + if (buf->b_signlist != NULL) { + buf_delete_signs(buf); } + } } /* diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 05d6c9758a..93e127394b 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3436,8 +3436,9 @@ static int ins_compl_get_exp(pos_T *ini) int set_match_pos; if (!compl_started) { - for (ins_buf = firstbuf; ins_buf != NULL; ins_buf = ins_buf->b_next) - ins_buf->b_scanned = 0; + FOR_ALL_BUFFERS(buf) { + buf->b_scanned = 0; + } found_all = FALSE; ins_buf = curbuf; e_cpt = (compl_cont_status & CONT_LOCAL) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 5bda9fcd3f..1cef91785c 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5405,7 +5405,6 @@ static int list_join(garray_T *gap, list_T *l, char_u *sep, int echo_style, int int garbage_collect(void) { int copyID; - buf_T *buf; win_T *wp; funccall_T *fc, **pfc; int did_free; @@ -5440,8 +5439,9 @@ int garbage_collect(void) set_ref_in_ht(&SCRIPT_VARS(i), copyID); /* buffer-local variables */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) + FOR_ALL_BUFFERS(buf) { set_ref_in_item(&buf->b_bufvar.di_tv, copyID); + } /* window-local variables */ FOR_ALL_TAB_WINDOWS(tp, wp) @@ -7223,13 +7223,16 @@ static buf_T *find_buffer(typval_T *avar) if (buf == NULL) { /* No full path name match, try a match with a URL or a "nofile" * buffer, these don't use the full path. */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) - if (buf->b_fname != NULL - && (path_with_url(buf->b_fname) - || bt_nofile(buf) + FOR_ALL_BUFFERS(bp) { + if (bp->b_fname != NULL + && (path_with_url(bp->b_fname) + || bt_nofile(bp) ) - && STRCMP(buf->b_fname, avar->vval.v_string) == 0) + && STRCMP(bp->b_fname, avar->vval.v_string) == 0) { + buf = bp; break; + } + } } } return buf; @@ -10635,11 +10638,12 @@ static void f_keys(typval_T *argvars, typval_T *rettv) static void f_last_buffer_nr(typval_T *argvars, typval_T *rettv) { int n = 0; - buf_T *buf; - for (buf = firstbuf; buf != NULL; buf = buf->b_next) - if (n < buf->b_fnum) + FOR_ALL_BUFFERS(buf) { + if (n < buf->b_fnum) { n = buf->b_fnum; + } + } rettv->vval.v_number = n; } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 48e75190aa..5b6604fc93 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1211,7 +1211,6 @@ do_shell ( int flags /* may be SHELL_DOOUT when output is redirected */ ) { - buf_T *buf; int save_nwr; /* @@ -1239,11 +1238,12 @@ do_shell ( if (p_warn && !autocmd_busy && msg_silent == 0) - for (buf = firstbuf; buf; buf = buf->b_next) + FOR_ALL_BUFFERS(buf) { if (bufIsChanged(buf)) { MSG_PUTS(_("[No write since last change]\n")); break; } + } /* This windgoto is required for when the '\n' resulted in a "delete line * 1" command to the terminal. */ @@ -1753,7 +1753,6 @@ static void do_viminfo(FILE *fp_in, FILE *fp_out, int flags) static int read_viminfo_up_to_marks(vir_T *virp, int forceit, int writing) { int eof; - buf_T *buf; prepare_viminfo_history(forceit ? 9999 : 0, writing); eof = viminfo_readline(virp); @@ -1816,8 +1815,9 @@ static int read_viminfo_up_to_marks(vir_T *virp, int forceit, int writing) finish_viminfo_history(); /* Change file names to buffer numbers for fmarks. */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) + FOR_ALL_BUFFERS(buf) { fmarks_check_names(buf); + } return eof; } @@ -2362,14 +2362,13 @@ void ex_wnext(exarg_T *eap) */ void do_wqall(exarg_T *eap) { - buf_T *buf; int error = 0; int save_forceit = eap->forceit; if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall) exiting = TRUE; - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { if (bufIsChanged(buf)) { /* * Check if there is a reason the buffer cannot be written: @@ -5679,7 +5678,6 @@ void ex_sign(exarg_T *eap) int idx; sign_T *sp; sign_T *sp_prev; - buf_T *buf; /* Parse the subcommand. */ p = skiptowhite(arg); @@ -5906,10 +5904,11 @@ void ex_sign(exarg_T *eap) if (idx == SIGNCMD_UNPLACE && *arg == NUL) { /* ":sign unplace {id}": remove placed sign by number */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) - if ((lnum = buf_delsign(buf, id)) != 0) - update_debug_sign(buf, lnum); - return; + FOR_ALL_BUFFERS(buf) { + if ((lnum = buf_delsign(buf, id)) != 0) + update_debug_sign(buf, lnum); + return; + } } } } @@ -5918,6 +5917,8 @@ void ex_sign(exarg_T *eap) * Check for line={lnum} name={name} and file={fname} or buffer={nr}. * Leave "arg" pointing to {fname}. */ + + buf_T *buf = NULL; for (;;) { if (STRNCMP(arg, "line=", 5) == 0) diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index afbb3b40f1..e0b0b55f41 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -1044,17 +1044,18 @@ int autowrite(buf_T *buf, int forceit) */ void autowrite_all(void) { - buf_T *buf; - - if (!(p_aw || p_awa) || !p_write) + if (!(p_aw || p_awa) || !p_write) { return; - for (buf = firstbuf; buf; buf = buf->b_next) + } + + FOR_ALL_BUFFERS(buf) { if (bufIsChanged(buf) && !buf->b_p_ro) { (void)buf_write_all(buf, FALSE); /* an autocommand may have deleted the buffer */ if (!buf_valid(buf)) buf = firstbuf; } + } } /* @@ -1070,15 +1071,14 @@ int check_changed(buf_T *buf, int flags) && ((flags & CCGD_MULTWIN) || buf->b_nwindows <= 1) && (!(flags & CCGD_AW) || autowrite(buf, forceit) == FAIL)) { if ((p_confirm || cmdmod.confirm) && p_write) { - buf_T *buf2; int count = 0; if (flags & CCGD_ALLBUF) - for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next) - if (bufIsChanged(buf2) - && (buf2->b_ffname != NULL - )) + FOR_ALL_BUFFERS(buf2) { + if (bufIsChanged(buf2) && (buf2->b_ffname != NULL)) { ++count; + } + } if (!buf_valid(buf)) /* Autocommand deleted buffer, oops! It's not changed now. */ return FALSE; @@ -1111,7 +1111,6 @@ dialog_changed ( { char_u buff[DIALOG_MSG_SIZE]; int ret; - buf_T *buf2; exarg_T ea; dialog_msg(buff, _("Save changes to \"%s\"?"), @@ -1139,7 +1138,7 @@ dialog_changed ( * Skip readonly buffers, these need to be confirmed * individually. */ - for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next) { + FOR_ALL_BUFFERS(buf2) { if (bufIsChanged(buf2) && (buf2->b_ffname != NULL ) @@ -1157,8 +1156,9 @@ dialog_changed ( /* * mark all buffers as unchanged */ - for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next) + FOR_ALL_BUFFERS(buf2) { unchanged(buf2, TRUE); + } } } @@ -1200,7 +1200,6 @@ check_changed_any ( ) { int ret = FALSE; - buf_T *buf; int save; int i; int bufnum = 0; @@ -1209,8 +1208,9 @@ check_changed_any ( tabpage_T *tp; win_T *wp; - for (buf = firstbuf; buf != NULL; buf = buf->b_next) + FOR_ALL_BUFFERS(buf) { ++bufcount; + } if (bufcount == 0) return FALSE; @@ -1230,9 +1230,11 @@ check_changed_any ( for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum); /* any other buf */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) + FOR_ALL_BUFFERS(buf) { add_bufnum(bufnrs, &bufnum, buf->b_fnum); + } + buf_T *buf = NULL; for (i = 0; i < bufnum; ++i) { buf = buflist_findnr(bufnrs[i]); if (buf == NULL) @@ -1817,7 +1819,6 @@ void ex_listdo(exarg_T *eap) int i; win_T *wp; tabpage_T *tp; - buf_T *buf; int next_fnum = 0; char_u *save_ei = NULL; char_u *p_shm_save; @@ -1882,7 +1883,7 @@ void ex_listdo(exarg_T *eap) /* Remember the number of the next listed buffer, in case * ":bwipe" is used or autocommands do something strange. */ next_fnum = -1; - for (buf = curbuf->b_next; buf != NULL; buf = buf->b_next) + for (buf_T *buf = curbuf->b_next; buf != NULL; buf = buf->b_next) if (buf->b_p_bl) { next_fnum = buf->b_fnum; break; @@ -1897,12 +1898,18 @@ void ex_listdo(exarg_T *eap) /* Done? */ if (next_fnum < 0) break; + /* Check if the buffer still exists. */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) - if (buf->b_fnum == next_fnum) + bool buf_still_exists = false; + FOR_ALL_BUFFERS(bp) { + if (bp->b_fnum == next_fnum) { + buf_still_exists = true; break; - if (buf == NULL) + } + } + if (buf_still_exists) { break; + } /* Go to the next buffer. Clear 'shm' to avoid that the file * message overwrites any output from the command. */ diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 3eb9d1277e..446d51be3f 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -7871,7 +7871,6 @@ makeopens ( char_u *dirnow /* Current directory name */ ) { - buf_T *buf; int only_save_windows = TRUE; int nr; int cnr = 1; @@ -7943,7 +7942,7 @@ makeopens ( return FAIL; /* Now put the other buffers into the buffer list */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { if (!(only_save_windows && buf->b_nwindows == 0) && !(buf->b_help && !(ssop_flags & SSOP_HELP)) && buf->b_fname != NULL diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index e1f9454b52..2e932e9695 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4345,11 +4345,10 @@ static int make_bom(char_u *buf, char_u *name) void shorten_fnames(int force) { char_u dirname[MAXPATHL]; - buf_T *buf; char_u *p; os_dirname(dirname, MAXPATHL); - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { if (buf->b_fname != NULL && !bt_nofile(buf) && !path_with_url(buf->b_fname) @@ -6109,7 +6108,6 @@ void ex_doautoall(exarg_T *eap) { int retval; aco_save_T aco; - buf_T *buf; char_u *arg = eap->arg; int call_do_modelines = check_nomodeline(&arg); @@ -6120,7 +6118,7 @@ void ex_doautoall(exarg_T *eap) * gives problems when the autocommands make changes to the list of * buffers or windows... */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { if (buf->b_ml.ml_mfp != NULL) { /* find a window for this buffer and save some values */ aucmd_prepbuf(&aco, buf); diff --git a/src/nvim/globals.h b/src/nvim/globals.h index a0cbedcc57..ad65f7e6fd 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -556,6 +556,9 @@ EXTERN buf_T *firstbuf INIT(= NULL); /* first buffer */ EXTERN buf_T *lastbuf INIT(= NULL); /* last buffer */ EXTERN buf_T *curbuf INIT(= NULL); /* currently active buffer */ +// Iterates over all buffers in the buffer list. +# define FOR_ALL_BUFFERS(buf) for (buf_T *buf = firstbuf; buf != NULL; buf = buf->b_next) + /* Flag that is set when switching off 'swapfile'. It means that all blocks * are to be loaded into memory. Shouldn't be global... */ EXTERN int mf_dont_release INIT(= FALSE); /* don't release blocks */ diff --git a/src/nvim/main.c b/src/nvim/main.c index 6b8c2f4d4d..1de4b04a07 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -744,7 +744,6 @@ main_loop ( /* Exit properly */ void getout(int exitval) { - buf_T *buf; win_T *wp; tabpage_T *tp, *next_tp; @@ -772,7 +771,7 @@ void getout(int exitval) if (wp->w_buffer == NULL) /* Autocmd must have close the buffer already, skip. */ continue; - buf = wp->w_buffer; + buf_T *buf = wp->w_buffer; if (buf->b_changedtick != -1) { apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, buf->b_fname, FALSE, buf); @@ -785,13 +784,14 @@ void getout(int exitval) } /* Trigger BufUnload for buffers that are loaded */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) + FOR_ALL_BUFFERS(buf) { if (buf->b_ml.ml_mfp != NULL) { apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, FALSE, buf); if (!buf_valid(buf)) /* autocmd may delete the buffer */ break; } + } apply_autocmds(EVENT_VIMLEAVEPRE, NULL, NULL, FALSE, curbuf); } diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 90abbb6fbb..43469cab45 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -1337,7 +1337,6 @@ int removable(char_u *name) int write_viminfo_marks(FILE *fp_out) { int count; - buf_T *buf; int is_mark_set; int i; win_T *win; @@ -1346,12 +1345,13 @@ int write_viminfo_marks(FILE *fp_out) /* * Set b_last_cursor for the all buffers that have a window. */ - FOR_ALL_TAB_WINDOWS(tp, win) - set_last_cursor(win); + FOR_ALL_TAB_WINDOWS(tp, win) { + set_last_cursor(win); + } fputs(_("\n# History of marks within files (newest to oldest):\n"), fp_out); count = 0; - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { /* * Only write something if buffer has been loaded and at least one * mark is set. @@ -1467,12 +1467,16 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags } } else { /* fp_out != NULL */ /* This is slow if there are many buffers!! */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) - if (buf->b_ffname != NULL) { - home_replace(NULL, buf->b_ffname, name_buf, LSIZE, TRUE); - if (fnamecmp(str, name_buf) == 0) + buf = NULL; + FOR_ALL_BUFFERS(bp) { + if (bp->b_ffname != NULL) { + home_replace(NULL, bp->b_ffname, name_buf, LSIZE, TRUE); + if (fnamecmp(str, name_buf) == 0) { + buf = bp; break; + } } + } /* * copy marks if the buffer has not been loaded diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 6e8d8f9972..82369b739a 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -613,7 +613,6 @@ static bhdr_T *mf_release(memfile_T *mfp, int page_count) { bhdr_T *hp; int need_release; - buf_T *buf; /* don't release while in mf_close_file() */ if (mf_dont_release) @@ -632,11 +631,16 @@ static bhdr_T *mf_release(memfile_T *mfp, int page_count) */ if (mfp->mf_fd < 0 && need_release && p_uc) { /* find for which buffer this memfile is */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) - if (buf->b_ml.ml_mfp == mfp) + buf_T *buf = NULL; + FOR_ALL_BUFFERS(bp) { + if (bp->b_ml.ml_mfp == mfp) { + buf = bp; break; - if (buf != NULL && buf->b_may_swap) + } + } + if (buf != NULL && buf->b_may_swap) { ml_open_file(buf); + } } /* @@ -686,12 +690,11 @@ static bhdr_T *mf_release(memfile_T *mfp, int page_count) */ int mf_release_all(void) { - buf_T *buf; memfile_T *mfp; bhdr_T *hp; int retval = FALSE; - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { mfp = buf->b_ml.ml_mfp; if (mfp != NULL) { /* If no swap file yet, may open one */ diff --git a/src/nvim/memline.c b/src/nvim/memline.c index a10fc2b8c5..229de4ae1c 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -466,11 +466,11 @@ void ml_setname(buf_T *buf) */ void ml_open_files(void) { - buf_T *buf; - - for (buf = firstbuf; buf != NULL; buf = buf->b_next) - if (!buf->b_p_ro || buf->b_changed) + FOR_ALL_BUFFERS(buf) { + if (!buf->b_p_ro || buf->b_changed) { ml_open_file(buf); + } + } } /* @@ -584,11 +584,10 @@ void ml_close(buf_T *buf, int del_file) */ void ml_close_all(int del_file) { - buf_T *buf; - - for (buf = firstbuf; buf != NULL; buf = buf->b_next) + FOR_ALL_BUFFERS(buf) { ml_close(buf, del_file && ((buf->b_flags & BF_PRESERVED) == 0 || vim_strchr(p_cpo, CPO_PRESERVE) == NULL)); + } spell_delete_wordlist(); /* delete the internal wordlist */ vim_deltempdir(); /* delete created temp directory */ } @@ -599,11 +598,11 @@ void ml_close_all(int del_file) */ void ml_close_notmod(void) { - buf_T *buf; - - for (buf = firstbuf; buf != NULL; buf = buf->b_next) - if (!bufIsChanged(buf)) + FOR_ALL_BUFFERS(buf) { + if (!bufIsChanged(buf)) { ml_close(buf, TRUE); /* close all not-modified buffers */ + } + } } /* @@ -1617,9 +1616,7 @@ static int recov_file_names(char_u **names, char_u *path, int prepend_dot) */ void ml_sync_all(int check_file, int check_char) { - buf_T *buf; - - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { if (buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp->mf_fname == NULL) continue; /* no file */ diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 6ba1e68d64..f0c4ee492e 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -3329,8 +3329,6 @@ void prepare_to_exit(void) */ void preserve_exit(void) { - buf_T *buf; - // Prevent repeated calls into this method. if (really_exiting) { exit(2); @@ -3346,7 +3344,7 @@ void preserve_exit(void) ml_close_notmod(); /* close all not-modified buffers */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) { OUT_STR("Vim: preserving files...\n"); screen_start(); /* don't know where cursor is now */ diff --git a/src/nvim/option.c b/src/nvim/option.c index 943bda88dc..63ea2ee338 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -7677,7 +7677,6 @@ static void paste_option_changed(void) static int save_ru = 0; static int save_ri = 0; static int save_hkmap = 0; - buf_T *buf; if (p_paste) { /* @@ -7686,7 +7685,7 @@ static void paste_option_changed(void) */ if (!old_p_paste) { /* save options for each buffer */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { buf->b_p_tw_nopaste = buf->b_p_tw; buf->b_p_wm_nopaste = buf->b_p_wm; buf->b_p_sts_nopaste = buf->b_p_sts; @@ -7710,7 +7709,7 @@ static void paste_option_changed(void) * already on. */ /* set options for each buffer */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { buf->b_p_tw = 0; /* textwidth is 0 */ buf->b_p_wm = 0; /* wrapmargin is 0 */ buf->b_p_sts = 0; /* softtabstop is 0 */ @@ -7735,7 +7734,7 @@ static void paste_option_changed(void) */ else if (old_p_paste) { /* restore options for each buffer */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + FOR_ALL_BUFFERS(buf) { buf->b_p_tw = buf->b_p_tw_nopaste; buf->b_p_wm = buf->b_p_wm_nopaste; buf->b_p_sts = buf->b_p_sts_nopaste; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 17093571c0..d277d71d99 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -4131,11 +4131,11 @@ void spell_delete_wordlist(void) void spell_free_all(void) { slang_T *slang; - buf_T *buf; // Go through all buffers and handle 'spelllang'. <VN> - for (buf = firstbuf; buf != NULL; buf = buf->b_next) + FOR_ALL_BUFFERS(buf) { ga_clear(&buf->b_s.b_langp); + } while (first_lang != NULL) { slang = first_lang; diff --git a/src/nvim/window.c b/src/nvim/window.c index 755ecb0ef1..050f5e2acd 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -3576,7 +3576,6 @@ win_free ( ) { int i; - buf_T *buf; wininfo_T *wip; handle_unregister_window(wp); @@ -3589,13 +3588,6 @@ win_free ( * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */ block_autocmds(); - - - - - - - clear_winopt(&wp->w_onebuf_opt); clear_winopt(&wp->w_allbuf_opt); @@ -3614,10 +3606,11 @@ win_free ( /* Remove the window from the b_wininfo lists, it may happen that the * freed memory is re-used for another window. */ - for (buf = firstbuf; buf != NULL; buf = buf->b_next) + FOR_ALL_BUFFERS(buf) { for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) if (wip->wi_win == wp) wip->wi_win = NULL; + } clear_matches(wp); |