mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Add FOR_ALL_BUFFERS helper
This commit is contained in:
parent
44afe610f8
commit
8cf45786b1
@ -115,9 +115,11 @@ open_buffer (
|
|||||||
* If we can't create one for the current buffer, take another buffer
|
* If we can't create one for the current buffer, take another buffer
|
||||||
*/
|
*/
|
||||||
close_buffer(NULL, curbuf, 0, FALSE);
|
close_buffer(NULL, curbuf, 0, FALSE);
|
||||||
for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
|
FOR_ALL_BUFFERS(curbuf) {
|
||||||
if (curbuf->b_ml.ml_mfp != NULL)
|
if (curbuf->b_ml.ml_mfp != NULL)
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if there is no memfile at all, exit
|
* if there is no memfile at all, exit
|
||||||
* This is OK, since there are no changes to lose.
|
* This is OK, since there are no changes to lose.
|
||||||
@ -262,9 +264,11 @@ int buf_valid(buf_T *buf)
|
|||||||
{
|
{
|
||||||
buf_T *bp;
|
buf_T *bp;
|
||||||
|
|
||||||
for (bp = firstbuf; bp != NULL; bp = bp->b_next)
|
FOR_ALL_BUFFERS(bp) {
|
||||||
if (bp == buf)
|
if (bp == buf) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -946,9 +950,11 @@ do_buffer (
|
|||||||
* If deleting the last (listed) buffer, make it empty.
|
* If deleting the last (listed) buffer, make it empty.
|
||||||
* The last (listed) buffer cannot be unloaded.
|
* The last (listed) buffer cannot be unloaded.
|
||||||
*/
|
*/
|
||||||
for (bp = firstbuf; bp != NULL; bp = bp->b_next)
|
FOR_ALL_BUFFERS(bp) {
|
||||||
if (bp->b_p_bl && bp != buf)
|
if (bp->b_p_bl && bp != buf) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (bp == NULL && buf == curbuf)
|
if (bp == NULL && buf == curbuf)
|
||||||
return empty_curbuf(TRUE, forceit, action);
|
return empty_curbuf(TRUE, forceit, action);
|
||||||
|
|
||||||
@ -1047,9 +1053,11 @@ do_buffer (
|
|||||||
if (buf == NULL) /* No loaded buffer, use unloaded one */
|
if (buf == NULL) /* No loaded buffer, use unloaded one */
|
||||||
buf = bp;
|
buf = bp;
|
||||||
if (buf == NULL) { /* No loaded buffer, find listed one */
|
if (buf == NULL) { /* No loaded buffer, find listed one */
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (buf->b_p_bl && buf != curbuf)
|
if (buf->b_p_bl && buf != curbuf) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (buf == NULL) { /* Still no buffer, just take one */
|
if (buf == NULL) { /* Still no buffer, just take one */
|
||||||
if (curbuf->b_next != NULL)
|
if (curbuf->b_next != NULL)
|
||||||
@ -1671,7 +1679,7 @@ static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id,
|
|||||||
{
|
{
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
|
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next) {
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if ((buf->b_flags & BF_DUMMY) == 0
|
if ((buf->b_flags & BF_DUMMY) == 0
|
||||||
&& !otherfile_buf(buf, ffname, file_id, file_id_valid)) {
|
&& !otherfile_buf(buf, ffname, file_id, file_id_valid)) {
|
||||||
return buf;
|
return buf;
|
||||||
@ -1745,7 +1753,7 @@ buflist_findpat (
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (buf->b_p_bl == find_listed
|
if (buf->b_p_bl == find_listed
|
||||||
&& (!diffmode || diff_mode_buf(buf))
|
&& (!diffmode || diff_mode_buf(buf))
|
||||||
&& buflist_match(prog, buf) != NULL) {
|
&& buflist_match(prog, buf) != NULL) {
|
||||||
@ -1766,6 +1774,7 @@ buflist_findpat (
|
|||||||
}
|
}
|
||||||
match = buf->b_fnum; /* remember first match */
|
match = buf->b_fnum; /* remember first match */
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vim_regfree(prog);
|
vim_regfree(prog);
|
||||||
if (match >= 0) /* found one match */
|
if (match >= 0) /* found one match */
|
||||||
@ -1836,7 +1845,7 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options)
|
|||||||
*/
|
*/
|
||||||
for (round = 1; round <= 2; ++round) {
|
for (round = 1; round <= 2; ++round) {
|
||||||
count = 0;
|
count = 0;
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next) {
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (!buf->b_p_bl) /* skip unlisted buffers */
|
if (!buf->b_p_bl) /* skip unlisted buffers */
|
||||||
continue;
|
continue;
|
||||||
p = buflist_match(prog, buf);
|
p = buflist_match(prog, buf);
|
||||||
@ -1924,9 +1933,11 @@ buf_T *buflist_findnr(int nr)
|
|||||||
|
|
||||||
if (nr == 0)
|
if (nr == 0)
|
||||||
nr = curwin->w_alt_fnum;
|
nr = curwin->w_alt_fnum;
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (buf->b_fnum == nr)
|
if (buf->b_fnum == nr) {
|
||||||
return buf;
|
return buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2345,7 +2356,7 @@ void buflist_slash_adjust(void)
|
|||||||
{
|
{
|
||||||
buf_T *bp;
|
buf_T *bp;
|
||||||
|
|
||||||
for (bp = firstbuf; bp != NULL; bp = bp->b_next) {
|
FOR_ALL_BUFFERS(bp) {
|
||||||
if (bp->b_ffname != NULL)
|
if (bp->b_ffname != NULL)
|
||||||
slash_adjust(bp->b_ffname);
|
slash_adjust(bp->b_ffname);
|
||||||
if (bp->b_sfname != NULL)
|
if (bp->b_sfname != NULL)
|
||||||
@ -4212,7 +4223,7 @@ void write_viminfo_bufferlist(FILE *fp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fputs(_("\n# Buffer list:\n"), 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
|
if (buf->b_fname == NULL
|
||||||
|| !buf->b_p_bl
|
|| !buf->b_p_bl
|
||||||
|| bt_quickfix(buf)
|
|| bt_quickfix(buf)
|
||||||
@ -4489,7 +4500,7 @@ void buf_delete_all_signs(void)
|
|||||||
{
|
{
|
||||||
buf_T *buf; /* buffer we are checking for signs */
|
buf_T *buf; /* buffer we are checking for signs */
|
||||||
|
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next) {
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (buf->b_signlist != NULL) {
|
if (buf->b_signlist != NULL) {
|
||||||
buf_delete_signs(buf);
|
buf_delete_signs(buf);
|
||||||
}
|
}
|
||||||
|
@ -3434,8 +3434,9 @@ static int ins_compl_get_exp(pos_T *ini)
|
|||||||
int set_match_pos;
|
int set_match_pos;
|
||||||
|
|
||||||
if (!compl_started) {
|
if (!compl_started) {
|
||||||
for (ins_buf = firstbuf; ins_buf != NULL; ins_buf = ins_buf->b_next)
|
FOR_ALL_BUFFERS(ins_buf) {
|
||||||
ins_buf->b_scanned = 0;
|
ins_buf->b_scanned = 0;
|
||||||
|
}
|
||||||
found_all = FALSE;
|
found_all = FALSE;
|
||||||
ins_buf = curbuf;
|
ins_buf = curbuf;
|
||||||
e_cpt = (compl_cont_status & CONT_LOCAL)
|
e_cpt = (compl_cont_status & CONT_LOCAL)
|
||||||
|
@ -5434,8 +5434,9 @@ int garbage_collect(void)
|
|||||||
set_ref_in_ht(&SCRIPT_VARS(i), copyID);
|
set_ref_in_ht(&SCRIPT_VARS(i), copyID);
|
||||||
|
|
||||||
/* buffer-local variables */
|
/* 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);
|
set_ref_in_item(&buf->b_bufvar.di_tv, copyID);
|
||||||
|
}
|
||||||
|
|
||||||
/* window-local variables */
|
/* window-local variables */
|
||||||
FOR_ALL_TAB_WINDOWS(tp, wp)
|
FOR_ALL_TAB_WINDOWS(tp, wp)
|
||||||
@ -7207,13 +7208,14 @@ static buf_T *find_buffer(typval_T *avar)
|
|||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
/* No full path name match, try a match with a URL or a "nofile"
|
/* No full path name match, try a match with a URL or a "nofile"
|
||||||
* buffer, these don't use the full path. */
|
* buffer, these don't use the full path. */
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (buf->b_fname != NULL
|
if (buf->b_fname != NULL
|
||||||
&& (path_with_url(buf->b_fname)
|
&& (path_with_url(buf->b_fname)
|
||||||
|| bt_nofile(buf)
|
|| bt_nofile(buf)
|
||||||
)
|
)
|
||||||
&& STRCMP(buf->b_fname, avar->vval.v_string) == 0)
|
&& STRCMP(buf->b_fname, avar->vval.v_string) == 0)
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
@ -10617,9 +10619,11 @@ static void f_last_buffer_nr(typval_T *argvars, typval_T *rettv)
|
|||||||
int n = 0;
|
int n = 0;
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
|
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (n < buf->b_fnum)
|
if (n < buf->b_fnum) {
|
||||||
n = buf->b_fnum;
|
n = buf->b_fnum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rettv->vval.v_number = n;
|
rettv->vval.v_number = n;
|
||||||
}
|
}
|
||||||
|
@ -1239,11 +1239,12 @@ do_shell (
|
|||||||
if (p_warn
|
if (p_warn
|
||||||
&& !autocmd_busy
|
&& !autocmd_busy
|
||||||
&& msg_silent == 0)
|
&& msg_silent == 0)
|
||||||
for (buf = firstbuf; buf; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (bufIsChanged(buf)) {
|
if (bufIsChanged(buf)) {
|
||||||
MSG_PUTS(_("[No write since last change]\n"));
|
MSG_PUTS(_("[No write since last change]\n"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* This windgoto is required for when the '\n' resulted in a "delete line
|
/* This windgoto is required for when the '\n' resulted in a "delete line
|
||||||
* 1" command to the terminal. */
|
* 1" command to the terminal. */
|
||||||
@ -1810,8 +1811,9 @@ static int read_viminfo_up_to_marks(vir_T *virp, int forceit, int writing)
|
|||||||
finish_viminfo_history();
|
finish_viminfo_history();
|
||||||
|
|
||||||
/* Change file names to buffer numbers for fmarks. */
|
/* 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);
|
fmarks_check_names(buf);
|
||||||
|
}
|
||||||
|
|
||||||
return eof;
|
return eof;
|
||||||
}
|
}
|
||||||
@ -2363,7 +2365,7 @@ void do_wqall(exarg_T *eap)
|
|||||||
if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall)
|
if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall)
|
||||||
exiting = TRUE;
|
exiting = TRUE;
|
||||||
|
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next) {
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (bufIsChanged(buf)) {
|
if (bufIsChanged(buf)) {
|
||||||
/*
|
/*
|
||||||
* Check if there is a reason the buffer cannot be written:
|
* Check if there is a reason the buffer cannot be written:
|
||||||
@ -5900,10 +5902,11 @@ void ex_sign(exarg_T *eap)
|
|||||||
if (idx == SIGNCMD_UNPLACE && *arg == NUL)
|
if (idx == SIGNCMD_UNPLACE && *arg == NUL)
|
||||||
{
|
{
|
||||||
/* ":sign unplace {id}": remove placed sign by number */
|
/* ":sign unplace {id}": remove placed sign by number */
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if ((lnum = buf_delsign(buf, id)) != 0)
|
if ((lnum = buf_delsign(buf, id)) != 0)
|
||||||
update_debug_sign(buf, lnum);
|
update_debug_sign(buf, lnum);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1048,13 +1048,14 @@ void autowrite_all(void)
|
|||||||
|
|
||||||
if (!(p_aw || p_awa) || !p_write)
|
if (!(p_aw || p_awa) || !p_write)
|
||||||
return;
|
return;
|
||||||
for (buf = firstbuf; buf; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (bufIsChanged(buf) && !buf->b_p_ro) {
|
if (bufIsChanged(buf) && !buf->b_p_ro) {
|
||||||
(void)buf_write_all(buf, FALSE);
|
(void)buf_write_all(buf, FALSE);
|
||||||
/* an autocommand may have deleted the buffer */
|
/* an autocommand may have deleted the buffer */
|
||||||
if (!buf_valid(buf))
|
if (!buf_valid(buf))
|
||||||
buf = firstbuf;
|
buf = firstbuf;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1074,11 +1075,11 @@ int check_changed(buf_T *buf, int flags)
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if (flags & CCGD_ALLBUF)
|
if (flags & CCGD_ALLBUF)
|
||||||
for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
|
FOR_ALL_BUFFERS(buf2) {
|
||||||
if (bufIsChanged(buf2)
|
if (bufIsChanged(buf2) && (buf2->b_ffname != NULL)) {
|
||||||
&& (buf2->b_ffname != NULL
|
|
||||||
))
|
|
||||||
++count;
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!buf_valid(buf))
|
if (!buf_valid(buf))
|
||||||
/* Autocommand deleted buffer, oops! It's not changed now. */
|
/* Autocommand deleted buffer, oops! It's not changed now. */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -1139,7 +1140,7 @@ dialog_changed (
|
|||||||
* Skip readonly buffers, these need to be confirmed
|
* Skip readonly buffers, these need to be confirmed
|
||||||
* individually.
|
* individually.
|
||||||
*/
|
*/
|
||||||
for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next) {
|
FOR_ALL_BUFFERS(buf2) {
|
||||||
if (bufIsChanged(buf2)
|
if (bufIsChanged(buf2)
|
||||||
&& (buf2->b_ffname != NULL
|
&& (buf2->b_ffname != NULL
|
||||||
)
|
)
|
||||||
@ -1157,8 +1158,9 @@ dialog_changed (
|
|||||||
/*
|
/*
|
||||||
* mark all buffers as unchanged
|
* mark all buffers as unchanged
|
||||||
*/
|
*/
|
||||||
for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
|
FOR_ALL_BUFFERS(buf2) {
|
||||||
unchanged(buf2, TRUE);
|
unchanged(buf2, TRUE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1209,8 +1211,9 @@ check_changed_any (
|
|||||||
tabpage_T *tp;
|
tabpage_T *tp;
|
||||||
win_T *wp;
|
win_T *wp;
|
||||||
|
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
++bufcount;
|
++bufcount;
|
||||||
|
}
|
||||||
|
|
||||||
if (bufcount == 0)
|
if (bufcount == 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -1230,8 +1233,9 @@ check_changed_any (
|
|||||||
for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
|
for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
|
||||||
add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
|
add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
|
||||||
/* any other buf */
|
/* any other buf */
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
add_bufnum(bufnrs, &bufnum, buf->b_fnum);
|
add_bufnum(bufnrs, &bufnum, buf->b_fnum);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < bufnum; ++i) {
|
for (i = 0; i < bufnum; ++i) {
|
||||||
buf = buflist_findnr(bufnrs[i]);
|
buf = buflist_findnr(bufnrs[i]);
|
||||||
@ -1898,9 +1902,11 @@ void ex_listdo(exarg_T *eap)
|
|||||||
if (next_fnum < 0)
|
if (next_fnum < 0)
|
||||||
break;
|
break;
|
||||||
/* Check if the buffer still exists. */
|
/* Check if the buffer still exists. */
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (buf->b_fnum == next_fnum)
|
if (buf->b_fnum == next_fnum) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -7943,7 +7943,7 @@ makeopens (
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
/* Now put the other buffers into the buffer list */
|
/* 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)
|
if (!(only_save_windows && buf->b_nwindows == 0)
|
||||||
&& !(buf->b_help && !(ssop_flags & SSOP_HELP))
|
&& !(buf->b_help && !(ssop_flags & SSOP_HELP))
|
||||||
&& buf->b_fname != NULL
|
&& buf->b_fname != NULL
|
||||||
|
@ -4363,7 +4363,7 @@ void shorten_fnames(int force)
|
|||||||
char_u *p;
|
char_u *p;
|
||||||
|
|
||||||
os_dirname(dirname, MAXPATHL);
|
os_dirname(dirname, MAXPATHL);
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next) {
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (buf->b_fname != NULL
|
if (buf->b_fname != NULL
|
||||||
&& !bt_nofile(buf)
|
&& !bt_nofile(buf)
|
||||||
&& !path_with_url(buf->b_fname)
|
&& !path_with_url(buf->b_fname)
|
||||||
@ -6134,7 +6134,7 @@ void ex_doautoall(exarg_T *eap)
|
|||||||
* gives problems when the autocommands make changes to the list of
|
* gives problems when the autocommands make changes to the list of
|
||||||
* buffers or windows...
|
* buffers or windows...
|
||||||
*/
|
*/
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next) {
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (buf->b_ml.ml_mfp != NULL) {
|
if (buf->b_ml.ml_mfp != NULL) {
|
||||||
/* find a window for this buffer and save some values */
|
/* find a window for this buffer and save some values */
|
||||||
aucmd_prepbuf(&aco, buf);
|
aucmd_prepbuf(&aco, buf);
|
||||||
|
@ -556,6 +556,9 @@ EXTERN buf_T *firstbuf INIT(= NULL); /* first buffer */
|
|||||||
EXTERN buf_T *lastbuf INIT(= NULL); /* last buffer */
|
EXTERN buf_T *lastbuf INIT(= NULL); /* last buffer */
|
||||||
EXTERN buf_T *curbuf INIT(= NULL); /* currently active 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 = firstbuf; buf != NULL; buf = buf->b_next)
|
||||||
|
|
||||||
/* Flag that is set when switching off 'swapfile'. It means that all blocks
|
/* Flag that is set when switching off 'swapfile'. It means that all blocks
|
||||||
* are to be loaded into memory. Shouldn't be global... */
|
* are to be loaded into memory. Shouldn't be global... */
|
||||||
EXTERN int mf_dont_release INIT(= FALSE); /* don't release blocks */
|
EXTERN int mf_dont_release INIT(= FALSE); /* don't release blocks */
|
||||||
|
@ -785,13 +785,14 @@ void getout(int exitval)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Trigger BufUnload for buffers that are loaded */
|
/* 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) {
|
if (buf->b_ml.ml_mfp != NULL) {
|
||||||
apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname,
|
apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname,
|
||||||
FALSE, buf);
|
FALSE, buf);
|
||||||
if (!buf_valid(buf)) /* autocmd may delete the buffer */
|
if (!buf_valid(buf)) /* autocmd may delete the buffer */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
apply_autocmds(EVENT_VIMLEAVEPRE, NULL, NULL, FALSE, curbuf);
|
apply_autocmds(EVENT_VIMLEAVEPRE, NULL, NULL, FALSE, curbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1351,7 +1351,7 @@ int write_viminfo_marks(FILE *fp_out)
|
|||||||
|
|
||||||
fputs(_("\n# History of marks within files (newest to oldest):\n"), fp_out);
|
fputs(_("\n# History of marks within files (newest to oldest):\n"), fp_out);
|
||||||
count = 0;
|
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
|
* Only write something if buffer has been loaded and at least one
|
||||||
* mark is set.
|
* mark is set.
|
||||||
@ -1467,12 +1467,13 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags
|
|||||||
}
|
}
|
||||||
} else { /* fp_out != NULL */
|
} else { /* fp_out != NULL */
|
||||||
/* This is slow if there are many buffers!! */
|
/* This is slow if there are many buffers!! */
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (buf->b_ffname != NULL) {
|
if (buf->b_ffname != NULL) {
|
||||||
home_replace(NULL, buf->b_ffname, name_buf, LSIZE, TRUE);
|
home_replace(NULL, buf->b_ffname, name_buf, LSIZE, TRUE);
|
||||||
if (fnamecmp(str, name_buf) == 0)
|
if (fnamecmp(str, name_buf) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* copy marks if the buffer has not been loaded
|
* copy marks if the buffer has not been loaded
|
||||||
|
@ -632,9 +632,11 @@ static bhdr_T *mf_release(memfile_T *mfp, int page_count)
|
|||||||
*/
|
*/
|
||||||
if (mfp->mf_fd < 0 && need_release && p_uc) {
|
if (mfp->mf_fd < 0 && need_release && p_uc) {
|
||||||
/* find for which buffer this memfile is */
|
/* find for which buffer this memfile is */
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (buf->b_ml.ml_mfp == mfp)
|
if (buf->b_ml.ml_mfp == mfp) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (buf != NULL && buf->b_may_swap)
|
if (buf != NULL && buf->b_may_swap)
|
||||||
ml_open_file(buf);
|
ml_open_file(buf);
|
||||||
}
|
}
|
||||||
@ -691,7 +693,7 @@ int mf_release_all(void)
|
|||||||
bhdr_T *hp;
|
bhdr_T *hp;
|
||||||
int retval = FALSE;
|
int retval = FALSE;
|
||||||
|
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next) {
|
FOR_ALL_BUFFERS(buf) {
|
||||||
mfp = buf->b_ml.ml_mfp;
|
mfp = buf->b_ml.ml_mfp;
|
||||||
if (mfp != NULL) {
|
if (mfp != NULL) {
|
||||||
/* If no swap file yet, may open one */
|
/* If no swap file yet, may open one */
|
||||||
|
@ -468,9 +468,11 @@ void ml_open_files(void)
|
|||||||
{
|
{
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
|
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (!buf->b_p_ro || buf->b_changed)
|
if (!buf->b_p_ro || buf->b_changed) {
|
||||||
ml_open_file(buf);
|
ml_open_file(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -586,9 +588,10 @@ void ml_close_all(int del_file)
|
|||||||
{
|
{
|
||||||
buf_T *buf;
|
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
|
ml_close(buf, del_file && ((buf->b_flags & BF_PRESERVED) == 0
|
||||||
|| vim_strchr(p_cpo, CPO_PRESERVE) == NULL));
|
|| vim_strchr(p_cpo, CPO_PRESERVE) == NULL));
|
||||||
|
}
|
||||||
spell_delete_wordlist(); /* delete the internal wordlist */
|
spell_delete_wordlist(); /* delete the internal wordlist */
|
||||||
vim_deltempdir(); /* delete created temp directory */
|
vim_deltempdir(); /* delete created temp directory */
|
||||||
}
|
}
|
||||||
@ -601,9 +604,11 @@ void ml_close_notmod(void)
|
|||||||
{
|
{
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
|
|
||||||
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (!bufIsChanged(buf))
|
if (!bufIsChanged(buf)) {
|
||||||
ml_close(buf, TRUE); /* close all not-modified buffers */
|
ml_close(buf, TRUE); /* close all not-modified buffers */
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1619,7 +1624,7 @@ void ml_sync_all(int check_file, int check_char)
|
|||||||
{
|
{
|
||||||
buf_T *buf;
|
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)
|
if (buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp->mf_fname == NULL)
|
||||||
continue; /* no file */
|
continue; /* no file */
|
||||||
|
|
||||||
|
@ -3346,7 +3346,7 @@ void preserve_exit(void)
|
|||||||
|
|
||||||
ml_close_notmod(); /* close all not-modified buffers */
|
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) {
|
if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) {
|
||||||
OUT_STR("Vim: preserving files...\n");
|
OUT_STR("Vim: preserving files...\n");
|
||||||
screen_start(); /* don't know where cursor is now */
|
screen_start(); /* don't know where cursor is now */
|
||||||
|
@ -4977,7 +4977,7 @@ set_bool_option (
|
|||||||
char_u hash[UNDO_HASH_SIZE];
|
char_u hash[UNDO_HASH_SIZE];
|
||||||
buf_T *save_curbuf = curbuf;
|
buf_T *save_curbuf = curbuf;
|
||||||
|
|
||||||
for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next) {
|
FOR_ALL_BUFFERS(curbuf) {
|
||||||
/* When 'undofile' is set globally: for every buffer, otherwise
|
/* When 'undofile' is set globally: for every buffer, otherwise
|
||||||
* only for the current buffer: Try to read in the undofile,
|
* only for the current buffer: Try to read in the undofile,
|
||||||
* if one exists, the buffer wasn't changed and the buffer was
|
* if one exists, the buffer wasn't changed and the buffer was
|
||||||
@ -7703,7 +7703,7 @@ static void paste_option_changed(void)
|
|||||||
*/
|
*/
|
||||||
if (!old_p_paste) {
|
if (!old_p_paste) {
|
||||||
/* save options for each buffer */
|
/* 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_tw_nopaste = buf->b_p_tw;
|
||||||
buf->b_p_wm_nopaste = buf->b_p_wm;
|
buf->b_p_wm_nopaste = buf->b_p_wm;
|
||||||
buf->b_p_sts_nopaste = buf->b_p_sts;
|
buf->b_p_sts_nopaste = buf->b_p_sts;
|
||||||
@ -7727,7 +7727,7 @@ static void paste_option_changed(void)
|
|||||||
* already on.
|
* already on.
|
||||||
*/
|
*/
|
||||||
/* set options for each buffer */
|
/* 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_tw = 0; /* textwidth is 0 */
|
||||||
buf->b_p_wm = 0; /* wrapmargin is 0 */
|
buf->b_p_wm = 0; /* wrapmargin is 0 */
|
||||||
buf->b_p_sts = 0; /* softtabstop is 0 */
|
buf->b_p_sts = 0; /* softtabstop is 0 */
|
||||||
@ -7752,7 +7752,7 @@ static void paste_option_changed(void)
|
|||||||
*/
|
*/
|
||||||
else if (old_p_paste) {
|
else if (old_p_paste) {
|
||||||
/* restore options for each buffer */
|
/* 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_tw = buf->b_p_tw_nopaste;
|
||||||
buf->b_p_wm = buf->b_p_wm_nopaste;
|
buf->b_p_wm = buf->b_p_wm_nopaste;
|
||||||
buf->b_p_sts = buf->b_p_sts_nopaste;
|
buf->b_p_sts = buf->b_p_sts_nopaste;
|
||||||
|
@ -4142,8 +4142,9 @@ void spell_free_all(void)
|
|||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
|
|
||||||
// Go through all buffers and handle 'spelllang'. <VN>
|
// 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);
|
ga_clear(&buf->b_s.b_langp);
|
||||||
|
}
|
||||||
|
|
||||||
while (first_lang != NULL) {
|
while (first_lang != NULL) {
|
||||||
slang = first_lang;
|
slang = first_lang;
|
||||||
|
@ -1608,7 +1608,7 @@ int set_termname(char_u *term)
|
|||||||
* loaded.
|
* loaded.
|
||||||
*/
|
*/
|
||||||
buf_T *old_curbuf = curbuf;
|
buf_T *old_curbuf = curbuf;
|
||||||
for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next) {
|
FOR_ALL_BUFFERS(curbuf) {
|
||||||
if (curbuf->b_ml.ml_mfp != NULL)
|
if (curbuf->b_ml.ml_mfp != NULL)
|
||||||
apply_autocmds(EVENT_TERMCHANGED, NULL, NULL, FALSE,
|
apply_autocmds(EVENT_TERMCHANGED, NULL, NULL, FALSE,
|
||||||
curbuf);
|
curbuf);
|
||||||
|
@ -3609,10 +3609,11 @@ win_free (
|
|||||||
|
|
||||||
/* Remove the window from the b_wininfo lists, it may happen that the
|
/* Remove the window from the b_wininfo lists, it may happen that the
|
||||||
* freed memory is re-used for another window. */
|
* 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)
|
for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
|
||||||
if (wip->wi_win == wp)
|
if (wip->wi_win == wp)
|
||||||
wip->wi_win = NULL;
|
wip->wi_win = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
clear_matches(wp);
|
clear_matches(wp);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user