diff options
-rw-r--r-- | Filelist | 2 | ||||
-rw-r--r-- | src/Make_cyg_ming.mak | 1 | ||||
-rw-r--r-- | src/Make_morph.mak | 1 | ||||
-rw-r--r-- | src/Make_mvc.mak | 4 | ||||
-rw-r--r-- | src/Make_vms.mms | 20 | ||||
-rw-r--r-- | src/Makefile | 28 | ||||
-rw-r--r-- | src/README.md | 1 | ||||
-rw-r--r-- | src/eval.c | 87 | ||||
-rw-r--r-- | src/ex_docmd.c | 1240 | ||||
-rw-r--r-- | src/misc2.c | 77 | ||||
-rw-r--r-- | src/proto.h | 3 | ||||
-rw-r--r-- | src/proto/eval.pro | 2 | ||||
-rw-r--r-- | src/proto/misc2.pro | 1 | ||||
-rw-r--r-- | src/proto/session.pro | 8 | ||||
-rw-r--r-- | src/session.c | 1346 | ||||
-rw-r--r-- | src/version.c | 2 |
16 files changed, 1401 insertions, 1422 deletions
@@ -88,6 +88,7 @@ SRC_ALL = \ src/regexp.h \ src/screen.c \ src/search.c \ + src/session.c \ src/sha256.c \ src/sign.c \ src/sound.c \ @@ -218,6 +219,7 @@ SRC_ALL = \ src/proto/regexp.pro \ src/proto/screen.pro \ src/proto/search.pro \ + src/proto/session.pro \ src/proto/sha256.pro \ src/proto/sign.pro \ src/proto/sound.pro \ diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak index 4ceaa91177..17847cc39e 100644 --- a/src/Make_cyg_ming.mak +++ b/src/Make_cyg_ming.mak @@ -758,6 +758,7 @@ OBJ = \ $(OUTDIR)/regexp.o \ $(OUTDIR)/screen.o \ $(OUTDIR)/search.o \ + $(OUTDIR)/session.o \ $(OUTDIR)/sha256.o \ $(OUTDIR)/sign.o \ $(OUTDIR)/spell.o \ diff --git a/src/Make_morph.mak b/src/Make_morph.mak index 8d93d7efec..f292934dd1 100644 --- a/src/Make_morph.mak +++ b/src/Make_morph.mak @@ -75,6 +75,7 @@ SRC = arabic.c \ regexp.c \ screen.c \ search.c \ + session.c \ sha256.c \ sign.c \ spell.c \ diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak index 10fcb74040..04cdd0841c 100644 --- a/src/Make_mvc.mak +++ b/src/Make_mvc.mak @@ -767,6 +767,7 @@ OBJ = \ $(OUTDIR)\regexp.obj \ $(OUTDIR)\screen.obj \ $(OUTDIR)\search.obj \ + $(OUTDIR)\session.obj \ $(OUTDIR)\sha256.obj \ $(OUTDIR)\sign.obj \ $(OUTDIR)\spell.obj \ @@ -1618,6 +1619,8 @@ $(OUTDIR)/screen.obj: $(OUTDIR) screen.c $(INCL) $(OUTDIR)/search.obj: $(OUTDIR) search.c $(INCL) +$(OUTDIR)/session.obj: $(OUTDIR) session.c $(INCL) + $(OUTDIR)/sha256.obj: $(OUTDIR) sha256.c $(INCL) $(OUTDIR)/sign.obj: $(OUTDIR) sign.c $(INCL) @@ -1788,6 +1791,7 @@ proto.h: \ proto/regexp.pro \ proto/screen.pro \ proto/search.pro \ + proto/session.pro \ proto/sha256.pro \ proto/sign.pro \ proto/spell.pro \ diff --git a/src/Make_vms.mms b/src/Make_vms.mms index 73f4998b9a..2fd98b8a85 100644 --- a/src/Make_vms.mms +++ b/src/Make_vms.mms @@ -314,10 +314,10 @@ SRC = arabic.c autocmd.c beval.c blob.c blowfish.c buffer.c change.c charset.c \ hardcopy.c hashtab.c highlight.c indent.c insexpand.c json.c list.c \ main.c mark.c menu.c mbyte.c memfile.c memline.c message.c misc1.c \ misc2.c move.c normal.c ops.c option.c popupmnu.c popupwin.c \ - profiler.c quickfix.c regexp.c search.c sha256.c sign.c spell.c \ - spellfile.c syntax.c tag.c term.c termlib.c testing.c textprop.c ui.c \ - undo.c usercmd.c userfunc.c version.c viminfo.c screen.c window.c \ - os_unix.c os_vms.c pathdef.c \ + profiler.c quickfix.c regexp.c search.c session.c sha256.c sign.c \ + spell.c spellfile.c syntax.c tag.c term.c termlib.c testing.c \ + textprop.c ui.c undo.c usercmd.c userfunc.c version.c viminfo.c \ + screen.c window.c os_unix.c os_vms.c pathdef.c \ $(GUI_SRC) $(PERL_SRC) $(PYTHON_SRC) $(TCL_SRC) \ $(RUBY_SRC) $(HANGULIN_SRC) $(MZSCH_SRC) $(XDIFF_SRC) @@ -330,10 +330,10 @@ OBJ = arabic.obj autocmd.obj beval.obj blob.obj blowfish.obj buffer.obj change. mark.obj menu.obj memfile.obj memline.obj message.obj misc1.obj \ misc2.obj move.obj mbyte.obj normal.obj ops.obj option.obj \ popupmnu.obj popupwin.obj profiler.obj quickfix.obj regexp.obj \ - search.obj sha256.obj sign.obj spell.obj spellfile.obj syntax.obj \ - tag.obj term.obj termlib.obj testing.obj textprop.obj ui.obj undo.obj \ - usercmd.obj userfunc.obj screen.obj version.obj viminfo.obj window.obj \ - os_unix.obj os_vms.obj pathdef.obj if_mzsch.obj \ + search.obj session.obj sha256.obj sign.obj spell.obj spellfile.obj \ + syntax.obj tag.obj term.obj termlib.obj testing.obj textprop.obj \ + ui.obj undo.obj usercmd.obj userfunc.obj screen.obj version.obj \ + viminfo.obj window.obj os_unix.obj os_vms.obj pathdef.obj if_mzsch.obj \ $(GUI_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(TCL_OBJ) \ $(RUBY_OBJ) $(HANGULIN_OBJ) $(MZSCH_OBJ) $(XDIFF_OBJ) @@ -718,6 +718,10 @@ search.obj : search.c vim.h [.auto]config.h feature.h os_unix.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ globals.h +session.obj : session.c vim.h [.auto]config.h feature.h os_unix.h \ + ascii.h keymap.h term.h macros.h structs.h regexp.h \ + gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ + globals.h sha256.obj : sha256.c vim.h [.auto]config.h feature.h os_unix.h \ ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \ beval.h [.proto]gui_beval.pro alloc.h ex_cmds.h spell.h proto.h \ diff --git a/src/Makefile b/src/Makefile index c6c528d63c..ce2ba2fdc5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -405,7 +405,7 @@ CClink = $(CC) # Set PATH environment variable to find lua or luajit executable. # This requires at least "normal" features, "tiny" and "small" don't work. #CONF_OPT_LUA = --enable-luainterp -#CONF_OPT_LUA = --enable-luainterp=dynamic +CONF_OPT_LUA = --enable-luainterp=dynamic #CONF_OPT_LUA = --enable-luainterp --with-luajit #CONF_OPT_LUA = --enable-luainterp=dynamic --with-luajit # Lua installation dir (when not set uses $LUA_PREFIX or defaults to /usr) @@ -431,7 +431,7 @@ CClink = $(CC) # When you get an error for a missing "perl.exp" file, try creating an empty # one: "touch perl.exp". # This requires at least "normal" features, "tiny" and "small" don't work. -#CONF_OPT_PERL = --enable-perlinterp +CONF_OPT_PERL = --enable-perlinterp #CONF_OPT_PERL = --enable-perlinterp=dynamic # PYTHON @@ -445,10 +445,10 @@ CClink = $(CC) # dlopen(), dlsym(), dlclose(), i.e. pythonX.Y.so must be available # However, this may still cause problems, such as "import termios" failing. # Build two separate versions of Vim in that case. -#CONF_OPT_PYTHON = --enable-pythoninterp +CONF_OPT_PYTHON = --enable-pythoninterp #CONF_OPT_PYTHON = --enable-pythoninterp --with-python-command=python2.7 #CONF_OPT_PYTHON = --enable-pythoninterp=dynamic -#CONF_OPT_PYTHON3 = --enable-python3interp +CONF_OPT_PYTHON3 = --enable-python3interp #CONF_OPT_PYTHON3 = --enable-python3interp --with-python3-command=python3.6 #CONF_OPT_PYTHON3 = --enable-python3interp=dynamic @@ -458,14 +458,14 @@ CClink = $(CC) # Note: you need the development package (e.g., ruby1.9.1-dev on Ubuntu). # This requires at least "normal" features, "tiny" and "small" don't work. #CONF_OPT_RUBY = --enable-rubyinterp -#CONF_OPT_RUBY = --enable-rubyinterp=dynamic +CONF_OPT_RUBY = --enable-rubyinterp=dynamic #CONF_OPT_RUBY = --enable-rubyinterp --with-ruby-command=ruby1.9.1 # TCL # Uncomment this when you want to include the Tcl interface. # First one is for static linking, second one for dynamic loading. #CONF_OPT_TCL = --enable-tclinterp -#CONF_OPT_TCL = --enable-tclinterp=dynamic +CONF_OPT_TCL = --enable-tclinterp=dynamic #CONF_OPT_TCL = --enable-tclinterp --with-tclsh=tclsh8.4 # CSCOPE @@ -541,7 +541,7 @@ CClink = $(CC) #CONF_OPT_FEAT = --with-features=small #CONF_OPT_FEAT = --with-features=normal #CONF_OPT_FEAT = --with-features=big -#CONF_OPT_FEAT = --with-features=huge +CONF_OPT_FEAT = --with-features=huge # COMPILED BY - For including a specific e-mail address for ":version". #CONF_OPT_COMPBY = "--with-compiledby=John Doe <JohnDoe@yahoo.com>" @@ -615,7 +615,7 @@ CClink = $(CC) # Use this with GCC to check for mistakes, unused arguments, etc. # Note: If you use -Wextra and get warnings in GTK code about function # parameters, you can add -Wno-cast-function-type -#CFLAGS = -g -Wall -Wextra -Wshadow -Wmissing-prototypes -Wunreachable-code -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 +CFLAGS = -g -Wall -Wextra -Wshadow -Wmissing-prototypes -Wunreachable-code -Wno-cast-function-type -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 # Add -Wpedantic to find // comments and other C99 constructs. # Better disable Perl and Python to avoid a lot of warnings. #CFLAGS = -g -Wall -Wextra -Wshadow -Wmissing-prototypes -Wpedantic -Wunreachable-code -Wunused-result -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 @@ -704,7 +704,7 @@ SANITIZER_LIBS = $(SANITIZER_CFLAGS) # Configuration is in the .ccmalloc or ~/.ccmalloc file. # Doesn't work very well, since memory linked to from global variables # (in libraries) is also marked as leaked memory. -#LEAK_CFLAGS = -DEXITFREE +LEAK_CFLAGS = -DEXITFREE #LEAK_LIBS = -lccmalloc # Uncomment this line to have Vim call abort() when an internal error is @@ -1634,6 +1634,7 @@ BASIC_SRC = \ regexp.c \ screen.c \ search.c \ + session.c \ sha256.c \ sign.c \ sound.c \ @@ -1754,6 +1755,7 @@ OBJ_COMMON = \ objects/regexp.o \ objects/screen.o \ objects/search.o \ + objects/session.o \ objects/sha256.o \ objects/sign.o \ objects/sound.o \ @@ -1899,6 +1901,7 @@ PRO_AUTO = \ regexp.pro \ screen.pro \ search.pro \ + session.pro \ sha256.pro \ sign.pro \ sound.pro \ @@ -3256,6 +3259,9 @@ objects/screen.o: screen.c objects/search.o: search.c $(CCC) -o $@ search.c +objects/session.o: session.c + $(CCC) -o $@ session.c + objects/sha256.o: sha256.c $(CCC) -o $@ sha256.c @@ -3686,6 +3692,10 @@ objects/search.o: search.c vim.h protodef.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ proto.h globals.h +objects/session.o: session.c vim.h protodef.h auto/config.h feature.h \ + os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ + proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ + proto.h globals.h objects/sha256.o: sha256.c vim.h protodef.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ diff --git a/src/README.md b/src/README.md index 40255ab2b6..f8eb9c4c72 100644 --- a/src/README.md +++ b/src/README.md @@ -52,6 +52,7 @@ quickfix.c | quickfix commands (":make", ":cn") regexp.c | pattern matching screen.c | updating the windows search.c | pattern searching +session.c | sessions and views sign.c | signs spell.c | spell checking syntax.c | syntax and other highlighting diff --git a/src/eval.c b/src/eval.c index a2d3d97688..278f307002 100644 --- a/src/eval.c +++ b/src/eval.c @@ -9319,93 +9319,6 @@ script_autoload( return ret; } -#if defined(FEAT_VIMINFO) || defined(FEAT_SESSION) - var_flavour_T -var_flavour(char_u *varname) -{ - char_u *p = varname; - - if (ASCII_ISUPPER(*p)) - { - while (*(++p)) - if (ASCII_ISLOWER(*p)) - return VAR_FLAVOUR_SESSION; - return VAR_FLAVOUR_VIMINFO; - } - else - return VAR_FLAVOUR_DEFAULT; -} -#endif - -#if defined(FEAT_SESSION) || defined(PROTO) - int -store_session_globals(FILE *fd) -{ - hashitem_T *hi; - dictitem_T *this_var; - int todo; - char_u *p, *t; - - todo = (int)globvarht.ht_used; - for (hi = globvarht.ht_array; todo > 0; ++hi) - { - if (!HASHITEM_EMPTY(hi)) - { - --todo; - this_var = HI2DI(hi); - if ((this_var->di_tv.v_type == VAR_NUMBER - || this_var->di_tv.v_type == VAR_STRING) - && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) - { - /* Escape special characters with a backslash. Turn a LF and - * CR into \n and \r. */ - p = vim_strsave_escaped(tv_get_string(&this_var->di_tv), - (char_u *)"\\\"\n\r"); - if (p == NULL) /* out of memory */ - break; - for (t = p; *t != NUL; ++t) - if (*t == '\n') - *t = 'n'; - else if (*t == '\r') - *t = 'r'; - if ((fprintf(fd, "let %s = %c%s%c", - this_var->di_key, - (this_var->di_tv.v_type == VAR_STRING) ? '"' - : ' ', - p, - (this_var->di_tv.v_type == VAR_STRING) ? '"' - : ' ') < 0) - || put_eol(fd) == FAIL) - { - vim_free(p); - return FAIL; - } - vim_free(p); - } -#ifdef FEAT_FLOAT - else if (this_var->di_tv.v_type == VAR_FLOAT - && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) - { - float_T f = this_var->di_tv.vval.v_float; - int sign = ' '; - - if (f < 0) - { - f = -f; - sign = '-'; - } - if ((fprintf(fd, "let %s = %c%f", - this_var->di_key, sign, f) < 0) - || put_eol(fd) == FAIL) - return FAIL; - } -#endif - } - } - return OK; -} -#endif - /* * Display script name where an item was last set. * Should only be invoked when 'verbose' is non-zero. diff --git a/src/ex_docmd.c b/src/ex_docmd.c index f3a4eb7c1b..601c51bbab 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -257,7 +257,6 @@ static void ex_redir(exarg_T *eap); static void ex_redrawstatus(exarg_T *eap); static void ex_redrawtabline(exarg_T *eap); static void close_redir(void); -static void ex_mkrc(exarg_T *eap); static void ex_mark(exarg_T *eap); static void ex_startinsert(exarg_T *eap); static void ex_stopinsert(exarg_T *eap); @@ -306,14 +305,9 @@ static void ex_tag_cmd(exarg_T *eap, char_u *name); # define ex_oldfiles ex_ni #endif static char_u *arg_all(void); -#ifdef FEAT_SESSION -static int makeopens(FILE *fd, char_u *dirnow); -static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int current_arg_idx); -static void ex_loadview(exarg_T *eap); -static char_u *get_view_file(int c); -static int did_lcd; /* whether ":lcd" was produced for a session */ -#else +#ifndef FEAT_SESSION # define ex_loadview ex_ni +# define ex_mkrc ex_ni #endif #ifndef FEAT_EVAL # define ex_compiler ex_ni @@ -8439,243 +8433,6 @@ close_redir(void) #endif } -#if defined(FEAT_SESSION) && defined(USE_CRNL) -# define MKSESSION_NL -static int mksession_nl = FALSE; /* use NL only in put_eol() */ -#endif - -/* - * ":mkexrc", ":mkvimrc", ":mkview" and ":mksession". - */ - static void -ex_mkrc( - exarg_T *eap) -{ - FILE *fd; - int failed = FALSE; - char_u *fname; -#ifdef FEAT_BROWSE - char_u *browseFile = NULL; -#endif -#ifdef FEAT_SESSION - int view_session = FALSE; - int using_vdir = FALSE; /* using 'viewdir'? */ - char_u *viewFile = NULL; - unsigned *flagp; -#endif - - if (eap->cmdidx == CMD_mksession || eap->cmdidx == CMD_mkview) - { -#ifdef FEAT_SESSION - view_session = TRUE; -#else - ex_ni(eap); - return; -#endif - } - -#ifdef FEAT_SESSION - /* Use the short file name until ":lcd" is used. We also don't use the - * short file name when 'acd' is set, that is checked later. */ - did_lcd = FALSE; - - /* ":mkview" or ":mkview 9": generate file name with 'viewdir' */ - if (eap->cmdidx == CMD_mkview - && (*eap->arg == NUL - || (vim_isdigit(*eap->arg) && eap->arg[1] == NUL))) - { - eap->forceit = TRUE; - fname = get_view_file(*eap->arg); - if (fname == NULL) - return; - viewFile = fname; - using_vdir = TRUE; - } - else -#endif - if (*eap->arg != NUL) - fname = eap->arg; - else if (eap->cmdidx == CMD_mkvimrc) - fname = (char_u *)VIMRC_FILE; -#ifdef FEAT_SESSION - else if (eap->cmdidx == CMD_mksession) - fname = (char_u *)SESSION_FILE; -#endif - else - fname = (char_u *)EXRC_FILE; - -#ifdef FEAT_BROWSE - if (cmdmod.browse) - { - browseFile = do_browse(BROWSE_SAVE, -# ifdef FEAT_SESSION - eap->cmdidx == CMD_mkview ? (char_u *)_("Save View") : - eap->cmdidx == CMD_mksession ? (char_u *)_("Save Session") : -# endif - (char_u *)_("Save Setup"), - fname, (char_u *)"vim", NULL, - (char_u *)_(BROWSE_FILTER_MACROS), NULL); - if (browseFile == NULL) - goto theend; - fname = browseFile; - eap->forceit = TRUE; /* since dialog already asked */ - } -#endif - -#if defined(FEAT_SESSION) && defined(vim_mkdir) - /* When using 'viewdir' may have to create the directory. */ - if (using_vdir && !mch_isdir(p_vdir)) - vim_mkdir_emsg(p_vdir, 0755); -#endif - - fd = open_exfile(fname, eap->forceit, WRITEBIN); - if (fd != NULL) - { -#ifdef FEAT_SESSION - if (eap->cmdidx == CMD_mkview) - flagp = &vop_flags; - else - flagp = &ssop_flags; -#endif - -#ifdef MKSESSION_NL - /* "unix" in 'sessionoptions': use NL line separator */ - if (view_session && (*flagp & SSOP_UNIX)) - mksession_nl = TRUE; -#endif - - /* Write the version command for :mkvimrc */ - if (eap->cmdidx == CMD_mkvimrc) - (void)put_line(fd, "version 6.0"); - -#ifdef FEAT_SESSION - if (eap->cmdidx == CMD_mksession) - { - if (put_line(fd, "let SessionLoad = 1") == FAIL) - failed = TRUE; - } - - if (eap->cmdidx != CMD_mkview) -#endif - { - /* Write setting 'compatible' first, because it has side effects. - * For that same reason only do it when needed. */ - if (p_cp) - (void)put_line(fd, "if !&cp | set cp | endif"); - else - (void)put_line(fd, "if &cp | set nocp | endif"); - } - -#ifdef FEAT_SESSION - if (!view_session - || (eap->cmdidx == CMD_mksession - && (*flagp & SSOP_OPTIONS))) -#endif - failed |= (makemap(fd, NULL) == FAIL - || makeset(fd, OPT_GLOBAL, FALSE) == FAIL); - -#ifdef FEAT_SESSION - if (!failed && view_session) - { - if (put_line(fd, "let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0") == FAIL) - failed = TRUE; - if (eap->cmdidx == CMD_mksession) - { - char_u *dirnow; /* current directory */ - - dirnow = alloc(MAXPATHL); - if (dirnow == NULL) - failed = TRUE; - else - { - /* - * Change to session file's dir. - */ - if (mch_dirname(dirnow, MAXPATHL) == FAIL - || mch_chdir((char *)dirnow) != 0) - *dirnow = NUL; - if (*dirnow != NUL && (ssop_flags & SSOP_SESDIR)) - { - if (vim_chdirfile(fname, NULL) == OK) - shorten_fnames(TRUE); - } - else if (*dirnow != NUL - && (ssop_flags & SSOP_CURDIR) && globaldir != NULL) - { - if (mch_chdir((char *)globaldir) == 0) - shorten_fnames(TRUE); - } - - failed |= (makeopens(fd, dirnow) == FAIL); - - /* restore original dir */ - if (*dirnow != NUL && ((ssop_flags & SSOP_SESDIR) - || ((ssop_flags & SSOP_CURDIR) && globaldir != NULL))) - { - if (mch_chdir((char *)dirnow) != 0) - emsg(_(e_prev_dir)); - shorten_fnames(TRUE); - } - vim_free(dirnow); - } - } - else - { - failed |= (put_view(fd, curwin, !using_vdir, flagp, - -1) == FAIL); - } - if (put_line(fd, "let &so = s:so_save | let &siso = s:siso_save") - == FAIL) - failed = TRUE; -# ifdef FEAT_SEARCH_EXTRA - if (no_hlsearch && put_line(fd, "nohlsearch") == FAIL) - failed = TRUE; -# endif - if (put_line(fd, "doautoall SessionLoadPost") == FAIL) - failed = TRUE; - if (eap->cmdidx == CMD_mksession) - { - if (put_line(fd, "unlet SessionLoad") == FAIL) - failed = TRUE; - } - } -#endif - if (put_line(fd, "\" vim: set ft=vim :") == FAIL) - failed = TRUE; - - failed |= fclose(fd); - - if (failed) - emsg(_(e_write)); -#if defined(FEAT_EVAL) && defined(FEAT_SESSION) - else if (eap->cmdidx == CMD_mksession) - { - /* successful session write - set this_session var */ - char_u *tbuf; - - tbuf = alloc(MAXPATHL); - if (tbuf != NULL) - { - if (vim_FullName(fname, tbuf, MAXPATHL, FALSE) == OK) - set_vim_var_string(VV_THIS_SESSION, tbuf, -1); - vim_free(tbuf); - } - } -#endif -#ifdef MKSESSION_NL - mksession_nl = FALSE; -#endif - } - -#ifdef FEAT_BROWSE -theend: - vim_free(browseFile); -#endif -#ifdef FEAT_SESSION - vim_free(viewFile); -#endif -} - #if ((defined(FEAT_SESSION) || defined(FEAT_EVAL)) && defined(vim_mkdir)) \ || defined(PROTO) int @@ -9717,999 +9474,6 @@ expand_sfile(char_u *arg) return result; } -#ifdef FEAT_SESSION -static int ses_winsizes(FILE *fd, int restore_size, - win_T *tab_firstwin); -static int ses_win_rec(FILE *fd, frame_T *fr); -static frame_T *ses_skipframe(frame_T *fr); -static int ses_do_frame(frame_T *fr); -static int ses_do_win(win_T *wp); -static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, unsigned *flagp); -static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp); -static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp, int add_eol); - -/* - * Write openfile commands for the current buffers to an .exrc file. - * Return FAIL on error, OK otherwise. - */ - static int -makeopens( - FILE *fd, - char_u *dirnow) /* Current directory name */ -{ - buf_T *buf; - int only_save_windows = TRUE; - int nr; - int restore_size = TRUE; - win_T *wp; - char_u *sname; - win_T *edited_win = NULL; - int tabnr; - int restore_stal = FALSE; - win_T *tab_firstwin; - frame_T *tab_topframe; - int cur_arg_idx = 0; - int next_arg_idx = 0; - - if (ssop_flags & SSOP_BUFFERS) - only_save_windows = FALSE; /* Save ALL buffers */ - - /* - * Begin by setting the this_session variable, and then other - * sessionable variables. - */ -#ifdef FEAT_EVAL - if (put_line(fd, "let v:this_session=expand(\"<sfile>:p\")") == FAIL) - return FAIL; - if (ssop_flags & SSOP_GLOBALS) - if (store_session_globals(fd) == FAIL) - return FAIL; -#endif - - /* - * Close all windows and tabs but one. - */ - if (put_line(fd, "silent only") == FAIL) - return FAIL; - if ((ssop_flags & SSOP_TABPAGES) - && put_line(fd, "silent tabonly") == FAIL) - return FAIL; - - /* - * Now a :cd command to the session directory or the current directory - */ - if (ssop_flags & SSOP_SESDIR) - { - if (put_line(fd, "exe \"cd \" . escape(expand(\"<sfile>:p:h\"), ' ')") - == FAIL) - return FAIL; - } - else if (ssop_flags & SSOP_CURDIR) - { - sname = home_replace_save(NULL, globaldir != NULL ? globaldir : dirnow); - if (sname == NULL - || fputs("cd ", fd) < 0 - || ses_put_fname(fd, sname, &ssop_flags) == FAIL - || put_eol(fd) == FAIL) - { - vim_free(sname); - return FAIL; - } - vim_free(sname); - } - - /* - * 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 && getline(1) == ''") == FAIL) - return FAIL; - if (put_line(fd, " let s:wipebuf = bufnr('%')") == FAIL) - return FAIL; - if (put_line(fd, "endif") == FAIL) - return FAIL; - - /* - * Now save the current files, current buffer first. - */ - if (put_line(fd, "set shortmess=aoO") == FAIL) - return FAIL; - - /* the global argument list */ - if (ses_arglist(fd, "argglobal", &global_alist.al_ga, - !(ssop_flags & SSOP_CURDIR), &ssop_flags) == FAIL) - return FAIL; - - if (ssop_flags & SSOP_RESIZE) - { - /* Note: after the restore we still check it worked!*/ - if (fprintf(fd, "set lines=%ld columns=%ld" , Rows, Columns) < 0 - || put_eol(fd) == FAIL) - return FAIL; - } - -#ifdef FEAT_GUI - if (gui.in_use && (ssop_flags & SSOP_WINPOS)) - { - int x, y; - - if (gui_mch_get_winpos(&x, &y) == OK) - { - /* Note: after the restore we still check it worked!*/ - if (fprintf(fd, "winpos %d %d", x, y) < 0 || put_eol(fd) == FAIL) - return FAIL; - } - } -#endif - - /* - * When there are two or more tabpages and 'showtabline' is 1 the tabline - * will be displayed when creating the next tab. That resizes the windows - * in the first tab, which may cause problems. Set 'showtabline' to 2 - * temporarily to avoid that. - */ - if (p_stal == 1 && first_tabpage->tp_next != NULL) - { - if (put_line(fd, "set stal=2") == FAIL) - return FAIL; - restore_stal = TRUE; - } - - /* - * May repeat putting Windows for each tab, when "tabpages" is in - * 'sessionoptions'. - * Don't use goto_tabpage(), it may change directory and trigger - * autocommands. - */ - tab_firstwin = firstwin; /* first window in tab page "tabnr" */ - tab_topframe = topframe; - if ((ssop_flags & SSOP_TABPAGES)) - { - tabpage_T *tp; - - // Similar to ses_win_rec() below, populate the tab pages first so - // later local options won't be copied to the new tabs. - FOR_ALL_TABPAGES(tp) - if (tp->tp_next != NULL && put_line(fd, "tabnew") == FAIL) - return FAIL; - if (first_tabpage->tp_next != NULL && put_line(fd, "tabrewind") == FAIL) - return FAIL; - } - for (tabnr = 1; ; ++tabnr) - { - tabpage_T *tp = NULL; - int need_tabnext = FALSE; - int cnr = 1; - - if ((ssop_flags & SSOP_TABPAGES)) - { - tp = find_tabpage(tabnr); - - if (tp == NULL) - break; /* done all tab pages */ - if (tp == curtab) - { - tab_firstwin = firstwin; - tab_topframe = topframe; - } - else - { - tab_firstwin = tp->tp_firstwin; - tab_topframe = tp->tp_topframe; - } - if (tabnr > 1) - need_tabnext = TRUE; - } - - /* - * Before creating the window layout, try loading one file. If this - * is aborted we don't end up with a number of useless windows. - * This may have side effects! (e.g., compressed or network file). - */ - for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) - { - if (ses_do_win(wp) - && wp->w_buffer->b_ffname != NULL - && !bt_help(wp->w_buffer) -#ifdef FEAT_QUICKFIX - && !bt_nofilename(wp->w_buffer) -#endif - ) - { - if (need_tabnext && put_line(fd, "tabnext") == FAIL) - return FAIL; - need_tabnext = FALSE; - - if (fputs("edit ", fd) < 0 - || ses_fname(fd, wp->w_buffer, &ssop_flags, TRUE) - == FAIL) - return FAIL; - if (!wp->w_arg_idx_invalid) - edited_win = wp; - break; - } - } - - /* If no file got edited create an empty tab page. */ - if (need_tabnext && put_line(fd, "tabnext") == FAIL) - return FAIL; - - /* - * Save current window layout. - */ - if (put_line(fd, "set splitbelow splitright") == FAIL) - return FAIL; - if (ses_win_rec(fd, tab_topframe) == FAIL) - return FAIL; - if (!p_sb && put_line(fd, "set nosplitbelow") == FAIL) - return FAIL; - if (!p_spr && put_line(fd, "set nosplitright") == FAIL) - return FAIL; - - /* - * Check if window sizes can be restored (no windows omitted). - * Remember the window number of the current window after restoring. - */ - nr = 0; - for (wp = tab_firstwin; wp != NULL; wp = W_NEXT(wp)) - { - if (ses_do_win(wp)) - ++nr; - else - restore_size = FALSE; - if (curwin == wp) - cnr = nr; - } - - /* Go to the first window. */ - if (put_line(fd, "wincmd t") == FAIL) - return FAIL; - - /* - * If more than one window, see if sizes can be restored. - * First set 'winheight' and 'winwidth' to 1 to avoid the windows being - * resized when moving between windows. - * Do this before restoring the view, so that the topline and the - * cursor can be set. This is done again below. - * winminheight and winminwidth need to be set to avoid an error if the - * user has set winheight or winwidth. - */ - if (put_line(fd, "set winminheight=0") == FAIL - || put_line(fd, "set winheight=1") == FAIL - || put_line(fd, "set winminwidth=0") == FAIL - || put_line(fd, "set winwidth=1") == FAIL) - return FAIL; - if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL) - return FAIL; - - // Restore the tab-local working directory if specified - // Do this before the windows, so that the window-local directory can - // override the tab-local directory. - if (tp != NULL && tp->tp_localdir != NULL && ssop_flags & SSOP_CURDIR) - { - if (fputs("tcd ", fd) < 0 - || ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL - || put_eol(fd) == FAIL) - return FAIL; - did_lcd = TRUE; - } - - /* - * Restore the view of the window (options, file, cursor, etc.). - */ - for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) - { - if (!ses_do_win(wp)) - continue; - if (put_view(fd, wp, wp != edited_win, &ssop_flags, - cur_arg_idx) == FAIL) - return FAIL; - if (nr > 1 && put_line(fd, "wincmd w") == FAIL) - return FAIL; - next_arg_idx = wp->w_arg_idx; - } - - /* 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 - * "tabedit". */ - cur_arg_idx = next_arg_idx; - - /* - * Restore cursor to the current window if it's not the first one. - */ - if (cnr > 1 && (fprintf(fd, "%dwincmd w", cnr) < 0 - || put_eol(fd) == FAIL)) - return FAIL; - - /* - * Restore window sizes again after jumping around in windows, because - * the current window has a minimum size while others may not. - */ - if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL) - return FAIL; - - /* Don't continue in another tab page when doing only the current one - * or when at the last tab page. */ - if (!(ssop_flags & SSOP_TABPAGES)) - break; - } - - if (ssop_flags & SSOP_TABPAGES) - { - if (fprintf(fd, "tabnext %d", tabpage_index(curtab)) < 0 - || put_eol(fd) == FAIL) - return FAIL; - } - if (restore_stal && put_line(fd, "set stal=1") == FAIL) - 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)) -#ifdef FEAT_TERMINAL - // Skip terminal buffers: finished ones are not useful, others - // will be resurrected and result in a new buffer. - && !bt_terminal(buf) -#endif - && buf->b_fname != NULL - && buf->b_p_bl) - { - if (fprintf(fd, "badd +%ld ", buf->b_wininfo == NULL ? 1L - : 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 (put_line(fd, "if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0") - == FAIL) - return FAIL; - if (put_line(fd, " silent exe 'bwipe ' . s:wipebuf") == FAIL) - return FAIL; - if (put_line(fd, "endif") == FAIL) - return FAIL; - if (put_line(fd, "unlet! s:wipebuf") == FAIL) - return FAIL; - - /* Re-apply 'winheight', 'winwidth' and 'shortmess'. */ - if (fprintf(fd, "set winheight=%ld winwidth=%ld shortmess=%s", - p_wh, p_wiw, p_shm) < 0 || put_eol(fd) == FAIL) - return FAIL; - /* Re-apply 'winminheight' and 'winminwidth'. */ - if (fprintf(fd, "set winminheight=%ld winminwidth=%ld", - p_wmh, p_wmw) < 0 || put_eol(fd) == FAIL) - return FAIL; - - /* - * Lastly, execute the x.vim file if it exists. - */ |