Mercurial > vim
annotate src/session.c @ 28653:94f2550a1af1
Added tag v8.2.4850 for changeset 27dcbe70e1f0bf400484d81aa0ddc22b71008d19
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 30 Apr 2022 17:15:03 +0200 |
parents | 27dcbe70e1f0 |
children | 8fc86c943863 |
rev | line source |
---|---|
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * session.c: session related functions |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 #if defined(FEAT_SESSION) || defined(PROTO) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 static int did_lcd; // whether ":lcd" was produced for a session |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 * Write a file name to the session file. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 * Takes care of the "slash" option in 'sessionoptions' and escapes special |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 * characters. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 * Returns FAIL if writing fails or out of memory. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 static int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 ses_put_fname(FILE *fd, char_u *name, unsigned *flagp) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 char_u *sname; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 char_u *p; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 int retval = OK; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 sname = home_replace_save(NULL, name); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 if (sname == NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 if (*flagp & SSOP_SLASH) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 // change all backslashes to forward slashes |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 for (p = sname; *p != NUL; MB_PTR_ADV(p)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 if (*p == '\\') |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 *p = '/'; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 // escape special characters |
25994
e8873138ffbb
patch 8.2.3530: ":buf {a}" fails while ":edit {a}" works
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
46 p = vim_strsave_fnameescape(sname, VSE_NONE); |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 vim_free(sname); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 if (p == NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 // write the result |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 if (fputs((char *)p, fd) < 0) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 retval = FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 vim_free(p); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 return retval; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 * Write a buffer name to the session file. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 * Also ends the line, if "add_eol" is TRUE. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 * Returns FAIL if writing fails. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 static int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 ses_fname(FILE *fd, buf_T *buf, unsigned *flagp, int add_eol) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 char_u *name; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 // Use the short file name if the current directory is known at the time |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 // the session file will be sourced. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 // Don't do this for ":mkview", we don't know the current directory. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 // Don't do this after ":lcd", we don't keep track of what the current |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 // directory is. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 if (buf->b_sfname != NULL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 && flagp == &ssop_flags |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 && (ssop_flags & (SSOP_CURDIR | SSOP_SESDIR)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 #ifdef FEAT_AUTOCHDIR |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 && !p_acd |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 && !did_lcd) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 name = buf->b_sfname; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 name = buf->b_ffname; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 if (ses_put_fname(fd, name, flagp) == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 || (add_eol && put_eol(fd) == FAIL)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 return OK; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 * Write an argument list to the session file. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 * Returns FAIL if writing fails. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 static int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 ses_arglist( |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 FILE *fd, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 char *cmd, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 garray_T *gap, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 int fullname, // TRUE: use full path name |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 unsigned *flagp) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 int i; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 char_u *buf = NULL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 char_u *s; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 if (fputs(cmd, fd) < 0 || put_eol(fd) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 if (put_line(fd, "%argdel") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 for (i = 0; i < gap->ga_len; ++i) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 // NULL file names are skipped (only happens when out of memory). |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 s = alist_name(&((aentry_T *)gap->ga_data)[i]); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 if (s != NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 if (fullname) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 buf = alloc(MAXPATHL); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 if (buf != NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 (void)vim_FullName(s, buf, MAXPATHL, FALSE); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 s = buf; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 if (fputs("$argadd ", fd) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 || ses_put_fname(fd, s, flagp) == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 || put_eol(fd) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 vim_free(buf); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 vim_free(buf); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 return OK; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 * Return non-zero if window "wp" is to be stored in the Session. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 static int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 ses_do_win(win_T *wp) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 #ifdef FEAT_TERMINAL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 if (bt_terminal(wp->w_buffer)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 return !term_is_finished(wp->w_buffer) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 && (ssop_flags & SSOP_TERMINAL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 && term_should_restore(wp->w_buffer); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 if (wp->w_buffer->b_fname == NULL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 #ifdef FEAT_QUICKFIX |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 // When 'buftype' is "nofile" can't restore the window contents. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 || bt_nofilename(wp->w_buffer) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 ) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 return (ssop_flags & SSOP_BLANK); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 if (bt_help(wp->w_buffer)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 return (ssop_flags & SSOP_HELP); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 return TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 * Return TRUE if frame "fr" has a window somewhere that we want to save in |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 * the Session. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 static int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 ses_do_frame(frame_T *fr) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 frame_T *frc; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 if (fr->fr_layout == FR_LEAF) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 return ses_do_win(fr->fr_win); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 FOR_ALL_FRAMES(frc, fr->fr_child) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 if (ses_do_frame(frc)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 return TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 return FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 * Skip frames that don't contain windows we want to save in the Session. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 * Returns NULL when there none. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 static frame_T * |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 ses_skipframe(frame_T *fr) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 frame_T *frc; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 FOR_ALL_FRAMES(frc, fr) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 if (ses_do_frame(frc)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 break; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 return frc; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 * Write commands to "fd" to recursively create windows for frame "fr", |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 * horizontally and vertically split. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 * After the commands the last window in the frame is the current window. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 * Returns FAIL when writing the commands to "fd" fails. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 static int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 ses_win_rec(FILE *fd, frame_T *fr) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 frame_T *frc; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 int count = 0; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 if (fr->fr_layout != FR_LEAF) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 // Find first frame that's not skipped and then create a window for |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 // each following one (first frame is already there). |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 frc = ses_skipframe(fr->fr_child); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 if (frc != NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 while ((frc = ses_skipframe(frc->fr_next)) != NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 // Make window as big as possible so that we have lots of room |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 // to split. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 if (put_line(fd, "wincmd _ | wincmd |") == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 || put_line(fd, fr->fr_layout == FR_COL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 ? "split" : "vsplit") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 ++count; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 // Go back to the first window. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 if (count > 0 && (fprintf(fd, fr->fr_layout == FR_COL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 ? "%dwincmd k" : "%dwincmd h", count) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 || put_eol(fd) == FAIL)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 // Recursively create frames/windows in each window of this column or |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 // row. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 frc = ses_skipframe(fr->fr_child); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 while (frc != NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 ses_win_rec(fd, frc); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 frc = ses_skipframe(frc->fr_next); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 // Go to next window. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 if (frc != NULL && put_line(fd, "wincmd w") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 return OK; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
244 static int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 ses_winsizes( |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 FILE *fd, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 int restore_size, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 win_T *tab_firstwin) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 int n = 0; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 win_T *wp; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 if (restore_size && (ssop_flags & SSOP_WINSIZE)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 if (!ses_do_win(wp)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 continue; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 ++n; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 // restore height when not full height |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 if (wp->w_height + wp->w_status_height < topframe->fr_height |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 && (fprintf(fd, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 "exe '%dresize ' . ((&lines * %ld + %ld) / %ld)", |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 n, (long)wp->w_height, Rows / 2, Rows) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 || put_eol(fd) == FAIL)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 // restore width when not full width |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 if (wp->w_width < Columns && (fprintf(fd, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 "exe 'vert %dresize ' . ((&columns * %ld + %ld) / %ld)", |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 n, (long)wp->w_width, Columns / 2, Columns) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 || put_eol(fd) == FAIL)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
274 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 // Just equalise window sizes |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 if (put_line(fd, "wincmd =") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 return OK; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 static int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 put_view_curpos(FILE *fd, win_T *wp, char *spaces) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 int r; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
290 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 if (wp->w_curswant == MAXCOL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 r = fprintf(fd, "%snormal! $", spaces); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
294 r = fprintf(fd, "%snormal! 0%d|", spaces, wp->w_virtcol + 1); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 return r < 0 || put_eol(fd) == FAIL ? FALSE : OK; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 * Write commands to "fd" to restore the view of a window. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 * Caller must make sure 'scrolloff' is zero. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 static int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 put_view( |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
304 FILE *fd, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
305 win_T *wp, |
22230
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
306 int add_edit, // add ":edit" command to view |
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
307 unsigned *flagp, // vop_flags or ssop_flags |
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
308 int current_arg_idx, // current argument index of the window, |
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
309 // use -1 if unknown |
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
310 hashtab_T *terminal_bufs UNUSED) // already encountered terminal buffers, |
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
311 // can be NULL |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
313 win_T *save_curwin; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 int f; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 int do_cursor; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 int did_next = FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 // Always restore cursor position for ":mksession". For ":mkview" only |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
319 // when 'viewoptions' contains "cursor". |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 do_cursor = (flagp == &ssop_flags || *flagp & SSOP_CURSOR); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
321 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 // Local argument list. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 if (wp->w_alist == &global_alist) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 if (put_line(fd, "argglobal") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
328 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 if (ses_arglist(fd, "arglocal", &wp->w_alist->al_ga, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 flagp == &vop_flags |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 || !(*flagp & SSOP_CURDIR) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 || wp->w_localdir != NULL, flagp) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 // Only when part of a session: restore the argument index. Some |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 // arguments may have been deleted, check if the index is valid. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 if (wp->w_arg_idx != current_arg_idx && wp->w_arg_idx < WARGCOUNT(wp) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
340 && flagp == &ssop_flags) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 if (fprintf(fd, "%ldargu", (long)wp->w_arg_idx + 1) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 || put_eol(fd) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
344 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 did_next = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 // Edit the file. Skip this when ":next" already did it. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
349 if (add_edit && (!did_next || wp->w_arg_idx_invalid)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 { |
26956
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
351 if (bt_help(wp->w_buffer)) |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
352 { |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
353 char *curtag = ""; |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
354 |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
355 // A help buffer needs some options to be set. |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
356 // First, create a new empty buffer with "buftype=help". |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
357 // Then ":help" will re-use both the buffer and the window and set |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
358 // the options, even when "options" is not in 'sessionoptions'. |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
359 if (0 < wp->w_tagstackidx |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
360 && wp->w_tagstackidx <= wp->w_tagstacklen) |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
361 curtag = (char *)wp->w_tagstack[wp->w_tagstackidx - 1].tagname; |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
362 |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
363 if (put_line(fd, "enew | setl bt=help") == FAIL |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
364 || fprintf(fd, "help %s", curtag) < 0 |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
365 || put_eol(fd) == FAIL) |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
366 return FAIL; |
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
367 } |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 # ifdef FEAT_TERMINAL |
26956
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
369 else if (bt_terminal(wp->w_buffer)) |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 { |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
371 if (term_write_session(fd, wp, terminal_bufs) == FAIL) |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 # endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 // Load the file. |
26956
86f8718c643d
patch 8.2.4007: session does not restore help buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
376 else if (wp->w_buffer->b_ffname != NULL |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 # ifdef FEAT_QUICKFIX |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 && !bt_nofilename(wp->w_buffer) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 # endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 ) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 // Editing a file in this buffer: use ":edit file". |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 // This may have side effects! (e.g., compressed or network file). |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 // |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 // Note, if a buffer for that file already exists, use :badd to |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
386 // edit that buffer, to not lose folding information (:edit resets |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 // folds in other buffers) |
28083
f1c00b8085f6
patch 8.2.4566: check for existing buffer in session file may not work
Bram Moolenaar <Bram@vim.org>
parents:
27122
diff
changeset
|
388 if (fputs("if bufexists(fnamemodify(\"", fd) < 0 |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 || ses_fname(fd, wp->w_buffer, flagp, FALSE) == FAIL |
28083
f1c00b8085f6
patch 8.2.4566: check for existing buffer in session file may not work
Bram Moolenaar <Bram@vim.org>
parents:
27122
diff
changeset
|
390 || fputs("\", \":p\")) | buffer ", fd) < 0 |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 || ses_fname(fd, wp->w_buffer, flagp, FALSE) == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 || fputs(" | else | edit ", fd) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 || ses_fname(fd, wp->w_buffer, flagp, FALSE) == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 || fputs(" | endif", fd) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 || put_eol(fd) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
400 // No file in this buffer, just make it empty. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 if (put_line(fd, "enew") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
403 #ifdef FEAT_QUICKFIX |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 if (wp->w_buffer->b_ffname != NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 // The buffer does have a name, but it's not a file name. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 if (fputs("file ", fd) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 || ses_fname(fd, wp->w_buffer, flagp, TRUE) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 do_cursor = FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 |
22840
7c1e2e3f2d8d
patch 8.2.1967: the session file does not restore the alternate file
Bram Moolenaar <Bram@vim.org>
parents:
22776
diff
changeset
|
416 if (wp->w_alt_fnum) |
7c1e2e3f2d8d
patch 8.2.1967: the session file does not restore the alternate file
Bram Moolenaar <Bram@vim.org>
parents:
22776
diff
changeset
|
417 { |
7c1e2e3f2d8d
patch 8.2.1967: the session file does not restore the alternate file
Bram Moolenaar <Bram@vim.org>
parents:
22776
diff
changeset
|
418 buf_T *alt = buflist_findnr(wp->w_alt_fnum); |
7c1e2e3f2d8d
patch 8.2.1967: the session file does not restore the alternate file
Bram Moolenaar <Bram@vim.org>
parents:
22776
diff
changeset
|
419 |
24106
3b5d499c2bb5
patch 8.2.2594: alternate buffer added to session file even when it's hidden
Bram Moolenaar <Bram@vim.org>
parents:
23851
diff
changeset
|
420 // Set the alternate file if the buffer is listed. |
23851
a2f13e56b0e7
patch 8.2.2467: script generated by :mkview changes alternate file
Bram Moolenaar <Bram@vim.org>
parents:
23023
diff
changeset
|
421 if ((flagp == &ssop_flags) |
a2f13e56b0e7
patch 8.2.2467: script generated by :mkview changes alternate file
Bram Moolenaar <Bram@vim.org>
parents:
23023
diff
changeset
|
422 && alt != NULL |
22840
7c1e2e3f2d8d
patch 8.2.1967: the session file does not restore the alternate file
Bram Moolenaar <Bram@vim.org>
parents:
22776
diff
changeset
|
423 && alt->b_fname != NULL |
7c1e2e3f2d8d
patch 8.2.1967: the session file does not restore the alternate file
Bram Moolenaar <Bram@vim.org>
parents:
22776
diff
changeset
|
424 && *alt->b_fname != NUL |
24106
3b5d499c2bb5
patch 8.2.2594: alternate buffer added to session file even when it's hidden
Bram Moolenaar <Bram@vim.org>
parents:
23851
diff
changeset
|
425 && alt->b_p_bl |
22840
7c1e2e3f2d8d
patch 8.2.1967: the session file does not restore the alternate file
Bram Moolenaar <Bram@vim.org>
parents:
22776
diff
changeset
|
426 && (fputs("balt ", fd) < 0 |
7c1e2e3f2d8d
patch 8.2.1967: the session file does not restore the alternate file
Bram Moolenaar <Bram@vim.org>
parents:
22776
diff
changeset
|
427 || ses_fname(fd, alt, flagp, TRUE) == FAIL)) |
7c1e2e3f2d8d
patch 8.2.1967: the session file does not restore the alternate file
Bram Moolenaar <Bram@vim.org>
parents:
22776
diff
changeset
|
428 return FAIL; |
7c1e2e3f2d8d
patch 8.2.1967: the session file does not restore the alternate file
Bram Moolenaar <Bram@vim.org>
parents:
22776
diff
changeset
|
429 } |
7c1e2e3f2d8d
patch 8.2.1967: the session file does not restore the alternate file
Bram Moolenaar <Bram@vim.org>
parents:
22776
diff
changeset
|
430 |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 // Local mappings and abbreviations. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 if ((*flagp & (SSOP_OPTIONS | SSOP_LOCALOPTIONS)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 && makemap(fd, wp->w_buffer) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 // Local options. Need to go to the window temporarily. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 // Store only local values when using ":mkview" and when ":mksession" is |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 // used and 'sessionoptions' doesn't include "options". |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 // Some folding options are always stored when "folds" is included, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 // otherwise the folds would not be restored correctly. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 save_curwin = curwin; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 curwin = wp; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 curbuf = curwin->w_buffer; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 if (*flagp & (SSOP_OPTIONS | SSOP_LOCALOPTIONS)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 f = makeset(fd, OPT_LOCAL, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 flagp == &vop_flags || !(*flagp & SSOP_OPTIONS)); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 #ifdef FEAT_FOLDING |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 else if (*flagp & SSOP_FOLDS) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 f = makefoldset(fd); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 f = OK; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 curwin = save_curwin; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 curbuf = curwin->w_buffer; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 if (f == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 #ifdef FEAT_FOLDING |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 // Save Folds when 'buftype' is empty and for help files. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 if ((*flagp & SSOP_FOLDS) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 && wp->w_buffer->b_ffname != NULL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 && (bt_normal(wp->w_buffer) || bt_help(wp->w_buffer))) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 if (put_folds(fd, wp) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 // Set the cursor after creating folds, since that moves the cursor. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 if (do_cursor) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
473 // Restore the cursor line in the file and relatively in the |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 // window. Don't use "G", it changes the jumplist. |
24561
f6049d3ab81c
patch 8.2.2820: session file may divide by zero
Bram Moolenaar <Bram@vim.org>
parents:
24473
diff
changeset
|
475 if (wp->w_height <= 0) |
f6049d3ab81c
patch 8.2.2820: session file may divide by zero
Bram Moolenaar <Bram@vim.org>
parents:
24473
diff
changeset
|
476 { |
f6049d3ab81c
patch 8.2.2820: session file may divide by zero
Bram Moolenaar <Bram@vim.org>
parents:
24473
diff
changeset
|
477 if (fprintf(fd, "let s:l = %ld", (long)wp->w_cursor.lnum) < 0) |
f6049d3ab81c
patch 8.2.2820: session file may divide by zero
Bram Moolenaar <Bram@vim.org>
parents:
24473
diff
changeset
|
478 return FAIL; |
f6049d3ab81c
patch 8.2.2820: session file may divide by zero
Bram Moolenaar <Bram@vim.org>
parents:
24473
diff
changeset
|
479 } |
f6049d3ab81c
patch 8.2.2820: session file may divide by zero
Bram Moolenaar <Bram@vim.org>
parents:
24473
diff
changeset
|
480 else if (fprintf(fd, |
f6049d3ab81c
patch 8.2.2820: session file may divide by zero
Bram Moolenaar <Bram@vim.org>
parents:
24473
diff
changeset
|
481 "let s:l = %ld - ((%ld * winheight(0) + %ld) / %ld)", |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 (long)wp->w_cursor.lnum, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 (long)(wp->w_cursor.lnum - wp->w_topline), |
24561
f6049d3ab81c
patch 8.2.2820: session file may divide by zero
Bram Moolenaar <Bram@vim.org>
parents:
24473
diff
changeset
|
484 (long)wp->w_height / 2, (long)wp->w_height) < 0) |
f6049d3ab81c
patch 8.2.2820: session file may divide by zero
Bram Moolenaar <Bram@vim.org>
parents:
24473
diff
changeset
|
485 return FAIL; |
f6049d3ab81c
patch 8.2.2820: session file may divide by zero
Bram Moolenaar <Bram@vim.org>
parents:
24473
diff
changeset
|
486 |
f6049d3ab81c
patch 8.2.2820: session file may divide by zero
Bram Moolenaar <Bram@vim.org>
parents:
24473
diff
changeset
|
487 if (put_eol(fd) == FAIL |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 || put_line(fd, "if s:l < 1 | let s:l = 1 | endif") == FAIL |
23023
4384c44c031a
patch 8.2.2058: using mkview/loadview changes the jumplist
Bram Moolenaar <Bram@vim.org>
parents:
22840
diff
changeset
|
489 || put_line(fd, "keepjumps exe s:l") == FAIL |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 || put_line(fd, "normal! zt") == FAIL |
23023
4384c44c031a
patch 8.2.2058: using mkview/loadview changes the jumplist
Bram Moolenaar <Bram@vim.org>
parents:
22840
diff
changeset
|
491 || fprintf(fd, "keepjumps %ld", (long)wp->w_cursor.lnum) < 0 |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 || put_eol(fd) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 // Restore the cursor column and left offset when not wrapping. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 if (wp->w_cursor.col == 0) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 if (put_line(fd, "normal! 0") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 if (!wp->w_p_wrap && wp->w_leftcol > 0 && wp->w_width > 0) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 if (fprintf(fd, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 "let s:c = %ld - ((%ld * winwidth(0) + %ld) / %ld)", |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 (long)wp->w_virtcol + 1, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 (long)(wp->w_virtcol - wp->w_leftcol), |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 (long)wp->w_width / 2, (long)wp->w_width) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 || put_eol(fd) == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 || put_line(fd, "if s:c > 0") == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 || fprintf(fd, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 " exe 'normal! ' . s:c . '|zs' . %ld . '|'", |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 (long)wp->w_virtcol + 1) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 || put_eol(fd) == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 || put_line(fd, "else") == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 || put_view_curpos(fd, wp, " ") == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 || put_line(fd, "endif") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 else if (put_view_curpos(fd, wp, "") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 // Local directory, if the current flag is not view options or the "curdir" |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 // option is included. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 if (wp->w_localdir != NULL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
528 && (flagp != &vop_flags || (*flagp & SSOP_CURDIR))) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 if (fputs("lcd ", fd) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 || ses_put_fname(fd, wp->w_localdir, flagp) == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 || put_eol(fd) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 did_lcd = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 return OK; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 #ifdef FEAT_EVAL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 static int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 store_session_globals(FILE *fd) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 { |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17539
diff
changeset
|
544 hashtab_T *gvht = get_globvar_ht(); |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 hashitem_T *hi; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
546 dictitem_T *this_var; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 int todo; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
548 char_u *p, *t; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
549 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17539
diff
changeset
|
550 todo = (int)gvht->ht_used; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17539
diff
changeset
|
551 for (hi = gvht->ht_array; todo > 0; ++hi) |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 if (!HASHITEM_EMPTY(hi)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
555 --todo; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 this_var = HI2DI(hi); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 if ((this_var->di_tv.v_type == VAR_NUMBER |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 || this_var->di_tv.v_type == VAR_STRING) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
559 && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 // Escape special characters with a backslash. Turn a LF and |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 // CR into \n and \r. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 p = vim_strsave_escaped(tv_get_string(&this_var->di_tv), |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 (char_u *)"\\\"\n\r"); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 if (p == NULL) // out of memory |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 break; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 for (t = p; *t != NUL; ++t) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 if (*t == '\n') |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 *t = 'n'; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 else if (*t == '\r') |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 *t = 'r'; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 if ((fprintf(fd, "let %s = %c%s%c", |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 this_var->di_key, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 (this_var->di_tv.v_type == VAR_STRING) ? '"' |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 : ' ', |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
576 p, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
577 (this_var->di_tv.v_type == VAR_STRING) ? '"' |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
578 : ' ') < 0) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
579 || put_eol(fd) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
580 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 vim_free(p); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 vim_free(p); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
585 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 #ifdef FEAT_FLOAT |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 else if (this_var->di_tv.v_type == VAR_FLOAT |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
589 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 float_T f = this_var->di_tv.vval.v_float; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 int sign = ' '; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 if (f < 0) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
594 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
595 f = -f; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 sign = '-'; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
597 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
598 if ((fprintf(fd, "let %s = %c%f", |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 this_var->di_key, sign, f) < 0) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 || put_eol(fd) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 return OK; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
607 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
610 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
611 * Write openfile commands for the current buffers to an .exrc file. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 * Return FAIL on error, OK otherwise. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
614 static int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
615 makeopens( |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 FILE *fd, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
617 char_u *dirnow) // Current directory name |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
618 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
619 buf_T *buf; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 int only_save_windows = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
621 int nr; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 int restore_size = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
623 win_T *wp; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
624 char_u *sname; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
625 win_T *edited_win = NULL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 int restore_stal = FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 win_T *tab_firstwin; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 frame_T *tab_topframe; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 int cur_arg_idx = 0; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 int next_arg_idx = 0; |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
631 int ret = FAIL; |
28652
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
632 tabpage_T *tp; |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
633 #ifdef FEAT_TERMINAL |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
634 hashtab_T terminal_bufs; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
635 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
636 hash_init(&terminal_bufs); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
637 #endif |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 if (ssop_flags & SSOP_BUFFERS) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
640 only_save_windows = FALSE; // Save ALL buffers |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 // Begin by setting the this_session variable, and then other |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 // sessionable variables. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 #ifdef FEAT_EVAL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
645 if (put_line(fd, "let v:this_session=expand(\"<sfile>:p\")") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
646 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 if (ssop_flags & SSOP_GLOBALS) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
648 if (store_session_globals(fd) == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
649 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
650 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
651 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 // Close all windows and tabs but one. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 if (put_line(fd, "silent only") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
654 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
655 if ((ssop_flags & SSOP_TABPAGES) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
656 && put_line(fd, "silent tabonly") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
657 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
659 // Now a :cd command to the session directory or the current directory |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 if (ssop_flags & SSOP_SESDIR) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 if (put_line(fd, "exe \"cd \" . escape(expand(\"<sfile>:p:h\"), ' ')") |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
663 == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
664 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 else if (ssop_flags & SSOP_CURDIR) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 sname = home_replace_save(NULL, globaldir != NULL ? globaldir : dirnow); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 if (sname == NULL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 || fputs("cd ", fd) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 || ses_put_fname(fd, sname, &ssop_flags) == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 || put_eol(fd) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 vim_free(sname); |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
675 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 vim_free(sname); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 // If there is an empty, unnamed buffer we will wipe it out later. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 // Remember the buffer number. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 if (put_line(fd, "if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
683 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 if (put_line(fd, " let s:wipebuf = bufnr('%')") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
685 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 if (put_line(fd, "endif") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
687 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
688 |
28238
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
689 // save 'shortmess' if not storing options |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
690 if ((ssop_flags & SSOP_OPTIONS) == 0 |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
691 && put_line(fd, "let s:shortmess_save = &shortmess") == FAIL) |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
692 goto fail; |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
693 |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 // Now save the current files, current buffer first. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 if (put_line(fd, "set shortmess=aoO") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
696 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
697 |
27122
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
698 // Put all buffers into the buffer list. |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
699 // Do it very early to preserve buffer order after loading session (which |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
700 // can be disrupted by prior `edit` or `tabedit` calls). |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
701 FOR_ALL_BUFFERS(buf) |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
702 { |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
703 if (!(only_save_windows && buf->b_nwindows == 0) |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
704 && !(buf->b_help && !(ssop_flags & SSOP_HELP)) |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
705 #ifdef FEAT_TERMINAL |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
706 // Skip terminal buffers: finished ones are not useful, others |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
707 // will be resurrected and result in a new buffer. |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
708 && !bt_terminal(buf) |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
709 #endif |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
710 && buf->b_fname != NULL |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
711 && buf->b_p_bl) |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
712 { |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
713 if (fprintf(fd, "badd +%ld ", buf->b_wininfo == NULL ? 1L |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
714 : buf->b_wininfo->wi_fpos.lnum) < 0 |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
715 || ses_fname(fd, buf, &ssop_flags, TRUE) == FAIL) |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
716 goto fail; |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
717 } |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
718 } |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
719 |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
720 // the global argument list |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
721 if (ses_arglist(fd, "argglobal", &global_alist.al_ga, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
722 !(ssop_flags & SSOP_CURDIR), &ssop_flags) == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
723 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
724 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 if (ssop_flags & SSOP_RESIZE) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
726 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 // Note: after the restore we still check it worked! |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 if (fprintf(fd, "set lines=%ld columns=%ld" , Rows, Columns) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
729 || put_eol(fd) == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
730 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
732 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 #ifdef FEAT_GUI |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 if (gui.in_use && (ssop_flags & SSOP_WINPOS)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 int x, y; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 if (gui_mch_get_winpos(&x, &y) == OK) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
740 // Note: after the restore we still check it worked! |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 if (fprintf(fd, "winpos %d %d", x, y) < 0 || put_eol(fd) == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
742 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
745 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 // When there are two or more tabpages and 'showtabline' is 1 the tabline |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
748 // will be displayed when creating the next tab. That resizes the windows |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 // in the first tab, which may cause problems. Set 'showtabline' to 2 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
750 // temporarily to avoid that. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 if (p_stal == 1 && first_tabpage->tp_next != NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
752 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
753 if (put_line(fd, "set stal=2") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
754 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 restore_stal = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 if ((ssop_flags & SSOP_TABPAGES)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 { |
28652
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
760 // "tabpages" is in 'sessionoptions': Similar to ses_win_rec() below, |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
761 // populate the tab pages first so later local options won't be copied |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
762 // to the new tabs. |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
763 FOR_ALL_TABPAGES(tp) |
27122
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
764 // Use `bufhidden=wipe` to remove empty "placeholder" buffers once |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
765 // they are not needed. This prevents creating extra buffers (see |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
766 // cause of patch 8.1.0829) |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
767 if (tp->tp_next != NULL |
4fd87205ca80
patch 8.2.4090: after restoring a session buffer order can be quite different
Bram Moolenaar <Bram@vim.org>
parents:
26956
diff
changeset
|
768 && put_line(fd, "tabnew +setlocal\\ bufhidden=wipe") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
769 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
770 if (first_tabpage->tp_next != NULL && put_line(fd, "tabrewind") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
771 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 } |
28652
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
773 |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
774 // Assume "tabpages" is in 'sessionoptions'. If not then we only do |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
775 // "curtab" and bail out of the loop. |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
776 FOR_ALL_TABPAGES(tp) |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 int need_tabnext = FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
779 int cnr = 1; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 |
28652
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
781 // May repeat putting Windows for each tab, when "tabpages" is in |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
782 // 'sessionoptions'. |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
783 // Don't use goto_tabpage(), it may change directory and trigger |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
784 // autocommands. |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 if ((ssop_flags & SSOP_TABPAGES)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
786 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
787 if (tp == curtab) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
788 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 tab_firstwin = firstwin; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
790 tab_topframe = topframe; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
791 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
792 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
793 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
794 tab_firstwin = tp->tp_firstwin; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
795 tab_topframe = tp->tp_topframe; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
796 } |
28652
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
797 if (tp != first_tabpage) |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
798 need_tabnext = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
799 } |
28652
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
800 else |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
801 { |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
802 tp = curtab; |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
803 tab_firstwin = firstwin; |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
804 tab_topframe = topframe; |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
805 } |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 // Before creating the window layout, try loading one file. If this |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 // is aborted we don't end up with a number of useless windows. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
809 // This may have side effects! (e.g., compressed or network file). |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
810 for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 if (ses_do_win(wp) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
813 && wp->w_buffer->b_ffname != NULL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
814 && !bt_help(wp->w_buffer) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
815 #ifdef FEAT_QUICKFIX |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
816 && !bt_nofilename(wp->w_buffer) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 ) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
819 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 if (need_tabnext && put_line(fd, "tabnext") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
821 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 need_tabnext = FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
824 if (fputs("edit ", fd) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 || ses_fname(fd, wp->w_buffer, &ssop_flags, TRUE) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
826 == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
827 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
828 if (!wp->w_arg_idx_invalid) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 edited_win = wp; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 break; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 // If no file got edited create an empty tab page. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 if (need_tabnext && put_line(fd, "tabnext") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
836 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 |
24473
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
838 if (tab_topframe->fr_layout != FR_LEAF) |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
839 { |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
840 // Save current window layout. |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
841 if (put_line(fd, "let s:save_splitbelow = &splitbelow") == FAIL |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
842 || put_line(fd, "let s:save_splitright = &splitright") |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
843 == FAIL) |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
844 goto fail; |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
845 if (put_line(fd, "set splitbelow splitright") == FAIL) |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
846 goto fail; |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
847 if (ses_win_rec(fd, tab_topframe) == FAIL) |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
848 goto fail; |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
849 if (put_line(fd, "let &splitbelow = s:save_splitbelow") == FAIL |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
850 || put_line(fd, "let &splitright = s:save_splitright") |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
851 == FAIL) |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
852 goto fail; |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
853 } |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 // Check if window sizes can be restored (no windows omitted). |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 // Remember the window number of the current window after restoring. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 nr = 0; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 for (wp = tab_firstwin; wp != NULL; wp = W_NEXT(wp)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
860 if (ses_do_win(wp)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
861 ++nr; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
862 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
863 restore_size = FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 if (curwin == wp) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 cnr = nr; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 |
24473
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
868 if (tab_firstwin->w_next != NULL) |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
869 { |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
870 // Go to the first window. |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
871 if (put_line(fd, "wincmd t") == FAIL) |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
872 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 |
24473
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
874 // If more than one window, see if sizes can be restored. |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
875 // First set 'winheight' and 'winwidth' to 1 to avoid the windows |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
876 // being resized when moving between windows. |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
877 // Do this before restoring the view, so that the topline and the |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
878 // cursor can be set. This is done again below. |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
879 // winminheight and winminwidth need to be set to avoid an error if |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
880 // the user has set winheight or winwidth. |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
881 if (put_line(fd, "let s:save_winminheight = &winminheight") == FAIL |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
882 || put_line(fd, "let s:save_winminwidth = &winminwidth") |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
883 == FAIL) |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
884 goto fail; |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
885 if (put_line(fd, "set winminheight=0") == FAIL |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
886 || put_line(fd, "set winheight=1") == FAIL |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
887 || put_line(fd, "set winminwidth=0") == FAIL |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
888 || put_line(fd, "set winwidth=1") == FAIL) |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
889 goto fail; |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
890 } |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
892 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
893 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 // Restore the tab-local working directory if specified |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 // Do this before the windows, so that the window-local directory can |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
896 // override the tab-local directory. |
28652
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
897 if ((ssop_flags & SSOP_CURDIR) && tp->tp_localdir != NULL) |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
898 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 if (fputs("tcd ", fd) < 0 |
28652
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
900 || ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL |
27dcbe70e1f0
patch 8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Bram Moolenaar <Bram@vim.org>
parents:
28238
diff
changeset
|
901 || put_eol(fd) == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
902 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
903 did_lcd = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 // Restore the view of the window (options, file, cursor, etc.). |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
907 for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
909 if (!ses_do_win(wp)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
910 continue; |
22230
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
911 if (put_view(fd, wp, wp != edited_win, &ssop_flags, cur_arg_idx, |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
912 #ifdef FEAT_TERMINAL |
22230
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
913 &terminal_bufs |
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
914 #else |
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
915 NULL |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
916 #endif |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
917 ) == FAIL) |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
918 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
919 if (nr > 1 && put_line(fd, "wincmd w") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
920 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 next_arg_idx = wp->w_arg_idx; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
922 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
923 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
924 // The argument index in the first tab page is zero, need to set it in |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
925 // each window. For further tab pages it's the window where we do |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
926 // "tabedit". |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
927 cur_arg_idx = next_arg_idx; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
929 // Restore cursor to the current window if it's not the first one. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
930 if (cnr > 1 && (fprintf(fd, "%dwincmd w", cnr) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
931 || put_eol(fd) == FAIL)) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
932 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 // Restore window sizes again after jumping around in windows, because |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 // the current window has a minimum size while others may not. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
937 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 // Don't continue in another tab page when doing only the current one |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 // or when at the last tab page. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 if (!(ssop_flags & SSOP_TABPAGES)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 break; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 if (ssop_flags & SSOP_TABPAGES) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 if (fprintf(fd, "tabnext %d", tabpage_index(curtab)) < 0 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
948 || put_eol(fd) == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
949 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
951 if (restore_stal && put_line(fd, "set stal=1") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
952 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
954 // Wipe out an empty unnamed buffer we started in. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
955 if (put_line(fd, "if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0") |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
957 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
958 if (put_line(fd, " silent exe 'bwipe ' . s:wipebuf") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
959 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
960 if (put_line(fd, "endif") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
961 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 if (put_line(fd, "unlet! s:wipebuf") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
963 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 |
28238
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
965 // Re-apply 'winheight' and 'winwidth'. |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
966 if (fprintf(fd, "set winheight=%ld winwidth=%ld", |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
967 p_wh, p_wiw) < 0 || put_eol(fd) == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
968 goto fail; |
28238
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
969 |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
970 // Restore 'shortmess'. |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
971 if (ssop_flags & SSOP_OPTIONS) |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
972 { |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
973 if (fprintf(fd, "set shortmess=%s", p_shm) < 0 || put_eol(fd) == FAIL) |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
974 goto fail; |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
975 } |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
976 else |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
977 { |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
978 if (put_line(fd, "let &shortmess = s:shortmess_save") == FAIL) |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
979 goto fail; |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
980 } |
800e7de2f96d
patch 8.2.4645: 'shortmess' changed when session does not store options
Bram Moolenaar <Bram@vim.org>
parents:
28083
diff
changeset
|
981 |
24473
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
982 if (tab_firstwin->w_next != NULL) |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
983 { |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
984 // Restore 'winminheight' and 'winminwidth'. |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
985 if (put_line(fd, "let &winminheight = s:save_winminheight") == FAIL |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
986 || put_line(fd, "let &winminwidth = s:save_winminwidth") == FAIL) |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
987 goto fail; |
b2484fa6cb02
patch 8.2.2776: :mksession uses current value of 'splitbelow' and 'splitright'
Bram Moolenaar <Bram@vim.org>
parents:
24464
diff
changeset
|
988 } |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 // Lastly, execute the x.vim file if it exists. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 if (put_line(fd, "let s:sx = expand(\"<sfile>:p:r\").\"x.vim\"") == FAIL |
20057
407351a89c61
patch 8.2.0584: viminfo file uses obsolete function file_readable()
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
992 || put_line(fd, "if filereadable(s:sx)") == FAIL |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 || put_line(fd, " exe \"source \" . fnameescape(s:sx)") == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 || put_line(fd, "endif") == FAIL) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
995 goto fail; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
997 ret = OK; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
998 fail: |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
999 #ifdef FEAT_TERMINAL |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
1000 hash_clear_all(&terminal_bufs, 0); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
1001 #endif |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
20057
diff
changeset
|
1002 return ret; |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 * Get the name of the view file for the current buffer. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 static char_u * |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 get_view_file(int c) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 int len = 0; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 char_u *p, *s; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 char_u *retval; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 char_u *sname; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 if (curbuf->b_ffname == NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 { |
25306
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24561
diff
changeset
|
1018 emsg(_(e_no_file_name)); |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 return NULL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 sname = home_replace_save(NULL, curbuf->b_ffname); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 if (sname == NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 return NULL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 // We want a file name without separators, because we're not going to make |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 // a directory. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 // "normal" path separator -> "=+" |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 // "=" -> "==" |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 // ":" path separator -> "=-" |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 for (p = sname; *p; ++p) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 if (*p == '=' || vim_ispathsep(*p)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 ++len; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 retval = alloc(STRLEN(sname) + len + STRLEN(p_vdir) + 9); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 if (retval != NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 STRCPY(retval, p_vdir); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 add_pathsep(retval); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 s = retval + STRLEN(retval); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 for (p = sname; *p; ++p) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 if (*p == '=') |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 *s++ = '='; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 *s++ = '='; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 else if (vim_ispathsep(*p)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 *s++ = '='; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 #if defined(BACKSLASH_IN_FILENAME) || defined(AMIGA) || defined(VMS) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 if (*p == ':') |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 *s++ = '-'; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 *s++ = '+'; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 *s++ = *p; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 *s++ = '='; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 *s++ = c; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 STRCPY(s, ".vim"); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 vim_free(sname); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 return retval; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 * ":loadview [nr]" |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 void |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 ex_loadview(exarg_T *eap) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 char_u *fname; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 fname = get_view_file(*eap->arg); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 if (fname != NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18215
diff
changeset
|
1079 do_source(fname, FALSE, DOSO_NONE, NULL); |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 vim_free(fname); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 |
18215
86a865a89661
patch 8.1.2102: can't build with GTK and FEAT_GUI_GNOME
Bram Moolenaar <Bram@vim.org>
parents:
18213
diff
changeset
|
1084 # if defined(FEAT_GUI_GNOME) \ |
18213
aa0972536d3e
patch 8.1.2101: write_session_file() often defined but not used
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
1085 || (defined(GUI_MAY_SPAWN) && defined(EXPERIMENTAL_GUI_CMD)) \ |
aa0972536d3e
patch 8.1.2101: write_session_file() often defined but not used
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
1086 || defined(PROTO) |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1088 * Generate a script that can be used to restore the current editing session. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 * Save the value of v:this_session before running :mksession in order to make |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 * automagic session save fully transparent. Return TRUE on success. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 write_session_file(char_u *filename) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 char_u *escaped_filename; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 char *mksession_cmdline; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 unsigned int save_ssop_flags; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 int failed; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 // Build an ex command line to create a script that restores the current |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 // session if executed. Escape the filename to avoid nasty surprises. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 escaped_filename = vim_strsave_escaped(filename, escape_chars); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 if (escaped_filename == NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1104 return FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 mksession_cmdline = alloc(10 + (int)STRLEN(escaped_filename) + 1); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 if (mksession_cmdline == NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 vim_free(escaped_filename); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 return FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 strcpy(mksession_cmdline, "mksession "); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 STRCAT(mksession_cmdline, escaped_filename); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 vim_free(escaped_filename); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 // Use a reasonable hardcoded set of 'sessionoptions' flags to avoid |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 // unpredictable effects when the session is saved automatically. Also, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 // we definitely need SSOP_GLOBALS to be able to restore v:this_session. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 // Don't use SSOP_BUFFERS to prevent the buffer list from becoming |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 // enormously large if the GNOME session feature is used regularly. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 save_ssop_flags = ssop_flags; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 ssop_flags = (SSOP_BLANK|SSOP_CURDIR|SSOP_FOLDS|SSOP_GLOBALS |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 |SSOP_HELP|SSOP_OPTIONS|SSOP_WINSIZE|SSOP_TABPAGES); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 do_cmdline_cmd((char_u *)"let Save_VV_this_session = v:this_session"); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 failed = (do_cmdline_cmd((char_u *)mksession_cmdline) == FAIL); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 do_cmdline_cmd((char_u *)"let v:this_session = Save_VV_this_session"); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 do_unlet((char_u *)"Save_VV_this_session", TRUE); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 ssop_flags = save_ssop_flags; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 vim_free(mksession_cmdline); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 // Reopen the file and append a command to restore v:this_session, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1133 // as if this save never happened. This is to avoid conflicts with |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 // the user's own sessions. FIXME: It's probably less hackish to add |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 // a "stealth" flag to 'sessionoptions' -- gotta ask Bram. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1136 if (!failed) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 FILE *fd; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 fd = open_exfile(filename, TRUE, APPENDBIN); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 failed = (fd == NULL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1143 || put_line(fd, "let v:this_session = Save_VV_this_session") |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1144 == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 || put_line(fd, "unlet Save_VV_this_session") == FAIL); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1146 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 if (fd != NULL && fclose(fd) != 0) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 failed = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1149 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 if (failed) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 mch_remove(filename); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 return !failed; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 # endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 #endif // FEAT_SESSION |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 #if defined(FEAT_SESSION) && defined(USE_CRNL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 # define MKSESSION_NL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 static int mksession_nl = FALSE; // use NL only in put_eol() |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 * ":mkexrc", ":mkvimrc", ":mkview" and ":mksession". |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 void |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 ex_mkrc(exarg_T *eap) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 FILE *fd; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 int failed = FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 char_u *fname; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 #ifdef FEAT_BROWSE |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 char_u *browseFile = NULL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 #ifdef FEAT_SESSION |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 int view_session = FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 int using_vdir = FALSE; // using 'viewdir'? |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 char_u *viewFile = NULL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 unsigned *flagp; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1183 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 if (eap->cmdidx == CMD_mksession || eap->cmdidx == CMD_mkview) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 #ifdef FEAT_SESSION |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 view_session = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 #else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 ex_ni(eap); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1190 return; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1191 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1193 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 #ifdef FEAT_SESSION |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 // Use the short file name until ":lcd" is used. We also don't use the |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 // short file name when 'acd' is set, that is checked later. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1197 did_lcd = FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 // ":mkview" or ":mkview 9": generate file name with 'viewdir' |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 if (eap->cmdidx == CMD_mkview |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 && (*eap->arg == NUL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 || (vim_isdigit(*eap->arg) && eap->arg[1] == NUL))) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 eap->forceit = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 fname = get_view_file(*eap->arg); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 if (fname == NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 return; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 viewFile = fname; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 using_vdir = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 if (*eap->arg != NUL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 fname = eap->arg; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1215 else if (eap->cmdidx == CMD_mkvimrc) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 fname = (char_u *)VIMRC_FILE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1217 #ifdef FEAT_SESSION |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 else if (eap->cmdidx == CMD_mksession) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1219 fname = (char_u *)SESSION_FILE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1220 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 fname = (char_u *)EXRC_FILE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1224 #ifdef FEAT_BROWSE |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22230
diff
changeset
|
1225 if (cmdmod.cmod_flags & CMOD_BROWSE) |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 browseFile = do_browse(BROWSE_SAVE, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 # ifdef FEAT_SESSION |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 eap->cmdidx == CMD_mkview ? (char_u *)_("Save View") : |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1230 eap->cmdidx == CMD_mksession ? (char_u *)_("Save Session") : |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 # endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 (char_u *)_("Save Setup"), |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 fname, (char_u *)"vim", NULL, |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 (char_u *)_(BROWSE_FILTER_MACROS), NULL); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1235 if (browseFile == NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 goto theend; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 fname = browseFile; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 eap->forceit = TRUE; // since dialog already asked |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 #if defined(FEAT_SESSION) && defined(vim_mkdir) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 // When using 'viewdir' may have to create the directory. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1244 if (using_vdir && !mch_isdir(p_vdir)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1245 vim_mkdir_emsg(p_vdir, 0755); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1246 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1248 fd = open_exfile(fname, eap->forceit, WRITEBIN); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 if (fd != NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 #ifdef FEAT_SESSION |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 if (eap->cmdidx == CMD_mkview) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1253 flagp = &vop_flags; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1254 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 flagp = &ssop_flags; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1257 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1258 #ifdef MKSESSION_NL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1259 // "unix" in 'sessionoptions': use NL line separator |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 if (view_session && (*flagp & SSOP_UNIX)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 mksession_nl = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 // Write the version command for :mkvimrc |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1265 if (eap->cmdidx == CMD_mkvimrc) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 (void)put_line(fd, "version 6.0"); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 #ifdef FEAT_SESSION |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 if (eap->cmdidx == CMD_mksession) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 if (put_line(fd, "let SessionLoad = 1") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1272 failed = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1273 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1274 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1275 if (eap->cmdidx != CMD_mkview) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 // Write setting 'compatible' first, because it has side effects. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 // For that same reason only do it when needed. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1280 if (p_cp) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1281 (void)put_line(fd, "if !&cp | set cp | endif"); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1282 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1283 (void)put_line(fd, "if &cp | set nocp | endif"); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1284 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1285 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1286 #ifdef FEAT_SESSION |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1287 if (!view_session |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 || (eap->cmdidx == CMD_mksession |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1289 && (*flagp & SSOP_OPTIONS))) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 #endif |
24464
a56f9c2ba51c
patch 8.2.2772: problems when restoring 'runtimepath' from a session file
Bram Moolenaar <Bram@vim.org>
parents:
24106
diff
changeset
|
1291 { |
a56f9c2ba51c
patch 8.2.2772: problems when restoring 'runtimepath' from a session file
Bram Moolenaar <Bram@vim.org>
parents:
24106
diff
changeset
|
1292 int flags = OPT_GLOBAL; |
a56f9c2ba51c
patch 8.2.2772: problems when restoring 'runtimepath' from a session file
Bram Moolenaar <Bram@vim.org>
parents:
24106
diff
changeset
|
1293 |
a56f9c2ba51c
patch 8.2.2772: problems when restoring 'runtimepath' from a session file
Bram Moolenaar <Bram@vim.org>
parents:
24106
diff
changeset
|
1294 #ifdef FEAT_SESSION |
a56f9c2ba51c
patch 8.2.2772: problems when restoring 'runtimepath' from a session file
Bram Moolenaar <Bram@vim.org>
parents:
24106
diff
changeset
|
1295 if (eap->cmdidx == CMD_mksession && (*flagp & SSOP_SKIP_RTP)) |
a56f9c2ba51c
patch 8.2.2772: problems when restoring 'runtimepath' from a session file
Bram Moolenaar <Bram@vim.org>
parents:
24106
diff
changeset
|
1296 flags |= OPT_SKIPRTP; |
a56f9c2ba51c
patch 8.2.2772: problems when restoring 'runtimepath' from a session file
Bram Moolenaar <Bram@vim.org>
parents:
24106
diff
changeset
|
1297 #endif |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 failed |= (makemap(fd, NULL) == FAIL |
24464
a56f9c2ba51c
patch 8.2.2772: problems when restoring 'runtimepath' from a session file
Bram Moolenaar <Bram@vim.org>
parents:
24106
diff
changeset
|
1299 || makeset(fd, flags, FALSE) == FAIL); |
a56f9c2ba51c
patch 8.2.2772: problems when restoring 'runtimepath' from a session file
Bram Moolenaar <Bram@vim.org>
parents:
24106
diff
changeset
|
1300 } |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 #ifdef FEAT_SESSION |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1303 if (!failed && view_session) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1304 { |
22776
0583f3e2c12e
patch 8.2.1936: session sets the local 'scrolloff' value to the global value
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1305 if (put_line(fd, "let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1") == FAIL) |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1306 failed = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1307 if (eap->cmdidx == CMD_mksession) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1309 char_u *dirnow; // current directory |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 dirnow = alloc(MAXPATHL); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 if (dirnow == NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 failed = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1314 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1315 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 // Change to session file's dir. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 if (mch_dirname(dirnow, MAXPATHL) == FAIL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1318 || mch_chdir((char *)dirnow) != 0) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1319 *dirnow = NUL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1320 if (*dirnow != NUL && (ssop_flags & SSOP_SESDIR)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1321 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1322 if (vim_chdirfile(fname, NULL) == OK) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1323 shorten_fnames(TRUE); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1325 else if (*dirnow != NUL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 && (ssop_flags & SSOP_CURDIR) && globaldir != NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1328 if (mch_chdir((char *)globaldir) == 0) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 shorten_fnames(TRUE); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1332 failed |= (makeopens(fd, dirnow) == FAIL); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1334 // restore original dir |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1335 if (*dirnow != NUL && ((ssop_flags & SSOP_SESDIR) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1336 || ((ssop_flags & SSOP_CURDIR) && globaldir != NULL))) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1337 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1338 if (mch_chdir((char *)dirnow) != 0) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
1339 emsg(_(e_cannot_go_back_to_previous_directory)); |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1340 shorten_fnames(TRUE); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1341 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1342 vim_free(dirnow); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1343 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1344 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1345 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1346 { |
22230
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
1347 failed |= (put_view(fd, curwin, !using_vdir, flagp, -1, NULL) |
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
1348 == FAIL); |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1349 } |
22776
0583f3e2c12e
patch 8.2.1936: session sets the local 'scrolloff' value to the global value
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1350 if (put_line(fd, "let &g:so = s:so_save | let &g:siso = s:siso_save") |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1351 == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1352 failed = TRUE; |
17539
554240b9574b
patch 8.1.1767: FEAT_SESSION defined separately
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
1353 #ifdef FEAT_SEARCH_EXTRA |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1354 if (no_hlsearch && put_line(fd, "nohlsearch") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1355 failed = TRUE; |
17539
554240b9574b
patch 8.1.1767: FEAT_SESSION defined separately
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
1356 #endif |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1357 if (put_line(fd, "doautoall SessionLoadPost") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1358 failed = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1359 if (eap->cmdidx == CMD_mksession) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1360 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1361 if (put_line(fd, "unlet SessionLoad") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1362 failed = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1363 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1364 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1365 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1366 if (put_line(fd, "\" vim: set ft=vim :") == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1367 failed = TRUE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1369 failed |= fclose(fd); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1370 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1371 if (failed) |
26439
b18f3b0f317c
patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents:
25994
diff
changeset
|
1372 emsg(_(e_error_while_writing)); |
17539
554240b9574b
patch 8.1.1767: FEAT_SESSION defined separately
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
1373 #if defined(FEAT_SESSION) |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 else if (eap->cmdidx == CMD_mksession) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1375 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 // successful session write - set this_session var |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1377 char_u *tbuf; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1378 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 tbuf = alloc(MAXPATHL); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 if (tbuf != NULL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1381 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 if (vim_FullName(fname, tbuf, MAXPATHL, FALSE) == OK) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 set_vim_var_string(VV_THIS_SESSION, tbuf, -1); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1384 vim_free(tbuf); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1385 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1387 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1388 #ifdef MKSESSION_NL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1389 mksession_nl = FALSE; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1393 #ifdef FEAT_BROWSE |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1394 theend: |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 vim_free(browseFile); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 #ifdef FEAT_SESSION |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 vim_free(viewFile); |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 |
17539
554240b9574b
patch 8.1.1767: FEAT_SESSION defined separately
Bram Moolenaar <Bram@vim.org>
parents:
17536
diff
changeset
|
1402 #if (defined(FEAT_VIMINFO) || defined(FEAT_SESSION)) || defined(PROTO) |
17536
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1403 var_flavour_T |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1404 var_flavour(char_u *varname) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 char_u *p = varname; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1408 if (ASCII_ISUPPER(*p)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1410 while (*(++p)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1411 if (ASCII_ISLOWER(*p)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1412 return VAR_FLAVOUR_SESSION; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 return VAR_FLAVOUR_VIMINFO; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 else |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1416 return VAR_FLAVOUR_DEFAULT; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1417 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1418 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1419 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1420 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1421 * Write end-of-line character(s) for ":mkexrc", ":mkvimrc" and ":mksession". |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 * Return FAIL for a write error. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1423 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1424 int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 put_eol(FILE *fd) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 if ( |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 #ifdef USE_CRNL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 ( |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 # ifdef MKSESSION_NL |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1431 !mksession_nl && |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 # endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 (putc('\r', fd) < 0)) || |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 #endif |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 (putc('\n', fd) < 0)) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1436 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 return OK; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 } |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1439 |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 /* |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 * Write a line to "fd". |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1442 * Return FAIL for a write error. |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1443 */ |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1444 int |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 put_line(FILE *fd, char *s) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1446 { |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1447 if (fputs(s, fd) < 0 || put_eol(fd) == FAIL) |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1448 return FAIL; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1449 return OK; |
e00d12c085a5
patch 8.1.1766: code for writing session file is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1450 } |