cleanup/ex_docmd.c: remove most put_line() calls

- prefer fprintf() instead of put_line()
- PUTLINE_FAIL macro to avoid some boilerplate
This commit is contained in:
Justin M. Keyes
2020-01-26 03:45:48 -08:00
parent 2c1d12d0be
commit 2070c082b5
2 changed files with 170 additions and 181 deletions

View File

@@ -8085,6 +8085,9 @@ static void close_redir(void)
} }
} }
#define PUTLINE_FAIL(s) \
do { if (FAIL == put_line(fd, (s))) { return FAIL; } } while (0)
/// ":mkexrc", ":mkvimrc", ":mkview", ":mksession". /// ":mkexrc", ":mkvimrc", ":mkview", ":mksession".
static void ex_mkrc(exarg_T *eap) static void ex_mkrc(exarg_T *eap)
{ {
@@ -8137,9 +8140,10 @@ static void ex_mkrc(exarg_T *eap)
else else
flagp = &ssop_flags; flagp = &ssop_flags;
/* Write the version command for :mkvimrc */ // Write the version command for :mkvimrc
if (eap->cmdidx == CMD_mkvimrc) if (eap->cmdidx == CMD_mkvimrc) {
(void)put_line(fd, "version 6.0"); (void)put_line(fd, "version 6.0");
}
if (eap->cmdidx == CMD_mksession) { if (eap->cmdidx == CMD_mksession) {
if (put_line(fd, "let SessionLoad = 1") == FAIL) if (put_line(fd, "let SessionLoad = 1") == FAIL)
@@ -8200,14 +8204,17 @@ static void ex_mkrc(exarg_T *eap)
failed |= (put_view(fd, curwin, !using_vdir, flagp, failed |= (put_view(fd, curwin, !using_vdir, flagp,
-1) == FAIL); -1) == FAIL);
} }
if (put_line(fd, "let &so = s:so_save | let &siso = s:siso_save") if (fprintf(fd,
== FAIL) "%s",
failed = TRUE; "let &so = s:so_save | let &siso = s:siso_save\n"
if (put_line(fd, "doautoall SessionLoadPost") == FAIL) "doautoall SessionLoadPost\n")
failed = TRUE; < 0) {
failed = true;
}
if (eap->cmdidx == CMD_mksession) { if (eap->cmdidx == CMD_mksession) {
if (put_line(fd, "unlet SessionLoad") == FAIL) if (fprintf(fd, "unlet SessionLoad\n") < 0) {
failed = TRUE; failed = true;
}
} }
} }
if (put_line(fd, "\" vim: set ft=vim :") == FAIL) if (put_line(fd, "\" vim: set ft=vim :") == FAIL)
@@ -9127,28 +9134,21 @@ static int makeopens(FILE *fd, char_u *dirnow)
only_save_windows = FALSE; /* Save ALL buffers */ only_save_windows = FALSE; /* Save ALL buffers */
// Begin by setting v:this_session, and then other sessionable variables. // Begin by setting v:this_session, and then other sessionable variables.
if (put_line(fd, "let v:this_session=expand(\"<sfile>:p\")") == FAIL) { PUTLINE_FAIL("let v:this_session=expand(\"<sfile>:p\")");
return FAIL;
}
if (ssop_flags & SSOP_GLOBALS) { if (ssop_flags & SSOP_GLOBALS) {
if (store_session_globals(fd) == FAIL) { if (store_session_globals(fd) == FAIL) {
return FAIL; return FAIL;
} }
} }
/* // Close all windows but one.
* Close all windows but one. PUTLINE_FAIL("silent only");
*/
if (put_line(fd, "silent only") == FAIL)
return FAIL;
/* //
* Now a :cd command to the session directory or the current directory // Now a :cd command to the session directory or the current directory
*/ //
if (ssop_flags & SSOP_SESDIR) { if (ssop_flags & SSOP_SESDIR) {
if (put_line(fd, "exe \"cd \" . escape(expand(\"<sfile>:p:h\"), ' ')") PUTLINE_FAIL("exe \"cd \" . escape(expand(\"<sfile>:p:h\"), ' ')");
== FAIL)
return FAIL;
} else if (ssop_flags & SSOP_CURDIR) { } else if (ssop_flags & SSOP_CURDIR) {
sname = home_replace_save(NULL, globaldir != NULL ? globaldir : dirnow); sname = home_replace_save(NULL, globaldir != NULL ? globaldir : dirnow);
if (fputs("cd ", fd) < 0 if (fputs("cd ", fd) < 0
@@ -9160,27 +9160,20 @@ static int makeopens(FILE *fd, char_u *dirnow)
xfree(sname); xfree(sname);
} }
/* if (fprintf(fd,
* If there is an empty, unnamed buffer we will wipe it out later. "%s",
* Remember the buffer number. // If there is an empty, unnamed buffer we will wipe it out later.
*/ // Remember the buffer number.
if (put_line(fd, "if expand('%') == '' && !&modified && line('$') <= 1"
"if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''") " && getline(1) == ''\n"
== " let s:wipebuf = bufnr('%')\n"
FAIL) "endif\n"
return FAIL; // Now save the current files, current buffer first.
if (put_line(fd, " let s:wipebuf = bufnr('%')") == FAIL) "set shortmess=aoO\n") < 0) {
return FAIL;
if (put_line(fd, "endif") == FAIL)
return FAIL; return FAIL;
}
/* // Now put the other buffers into the buffer list.
* Now save the current files, current buffer first.
*/
if (put_line(fd, "set shortmess=aoO") == FAIL)
return FAIL;
/* Now put the other buffers into the buffer list */
FOR_ALL_BUFFERS(buf) { 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))
@@ -9216,9 +9209,7 @@ static int makeopens(FILE *fd, char_u *dirnow)
// in the first tab, which may cause problems. Set 'showtabline' to 2 // in the first tab, which may cause problems. Set 'showtabline' to 2
// temporarily to avoid that. // temporarily to avoid that.
if (p_stal == 1 && first_tabpage->tp_next != NULL) { if (p_stal == 1 && first_tabpage->tp_next != NULL) {
if (put_line(fd, "set stal=2") == FAIL) { PUTLINE_FAIL("set stal=2");
return FAIL;
}
restore_stal = TRUE; restore_stal = TRUE;
} }
@@ -9273,26 +9264,29 @@ static int makeopens(FILE *fd, char_u *dirnow)
} }
} }
/* If no file got edited create an empty tab page. */ // If no file got edited create an empty tab page.
if (need_tabnew && put_line(fd, "tabnew") == FAIL) if (need_tabnew && put_line(fd, "tabnew") == FAIL) {
return FAIL; return FAIL;
}
/* //
* Save current window layout. // Save current window layout.
*/ //
if (put_line(fd, "set splitbelow splitright") == FAIL) PUTLINE_FAIL("set splitbelow splitright");
if (ses_win_rec(fd, tab_topframe) == FAIL) {
return FAIL; return FAIL;
if (ses_win_rec(fd, tab_topframe) == FAIL) }
if (!p_sb && put_line(fd, "set nosplitbelow") == FAIL) {
return FAIL; return FAIL;
if (!p_sb && put_line(fd, "set nosplitbelow") == FAIL) }
return FAIL; if (!p_spr && put_line(fd, "set nosplitright") == FAIL) {
if (!p_spr && put_line(fd, "set nosplitright") == FAIL)
return FAIL; return FAIL;
}
/* //
* Check if window sizes can be restored (no windows omitted). // Check if window sizes can be restored (no windows omitted).
* Remember the window number of the current window after restoring. // Remember the window number of the current window after restoring.
*/ //
nr = 0; nr = 0;
for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) { for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) {
if (ses_do_win(wp)) if (ses_do_win(wp))
@@ -9303,9 +9297,8 @@ static int makeopens(FILE *fd, char_u *dirnow)
cnr = nr; cnr = nr;
} }
/* Go to the first window. */ // Go to the first window.
if (put_line(fd, "wincmd t") == FAIL) PUTLINE_FAIL("wincmd t");
return FAIL;
// If more than one window, see if sizes can be restored. // If more than one window, see if sizes can be restored.
// First set 'winheight' and 'winwidth' to 1 to avoid the windows being // First set 'winheight' and 'winwidth' to 1 to avoid the windows being
@@ -9314,10 +9307,11 @@ static int makeopens(FILE *fd, char_u *dirnow)
// cursor can be set. This is done again below. // cursor can be set. This is done again below.
// winminheight and winminwidth need to be set to avoid an error if the // winminheight and winminwidth need to be set to avoid an error if the
// user has set winheight or winwidth. // user has set winheight or winwidth.
if (put_line(fd, "set winminheight=0") == FAIL if (fprintf(fd,
|| put_line(fd, "set winheight=1") == FAIL "set winminheight=0\n"
|| put_line(fd, "set winminwidth=0") == FAIL "set winheight=1\n"
|| put_line(fd, "set winwidth=1") == FAIL) { "set winminwidth=0\n"
"set winwidth=1\n") < 0) {
return FAIL; return FAIL;
} }
if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL) { if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL) {
@@ -9328,34 +9322,39 @@ static int makeopens(FILE *fd, char_u *dirnow)
// Restore the view of the window (options, file, cursor, etc.). // Restore the view of the window (options, file, cursor, etc.).
// //
for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) { for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) {
if (!ses_do_win(wp)) if (!ses_do_win(wp)) {
continue; continue;
if (put_view(fd, wp, wp != edited_win, &ssop_flags, }
cur_arg_idx) == FAIL) if (put_view(fd, wp, wp != edited_win, &ssop_flags, cur_arg_idx)
== FAIL) {
return FAIL; return FAIL;
if (nr > 1 && put_line(fd, "wincmd w") == FAIL) }
if (nr > 1 && put_line(fd, "wincmd w") == FAIL) {
return FAIL; return FAIL;
}
next_arg_idx = wp->w_arg_idx; next_arg_idx = wp->w_arg_idx;
} }
/* The argument index in the first tab page is zero, need to set it in // The argument index in the first tab page is zero, need to set it in
* each window. For further tab pages it's the window where we do // each window. For further tab pages it's the window where we do
* "tabedit". */ // "tabedit".
cur_arg_idx = next_arg_idx; cur_arg_idx = next_arg_idx;
/* //
* Restore cursor to the current window if it's not the first one. // Restore cursor to the current window if it's not the first one.
*/ //
if (cnr > 1 && (fprintf(fd, "%dwincmd w", cnr) < 0 if (cnr > 1 && (fprintf(fd, "%dwincmd w", cnr) < 0
|| put_eol(fd) == FAIL)) || put_eol(fd) == FAIL)) {
return FAIL; return FAIL;
}
/* //
* Restore window sizes again after jumping around in windows, because // Restore window sizes again after jumping around in windows, because
* the current window has a minimum size while others may not. // the current window has a minimum size while others may not.
*/ //
if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL) if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL) {
return FAIL; return FAIL;
}
// Take care of tab-local working directories if applicable // Take care of tab-local working directories if applicable
if (tp->tp_localdir) { if (tp->tp_localdir) {
@@ -9368,34 +9367,33 @@ static int makeopens(FILE *fd, char_u *dirnow)
did_lcd = true; did_lcd = true;
} }
/* Don't continue in another tab page when doing only the current one // Don't continue in another tab page when doing only the current one
* or when at the last tab page. */ // or when at the last tab page.
if (!(ssop_flags & SSOP_TABPAGES)) if (!(ssop_flags & SSOP_TABPAGES)) {
break; break;
} }
}
if (ssop_flags & SSOP_TABPAGES) { if (ssop_flags & SSOP_TABPAGES) {
if (fprintf(fd, "tabnext %d", tabpage_index(curtab)) < 0 if (fprintf(fd, "tabnext %d\n", tabpage_index(curtab)) < 0) {
|| put_eol(fd) == FAIL)
return FAIL; return FAIL;
} }
}
if (restore_stal && put_line(fd, "set stal=1") == FAIL) { if (restore_stal && put_line(fd, "set stal=1") == FAIL) {
return FAIL; return FAIL;
} }
/* //
* Wipe out an empty unnamed buffer we started in. // Wipe out an empty unnamed buffer we started in.
*/ //
if (put_line(fd, "if exists('s:wipebuf') " if (fprintf(fd, "%s",
"&& getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'") "if exists('s:wipebuf') "
== FAIL) "&& getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'\n"
return FAIL; " silent exe 'bwipe ' . s:wipebuf\n"
if (put_line(fd, " silent exe 'bwipe ' . s:wipebuf") == FAIL) "endif\n"
return FAIL; "unlet! s:wipebuf\n") < 0) {
if (put_line(fd, "endif") == FAIL)
return FAIL;
if (put_line(fd, "unlet! s:wipebuf") == FAIL)
return FAIL; return FAIL;
}
// Re-apply options. // Re-apply options.
if (fprintf(fd, "set winheight=%" PRId64 " winwidth=%" PRId64 if (fprintf(fd, "set winheight=%" PRId64 " winwidth=%" PRId64
@@ -9410,14 +9408,16 @@ static int makeopens(FILE *fd, char_u *dirnow)
return FAIL; return FAIL;
} }
/* //
* Lastly, execute the x.vim file if it exists. // Lastly, execute the x.vim file if it exists.
*/ //
if (put_line(fd, "let s:sx = expand(\"<sfile>:p:r\").\"x.vim\"") == FAIL if (fprintf(fd, "%s",
|| put_line(fd, "if file_readable(s:sx)") == FAIL "let s:sx = expand(\"<sfile>:p:r\").\"x.vim\"\n"
|| put_line(fd, " exe \"source \" . fnameescape(s:sx)") == FAIL "if file_readable(s:sx)\n"
|| put_line(fd, "endif") == FAIL) " exe \"source \" . fnameescape(s:sx)\n"
"endif\n") < 0) {
return FAIL; return FAIL;
}
return OK; return OK;
} }
@@ -9457,53 +9457,50 @@ static int ses_winsizes(FILE *fd, int restore_size, win_T *tab_firstwin)
} }
} }
} else { } else {
// Just equalise window sizes // Just equalize window sizes.
if (put_line(fd, "wincmd =") == FAIL) { PUTLINE_FAIL("wincmd =");
return FAIL;
}
} }
return OK; return OK;
} }
/* // Write commands to "fd" to recursively create windows for frame "fr",
* Write commands to "fd" to recursively create windows for frame "fr", // horizontally and vertically split.
* horizontally and vertically split. // After the commands the last window in the frame is the current window.
* After the commands the last window in the frame is the current window. // Returns FAIL when writing the commands to "fd" fails.
* Returns FAIL when writing the commands to "fd" fails.
*/
static int ses_win_rec(FILE *fd, frame_T *fr) static int ses_win_rec(FILE *fd, frame_T *fr)
{ {
frame_T *frc; frame_T *frc;
int count = 0; int count = 0;
if (fr->fr_layout != FR_LEAF) { if (fr->fr_layout != FR_LEAF) {
/* Find first frame that's not skipped and then create a window for // Find first frame that's not skipped and then create a window for
* each following one (first frame is already there). */ // each following one (first frame is already there).
frc = ses_skipframe(fr->fr_child); frc = ses_skipframe(fr->fr_child);
if (frc != NULL) if (frc != NULL)
while ((frc = ses_skipframe(frc->fr_next)) != NULL) { while ((frc = ses_skipframe(frc->fr_next)) != NULL) {
/* Make window as big as possible so that we have lots of room // Make window as big as possible so that we have lots of room
* to split. */ // to split.
if (put_line(fd, "wincmd _ | wincmd |") == FAIL if (fprintf(fd, "%s%s",
|| put_line(fd, fr->fr_layout == FR_COL "wincmd _ | wincmd |\n",
? "split" : "vsplit") == FAIL) (fr->fr_layout == FR_COL ? "split\n" : "vsplit\n")
) < 0) {
return FAIL; return FAIL;
}
++count; ++count;
} }
/* Go back to the first window. */ // Go back to the first window.
if (count > 0 && (fprintf(fd, fr->fr_layout == FR_COL if (count > 0 && (fprintf(fd, fr->fr_layout == FR_COL
? "%dwincmd k" : "%dwincmd h", count) < 0 ? "%dwincmd k" : "%dwincmd h", count) < 0
|| put_eol(fd) == FAIL)) || put_eol(fd) == FAIL))
return FAIL; return FAIL;
/* Recursively create frames/windows in each window of this column or // Recursively create frames/windows in each window of this column or row.
* row. */
frc = ses_skipframe(fr->fr_child); frc = ses_skipframe(fr->fr_child);
while (frc != NULL) { while (frc != NULL) {
ses_win_rec(fd, frc); ses_win_rec(fd, frc);
frc = ses_skipframe(frc->fr_next); frc = ses_skipframe(frc->fr_next);
/* Go to next window. */ // Go to next window.
if (frc != NULL && put_line(fd, "wincmd w") == FAIL) if (frc != NULL && put_line(fd, "wincmd w") == FAIL)
return FAIL; return FAIL;
} }
@@ -9511,10 +9508,8 @@ static int ses_win_rec(FILE *fd, frame_T *fr)
return OK; return OK;
} }
/* // Skip frames that don't contain windows we want to save in the Session.
* Skip frames that don't contain windows we want to save in the Session. // Returns NULL when there none.
* Returns NULL when there none.
*/
static frame_T *ses_skipframe(frame_T *fr) static frame_T *ses_skipframe(frame_T *fr)
{ {
frame_T *frc; frame_T *frc;
@@ -9598,15 +9593,15 @@ put_view(
* Local argument list. * Local argument list.
*/ */
if (wp->w_alist == &global_alist) { if (wp->w_alist == &global_alist) {
if (put_line(fd, "argglobal") == FAIL) PUTLINE_FAIL("argglobal");
return FAIL;
} else { } else {
if (ses_arglist(fd, "arglocal", &wp->w_alist->al_ga, if (ses_arglist(fd, "arglocal", &wp->w_alist->al_ga,
flagp == &vop_flags flagp == &vop_flags
|| !(*flagp & SSOP_CURDIR) || !(*flagp & SSOP_CURDIR)
|| wp->w_localdir != NULL, flagp) == FAIL) || wp->w_localdir != NULL, flagp) == FAIL) {
return FAIL; return FAIL;
} }
}
/* Only when part of a session: restore the argument index. Some /* Only when part of a session: restore the argument index. Some
* arguments may have been deleted, check if the index is valid. */ * arguments may have been deleted, check if the index is valid. */
@@ -9658,9 +9653,7 @@ put_view(
xfree(fname_esc); xfree(fname_esc);
} else { } else {
// No file in this buffer, just make it empty. // No file in this buffer, just make it empty.
if (put_line(fd, "enew") == FAIL) { PUTLINE_FAIL("enew");
return FAIL;
}
if (wp->w_buffer->b_ffname != NULL) { if (wp->w_buffer->b_ffname != NULL) {
// The buffer does have a name, but it's not a file name. // The buffer does have a name, but it's not a file name.
if (fputs("file ", fd) < 0 if (fputs("file ", fd) < 0
@@ -9717,41 +9710,41 @@ put_view(
*/ */
if (do_cursor) { if (do_cursor) {
/* Restore the cursor line in the file and relatively in the // Restore the cursor line in the file and relatively in the
* window. Don't use "G", it changes the jumplist. */ // window. Don't use "G", it changes the jumplist.
if (fprintf(fd, if (fprintf(fd,
"let s:l = %" PRId64 " - ((%" PRId64 "let s:l = %" PRId64 " - ((%" PRId64
" * winheight(0) + %" PRId64 ") / %" PRId64 ")", " * winheight(0) + %" PRId64 ") / %" PRId64 ")\n"
"if s:l < 1 | let s:l = 1 | endif\n"
"exe s:l\n"
"normal! zt\n"
"%" PRId64 "\n"
,
(int64_t)wp->w_cursor.lnum, (int64_t)wp->w_cursor.lnum,
(int64_t)(wp->w_cursor.lnum - wp->w_topline), (int64_t)(wp->w_cursor.lnum - wp->w_topline),
(int64_t)(wp->w_height_inner / 2), (int64_t)(wp->w_height_inner / 2),
(int64_t)wp->w_height_inner) < 0 (int64_t)wp->w_height_inner,
|| put_eol(fd) == FAIL (int64_t)wp->w_cursor.lnum
|| put_line(fd, "if s:l < 1 | let s:l = 1 | endif") == FAIL ) < 0) {
|| put_line(fd, "exe s:l") == FAIL
|| put_line(fd, "normal! zt") == FAIL
|| fprintf(fd, "%" PRId64, (int64_t)wp->w_cursor.lnum) < 0
|| put_eol(fd) == FAIL)
return FAIL; return FAIL;
/* Restore the cursor column and left offset when not wrapping. */ }
// Restore the cursor column and left offset when not wrapping.
if (wp->w_cursor.col == 0) { if (wp->w_cursor.col == 0) {
if (put_line(fd, "normal! 0") == FAIL) PUTLINE_FAIL("normal! 0");
return FAIL;
} else { } else {
if (!wp->w_p_wrap && wp->w_leftcol > 0 && wp->w_width > 0) { if (!wp->w_p_wrap && wp->w_leftcol > 0 && wp->w_width > 0) {
if (fprintf(fd, if (fprintf(fd,
"let s:c = %" PRId64 " - ((%" PRId64 "let s:c = %" PRId64 " - ((%" PRId64
" * winwidth(0) + %" PRId64 ") / %" PRId64 ")", " * winwidth(0) + %" PRId64 ") / %" PRId64 ")\n"
"if s:c > 0\n"
" exe 'normal! ' . s:c . '|zs' . %" PRId64 " . '|'\n"
"else\n"
,
(int64_t)wp->w_virtcol + 1, (int64_t)wp->w_virtcol + 1,
(int64_t)(wp->w_virtcol - wp->w_leftcol), (int64_t)(wp->w_virtcol - wp->w_leftcol),
(int64_t)(wp->w_width / 2), (int64_t)(wp->w_width / 2),
(int64_t)wp->w_width) < 0 (int64_t)wp->w_width,
|| put_eol(fd) == FAIL
|| put_line(fd, "if s:c > 0") == FAIL
|| fprintf(fd, " exe 'normal! ' . s:c . '|zs' . %" PRId64 " . '|'",
(int64_t)wp->w_virtcol + 1) < 0 (int64_t)wp->w_virtcol + 1) < 0
|| put_eol(fd) == FAIL
|| put_line(fd, "else") == FAIL
|| put_view_curpos(fd, wp, " ") == FAIL || put_view_curpos(fd, wp, " ") == FAIL
|| put_line(fd, "endif") == FAIL) { || put_line(fd, "endif") == FAIL) {
return FAIL; return FAIL;
@@ -9779,18 +9772,17 @@ put_view(
return OK; return OK;
} }
/* /// Writes an :argument list to the session file.
* Write an argument list to the session file. ///
* Returns FAIL if writing fails. /// @param fd
*/ /// @param cmd
static int /// @param gap
ses_arglist( /// @param fullname true: use full path name
FILE *fd, /// @param flagp
char *cmd, ///
garray_T *gap, /// @returns FAIL if writing fails.
int fullname, /* TRUE: use full path name */ static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname,
unsigned *flagp unsigned *flagp)
)
{ {
char_u *buf = NULL; char_u *buf = NULL;
char_u *s; char_u *s;
@@ -9798,9 +9790,7 @@ ses_arglist(
if (fputs(cmd, fd) < 0 || put_eol(fd) == FAIL) { if (fputs(cmd, fd) < 0 || put_eol(fd) == FAIL) {
return FAIL; return FAIL;
} }
if (put_line(fd, "%argdel") == FAIL) { PUTLINE_FAIL("%argdel");
return FAIL;
}
for (int i = 0; i < gap->ga_len; ++i) { for (int i = 0; i < gap->ga_len; ++i) {
/* NULL file names are skipped (only happens when out of memory). */ /* NULL file names are skipped (only happens when out of memory). */
s = alist_name(&((aentry_T *)gap->ga_data)[i]); s = alist_name(&((aentry_T *)gap->ga_data)[i]);
@@ -9838,6 +9828,7 @@ static char *ses_get_fname(buf_T *buf, unsigned *flagp, bool add_eol)
} }
return (char *)buf->b_ffname; return (char *)buf->b_ffname;
} }
/// Write a buffer name to the session file. /// Write a buffer name to the session file.
/// Also ends the line, if "add_eol" is true. /// Also ends the line, if "add_eol" is true.
/// Returns FAIL if writing fails. /// Returns FAIL if writing fails.
@@ -9960,14 +9951,12 @@ int put_eol(FILE *fd)
return OK; return OK;
} }
/* // TODO(justinmk): remove this, not needed after 823750fef315.
* Write a line to "fd".
* Return FAIL for a write error.
*/
int put_line(FILE *fd, char *s) int put_line(FILE *fd, char *s)
{ {
if (fputs(s, fd) < 0 || put_eol(fd) == FAIL) if (0 > fprintf(fd, "%s\n", s)) {
return FAIL; return FAIL;
}
return OK; return OK;
} }

View File

@@ -578,7 +578,7 @@ static char *(p_ssop_values[]) = {
# define SSOP_BLANK 0x080 # define SSOP_BLANK 0x080
# define SSOP_GLOBALS 0x100 # define SSOP_GLOBALS 0x100
# define SSOP_SLASH 0x200 # define SSOP_SLASH 0x200
# define SSOP_UNIX 0x400 # define SSOP_UNIX 0x400 /* Deprecated, not used. */
# define SSOP_SESDIR 0x800 # define SSOP_SESDIR 0x800
# define SSOP_CURDIR 0x1000 # define SSOP_CURDIR 0x1000
# define SSOP_FOLDS 0x2000 # define SSOP_FOLDS 0x2000