aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_session.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/ex_session.c')
-rw-r--r--src/nvim/ex_session.c107
1 files changed, 53 insertions, 54 deletions
diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c
index 67b8e7e92f..4aadd77d45 100644
--- a/src/nvim/ex_session.c
+++ b/src/nvim/ex_session.c
@@ -8,13 +8,11 @@
// :mksession
#include <assert.h>
-#include <string.h>
+#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
-#include <inttypes.h>
+#include <string.h>
-#include "nvim/vim.h"
-#include "nvim/globals.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/cursor.h"
@@ -28,6 +26,7 @@
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
+#include "nvim/globals.h"
#include "nvim/keymap.h"
#include "nvim/misc1.h"
#include "nvim/move.h"
@@ -36,6 +35,7 @@
#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/path.h"
+#include "nvim/vim.h"
#include "nvim/window.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -63,7 +63,7 @@ static int put_view_curpos(FILE *fd, const win_T *wp, char *spaces)
static int ses_winsizes(FILE *fd, int restore_size, win_T *tab_firstwin)
{
int n = 0;
- win_T *wp;
+ win_T *wp;
if (restore_size && (ssop_flags & SSOP_WINSIZE)) {
for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) {
@@ -105,7 +105,7 @@ static int ses_winsizes(FILE *fd, int restore_size, win_T *tab_firstwin)
// Returns FAIL when writing the commands to "fd" fails.
static int ses_win_rec(FILE *fd, frame_T *fr)
{
- frame_T *frc;
+ frame_T *frc;
int count = 0;
if (fr->fr_layout != FR_LEAF) {
@@ -149,7 +149,7 @@ static int ses_win_rec(FILE *fd, frame_T *fr)
// Returns NULL when there none.
static frame_T *ses_skipframe(frame_T *fr)
{
- frame_T *frc;
+ frame_T *frc;
FOR_ALL_FRAMES(frc, fr) {
if (ses_do_frame(frc)) {
@@ -200,11 +200,10 @@ static int ses_do_win(win_T *wp)
/// @param flagp
///
/// @returns FAIL if writing fails.
-static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname,
- unsigned *flagp)
+static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, unsigned *flagp)
{
- char_u *buf = NULL;
- char_u *s;
+ char_u *buf = NULL;
+ char_u *s;
if (fprintf(fd, "%s\n%s\n", cmd, "%argdel") < 0) {
return FAIL;
@@ -297,17 +296,15 @@ static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp)
return retval;
}
-// Write commands to "fd" to restore the view of a window.
-// Caller must make sure 'scrolloff' is zero.
-static int put_view(
- FILE *fd,
- win_T *wp,
- int add_edit, // add ":edit" command to view
- unsigned *flagp, // vop_flags or ssop_flags
- int current_arg_idx // current argument index of the window, use
-) // -1 if unknown
+/// Write commands to "fd" to restore the view of a window.
+/// Caller must make sure 'scrolloff' is zero.
+///
+/// @param add_edit add ":edit" command to view
+/// @param flagp vop_flags or ssop_flags
+/// @param current_arg_idx current argument index of the window, use -1 if unknown
+static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int current_arg_idx)
{
- win_T *save_curwin;
+ win_T *save_curwin;
int f;
int do_cursor;
int did_next = false;
@@ -348,8 +345,8 @@ static int put_view(
// Load the file.
//
if (wp->w_buffer->b_ffname != NULL
- && (!bt_nofile(wp->w_buffer) || wp->w_buffer->terminal)
- ) {
+ && (!bt_nofile(wp->w_buffer) ||
+ wp->w_buffer->terminal)) {
// Editing a file in this buffer: use ":edit file".
// This may have side effects! (e.g., compressed or network file).
//
@@ -434,8 +431,8 @@ static int put_view(
//
if ((*flagp & SSOP_FOLDS)
&& wp->w_buffer->b_ffname != NULL
- && (bt_normal(wp->w_buffer) || bt_help(wp->w_buffer))
- ) {
+ && (bt_normal(wp->w_buffer) ||
+ bt_help(wp->w_buffer))) {
if (put_folds(fd, wp) == FAIL) {
return FAIL;
}
@@ -453,11 +450,11 @@ static int put_view(
}
} else if (fprintf(fd,
"let s:l = %" PRIdLINENR " - ((%" PRIdLINENR
- " * winheight(0) + %" PRId64 ") / %" PRId64 ")\n",
+ " * winheight(0) + %d) / %d)\n",
wp->w_cursor.lnum,
wp->w_cursor.lnum - wp->w_topline,
- (int64_t)(wp->w_height_inner / 2),
- (int64_t)wp->w_height_inner) < 0) {
+ (wp->w_height_inner / 2),
+ wp->w_height_inner) < 0) {
return FAIL;
}
if (fprintf(fd,
@@ -525,12 +522,12 @@ static int makeopens(FILE *fd, char_u *dirnow)
int only_save_windows = true;
int nr;
int restore_size = true;
- win_T *wp;
- char_u *sname;
- win_T *edited_win = NULL;
+ win_T *wp;
+ char_u *sname;
+ win_T *edited_win = NULL;
int tabnr;
- win_T *tab_firstwin;
- frame_T *tab_topframe;
+ win_T *tab_firstwin;
+ frame_T *tab_topframe;
int cur_arg_idx = 0;
int next_arg_idx = 0;
@@ -583,22 +580,6 @@ static int makeopens(FILE *fd, char_u *dirnow)
return FAIL;
}
- // Now put the other buffers into the buffer list.
- FOR_ALL_BUFFERS(buf) {
- if (!(only_save_windows && buf->b_nwindows == 0)
- && !(buf->b_help && !(ssop_flags & SSOP_HELP))
- && buf->b_fname != NULL
- && buf->b_p_bl) {
- if (fprintf(fd, "badd +%" PRId64 " ",
- buf->b_wininfo == NULL
- ? (int64_t)1L
- : (int64_t)buf->b_wininfo->wi_fpos.lnum) < 0
- || ses_fname(fd, buf, &ssop_flags, true) == FAIL) {
- return FAIL;
- }
- }
- }
-
// the global argument list
if (ses_arglist(fd, "argglobal", &global_alist.al_ga,
!(ssop_flags & SSOP_CURDIR), &ssop_flags) == FAIL) {
@@ -674,8 +655,7 @@ static int makeopens(FILE *fd, char_u *dirnow)
if (ses_do_win(wp)
&& wp->w_buffer->b_ffname != NULL
&& !bt_help(wp->w_buffer)
- && !bt_nofile(wp->w_buffer)
- ) {
+ && !bt_nofile(wp->w_buffer)) {
if (need_tabnext && put_line(fd, "tabnext") == FAIL) {
return FAIL;
}
@@ -813,12 +793,31 @@ static int makeopens(FILE *fd, char_u *dirnow)
return FAIL;
}
+ // Now put the remaining buffers into the buffer list.
+ // This is near the end, so that when 'hidden' is set we don't create extra
+ // buffers. If the buffer was already created with another command the
+ // ":badd" will have no effect.
+ FOR_ALL_BUFFERS(buf) {
+ if (!(only_save_windows && buf->b_nwindows == 0)
+ && !(buf->b_help && !(ssop_flags & SSOP_HELP))
+ && buf->b_fname != NULL
+ && buf->b_p_bl) {
+ if (fprintf(fd, "badd +%" PRId64 " ",
+ buf->b_wininfo == NULL
+ ? (int64_t)1L
+ : (int64_t)buf->b_wininfo->wi_fpos.lnum) < 0
+ || ses_fname(fd, buf, &ssop_flags, true) == FAIL) {
+ return FAIL;
+ }
+ }
+ }
+
//
// Wipe out an empty unnamed buffer we started in.
//
if (fprintf(fd, "%s",
"if exists('s:wipebuf') "
- "&& len(win_findbuf(s:wipebuf)) == 0"
+ "&& len(win_findbuf(s:wipebuf)) == 0 "
"&& getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'\n"
" silent exe 'bwipe ' . s:wipebuf\n"
"endif\n"
@@ -874,12 +873,12 @@ void ex_loadview(exarg_T *eap)
/// - SSOP_SLASH: filenames are written with "/" slash
void ex_mkrc(exarg_T *eap)
{
- FILE *fd;
+ FILE *fd;
int failed = false;
int view_session = false; // :mkview, :mksession
int using_vdir = false; // using 'viewdir'?
char *viewFile = NULL;
- unsigned *flagp;
+ unsigned *flagp;
if (eap->cmdidx == CMD_mksession || eap->cmdidx == CMD_mkview) {
view_session = true;