aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_session.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-12-23 08:28:17 +0800
committerGitHub <noreply@github.com>2023-12-23 08:28:17 +0800
commit242261d4e77806cdb4559c2be58613113a393a4e (patch)
tree9a6a6e1ded19514fe118833d2698532811691d0b /src/nvim/ex_session.c
parent0c3d2a7fd99d6171fad81cc8b010281b1cd1c3e0 (diff)
downloadrneovim-242261d4e77806cdb4559c2be58613113a393a4e.tar.gz
rneovim-242261d4e77806cdb4559c2be58613113a393a4e.tar.bz2
rneovim-242261d4e77806cdb4559c2be58613113a393a4e.zip
refactor(IWYU): move evalarg_T to eval_defs.h (#26716)
Diffstat (limited to 'src/nvim/ex_session.c')
-rw-r--r--src/nvim/ex_session.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c
index 82e3fe09d2..98869c0a25 100644
--- a/src/nvim/ex_session.c
+++ b/src/nvim/ex_session.c
@@ -13,6 +13,7 @@
#include "nvim/ascii_defs.h"
#include "nvim/buffer.h"
#include "nvim/eval.h"
+#include "nvim/eval/typval.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
@@ -35,6 +36,7 @@
#include "nvim/path.h"
#include "nvim/pos_defs.h"
#include "nvim/runtime.h"
+#include "nvim/strings.h"
#include "nvim/types_defs.h"
#include "nvim/vim_defs.h"
#include "nvim/window.h"
@@ -519,6 +521,50 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr
return OK;
}
+static int store_session_globals(FILE *fd)
+{
+ TV_DICT_ITER(&globvardict, this_var, {
+ 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.
+ char *const p = vim_strsave_escaped(tv_get_string(&this_var->di_tv), "\\\"\n\r");
+ for (char *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) {
+ xfree(p);
+ return FAIL;
+ }
+ xfree(p);
+ } 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;
+ }
+ }
+ });
+ return OK;
+}
+
/// Writes commands for restoring the current buffers, for :mksession.
///
/// Legacy 'sessionoptions'/'viewoptions' flags SSOP_UNIX, SSOP_SLASH are