Mercurial > vim
annotate src/misc1.c @ 18104:e59ff7b5d7a7 v8.1.2047
patch 8.1.2047: cannot check the current state
Commit: https://github.com/vim/vim/commit/0e57dd859ecb1e8a3b91509d2f4343e839340eb8
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 16 22:56:03 2019 +0200
patch 8.1.2047: cannot check the current state
Problem: Cannot check the current state.
Solution: Add the state() function.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 16 Sep 2019 23:00:04 +0200 |
parents | d1e77015f60b |
children | 1868ec23360e |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10002
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * misc1.c: functions that didn't seem to fit elsewhere | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 #include "version.h" | |
16 | |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17452
diff
changeset
|
17 #if defined(MSWIN) |
14133
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
18 # include <lm.h> |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
19 #endif |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
20 |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
21 #define URL_SLASH 1 /* path_is_url() has found "://" */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
22 #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
23 |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17452
diff
changeset
|
24 // All user names (for ~user completion as done by shell). |
3744 | 25 static garray_T ga_users; |
26 | |
7 | 27 /* |
28 * Count the size (in window cells) of the indent in the current line. | |
29 */ | |
30 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
31 get_indent(void) |
7 | 32 { |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
33 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
34 return get_indent_str_vtab(ml_get_curline(), (int)curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
35 curbuf->b_p_vts_array, FALSE); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
36 #else |
5995 | 37 return get_indent_str(ml_get_curline(), (int)curbuf->b_p_ts, FALSE); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
38 #endif |
7 | 39 } |
40 | |
41 /* | |
42 * Count the size (in window cells) of the indent in line "lnum". | |
43 */ | |
44 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
45 get_indent_lnum(linenr_T lnum) |
7 | 46 { |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
47 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
48 return get_indent_str_vtab(ml_get(lnum), (int)curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
49 curbuf->b_p_vts_array, FALSE); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
50 #else |
5995 | 51 return get_indent_str(ml_get(lnum), (int)curbuf->b_p_ts, FALSE); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
52 #endif |
7 | 53 } |
54 | |
55 #if defined(FEAT_FOLDING) || defined(PROTO) | |
56 /* | |
57 * Count the size (in window cells) of the indent in line "lnum" of buffer | |
58 * "buf". | |
59 */ | |
60 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
61 get_indent_buf(buf_T *buf, linenr_T lnum) |
7 | 62 { |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
63 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
64 return get_indent_str_vtab(ml_get_buf(buf, lnum, FALSE), |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
65 (int)curbuf->b_p_ts, buf->b_p_vts_array, FALSE); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
66 #else |
5995 | 67 return get_indent_str(ml_get_buf(buf, lnum, FALSE), (int)buf->b_p_ts, FALSE); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
68 #endif |
7 | 69 } |
70 #endif | |
71 | |
72 /* | |
73 * count the size (in window cells) of the indent in line "ptr", with | |
74 * 'tabstop' at "ts" | |
75 */ | |
164 | 76 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
77 get_indent_str( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
78 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
79 int ts, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
80 int list) /* if TRUE, count only screen size for tabs */ |
7 | 81 { |
82 int count = 0; | |
83 | |
84 for ( ; *ptr; ++ptr) | |
85 { | |
5995 | 86 if (*ptr == TAB) |
87 { | |
88 if (!list || lcs_tab1) /* count a tab for what it is worth */ | |
89 count += ts - (count % ts); | |
90 else | |
6174 | 91 /* In list mode, when tab is not set, count screen char width |
92 * for Tab, displays: ^I */ | |
5995 | 93 count += ptr2cells(ptr); |
94 } | |
7 | 95 else if (*ptr == ' ') |
96 ++count; /* count a space for one */ | |
97 else | |
98 break; | |
99 } | |
164 | 100 return count; |
7 | 101 } |
102 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
103 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
104 /* |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
105 * Count the size (in window cells) of the indent in line "ptr", using |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
106 * variable tabstops. |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
107 * if "list" is TRUE, count only screen size for tabs. |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
108 */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
109 int |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
110 get_indent_str_vtab(char_u *ptr, int ts, int *vts, int list) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
111 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
112 int count = 0; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
113 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
114 for ( ; *ptr; ++ptr) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
115 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
116 if (*ptr == TAB) /* count a tab for what it is worth */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
117 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
118 if (!list || lcs_tab1) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
119 count += tabstop_padding(count, ts, vts); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
120 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
121 /* In list mode, when tab is not set, count screen char width |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
122 * for Tab, displays: ^I */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
123 count += ptr2cells(ptr); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
124 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
125 else if (*ptr == ' ') |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
126 ++count; /* count a space for one */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
127 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
128 break; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
129 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
130 return count; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
131 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
132 #endif |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
133 |
7 | 134 /* |
135 * Set the indent of the current line. | |
136 * Leaves the cursor on the first non-blank in the line. | |
137 * Caller must take care of undo. | |
138 * "flags": | |
139 * SIN_CHANGED: call changed_bytes() if the line was changed. | |
140 * SIN_INSERT: insert the indent in front of the line. | |
141 * SIN_UNDO: save line for undo before changing it. | |
142 * Returns TRUE if the line was changed. | |
143 */ | |
144 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
145 set_indent( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
146 int size, /* measured in spaces */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
147 int flags) |
7 | 148 { |
149 char_u *p; | |
150 char_u *newline; | |
151 char_u *oldline; | |
152 char_u *s; | |
153 int todo; | |
1324 | 154 int ind_len; /* measured in characters */ |
7 | 155 int line_len; |
156 int doit = FALSE; | |
1324 | 157 int ind_done = 0; /* measured in spaces */ |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
158 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
159 int ind_col = 0; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
160 #endif |
7 | 161 int tab_pad; |
217 | 162 int retval = FALSE; |
1359 | 163 int orig_char_len = -1; /* number of initial whitespace chars when |
1324 | 164 'et' and 'pi' are both set */ |
7 | 165 |
166 /* | |
167 * First check if there is anything to do and compute the number of | |
168 * characters needed for the indent. | |
169 */ | |
170 todo = size; | |
171 ind_len = 0; | |
172 p = oldline = ml_get_curline(); | |
173 | |
174 /* Calculate the buffer size for the new indent, and check to see if it | |
175 * isn't already set */ | |
176 | |
1324 | 177 /* if 'expandtab' isn't set: use TABs; if both 'expandtab' and |
178 * 'preserveindent' are set count the number of characters at the | |
179 * beginning of the line to be copied */ | |
180 if (!curbuf->b_p_et || (!(flags & SIN_INSERT) && curbuf->b_p_pi)) | |
7 | 181 { |
182 /* If 'preserveindent' is set then reuse as much as possible of | |
183 * the existing indent structure for the new indent */ | |
184 if (!(flags & SIN_INSERT) && curbuf->b_p_pi) | |
185 { | |
186 ind_done = 0; | |
187 | |
188 /* count as many characters as we can use */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
189 while (todo > 0 && VIM_ISWHITE(*p)) |
7 | 190 { |
191 if (*p == TAB) | |
192 { | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
193 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
194 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
195 curbuf->b_p_vts_array); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
196 #else |
7 | 197 tab_pad = (int)curbuf->b_p_ts |
198 - (ind_done % (int)curbuf->b_p_ts); | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
199 #endif |
7 | 200 /* stop if this tab will overshoot the target */ |
201 if (todo < tab_pad) | |
202 break; | |
203 todo -= tab_pad; | |
204 ++ind_len; | |
205 ind_done += tab_pad; | |
206 } | |
207 else | |
208 { | |
209 --todo; | |
210 ++ind_len; | |
211 ++ind_done; | |
212 } | |
213 ++p; | |
214 } | |
215 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
216 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
217 /* These diverge from this point. */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
218 ind_col = ind_done; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
219 #endif |
1324 | 220 /* Set initial number of whitespace chars to copy if we are |
221 * preserving indent but expandtab is set */ | |
222 if (curbuf->b_p_et) | |
223 orig_char_len = ind_len; | |
224 | |
7 | 225 /* Fill to next tabstop with a tab, if possible */ |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
226 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
227 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
228 curbuf->b_p_vts_array); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
229 #else |
7 | 230 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
231 #endif |
1359 | 232 if (todo >= tab_pad && orig_char_len == -1) |
7 | 233 { |
234 doit = TRUE; | |
235 todo -= tab_pad; | |
236 ++ind_len; | |
237 /* ind_done += tab_pad; */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
238 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
239 ind_col += tab_pad; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
240 #endif |
7 | 241 } |
242 } | |
243 | |
244 /* count tabs required for indent */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
245 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
246 for (;;) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
247 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
248 tab_pad = tabstop_padding(ind_col, curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
249 curbuf->b_p_vts_array); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
250 if (todo < tab_pad) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
251 break; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
252 if (*p != TAB) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
253 doit = TRUE; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
254 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
255 ++p; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
256 todo -= tab_pad; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
257 ++ind_len; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
258 ind_col += tab_pad; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
259 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
260 #else |
7 | 261 while (todo >= (int)curbuf->b_p_ts) |
262 { | |
263 if (*p != TAB) | |
264 doit = TRUE; | |
265 else | |
266 ++p; | |
267 todo -= (int)curbuf->b_p_ts; | |
268 ++ind_len; | |
269 /* ind_done += (int)curbuf->b_p_ts; */ | |
270 } | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
271 #endif |
7 | 272 } |
273 /* count spaces required for indent */ | |
274 while (todo > 0) | |
275 { | |
276 if (*p != ' ') | |
277 doit = TRUE; | |
278 else | |
279 ++p; | |
280 --todo; | |
281 ++ind_len; | |
282 /* ++ind_done; */ | |
283 } | |
284 | |
285 /* Return if the indent is OK already. */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
286 if (!doit && !VIM_ISWHITE(*p) && !(flags & SIN_INSERT)) |
7 | 287 return FALSE; |
288 | |
289 /* Allocate memory for the new line. */ | |
290 if (flags & SIN_INSERT) | |
291 p = oldline; | |
292 else | |
293 p = skipwhite(p); | |
294 line_len = (int)STRLEN(p) + 1; | |
1324 | 295 |
296 /* If 'preserveindent' and 'expandtab' are both set keep the original | |
297 * characters and allocate accordingly. We will fill the rest with spaces | |
298 * after the if (!curbuf->b_p_et) below. */ | |
1359 | 299 if (orig_char_len != -1) |
1324 | 300 { |
301 newline = alloc(orig_char_len + size - ind_done + line_len); | |
302 if (newline == NULL) | |
303 return FALSE; | |
1359 | 304 todo = size - ind_done; |
305 ind_len = orig_char_len + todo; /* Set total length of indent in | |
306 * characters, which may have been | |
307 * undercounted until now */ | |
1324 | 308 p = oldline; |
309 s = newline; | |
310 while (orig_char_len > 0) | |
311 { | |
312 *s++ = *p++; | |
313 orig_char_len--; | |
314 } | |
1474 | 315 |
1324 | 316 /* Skip over any additional white space (useful when newindent is less |
317 * than old) */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
318 while (VIM_ISWHITE(*p)) |
1474 | 319 ++p; |
1348 | 320 |
1324 | 321 } |
322 else | |
323 { | |
324 todo = size; | |
325 newline = alloc(ind_len + line_len); | |
326 if (newline == NULL) | |
327 return FALSE; | |
328 s = newline; | |
329 } | |
7 | 330 |
331 /* Put the characters in the new line. */ | |
332 /* if 'expandtab' isn't set: use TABs */ | |
333 if (!curbuf->b_p_et) | |
334 { | |
335 /* If 'preserveindent' is set then reuse as much as possible of | |
336 * the existing indent structure for the new indent */ | |
337 if (!(flags & SIN_INSERT) && curbuf->b_p_pi) | |
338 { | |
339 p = oldline; | |
340 ind_done = 0; | |
341 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
342 while (todo > 0 && VIM_ISWHITE(*p)) |
7 | 343 { |
344 if (*p == TAB) | |
345 { | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
346 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
347 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
348 curbuf->b_p_vts_array); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
349 #else |
7 | 350 tab_pad = (int)curbuf->b_p_ts |
351 - (ind_done % (int)curbuf->b_p_ts); | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
352 #endif |
7 | 353 /* stop if this tab will overshoot the target */ |
354 if (todo < tab_pad) | |
355 break; | |
356 todo -= tab_pad; | |
357 ind_done += tab_pad; | |
358 } | |
359 else | |
360 { | |
361 --todo; | |
362 ++ind_done; | |
363 } | |
364 *s++ = *p++; | |
365 } | |
366 | |
367 /* Fill to next tabstop with a tab, if possible */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
368 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
369 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
370 curbuf->b_p_vts_array); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
371 #else |
7 | 372 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
373 #endif |
7 | 374 if (todo >= tab_pad) |
375 { | |
376 *s++ = TAB; | |
377 todo -= tab_pad; | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
378 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
379 ind_done += tab_pad; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
380 #endif |
7 | 381 } |
382 | |
383 p = skipwhite(p); | |
384 } | |
385 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
386 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
387 for (;;) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
388 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
389 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
390 curbuf->b_p_vts_array); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
391 if (todo < tab_pad) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
392 break; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
393 *s++ = TAB; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
394 todo -= tab_pad; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
395 ind_done += tab_pad; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
396 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
397 #else |
7 | 398 while (todo >= (int)curbuf->b_p_ts) |
399 { | |
400 *s++ = TAB; | |
401 todo -= (int)curbuf->b_p_ts; | |
402 } | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
403 #endif |
7 | 404 } |
405 while (todo > 0) | |
406 { | |
407 *s++ = ' '; | |
408 --todo; | |
409 } | |
410 mch_memmove(s, p, (size_t)line_len); | |
411 | |
15398
3e02464faaac
patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
412 // Replace the line (unless undo fails). |
7 | 413 if (!(flags & SIN_UNDO) || u_savesub(curwin->w_cursor.lnum) == OK) |
414 { | |
415 ml_replace(curwin->w_cursor.lnum, newline, FALSE); | |
416 if (flags & SIN_CHANGED) | |
417 changed_bytes(curwin->w_cursor.lnum, 0); | |
15398
3e02464faaac
patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
418 |
3e02464faaac
patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
419 // Correct saved cursor position if it is in this line. |
5403 | 420 if (saved_cursor.lnum == curwin->w_cursor.lnum) |
421 { | |
422 if (saved_cursor.col >= (colnr_T)(p - oldline)) | |
15398
3e02464faaac
patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
423 // cursor was after the indent, adjust for the number of |
3e02464faaac
patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
424 // bytes added/removed |
5403 | 425 saved_cursor.col += ind_len - (colnr_T)(p - oldline); |
426 else if (saved_cursor.col >= (colnr_T)(s - newline)) | |
15398
3e02464faaac
patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
427 // cursor was in the indent, and is now after it, put it back |
3e02464faaac
patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
428 // at the start of the indent (replacing spaces with TAB) |
5403 | 429 saved_cursor.col = (colnr_T)(s - newline); |
430 } | |
15398
3e02464faaac
patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
431 #ifdef FEAT_TEXT_PROP |
16682
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16632
diff
changeset
|
432 { |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16632
diff
changeset
|
433 int added = ind_len - (colnr_T)(p - oldline); |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16632
diff
changeset
|
434 |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16632
diff
changeset
|
435 // When increasing indent this behaves like spaces were inserted at |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16632
diff
changeset
|
436 // the old indent, when decreasing indent it behaves like spaces |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16632
diff
changeset
|
437 // were deleted at the new indent. |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16632
diff
changeset
|
438 adjust_prop_columns(curwin->w_cursor.lnum, |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
439 (colnr_T)(added > 0 ? (p - oldline) : ind_len), added, 0); |
16682
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16632
diff
changeset
|
440 } |
15398
3e02464faaac
patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
441 #endif |
217 | 442 retval = TRUE; |
7 | 443 } |
444 else | |
445 vim_free(newline); | |
446 | |
447 curwin->w_cursor.col = ind_len; | |
217 | 448 return retval; |
7 | 449 } |
450 | |
451 /* | |
452 * Return the indent of the current line after a number. Return -1 if no | |
453 * number was found. Used for 'n' in 'formatoptions': numbered list. | |
41 | 454 * Since a pattern is used it can actually handle more than numbers. |
7 | 455 */ |
456 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
457 get_number_indent(linenr_T lnum) |
7 | 458 { |
459 colnr_T col; | |
460 pos_T pos; | |
461 | |
3632 | 462 regmatch_T regmatch; |
463 int lead_len = 0; /* length of comment leader */ | |
464 | |
7 | 465 if (lnum > curbuf->b_ml.ml_line_count) |
466 return -1; | |
41 | 467 pos.lnum = 0; |
3584 | 468 |
469 #ifdef FEAT_COMMENTS | |
3632 | 470 /* In format_lines() (i.e. not insert mode), fo+=q is needed too... */ |
471 if ((State & INSERT) || has_format_option(FO_Q_COMS)) | |
3584 | 472 lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE); |
3632 | 473 #endif |
474 regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC); | |
475 if (regmatch.regprog != NULL) | |
476 { | |
477 regmatch.rm_ic = FALSE; | |
478 | |
479 /* vim_regexec() expects a pointer to a line. This lets us | |
480 * start matching for the flp beyond any comment leader... */ | |
481 if (vim_regexec(®match, ml_get(lnum) + lead_len, (colnr_T)0)) | |
482 { | |
483 pos.lnum = lnum; | |
484 pos.col = (colnr_T)(*regmatch.endp - ml_get(lnum)); | |
485 pos.coladd = 0; | |
486 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4752
diff
changeset
|
487 vim_regfree(regmatch.regprog); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4752
diff
changeset
|
488 } |
41 | 489 |
490 if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL) | |
7 | 491 return -1; |
492 getvcol(curwin, &pos, &col, NULL, NULL); | |
493 return (int)col; | |
494 } | |
495 | |
5995 | 496 #if defined(FEAT_LINEBREAK) || defined(PROTO) |
497 /* | |
498 * Return appropriate space number for breakindent, taking influencing | |
499 * parameters into account. Window must be specified, since it is not | |
500 * necessarily always the current one. | |
501 */ | |
502 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
503 get_breakindent_win( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
504 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
505 char_u *line) /* start of the line */ |
5995 | 506 { |
507 static int prev_indent = 0; /* cached indent value */ | |
508 static long prev_ts = 0L; /* cached tabstop value */ | |
509 static char_u *prev_line = NULL; /* cached pointer to line */ | |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10807
diff
changeset
|
510 static varnumber_T prev_tick = 0; /* changedtick of cached value */ |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
511 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
512 static int *prev_vts = NULL; /* cached vartabs values */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
513 #endif |
5995 | 514 int bri = 0; |
515 /* window width minus window margin space, i.e. what rests for text */ | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
516 const int eff_wwidth = wp->w_width |
5995 | 517 - ((wp->w_p_nu || wp->w_p_rnu) |
518 && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL) | |
519 ? number_width(wp) + 1 : 0); | |
520 | |
521 /* used cached indent, unless pointer or 'tabstop' changed */ | |
6010 | 522 if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
523 || prev_tick != CHANGEDTICK(wp->w_buffer) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
524 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
525 || prev_vts != wp->w_buffer->b_p_vts_array |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
526 #endif |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
527 ) |
5995 | 528 { |
529 prev_line = line; | |
530 prev_ts = wp->w_buffer->b_p_ts; | |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10932
diff
changeset
|
531 prev_tick = CHANGEDTICK(wp->w_buffer); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
532 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
533 prev_vts = wp->w_buffer->b_p_vts_array; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
534 prev_indent = get_indent_str_vtab(line, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
535 (int)wp->w_buffer->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
536 wp->w_buffer->b_p_vts_array, wp->w_p_list); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
537 #else |
5995 | 538 prev_indent = get_indent_str(line, |
6012 | 539 (int)wp->w_buffer->b_p_ts, wp->w_p_list); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14133
diff
changeset
|
540 #endif |
6012 | 541 } |
542 bri = prev_indent + wp->w_p_brishift; | |
5995 | 543 |
544 /* indent minus the length of the showbreak string */ | |
545 if (wp->w_p_brisbr) | |
546 bri -= vim_strsize(p_sbr); | |
547 | |
548 /* Add offset for number column, if 'n' is in 'cpoptions' */ | |
549 bri += win_col_off2(wp); | |
550 | |
551 /* never indent past left window margin */ | |
552 if (bri < 0) | |
553 bri = 0; | |
554 /* always leave at least bri_min characters on the left, | |
555 * if text width is sufficient */ | |
556 else if (bri > eff_wwidth - wp->w_p_brimin) | |
557 bri = (eff_wwidth - wp->w_p_brimin < 0) | |
558 ? 0 : eff_wwidth - wp->w_p_brimin; | |
559 | |
560 return bri; | |
561 } | |
562 #endif | |
563 | |
7 | 564 #if defined(FEAT_COMMENTS) || defined(PROTO) |
565 /* | |
5403 | 566 * get_leader_len() returns the length in bytes of the prefix of the given |
567 * string which introduces a comment. If this string is not a comment then | |
568 * 0 is returned. | |
7 | 569 * When "flags" is not NULL, it is set to point to the flags of the recognized |
570 * comment leader. | |
571 * "backward" must be true for the "O" command. | |
3562 | 572 * If "include_space" is set, include trailing whitespace while calculating the |
573 * length. | |
7 | 574 */ |
575 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
576 get_leader_len( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
577 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
578 char_u **flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
579 int backward, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
580 int include_space) |
7 | 581 { |
582 int i, j; | |
3562 | 583 int result; |
7 | 584 int got_com = FALSE; |
585 int found_one; | |
586 char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */ | |
587 char_u *string; /* pointer to comment string */ | |
588 char_u *list; | |
2809 | 589 int middle_match_len = 0; |
590 char_u *prev_list; | |
2813 | 591 char_u *saved_flags = NULL; |
7 | 592 |
3562 | 593 result = i = 0; |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
594 while (VIM_ISWHITE(line[i])) /* leading white space is ignored */ |
7 | 595 ++i; |
596 | |
597 /* | |
598 * Repeat to match several nested comment strings. | |
599 */ | |
2809 | 600 while (line[i] != NUL) |
7 | 601 { |
602 /* | |
603 * scan through the 'comments' option for a match | |
604 */ | |
605 found_one = FALSE; | |
606 for (list = curbuf->b_p_com; *list; ) | |
607 { | |
2809 | 608 /* Get one option part into part_buf[]. Advance "list" to next |
609 * one. Put "string" at start of string. */ | |
610 if (!got_com && flags != NULL) | |
611 *flags = list; /* remember where flags started */ | |
612 prev_list = list; | |
7 | 613 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); |
614 string = vim_strchr(part_buf, ':'); | |
615 if (string == NULL) /* missing ':', ignore this part */ | |
616 continue; | |
617 *string++ = NUL; /* isolate flags from string */ | |
618 | |
2809 | 619 /* If we found a middle match previously, use that match when this |
620 * is not a middle or end. */ | |
621 if (middle_match_len != 0 | |
622 && vim_strchr(part_buf, COM_MIDDLE) == NULL | |
623 && vim_strchr(part_buf, COM_END) == NULL) | |
624 break; | |
625 | |
626 /* When we already found a nested comment, only accept further | |
627 * nested comments. */ | |
7 | 628 if (got_com && vim_strchr(part_buf, COM_NEST) == NULL) |
629 continue; | |
630 | |
2809 | 631 /* When 'O' flag present and using "O" command skip this one. */ |
7 | 632 if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL) |
633 continue; | |
634 | |
2809 | 635 /* Line contents and string must match. |
7 | 636 * When string starts with white space, must have some white space |
637 * (but the amount does not need to match, there might be a mix of | |
2809 | 638 * TABs and spaces). */ |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
639 if (VIM_ISWHITE(string[0])) |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
640 { |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
641 if (i == 0 || !VIM_ISWHITE(line[i - 1])) |
4352 | 642 continue; /* missing white space */ |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
643 while (VIM_ISWHITE(string[0])) |
7 | 644 ++string; |
645 } | |
646 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) | |
647 ; | |
648 if (string[j] != NUL) | |
2809 | 649 continue; /* string doesn't match */ |
650 | |
651 /* When 'b' flag used, there must be white space or an | |
652 * end-of-line after the string in the line. */ | |
7 | 653 if (vim_strchr(part_buf, COM_BLANK) != NULL |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
654 && !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL) |
7 | 655 continue; |
656 | |
2809 | 657 /* We have found a match, stop searching unless this is a middle |
658 * comment. The middle comment can be a substring of the end | |
659 * comment in which case it's better to return the length of the | |
660 * end comment and its flags. Thus we keep searching with middle | |
661 * and end matches and use an end match if it matches better. */ | |
662 if (vim_strchr(part_buf, COM_MIDDLE) != NULL) | |
663 { | |
664 if (middle_match_len == 0) | |
665 { | |
666 middle_match_len = j; | |
667 saved_flags = prev_list; | |
668 } | |
669 continue; | |
670 } | |
671 if (middle_match_len != 0 && j > middle_match_len) | |
672 /* Use this match instead of the middle match, since it's a | |
673 * longer thus better match. */ | |
674 middle_match_len = 0; | |
675 | |
676 if (middle_match_len == 0) | |
677 i += j; | |
7 | 678 found_one = TRUE; |
679 break; | |
680 } | |
681 | |
2809 | 682 if (middle_match_len != 0) |
683 { | |
684 /* Use the previously found middle match after failing to find a | |
685 * match with an end. */ | |
686 if (!got_com && flags != NULL) | |
687 *flags = saved_flags; | |
688 i += middle_match_len; | |
689 found_one = TRUE; | |
690 } | |
691 | |
692 /* No match found, stop scanning. */ | |
7 | 693 if (!found_one) |
694 break; | |
695 | |
3562 | 696 result = i; |
697 | |
2809 | 698 /* Include any trailing white space. */ |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
699 while (VIM_ISWHITE(line[i])) |
7 | 700 ++i; |
701 | |
3562 | 702 if (include_space) |
703 result = i; | |
704 | |
2809 | 705 /* If this comment doesn't nest, stop here. */ |
706 got_com = TRUE; | |
7 | 707 if (vim_strchr(part_buf, COM_NEST) == NULL) |
708 break; | |
709 } | |
3562 | 710 return result; |
711 } | |
712 | |
713 /* | |
714 * Return the offset at which the last comment in line starts. If there is no | |
715 * comment in the whole line, -1 is returned. | |
716 * | |
717 * When "flags" is not null, it is set to point to the flags describing the | |
718 * recognized comment leader. | |
719 */ | |
720 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
721 get_last_leader_offset(char_u *line, char_u **flags) |
3562 | 722 { |
723 int result = -1; | |
724 int i, j; | |
725 int lower_check_bound = 0; | |
726 char_u *string; | |
727 char_u *com_leader; | |
728 char_u *com_flags; | |
729 char_u *list; | |
730 int found_one; | |
731 char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */ | |
732 | |
733 /* | |
734 * Repeat to match several nested comment strings. | |
735 */ | |
736 i = (int)STRLEN(line); | |
737 while (--i >= lower_check_bound) | |
738 { | |
739 /* | |
740 * scan through the 'comments' option for a match | |
741 */ | |
742 found_one = FALSE; | |
743 for (list = curbuf->b_p_com; *list; ) | |
744 { | |
745 char_u *flags_save = list; | |
746 | |
747 /* | |
748 * Get one option part into part_buf[]. Advance list to next one. | |
749 * put string at start of string. | |
750 */ | |
751 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); | |
752 string = vim_strchr(part_buf, ':'); | |
753 if (string == NULL) /* If everything is fine, this cannot actually | |
754 * happen. */ | |
755 continue; | |
756 *string++ = NUL; /* Isolate flags from string. */ | |
757 com_leader = string; | |
758 | |
759 /* | |
760 * Line contents and string must match. | |
761 * When string starts with white space, must have some white space | |
762 * (but the amount does not need to match, there might be a mix of | |
763 * TABs and spaces). | |
764 */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
765 if (VIM_ISWHITE(string[0])) |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
766 { |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
767 if (i == 0 || !VIM_ISWHITE(line[i - 1])) |
3562 | 768 continue; |
15119
6e9f37bf987b
patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents:
15046
diff
changeset
|
769 while (VIM_ISWHITE(*string)) |
3562 | 770 ++string; |
771 } | |
772 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) | |
773 /* do nothing */; | |
774 if (string[j] != NUL) | |
775 continue; | |
776 | |
777 /* | |
778 * When 'b' flag used, there must be white space or an | |
779 * end-of-line after the string in the line. | |
780 */ | |
781 if (vim_strchr(part_buf, COM_BLANK) != NULL | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
782 && !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL) |
3562 | 783 continue; |
15119
6e9f37bf987b
patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents:
15046
diff
changeset
|
784 |
15127
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
785 if (vim_strchr(part_buf, COM_MIDDLE) != NULL) |
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
786 { |
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
787 // For a middlepart comment, only consider it to match if |
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
788 // everything before the current position in the line is |
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
789 // whitespace. Otherwise we would think we are inside a |
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
790 // comment if the middle part appears somewhere in the middle |
31a0127813cb
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents:
15119
diff
changeset
|
791 // of the line. E.g. for C the "*" appears often. |
15119
6e9f37bf987b
patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents:
15046
diff
changeset
|
792 for (j = 0; VIM_ISWHITE(line[j]) && j <= i; j++) |
6e9f37bf987b
patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents:
15046
diff
changeset
|
793 ; |
6e9f37bf987b
patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents:
15046
diff
changeset
|
794 if (j < i) |
6e9f37bf987b
patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents:
15046
diff
changeset
|
795 continue; |
3562 | 796 } |
797 | |
798 /* | |
799 * We have found a match, stop searching. | |
800 */ | |
801 found_one = TRUE; | |
802 | |
803 if (flags) | |
804 *flags = flags_save; | |
805 com_flags = flags_save; | |
806 | |
807 break; | |
808 } | |
809 | |
810 if (found_one) | |
811 { | |
812 char_u part_buf2[COM_MAX_LEN]; /* buffer for one option part */ | |
813 int len1, len2, off; | |
814 | |
815 result = i; | |
816 /* | |
817 * If this comment nests, continue searching. | |
818 */ | |
819 if (vim_strchr(part_buf, COM_NEST) != NULL) | |
820 continue; | |
821 | |
822 lower_check_bound = i; | |
823 | |
824 /* Let's verify whether the comment leader found is a substring | |
825 * of other comment leaders. If it is, let's adjust the | |
826 * lower_check_bound so that we make sure that we have determined | |
827 * the comment leader correctly. | |
828 */ | |
829 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
830 while (VIM_ISWHITE(*com_leader)) |
3562 | 831 ++com_leader; |
832 len1 = (int)STRLEN(com_leader); | |
833 | |
834 for (list = curbuf->b_p_com; *list; ) | |
835 { | |
836 char_u *flags_save = list; | |
837 | |
838 (void)copy_option_part(&list, part_buf2, COM_MAX_LEN, ","); | |
839 if (flags_save == com_flags) | |
840 continue; | |
841 string = vim_strchr(part_buf2, ':'); | |
842 ++string; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
843 while (VIM_ISWHITE(*string)) |
3562 | 844 ++string; |
845 len2 = (int)STRLEN(string); | |
846 if (len2 == 0) | |
847 continue; | |
848 | |
849 /* Now we have to verify whether string ends with a substring | |
850 * beginning the com_leader. */ | |
851 for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;) | |
852 { | |
853 --off; | |
854 if (!STRNCMP(string + off, com_leader, len2 - off)) | |
855 { | |
856 if (i - off < lower_check_bound) | |
857 lower_check_bound = i - off; | |
858 } | |
859 } | |
860 } | |
861 } | |
862 } | |
863 return result; | |
7 | 864 } |
865 #endif | |
866 | |
867 /* | |
868 * Return the number of window lines occupied by buffer line "lnum". | |
869 */ | |
870 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
871 plines(linenr_T lnum) |
7 | 872 { |
873 return plines_win(curwin, lnum, TRUE); | |
874 } | |
875 | |
876 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
877 plines_win( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
878 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
879 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
880 int winheight) /* when TRUE limit to window height */ |
7 | 881 { |
882 #if defined(FEAT_DIFF) || defined(PROTO) | |
883 /* Check for filler lines above this buffer line. When folded the result | |
884 * is one line anyway. */ | |
885 return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum); | |
886 } | |
887 | |
888 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
889 plines_nofill(linenr_T lnum) |
7 | 890 { |
891 return plines_win_nofill(curwin, lnum, TRUE); | |
892 } | |
893 | |
894 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
895 plines_win_nofill( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
896 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
897 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
898 int winheight) /* when TRUE limit to window height */ |
7 | 899 { |
900 #endif | |
901 int lines; | |
902 | |
903 if (!wp->w_p_wrap) | |
904 return 1; | |
905 | |
906 if (wp->w_width == 0) | |
907 return 1; | |
908 | |
909 #ifdef FEAT_FOLDING | |
910 /* A folded lines is handled just like an empty line. */ | |
911 /* NOTE: Caller must handle lines that are MAYBE folded. */ | |
912 if (lineFolded(wp, lnum) == TRUE) | |
913 return 1; | |
914 #endif | |
915 | |
916 lines = plines_win_nofold(wp, lnum); | |
917 if (winheight > 0 && lines > wp->w_height) | |
918 return (int)wp->w_height; | |
919 return lines; | |
920 } | |
921 | |
922 /* | |
923 * Return number of window lines physical line "lnum" will occupy in window | |
924 * "wp". Does not care about folding, 'wrap' or 'diff'. | |
925 */ | |
926 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
927 plines_win_nofold(win_T *wp, linenr_T lnum) |
7 | 928 { |
929 char_u *s; | |
930 long col; | |
931 int width; | |
932 | |
933 s = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
934 if (*s == NUL) /* empty line */ | |
935 return 1; | |
936 col = win_linetabsize(wp, s, (colnr_T)MAXCOL); | |
937 | |
938 /* | |
939 * If list mode is on, then the '$' at the end of the line may take up one | |
940 * extra column. | |
941 */ | |
942 if (wp->w_p_list && lcs_eol != NUL) | |
943 col += 1; | |
944 | |
945 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2162
diff
changeset
|
946 * Add column offset for 'number', 'relativenumber' and 'foldcolumn'. |
7 | 947 */ |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
948 width = wp->w_width - win_col_off(wp); |
7 | 949 if (width <= 0) |
950 return 32000; | |
951 if (col <= width) | |
952 return 1; | |
953 col -= width; | |
954 width += win_col_off2(wp); | |
955 return (col + (width - 1)) / width + 1; | |
956 } | |
957 | |
958 /* | |
959 * Like plines_win(), but only reports the number of physical screen lines | |
960 * used from the start of the line to the given column number. | |
961 */ | |
962 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
963 plines_win_col(win_T *wp, linenr_T lnum, long column) |
7 | 964 { |
965 long col; | |
966 char_u *s; | |
967 int lines = 0; | |
968 int width; | |
5995 | 969 char_u *line; |
7 | 970 |
971 #ifdef FEAT_DIFF | |
972 /* Check for filler lines above this buffer line. When folded the result | |
973 * is one line anyway. */ | |
974 lines = diff_check_fill(wp, lnum); | |
975 #endif | |
976 | |
977 if (!wp->w_p_wrap) | |
978 return lines + 1; | |
979 | |
980 if (wp->w_width == 0) | |
981 return lines + 1; | |
982 | |
5995 | 983 line = s = ml_get_buf(wp->w_buffer, lnum, FALSE); |
7 | 984 |
985 col = 0; | |
986 while (*s != NUL && --column >= 0) | |
987 { | |
5995 | 988 col += win_lbr_chartabsize(wp, line, s, (colnr_T)col, NULL); |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
989 MB_PTR_ADV(s); |
7 | 990 } |
991 | |
992 /* | |
993 * If *s is a TAB, and the TAB is not displayed as ^I, and we're not in | |
994 * INSERT mode, then col must be adjusted so that it represents the last | |
995 * screen position of the TAB. This only fixes an error when the TAB wraps | |
996 * from one screen line to the next (when 'columns' is not a multiple of | |
997 * 'ts') -- webb. | |
998 */ | |
999 if (*s == TAB && (State & NORMAL) && (!wp->w_p_list || lcs_tab1)) | |
5995 | 1000 col += win_lbr_chartabsize(wp, line, s, (colnr_T)col, NULL) - 1; |
7 | 1001 |
1002 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2162
diff
changeset
|
1003 * Add column offset for 'number', 'relativenumber', 'foldcolumn', etc. |
7 | 1004 */ |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1005 width = wp->w_width - win_col_off(wp); |
1023 | 1006 if (width <= 0) |
1007 return 9999; | |
1008 | |
1009 lines += 1; | |
1010 if (col > width) | |
1011 lines += (col - width) / (width + win_col_off2(wp)) + 1; | |
1012 return lines; | |
7 | 1013 } |
1014 | |
1015 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1016 plines_m_win(win_T *wp, linenr_T first, linenr_T last) |
7 | 1017 { |
1018 int count = 0; | |
1019 | |
1020 while (first <= last) | |
1021 { | |
1022 #ifdef FEAT_FOLDING | |
1023 int x; | |
1024 | |
1025 /* Check if there are any really folded lines, but also included lines | |
1026 * that are maybe folded. */ | |
1027 x = foldedCount(wp, first, NULL); | |
1028 if (x > 0) | |
1029 { | |
1030 ++count; /* count 1 for "+-- folded" line */ | |
1031 first += x; | |
1032 } | |
1033 else | |
1034 #endif | |
1035 { | |
1036 #ifdef FEAT_DIFF | |
1037 if (first == wp->w_topline) | |
1038 count += plines_win_nofill(wp, first, TRUE) + wp->w_topfill; | |
1039 else | |
1040 #endif | |
1041 count += plines_win(wp, first, TRUE); | |
1042 ++first; | |
1043 } | |
1044 } | |
1045 return (count); | |
1046 } | |
1047 | |
1048 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1049 gchar_pos(pos_T *pos) |
7 | 1050 { |
13082
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
1051 char_u *ptr; |
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
1052 |
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
1053 /* When searching columns is sometimes put at the end of a line. */ |
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
1054 if (pos->col == MAXCOL) |
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
1055 return NUL; |
a80082fd1a1d
patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
1056 ptr = ml_get_pos(pos); |
7 | 1057 if (has_mbyte) |
1058 return (*mb_ptr2char)(ptr); | |
1059 return (int)*ptr; | |
1060 } | |
1061 | |
1062 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1063 gchar_cursor(void) |
7 | 1064 { |
1065 if (has_mbyte) | |
1066 return (*mb_ptr2char)(ml_get_cursor()); | |
1067 return (int)*ml_get_cursor(); | |
1068 } | |
1069 | |
1070 /* | |
1071 * Write a character at the current cursor position. | |
1072 * It is directly written into the block. | |
1073 */ | |
1074 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1075 pchar_cursor(int c) |
7 | 1076 { |
1077 *(ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE) | |
1078 + curwin->w_cursor.col) = c; | |
1079 } | |
1080 | |
1081 /* | |
1082 * When extra == 0: Return TRUE if the cursor is before or on the first | |
1083 * non-blank in the line. | |
1084 * When extra == 1: Return TRUE if the cursor is before the first non-blank in | |
1085 * the line. | |
1086 */ | |
1087 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1088 inindent(int extra) |
7 | 1089 { |
1090 char_u *ptr; | |
1091 colnr_T col; | |
1092 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1093 for (col = 0, ptr = ml_get_curline(); VIM_ISWHITE(*ptr); ++col) |
7 | 1094 ++ptr; |
1095 if (col >= curwin->w_cursor.col + extra) | |
1096 return TRUE; | |
1097 else | |
1098 return FALSE; | |
1099 } | |
1100 | |
1101 /* | |
1102 * Skip to next part of an option argument: Skip space and comma. | |
1103 */ | |
1104 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1105 skip_to_option_part(char_u *p) |
7 | 1106 { |
1107 if (*p == ',') | |
1108 ++p; | |
1109 while (*p == ' ') | |
1110 ++p; | |
1111 return p; | |
1112 } | |
1113 | |
1114 /* | |
1115 * check_status: called when the status bars for the buffer 'buf' | |
1116 * need to be updated | |
1117 */ | |
1118 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1119 check_status(buf_T *buf) |
7 | 1120 { |
1121 win_T *wp; | |
1122 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
1123 FOR_ALL_WINDOWS(wp) |
7 | 1124 if (wp->w_buffer == buf && wp->w_status_height) |
1125 { | |
1126 wp->w_redr_status = TRUE; | |
1127 if (must_redraw < VALID) | |
1128 must_redraw = VALID; | |
1129 } | |
1130 } | |
1131 | |
1132 /* | |
1133 * Ask for a reply from the user, a 'y' or a 'n'. | |
1134 * No other characters are accepted, the message is repeated until a valid | |
1135 * reply is entered or CTRL-C is hit. | |
1136 * If direct is TRUE, don't use vgetc() but ui_inchar(), don't get characters | |
1137 * from any buffers but directly from the user. | |
1138 * | |
1139 * return the 'y' or 'n' | |
1140 */ | |
1141 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1142 ask_yesno(char_u *str, int direct) |
7 | 1143 { |
1144 int r = ' '; | |
1145 int save_State = State; | |
1146 | |
1147 if (exiting) /* put terminal in raw mode for this question */ | |
1148 settmode(TMODE_RAW); | |
1149 ++no_wait_return; | |
1150 #ifdef USE_ON_FLY_SCROLL | |
1151 dont_scroll = TRUE; /* disallow scrolling here */ | |
1152 #endif | |
1153 State = CONFIRM; /* mouse behaves like with :confirm */ | |
1154 #ifdef FEAT_MOUSE | |
1155 setmouse(); /* disables mouse for xterm */ | |
1156 #endif | |
1157 ++no_mapping; | |
1158 ++allow_keys; /* no mapping here, but recognize keys */ | |
1159 | |
1160 while (r != 'y' && r != 'n') | |
1161 { | |
1162 /* same highlighting as for wait_return */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15420
diff
changeset
|
1163 smsg_attr(HL_ATTR(HLF_R), "%s (y/n)?", str); |
7 | 1164 if (direct) |
1165 r = get_keystroke(); | |
1166 else | |
1474 | 1167 r = plain_vgetc(); |
7 | 1168 if (r == Ctrl_C || r == ESC) |
1169 r = 'n'; | |
1170 msg_putchar(r); /* show what you typed */ | |
1171 out_flush(); | |
1172 } | |
1173 --no_wait_return; | |
1174 State = save_State; | |
1175 #ifdef FEAT_MOUSE | |
1176 setmouse(); | |
1177 #endif | |
1178 --no_mapping; | |
1179 --allow_keys; | |
1180 | |
1181 return r; | |
1182 } | |
1183 | |
4221 | 1184 #if defined(FEAT_MOUSE) || defined(PROTO) |
1185 /* | |
1186 * Return TRUE if "c" is a mouse key. | |
1187 */ | |
1188 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1189 is_mouse_key(int c) |
4221 | 1190 { |
1191 return c == K_LEFTMOUSE | |
1192 || c == K_LEFTMOUSE_NM | |
1193 || c == K_LEFTDRAG | |
1194 || c == K_LEFTRELEASE | |
1195 || c == K_LEFTRELEASE_NM | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1196 || c == K_MOUSEMOVE |
4221 | 1197 || c == K_MIDDLEMOUSE |
1198 || c == K_MIDDLEDRAG | |
1199 || c == K_MIDDLERELEASE | |
1200 || c == K_RIGHTMOUSE | |
1201 || c == K_RIGHTDRAG | |
1202 || c == K_RIGHTRELEASE | |
1203 || c == K_MOUSEDOWN | |
1204 || c == K_MOUSEUP | |
1205 || c == K_MOUSELEFT | |
1206 || c == K_MOUSERIGHT | |
1207 || c == K_X1MOUSE | |
1208 || c == K_X1DRAG | |
1209 || c == K_X1RELEASE | |
1210 || c == K_X2MOUSE | |
1211 || c == K_X2DRAG | |
1212 || c == K_X2RELEASE; | |
1213 } | |
1214 #endif | |
1215 | |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1216 #if defined(FEAT_EVAL) || defined(PROTO) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1217 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1218 /* |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1219 * "mode()" function |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1220 */ |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1221 void |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1222 f_mode(typval_T *argvars, typval_T *rettv) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1223 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1224 char_u buf[4]; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1225 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1226 vim_memset(buf, 0, sizeof(buf)); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1227 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1228 if (time_for_testing == 93784) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1229 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1230 /* Testing the two-character code. */ |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1231 buf[0] = 'x'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1232 buf[1] = '!'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1233 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1234 #ifdef FEAT_TERMINAL |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1235 else if (term_use_loop()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1236 buf[0] = 't'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1237 #endif |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1238 else if (VIsual_active) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1239 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1240 if (VIsual_select) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1241 buf[0] = VIsual_mode + 's' - 'v'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1242 else |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1243 buf[0] = VIsual_mode; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1244 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1245 else if (State == HITRETURN || State == ASKMORE || State == SETWSIZE |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1246 || State == CONFIRM) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1247 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1248 buf[0] = 'r'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1249 if (State == ASKMORE) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1250 buf[1] = 'm'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1251 else if (State == CONFIRM) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1252 buf[1] = '?'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1253 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1254 else if (State == EXTERNCMD) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1255 buf[0] = '!'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1256 else if (State & INSERT) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1257 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1258 if (State & VREPLACE_FLAG) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1259 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1260 buf[0] = 'R'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1261 buf[1] = 'v'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1262 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1263 else |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1264 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1265 if (State & REPLACE_FLAG) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1266 buf[0] = 'R'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1267 else |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1268 buf[0] = 'i'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1269 if (ins_compl_active()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1270 buf[1] = 'c'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1271 else if (ctrl_x_mode_not_defined_yet()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1272 buf[1] = 'x'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1273 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1274 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1275 else if ((State & CMDLINE) || exmode_active) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1276 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1277 buf[0] = 'c'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1278 if (exmode_active == EXMODE_VIM) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1279 buf[1] = 'v'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1280 else if (exmode_active == EXMODE_NORMAL) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1281 buf[1] = 'e'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1282 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1283 else |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1284 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1285 buf[0] = 'n'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1286 if (finish_op) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1287 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1288 buf[1] = 'o'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1289 // to be able to detect force-linewise/blockwise/characterwise operations |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1290 buf[2] = motion_force; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1291 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1292 else if (restart_edit == 'I' || restart_edit == 'R' |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1293 || restart_edit == 'V') |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1294 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1295 buf[1] = 'i'; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1296 buf[2] = restart_edit; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1297 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1298 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1299 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1300 /* Clear out the minor mode when the argument is not a non-zero number or |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1301 * non-empty string. */ |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1302 if (!non_zero_arg(&argvars[0])) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1303 buf[1] = NUL; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1304 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1305 rettv->vval.v_string = vim_strsave(buf); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1306 rettv->v_type = VAR_STRING; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1307 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1308 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1309 static void |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1310 may_add_state_char(garray_T *gap, char_u *include, int c) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1311 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1312 if (include == NULL || vim_strchr(include, c) != NULL) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1313 ga_append(gap, c); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1314 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1315 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1316 /* |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1317 * "state()" function |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1318 */ |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1319 void |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1320 f_state(typval_T *argvars, typval_T *rettv) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1321 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1322 garray_T ga; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1323 char_u *include = NULL; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1324 int i; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1325 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1326 ga_init2(&ga, 1, 20); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1327 if (argvars[0].v_type != VAR_UNKNOWN) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1328 include = tv_get_string(&argvars[0]); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1329 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1330 if (!(stuff_empty() && typebuf.tb_len == 0 && scriptin[curscript] == NULL)) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1331 may_add_state_char(&ga, include, 'm'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1332 if (op_pending()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1333 may_add_state_char(&ga, include, 'o'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1334 if (autocmd_busy) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1335 may_add_state_char(&ga, include, 'x'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1336 if (!ctrl_x_mode_none()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1337 may_add_state_char(&ga, include, 'a'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1338 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1339 # ifdef FEAT_JOB_CHANNEL |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1340 if (channel_in_blocking_wait()) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1341 may_add_state_char(&ga, include, 'w'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1342 # endif |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1343 for (i = 0; i < get_callback_depth() && i < 3; ++i) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1344 may_add_state_char(&ga, include, 'c'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1345 if (msg_scrolled > 0) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1346 may_add_state_char(&ga, include, 's'); |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1347 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1348 rettv->v_type = VAR_STRING; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1349 rettv->vval.v_string = ga.ga_data; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1350 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1351 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1352 #endif // FEAT_EVAL |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1353 |
7 | 1354 /* |
1355 * Get a key stroke directly from the user. | |
1356 * Ignores mouse clicks and scrollbar events, except a click for the left | |
1357 * button (used at the more prompt). | |
1358 * Doesn't use vgetc(), because it syncs undo and eats mapped characters. | |
1359 * Disadvantage: typeahead is ignored. | |
1360 * Translates the interrupt character for unix to ESC. | |
1361 */ | |
1362 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1363 get_keystroke(void) |
7 | 1364 { |
3328 | 1365 char_u *buf = NULL; |
1366 int buflen = 150; | |
1367 int maxlen; | |
7 | 1368 int len = 0; |
1369 int n; | |
1370 int save_mapped_ctrl_c = mapped_ctrl_c; | |
964 | 1371 int waited = 0; |
7 | 1372 |
1373 mapped_ctrl_c = FALSE; /* mappings are not used here */ | |
1374 for (;;) | |
1375 { | |
1376 cursor_on(); | |
1377 out_flush(); | |
1378 | |
3328 | 1379 /* Leave some room for check_termcode() to insert a key code into (max |
1380 * 5 chars plus NUL). And fix_input_buffer() can triple the number of | |
1381 * bytes. */ | |
1382 maxlen = (buflen - 6 - len) / 3; | |
1383 if (buf == NULL) | |
1384 buf = alloc(buflen); | |
1385 else if (maxlen < 10) | |
1386 { | |
6596 | 1387 char_u *t_buf = buf; |
1388 | |
3596 | 1389 /* Need some more space. This might happen when receiving a long |
3328 | 1390 * escape sequence. */ |
1391 buflen += 100; | |
1392 buf = vim_realloc(buf, buflen); | |
6596 | 1393 if (buf == NULL) |
1394 vim_free(t_buf); | |
3328 | 1395 maxlen = (buflen - 6 - len) / 3; |
1396 } | |
1397 if (buf == NULL) | |
1398 { | |
1399 do_outofmem_msg((long_u)buflen); | |
1400 return ESC; /* panic! */ | |
1401 } | |
1402 | |
7 | 1403 /* First time: blocking wait. Second time: wait up to 100ms for a |
3328 | 1404 * terminal code to complete. */ |
1405 n = ui_inchar(buf + len, maxlen, len == 0 ? -1L : 100L, 0); | |
7 | 1406 if (n > 0) |
1407 { | |
1408 /* Replace zero and CSI by a special key code. */ | |
9896
7b39615c0db1
commit https://github.com/vim/vim/commit/6bff02eb530aa29aafa2cb5627399837be7a5dd5
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
1409 n = fix_input_buffer(buf + len, n); |
7 | 1410 len += n; |
964 | 1411 waited = 0; |
1412 } | |
1413 else if (len > 0) | |
1414 ++waited; /* keep track of the waiting time */ | |
1415 | |
1416 /* Incomplete termcode and not timed out yet: get more characters */ | |
3328 | 1417 if ((n = check_termcode(1, buf, buflen, &len)) < 0 |
964 | 1418 && (!p_ttimeout || waited * 100L < (p_ttm < 0 ? p_tm : p_ttm))) |
7 | 1419 continue; |
964 | 1420 |
2672 | 1421 if (n == KEYLEN_REMOVED) /* key code removed */ |
2721 | 1422 { |
2723 | 1423 if (must_redraw != 0 && !need_wait_return && (State & CMDLINE) == 0) |
2721 | 1424 { |
1425 /* Redrawing was postponed, do it now. */ | |
1426 update_screen(0); | |
1427 setcursor(); /* put cursor back where it belongs */ | |
1428 } | |
2672 | 1429 continue; |
2721 | 1430 } |
2672 | 1431 if (n > 0) /* found a termcode: adjust length */ |
7 | 1432 len = n; |
2672 | 1433 if (len == 0) /* nothing typed yet */ |
7 | 1434 continue; |
1435 | |
1436 /* Handle modifier and/or special key code. */ | |
1437 n = buf[0]; | |
1438 if (n == K_SPECIAL) | |
1439 { | |
1440 n = TO_SPECIAL(buf[1], buf[2]); | |
1441 if (buf[1] == KS_MODIFIER | |
1442 || n == K_IGNORE | |
4225 | 1443 #ifdef FEAT_MOUSE |
4221 | 1444 || (is_mouse_key(n) && n != K_LEFTMOUSE) |
4225 | 1445 #endif |
4221 | 1446 #ifdef FEAT_GUI |
7 | 1447 || n == K_VER_SCROLLBAR |
1448 || n == K_HOR_SCROLLBAR | |
1449 #endif | |
1450 ) | |
1451 { | |
1452 if (buf[1] == KS_MODIFIER) | |
1453 mod_mask = buf[2]; | |
1454 len -= 3; | |
1455 if (len > 0) | |
1456 mch_memmove(buf, buf + 3, (size_t)len); | |
1457 continue; | |
1458 } | |
828 | 1459 break; |
7 | 1460 } |
1461 if (has_mbyte) | |
1462 { | |
1463 if (MB_BYTE2LEN(n) > len) | |
1464 continue; /* more bytes to get */ | |
3328 | 1465 buf[len >= buflen ? buflen - 1 : len] = NUL; |
7 | 1466 n = (*mb_ptr2char)(buf); |
1467 } | |
1468 #ifdef UNIX | |
1469 if (n == intr_char) | |
1470 n = ESC; | |
1471 #endif | |
1472 break; | |
1473 } | |
3328 | 1474 vim_free(buf); |
7 | 1475 |
1476 mapped_ctrl_c = save_mapped_ctrl_c; | |
1477 return n; | |
1478 } | |
1479 | |
1480 /* | |
374 | 1481 * Get a number from the user. |
1482 * When "mouse_used" is not NULL allow using the mouse. | |
7 | 1483 */ |
1484 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1485 get_number( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1486 int colon, /* allow colon to abort */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1487 int *mouse_used) |
7 | 1488 { |
1489 int n = 0; | |
1490 int c; | |
810 | 1491 int typed = 0; |
7 | 1492 |
374 | 1493 if (mouse_used != NULL) |
1494 *mouse_used = FALSE; | |
1495 | |
7 | 1496 /* When not printing messages, the user won't know what to type, return a |
1497 * zero (as if CR was hit). */ | |
1498 if (msg_silent != 0) | |
1499 return 0; | |
1500 | |
1501 #ifdef USE_ON_FLY_SCROLL | |
1502 dont_scroll = TRUE; /* disallow scrolling here */ | |
1503 #endif | |
1504 ++no_mapping; | |
1505 ++allow_keys; /* no mapping here, but recognize keys */ | |
1506 for (;;) | |
1507 { | |
1508 windgoto(msg_row, msg_col); | |
1509 c = safe_vgetc(); | |
1510 if (VIM_ISDIGIT(c)) | |
1511 { | |
1512 n = n * 10 + c - '0'; | |
1513 msg_putchar(c); | |
810 | 1514 ++typed; |
7 | 1515 } |
1516 else if (c == K_DEL || c == K_KDEL || c == K_BS || c == Ctrl_H) | |
1517 { | |
810 | 1518 if (typed > 0) |
1519 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1520 msg_puts("\b \b"); |
810 | 1521 --typed; |
1522 } | |
7 | 1523 n /= 10; |
1524 } | |
374 | 1525 #ifdef FEAT_MOUSE |
1526 else if (mouse_used != NULL && c == K_LEFTMOUSE) | |
1527 { | |
1528 *mouse_used = TRUE; | |
1529 n = mouse_row + 1; | |
1530 break; | |
1531 } | |
1532 #endif | |
7 | 1533 else if (n == 0 && c == ':' && colon) |
1534 { | |
1535 stuffcharReadbuff(':'); | |
1536 if (!exmode_active) | |
1537 cmdline_row = msg_row; | |
1538 skip_redraw = TRUE; /* skip redraw once */ | |
1539 do_redraw = FALSE; | |
1540 break; | |
1541 } | |
1542 else if (c == CAR || c == NL || c == Ctrl_C || c == ESC) | |
1543 break; | |
1544 } | |
1545 --no_mapping; | |
1546 --allow_keys; | |
1547 return n; | |
1548 } | |
1549 | |
323 | 1550 /* |
1551 * Ask the user to enter a number. | |
374 | 1552 * When "mouse_used" is not NULL allow using the mouse and in that case return |
1553 * the line number. | |
323 | 1554 */ |
1555 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1556 prompt_for_number(int *mouse_used) |
323 | 1557 { |
1558 int i; | |
344 | 1559 int save_cmdline_row; |
1560 int save_State; | |
323 | 1561 |
1562 /* When using ":silent" assume that <CR> was entered. */ | |
375 | 1563 if (mouse_used != NULL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1564 msg_puts(_("Type number and <Enter> or click with mouse (empty cancels): ")); |
375 | 1565 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1566 msg_puts(_("Type number and <Enter> (empty cancels): ")); |
344 | 1567 |
14629
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1568 // Set the state such that text can be selected/copied/pasted and we still |
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1569 // get mouse events. redraw_after_callback() will not redraw if cmdline_row |
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1570 // is zero. |
344 | 1571 save_cmdline_row = cmdline_row; |
957 | 1572 cmdline_row = 0; |
344 | 1573 save_State = State; |
14629
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1574 State = CMDLINE; |
13768
bcef80912112
patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1575 #ifdef FEAT_MOUSE |
14629
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1576 // May show different mouse shape. |
13768
bcef80912112
patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1577 setmouse(); |
bcef80912112
patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1578 #endif |
bcef80912112
patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1579 |
374 | 1580 i = get_number(TRUE, mouse_used); |
1581 if (KeyTyped) | |
1582 { | |
17018
b1263192461f
patch 8.1.1509: cmdline_row can become negative, causing a crash
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1583 // don't call wait_return() now |
b1263192461f
patch 8.1.1509: cmdline_row can become negative, causing a crash
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1584 if (msg_row > 0) |
b1263192461f
patch 8.1.1509: cmdline_row can become negative, causing a crash
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1585 cmdline_row = msg_row - 1; |
323 | 1586 need_wait_return = FALSE; |
1587 msg_didany = FALSE; | |
1938 | 1588 msg_didout = FALSE; |
323 | 1589 } |
344 | 1590 else |
1591 cmdline_row = save_cmdline_row; | |
1592 State = save_State; | |
13768
bcef80912112
patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1593 #ifdef FEAT_MOUSE |
14629
100a44722322
patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1594 // May need to restore mouse shape. |
13768
bcef80912112
patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1595 setmouse(); |
bcef80912112
patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1596 #endif |
344 | 1597 |
323 | 1598 return i; |
1599 } | |
1600 | |
7 | 1601 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1602 msgmore(long n) |
7 | 1603 { |
1604 long pn; | |
1605 | |
1606 if (global_busy /* no messages now, wait until global is finished */ | |
1607 || !messaging()) /* 'lazyredraw' set, don't do messages now */ | |
1608 return; | |
1609 | |
135 | 1610 /* We don't want to overwrite another important message, but do overwrite |
1611 * a previous "more lines" or "fewer lines" message, so that "5dd" and | |
1612 * then "put" reports the last action. */ | |
1613 if (keep_msg != NULL && !keep_msg_more) | |
1614 return; | |
1615 | |
7 | 1616 if (n > 0) |
1617 pn = n; | |
1618 else | |
1619 pn = -n; | |
1620 | |
1621 if (pn > p_report) | |
1622 { | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
1623 if (n > 0) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1624 vim_snprintf(msg_buf, MSG_BUF_LEN, |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
1625 NGETTEXT("%ld more line", "%ld more lines", pn), pn); |
7 | 1626 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1627 vim_snprintf(msg_buf, MSG_BUF_LEN, |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
1628 NGETTEXT("%ld line less", "%ld fewer lines", pn), pn); |
7 | 1629 if (got_int) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1630 vim_strcat((char_u *)msg_buf, (char_u *)_(" (Interrupted)"), |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1631 MSG_BUF_LEN); |
7 | 1632 if (msg(msg_buf)) |
1633 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1634 set_keep_msg((char_u *)msg_buf, 0); |
135 | 1635 keep_msg_more = TRUE; |
7 | 1636 } |
1637 } | |
1638 } | |
1639 | |
1640 /* | |
1641 * flush map and typeahead buffers and give a warning for an error | |
1642 */ | |
1643 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1644 beep_flush(void) |
7 | 1645 { |
1646 if (emsg_silent == 0) | |
1647 { | |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1648 flush_buffers(FLUSH_MINIMAL); |
6949 | 1649 vim_beep(BO_ERROR); |
1650 } | |
1651 } | |
1652 | |
1653 /* | |
1654 * Give a warning for an error. | |
7 | 1655 */ |
1656 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1657 vim_beep( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1658 unsigned val) /* one of the BO_ values, e.g., BO_OPER */ |
7 | 1659 { |
13272
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1660 #ifdef FEAT_EVAL |
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1661 called_vim_beep = TRUE; |
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1662 #endif |
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1663 |
7 | 1664 if (emsg_silent == 0) |
1665 { | |
6949 | 1666 if (!((bo_flags & val) || (bo_flags & BO_ALL))) |
1667 { | |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1668 #ifdef ELAPSED_FUNC |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1669 static int did_init = FALSE; |
15525
3ef31ce9d9f9
patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1670 static elapsed_T start_tv; |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1671 |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1672 /* Only beep once per half a second, otherwise a sequence of beeps |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1673 * would freeze Vim. */ |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1674 if (!did_init || ELAPSED_FUNC(start_tv) > 500) |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1675 { |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1676 did_init = TRUE; |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1677 ELAPSED_INIT(start_tv); |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1678 #endif |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1679 if (p_vb |
7 | 1680 #ifdef FEAT_GUI |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1681 /* While the GUI is starting up the termcap is set for |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1682 * the GUI but the output still goes to a terminal. */ |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1683 && !(gui.in_use && gui.starting) |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1684 #endif |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1685 ) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1686 { |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1687 out_str_cf(T_VB); |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1688 #ifdef FEAT_VTP |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1689 /* No restore color information, refresh the screen. */ |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1690 if (has_vtp_working() != 0 |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1691 # ifdef FEAT_TERMGUICOLORS |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
1692 && (p_tgc || (!p_tgc && t_colors >= 256)) |
13314
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1693 # endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1694 ) |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1695 { |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1696 redraw_later(CLEAR); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1697 update_screen(0); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1698 redrawcmd(); |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1699 } |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1700 #endif |
65c3e8259124
patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13272
diff
changeset
|
1701 } |
11601
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1702 else |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1703 out_char(BELL); |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1704 #ifdef ELAPSED_FUNC |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1705 } |
0a5d405e2520
patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents:
11384
diff
changeset
|
1706 #endif |
7 | 1707 } |
169 | 1708 |
13272
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1709 /* When 'debug' contains "beep" produce a message. If we are sourcing |
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1710 * a script or executing a function give the user a hint where the beep |
abaebba89fd4
patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1711 * comes from. */ |
169 | 1712 if (vim_strchr(p_debug, 'e') != NULL) |
1713 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1714 msg_source(HL_ATTR(HLF_W)); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15525
diff
changeset
|
1715 msg_attr(_("Beep!"), HL_ATTR(HLF_W)); |
169 | 1716 } |
7 | 1717 } |
1718 } | |
1719 | |
1720 /* | |
1721 * To get the "real" home directory: | |
1722 * - get value of $HOME | |
1723 * For Unix: | |
1724 * - go to that directory | |
1725 * - do mch_dirname() to get the real name of that directory. | |
1726 * This also works with mounts and links. | |
1727 * Don't do this for MS-DOS, it will change the "current dir" for a drive. | |
15046
c1be7c8bb602
patch 8.1.0534: MS-Windows installer uses different $HOME than Vim
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
1728 * For Windows: |
c1be7c8bb602
patch 8.1.0534: MS-Windows installer uses different $HOME than Vim
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
1729 * This code is duplicated in init_homedir() in dosinst.c. Keep in sync! |
7 | 1730 */ |
1731 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1732 init_homedir(void) |
7 | 1733 { |
1734 char_u *var; | |
1735 | |
170 | 1736 /* In case we are called a second time (when 'encoding' changes). */ |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
1737 VIM_CLEAR(homedir); |
170 | 1738 |
7 | 1739 #ifdef VMS |
1740 var = mch_getenv((char_u *)"SYS$LOGIN"); | |
1741 #else | |
1742 var = mch_getenv((char_u *)"HOME"); | |
1743 #endif | |
1744 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15814
diff
changeset
|
1745 #ifdef MSWIN |
7 | 1746 /* |
12265
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1747 * Typically, $HOME is not defined on Windows, unless the user has |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1748 * specifically defined it for Vim's sake. However, on Windows NT |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1749 * platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1750 * each user. Try constructing $HOME from these. |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1751 */ |
12269
d2373927d76d
patch 8.0.1014: old compiler doesn't know uint32_t
Christian Brabandt <cb@256bit.org>
parents:
12265
diff
changeset
|
1752 if (var == NULL || *var == NUL) |
12265
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1753 { |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1754 char_u *homedrive, *homepath; |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1755 |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1756 homedrive = mch_getenv((char_u *)"HOMEDRIVE"); |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1757 homepath = mch_getenv((char_u *)"HOMEPATH"); |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1758 if (homepath == NULL || *homepath == NUL) |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1759 homepath = (char_u *)"\\"; |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1760 if (homedrive != NULL |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1761 && STRLEN(homedrive) + STRLEN(homepath) < MAXPATHL) |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1762 { |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1763 sprintf((char *)NameBuff, "%s%s", homedrive, homepath); |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1764 if (NameBuff[0] != NUL) |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1765 var = NameBuff; |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1766 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1767 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1768 |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1769 if (var == NULL) |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1770 var = mch_getenv((char_u *)"USERPROFILE"); |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1771 |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1772 /* |
7 | 1773 * Weird but true: $HOME may contain an indirect reference to another |
1774 * variable, esp. "%USERPROFILE%". Happens when $USERPROFILE isn't set | |
1775 * when $HOME is being set. | |
1776 */ | |
1777 if (var != NULL && *var == '%') | |
1778 { | |
1779 char_u *p; | |
1780 char_u *exp; | |
1781 | |
1782 p = vim_strchr(var + 1, '%'); | |
1783 if (p != NULL) | |
1784 { | |
419 | 1785 vim_strncpy(NameBuff, var + 1, p - (var + 1)); |
7 | 1786 exp = mch_getenv(NameBuff); |
1787 if (exp != NULL && *exp != NUL | |
1788 && STRLEN(exp) + STRLEN(p) < MAXPATHL) | |
1789 { | |
274 | 1790 vim_snprintf((char *)NameBuff, MAXPATHL, "%s%s", exp, p + 1); |
7 | 1791 var = NameBuff; |
12265
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1792 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1793 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1794 } |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1795 |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1796 if (var != NULL && *var == NUL) /* empty is same as not set */ |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1797 var = NULL; |
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1798 |
170 | 1799 if (enc_utf8 && var != NULL) |
1800 { | |
1801 int len; | |
2786 | 1802 char_u *pp = NULL; |
170 | 1803 |
1804 /* Convert from active codepage to UTF-8. Other conversions are | |
1805 * not done, because they would fail for non-ASCII characters. */ | |
835 | 1806 acp_to_enc(var, (int)STRLEN(var), &pp, &len); |
170 | 1807 if (pp != NULL) |
1808 { | |
1809 homedir = pp; | |
1810 return; | |
1811 } | |
1812 } | |
12265
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1813 |
7 | 1814 /* |
1815 * Default home dir is C:/ | |
1816 * Best assumption we can make in such a situation. | |
1817 */ | |
1818 if (var == NULL) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
1819 var = (char_u *)"C:/"; |
7 | 1820 #endif |
12265
03e4be2e3d53
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
1821 |
7 | 1822 if (var != NULL) |
1823 { | |
1824 #ifdef UNIX | |
1825 /* | |
1826 * Change to the directory and get the actual path. This resolves | |
1827 * links. Don't do it when we can't return. | |
1828 */ | |
1829 if (mch_dirname(NameBuff, MAXPATHL) == OK | |
1830 && mch_chdir((char *)NameBuff) == 0) | |
1831 { | |
1832 if (!mch_chdir((char *)var) && mch_dirname(IObuff, IOSIZE) == OK) | |
1833 var = IObuff; | |
1834 if (mch_chdir((char *)NameBuff) != 0) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15420
diff
changeset
|
1835 emsg(_(e_prev_dir)); |
7 | 1836 } |
1837 #endif | |
1838 homedir = vim_strsave(var); | |
1839 } | |
1840 } | |
1841 | |
359 | 1842 #if defined(EXITFREE) || defined(PROTO) |
1843 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1844 free_homedir(void) |
359 | 1845 { |
1846 vim_free(homedir); | |
1847 } | |
3744 | 1848 |
1849 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1850 free_users(void) |
3744 | 1851 { |
1852 ga_clear_strings(&ga_users); | |
1853 } | |
359 | 1854 #endif |
1855 | |
7 | 1856 /* |
1408 | 1857 * Call expand_env() and store the result in an allocated string. |
1858 * This is not very memory efficient, this expects the result to be freed | |
1859 * again soon. | |
1860 */ | |
1861 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1862 expand_env_save(char_u *src) |
1408 | 1863 { |
1864 return expand_env_save_opt(src, FALSE); | |
1865 } | |
1866 | |
1867 /* | |
1868 * Idem, but when "one" is TRUE handle the string as one file name, only | |
1869 * expand "~" at the start. | |
1870 */ | |
1871 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1872 expand_env_save_opt(char_u *src, int one) |
1408 | 1873 { |
1874 char_u *p; | |
1875 | |
1876 p = alloc(MAXPATHL); | |
1877 if (p != NULL) | |
1878 expand_env_esc(src, p, MAXPATHL, FALSE, one, NULL); | |
1879 return p; | |
1880 } | |
1881 | |
1882 /* | |
7 | 1883 * Expand environment variable with path name. |
1884 * "~/" is also expanded, using $HOME. For Unix "~user/" is expanded. | |
1408 | 1885 * Skips over "\ ", "\~" and "\$" (not for Win32 though). |
7 | 1886 * If anything fails no expansion is done and dst equals src. |
1887 */ | |
1888 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1889 expand_env( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1890 char_u *src, /* input string e.g. "$HOME/vim.hlp" */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1891 char_u *dst, /* where to put the result */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1892 int dstlen) /* maximum length of the result */ |
7 | 1893 { |
1408 | 1894 expand_env_esc(src, dst, dstlen, FALSE, FALSE, NULL); |
7 | 1895 } |
1896 | |
1897 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1898 expand_env_esc( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1899 char_u *srcp, /* input string e.g. "$HOME/vim.hlp" */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1900 char_u *dst, /* where to put the result */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1901 int dstlen, /* maximum length of the result */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1902 int esc, /* escape spaces in expanded variables */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1903 int one, /* "srcp" is one file name */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1904 char_u *startstr) /* start again after this (can be NULL) */ |
374 | 1905 { |
1906 char_u *src; | |
7 | 1907 char_u *tail; |
1908 int c; | |
1909 char_u *var; | |
1910 int copy_char; | |
1911 int mustfree; /* var was allocated, need to free it later */ | |
1912 int at_start = TRUE; /* at start of a name */ | |
374 | 1913 int startstr_len = 0; |
1914 | |
1915 if (startstr != NULL) | |
835 | 1916 startstr_len = (int)STRLEN(startstr); |
374 | 1917 |
1918 src = skipwhite(srcp); | |
7 | 1919 --dstlen; /* leave one char space for "\," */ |
1920 while (*src && dstlen > 0) | |
1921 { | |
7038
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1922 #ifdef FEAT_EVAL |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1923 /* Skip over `=expr`. */ |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1924 if (src[0] == '`' && src[1] == '=') |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1925 { |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1926 size_t len; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1927 |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1928 var = src; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1929 src += 2; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1930 (void)skip_expr(&src); |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1931 if (*src == '`') |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1932 ++src; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1933 len = src - var; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1934 if (len > (size_t)dstlen) |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1935 len = dstlen; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1936 vim_strncpy(dst, var, len); |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1937 dst += len; |
7066
094c8ccdc279
commit https://github.com/vim/vim/commit/5df1ed2de3fa9dcace996b9a0a4c9b3cea79cf1e
Christian Brabandt <cb@256bit.org>
parents:
7038
diff
changeset
|
1938 dstlen -= (int)len; |
7038
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1939 continue; |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1940 } |
76042a56ab85
commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents:
7036
diff
changeset
|
1941 #endif |
7 | 1942 copy_char = TRUE; |
22 | 1943 if ((*src == '$' |
1944 #ifdef VMS | |
1945 && at_start | |
1946 #endif | |
1947 ) | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8163
diff
changeset
|
1948 #if defined(MSWIN) |
7 | 1949 || *src == '%' |
1950 #endif | |
1951 || (*src == '~' && at_start)) | |
1952 { | |
1953 mustfree = FALSE; | |
1954 | |
1955 /* | |
1956 * The variable name is copied into dst temporarily, because it may | |
1957 * be a string in read-only memory and a NUL needs to be appended. | |
1958 */ | |
1959 if (*src != '~') /* environment var */ | |
1960 { | |
1961 tail = src + 1; | |
1962 var = dst; | |
1963 c = dstlen - 1; | |
1964 | |
1965 #ifdef UNIX | |
1966 /* Unix has ${var-name} type environment vars */ | |
1967 if (*tail == '{' && !vim_isIDc('{')) | |
1968 { | |
1969 tail++; /* ignore '{' */ | |
1970 while (c-- > 0 && *tail && *tail != '}') | |
1971 *var++ = *tail++; | |
1972 } | |
1973 else | |
1974 #endif | |
1975 { | |
1976 while (c-- > 0 && *tail != NUL && ((vim_isIDc(*tail)) | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8163
diff
changeset
|
1977 #if defined(MSWIN) |
7 | 1978 || (*src == '%' && *tail != '%') |
1979 #endif | |
1980 )) | |
1981 *var++ = *tail++; | |
1982 } | |
1983 | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8163
diff
changeset
|
1984 #if defined(MSWIN) || defined(UNIX) |
7 | 1985 # ifdef UNIX |
1986 if (src[1] == '{' && *tail != '}') | |
1987 # else | |
1988 if (*src == '%' && *tail != '%') | |
1989 # endif | |
1990 var = NULL; | |
1991 else | |
1992 { | |
1993 # ifdef UNIX | |
1994 if (src[1] == '{') | |
1995 # else | |
1996 if (*src == '%') | |
1997 #endif | |
1998 ++tail; | |
1999 #endif | |
2000 *var = NUL; | |
2001 var = vim_getenv(dst, &mustfree); | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8163
diff
changeset
|
2002 #if defined(MSWIN) || defined(UNIX) |
7 | 2003 } |
2004 #endif | |
2005 } | |
2006 /* home directory */ | |
2007 else if ( src[1] == NUL | |
2008 || vim_ispathsep(src[1]) | |
2009 || vim_strchr((char_u *)" ,\t\n", src[1]) != NULL) | |
2010 { | |
2011 var = homedir; | |
2012 tail = src + 1; | |
2013 } | |
2014 else /* user directory */ | |
2015 { | |
2016 #if defined(UNIX) || (defined(VMS) && defined(USER_HOME)) | |
2017 /* | |
2018 * Copy ~user to dst[], so we can put a NUL after it. | |
2019 */ | |
2020 tail = src; | |
2021 var = dst; | |
2022 c = dstlen - 1; | |
2023 while ( c-- > 0 | |
2024 && *tail | |
2025 && vim_isfilec(*tail) | |
2026 && !vim_ispathsep(*tail)) | |
2027 *var++ = *tail++; | |
2028 *var = NUL; | |
2029 # ifdef UNIX | |
2030 /* | |
2031 * If the system supports getpwnam(), use it. | |
2032 * Otherwise, or if getpwnam() fails, the shell is used to | |
2033 * expand ~user. This is slower and may fail if the shell | |
2034 * does not support ~user (old versions of /bin/sh). | |
2035 */ | |
2036 # if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H) | |
2037 { | |
626 | 2038 /* Note: memory allocated by getpwnam() is never freed. |
2039 * Calling endpwent() apparently doesn't help. */ | |
10932
141fe140976c
patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
2040 struct passwd *pw = (*dst == NUL) |
141fe140976c
patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
2041 ? NULL : getpwnam((char *)dst + 1); |
141fe140976c
patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
2042 |
141fe140976c
patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
2043 var = (pw == NULL) ? NULL : (char_u *)pw->pw_dir; |
7 | 2044 } |
2045 if (var == NULL) | |
2046 # endif | |
2047 { | |
2048 expand_T xpc; | |
2049 | |
2050 ExpandInit(&xpc); | |
2051 xpc.xp_context = EXPAND_FILES; | |
2052 var = ExpandOne(&xpc, dst, NULL, | |
2053 WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE); | |
2054 mustfree = TRUE; | |
2055 } | |
2056 | |
2057 # else /* !UNIX, thus VMS */ | |
2058 /* | |
2059 * USER_HOME is a comma-separated list of | |
2060 * directories to search for the user account in. | |
2061 */ | |
2062 { | |
2063 char_u test[MAXPATHL], paths[MAXPATHL]; | |
2064 char_u *path, *next_path, *ptr; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
2065 stat_T st; |
7 | 2066 |
2067 STRCPY(paths, USER_HOME); | |
2068 next_path = paths; | |
2069 while (*next_path) | |
2070 { | |
2071 for (path = next_path; *next_path && *next_path != ','; | |
2072 next_path++); | |
2073 if (*next_path) | |
2074 *next_path++ = NUL; | |
2075 STRCPY(test, path); | |
2076 STRCAT(test, "/"); | |
2077 STRCAT(test, dst + 1); | |
2078 if (mch_stat(test, &st) == 0) | |
2079 { | |
2080 var = alloc(STRLEN(test) + 1); | |
2081 STRCPY(var, test); | |
2082 mustfree = TRUE; | |
2083 break; | |
2084 } | |
2085 } | |
2086 } | |
2087 # endif /* UNIX */ | |
2088 #else | |
2089 /* cannot expand user's home directory, so don't try */ | |
2090 var = NULL; | |
2091 tail = (char_u *)""; /* for gcc */ | |
2092 #endif /* UNIX || VMS */ | |
2093 } | |
2094 | |
2095 #ifdef BACKSLASH_IN_FILENAME | |
2096 /* If 'shellslash' is set change backslashes to forward slashes. | |
2097 * Can't use slash_adjust(), p_ssl may be set temporarily. */ | |
2098 if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL) | |
2099 { | |
2100 char_u *p = vim_strsave(var); | |
2101 | |
2102 if (p != NULL) | |
2103 { | |
2104 if (mustfree) | |
2105 vim_free(var); | |
2106 var = p; | |
2107 mustfree = TRUE; | |
2108 forward_slash(var); | |
2109 } | |
2110 } | |
2111 #endif | |
2112 | |
2113 /* If "var" contains white space, escape it with a backslash. | |
2114 * Required for ":e ~/tt" when $HOME includes a space. */ | |
2115 if (esc && var != NULL && vim_strpbrk(var, (char_u *)" \t") != NULL) | |
2116 { | |
2117 char_u *p = vim_strsave_escaped(var, (char_u *)" \t"); | |
2118 | |
2119 if (p != NULL) | |
2120 { | |
2121 if (mustfree) | |
2122 vim_free(var); | |
2123 var = p; | |
2124 mustfree = TRUE; | |
2125 } | |
2126 } | |
2127 | |
2128 if (var != NULL && *var != NUL | |
2129 && (STRLEN(var) + STRLEN(tail) + 1 < (unsigned)dstlen)) | |
2130 { | |
2131 STRCPY(dst, var); | |
2132 dstlen -= (int)STRLEN(var); | |
835 | 2133 c = (int)STRLEN(var); |
7 | 2134 /* if var[] ends in a path separator and tail[] starts |
2135 * with it, skip a character */ | |
39 | 2136 if (*var != NUL && after_pathsep(dst, dst + c) |
7 | 2137 #if defined(BACKSLASH_IN_FILENAME) || defined(AMIGA) |
2138 && dst[-1] != ':' | |
2139 #endif | |
2140 && vim_ispathsep(*tail)) | |
2141 ++tail; | |
39 | 2142 dst += c; |
7 | 2143 src = tail; |
2144 copy_char = FALSE; | |
2145 } | |
2146 if (mustfree) | |
2147 vim_free(var); | |
2148 } | |
2149 | |
2150 if (copy_char) /* copy at least one char */ | |
2151 { | |
2152 /* | |
1224 | 2153 * Recognize the start of a new name, for '~'. |
1408 | 2154 * Don't do this when "one" is TRUE, to avoid expanding "~" in |
2155 * ":edit foo ~ foo". | |
7 | 2156 */ |
2157 at_start = FALSE; | |
2158 if (src[0] == '\\' && src[1] != NUL) | |
2159 { | |
2160 *dst++ = *src++; | |
2161 --dstlen; | |
2162 } | |
1408 | 2163 else if ((src[0] == ' ' || src[0] == ',') && !one) |
7 | 2164 at_start = TRUE; |
12005
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
2165 if (dstlen > 0) |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
2166 { |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
2167 *dst++ = *src++; |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
2168 --dstlen; |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
2169 |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
2170 if (startstr != NULL && src - startstr_len >= srcp |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
2171 && STRNCMP(src - startstr_len, startstr, |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
2172 startstr_len) == 0) |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
2173 at_start = TRUE; |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
2174 } |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
2175 } |
0496ea4c5c2e
patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents:
11989
diff
changeset
|
2176 |
7 | 2177 } |
2178 *dst = NUL; | |
2179 } | |
2180 | |
2181 /* | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2182 * If the string between "p" and "pend" ends in "name/", return "pend" minus |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2183 * the length of "name/". Otherwise return "pend". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2184 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2185 static char_u * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2186 remove_tail(char_u *p, char_u *pend, char_u *name) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2187 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2188 int len = (int)STRLEN(name) + 1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2189 char_u *newend = pend - len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2190 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2191 if (newend >= p |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2192 && fnamencmp(newend, name, len - 1) == 0 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2193 && (newend == p || after_pathsep(p, newend))) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2194 return newend; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2195 return pend; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2196 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2197 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2198 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2199 * Check if the directory "vimdir/<version>" or "vimdir/runtime" exists. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2200 * Return NULL if not, return its name in allocated memory otherwise. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2201 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2202 static char_u * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2203 vim_version_dir(char_u *vimdir) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2204 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2205 char_u *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2206 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2207 if (vimdir == NULL || *vimdir == NUL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2208 return NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2209 p = concat_fnames(vimdir, (char_u *)VIM_VERSION_NODOT, TRUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2210 if (p != NULL && mch_isdir(p)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2211 return p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2212 vim_free(p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2213 p = concat_fnames(vimdir, (char_u *)RUNTIME_DIRNAME, TRUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2214 if (p != NULL && mch_isdir(p)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2215 return p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2216 vim_free(p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2217 return NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2218 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2219 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2220 /* |
7 | 2221 * Vim's version of getenv(). |
2222 * Special handling of $HOME, $VIM and $VIMRUNTIME. | |
196 | 2223 * Also does ACP to 'enc' conversion for Win32. |
2786 | 2224 * "mustfree" is set to TRUE when returned is allocated, it must be |
2225 * initialized to FALSE by the caller. | |
7 | 2226 */ |
2227 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2228 vim_getenv(char_u *name, int *mustfree) |
7 | 2229 { |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2230 char_u *p = NULL; |
7 | 2231 char_u *pend; |
2232 int vimruntime; | |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2233 #ifdef MSWIN |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2234 WCHAR *wn, *wp; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2235 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2236 // use "C:/" when $HOME is not set |
7 | 2237 if (STRCMP(name, "HOME") == 0) |
2238 return homedir; | |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2239 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2240 // Use Wide function |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2241 wn = enc_to_utf16(name, NULL); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2242 if (wn == NULL) |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2243 return NULL; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2244 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2245 wp = _wgetenv(wn); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2246 vim_free(wn); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2247 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2248 if (wp != NULL && *wp == NUL) // empty is the same as not set |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2249 wp = NULL; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2250 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2251 if (wp != NULL) |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2252 { |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2253 p = utf16_to_enc(wp, NULL); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2254 if (p == NULL) |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2255 return NULL; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2256 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2257 *mustfree = TRUE; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2258 return p; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2259 } |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2260 #else |
7 | 2261 p = mch_getenv(name); |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2262 if (p != NULL && *p == NUL) // empty is the same as not set |
7 | 2263 p = NULL; |
2264 | |
2265 if (p != NULL) | |
2266 return p; | |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2267 #endif |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2268 |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2269 // handling $VIMRUNTIME and $VIM is below, bail out if it's another name. |
7 | 2270 vimruntime = (STRCMP(name, "VIMRUNTIME") == 0); |
2271 if (!vimruntime && STRCMP(name, "VIM") != 0) | |
2272 return NULL; | |
2273 | |
2274 /* | |
2275 * When expanding $VIMRUNTIME fails, try using $VIM/vim<version> or $VIM. | |
2276 * Don't do this when default_vimruntime_dir is non-empty. | |
2277 */ | |
2278 if (vimruntime | |
2279 #ifdef HAVE_PATHDEF | |
2280 && *default_vimruntime_dir == NUL | |
2281 #endif | |
2282 ) | |
2283 { | |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2284 #ifdef MSWIN |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2285 // Use Wide function |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2286 wp = _wgetenv(L"VIM"); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2287 if (wp != NULL && *wp == NUL) // empty is the same as not set |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2288 wp = NULL; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2289 if (wp != NULL) |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2290 { |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2291 char_u *q = utf16_to_enc(wp, NULL); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2292 if (q != NULL) |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2293 { |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2294 p = vim_version_dir(q); |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2295 *mustfree = TRUE; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2296 if (p == NULL) |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2297 p = q; |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2298 } |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2299 } |
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2300 #else |
7 | 2301 p = mch_getenv((char_u *)"VIM"); |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2302 if (p != NULL && *p == NUL) // empty is the same as not set |
7 | 2303 p = NULL; |
2304 if (p != NULL) | |
2305 { | |
2306 p = vim_version_dir(p); | |
2307 if (p != NULL) | |
2308 *mustfree = TRUE; | |
2309 else | |
2310 p = mch_getenv((char_u *)"VIM"); | |
2311 } | |
16172
6b0836727cf3
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
2312 #endif |
7 | 2313 } |
2314 | |
2315 /* | |
2316 * When expanding $VIM or $VIMRUNTIME fails, try using: | |
2317 * - the directory name from 'helpfile' (unless it contains '$') | |
2318 * - the executable name from argv[0] | |
2319 */ | |
2320 if (p == NULL) | |
2321 { | |
2322 if (p_hf != NULL && vim_strchr(p_hf, '$') == NULL) | |
2323 p = p_hf; | |
2324 #ifdef USE_EXE_NAME | |
2325 /* | |
2326 * Use the name of the executable, obtained from argv[0]. | |
2327 */ | |
2328 else | |
2329 p = exe_name; | |
2330 #endif | |
2331 if (p != NULL) | |
2332 { | |
2333 /* remove the file name */ | |
2334 pend = gettail(p); | |
2335 | |
2336 /* remove "doc/" from 'helpfile', if present */ | |
2337 if (p == p_hf) | |
2338 pend = remove_tail(p, pend, (char_u *)"doc"); | |
2339 | |
2340 #ifdef USE_EXE_NAME | |
2341 # ifdef MACOS_X | |
768 | 2342 /* remove "MacOS" from exe_name and add "Resources/vim" */ |
7 | 2343 if (p == exe_name) |
2344 { | |
2345 char_u *pend1; | |
768 | 2346 char_u *pnew; |
2347 | |
2348 pend1 = remove_tail(p, pend, (char_u *)"MacOS"); | |
2349 if (pend1 != pend) | |
2350 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
2351 pnew = alloc(pend1 - p + 15); |
768 | 2352 if (pnew != NULL) |
2353 { | |
2354 STRNCPY(pnew, p, (pend1 - p)); | |
2355 STRCPY(pnew + (pend1 - p), "Resources/vim"); | |
2356 p = pnew; | |
2357 pend = p + STRLEN(p); | |
2358 } | |
2359 } | |
7 | 2360 } |
2361 # endif | |
2362 /* remove "src/" from exe_name, if present */ | |
2363 if (p == exe_name) | |
2364 pend = remove_tail(p, pend, (char_u *)"src"); | |
2365 #endif | |
2366 | |
2367 /* for $VIM, remove "runtime/" or "vim54/", if present */ | |
2368 if (!vimruntime) | |
2369 { | |
2370 pend = remove_tail(p, pend, (char_u *)RUNTIME_DIRNAME); | |
2371 pend = remove_tail(p, pend, (char_u *)VIM_VERSION_NODOT); | |
2372 } | |
2373 | |
2374 /* remove trailing path separator */ | |
39 | 2375 if (pend > p && after_pathsep(p, pend)) |
7 | 2376 --pend; |
2377 | |
768 | 2378 #ifdef MACOS_X |
2379 if (p == exe_name || p == p_hf) | |
2380 #endif | |
2381 /* check that the result is a directory name */ | |
2382 p = vim_strnsave(p, (int)(pend - p)); | |
7 | 2383 |
2384 if (p != NULL && !mch_isdir(p)) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
2385 VIM_CLEAR(p); |
7 | 2386 else |
2387 { | |
2388 #ifdef USE_EXE_NAME | |
2389 /* may add "/vim54" or "/runtime" if it exists */ | |
2390 if (vimruntime && (pend = vim_version_dir(p)) != NULL) | |
2391 { | |
2392 vim_free(p); | |
2393 p = pend; | |
2394 } | |
2395 #endif | |
2396 *mustfree = TRUE; | |
2397 } | |
2398 } | |
2399 } | |
2400 | |
2401 #ifdef HAVE_PATHDEF | |
2402 /* When there is a pathdef.c file we can use default_vim_dir and | |
2403 * default_vimruntime_dir */ | |
2404 if (p == NULL) | |
2405 { | |
2406 /* Only use default_vimruntime_dir when it is not empty */ | |
2407 if (vimruntime && *default_vimruntime_dir != NUL) | |
2408 { | |
2409 p = default_vimruntime_dir; | |
2410 *mustfree = FALSE; | |
2411 } | |
2412 else if (*default_vim_dir != NUL) | |
2413 { | |
2414 if (vimruntime && (p = vim_version_dir(default_vim_dir)) != NULL) | |
2415 *mustfree = TRUE; | |
2416 else | |
2417 { | |
2418 p = default_vim_dir; | |
2419 *mustfree = FALSE; | |
2420 } | |
2421 } | |
2422 } | |
2423 #endif | |
2424 | |
2425 /* | |
2426 * Set the environment variable, so that the new value can be found fast | |
2427 * next time, and others can also use it (e.g. Perl). | |
2428 */ | |
2429 if (p != NULL) | |
2430 { | |
2431 if (vimruntime) | |
2432 { | |
2433 vim_setenv((char_u *)"VIMRUNTIME", p); | |
2434 didset_vimruntime = TRUE; | |
2435 } | |
2436 else | |
2437 { | |
2438 vim_setenv((char_u *)"VIM", p); | |
2439 didset_vim = TRUE; | |
2440 } | |
2441 } | |
2442 return p; | |
2443 } | |
2444 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2445 #if defined(FEAT_EVAL) || defined(PROTO) |
13923
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2446 void |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2447 vim_unsetenv(char_u *var) |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2448 { |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2449 #ifdef HAVE_UNSETENV |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2450 unsetenv((char *)var); |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2451 #else |
13942
a039c93f5ff7
patch 8.0.1841: HP-UX does not have setenv()
Christian Brabandt <cb@256bit.org>
parents:
13923
diff
changeset
|
2452 vim_setenv(var, (char_u *)""); |
13923
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2453 #endif |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2454 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2455 #endif |
13923
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2456 |
e4d5726e1678
patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2457 |
7 | 2458 /* |
2459 * Our portable version of setenv. | |
2460 */ | |
2461 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2462 vim_setenv(char_u *name, char_u *val) |
7 | 2463 { |
2464 #ifdef HAVE_SETENV | |
2465 mch_setenv((char *)name, (char *)val, 1); | |
2466 #else | |
2467 char_u *envbuf; | |
2468 | |
2469 /* | |
2470 * Putenv does not copy the string, it has to remain | |
2471 * valid. The allocated memory will never be freed. | |
2472 */ | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
2473 envbuf = alloc(STRLEN(name) + STRLEN(val) + 2); |
7 | 2474 if (envbuf != NULL) |
2475 { | |
2476 sprintf((char *)envbuf, "%s=%s", name, val); | |
2477 putenv((char *)envbuf); | |
2478 } | |
2479 #endif | |
3382 | 2480 #ifdef FEAT_GETTEXT |
2481 /* | |
2482 * When setting $VIMRUNTIME adjust the directory to find message | |
2483 * translations to $VIMRUNTIME/lang. | |
2484 */ | |
2485 if (*val != NUL && STRICMP(name, "VIMRUNTIME") == 0) | |
2486 { | |
2487 char_u *buf = concat_str(val, (char_u *)"/lang"); | |
2488 | |
2489 if (buf != NULL) | |
2490 { | |
2491 bindtextdomain(VIMPACKAGE, (char *)buf); | |
2492 vim_free(buf); | |
2493 } | |
2494 } | |
2495 #endif | |
7 | 2496 } |
2497 | |
2498 /* | |
2499 * Function given to ExpandGeneric() to obtain an environment variable name. | |
2500 */ | |
2501 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2502 get_env_name( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2503 expand_T *xp UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2504 int idx) |
7 | 2505 { |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
2506 # if defined(AMIGA) |
7 | 2507 /* |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
2508 * No environ[] on the Amiga. |
7 | 2509 */ |
2510 return NULL; | |
2511 # else | |
2512 # ifndef __WIN32__ | |
2513 /* Borland C++ 5.2 has this in a header file. */ | |
2514 extern char **environ; | |
2515 # endif | |
17 | 2516 # define ENVNAMELEN 100 |
2517 static char_u name[ENVNAMELEN]; | |
7 | 2518 char_u *str; |
2519 int n; | |
2520 | |
2521 str = (char_u *)environ[idx]; | |
2522 if (str == NULL) | |
2523 return NULL; | |
2524 | |
17 | 2525 for (n = 0; n < ENVNAMELEN - 1; ++n) |
7 | 2526 { |
2527 if (str[n] == '=' || str[n] == NUL) | |
2528 break; | |
2529 name[n] = str[n]; | |
2530 } | |
2531 name[n] = NUL; | |
2532 return name; | |
2533 # endif | |
2534 } | |
3744 | 2535 |
2536 /* | |
14698
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2537 * Add a user name to the list of users in ga_users. |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2538 * Do nothing if user name is NULL or empty. |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2539 */ |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2540 static void |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2541 add_user(char_u *user, int need_copy) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2542 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2543 char_u *user_copy = (user != NULL && need_copy) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2544 ? vim_strsave(user) : user; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2545 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2546 if (user_copy == NULL || *user_copy == NUL || ga_grow(&ga_users, 1) == FAIL) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2547 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2548 if (need_copy) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2549 vim_free(user); |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2550 return; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2551 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2552 ((char_u **)(ga_users.ga_data))[ga_users.ga_len++] = user_copy; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2553 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2554 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2555 /* |
3744 | 2556 * Find all user names for user completion. |
2557 * Done only once and then cached. | |
2558 */ | |
2559 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2560 init_users(void) |
4938
bcb84438bb5b
updated for version 7.3.1214
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2561 { |
3744 | 2562 static int lazy_init_done = FALSE; |
2563 | |
2564 if (lazy_init_done) | |
2565 return; | |
2566 | |
2567 lazy_init_done = TRUE; | |
2568 ga_init2(&ga_users, sizeof(char_u *), 20); | |
2569 | |
2570 # if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H) | |
2571 { | |
2572 struct passwd* pw; | |
2573 | |
2574 setpwent(); | |
2575 while ((pw = getpwent()) != NULL) | |
14698
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2576 add_user((char_u *)pw->pw_name, TRUE); |
3744 | 2577 endpwent(); |
2578 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15814
diff
changeset
|
2579 # elif defined(MSWIN) |
14133
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2580 { |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2581 DWORD nusers = 0, ntotal = 0, i; |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2582 PUSER_INFO_0 uinfo; |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2583 |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2584 if (NetUserEnum(NULL, 0, 0, (LPBYTE *) &uinfo, MAX_PREFERRED_LENGTH, |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2585 &nusers, &ntotal, NULL) == NERR_Success) |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2586 { |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2587 for (i = 0; i < nusers; i++) |
14698
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2588 add_user(utf16_to_enc(uinfo[i].usri0_name, NULL), FALSE); |
14133
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2589 |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2590 NetApiBufferFree(uinfo); |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2591 } |
352c2832d17f
patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13942
diff
changeset
|
2592 } |
3744 | 2593 # endif |
14698
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2594 # if defined(HAVE_GETPWNAM) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2595 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2596 char_u *user_env = mch_getenv((char_u *)"USER"); |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2597 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2598 // The $USER environment variable may be a valid remote user name (NIS, |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2599 // LDAP) not already listed by getpwent(), as getpwent() only lists |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2600 // local user names. If $USER is not already listed, check whether it |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2601 // is a valid remote user name using getpwnam() and if it is, add it to |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2602 // the list of user names. |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2603 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2604 if (user_env != NULL && *user_env != NUL) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2605 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2606 int i; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2607 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2608 for (i = 0; i < ga_users.ga_len; i++) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2609 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2610 char_u *local_user = ((char_u **)ga_users.ga_data)[i]; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2611 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2612 if (STRCMP(local_user, user_env) == 0) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2613 break; |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2614 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2615 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2616 if (i == ga_users.ga_len) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2617 { |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2618 struct passwd *pw = getpwnam((char *)user_env); |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2619 |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2620 if (pw != NULL) |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2621 add_user((char_u *)pw->pw_name, TRUE); |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2622 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2623 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2624 } |
d2cfca5b178e
patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents:
14629
diff
changeset
|
2625 # endif |
3744 | 2626 } |
2627 | |
2628 /* | |
2629 * Function given to ExpandGeneric() to obtain an user names. | |
2630 */ | |
2631 char_u* | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2632 get_users(expand_T *xp UNUSED, int idx) |
3744 | 2633 { |
2634 init_users(); | |
2635 if (idx < ga_users.ga_len) | |
2636 return ((char_u **)ga_users.ga_data)[idx]; | |
2637 return NULL; | |
2638 } | |
2639 | |
2640 /* | |
2641 * Check whether name matches a user name. Return: | |
2642 * 0 if name does not match any user name. | |
2643 * 1 if name partially matches the beginning of a user name. | |
2644 * 2 is name fully matches a user name. | |
2645 */ | |
14286
95030c543411
patch 8.1.0159: completion for user names does not work for a prefix.
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
2646 int |
95030c543411
patch 8.1.0159: completion for user names does not work for a prefix.
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
2647 match_user(char_u *name) |
3744 | 2648 { |
2649 int i; | |
2650 int n = (int)STRLEN(name); | |
2651 int result = 0; | |
2652 | |
2653 init_users(); | |
2654 for (i = 0; i < ga_users.ga_len; i++) | |
2655 { | |
2656 if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0) | |
2657 return 2; /* full match */ | |
2658 if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) | |
2659 result = 1; /* partial match */ | |
2660 } | |
2661 return result; | |
2662 } | |
7 | 2663 |
2664 /* | |
115 | 2665 * Concatenate two strings and return the result in allocated memory. |
2666 * Returns NULL when out of memory. | |
2667 */ | |
2668 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2669 concat_str(char_u *str1, char_u *str2) |
115 | 2670 { |
2671 char_u *dest; | |
2672 size_t l = STRLEN(str1); | |
2673 | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
2674 dest = alloc(l + STRLEN(str2) + 1L); |
115 | 2675 if (dest != NULL) |
2676 { | |
2677 STRCPY(dest, str1); | |
2678 STRCPY(dest + l, str2); | |
2679 } | |
2680 return dest; | |
2681 } | |
2682 | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2683 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2684 prepare_to_exit(void) |
7 | 2685 { |
39 | 2686 #if defined(SIGHUP) && defined(SIG_IGN) |
2687 /* Ignore SIGHUP, because a dropped connection causes a read error, which | |
2688 * makes Vim exit and then handling SIGHUP causes various reentrance | |
2689 * problems. */ | |
36 | 2690 signal(SIGHUP, SIG_IGN); |
2691 #endif | |
2692 | |
7 | 2693 #ifdef FEAT_GUI |
2694 if (gui.in_use) | |
2695 { | |
2696 gui.dying = TRUE; | |
2697 out_trash(); /* trash any pending output */ | |
2698 } | |
2699 else | |
2700 #endif | |
2701 { | |
2702 windgoto((int)Rows - 1, 0); | |
2703 | |
2704 /* | |
2705 * Switch terminal mode back now, so messages end up on the "normal" | |
2706 * screen (if there are two screens). | |
2707 */ | |
2708 settmode(TMODE_COOK); | |
10264
c036c0f636d5
commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents:
10180
diff
changeset
|
2709 stoptermcap(); |
7 | 2710 out_flush(); |
2711 } | |
2712 } | |
2713 | |
2714 /* | |
2715 * Preserve files and exit. | |
2716 * When called IObuff must contain a message. | |
5338 | 2717 * NOTE: This may be called from deathtrap() in a signal handler, avoid unsafe |
2718 * functions, such as allocating memory. | |
7 | 2719 */ |
2720 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2721 preserve_exit(void) |
7 | 2722 { |
2723 buf_T *buf; | |
2724 | |
2725 prepare_to_exit(); | |
2726 | |
625 | 2727 /* Setting this will prevent free() calls. That avoids calling free() |
2728 * recursively when free() was invoked with a bad pointer. */ | |
2729 really_exiting = TRUE; | |
2730 | |
7 | 2731 out_str(IObuff); |
2732 screen_start(); /* don't know where cursor is now */ | |
2733 out_flush(); | |
2734 | |
2735 ml_close_notmod(); /* close all not-modified buffers */ | |
2736 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
2737 FOR_ALL_BUFFERS(buf) |
7 | 2738 { |
2739 if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) | |
2740 { | |
5338 | 2741 OUT_STR("Vim: preserving files...\n"); |
7 | 2742 screen_start(); /* don't know where cursor is now */ |
2743 out_flush(); | |
2744 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2745 break; | |
2746 } | |
2747 } | |
2748 | |
2749 ml_close_all(FALSE); /* close all memfiles, without deleting */ | |
2750 | |
5338 | 2751 OUT_STR("Vim: Finished.\n"); |
7 | 2752 |
2753 getout(1); | |
2754 } | |
2755 | |
2756 /* | |
2757 * Check for CTRL-C pressed, but only once in a while. | |
2758 * Should be used instead of ui_breakcheck() for functions that check for | |
2759 * each line in the file. Calling ui_breakcheck() each time takes too much | |
2760 * time, because it can be a system call. | |
2761 */ | |
2762 | |
2763 #ifndef BREAKCHECK_SKIP | |
17452
f12745505a23
patch 8.1.1724: too much overhead checking for CTRL-C while processing text
Bram Moolenaar <Bram@vim.org>
parents:
17018
diff
changeset
|
2764 # define BREAKCHECK_SKIP 1000 |
7 | 2765 #endif |
2766 | |
2767 static int breakcheck_count = 0; | |
2768 | |
2769 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2770 line_breakcheck(void) |
7 | 2771 { |
2772 if (++breakcheck_count >= BREAKCHECK_SKIP) | |
2773 { | |
2774 breakcheck_count = 0; | |
2775 ui_breakcheck(); | |
2776 } | |
2777 } | |
2778 | |
2779 /* | |
2780 * Like line_breakcheck() but check 10 times less often. | |
2781 */ | |
2782 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2783 fast_breakcheck(void) |
7 | 2784 { |
2785 if (++breakcheck_count >= BREAKCHECK_SKIP * 10) | |
2786 { | |
2787 breakcheck_count = 0; | |
2788 ui_breakcheck(); | |
2789 } | |
2790 } | |
2791 | |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17452
diff
changeset
|
2792 #if defined(VIM_BACKTICK) || defined(FEAT_EVAL) \ |
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17452
diff
changeset
|
2793 || (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ |
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17452
diff
changeset
|
2794 || defined(PROTO) |
7 | 2795 |
2796 #ifndef SEEK_SET | |
2797 # define SEEK_SET 0 | |
2798 #endif | |
2799 #ifndef SEEK_END | |
2800 # define SEEK_END 2 | |
2801 #endif | |
2802 | |
2803 /* | |
2804 * Get the stdout of an external command. | |
5808 | 2805 * If "ret_len" is NULL replace NUL characters with NL. When "ret_len" is not |
2806 * NULL store the length there. | |
7 | 2807 * Returns an allocated string, or NULL for error. |
2808 */ | |
2809 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2810 get_cmd_output( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2811 char_u *cmd, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2812 char_u *infile, /* optional input file name */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2813 int flags, /* can be SHELL_SILENT */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2814 int *ret_len) |
7 | 2815 { |
2816 char_u *tempname; | |
2817 char_u *command; | |
2818 char_u *buffer = NULL; | |
2819 int len; | |
2820 int i = 0; | |
2821 FILE *fd; | |
2822 | |
2823 if (check_restricted() || check_secure()) | |
2824 return NULL; | |
2825 | |
2826 /* get a name for the temp file */ | |
6721 | 2827 if ((tempname = vim_tempname('o', FALSE)) == NULL) |
7 | 2828 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15420
diff
changeset
|
2829 emsg(_(e_notmp)); |
7 | 2830 return NULL; |
2831 } | |
2832 | |
2833 /* Add the redirection stuff */ | |
24 | 2834 command = make_filter_cmd(cmd, infile, tempname); |
7 | 2835 if (command == NULL) |
2836 goto done; | |
2837 | |
2838 /* | |
2839 * Call the shell to execute the command (errors are ignored). | |
2840 * Don't check timestamps here. | |
2841 */ | |
2842 ++no_check_timestamps; | |
2843 call_shell(command, SHELL_DOOUT | SHELL_EXPAND | flags); | |
2844 --no_check_timestamps; | |
2845 | |
2846 vim_free(command); | |
2847 | |
2848 /* | |
2849 * read the names from the file into memory | |
2850 */ | |
2851 # ifdef VMS | |
1224 | 2852 /* created temporary file is not always readable as binary */ |
7 | 2853 fd = mch_fopen((char *)tempname, "r"); |
2854 # else | |
2855 fd = mch_fopen((char *)tempname, READBIN); | |
2856 # endif | |
2857 | |
2858 if (fd == NULL) | |
2859 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15420
diff
changeset
|
2860 semsg(_(e_notopen), tempname); |
7 | 2861 goto done; |
2862 } | |
2863 | |
2864 fseek(fd, 0L, SEEK_END); | |
2865 len = ftell(fd); /* get size of temp file */ | |
2866 fseek(fd, 0L, SEEK_SET); | |
2867 | |
2868 buffer = alloc(len + 1); | |
2869 if (buffer != NULL) | |
2870 i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd); | |
2871 fclose(fd); | |
2872 mch_remove(tempname); | |
2873 if (buffer == NULL) | |
2874 goto done; | |
2875 #ifdef VMS | |
2876 len = i; /* VMS doesn't give us what we asked for... */ | |
2877 #endif | |
2878 if (i != len) | |
2879 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15420
diff
changeset
|
2880 semsg(_(e_notread), tempname); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
2881 VIM_CLEAR(buffer); |
7 | 2882 } |
5808 | 2883 else if (ret_len == NULL) |
5271
25f67b62afd8
updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2884 { |
25f67b62afd8
updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2885 /* Change NUL into SOH, otherwise the string is truncated. */ |
25f67b62afd8
updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2886 for (i = 0; i < len; ++i) |
5275
3ddec3d25bd1
updated for version 7.4b.014
Bram Moolenaar <bram@vim.org>
parents:
5271
diff
changeset
|
2887 if (buffer[i] == NUL) |
3ddec3d25bd1
updated for version 7.4b.014
Bram Moolenaar <bram@vim.org>
parents:
5271
diff
changeset
|
2888 buffer[i] = 1; |
5271
25f67b62afd8
updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2889 |
2429
7ce8b24450dc
Improvements for ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
2890 buffer[len] = NUL; /* make sure the buffer is terminated */ |
5271
25f67b62afd8
updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2891 } |
5808 | 2892 else |
2893 *ret_len = len; | |
7 | 2894 |
2895 done: | |
2896 vim_free(tempname); | |
2897 return buffer; | |
2898 } | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2899 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2900 # if defined(FEAT_EVAL) || defined(PROTO) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2901 |
18051
d1e77015f60b
patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
2902 static void |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2903 get_cmd_output_as_rettv( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2904 typval_T *argvars, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2905 typval_T *rettv, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2906 int retlist) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2907 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2908 char_u *res = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2909 char_u *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2910 char_u *infile = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2911 int err = FALSE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2912 FILE *fd; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2913 list_T *list = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2914 int flags = SHELL_SILENT; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2915 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2916 rettv->v_type = VAR_STRING; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2917 rettv->vval.v_string = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2918 if (check_restricted() || check_secure()) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2919 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2920 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2921 if (argvars[1].v_type != VAR_UNKNOWN) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2922 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2923 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2924 * Write the text to a temp file, to be used for input of the shell |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2925 * command. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2926 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2927 if ((infile = vim_tempname('i', TRUE)) == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2928 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2929 emsg(_(e_notmp)); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2930 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2931 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2932 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2933 fd = mch_fopen((char *)infile, WRITEBIN); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2934 if (fd == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2935 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2936 semsg(_(e_notopen), infile); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2937 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2938 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2939 if (argvars[1].v_type == VAR_NUMBER) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2940 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2941 linenr_T lnum; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2942 buf_T *buf; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2943 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2944 buf = buflist_findnr(argvars[1].vval.v_number); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2945 if (buf == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2946 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2947 semsg(_(e_nobufnr), argvars[1].vval.v_number); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2948 fclose(fd); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2949 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2950 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2951 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2952 for (lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2953 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2954 for (p = ml_get_buf(buf, lnum, FALSE); *p != NUL; ++p) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2955 if (putc(*p == '\n' ? NUL : *p, fd) == EOF) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2956 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2957 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2958 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2959 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2960 if (putc(NL, fd) == EOF) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2961 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2962 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2963 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2964 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2965 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2966 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2967 else if (argvars[1].v_type == VAR_LIST) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2968 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2969 if (write_list(fd, argvars[1].vval.v_list, TRUE) == FAIL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2970 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2971 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2972 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2973 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2974 size_t len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2975 char_u buf[NUMBUFLEN]; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2976 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2977 p = tv_get_string_buf_chk(&argvars[1], buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2978 if (p == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2979 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2980 fclose(fd); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2981 goto errret; /* type error; errmsg already given */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2982 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2983 len = STRLEN(p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2984 if (len > 0 && fwrite(p, len, 1, fd) != 1) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2985 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2986 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2987 if (fclose(fd) != 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2988 err = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2989 if (err) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2990 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2991 emsg(_("E677: Error writing temp file")); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2992 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2993 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2994 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2995 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2996 /* Omit SHELL_COOKED when invoked with ":silent". Avoids that the shell |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2997 * echoes typeahead, that messes up the display. */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2998 if (!msg_silent) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2999 flags += SHELL_COOKED; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3000 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3001 if (retlist) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3002 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3003 int len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3004 listitem_T *li; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3005 char_u *s = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3006 char_u *start; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3007 char_u *end; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3008 int i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3009 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3010 res = get_cmd_output(tv_get_string(&argvars[0]), infile, flags, &len); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3011 if (res == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3012 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3013 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3014 list = list_alloc(); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3015 if (list == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3016 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3017 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3018 for (i = 0; i < len; ++i) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3019 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3020 start = res + i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3021 while (i < len && res[i] != NL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3022 ++i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3023 end = res + i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3024 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3025 s = alloc(end - start + 1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3026 if (s == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3027 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3028 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3029 for (p = s; start < end; ++p, ++start) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3030 *p = *start == NUL ? NL : *start; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3031 *p = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3032 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3033 li = listitem_alloc(); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3034 if (li == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3035 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3036 vim_free(s); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3037 goto errret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3038 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3039 li->li_tv.v_type = VAR_STRING; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3040 li->li_tv.v_lock = 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3041 li->li_tv.vval.v_string = s; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3042 list_append(list, li); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3043 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3044 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3045 rettv_list_set(rettv, list); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3046 list = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3047 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3048 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3049 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3050 res = get_cmd_output(tv_get_string(&argvars[0]), infile, flags, NULL); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3051 #ifdef USE_CRNL |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3052 /* translate <CR><NL> into <NL> */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3053 if (res != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3054 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3055 char_u *s, *d; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3056 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3057 d = res; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3058 for (s = res; *s; ++s) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3059 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3060 if (s[0] == CAR && s[1] == NL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3061 ++s; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3062 *d++ = *s; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3063 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3064 *d = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3065 } |
7 | 3066 #endif |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3067 rettv->vval.v_string = res; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3068 res = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3069 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3070 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3071 errret: |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3072 if (infile != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3073 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3074 mch_remove(infile); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3075 vim_free(infile); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3076 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3077 if (res != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3078 vim_free(res); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3079 if (list != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3080 list_free(list); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3081 } |
7 | 3082 |
3083 /* | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3084 * "system()" function |
7 | 3085 */ |
3086 void | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3087 f_system(typval_T *argvars, typval_T *rettv) |
7 | 3088 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3089 get_cmd_output_as_rettv(argvars, rettv, FALSE); |
7 | 3090 } |
3091 | |
3092 /* | |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3093 * "systemlist()" function |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3094 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3095 void |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3096 f_systemlist(typval_T *argvars, typval_T *rettv) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3097 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3098 get_cmd_output_as_rettv(argvars, rettv, TRUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3099 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3100 # endif // FEAT_EVAL |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3101 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3102 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3103 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3104 /* |
2302
488be8cbe19c
Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
3105 * Return TRUE when need to go to Insert mode because of 'insertmode'. |
7 | 3106 * Don't do this when still processing a command or a mapping. |
3107 * Don't do this when inside a ":normal" command. | |
3108 */ | |
3109 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3110 goto_im(void) |
7 | 3111 { |
3112 return (p_im && stuff_empty() && typebuf_typed()); | |
3113 } | |
5867 | 3114 |
3115 /* | |
5911 | 3116 * Returns the isolated name of the shell in allocated memory: |
5867 | 3117 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f". |
3118 * - Remove any argument. E.g., "csh -f" -> "csh". | |
3119 * But don't allow a space in the path, so that this works: | |
3120 * "/usr/bin/csh --rcfile ~/.cshrc" | |
3121 * But don't do that for Windows, it's common to have a space in the path. | |
3122 */ | |
3123 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3124 get_isolated_shell_name(void) |
5867 | 3125 { |
3126 char_u *p; | |
3127 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15814
diff
changeset
|
3128 #ifdef MSWIN |
5867 | 3129 p = gettail(p_sh); |
3130 p = vim_strnsave(p, (int)(skiptowhite(p) - p)); | |
3131 #else | |
3132 p = skiptowhite(p_sh); | |
3133 if (*p == NUL) | |
3134 { | |
3135 /* No white space, use the tail. */ | |
3136 p = vim_strsave(gettail(p_sh)); | |
3137 } | |
3138 else | |
3139 { | |
3140 char_u *p1, *p2; | |
3141 | |
3142 /* Find the last path separator before the space. */ | |
3143 p1 = p_sh; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3144 for (p2 = p_sh; p2 < p; MB_PTR_ADV(p2)) |
5867 | 3145 if (vim_ispathsep(*p2)) |
3146 p1 = p2 + 1; | |
3147 p = vim_strnsave(p1, (int)(p - p1)); | |
3148 } | |
3149 #endif | |
3150 return p; | |
3151 } | |
15814
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3152 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3153 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3154 * Check if the "://" of a URL is at the pointer, return URL_SLASH. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3155 * Also check for ":\\", which MS Internet Explorer accepts, return |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3156 * URL_BACKSLASH. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3157 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3158 int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3159 path_is_url(char_u *p) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3160 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3161 if (STRNCMP(p, "://", (size_t)3) == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3162 return URL_SLASH; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3163 else if (STRNCMP(p, ":\\\\", (size_t)3) == 0) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3164 return URL_BACKSLASH; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3165 return 0; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3166 } |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3167 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3168 /* |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3169 * Check if "fname" starts with "name://". Return URL_SLASH if it does. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3170 * Return URL_BACKSLASH for "name:\\". |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3171 * Return zero otherwise. |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3172 */ |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3173 int |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3174 path_with_url(char_u *fname) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3175 { |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3176 char_u *p; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3177 |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3178 for (p = fname; isalpha(*p); ++p) |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3179 ; |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3180 return path_is_url(p); |
99ebf78686a9
patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents:
15699
diff
changeset
|
3181 } |