diff options
Diffstat (limited to 'src/nvim/ex_cmds2.c')
-rw-r--r-- | src/nvim/ex_cmds2.c | 47 |
1 files changed, 27 insertions, 20 deletions
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. */ |