Mercurial > vim
annotate src/viminfo.c @ 33821:6c92d6f3a255 v9.0.2126
patch 9.0.2126: unused assignments when checking 'listchars'
Commit: https://github.com/vim/vim/commit/00624a2fa08d04bdded240d474e9cfdc193dbe10
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu Nov 23 20:47:16 2023 +0100
patch 9.0.2126: unused assignments when checking 'listchars'
Problem: Unused assignments when checking the value of 'listchars'.
Solution: Loop only once when just checking the value. Add a test to
check that this change doesn't cause double-free.
closes: #13559
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 23 Nov 2023 21:00:04 +0100 |
parents | 7d9d2404a3d4 |
children | 1629cc65d78d |
rev | line source |
---|---|
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
cfdef48743ed
patch 8.1.1727: code for viminfo support 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. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * viminfo.c: viminfo related functions |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 #include "version.h" |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 |
18263
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
17 /* |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
18 * Structure used for reading from the viminfo file. |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
19 */ |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
20 typedef struct |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
21 { |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
22 char_u *vir_line; // text of the current line |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
23 FILE *vir_fd; // file descriptor |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
24 vimconv_T vir_conv; // encoding conversion |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
25 int vir_version; // viminfo version detected or -1 |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
26 garray_T vir_barlines; // lines starting with | |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
27 } vir_T; |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
28 |
19364
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
29 typedef enum { |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
30 BVAL_NR, |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
31 BVAL_STRING, |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
32 BVAL_EMPTY |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
33 } btype_T; |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
34 |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
35 typedef struct { |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
36 btype_T bv_type; |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
37 long bv_nr; |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
38 char_u *bv_string; |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
39 char_u *bv_tofree; // free later when not NULL |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
40 int bv_len; // length of bv_string |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
41 int bv_allocated; // bv_string was allocated |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
42 } bval_T; |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
43 |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 #if defined(FEAT_VIMINFO) || defined(PROTO) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 static int viminfo_errcnt; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 /* |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
49 * Find the parameter represented by the given character (eg ''', ':', '"', or |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
50 * '/') in the 'viminfo' option and return a pointer to the string after it. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
51 * Return NULL if the parameter is not specified in the string. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
52 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
53 static char_u * |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
54 find_viminfo_parameter(int type) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
55 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
56 char_u *p; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
57 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
58 for (p = p_viminfo; *p; ++p) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
59 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
60 if (*p == type) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
61 return p + 1; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
62 if (*p == 'n') // 'n' is always the last one |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
63 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
64 p = vim_strchr(p, ','); // skip until next ',' |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
65 if (p == NULL) // hit the end without finding parameter |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
66 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
67 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
68 return NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
69 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
70 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
71 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
72 * Find the parameter represented by the given character (eg ', :, ", or /), |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
73 * and return its associated value in the 'viminfo' string. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
74 * Only works for number parameters, not for 'r' or 'n'. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
75 * If the parameter is not specified in the string or there is no following |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
76 * number, return -1. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
77 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
78 int |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
79 get_viminfo_parameter(int type) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
80 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
81 char_u *p; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
82 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
83 p = find_viminfo_parameter(type); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
84 if (p != NULL && VIM_ISDIGIT(*p)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
85 return atoi((char *)p); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
86 return -1; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
87 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
88 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
89 /* |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 * Get the viminfo file name to use. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 * If "file" is given and not empty, use it (has already been expanded by |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 * cmdline functions). |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 * Otherwise use "-i file_name", value from 'viminfo' or the default, and |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 * expand environment variables. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 * Returns an allocated string. NULL when out of memory. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 */ |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 static char_u * |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 viminfo_filename(char_u *file) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 if (file == NULL || *file == NUL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 if (*p_viminfofile != NUL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 file = p_viminfofile; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 else if ((file = find_viminfo_parameter('n')) == NULL || *file == NUL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 #ifdef VIMINFO_FILE2 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 # ifdef VMS |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 if (mch_getenv((char_u *)"SYS$LOGIN") == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 # else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 # ifdef MSWIN |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 // Use $VIM only if $HOME is the default "C:/". |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 if (STRCMP(vim_getenv((char_u *)"HOME", NULL), "C:/") == 0 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 && mch_getenv((char_u *)"HOME") == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 # else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 if (mch_getenv((char_u *)"HOME") == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 # endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 # endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 // don't use $VIM when not available. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 expand_env((char_u *)"$VIM", NameBuff, MAXPATHL); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 if (STRCMP("$VIM", NameBuff) != 0) // $VIM was expanded |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 file = (char_u *)VIMINFO_FILE2; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 file = (char_u *)VIMINFO_FILE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 #endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 file = (char_u *)VIMINFO_FILE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 expand_env(file, NameBuff, MAXPATHL); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 file = NameBuff; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 return vim_strsave(file); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
136 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
137 * write string to viminfo file |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
138 * - replace CTRL-V with CTRL-V CTRL-V |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
139 * - replace '\n' with CTRL-V 'n' |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
140 * - add a '\n' at the end |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
141 * |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
142 * For a long line: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
143 * - write " CTRL-V <length> \n " in first line |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
144 * - write " < <string> \n " in second line |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
145 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
146 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
147 viminfo_writestring(FILE *fd, char_u *p) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
148 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
149 int c; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
150 char_u *s; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
151 int len = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
152 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
153 for (s = p; *s != NUL; ++s) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
154 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
155 if (*s == Ctrl_V || *s == '\n') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
156 ++len; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
157 ++len; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
158 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
159 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
160 // If the string will be too long, write its length and put it in the next |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
161 // line. Take into account that some room is needed for what comes before |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
162 // the string (e.g., variable name). Add something to the length for the |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
163 // '<', NL and trailing NUL. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
164 if (len > LSIZE / 2) |
27490
fb4c30606b4a
patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
165 fprintf(fd, "\026%d\n<", len + 3); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
166 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
167 while ((c = *p++) != NUL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
168 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
169 if (c == Ctrl_V || c == '\n') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
170 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
171 putc(Ctrl_V, fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
172 if (c == '\n') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
173 c = 'n'; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
174 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
175 putc(c, fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
176 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
177 putc('\n', fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
178 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
179 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
180 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
181 * Write a string in quotes that barline_parse() can read back. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
182 * Breaks the line in less than LSIZE pieces when needed. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
183 * Returns remaining characters in the line. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
184 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
185 static int |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
186 barline_writestring(FILE *fd, char_u *s, int remaining_start) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
187 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
188 char_u *p; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
189 int remaining = remaining_start; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
190 int len = 2; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
191 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
192 // Count the number of characters produced, including quotes. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
193 for (p = s; *p != NUL; ++p) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
194 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
195 if (*p == NL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
196 len += 2; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
197 else if (*p == '"' || *p == '\\') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
198 len += 2; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
199 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
200 ++len; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
201 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
202 if (len > remaining - 2) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
203 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
204 fprintf(fd, ">%d\n|<", len); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
205 remaining = LSIZE - 20; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
206 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
207 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
208 putc('"', fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
209 for (p = s; *p != NUL; ++p) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
210 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
211 if (*p == NL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
212 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
213 putc('\\', fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
214 putc('n', fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
215 --remaining; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
216 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
217 else if (*p == '"' || *p == '\\') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
218 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
219 putc('\\', fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
220 putc(*p, fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
221 --remaining; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
222 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
223 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
224 putc(*p, fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
225 --remaining; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
226 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
227 if (remaining < 3) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
228 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
229 putc('\n', fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
230 putc('|', fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
231 putc('<', fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
232 // Leave enough space for another continuation. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
233 remaining = LSIZE - 20; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
234 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
235 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
236 putc('"', fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
237 return remaining - 2; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
238 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
239 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
240 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
241 * Check string read from viminfo file. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
242 * Remove '\n' at the end of the line. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
243 * - replace CTRL-V CTRL-V with CTRL-V |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
244 * - replace CTRL-V 'n' with '\n' |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
245 * |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
246 * Check for a long line as written by viminfo_writestring(). |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
247 * |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
248 * Return the string in allocated memory (NULL when out of memory). |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
249 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
250 static char_u * |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
251 viminfo_readstring( |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
252 vir_T *virp, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
253 int off, // offset for virp->vir_line |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
254 int convert UNUSED) // convert the string |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
255 { |
25589
50f8204eb8f7
patch 8.2.3331: Coverity warns for using value without boundary check
Bram Moolenaar <Bram@vim.org>
parents:
25557
diff
changeset
|
256 char_u *retval = NULL; |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
257 char_u *s, *d; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
258 long len; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
259 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
260 if (virp->vir_line[off] == Ctrl_V && vim_isdigit(virp->vir_line[off + 1])) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
261 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
262 len = atol((char *)virp->vir_line + off + 1); |
25589
50f8204eb8f7
patch 8.2.3331: Coverity warns for using value without boundary check
Bram Moolenaar <Bram@vim.org>
parents:
25557
diff
changeset
|
263 if (len > 0 && len < 1000000) |
50f8204eb8f7
patch 8.2.3331: Coverity warns for using value without boundary check
Bram Moolenaar <Bram@vim.org>
parents:
25557
diff
changeset
|
264 retval = lalloc(len, TRUE); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
265 if (retval == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
266 { |
25589
50f8204eb8f7
patch 8.2.3331: Coverity warns for using value without boundary check
Bram Moolenaar <Bram@vim.org>
parents:
25557
diff
changeset
|
267 // Invalid length, line too long, out of memory? Skip next line. |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
268 (void)vim_fgets(virp->vir_line, 10, virp->vir_fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
269 return NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
270 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
271 (void)vim_fgets(retval, (int)len, virp->vir_fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
272 s = retval + 1; // Skip the leading '<' |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
273 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
274 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
275 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
276 retval = vim_strsave(virp->vir_line + off); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
277 if (retval == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
278 return NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
279 s = retval; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
280 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
281 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
282 // Change CTRL-V CTRL-V to CTRL-V and CTRL-V n to \n in-place. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
283 d = retval; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
284 while (*s != NUL && *s != '\n') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
285 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
286 if (s[0] == Ctrl_V && s[1] != NUL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
287 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
288 if (s[1] == 'n') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
289 *d++ = '\n'; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
290 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
291 *d++ = Ctrl_V; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
292 s += 2; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
293 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
294 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
295 *d++ = *s++; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
296 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
297 *d = NUL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
298 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
299 if (convert && virp->vir_conv.vc_type != CONV_NONE && *retval != NUL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
300 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
301 d = string_convert(&virp->vir_conv, retval, NULL); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
302 if (d != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
303 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
304 vim_free(retval); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
305 retval = d; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
306 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
307 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
308 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
309 return retval; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
310 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
311 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
312 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
313 * Read a line from the viminfo file. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
314 * Returns TRUE for end-of-file; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
315 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
316 static int |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
317 viminfo_readline(vir_T *virp) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
318 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
319 return vim_fgets(virp->vir_line, LSIZE, virp->vir_fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
320 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
321 |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 static int |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 read_viminfo_bufferlist( |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 vir_T *virp, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 int writing) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 char_u *tab; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
328 linenr_T lnum; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 colnr_T col; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 buf_T *buf; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 char_u *sfname; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 char_u *xline; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 // Handle long line and escaped characters. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 xline = viminfo_readstring(virp, 1, FALSE); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 // don't read in if there are files on the command-line or if writing: |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 if (xline != NULL && !writing && ARGCOUNT == 0 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 && find_viminfo_parameter('%') != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
340 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 // Format is: <fname> Tab <lnum> Tab <col>. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 // Watch out for a Tab in the file name, work from the end. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 lnum = 0; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
344 col = 0; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 tab = vim_strrchr(xline, '\t'); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 if (tab != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 *tab++ = '\0'; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
349 col = (colnr_T)atoi((char *)tab); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 tab = vim_strrchr(xline, '\t'); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 if (tab != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
352 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 *tab++ = '\0'; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
354 lnum = atol((char *)tab); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
357 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 // Expand "~/" in the file name at "line + 1" to a full path. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 // Then try shortening it by comparing with the current directory |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 expand_env(xline, NameBuff, MAXPATHL); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 sfname = shorten_fname1(NameBuff); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
363 buf = buflist_new(NameBuff, sfname, (linenr_T)0, BLN_LISTED); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 if (buf != NULL) // just in case... |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
365 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 buf->b_last_cursor.lnum = lnum; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 buf->b_last_cursor.col = col; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 buflist_setfpos(buf, curwin, lnum, col, FALSE); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
369 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 vim_free(xline); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 return viminfo_readline(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
376 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
377 * Return TRUE if "name" is on removable media (depending on 'viminfo'). |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
378 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
379 static int |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
380 removable(char_u *name) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
381 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
382 char_u *p; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
383 char_u part[51]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
384 int retval = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
385 size_t n; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
386 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
387 name = home_replace_save(NULL, name); |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
388 if (name == NULL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
389 return FALSE; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
390 for (p = p_viminfo; *p; ) |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
391 { |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
392 copy_option_part(&p, part, 51, ", "); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
393 if (part[0] == 'r') |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
394 { |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
395 n = STRLEN(part + 1); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
396 if (MB_STRNICMP(part + 1, name, n) == 0) |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
397 { |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
398 retval = TRUE; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
399 break; |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
400 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
401 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
402 } |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
403 vim_free(name); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
404 return retval; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
405 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
406 |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 static void |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 write_viminfo_bufferlist(FILE *fp) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 buf_T *buf; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 win_T *win; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 tabpage_T *tp; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 char_u *line; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 int max_buffers; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 if (find_viminfo_parameter('%') == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 return; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 // Without a number -1 is returned: do all buffers. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 max_buffers = get_viminfo_parameter('%'); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 // Allocate room for the file name, lnum and col. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 #define LINE_BUF_LEN (MAXPATHL + 40) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 line = alloc(LINE_BUF_LEN); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 if (line == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 return; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 FOR_ALL_TAB_WINDOWS(tp, win) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 set_last_cursor(win); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 fputs(_("\n# Buffer list:\n"), fp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 FOR_ALL_BUFFERS(buf) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 if (buf->b_fname == NULL |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 || !buf->b_p_bl |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 || bt_quickfix(buf) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 || bt_terminal(buf) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 || removable(buf->b_ffname)) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 continue; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 if (max_buffers-- == 0) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 putc('%', fp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 home_replace(NULL, buf->b_ffname, line, MAXPATHL, TRUE); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 vim_snprintf_add((char *)line, LINE_BUF_LEN, "\t%ld\t%d", |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 (long)buf->b_last_cursor.lnum, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 buf->b_last_cursor.col); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 viminfo_writestring(fp, line); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 vim_free(line); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 |
17460
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
453 /* |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
454 * Buffers for history read from a viminfo file. Only valid while reading. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
455 */ |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
456 static histentry_T *viminfo_history[HIST_COUNT] = |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
457 {NULL, NULL, NULL, NULL, NULL}; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
458 static int viminfo_hisidx[HIST_COUNT] = {0, 0, 0, 0, 0}; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
459 static int viminfo_hislen[HIST_COUNT] = {0, 0, 0, 0, 0}; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
460 static int viminfo_add_at_front = FALSE; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
461 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
462 /* |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
463 * Translate a history type number to the associated character. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
464 */ |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
465 static int |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
466 hist_type2char( |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
467 int type, |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
468 int use_question) // use '?' instead of '/' |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
469 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
470 if (type == HIST_CMD) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
471 return ':'; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
472 if (type == HIST_SEARCH) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
473 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
474 if (use_question) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
475 return '?'; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
476 else |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
477 return '/'; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
478 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
479 if (type == HIST_EXPR) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
480 return '='; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
481 return '@'; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
482 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
483 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
484 /* |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
485 * Prepare for reading the history from the viminfo file. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
486 * This allocates history arrays to store the read history lines. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
487 */ |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
488 static void |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
489 prepare_viminfo_history(int asklen, int writing) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
490 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
491 int i; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
492 int num; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
493 int type; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
494 int len; |
17466
15de78cb9f39
patch 8.1.1731: command line history not read from viminfo on startup
Bram Moolenaar <Bram@vim.org>
parents:
17464
diff
changeset
|
495 int hislen; |
17460
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
496 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
497 init_history(); |
17466
15de78cb9f39
patch 8.1.1731: command line history not read from viminfo on startup
Bram Moolenaar <Bram@vim.org>
parents:
17464
diff
changeset
|
498 hislen = get_hislen(); |
17460
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
499 viminfo_add_at_front = (asklen != 0 && !writing); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
500 if (asklen > hislen) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
501 asklen = hislen; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
502 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
503 for (type = 0; type < HIST_COUNT; ++type) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
504 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
505 histentry_T *histentry = get_histentry(type); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
506 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
507 // Count the number of empty spaces in the history list. Entries read |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
508 // from viminfo previously are also considered empty. If there are |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
509 // more spaces available than we request, then fill them up. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
510 for (i = 0, num = 0; i < hislen; i++) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
511 if (histentry[i].hisstr == NULL || histentry[i].viminfo) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
512 num++; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
513 len = asklen; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
514 if (num > len) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
515 len = num; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
516 if (len <= 0) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
517 viminfo_history[type] = NULL; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
518 else |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
519 viminfo_history[type] = LALLOC_MULT(histentry_T, len); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
520 if (viminfo_history[type] == NULL) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
521 len = 0; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
522 viminfo_hislen[type] = len; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
523 viminfo_hisidx[type] = 0; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
524 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
525 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
526 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
527 /* |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
528 * Accept a line from the viminfo, store it in the history array when it's |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
529 * new. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
530 */ |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
531 static int |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
532 read_viminfo_history(vir_T *virp, int writing) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
533 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
534 int type; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
535 long_u len; |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
536 char_u *val = NULL; |
17460
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
537 char_u *p; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
538 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
539 type = hist_char2type(virp->vir_line[0]); |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
540 if (viminfo_hisidx[type] >= viminfo_hislen[type]) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
541 goto done; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
542 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
543 val = viminfo_readstring(virp, 1, TRUE); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
544 if (val == NULL || *val == NUL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
545 goto done; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
546 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
547 int sep = (*val == ' ' ? NUL : *val); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
548 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
549 if (in_history(type, val + (type == HIST_SEARCH), viminfo_add_at_front, |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
550 sep, writing)) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
551 goto done; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
552 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
553 // Need to re-allocate to append the separator byte. |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
554 len = STRLEN(val); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
555 p = alloc(len + 2); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
556 if (p == NULL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
557 goto done; |
17460
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
558 |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
559 if (type == HIST_SEARCH) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
560 { |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
561 // Search entry: Move the separator from the first |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
562 // column to after the NUL. |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
563 mch_memmove(p, val + 1, (size_t)len); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
564 p[len] = sep; |
17460
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
565 } |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
566 else |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
567 { |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
568 // Not a search entry: No separator in the viminfo |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
569 // file, add a NUL separator. |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
570 mch_memmove(p, val, (size_t)len + 1); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
571 p[len + 1] = NUL; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
572 } |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
573 viminfo_history[type][viminfo_hisidx[type]].hisstr = p; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
574 viminfo_history[type][viminfo_hisidx[type]].time_set = 0; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
575 viminfo_history[type][viminfo_hisidx[type]].viminfo = TRUE; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
576 viminfo_history[type][viminfo_hisidx[type]].hisnum = 0; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
577 viminfo_hisidx[type]++; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
578 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
579 done: |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
580 vim_free(val); |
17460
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
581 return viminfo_readline(virp); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
582 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
583 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
584 /* |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
585 * Accept a new style history line from the viminfo, store it in the history |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
586 * array when it's new. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
587 */ |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
588 static void |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
589 handle_viminfo_history( |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
590 garray_T *values, |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
591 int writing) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
592 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
593 int type; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
594 long_u len; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
595 char_u *val; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
596 char_u *p; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
597 bval_T *vp = (bval_T *)values->ga_data; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
598 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
599 // Check the format: |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
600 // |{bartype},{histtype},{timestamp},{separator},"text" |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
601 if (values->ga_len < 4 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
602 || vp[0].bv_type != BVAL_NR |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
603 || vp[1].bv_type != BVAL_NR |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
604 || (vp[2].bv_type != BVAL_NR && vp[2].bv_type != BVAL_EMPTY) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
605 || vp[3].bv_type != BVAL_STRING) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
606 return; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
607 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
608 type = vp[0].bv_nr; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
609 if (type >= HIST_COUNT) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
610 return; |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
611 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
612 if (viminfo_hisidx[type] >= viminfo_hislen[type]) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
613 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
614 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
615 val = vp[3].bv_string; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
616 if (val == NULL || *val == NUL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
617 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
618 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
619 int sep = type == HIST_SEARCH && vp[2].bv_type == BVAL_NR |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
620 ? vp[2].bv_nr : NUL; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
621 int idx; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
622 int overwrite = FALSE; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
623 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
624 if (in_history(type, val, viminfo_add_at_front, sep, writing)) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
625 return; |
17460
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
626 |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
627 // If lines were written by an older Vim we need to avoid |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
628 // getting duplicates. See if the entry already exists. |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
629 for (idx = 0; idx < viminfo_hisidx[type]; ++idx) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
630 { |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
631 p = viminfo_history[type][idx].hisstr; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
632 if (STRCMP(val, p) == 0 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
633 && (type != HIST_SEARCH || sep == p[STRLEN(p) + 1])) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
634 { |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
635 overwrite = TRUE; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
636 break; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
637 } |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
638 } |
17460
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
639 |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
640 if (!overwrite) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
641 { |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
642 // Need to re-allocate to append the separator byte. |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
643 len = vp[3].bv_len; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
644 p = alloc(len + 2); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
645 } |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
646 else |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
647 len = 0; // for picky compilers |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
648 if (p != NULL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
649 { |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
650 viminfo_history[type][idx].time_set = vp[1].bv_nr; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
651 if (!overwrite) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
652 { |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
653 mch_memmove(p, val, (size_t)len + 1); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
654 // Put the separator after the NUL. |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
655 p[len + 1] = sep; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
656 viminfo_history[type][idx].hisstr = p; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
657 viminfo_history[type][idx].hisnum = 0; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
658 viminfo_history[type][idx].viminfo = TRUE; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
659 viminfo_hisidx[type]++; |
17460
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
660 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
661 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
662 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
663 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
664 /* |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
665 * Concatenate history lines from viminfo after the lines typed in this Vim. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
666 */ |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
667 static void |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
668 concat_history(int type) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
669 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
670 int idx; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
671 int i; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
672 int hislen = get_hislen(); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
673 histentry_T *histentry = get_histentry(type); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
674 int *hisidx = get_hisidx(type); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
675 int *hisnum = get_hisnum(type); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
676 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
677 idx = *hisidx + viminfo_hisidx[type]; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
678 if (idx >= hislen) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
679 idx -= hislen; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
680 else if (idx < 0) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
681 idx = hislen - 1; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
682 if (viminfo_add_at_front) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
683 *hisidx = idx; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
684 else |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
685 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
686 if (*hisidx == -1) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
687 *hisidx = hislen - 1; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
688 do |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
689 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
690 if (histentry[idx].hisstr != NULL || histentry[idx].viminfo) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
691 break; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
692 if (++idx == hislen) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
693 idx = 0; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
694 } while (idx != *hisidx); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
695 if (idx != *hisidx && --idx < 0) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
696 idx = hislen - 1; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
697 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
698 for (i = 0; i < viminfo_hisidx[type]; i++) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
699 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
700 vim_free(histentry[idx].hisstr); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
701 histentry[idx].hisstr = viminfo_history[type][i].hisstr; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
702 histentry[idx].viminfo = TRUE; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
703 histentry[idx].time_set = viminfo_history[type][i].time_set; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
704 if (--idx < 0) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
705 idx = hislen - 1; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
706 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
707 idx += 1; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
708 idx %= hislen; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
709 for (i = 0; i < viminfo_hisidx[type]; i++) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
710 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
711 histentry[idx++].hisnum = ++*hisnum; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
712 idx %= hislen; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
713 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
714 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
715 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
716 static int |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
717 sort_hist(const void *s1, const void *s2) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
718 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
719 histentry_T *p1 = *(histentry_T **)s1; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
720 histentry_T *p2 = *(histentry_T **)s2; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
721 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
722 if (p1->time_set < p2->time_set) return -1; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
723 if (p1->time_set > p2->time_set) return 1; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
724 return 0; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
725 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
726 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
727 /* |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
728 * Merge history lines from viminfo and lines typed in this Vim based on the |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
729 * timestamp; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
730 */ |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
731 static void |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
732 merge_history(int type) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
733 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
734 int max_len; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
735 histentry_T **tot_hist; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
736 histentry_T *new_hist; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
737 int i; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
738 int len; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
739 int hislen = get_hislen(); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
740 histentry_T *histentry = get_histentry(type); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
741 int *hisidx = get_hisidx(type); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
742 int *hisnum = get_hisnum(type); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
743 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
744 // Make one long list with all entries. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
745 max_len = hislen + viminfo_hisidx[type]; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
746 tot_hist = ALLOC_MULT(histentry_T *, max_len); |
17466
15de78cb9f39
patch 8.1.1731: command line history not read from viminfo on startup
Bram Moolenaar <Bram@vim.org>
parents:
17464
diff
changeset
|
747 new_hist = ALLOC_MULT(histentry_T, hislen); |
17460
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
748 if (tot_hist == NULL || new_hist == NULL) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
749 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
750 vim_free(tot_hist); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
751 vim_free(new_hist); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
752 return; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
753 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
754 for (i = 0; i < viminfo_hisidx[type]; i++) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
755 tot_hist[i] = &viminfo_history[type][i]; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
756 len = i; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
757 for (i = 0; i < hislen; i++) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
758 if (histentry[i].hisstr != NULL) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
759 tot_hist[len++] = &histentry[i]; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
760 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
761 // Sort the list on timestamp. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
762 qsort((void *)tot_hist, (size_t)len, sizeof(histentry_T *), sort_hist); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
763 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
764 // Keep the newest ones. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
765 for (i = 0; i < hislen; i++) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
766 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
767 if (i < len) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
768 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
769 new_hist[i] = *tot_hist[i]; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
770 tot_hist[i]->hisstr = NULL; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
771 if (new_hist[i].hisnum == 0) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
772 new_hist[i].hisnum = ++*hisnum; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
773 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
774 else |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
775 clear_hist_entry(&new_hist[i]); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
776 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
777 *hisidx = (i < len ? i : len) - 1; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
778 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
779 // Free what is not kept. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
780 for (i = 0; i < viminfo_hisidx[type]; i++) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
781 vim_free(viminfo_history[type][i].hisstr); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
782 for (i = 0; i < hislen; i++) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
783 vim_free(histentry[i].hisstr); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
784 vim_free(histentry); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
785 set_histentry(type, new_hist); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
786 vim_free(tot_hist); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
787 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
788 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
789 /* |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
790 * Finish reading history lines from viminfo. Not used when writing viminfo. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
791 */ |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
792 static void |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
793 finish_viminfo_history(vir_T *virp) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
794 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
795 int type; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
796 int merge = virp->vir_version >= VIMINFO_VERSION_WITH_HISTORY; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
797 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
798 for (type = 0; type < HIST_COUNT; ++type) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
799 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
800 if (get_histentry(type) == NULL) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
801 continue; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
802 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
803 if (merge) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
804 merge_history(type); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
805 else |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
806 concat_history(type); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
807 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
808 VIM_CLEAR(viminfo_history[type]); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
809 viminfo_hisidx[type] = 0; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
810 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
811 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
812 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
813 /* |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
814 * Write history to viminfo file in "fp". |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
815 * When "merge" is TRUE merge history lines with a previously read viminfo |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
816 * file, data is in viminfo_history[]. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
817 * When "merge" is FALSE just write all history lines. Used for ":wviminfo!". |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
818 */ |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
819 static void |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
820 write_viminfo_history(FILE *fp, int merge) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
821 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
822 int i; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
823 int type; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
824 int num_saved; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
825 int round; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
826 int hislen; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
827 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
828 init_history(); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
829 hislen = get_hislen(); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
830 if (hislen == 0) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
831 return; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
832 for (type = 0; type < HIST_COUNT; ++type) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
833 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
834 histentry_T *histentry = get_histentry(type); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
835 int *hisidx = get_hisidx(type); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
836 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
837 num_saved = get_viminfo_parameter(hist_type2char(type, FALSE)); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
838 if (num_saved == 0) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
839 continue; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
840 if (num_saved < 0) // Use default |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
841 num_saved = hislen; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
842 fprintf(fp, _("\n# %s History (newest to oldest):\n"), |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
843 type == HIST_CMD ? _("Command Line") : |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
844 type == HIST_SEARCH ? _("Search String") : |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
845 type == HIST_EXPR ? _("Expression") : |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
846 type == HIST_INPUT ? _("Input Line") : |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
847 _("Debug Line")); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
848 if (num_saved > hislen) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
849 num_saved = hislen; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
850 |
18263
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
851 // Merge typed and viminfo history: |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
852 // round 1: history of typed commands. |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
853 // round 2: history from recently read viminfo. |
17460
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
854 for (round = 1; round <= 2; ++round) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
855 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
856 if (round == 1) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
857 // start at newest entry, somewhere in the list |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
858 i = *hisidx; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
859 else if (viminfo_hisidx[type] > 0) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
860 // start at newest entry, first in the list |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
861 i = 0; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
862 else |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
863 // empty list |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
864 i = -1; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
865 if (i >= 0) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
866 while (num_saved > 0 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
867 && !(round == 2 && i >= viminfo_hisidx[type])) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
868 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
869 char_u *p; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
870 time_t timestamp; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
871 int c = NUL; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
872 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
873 if (round == 1) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
874 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
875 p = histentry[i].hisstr; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
876 timestamp = histentry[i].time_set; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
877 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
878 else |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
879 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
880 p = viminfo_history[type] == NULL ? NULL |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
881 : viminfo_history[type][i].hisstr; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
882 timestamp = viminfo_history[type] == NULL ? 0 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
883 : viminfo_history[type][i].time_set; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
884 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
885 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
886 if (p != NULL && (round == 2 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
887 || !merge |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
888 || !histentry[i].viminfo)) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
889 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
890 --num_saved; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
891 fputc(hist_type2char(type, TRUE), fp); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
892 // For the search history: put the separator in the |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
893 // second column; use a space if there isn't one. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
894 if (type == HIST_SEARCH) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
895 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
896 c = p[STRLEN(p) + 1]; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
897 putc(c == NUL ? ' ' : c, fp); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
898 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
899 viminfo_writestring(fp, p); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
900 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
901 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
902 char cbuf[NUMBUFLEN]; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
903 |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
904 // New style history with a bar line. Format: |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
905 // |{bartype},{histtype},{timestamp},{separator},"text" |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
906 if (c == NUL) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
907 cbuf[0] = NUL; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
908 else |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
909 sprintf(cbuf, "%d", c); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
910 fprintf(fp, "|%d,%d,%ld,%s,", BARTYPE_HISTORY, |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
911 type, (long)timestamp, cbuf); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
912 barline_writestring(fp, p, LSIZE - 20); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
913 putc('\n', fp); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
914 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
915 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
916 if (round == 1) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
917 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
918 // Decrement index, loop around and stop when back at |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
919 // the start. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
920 if (--i < 0) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
921 i = hislen - 1; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
922 if (i == *hisidx) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
923 break; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
924 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
925 else |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
926 { |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
927 // Increment index. Stop at the end in the while. |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
928 ++i; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
929 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
930 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
931 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
932 for (i = 0; i < viminfo_hisidx[type]; ++i) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
933 if (viminfo_history[type] != NULL) |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
934 vim_free(viminfo_history[type][i].hisstr); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
935 VIM_CLEAR(viminfo_history[type]); |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
936 viminfo_hisidx[type] = 0; |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
937 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
938 } |
e43f0c0c491c
patch 8.1.1728: wrong place for command line history viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
17458
diff
changeset
|
939 |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 static void |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 write_viminfo_barlines(vir_T *virp, FILE *fp_out) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 int i; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 garray_T *gap = &virp->vir_barlines; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 int seen_useful = FALSE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 char *line; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
948 if (gap->ga_len <= 0) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
949 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
950 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
951 fputs(_("\n# Bar lines, copied verbatim:\n"), fp_out); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
952 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
953 // Skip over continuation lines until seeing a useful line. |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
954 for (i = 0; i < gap->ga_len; ++i) |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
955 { |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
956 line = ((char **)(gap->ga_data))[i]; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
957 if (seen_useful || line[1] != '<') |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
958 { |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
959 fputs(line, fp_out); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
960 seen_useful = TRUE; |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 /* |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 * Parse a viminfo line starting with '|'. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 * Add each decoded value to "values". |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 * Returns TRUE if the next line is to be read after using the parsed values. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 */ |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 static int |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 barline_parse(vir_T *virp, char_u *text, garray_T *values) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 char_u *p = text; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 char_u *nextp = NULL; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 char_u *buf = NULL; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 bval_T *value; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 int i; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 int allocated = FALSE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 int eof; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 char_u *sconv; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 int converted; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 while (*p == ',') |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 ++p; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 if (ga_grow(values, 1) == FAIL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 value = (bval_T *)(values->ga_data) + values->ga_len; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 if (*p == '>') |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 // Need to read a continuation line. Put strings in allocated |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 // memory, because virp->vir_line is overwritten. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 if (!allocated) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 for (i = 0; i < values->ga_len; ++i) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 bval_T *vp = (bval_T *)(values->ga_data) + i; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 if (vp->bv_type == BVAL_STRING && !vp->bv_allocated) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 vp->bv_string = vim_strnsave(vp->bv_string, vp->bv_len); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 vp->bv_allocated = TRUE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 allocated = TRUE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 if (vim_isdigit(p[1])) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 size_t len; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 size_t todo; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 size_t n; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 // String value was split into lines that are each shorter |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 // than LSIZE: |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 // |{bartype},>{length of "{text}{text2}"} |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 // |<"{text1} |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 // |<{text2}",{value} |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 // Length includes the quotes. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 ++p; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 len = getdigits(&p); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 buf = alloc((int)(len + 1)); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 if (buf == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 return TRUE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 p = buf; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 for (todo = len; todo > 0; todo -= n) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 eof = viminfo_readline(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 if (eof || virp->vir_line[0] != '|' |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 || virp->vir_line[1] != '<') |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 // File was truncated or garbled. Read another line if |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 // this one starts with '|'. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 vim_free(buf); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 return eof || virp->vir_line[0] == '|'; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 // Get length of text, excluding |< and NL chars. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 n = STRLEN(virp->vir_line); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 while (n > 0 && (virp->vir_line[n - 1] == NL |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 || virp->vir_line[n - 1] == CAR)) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 --n; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 n -= 2; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 if (n > todo) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 // more values follow after the string |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 nextp = virp->vir_line + 2 + todo; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 n = todo; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 mch_memmove(p, virp->vir_line + 2, n); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 p += n; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 *p = NUL; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 p = buf; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 // Line ending in ">" continues in the next line: |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 // |{bartype},{lots of values},> |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 // |<{value},{value} |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 eof = viminfo_readline(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 if (eof || virp->vir_line[0] != '|' |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 || virp->vir_line[1] != '<') |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 // File was truncated or garbled. Read another line if |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 // this one starts with '|'. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 return eof || virp->vir_line[0] == '|'; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 p = virp->vir_line + 2; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 if (isdigit(*p)) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 value->bv_type = BVAL_NR; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 value->bv_nr = getdigits(&p); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 ++values->ga_len; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 else if (*p == '"') |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 int len = 0; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 char_u *s = p; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 // Unescape special characters in-place. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 ++p; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 while (*p != '"') |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 if (*p == NL || *p == NUL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 return TRUE; // syntax error, drop the value |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1088 if (*p == '\\') |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 ++p; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 if (*p == 'n') |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 s[len++] = '\n'; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 s[len++] = *p; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 ++p; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 s[len++] = *p++; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 ++p; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 s[len] = NUL; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 converted = FALSE; |
19364
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1104 value->bv_tofree = NULL; |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 if (virp->vir_conv.vc_type != CONV_NONE && *s != NUL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 sconv = string_convert(&virp->vir_conv, s, NULL); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 if (sconv != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 if (s == buf) |
19364
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1111 // the converted string is stored in bv_string and |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1112 // freed later, also need to free "buf" later |
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1113 value->bv_tofree = buf; |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 s = sconv; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 converted = TRUE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 // Need to copy in allocated memory if the string wasn't allocated |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 // above and we did allocate before, thus vir_line may change. |
19364
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1121 if (s != buf && allocated && !converted) |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 s = vim_strsave(s); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 value->bv_string = s; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 value->bv_type = BVAL_STRING; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 value->bv_len = len; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 value->bv_allocated = allocated || converted; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 ++values->ga_len; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 if (nextp != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 // values following a long string |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 p = nextp; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 nextp = NULL; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1133 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 else if (*p == ',') |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1136 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 value->bv_type = BVAL_EMPTY; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 ++values->ga_len; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1143 return TRUE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1144 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1146 static void |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 write_viminfo_version(FILE *fp_out) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1149 fprintf(fp_out, "# Viminfo version\n|%d,%d\n\n", |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 BARTYPE_VERSION, VIMINFO_VERSION); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 static int |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 no_viminfo(void) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 // "vim -i NONE" does not read or write a viminfo file |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 return STRCMP(p_viminfofile, "NONE") == 0; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 /* |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 * Report an error for reading a viminfo file. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 * Count the number of errors. When there are more than 10, return TRUE. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 */ |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1164 static int |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 viminfo_error(char *errnum, char *message, char_u *line) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 vim_snprintf((char *)IObuff, IOSIZE, _("%sviminfo: %s in line: "), |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 errnum, message); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 STRNCAT(IObuff, line, IOSIZE - STRLEN(IObuff) - 1); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 if (IObuff[STRLEN(IObuff) - 1] == '\n') |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 IObuff[STRLEN(IObuff) - 1] = NUL; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 emsg((char *)IObuff); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 if (++viminfo_errcnt >= 10) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26532
diff
changeset
|
1175 emsg(_(e_viminfo_too_many_errors_skipping_rest_of_file)); |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 return TRUE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 return FALSE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 /* |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 * Compare the 'encoding' value in the viminfo file with the current value of |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1183 * 'encoding'. If different and the 'c' flag is in 'viminfo', setup for |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 * conversion of text with iconv() in viminfo_readstring(). |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 */ |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 static int |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 viminfo_encoding(vir_T *virp) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 char_u *p; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1190 int i; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1191 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 if (get_viminfo_parameter('c') != 0) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1193 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 p = vim_strchr(virp->vir_line, '='); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 if (p != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1197 // remove trailing newline |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 ++p; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 for (i = 0; vim_isprintc(p[i]); ++i) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 ; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 p[i] = NUL; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 convert_setup(&virp->vir_conv, p, p_enc); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 return viminfo_readline(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 #if defined(FEAT_EVAL) || defined(PROTO) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 /* |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 * Restore global vars that start with a capital from the viminfo file |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 */ |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 static int |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 read_viminfo_varlist(vir_T *virp, int writing) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1215 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 char_u *tab; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1217 int type = VAR_NUMBER; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 typval_T tv; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1219 funccal_entry_T funccal_entry; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1220 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 if (!writing && (find_viminfo_parameter('!') != NULL)) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 tab = vim_strchr(virp->vir_line + 1, '\t'); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1224 if (tab != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1225 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 *tab++ = '\0'; // isolate the variable name |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 switch (*tab) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 case 'S': type = VAR_STRING; break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1230 case 'F': type = VAR_FLOAT; break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 case 'D': type = VAR_DICT; break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 case 'L': type = VAR_LIST; break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 case 'B': type = VAR_BLOB; break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 case 'X': type = VAR_SPECIAL; break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1235 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 tab = vim_strchr(tab, '\t'); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 if (tab != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 tv.v_type = type; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 if (type == VAR_STRING || type == VAR_DICT |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 || type == VAR_LIST || type == VAR_BLOB) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 tv.vval.v_string = viminfo_readstring(virp, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1244 (int)(tab - virp->vir_line + 1), TRUE); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1245 else if (type == VAR_FLOAT) |
25557
763ea8f075db
patch 8.2.3315: cannot use single quote in a float number for readability
Bram Moolenaar <Bram@vim.org>
parents:
24606
diff
changeset
|
1246 (void)string2float(tab + 1, &tv.vval.v_float, FALSE); |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 else |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1248 { |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 tv.vval.v_number = atol((char *)tab + 1); |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1250 if (type == VAR_SPECIAL && (tv.vval.v_number == VVAL_FALSE |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1251 || tv.vval.v_number == VVAL_TRUE)) |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1252 tv.v_type = VAR_BOOL; |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1253 } |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1254 if (type == VAR_DICT || type == VAR_LIST) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 typval_T *etv = eval_expr(tv.vval.v_string, NULL); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1257 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1258 if (etv == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1259 // Failed to parse back the dict or list, use it as a |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 // string. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 tv.v_type = VAR_STRING; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 vim_free(tv.vval.v_string); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1265 tv = *etv; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 vim_free(etv); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 else if (type == VAR_BLOB) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 blob_T *blob = string2blob(tv.vval.v_string); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1272 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1273 if (blob == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1274 // Failed to parse back the blob, use it as a string. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1275 tv.v_type = VAR_STRING; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 vim_free(tv.vval.v_string); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 tv.v_type = VAR_BLOB; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1280 tv.vval.v_blob = blob; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1281 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1282 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1283 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1284 // when in a function use global variables |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1285 save_funccal(&funccal_entry); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1286 set_var(virp->vir_line + 1, &tv, FALSE); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1287 restore_funccal(); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1289 if (tv.v_type == VAR_STRING) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 vim_free(tv.vval.v_string); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1291 else if (tv.v_type == VAR_DICT || tv.v_type == VAR_LIST || |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 tv.v_type == VAR_BLOB) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1293 clear_tv(&tv); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1295 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1296 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1297 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 return viminfo_readline(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1299 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1300 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 /* |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 * Write global vars that start with a capital to the viminfo file |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1303 */ |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1304 static void |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1305 write_viminfo_varlist(FILE *fp) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1306 { |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
1307 hashtab_T *gvht = get_globvar_ht(); |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 hashitem_T *hi; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1309 dictitem_T *this_var; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 int todo; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 char *s = ""; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 char_u *p; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 char_u *tofree; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1314 char_u numbuf[NUMBUFLEN]; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1315 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 if (find_viminfo_parameter('!') == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 return; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1318 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1319 fputs(_("\n# global variables:\n"), fp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1320 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
1321 todo = (int)gvht->ht_used; |
32118
04d9dff67d99
patch 9.0.1390: FOR_ALL_ macros are defined in an unexpected file
Bram Moolenaar <Bram@vim.org>
parents:
31827
diff
changeset
|
1322 FOR_ALL_HASHTAB_ITEMS(gvht, hi, todo) |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1323 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 if (!HASHITEM_EMPTY(hi)) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1325 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 --todo; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 this_var = HI2DI(hi); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1328 if (var_flavour(this_var->di_key) == VAR_FLAVOUR_VIMINFO) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 switch (this_var->di_tv.v_type) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 { |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1332 case VAR_STRING: s = "STR"; break; |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1333 case VAR_NUMBER: s = "NUM"; break; |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1334 case VAR_FLOAT: s = "FLO"; break; |
20735
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1335 case VAR_DICT: |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1336 { |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1337 dict_T *di = this_var->di_tv.vval.v_dict; |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1338 int copyID = get_copyID(); |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1339 |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1340 s = "DIC"; |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1341 if (di != NULL && !set_ref_in_ht( |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1342 &di->dv_hashtab, copyID, NULL) |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1343 && di->dv_copyID == copyID) |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1344 // has a circular reference, can't turn the |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1345 // value into a string |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1346 continue; |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1347 break; |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1348 } |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1349 case VAR_LIST: |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1350 { |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1351 list_T *l = this_var->di_tv.vval.v_list; |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1352 int copyID = get_copyID(); |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1353 |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1354 s = "LIS"; |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1355 if (l != NULL && !set_ref_in_list_items( |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1356 l, copyID, NULL) |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1357 && l->lv_copyID == copyID) |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1358 // has a circular reference, can't turn the |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1359 // value into a string |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1360 continue; |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1361 break; |
298ef749e5fb
patch 8.2.0920: writing viminfo fails with a circular reference
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
1362 } |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1363 case VAR_BLOB: s = "BLO"; break; |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1364 case VAR_BOOL: s = "XPL"; break; // backwards compat. |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1365 case VAR_SPECIAL: s = "XPL"; break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1366 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1367 case VAR_UNKNOWN: |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19760
diff
changeset
|
1368 case VAR_ANY: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
1369 case VAR_VOID: |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1370 case VAR_FUNC: |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1371 case VAR_PARTIAL: |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 case VAR_JOB: |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 case VAR_CHANNEL: |
24606
a4fda40e0bb9
patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
23903
diff
changeset
|
1374 case VAR_INSTR: |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1375 case VAR_CLASS: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
1376 case VAR_OBJECT: |
33678
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33006
diff
changeset
|
1377 case VAR_TYPEALIAS: |
7d9d2404a3d4
patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents:
33006
diff
changeset
|
1378 continue; |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 fprintf(fp, "!%s\t%s\t", this_var->di_key, s); |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1381 if (this_var->di_tv.v_type == VAR_BOOL |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1382 || this_var->di_tv.v_type == VAR_SPECIAL) |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 { |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1384 // do not use "v:true" but "1" |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1385 sprintf((char *)numbuf, "%ld", |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 (long)this_var->di_tv.vval.v_number); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1387 p = numbuf; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1388 tofree = NULL; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1389 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 p = echo_string(&this_var->di_tv, &tofree, numbuf, 0); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 if (p != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1393 viminfo_writestring(fp, p); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1394 vim_free(tofree); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 #endif // FEAT_EVAL |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1401 static int |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1402 read_viminfo_sub_string(vir_T *virp, int force) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1403 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1404 if (force || get_old_sub() == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1405 set_old_sub(viminfo_readstring(virp, 1, TRUE)); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1406 return viminfo_readline(virp); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1407 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1408 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1409 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1410 write_viminfo_sub_string(FILE *fp) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1411 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1412 char_u *old_sub = get_old_sub(); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1413 |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1414 if (get_viminfo_parameter('/') == 0 || old_sub == NULL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1415 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1416 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1417 fputs(_("\n# Last Substitute String:\n$"), fp); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1418 viminfo_writestring(fp, old_sub); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1419 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1420 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1421 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1422 * Functions relating to reading/writing the search pattern from viminfo |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1423 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1424 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1425 static int |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1426 read_viminfo_search_pattern(vir_T *virp, int force) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1427 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1428 char_u *lp; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1429 int idx = -1; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1430 int magic = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1431 int no_scs = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1432 int off_line = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1433 int off_end = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1434 long off = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1435 int setlast = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1436 #ifdef FEAT_SEARCH_EXTRA |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1437 static int hlsearch_on = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1438 #endif |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1439 char_u *val; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1440 spat_T *spat; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1441 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1442 // Old line types: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1443 // "/pat", "&pat": search/subst. pat |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1444 // "~/pat", "~&pat": last used search/subst. pat |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1445 // New line types: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1446 // "~h", "~H": hlsearch highlighting off/on |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1447 // "~<magic><smartcase><line><end><off><last><which>pat" |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1448 // <magic>: 'm' off, 'M' on |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1449 // <smartcase>: 's' off, 'S' on |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1450 // <line>: 'L' line offset, 'l' char offset |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1451 // <end>: 'E' from end, 'e' from start |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1452 // <off>: decimal, offset |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1453 // <last>: '~' last used pattern |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1454 // <which>: '/' search pat, '&' subst. pat |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1455 lp = virp->vir_line; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1456 if (lp[0] == '~' && (lp[1] == 'm' || lp[1] == 'M')) // new line type |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1457 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1458 if (lp[1] == 'M') // magic on |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1459 magic = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1460 if (lp[2] == 's') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1461 no_scs = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1462 if (lp[3] == 'L') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1463 off_line = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1464 if (lp[4] == 'E') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1465 off_end = SEARCH_END; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1466 lp += 5; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1467 off = getdigits(&lp); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1468 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1469 if (lp[0] == '~') // use this pattern for last-used pattern |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1470 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1471 setlast = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1472 lp++; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1473 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1474 if (lp[0] == '/') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1475 idx = RE_SEARCH; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1476 else if (lp[0] == '&') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1477 idx = RE_SUBST; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1478 #ifdef FEAT_SEARCH_EXTRA |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1479 else if (lp[0] == 'h') // ~h: 'hlsearch' highlighting off |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1480 hlsearch_on = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1481 else if (lp[0] == 'H') // ~H: 'hlsearch' highlighting on |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1482 hlsearch_on = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1483 #endif |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1484 if (idx >= 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1485 { |
17502
bc6088919610
patch 8.1.1749: Coverity warns for using negative index
Bram Moolenaar <Bram@vim.org>
parents:
17476
diff
changeset
|
1486 spat = get_spat(idx); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1487 if (force || spat->pat == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1488 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1489 val = viminfo_readstring(virp, (int)(lp - virp->vir_line + 1), |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1490 TRUE); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1491 if (val != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1492 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1493 set_last_search_pat(val, idx, magic, setlast); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1494 vim_free(val); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1495 spat->no_scs = no_scs; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1496 spat->off.line = off_line; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1497 spat->off.end = off_end; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1498 spat->off.off = off; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1499 #ifdef FEAT_SEARCH_EXTRA |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1500 if (setlast) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1501 set_no_hlsearch(!hlsearch_on); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1502 #endif |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1503 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1504 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1505 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1506 return viminfo_readline(virp); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1507 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1508 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1509 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1510 wvsp_one( |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1511 FILE *fp, // file to write to |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1512 int idx, // spats[] index |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1513 char *s, // search pat |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1514 int sc) // dir char |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1515 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1516 spat_T *spat = get_spat(idx); |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1517 if (spat->pat == NULL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1518 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1519 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1520 fprintf(fp, _("\n# Last %sSearch Pattern:\n~"), s); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1521 // off.dir is not stored, it's reset to forward |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1522 fprintf(fp, "%c%c%c%c%ld%s%c", |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1523 spat->magic ? 'M' : 'm', // magic |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1524 spat->no_scs ? 's' : 'S', // smartcase |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1525 spat->off.line ? 'L' : 'l', // line offset |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1526 spat->off.end ? 'E' : 'e', // offset from end |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1527 spat->off.off, // offset |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1528 get_spat_last_idx() == idx ? "~" : "", // last used pat |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1529 sc); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1530 viminfo_writestring(fp, spat->pat); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1531 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1532 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1533 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1534 write_viminfo_search_pattern(FILE *fp) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1535 { |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1536 if (get_viminfo_parameter('/') == 0) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1537 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1538 |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1539 #ifdef FEAT_SEARCH_EXTRA |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1540 fprintf(fp, "\n# hlsearch on (H) or off (h):\n~%c", |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1541 (no_hlsearch || find_viminfo_parameter('h') != NULL) ? 'h' : 'H'); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1542 #endif |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1543 wvsp_one(fp, RE_SEARCH, "", '/'); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1544 wvsp_one(fp, RE_SUBST, _("Substitute "), '&'); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1545 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1546 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1547 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1548 * Functions relating to reading/writing registers from viminfo |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1549 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1550 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1551 static yankreg_T *y_read_regs = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1552 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1553 #define REG_PREVIOUS 1 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1554 #define REG_EXEC 2 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1555 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1556 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1557 * Prepare for reading viminfo registers when writing viminfo later. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1558 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1559 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1560 prepare_viminfo_registers(void) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1561 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1562 y_read_regs = ALLOC_CLEAR_MULT(yankreg_T, NUM_REGISTERS); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1563 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1564 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1565 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1566 finish_viminfo_registers(void) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1567 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1568 int i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1569 int j; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1570 |
31827
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1571 if (y_read_regs == NULL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1572 return; |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1573 |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1574 for (i = 0; i < NUM_REGISTERS; ++i) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1575 if (y_read_regs[i].y_array != NULL) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1576 { |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1577 for (j = 0; j < y_read_regs[i].y_size; j++) |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1578 vim_free(y_read_regs[i].y_array[j]); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1579 vim_free(y_read_regs[i].y_array); |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1580 } |
1009c33499e7
patch 9.0.1246: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
1581 VIM_CLEAR(y_read_regs); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1582 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1583 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1584 static int |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1585 read_viminfo_register(vir_T *virp, int force) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1586 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1587 int eof; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1588 int do_it = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1589 int size; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1590 int limit; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1591 int i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1592 int set_prev = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1593 char_u *str; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1594 char_u **array = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1595 int new_type = MCHAR; // init to shut up compiler |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1596 colnr_T new_width = 0; // init to shut up compiler |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1597 yankreg_T *y_current_p; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1598 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1599 // We only get here (hopefully) if line[0] == '"' |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1600 str = virp->vir_line + 1; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1601 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1602 // If the line starts with "" this is the y_previous register. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1603 if (*str == '"') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1604 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1605 set_prev = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1606 str++; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1607 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1608 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1609 if (!ASCII_ISALNUM(*str) && *str != '-') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1610 { |
26917
d91aea2a612c
patch 8.2.3987: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26893
diff
changeset
|
1611 if (viminfo_error("E577: ", _(e_illegal_register_name), virp->vir_line)) |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1612 return TRUE; // too many errors, pretend end-of-file |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1613 do_it = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1614 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1615 get_yank_register(*str++, FALSE); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1616 y_current_p = get_y_current(); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1617 if (!force && y_current_p->y_array != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1618 do_it = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1619 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1620 if (*str == '@') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1621 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1622 // "x@: register x used for @@ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1623 if (force || get_execreg_lastc() == NUL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1624 set_execreg_lastc(str[-1]); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1625 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1626 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1627 size = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1628 limit = 100; // Optimized for registers containing <= 100 lines |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1629 if (do_it) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1630 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1631 // Build the new register in array[]. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1632 // y_array is kept as-is until done. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1633 // The "do_it" flag is reset when something is wrong, in which case |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1634 // array[] needs to be freed. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1635 if (set_prev) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1636 set_y_previous(y_current_p); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1637 array = ALLOC_MULT(char_u *, limit); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1638 str = skipwhite(skiptowhite(str)); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1639 if (STRNCMP(str, "CHAR", 4) == 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1640 new_type = MCHAR; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1641 else if (STRNCMP(str, "BLOCK", 5) == 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1642 new_type = MBLOCK; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1643 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1644 new_type = MLINE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1645 // get the block width; if it's missing we get a zero, which is OK |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1646 str = skipwhite(skiptowhite(str)); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1647 new_width = getdigits(&str); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1648 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1649 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1650 while (!(eof = viminfo_readline(virp)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1651 && (virp->vir_line[0] == TAB || virp->vir_line[0] == '<')) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1652 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1653 if (do_it) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1654 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1655 if (size == limit) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1656 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1657 char_u **new_array = (char_u **) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1658 alloc(limit * 2 * sizeof(char_u *)); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1659 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1660 if (new_array == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1661 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1662 do_it = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1663 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1664 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1665 for (i = 0; i < limit; i++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1666 new_array[i] = array[i]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1667 vim_free(array); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1668 array = new_array; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1669 limit *= 2; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1670 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1671 str = viminfo_readstring(virp, 1, TRUE); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1672 if (str != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1673 array[size++] = str; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1674 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1675 // error, don't store the result |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1676 do_it = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1677 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1678 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1679 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1680 if (do_it) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1681 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1682 // free y_array[] |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1683 for (i = 0; i < y_current_p->y_size; i++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1684 vim_free(y_current_p->y_array[i]); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1685 vim_free(y_current_p->y_array); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1686 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1687 y_current_p->y_type = new_type; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1688 y_current_p->y_width = new_width; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1689 y_current_p->y_size = size; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1690 y_current_p->y_time_set = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1691 if (size == 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1692 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1693 y_current_p->y_array = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1694 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1695 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1696 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1697 // Move the lines from array[] to y_array[]. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1698 y_current_p->y_array = ALLOC_MULT(char_u *, size); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1699 for (i = 0; i < size; i++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1700 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1701 if (y_current_p->y_array == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1702 vim_free(array[i]); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1703 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1704 y_current_p->y_array[i] = array[i]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1705 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1706 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1707 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1708 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1709 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1710 // Free array[] if it was filled. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1711 for (i = 0; i < size; i++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1712 vim_free(array[i]); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1713 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1714 vim_free(array); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1715 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1716 return eof; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1717 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1718 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1719 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1720 * Accept a new style register line from the viminfo, store it when it's new. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1721 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1722 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1723 handle_viminfo_register(garray_T *values, int force) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1724 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1725 bval_T *vp = (bval_T *)values->ga_data; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1726 int flags; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1727 int name; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1728 int type; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1729 int linecount; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1730 int width; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1731 time_t timestamp; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1732 yankreg_T *y_ptr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1733 yankreg_T *y_regs_p = get_y_regs(); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1734 int i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1735 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1736 // Check the format: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1737 // |{bartype},{flags},{name},{type}, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1738 // {linecount},{width},{timestamp},"line1","line2" |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1739 if (values->ga_len < 6 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1740 || vp[0].bv_type != BVAL_NR |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1741 || vp[1].bv_type != BVAL_NR |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1742 || vp[2].bv_type != BVAL_NR |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1743 || vp[3].bv_type != BVAL_NR |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1744 || vp[4].bv_type != BVAL_NR |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1745 || vp[5].bv_type != BVAL_NR) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1746 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1747 flags = vp[0].bv_nr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1748 name = vp[1].bv_nr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1749 if (name < 0 || name >= NUM_REGISTERS) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1750 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1751 type = vp[2].bv_nr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1752 if (type != MCHAR && type != MLINE && type != MBLOCK) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1753 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1754 linecount = vp[3].bv_nr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1755 if (values->ga_len < 6 + linecount) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1756 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1757 width = vp[4].bv_nr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1758 if (width < 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1759 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1760 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1761 if (y_read_regs != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1762 // Reading viminfo for merging and writing. Store the register |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1763 // content, don't update the current registers. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1764 y_ptr = &y_read_regs[name]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1765 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1766 y_ptr = &y_regs_p[name]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1767 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1768 // Do not overwrite unless forced or the timestamp is newer. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1769 timestamp = (time_t)vp[5].bv_nr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1770 if (y_ptr->y_array != NULL && !force |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1771 && (timestamp == 0 || y_ptr->y_time_set > timestamp)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1772 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1773 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1774 if (y_ptr->y_array != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1775 for (i = 0; i < y_ptr->y_size; i++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1776 vim_free(y_ptr->y_array[i]); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1777 vim_free(y_ptr->y_array); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1778 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1779 if (y_read_regs == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1780 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1781 if (flags & REG_PREVIOUS) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1782 set_y_previous(y_ptr); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1783 if ((flags & REG_EXEC) && (force || get_execreg_lastc() == NUL)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1784 set_execreg_lastc(get_register_name(name)); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1785 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1786 y_ptr->y_type = type; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1787 y_ptr->y_width = width; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1788 y_ptr->y_size = linecount; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1789 y_ptr->y_time_set = timestamp; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1790 if (linecount == 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1791 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1792 y_ptr->y_array = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1793 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1794 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1795 y_ptr->y_array = ALLOC_MULT(char_u *, linecount); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1796 if (y_ptr->y_array == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1797 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1798 y_ptr->y_size = 0; // ensure object state is consistent |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1799 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1800 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1801 for (i = 0; i < linecount; i++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1802 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1803 if (vp[i + 6].bv_allocated) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1804 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1805 y_ptr->y_array[i] = vp[i + 6].bv_string; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1806 vp[i + 6].bv_string = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1807 } |
33006
29b2193466e0
patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents:
32860
diff
changeset
|
1808 else if (vp[i + 6].bv_type != BVAL_STRING) |
29b2193466e0
patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents:
32860
diff
changeset
|
1809 { |
29b2193466e0
patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents:
32860
diff
changeset
|
1810 free(y_ptr->y_array); |
29b2193466e0
patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents:
32860
diff
changeset
|
1811 y_ptr->y_array = NULL; |
29b2193466e0
patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents:
32860
diff
changeset
|
1812 } |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1813 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1814 y_ptr->y_array[i] = vim_strsave(vp[i + 6].bv_string); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1815 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1816 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1817 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1818 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1819 write_viminfo_registers(FILE *fp) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1820 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1821 int i, j; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1822 char_u *type; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1823 char_u c; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1824 int num_lines; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1825 int max_num_lines; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1826 int max_kbyte; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1827 long len; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1828 yankreg_T *y_ptr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1829 yankreg_T *y_regs_p = get_y_regs();; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1830 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1831 fputs(_("\n# Registers:\n"), fp); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1832 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1833 // Get '<' value, use old '"' value if '<' is not found. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1834 max_num_lines = get_viminfo_parameter('<'); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1835 if (max_num_lines < 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1836 max_num_lines = get_viminfo_parameter('"'); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1837 if (max_num_lines == 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1838 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1839 max_kbyte = get_viminfo_parameter('s'); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1840 if (max_kbyte == 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1841 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1842 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1843 for (i = 0; i < NUM_REGISTERS; i++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1844 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1845 #ifdef FEAT_CLIPBOARD |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1846 // Skip '*'/'+' register, we don't want them back next time |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1847 if (i == STAR_REGISTER || i == PLUS_REGISTER) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1848 continue; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1849 #endif |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1850 #ifdef FEAT_DND |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1851 // Neither do we want the '~' register |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1852 if (i == TILDE_REGISTER) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1853 continue; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1854 #endif |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1855 // When reading viminfo for merging and writing: Use the register from |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1856 // viminfo if it's newer. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1857 if (y_read_regs != NULL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1858 && y_read_regs[i].y_array != NULL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1859 && (y_regs_p[i].y_array == NULL || |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1860 y_read_regs[i].y_time_set > y_regs_p[i].y_time_set)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1861 y_ptr = &y_read_regs[i]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1862 else if (y_regs_p[i].y_array == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1863 continue; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1864 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1865 y_ptr = &y_regs_p[i]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1866 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1867 // Skip empty registers. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1868 num_lines = y_ptr->y_size; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1869 if (num_lines == 0 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1870 || (num_lines == 1 && y_ptr->y_type == MCHAR |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1871 && *y_ptr->y_array[0] == NUL)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1872 continue; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1873 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1874 if (max_kbyte > 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1875 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1876 // Skip register if there is more text than the maximum size. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1877 len = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1878 for (j = 0; j < num_lines; j++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1879 len += (long)STRLEN(y_ptr->y_array[j]) + 1L; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1880 if (len > (long)max_kbyte * 1024L) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1881 continue; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1882 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1883 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1884 switch (y_ptr->y_type) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1885 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1886 case MLINE: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1887 type = (char_u *)"LINE"; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1888 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1889 case MCHAR: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1890 type = (char_u *)"CHAR"; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1891 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1892 case MBLOCK: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1893 type = (char_u *)"BLOCK"; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1894 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1895 default: |
26917
d91aea2a612c
patch 8.2.3987: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26893
diff
changeset
|
1896 semsg(_(e_unknown_register_type_nr), y_ptr->y_type); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1897 type = (char_u *)"LINE"; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1898 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1899 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1900 if (get_y_previous() == &y_regs_p[i]) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1901 fprintf(fp, "\""); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1902 c = get_register_name(i); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1903 fprintf(fp, "\"%c", c); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1904 if (c == get_execreg_lastc()) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1905 fprintf(fp, "@"); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1906 fprintf(fp, "\t%s\t%d\n", type, (int)y_ptr->y_width); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1907 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1908 // If max_num_lines < 0, then we save ALL the lines in the register |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1909 if (max_num_lines > 0 && num_lines > max_num_lines) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1910 num_lines = max_num_lines; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1911 for (j = 0; j < num_lines; j++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1912 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1913 putc('\t', fp); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1914 viminfo_writestring(fp, y_ptr->y_array[j]); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1915 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1916 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1917 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1918 int flags = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1919 int remaining; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1920 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1921 // New style with a bar line. Format: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1922 // |{bartype},{flags},{name},{type}, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1923 // {linecount},{width},{timestamp},"line1","line2" |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1924 // flags: REG_PREVIOUS - register is y_previous |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1925 // REG_EXEC - used for @@ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1926 if (get_y_previous() == &y_regs_p[i]) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1927 flags |= REG_PREVIOUS; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1928 if (c == get_execreg_lastc()) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1929 flags |= REG_EXEC; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1930 fprintf(fp, "|%d,%d,%d,%d,%d,%d,%ld", BARTYPE_REGISTER, flags, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1931 i, y_ptr->y_type, num_lines, (int)y_ptr->y_width, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1932 (long)y_ptr->y_time_set); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1933 // 11 chars for type/flags/name/type, 3 * 20 for numbers |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1934 remaining = LSIZE - 71; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1935 for (j = 0; j < num_lines; j++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1936 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1937 putc(',', fp); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1938 --remaining; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1939 remaining = barline_writestring(fp, y_ptr->y_array[j], |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1940 remaining); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1941 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1942 putc('\n', fp); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1943 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1944 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1945 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1946 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1947 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1948 * Functions relating to reading/writing marks from viminfo |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1949 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1950 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1951 static xfmark_T *vi_namedfm = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1952 static xfmark_T *vi_jumplist = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1953 static int vi_jumplist_len = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1954 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1955 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1956 write_one_mark(FILE *fp_out, int c, pos_T *pos) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1957 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1958 if (pos->lnum != 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1959 fprintf(fp_out, "\t%c\t%ld\t%d\n", c, (long)pos->lnum, (int)pos->col); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1960 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1961 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1962 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1963 write_buffer_marks(buf_T *buf, FILE *fp_out) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1964 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1965 int i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1966 pos_T pos; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1967 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1968 home_replace(NULL, buf->b_ffname, IObuff, IOSIZE, TRUE); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1969 fprintf(fp_out, "\n> "); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1970 viminfo_writestring(fp_out, IObuff); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1971 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1972 // Write the last used timestamp as the lnum of the non-existing mark '*'. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1973 // Older Vims will ignore it and/or copy it. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1974 pos.lnum = (linenr_T)buf->b_last_used; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1975 pos.col = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1976 write_one_mark(fp_out, '*', &pos); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1977 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1978 write_one_mark(fp_out, '"', &buf->b_last_cursor); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1979 write_one_mark(fp_out, '^', &buf->b_last_insert); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1980 write_one_mark(fp_out, '.', &buf->b_last_change); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1981 // changelist positions are stored oldest first |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1982 for (i = 0; i < buf->b_changelistlen; ++i) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1983 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1984 // skip duplicates |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1985 if (i == 0 || !EQUAL_POS(buf->b_changelist[i - 1], |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1986 buf->b_changelist[i])) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1987 write_one_mark(fp_out, '+', &buf->b_changelist[i]); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1988 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1989 for (i = 0; i < NMARKS; i++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1990 write_one_mark(fp_out, 'a' + i, &buf->b_namedm[i]); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1991 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1992 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1993 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1994 * Return TRUE if marks for "buf" should not be written. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1995 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1996 static int |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1997 skip_for_viminfo(buf_T *buf) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
1998 { |
29849
6c7eddcce52c
patch 9.0.0263: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1999 return bt_terminal(buf) || removable(buf->b_ffname); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2000 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2001 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2002 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2003 * Write all the named marks for all buffers. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2004 * When "buflist" is not NULL fill it with the buffers for which marks are to |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2005 * be written. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2006 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2007 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2008 write_viminfo_marks(FILE *fp_out, garray_T *buflist) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2009 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2010 buf_T *buf; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2011 int is_mark_set; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2012 int i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2013 win_T *win; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2014 tabpage_T *tp; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2015 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2016 // Set b_last_cursor for the all buffers that have a window. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2017 FOR_ALL_TAB_WINDOWS(tp, win) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2018 set_last_cursor(win); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2019 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2020 fputs(_("\n# History of marks within files (newest to oldest):\n"), fp_out); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2021 FOR_ALL_BUFFERS(buf) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2022 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2023 // Only write something if buffer has been loaded and at least one |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2024 // mark is set. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2025 if (buf->b_marks_read) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2026 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2027 if (buf->b_last_cursor.lnum != 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2028 is_mark_set = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2029 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2030 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2031 is_mark_set = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2032 for (i = 0; i < NMARKS; i++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2033 if (buf->b_namedm[i].lnum != 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2034 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2035 is_mark_set = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2036 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2037 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2038 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2039 if (is_mark_set && buf->b_ffname != NULL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2040 && buf->b_ffname[0] != NUL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2041 && !skip_for_viminfo(buf)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2042 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2043 if (buflist == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2044 write_buffer_marks(buf, fp_out); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2045 else if (ga_grow(buflist, 1) == OK) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2046 ((buf_T **)buflist->ga_data)[buflist->ga_len++] = buf; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2047 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2048 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2049 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2050 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2051 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2052 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2053 write_one_filemark( |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2054 FILE *fp, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2055 xfmark_T *fm, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2056 int c1, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2057 int c2) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2058 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2059 char_u *name; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2060 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2061 if (fm->fmark.mark.lnum == 0) // not set |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2062 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2063 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2064 if (fm->fmark.fnum != 0) // there is a buffer |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2065 name = buflist_nr2name(fm->fmark.fnum, TRUE, FALSE); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2066 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2067 name = fm->fname; // use name from .viminfo |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2068 if (name != NULL && *name != NUL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2069 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2070 fprintf(fp, "%c%c %ld %ld ", c1, c2, (long)fm->fmark.mark.lnum, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2071 (long)fm->fmark.mark.col); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2072 viminfo_writestring(fp, name); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2073 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2074 // Barline: |{bartype},{name},{lnum},{col},{timestamp},{filename} |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2075 // size up to filename: 8 + 3 * 20 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2076 fprintf(fp, "|%d,%d,%ld,%ld,%ld,", BARTYPE_MARK, c2, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2077 (long)fm->fmark.mark.lnum, (long)fm->fmark.mark.col, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2078 (long)fm->time_set); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2079 barline_writestring(fp, name, LSIZE - 70); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2080 putc('\n', fp); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2081 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2082 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2083 if (fm->fmark.fnum != 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2084 vim_free(name); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2085 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2086 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2087 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2088 write_viminfo_filemarks(FILE *fp) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2089 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2090 int i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2091 char_u *name; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2092 buf_T *buf; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2093 xfmark_T *namedfm_p = get_namedfm(); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2094 xfmark_T *fm; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2095 int vi_idx; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2096 int idx; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2097 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2098 if (get_viminfo_parameter('f') == 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2099 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2100 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2101 fputs(_("\n# File marks:\n"), fp); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2102 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2103 // Write the filemarks 'A - 'Z |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2104 for (i = 0; i < NMARKS; i++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2105 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2106 if (vi_namedfm != NULL |
18979
de2d1820215a
patch 8.2.0050: after deleting a file mark it is still in viminfo
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2107 && (vi_namedfm[i].time_set > namedfm_p[i].time_set)) |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2108 fm = &vi_namedfm[i]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2109 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2110 fm = &namedfm_p[i]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2111 write_one_filemark(fp, fm, '\'', i + 'A'); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2112 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2113 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2114 // Find a mark that is the same file and position as the cursor. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2115 // That one, or else the last one is deleted. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2116 // Move '0 to '1, '1 to '2, etc. until the matching one or '9 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2117 // Set the '0 mark to current cursor position. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2118 if (curbuf->b_ffname != NULL && !skip_for_viminfo(curbuf)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2119 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2120 name = buflist_nr2name(curbuf->b_fnum, TRUE, FALSE); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2121 for (i = NMARKS; i < NMARKS + EXTRA_MARKS - 1; ++i) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2122 if (namedfm_p[i].fmark.mark.lnum == curwin->w_cursor.lnum |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2123 && (namedfm_p[i].fname == NULL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2124 ? namedfm_p[i].fmark.fnum == curbuf->b_fnum |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2125 : (name != NULL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2126 && STRCMP(name, namedfm_p[i].fname) == 0))) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2127 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2128 vim_free(name); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2129 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2130 vim_free(namedfm_p[i].fname); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2131 for ( ; i > NMARKS; --i) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2132 namedfm_p[i] = namedfm_p[i - 1]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2133 namedfm_p[NMARKS].fmark.mark = curwin->w_cursor; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2134 namedfm_p[NMARKS].fmark.fnum = curbuf->b_fnum; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2135 namedfm_p[NMARKS].fname = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2136 namedfm_p[NMARKS].time_set = vim_time(); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2137 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2138 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2139 // Write the filemarks '0 - '9. Newest (highest timestamp) first. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2140 vi_idx = NMARKS; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2141 idx = NMARKS; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2142 for (i = NMARKS; i < NMARKS + EXTRA_MARKS; i++) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2143 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2144 xfmark_T *vi_fm = vi_namedfm != NULL ? &vi_namedfm[vi_idx] : NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2145 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2146 if (vi_fm != NULL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2147 && vi_fm->fmark.mark.lnum != 0 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2148 && (vi_fm->time_set > namedfm_p[idx].time_set |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2149 || namedfm_p[idx].fmark.mark.lnum == 0)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2150 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2151 fm = vi_fm; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2152 ++vi_idx; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2153 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2154 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2155 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2156 fm = &namedfm_p[idx++]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2157 if (vi_fm != NULL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2158 && vi_fm->fmark.mark.lnum == fm->fmark.mark.lnum |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2159 && vi_fm->time_set == fm->time_set |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2160 && ((vi_fm->fmark.fnum != 0 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2161 && vi_fm->fmark.fnum == fm->fmark.fnum) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2162 || (vi_fm->fname != NULL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2163 && fm->fname != NULL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2164 && STRCMP(vi_fm->fname, fm->fname) == 0))) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2165 ++vi_idx; // skip duplicate |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2166 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2167 write_one_filemark(fp, fm, '\'', i - NMARKS + '0'); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2168 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2169 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2170 // Write the jumplist with -' |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2171 fputs(_("\n# Jumplist (newest first):\n"), fp); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2172 setpcmark(); // add current cursor position |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2173 cleanup_jumplist(curwin, FALSE); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2174 vi_idx = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2175 idx = curwin->w_jumplistlen - 1; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2176 for (i = 0; i < JUMPLISTSIZE; ++i) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2177 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2178 xfmark_T *vi_fm; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2179 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2180 fm = idx >= 0 ? &curwin->w_jumplist[idx] : NULL; |
22029
2d6d70a913c1
patch 8.2.1564: a few remaining errors from ubsan
Bram Moolenaar <Bram@vim.org>
parents:
21580
diff
changeset
|
2181 vi_fm = (vi_jumplist != NULL && vi_idx < vi_jumplist_len) |
2d6d70a913c1
patch 8.2.1564: a few remaining errors from ubsan
Bram Moolenaar <Bram@vim.org>
parents:
21580
diff
changeset
|
2182 ? &vi_jumplist[vi_idx] : NULL; |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2183 if (fm == NULL && vi_fm == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2184 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2185 if (fm == NULL || (vi_fm != NULL && fm->time_set < vi_fm->time_set)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2186 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2187 fm = vi_fm; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2188 ++vi_idx; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2189 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2190 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2191 --idx; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2192 if (fm->fmark.fnum == 0 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2193 || ((buf = buflist_findnr(fm->fmark.fnum)) != NULL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2194 && !skip_for_viminfo(buf))) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2195 write_one_filemark(fp, fm, '-', '\''); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2196 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2197 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2198 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2199 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2200 * Compare functions for qsort() below, that compares b_last_used. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2201 */ |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18263
diff
changeset
|
2202 int |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2203 buf_compare(const void *s1, const void *s2) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2204 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2205 buf_T *buf1 = *(buf_T **)s1; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2206 buf_T *buf2 = *(buf_T **)s2; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2207 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2208 if (buf1->b_last_used == buf2->b_last_used) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2209 return 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2210 return buf1->b_last_used > buf2->b_last_used ? -1 : 1; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2211 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2212 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2213 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2214 * Handle marks in the viminfo file: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2215 * fp_out != NULL: copy marks, in time order with buffers in "buflist". |
23903
402f1d8653c1
patch 8.2.2494: ":rviminfo!" clears most of oldfiles
Bram Moolenaar <Bram@vim.org>
parents:
22029
diff
changeset
|
2216 * fp_out == NULL && (flags & VIF_WANT_MARKS): read marks for curbuf |
402f1d8653c1
patch 8.2.2494: ":rviminfo!" clears most of oldfiles
Bram Moolenaar <Bram@vim.org>
parents:
22029
diff
changeset
|
2217 * fp_out == NULL && (flags & VIF_ONLY_CURBUF): bail out after curbuf marks |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2218 * fp_out == NULL && (flags & VIF_GET_OLDFILES | VIF_FORCEIT): fill v:oldfiles |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2219 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2220 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2221 copy_viminfo_marks( |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2222 vir_T *virp, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2223 FILE *fp_out, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2224 garray_T *buflist, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2225 int eof, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2226 int flags) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2227 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2228 char_u *line = virp->vir_line; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2229 buf_T *buf; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2230 int num_marked_files; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2231 int load_marks; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2232 int copy_marks_out; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2233 char_u *str; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2234 int i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2235 char_u *p; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2236 char_u *name_buf; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2237 pos_T pos; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2238 #ifdef FEAT_EVAL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2239 list_T *list = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2240 #endif |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2241 int count = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2242 int buflist_used = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2243 buf_T *buflist_buf = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2244 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2245 if ((name_buf = alloc(LSIZE)) == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2246 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2247 *name_buf = NUL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2248 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2249 if (fp_out != NULL && buflist->ga_len > 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2250 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2251 // Sort the list of buffers on b_last_used. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2252 qsort(buflist->ga_data, (size_t)buflist->ga_len, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2253 sizeof(buf_T *), buf_compare); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2254 buflist_buf = ((buf_T **)buflist->ga_data)[0]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2255 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2256 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2257 #ifdef FEAT_EVAL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2258 if (fp_out == NULL && (flags & (VIF_GET_OLDFILES | VIF_FORCEIT))) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2259 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2260 list = list_alloc(); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2261 if (list != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2262 set_vim_var_list(VV_OLDFILES, list); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2263 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2264 #endif |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2265 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2266 num_marked_files = get_viminfo_parameter('\''); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2267 while (!eof && (count < num_marked_files || fp_out == NULL)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2268 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2269 if (line[0] != '>') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2270 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2271 if (line[0] != '\n' && line[0] != '\r' && line[0] != '#') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2272 { |
26917
d91aea2a612c
patch 8.2.3987: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26893
diff
changeset
|
2273 if (viminfo_error("E576: ", _(e_nonr_missing_gt), line)) |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2274 break; // too many errors, return now |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2275 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2276 eof = vim_fgets(line, LSIZE, virp->vir_fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2277 continue; // Skip this dud line |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2278 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2279 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2280 // Handle long line and translate escaped characters. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2281 // Find file name, set str to start. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2282 // Ignore leading and trailing white space. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2283 str = skipwhite(line + 1); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2284 str = viminfo_readstring(virp, (int)(str - virp->vir_line), FALSE); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2285 if (str == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2286 continue; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2287 p = str + STRLEN(str); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2288 while (p != str && (*p == NUL || vim_isspace(*p))) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2289 p--; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2290 if (*p) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2291 p++; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2292 *p = NUL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2293 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2294 #ifdef FEAT_EVAL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2295 if (list != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2296 list_append_string(list, str, -1); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2297 #endif |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2298 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2299 // If fp_out == NULL, load marks for current buffer. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2300 // If fp_out != NULL, copy marks for buffers not in buflist. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2301 load_marks = copy_marks_out = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2302 if (fp_out == NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2303 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2304 if ((flags & VIF_WANT_MARKS) && curbuf->b_ffname != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2305 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2306 if (*name_buf == NUL) // only need to do this once |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2307 home_replace(NULL, curbuf->b_ffname, name_buf, LSIZE, TRUE); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2308 if (fnamecmp(str, name_buf) == 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2309 load_marks = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2310 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2311 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2312 else // fp_out != NULL |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2313 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2314 // This is slow if there are many buffers!! |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2315 FOR_ALL_BUFFERS(buf) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2316 if (buf->b_ffname != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2317 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2318 home_replace(NULL, buf->b_ffname, name_buf, LSIZE, TRUE); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2319 if (fnamecmp(str, name_buf) == 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2320 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2321 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2322 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2323 // Copy marks if the buffer has not been loaded. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2324 if (buf == NULL || !buf->b_marks_read) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2325 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2326 int did_read_line = FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2327 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2328 if (buflist_buf != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2329 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2330 // Read the next line. If it has the "*" mark compare the |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2331 // time stamps. Write entries from "buflist" that are |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2332 // newer. |
30077
d45ee1f829ba
patch 9.0.0376: clang warns for dead assignments
Bram Moolenaar <Bram@vim.org>
parents:
29960
diff
changeset
|
2333 if (!viminfo_readline(virp) && line[0] == TAB) |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2334 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2335 did_read_line = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2336 if (line[1] == '*') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2337 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2338 long ltime; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2339 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2340 sscanf((char *)line + 2, "%ld ", <ime); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2341 while ((time_T)ltime < buflist_buf->b_last_used) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2342 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2343 write_buffer_marks(buflist_buf, fp_out); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2344 if (++count >= num_marked_files) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2345 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2346 if (++buflist_used == buflist->ga_len) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2347 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2348 buflist_buf = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2349 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2350 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2351 buflist_buf = |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2352 ((buf_T **)buflist->ga_data)[buflist_used]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2353 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2354 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2355 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2356 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2357 // No timestamp, must be written by an older Vim. |
18498
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
18463
diff
changeset
|
2358 // Assume all remaining buffers are older than |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2359 // ours. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2360 while (count < num_marked_files |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2361 && buflist_used < buflist->ga_len) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2362 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2363 buflist_buf = ((buf_T **)buflist->ga_data) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2364 [buflist_used++]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2365 write_buffer_marks(buflist_buf, fp_out); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2366 ++count; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2367 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2368 buflist_buf = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2369 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2370 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2371 if (count >= num_marked_files) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2372 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2373 vim_free(str); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2374 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2375 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2376 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2377 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2378 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2379 fputs("\n> ", fp_out); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2380 viminfo_writestring(fp_out, str); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2381 if (did_read_line) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2382 fputs((char *)line, fp_out); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2383 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2384 count++; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2385 copy_marks_out = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2386 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2387 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2388 vim_free(str); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2389 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2390 pos.coladd = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2391 while (!(eof = viminfo_readline(virp)) && line[0] == TAB) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2392 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2393 if (load_marks) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2394 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2395 if (line[1] != NUL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2396 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2397 unsigned u; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2398 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2399 sscanf((char *)line + 2, "%ld %u", &pos.lnum, &u); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2400 pos.col = u; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2401 switch (line[1]) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2402 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2403 case '"': curbuf->b_last_cursor = pos; break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2404 case '^': curbuf->b_last_insert = pos; break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2405 case '.': curbuf->b_last_change = pos; break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2406 case '+': |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2407 // changelist positions are stored oldest |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2408 // first |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2409 if (curbuf->b_changelistlen == JUMPLISTSIZE) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2410 // list is full, remove oldest entry |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2411 mch_memmove(curbuf->b_changelist, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2412 curbuf->b_changelist + 1, |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2413 sizeof(pos_T) * (JUMPLISTSIZE - 1)); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2414 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2415 ++curbuf->b_changelistlen; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2416 curbuf->b_changelist[ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2417 curbuf->b_changelistlen - 1] = pos; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2418 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2419 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2420 // Using the line number for the last-used |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2421 // timestamp. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2422 case '*': curbuf->b_last_used = pos.lnum; break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2423 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2424 default: if ((i = line[1] - 'a') >= 0 && i < NMARKS) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2425 curbuf->b_namedm[i] = pos; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2426 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2427 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2428 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2429 else if (copy_marks_out) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2430 fputs((char *)line, fp_out); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2431 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2432 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2433 if (load_marks) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2434 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2435 win_T *wp; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2436 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2437 FOR_ALL_WINDOWS(wp) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2438 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2439 if (wp->w_buffer == curbuf) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2440 wp->w_changelistidx = curbuf->b_changelistlen; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2441 } |
23903
402f1d8653c1
patch 8.2.2494: ":rviminfo!" clears most of oldfiles
Bram Moolenaar <Bram@vim.org>
parents:
22029
diff
changeset
|
2442 if (flags & VIF_ONLY_CURBUF) |
402f1d8653c1
patch 8.2.2494: ":rviminfo!" clears most of oldfiles
Bram Moolenaar <Bram@vim.org>
parents:
22029
diff
changeset
|
2443 break; |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2444 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2445 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2446 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2447 if (fp_out != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2448 // Write any remaining entries from buflist. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2449 while (count < num_marked_files && buflist_used < buflist->ga_len) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2450 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2451 buflist_buf = ((buf_T **)buflist->ga_data)[buflist_used++]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2452 write_buffer_marks(buflist_buf, fp_out); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2453 ++count; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2454 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2455 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2456 vim_free(name_buf); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2457 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2458 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2459 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2460 * Read marks for the current buffer from the viminfo file, when we support |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2461 * buffer marks and the buffer has a name. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2462 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2463 void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2464 check_marks_read(void) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2465 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2466 if (!curbuf->b_marks_read && get_viminfo_parameter('\'') > 0 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2467 && curbuf->b_ffname != NULL) |
23903
402f1d8653c1
patch 8.2.2494: ":rviminfo!" clears most of oldfiles
Bram Moolenaar <Bram@vim.org>
parents:
22029
diff
changeset
|
2468 read_viminfo(NULL, VIF_WANT_MARKS | VIF_ONLY_CURBUF); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2469 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2470 // Always set b_marks_read; needed when 'viminfo' is changed to include |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2471 // the ' parameter after opening a buffer. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2472 curbuf->b_marks_read = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2473 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2474 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2475 static int |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2476 read_viminfo_filemark(vir_T *virp, int force) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2477 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2478 char_u *str; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2479 xfmark_T *namedfm_p = get_namedfm(); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2480 xfmark_T *fm; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2481 int i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2482 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2483 // We only get here if line[0] == '\'' or '-'. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2484 // Illegal mark names are ignored (for future expansion). |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2485 str = virp->vir_line + 1; |
27490
fb4c30606b4a
patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2486 if (*str <= 127 |
fb4c30606b4a
patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2487 && ((*virp->vir_line == '\'' |
fb4c30606b4a
patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2488 && (VIM_ISDIGIT(*str) || isupper(*str))) |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2489 || (*virp->vir_line == '-' && *str == '\''))) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2490 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2491 if (*str == '\'') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2492 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2493 // If the jumplist isn't full insert fmark as oldest entry |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2494 if (curwin->w_jumplistlen == JUMPLISTSIZE) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2495 fm = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2496 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2497 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2498 for (i = curwin->w_jumplistlen; i > 0; --i) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2499 curwin->w_jumplist[i] = curwin->w_jumplist[i - 1]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2500 ++curwin->w_jumplistidx; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2501 ++curwin->w_jumplistlen; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2502 fm = &curwin->w_jumplist[0]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2503 fm->fmark.mark.lnum = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2504 fm->fname = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2505 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2506 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2507 else if (VIM_ISDIGIT(*str)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2508 fm = &namedfm_p[*str - '0' + NMARKS]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2509 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2510 fm = &namedfm_p[*str - 'A']; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2511 if (fm != NULL && (fm->fmark.mark.lnum == 0 || force)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2512 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2513 str = skipwhite(str + 1); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2514 fm->fmark.mark.lnum = getdigits(&str); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2515 str = skipwhite(str); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2516 fm->fmark.mark.col = getdigits(&str); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2517 fm->fmark.mark.coladd = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2518 fm->fmark.fnum = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2519 str = skipwhite(str); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2520 vim_free(fm->fname); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2521 fm->fname = viminfo_readstring(virp, (int)(str - virp->vir_line), |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2522 FALSE); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2523 fm->time_set = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2524 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2525 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2526 return vim_fgets(virp->vir_line, LSIZE, virp->vir_fd); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2527 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2528 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2529 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2530 * Prepare for reading viminfo marks when writing viminfo later. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2531 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2532 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2533 prepare_viminfo_marks(void) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2534 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2535 vi_namedfm = ALLOC_CLEAR_MULT(xfmark_T, NMARKS + EXTRA_MARKS); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2536 vi_jumplist = ALLOC_CLEAR_MULT(xfmark_T, JUMPLISTSIZE); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2537 vi_jumplist_len = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2538 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2539 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2540 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2541 finish_viminfo_marks(void) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2542 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2543 int i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2544 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2545 if (vi_namedfm != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2546 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2547 for (i = 0; i < NMARKS + EXTRA_MARKS; ++i) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2548 vim_free(vi_namedfm[i].fname); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2549 VIM_CLEAR(vi_namedfm); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2550 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2551 if (vi_jumplist != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2552 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2553 for (i = 0; i < vi_jumplist_len; ++i) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2554 vim_free(vi_jumplist[i].fname); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2555 VIM_CLEAR(vi_jumplist); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2556 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2557 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2558 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2559 /* |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2560 * Accept a new style mark line from the viminfo, store it when it's new. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2561 */ |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2562 static void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2563 handle_viminfo_mark(garray_T *values, int force) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2564 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2565 bval_T *vp = (bval_T *)values->ga_data; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2566 int name; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2567 linenr_T lnum; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2568 colnr_T col; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2569 time_t timestamp; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2570 xfmark_T *fm = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2571 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2572 // Check the format: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2573 // |{bartype},{name},{lnum},{col},{timestamp},{filename} |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2574 if (values->ga_len < 5 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2575 || vp[0].bv_type != BVAL_NR |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2576 || vp[1].bv_type != BVAL_NR |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2577 || vp[2].bv_type != BVAL_NR |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2578 || vp[3].bv_type != BVAL_NR |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2579 || vp[4].bv_type != BVAL_STRING) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2580 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2581 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2582 name = vp[0].bv_nr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2583 if (name != '\'' && !VIM_ISDIGIT(name) && !ASCII_ISUPPER(name)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2584 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2585 lnum = vp[1].bv_nr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2586 col = vp[2].bv_nr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2587 if (lnum <= 0 || col < 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2588 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2589 timestamp = (time_t)vp[3].bv_nr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2590 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2591 if (name == '\'') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2592 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2593 if (vi_jumplist != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2594 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2595 if (vi_jumplist_len < JUMPLISTSIZE) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2596 fm = &vi_jumplist[vi_jumplist_len++]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2597 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2598 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2599 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2600 int idx; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2601 int i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2602 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2603 // If we have a timestamp insert it in the right place. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2604 if (timestamp != 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2605 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2606 for (idx = curwin->w_jumplistlen - 1; idx >= 0; --idx) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2607 if (curwin->w_jumplist[idx].time_set < timestamp) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2608 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2609 ++idx; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2610 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2611 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2612 // idx cannot be zero now |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2613 if (idx < 0 && curwin->w_jumplistlen < JUMPLISTSIZE) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2614 // insert as the oldest entry |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2615 idx = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2616 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2617 else if (curwin->w_jumplistlen < JUMPLISTSIZE) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2618 // insert as oldest entry |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2619 idx = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2620 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2621 idx = -1; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2622 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2623 if (idx >= 0) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2624 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2625 if (curwin->w_jumplistlen == JUMPLISTSIZE) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2626 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2627 // Drop the oldest entry. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2628 --idx; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2629 vim_free(curwin->w_jumplist[0].fname); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2630 for (i = 0; i < idx; ++i) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2631 curwin->w_jumplist[i] = curwin->w_jumplist[i + 1]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2632 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2633 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2634 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2635 // Move newer entries forward. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2636 for (i = curwin->w_jumplistlen; i > idx; --i) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2637 curwin->w_jumplist[i] = curwin->w_jumplist[i - 1]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2638 ++curwin->w_jumplistidx; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2639 ++curwin->w_jumplistlen; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2640 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2641 fm = &curwin->w_jumplist[idx]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2642 fm->fmark.mark.lnum = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2643 fm->fname = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2644 fm->time_set = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2645 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2646 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2647 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2648 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2649 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2650 int idx; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2651 xfmark_T *namedfm_p = get_namedfm(); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2652 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2653 if (VIM_ISDIGIT(name)) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2654 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2655 if (vi_namedfm != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2656 idx = name - '0' + NMARKS; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2657 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2658 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2659 int i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2660 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2661 // Do not use the name from the viminfo file, insert in time |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2662 // order. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2663 for (idx = NMARKS; idx < NMARKS + EXTRA_MARKS; ++idx) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2664 if (namedfm_p[idx].time_set < timestamp) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2665 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2666 if (idx == NMARKS + EXTRA_MARKS) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2667 // All existing entries are newer. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2668 return; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2669 i = NMARKS + EXTRA_MARKS - 1; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2670 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2671 vim_free(namedfm_p[i].fname); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2672 for ( ; i > idx; --i) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2673 namedfm_p[i] = namedfm_p[i - 1]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2674 namedfm_p[idx].fname = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2675 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2676 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2677 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2678 idx = name - 'A'; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2679 if (vi_namedfm != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2680 fm = &vi_namedfm[idx]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2681 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2682 fm = &namedfm_p[idx]; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2683 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2684 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2685 if (fm != NULL) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2686 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2687 if (vi_namedfm != NULL || fm->fmark.mark.lnum == 0 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2688 || fm->time_set < timestamp || force) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2689 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2690 fm->fmark.mark.lnum = lnum; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2691 fm->fmark.mark.col = col; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2692 fm->fmark.mark.coladd = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2693 fm->fmark.fnum = 0; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2694 vim_free(fm->fname); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2695 if (vp[4].bv_allocated) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2696 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2697 fm->fname = vp[4].bv_string; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2698 vp[4].bv_string = NULL; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2699 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2700 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2701 fm->fname = vim_strsave(vp[4].bv_string); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2702 fm->time_set = timestamp; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2703 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2704 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2705 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2706 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2707 static int |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2708 read_viminfo_barline(vir_T *virp, int got_encoding, int force, int writing) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2709 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2710 char_u *p = virp->vir_line + 1; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2711 int bartype; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2712 garray_T values; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2713 bval_T *vp; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2714 int i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2715 int read_next = TRUE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2716 |
18263
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
2717 // The format is: |{bartype},{value},... |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
2718 // For a very long string: |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
2719 // |{bartype},>{length of "{text}{text2}"} |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
2720 // |<{text1} |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
2721 // |<{text2},{value} |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
2722 // For a long line not using a string |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
2723 // |{bartype},{lots of values},> |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
2724 // |<{value},{value} |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2725 if (*p == '<') |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2726 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2727 // Continuation line of an unrecognized item. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2728 if (writing) |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
2729 ga_copy_string(&virp->vir_barlines, virp->vir_line); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2730 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2731 else |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2732 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2733 ga_init2(&values, sizeof(bval_T), 20); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2734 bartype = getdigits(&p); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2735 switch (bartype) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2736 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2737 case BARTYPE_VERSION: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2738 // Only use the version when it comes before the encoding. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2739 // If it comes later it was copied by a Vim version that |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2740 // doesn't understand the version. |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2741 if (!got_encoding) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2742 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2743 read_next = barline_parse(virp, p, &values); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2744 vp = (bval_T *)values.ga_data; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2745 if (values.ga_len > 0 && vp->bv_type == BVAL_NR) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2746 virp->vir_version = vp->bv_nr; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2747 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2748 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2749 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2750 case BARTYPE_HISTORY: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2751 read_next = barline_parse(virp, p, &values); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2752 handle_viminfo_history(&values, writing); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2753 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2754 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2755 case BARTYPE_REGISTER: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2756 read_next = barline_parse(virp, p, &values); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2757 handle_viminfo_register(&values, force); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2758 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2759 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2760 case BARTYPE_MARK: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2761 read_next = barline_parse(virp, p, &values); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2762 handle_viminfo_mark(&values, force); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2763 break; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2764 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2765 default: |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2766 // copy unrecognized line (for future use) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2767 if (writing) |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
2768 ga_copy_string(&virp->vir_barlines, virp->vir_line); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2769 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2770 for (i = 0; i < values.ga_len; ++i) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2771 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2772 vp = (bval_T *)values.ga_data + i; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2773 if (vp->bv_type == BVAL_STRING && vp->bv_allocated) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2774 vim_free(vp->bv_string); |
19364
b7abf45d527b
patch 8.2.0240: using memory after it was freed
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
2775 vim_free(vp->bv_tofree); |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2776 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2777 ga_clear(&values); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2778 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2779 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2780 if (read_next) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2781 return viminfo_readline(virp); |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2782 return FALSE; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2783 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17466
diff
changeset
|
2784 |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2785 /* |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2786 * read_viminfo_up_to_marks() -- Only called from do_viminfo(). Reads in the |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2787 * first part of the viminfo file which contains everything but the marks that |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2788 * are local to a file. Returns TRUE when end-of-file is reached. -- webb |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2789 */ |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2790 static int |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2791 read_viminfo_up_to_marks( |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2792 vir_T *virp, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2793 int forceit, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2794 int writing) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2795 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2796 int eof; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2797 buf_T *buf; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2798 int got_encoding = FALSE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2799 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2800 prepare_viminfo_history(forceit ? 9999 : 0, writing); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2801 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2802 eof = viminfo_readline(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2803 while (!eof && virp->vir_line[0] != '>') |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2804 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2805 switch (virp->vir_line[0]) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2806 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2807 // Characters reserved for future expansion, ignored now |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2808 case '+': // "+40 /path/dir file", for running vim without args |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2809 case '^': // to be defined |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2810 case '<': // long line - ignored |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2811 // A comment or empty line. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2812 case NUL: |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2813 case '\r': |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2814 case '\n': |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2815 case '#': |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2816 eof = viminfo_readline(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2817 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2818 case '|': |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2819 eof = read_viminfo_barline(virp, got_encoding, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2820 forceit, writing); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2821 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2822 case '*': // "*encoding=value" |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2823 got_encoding = TRUE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2824 eof = viminfo_encoding(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2825 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2826 case '!': // global variable |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2827 #ifdef FEAT_EVAL |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2828 eof = read_viminfo_varlist(virp, writing); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2829 #else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2830 eof = viminfo_readline(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2831 #endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2832 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2833 case '%': // entry for buffer list |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2834 eof = read_viminfo_bufferlist(virp, writing); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2835 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2836 case '"': |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2837 // When registers are in bar lines skip the old style register |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2838 // lines. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2839 if (virp->vir_version < VIMINFO_VERSION_WITH_REGISTERS) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2840 eof = read_viminfo_register(virp, forceit); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2841 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2842 do { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2843 eof = viminfo_readline(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2844 } while (!eof && (virp->vir_line[0] == TAB |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2845 || virp->vir_line[0] == '<')); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2846 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2847 case '/': // Search string |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2848 case '&': // Substitute search string |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2849 case '~': // Last search string, followed by '/' or '&' |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2850 eof = read_viminfo_search_pattern(virp, forceit); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2851 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2852 case '$': |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2853 eof = read_viminfo_sub_string(virp, forceit); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2854 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2855 case ':': |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2856 case '?': |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2857 case '=': |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2858 case '@': |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2859 // When history is in bar lines skip the old style history |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2860 // lines. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2861 if (virp->vir_version < VIMINFO_VERSION_WITH_HISTORY) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2862 eof = read_viminfo_history(virp, writing); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2863 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2864 eof = viminfo_readline(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2865 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2866 case '-': |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2867 case '\'': |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2868 // When file marks are in bar lines skip the old style lines. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2869 if (virp->vir_version < VIMINFO_VERSION_WITH_MARKS) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2870 eof = read_viminfo_filemark(virp, forceit); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2871 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2872 eof = viminfo_readline(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2873 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2874 default: |
26917
d91aea2a612c
patch 8.2.3987: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26893
diff
changeset
|
2875 if (viminfo_error("E575: ", _(e_illegal_starting_char), |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2876 virp->vir_line)) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2877 eof = TRUE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2878 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2879 eof = viminfo_readline(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2880 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2881 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2882 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2883 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2884 // Finish reading history items. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2885 if (!writing) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2886 finish_viminfo_history(virp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2887 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2888 // Change file names to buffer numbers for fmarks. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2889 FOR_ALL_BUFFERS(buf) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2890 fmarks_check_names(buf); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2891 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2892 return eof; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2893 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2894 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2895 /* |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2896 * do_viminfo() -- Should only be called from read_viminfo() & write_viminfo(). |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2897 */ |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2898 static void |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2899 do_viminfo(FILE *fp_in, FILE *fp_out, int flags) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2900 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2901 int eof = FALSE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2902 vir_T vir; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2903 int merge = FALSE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2904 int do_copy_marks = FALSE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2905 garray_T buflist; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2906 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2907 if ((vir.vir_line = alloc(LSIZE)) == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2908 return; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2909 vir.vir_fd = fp_in; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2910 vir.vir_conv.vc_type = CONV_NONE; |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
2911 ga_init2(&vir.vir_barlines, sizeof(char_u *), 100); |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2912 vir.vir_version = -1; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2913 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2914 if (fp_in != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2915 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2916 if (flags & VIF_WANT_INFO) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2917 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2918 if (fp_out != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2919 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2920 // Registers and marks are read and kept separate from what |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2921 // this Vim is using. They are merged when writing. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2922 prepare_viminfo_registers(); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2923 prepare_viminfo_marks(); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2924 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2925 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2926 eof = read_viminfo_up_to_marks(&vir, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2927 flags & VIF_FORCEIT, fp_out != NULL); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2928 merge = TRUE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2929 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2930 else if (flags != 0) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2931 // Skip info, find start of marks |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2932 while (!(eof = viminfo_readline(&vir)) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2933 && vir.vir_line[0] != '>') |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2934 ; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2935 |
23903
402f1d8653c1
patch 8.2.2494: ":rviminfo!" clears most of oldfiles
Bram Moolenaar <Bram@vim.org>
parents:
22029
diff
changeset
|
2936 do_copy_marks = (flags & (VIF_WANT_MARKS | VIF_ONLY_CURBUF |
402f1d8653c1
patch 8.2.2494: ":rviminfo!" clears most of oldfiles
Bram Moolenaar <Bram@vim.org>
parents:
22029
diff
changeset
|
2937 | VIF_GET_OLDFILES | VIF_FORCEIT)); |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2938 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2939 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2940 if (fp_out != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2941 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2942 // Write the info: |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2943 fprintf(fp_out, _("# This viminfo file was generated by Vim %s.\n"), |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2944 VIM_VERSION_MEDIUM); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2945 fputs(_("# You may edit it if you're careful!\n\n"), fp_out); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2946 write_viminfo_version(fp_out); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2947 fputs(_("# Value of 'encoding' when this file was written\n"), fp_out); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2948 fprintf(fp_out, "*encoding=%s\n\n", p_enc); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2949 write_viminfo_search_pattern(fp_out); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2950 write_viminfo_sub_string(fp_out); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2951 write_viminfo_history(fp_out, merge); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2952 write_viminfo_registers(fp_out); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2953 finish_viminfo_registers(); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2954 #ifdef FEAT_EVAL |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2955 write_viminfo_varlist(fp_out); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2956 #endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2957 write_viminfo_filemarks(fp_out); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2958 finish_viminfo_marks(); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2959 write_viminfo_bufferlist(fp_out); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2960 write_viminfo_barlines(&vir, fp_out); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2961 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2962 if (do_copy_marks) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2963 ga_init2(&buflist, sizeof(buf_T *), 50); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2964 write_viminfo_marks(fp_out, do_copy_marks ? &buflist : NULL); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2965 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2966 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2967 if (do_copy_marks) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2968 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2969 copy_viminfo_marks(&vir, fp_out, &buflist, eof, flags); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2970 if (fp_out != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2971 ga_clear(&buflist); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2972 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2973 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2974 vim_free(vir.vir_line); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2975 if (vir.vir_conv.vc_type != CONV_NONE) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2976 convert_setup(&vir.vir_conv, NULL, NULL); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2977 ga_clear_strings(&vir.vir_barlines); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2978 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2979 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2980 /* |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2981 * read_viminfo() -- Read the viminfo file. Registers etc. which are already |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2982 * set are not over-written unless "flags" includes VIF_FORCEIT. -- webb |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2983 */ |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2984 int |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2985 read_viminfo( |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2986 char_u *file, // file name or NULL to use default name |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2987 int flags) // VIF_WANT_INFO et al. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2988 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2989 FILE *fp; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2990 char_u *fname; |
21580
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
2991 stat_T st; // mch_stat() of existing viminfo file |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2992 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2993 if (no_viminfo()) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2994 return FAIL; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2995 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2996 fname = viminfo_filename(file); // get file name in allocated buffer |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2997 if (fname == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2998 return FAIL; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2999 fp = mch_fopen((char *)fname, READBIN); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3000 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3001 if (p_verbose > 0) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3002 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3003 verbose_enter(); |
19760
9daed26b788b
patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents:
19364
diff
changeset
|
3004 smsg(_("Reading viminfo file \"%s\"%s%s%s%s"), |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3005 fname, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3006 (flags & VIF_WANT_INFO) ? _(" info") : "", |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3007 (flags & VIF_WANT_MARKS) ? _(" marks") : "", |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3008 (flags & VIF_GET_OLDFILES) ? _(" oldfiles") : "", |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3009 fp == NULL ? _(" FAILED") : ""); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3010 verbose_leave(); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3011 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3012 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3013 vim_free(fname); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3014 if (fp == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3015 return FAIL; |
21580
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3016 if (mch_fstat(fileno(fp), &st) < 0 || S_ISDIR(st.st_mode)) |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3017 { |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3018 fclose(fp); |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3019 return FAIL; |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3020 } |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3021 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3022 viminfo_errcnt = 0; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3023 do_viminfo(fp, NULL, flags); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3024 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3025 fclose(fp); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3026 return OK; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3027 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3028 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3029 /* |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3030 * Write the viminfo file. The old one is read in first so that effectively a |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3031 * merge of current info and old info is done. This allows multiple vims to |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3032 * run simultaneously, without losing any marks etc. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3033 * If "forceit" is TRUE, then the old file is not read in, and only internal |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3034 * info is written to the file. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3035 */ |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3036 void |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3037 write_viminfo(char_u *file, int forceit) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3038 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3039 char_u *fname; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3040 FILE *fp_in = NULL; // input viminfo file, if any |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3041 FILE *fp_out = NULL; // output viminfo file |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3042 char_u *tempname = NULL; // name of temp viminfo file |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3043 stat_T st_new; // mch_stat() of potential new file |
21580
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3044 stat_T st_old; // mch_stat() of existing viminfo file |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3045 #if defined(UNIX) || defined(VMS) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3046 mode_t umask_save; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3047 #endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3048 #ifdef UNIX |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3049 int shortname = FALSE; // use 8.3 file name |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3050 #endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3051 #ifdef MSWIN |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3052 int hidden = FALSE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3053 #endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3054 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3055 if (no_viminfo()) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3056 return; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3057 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3058 fname = viminfo_filename(file); // may set to default if NULL |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3059 if (fname == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3060 return; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3061 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3062 fp_in = mch_fopen((char *)fname, READBIN); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3063 if (fp_in == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3064 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3065 int fd; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3066 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3067 // if it does exist, but we can't read it, don't try writing |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3068 if (mch_stat((char *)fname, &st_new) == 0) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3069 goto end; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3070 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3071 // Create the new .viminfo non-accessible for others, because it may |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3072 // contain text from non-accessible documents. It is up to the user to |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3073 // widen access (e.g. to a group). This may also fail if there is a |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3074 // race condition, then just give up. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3075 fd = mch_open((char *)fname, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3076 O_CREAT|O_EXTRA|O_EXCL|O_WRONLY|O_NOFOLLOW, 0600); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3077 if (fd < 0) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3078 goto end; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3079 fp_out = fdopen(fd, WRITEBIN); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3080 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3081 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3082 { |
18263
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3083 // There is an existing viminfo file. Create a temporary file to |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3084 // write the new viminfo into, in the same directory as the |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3085 // existing viminfo file, which will be renamed once all writing is |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3086 // successful. |
21580
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3087 if (mch_fstat(fileno(fp_in), &st_old) < 0 |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3088 || S_ISDIR(st_old.st_mode) |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3089 #ifdef UNIX |
21580
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3090 // For Unix we check the owner of the file. It's not very nice |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3091 // to overwrite a user's viminfo file after a "su root", with a |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3092 // viminfo file that the user can't read. |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3093 || (getuid() != ROOT_UID |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3094 && !(st_old.st_uid == getuid() |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3095 ? (st_old.st_mode & 0200) |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3096 : (st_old.st_gid == getgid() |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3097 ? (st_old.st_mode & 0020) |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3098 : (st_old.st_mode & 0002)))) |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3099 #endif |
93dae47699fb
patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
20735
diff
changeset
|
3100 ) |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3101 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3102 int tt = msg_didany; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3103 |
29960
4fcf816aa806
patch 9.0.0318: clearing screen causes flicker
Bram Moolenaar <Bram@vim.org>
parents:
29849
diff
changeset
|
3104 // avoid a wait_return() for this message, it's annoying |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26532
diff
changeset
|
3105 semsg(_(e_viminfo_file_is_not_writable_str), fname); |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3106 msg_didany = tt; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3107 fclose(fp_in); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3108 goto end; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3109 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3110 #ifdef MSWIN |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3111 // Get the file attributes of the existing viminfo file. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3112 hidden = mch_ishidden(fname); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3113 #endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3114 |
18263
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3115 // Make tempname, find one that does not exist yet. |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3116 // Beware of a race condition: If someone logs out and all Vim |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3117 // instances exit at the same time a temp file might be created between |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3118 // stat() and open(). Use mch_open() with O_EXCL to avoid that. |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3119 // May try twice: Once normal and once with shortname set, just in |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3120 // case somebody puts his viminfo file in an 8.3 filesystem. |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3121 for (;;) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3122 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3123 int next_char = 'z'; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3124 char_u *wp; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3125 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3126 tempname = buf_modname( |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3127 #ifdef UNIX |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3128 shortname, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3129 #else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3130 FALSE, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3131 #endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3132 fname, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3133 #ifdef VMS |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3134 (char_u *)"-tmp", |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3135 #else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3136 (char_u *)".tmp", |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3137 #endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3138 FALSE); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3139 if (tempname == NULL) // out of memory |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3140 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3141 |
18263
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3142 // Try a series of names. Change one character, just before |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3143 // the extension. This should also work for an 8.3 |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3144 // file name, when after adding the extension it still is |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3145 // the same file as the original. |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3146 wp = tempname + STRLEN(tempname) - 5; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3147 if (wp < gettail(tempname)) // empty file name? |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3148 wp = gettail(tempname); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3149 for (;;) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3150 { |
18263
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3151 // Check if tempfile already exists. Never overwrite an |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3152 // existing file! |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3153 if (mch_stat((char *)tempname, &st_new) == 0) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3154 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3155 #ifdef UNIX |
18263
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3156 // Check if tempfile is same as original file. May happen |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3157 // when modname() gave the same file back. E.g. silly |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3158 // link, or file name-length reached. Try again with |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3159 // shortname set. |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3160 if (!shortname && st_new.st_dev == st_old.st_dev |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3161 && st_new.st_ino == st_old.st_ino) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3162 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3163 VIM_CLEAR(tempname); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3164 shortname = TRUE; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3165 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3166 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3167 #endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3168 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3169 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3170 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3171 // Try creating the file exclusively. This may fail if |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3172 // another Vim tries to do it at the same time. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3173 #ifdef VMS |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3174 // fdopen() fails for some reason |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3175 umask_save = umask(077); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3176 fp_out = mch_fopen((char *)tempname, WRITEBIN); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3177 (void)umask(umask_save); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3178 #else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3179 int fd; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3180 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3181 // Use mch_open() to be able to use O_NOFOLLOW and set file |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3182 // protection: |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3183 // Unix: same as original file, but strip s-bit. Reset |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3184 // umask to avoid it getting in the way. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3185 // Others: r&w for user only. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3186 # ifdef UNIX |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3187 umask_save = umask(0); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3188 fd = mch_open((char *)tempname, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3189 O_CREAT|O_EXTRA|O_EXCL|O_WRONLY|O_NOFOLLOW, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3190 (int)((st_old.st_mode & 0777) | 0600)); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3191 (void)umask(umask_save); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3192 # else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3193 fd = mch_open((char *)tempname, |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3194 O_CREAT|O_EXTRA|O_EXCL|O_WRONLY|O_NOFOLLOW, 0600); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3195 # endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3196 if (fd < 0) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3197 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3198 fp_out = NULL; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3199 # ifdef EEXIST |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3200 // Avoid trying lots of names while the problem is lack |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3201 // of permission, only retry if the file already |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3202 // exists. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3203 if (errno != EEXIST) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3204 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3205 # endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3206 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3207 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3208 fp_out = fdopen(fd, WRITEBIN); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3209 #endif // VMS |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3210 if (fp_out != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3211 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3212 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3213 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3214 // Assume file exists, try again with another name. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3215 if (next_char == 'a' - 1) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3216 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3217 // They all exist? Must be something wrong! Don't write |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3218 // the viminfo file then. |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26917
diff
changeset
|
3219 semsg(_(e_too_many_viminfo_temp_files_like_str), tempname); |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3220 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3221 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3222 *wp = next_char; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3223 --next_char; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3224 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3225 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3226 if (tempname != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3227 break; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3228 // continue if shortname was set |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3229 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3230 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3231 #if defined(UNIX) && defined(HAVE_FCHOWN) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3232 if (tempname != NULL && fp_out != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3233 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3234 stat_T tmp_st; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3235 |
18263
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3236 // Make sure the original owner can read/write the tempfile and |
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3237 // otherwise preserve permissions, making sure the group matches. |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3238 if (mch_stat((char *)tempname, &tmp_st) >= 0) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3239 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3240 if (st_old.st_uid != tmp_st.st_uid) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3241 // Changing the owner might fail, in which case the |
18498
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
18463
diff
changeset
|
3242 // file will now be owned by the current user, oh well. |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3243 vim_ignored = fchown(fileno(fp_out), st_old.st_uid, -1); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3244 if (st_old.st_gid != tmp_st.st_gid |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3245 && fchown(fileno(fp_out), -1, st_old.st_gid) == -1) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3246 // can't set the group to what it should be, remove |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3247 // group permissions |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3248 (void)mch_setperm(tempname, 0600); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3249 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3250 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3251 // can't stat the file, set conservative permissions |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3252 (void)mch_setperm(tempname, 0600); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3253 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3254 #endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3255 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3256 |
18263
a5de1d88590d
patch 8.1.2126: viminfo not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
3257 // Check if the new viminfo file can be written to. |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3258 if (fp_out == NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3259 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26532
diff
changeset
|
3260 semsg(_(e_cant_write_viminfo_file_str), |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3261 (fp_in == NULL || tempname == NULL) ? fname : tempname); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3262 if (fp_in != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3263 fclose(fp_in); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3264 goto end; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3265 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3266 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3267 if (p_verbose > 0) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3268 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3269 verbose_enter(); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3270 smsg(_("Writing viminfo file \"%s\""), fname); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3271 verbose_leave(); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3272 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3273 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3274 viminfo_errcnt = 0; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3275 do_viminfo(fp_in, fp_out, forceit ? 0 : (VIF_WANT_INFO | VIF_WANT_MARKS)); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3276 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3277 if (fclose(fp_out) == EOF) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3278 ++viminfo_errcnt; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3279 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3280 if (fp_in != NULL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3281 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3282 fclose(fp_in); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3283 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3284 // In case of an error keep the original viminfo file. Otherwise |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3285 // rename the newly written file. Give an error if that fails. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3286 if (viminfo_errcnt == 0) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3287 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3288 if (vim_rename(tempname, fname) == -1) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3289 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3290 ++viminfo_errcnt; |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26917
diff
changeset
|
3291 semsg(_(e_cant_rename_viminfo_file_to_str), fname); |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3292 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3293 # ifdef MSWIN |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3294 // If the viminfo file was hidden then also hide the new file. |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3295 else if (hidden) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3296 mch_hide(fname); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3297 # endif |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3298 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3299 if (viminfo_errcnt > 0) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3300 mch_remove(tempname); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3301 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3302 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3303 end: |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3304 vim_free(fname); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3305 vim_free(tempname); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3306 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3307 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3308 /* |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3309 * ":rviminfo" and ":wviminfo". |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3310 */ |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3311 void |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3312 ex_viminfo( |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3313 exarg_T *eap) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3314 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3315 char_u *save_viminfo; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3316 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3317 save_viminfo = p_viminfo; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3318 if (*p_viminfo == NUL) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3319 p_viminfo = (char_u *)"'100"; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3320 if (eap->cmdidx == CMD_rviminfo) |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3321 { |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3322 if (read_viminfo(eap->arg, VIF_WANT_INFO | VIF_WANT_MARKS |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3323 | (eap->forceit ? VIF_FORCEIT : 0)) == FAIL) |
26893
79c76ca2c53c
patch 8.2.3975: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26757
diff
changeset
|
3324 emsg(_(e_cannot_open_viminfo_file_for_reading)); |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3325 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3326 else |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3327 write_viminfo(eap->arg, eap->forceit); |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3328 p_viminfo = save_viminfo; |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3329 } |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3330 |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3331 #endif // FEAT_VIMINFO |