Mercurial > vim
annotate src/ex_cmds2.c @ 16872:a836d122231a v8.1.1437
patch 8.1.1437: code to handle callbacks is duplicated
commit https://github.com/vim/vim/commit/3a97bb3f0f8bd118ae23f1c97e55d84ff42eef20
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jun 1 13:28:35 2019 +0200
patch 8.1.1437: code to handle callbacks is duplicated
Problem: Code to handle callbacks is duplicated.
Solution: Add callback_T and functions to deal with it.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 01 Jun 2019 13:30:07 +0200 |
parents | ce04ebdf26b8 |
children | da5f5836e90c |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9812
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 * ex_cmds2.c: some more functions for command line commands | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 #include "version.h" | |
16 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
17 static void cmd_source(char_u *fname, exarg_T *eap); |
7 | 18 |
170 | 19 #ifdef FEAT_EVAL |
177 | 20 /* Growarray to store info about already sourced scripts. |
170 | 21 * For Unix also store the dev/ino, so that we don't have to stat() each |
22 * script when going through the list. */ | |
23 typedef struct scriptitem_S | |
24 { | |
25 char_u *sn_name; | |
26 # ifdef UNIX | |
1882 | 27 int sn_dev_valid; |
28 dev_t sn_dev; | |
170 | 29 ino_t sn_ino; |
30 # endif | |
31 # ifdef FEAT_PROFILE | |
32 int sn_prof_on; /* TRUE when script is/was profiled */ | |
177 | 33 int sn_pr_force; /* forceit: profile functions in this script */ |
170 | 34 proftime_T sn_pr_child; /* time set when going into first child */ |
35 int sn_pr_nest; /* nesting for sn_pr_child */ | |
36 /* profiling the script as a whole */ | |
37 int sn_pr_count; /* nr of times sourced */ | |
1624 | 38 proftime_T sn_pr_total; /* time spent in script + children */ |
39 proftime_T sn_pr_self; /* time spent in script itself */ | |
170 | 40 proftime_T sn_pr_start; /* time at script start */ |
41 proftime_T sn_pr_children; /* time in children after script start */ | |
42 /* profiling the script per line */ | |
43 garray_T sn_prl_ga; /* things stored for every line */ | |
44 proftime_T sn_prl_start; /* start time for current line */ | |
45 proftime_T sn_prl_children; /* time spent in children for this line */ | |
46 proftime_T sn_prl_wait; /* wait start time for current line */ | |
47 int sn_prl_idx; /* index of line being timed; -1 if none */ | |
48 int sn_prl_execed; /* line being timed was executed */ | |
49 # endif | |
50 } scriptitem_T; | |
51 | |
52 static garray_T script_items = {0, 0, sizeof(scriptitem_T), 4, NULL}; | |
53 #define SCRIPT_ITEM(id) (((scriptitem_T *)script_items.ga_data)[(id) - 1]) | |
54 | |
55 # ifdef FEAT_PROFILE | |
56 /* Struct used in sn_prl_ga for every line of a script. */ | |
57 typedef struct sn_prl_S | |
58 { | |
59 int snp_count; /* nr of times line was executed */ | |
1624 | 60 proftime_T sn_prl_total; /* time spent in a line + children */ |
61 proftime_T sn_prl_self; /* time spent in a line itself */ | |
170 | 62 } sn_prl_T; |
63 | |
64 # define PRL_ITEM(si, idx) (((sn_prl_T *)(si)->sn_prl_ga.ga_data)[(idx)]) | |
65 # endif | |
66 #endif | |
67 | |
7 | 68 #if defined(FEAT_EVAL) || defined(PROTO) |
794 | 69 # if defined(FEAT_PROFILE) || defined(FEAT_RELTIME) || defined(PROTO) |
170 | 70 /* |
71 * Store the current time in "tm". | |
72 */ | |
73 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
74 profile_start(proftime_T *tm) |
170 | 75 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
76 # ifdef MSWIN |
177 | 77 QueryPerformanceCounter(tm); |
78 # else | |
170 | 79 gettimeofday(tm, NULL); |
177 | 80 # endif |
170 | 81 } |
82 | |
83 /* | |
84 * Compute the elapsed time from "tm" till now and store in "tm". | |
85 */ | |
86 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
87 profile_end(proftime_T *tm) |
170 | 88 { |
89 proftime_T now; | |
90 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
91 # ifdef MSWIN |
177 | 92 QueryPerformanceCounter(&now); |
93 tm->QuadPart = now.QuadPart - tm->QuadPart; | |
94 # else | |
170 | 95 gettimeofday(&now, NULL); |
96 tm->tv_usec = now.tv_usec - tm->tv_usec; | |
97 tm->tv_sec = now.tv_sec - tm->tv_sec; | |
98 if (tm->tv_usec < 0) | |
99 { | |
100 tm->tv_usec += 1000000; | |
101 --tm->tv_sec; | |
102 } | |
177 | 103 # endif |
170 | 104 } |
105 | |
106 /* | |
107 * Subtract the time "tm2" from "tm". | |
108 */ | |
109 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
110 profile_sub(proftime_T *tm, proftime_T *tm2) |
170 | 111 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
112 # ifdef MSWIN |
177 | 113 tm->QuadPart -= tm2->QuadPart; |
114 # else | |
170 | 115 tm->tv_usec -= tm2->tv_usec; |
116 tm->tv_sec -= tm2->tv_sec; | |
117 if (tm->tv_usec < 0) | |
118 { | |
119 tm->tv_usec += 1000000; | |
120 --tm->tv_sec; | |
121 } | |
177 | 122 # endif |
170 | 123 } |
124 | |
125 /* | |
794 | 126 * Return a string that represents the time in "tm". |
127 * Uses a static buffer! | |
128 */ | |
129 char * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
130 profile_msg(proftime_T *tm) |
794 | 131 { |
132 static char buf[50]; | |
133 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
134 # ifdef MSWIN |
794 | 135 LARGE_INTEGER fr; |
136 | |
137 QueryPerformanceFrequency(&fr); | |
138 sprintf(buf, "%10.6lf", (double)tm->QuadPart / (double)fr.QuadPart); | |
139 # else | |
140 sprintf(buf, "%3ld.%06ld", (long)tm->tv_sec, (long)tm->tv_usec); | |
1496 | 141 # endif |
794 | 142 return buf; |
143 } | |
144 | |
7979
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
145 # if defined(FEAT_FLOAT) || defined(PROTO) |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
146 /* |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
147 * Return a float that represents the time in "tm". |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
148 */ |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
149 float_T |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
150 profile_float(proftime_T *tm) |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
151 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
152 # ifdef MSWIN |
7979
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
153 LARGE_INTEGER fr; |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
154 |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
155 QueryPerformanceFrequency(&fr); |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
156 return (float_T)tm->QuadPart / (float_T)fr.QuadPart; |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
157 # else |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
158 return (float_T)tm->tv_sec + (float_T)tm->tv_usec / 1000000.0; |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
159 # endif |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
160 } |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
161 # endif |
22367b9f528a
commit https://github.com/vim/vim/commit/79c2c881bb7ae1cbdeeff91d4875b4bf2e54df06
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
162 |
794 | 163 /* |
1496 | 164 * Put the time "msec" past now in "tm". |
794 | 165 */ |
1496 | 166 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
167 profile_setlimit(long msec, proftime_T *tm) |
1496 | 168 { |
169 if (msec <= 0) /* no limit */ | |
170 profile_zero(tm); | |
171 else | |
172 { | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
173 # ifdef MSWIN |
1496 | 174 LARGE_INTEGER fr; |
175 | |
176 QueryPerformanceCounter(tm); | |
177 QueryPerformanceFrequency(&fr); | |
1517 | 178 tm->QuadPart += (LONGLONG)((double)msec / 1000.0 * (double)fr.QuadPart); |
1496 | 179 # else |
180 long usec; | |
181 | |
182 gettimeofday(tm, NULL); | |
183 usec = (long)tm->tv_usec + (long)msec * 1000; | |
184 tm->tv_usec = usec % 1000000L; | |
185 tm->tv_sec += usec / 1000000L; | |
186 # endif | |
187 } | |
188 } | |
189 | |
190 /* | |
191 * Return TRUE if the current time is past "tm". | |
192 */ | |
193 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
194 profile_passed_limit(proftime_T *tm) |
1496 | 195 { |
196 proftime_T now; | |
197 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
198 # ifdef MSWIN |
1496 | 199 if (tm->QuadPart == 0) /* timer was not set */ |
200 return FALSE; | |
201 QueryPerformanceCounter(&now); | |
202 return (now.QuadPart > tm->QuadPart); | |
203 # else | |
204 if (tm->tv_sec == 0) /* timer was not set */ | |
205 return FALSE; | |
206 gettimeofday(&now, NULL); | |
207 return (now.tv_sec > tm->tv_sec | |
208 || (now.tv_sec == tm->tv_sec && now.tv_usec > tm->tv_usec)); | |
209 # endif | |
210 } | |
794 | 211 |
212 /* | |
213 * Set the time in "tm" to zero. | |
214 */ | |
215 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
216 profile_zero(proftime_T *tm) |
794 | 217 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
218 # ifdef MSWIN |
794 | 219 tm->QuadPart = 0; |
220 # else | |
221 tm->tv_usec = 0; | |
222 tm->tv_sec = 0; | |
223 # endif | |
224 } | |
225 | |
1496 | 226 # endif /* FEAT_PROFILE || FEAT_RELTIME */ |
227 | |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
228 # if defined(FEAT_TIMERS) || defined(PROTO) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
229 static timer_T *first_timer = NULL; |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
230 static long last_timer_id = 0; |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
231 |
16594
6f52e82d9d4e
patch 8.1.1300: in a terminal 'ballooneval' does not work right away
Bram Moolenaar <Bram@vim.org>
parents:
16515
diff
changeset
|
232 /* |
6f52e82d9d4e
patch 8.1.1300: in a terminal 'ballooneval' does not work right away
Bram Moolenaar <Bram@vim.org>
parents:
16515
diff
changeset
|
233 * Return time left until "due". Negative if past "due". |
6f52e82d9d4e
patch 8.1.1300: in a terminal 'ballooneval' does not work right away
Bram Moolenaar <Bram@vim.org>
parents:
16515
diff
changeset
|
234 */ |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
235 long |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
236 proftime_time_left(proftime_T *due, proftime_T *now) |
12495
65f8c6fcfd83
patch 8.0.1127: Test_peek_and_get_char fails on 32 bit system
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
237 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
238 # ifdef MSWIN |
12495
65f8c6fcfd83
patch 8.0.1127: Test_peek_and_get_char fails on 32 bit system
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
239 LARGE_INTEGER fr; |
65f8c6fcfd83
patch 8.0.1127: Test_peek_and_get_char fails on 32 bit system
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
240 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
241 if (now->QuadPart > due->QuadPart) |
12495
65f8c6fcfd83
patch 8.0.1127: Test_peek_and_get_char fails on 32 bit system
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
242 return 0; |
65f8c6fcfd83
patch 8.0.1127: Test_peek_and_get_char fails on 32 bit system
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
243 QueryPerformanceFrequency(&fr); |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
244 return (long)(((double)(due->QuadPart - now->QuadPart) |
12495
65f8c6fcfd83
patch 8.0.1127: Test_peek_and_get_char fails on 32 bit system
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
245 / (double)fr.QuadPart) * 1000); |
65f8c6fcfd83
patch 8.0.1127: Test_peek_and_get_char fails on 32 bit system
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
246 # else |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
247 if (now->tv_sec > due->tv_sec) |
12495
65f8c6fcfd83
patch 8.0.1127: Test_peek_and_get_char fails on 32 bit system
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
248 return 0; |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
249 return (due->tv_sec - now->tv_sec) * 1000 |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
250 + (due->tv_usec - now->tv_usec) / 1000; |
12495
65f8c6fcfd83
patch 8.0.1127: Test_peek_and_get_char fails on 32 bit system
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
251 # endif |
65f8c6fcfd83
patch 8.0.1127: Test_peek_and_get_char fails on 32 bit system
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
252 } |
10066
dc1610dc910f
commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
253 |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
254 /* |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
255 * Insert a timer in the list of timers. |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
256 */ |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
257 static void |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
258 insert_timer(timer_T *timer) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
259 { |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
260 timer->tr_next = first_timer; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
261 timer->tr_prev = NULL; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
262 if (first_timer != NULL) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
263 first_timer->tr_prev = timer; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
264 first_timer = timer; |
9179
5e18efdad322
commit https://github.com/vim/vim/commit/4231da403e3c879dd6ac261e51f4ca60813935e3
Christian Brabandt <cb@256bit.org>
parents:
9155
diff
changeset
|
265 did_add_timer = TRUE; |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
266 } |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
267 |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
268 /* |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
269 * Take a timer out of the list of timers. |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
270 */ |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
271 static void |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
272 remove_timer(timer_T *timer) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
273 { |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
274 if (timer->tr_prev == NULL) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
275 first_timer = timer->tr_next; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
276 else |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
277 timer->tr_prev->tr_next = timer->tr_next; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
278 if (timer->tr_next != NULL) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
279 timer->tr_next->tr_prev = timer->tr_prev; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
280 } |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
281 |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
282 static void |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
283 free_timer(timer_T *timer) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
284 { |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
285 free_callback(&timer->tr_callback); |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
286 vim_free(timer); |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
287 } |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
288 |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
289 /* |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
290 * Create a timer and return it. NULL if out of memory. |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
291 * Caller should set the callback. |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
292 */ |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
293 timer_T * |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
294 create_timer(long msec, int repeat) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
295 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
296 timer_T *timer = ALLOC_CLEAR_ONE(timer_T); |
10182
40f6ce4fe30e
commit https://github.com/vim/vim/commit/ee39ef0b93d31763d05e54ba99801e3f1a254c0d
Christian Brabandt <cb@256bit.org>
parents:
10122
diff
changeset
|
297 long prev_id = last_timer_id; |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
298 |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
299 if (timer == NULL) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
300 return NULL; |
10182
40f6ce4fe30e
commit https://github.com/vim/vim/commit/ee39ef0b93d31763d05e54ba99801e3f1a254c0d
Christian Brabandt <cb@256bit.org>
parents:
10122
diff
changeset
|
301 if (++last_timer_id <= prev_id) |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
302 /* Overflow! Might cause duplicates... */ |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
303 last_timer_id = 0; |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
304 timer->tr_id = last_timer_id; |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
305 insert_timer(timer); |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
306 if (repeat != 0) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
307 timer->tr_repeat = repeat - 1; |
9790
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
308 timer->tr_interval = msec; |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
309 |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
310 profile_setlimit(msec, &timer->tr_due); |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
311 return timer; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
312 } |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
313 |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
314 /* |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
315 * Invoke the callback of "timer". |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
316 */ |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
317 static void |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
318 timer_callback(timer_T *timer) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
319 { |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
320 typval_T rettv; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
321 int dummy; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
322 typval_T argv[2]; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
323 |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
324 argv[0].v_type = VAR_NUMBER; |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
325 argv[0].vval.v_number = (varnumber_T)timer->tr_id; |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
326 argv[1].v_type = VAR_UNKNOWN; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
327 |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
328 call_callback(&timer->tr_callback, -1, |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
329 &rettv, 1, argv, NULL, 0L, 0L, &dummy, TRUE, NULL); |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
330 clear_tv(&rettv); |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
331 } |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
332 |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
333 /* |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
334 * Call timers that are due. |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
335 * Return the time in msec until the next timer is due. |
11631
3b53bb2a0e39
patch 8.0.0698: crash on exit when using Python function in timer.
Christian Brabandt <cb@256bit.org>
parents:
11595
diff
changeset
|
336 * Returns -1 if there are no pending timers. |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
337 */ |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
338 long |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9179
diff
changeset
|
339 check_due_timer(void) |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
340 { |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
341 timer_T *timer; |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
342 timer_T *timer_next; |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
343 long this_due; |
8587
fb8d7086e99d
commit https://github.com/vim/vim/commit/597385ab43093ba27adcb86cdc1b46aba86a0093
Christian Brabandt <cb@256bit.org>
parents:
8577
diff
changeset
|
344 long next_due = -1; |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
345 proftime_T now; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
346 int did_one = FALSE; |
12244
d0b039e2ed56
patch 8.0.1002: unnecessarily updating screen after timer callback
Christian Brabandt <cb@256bit.org>
parents:
12206
diff
changeset
|
347 int need_update_screen = FALSE; |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
348 long current_id = last_timer_id; |
11639
71d7b5ed08a0
patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents:
11631
diff
changeset
|
349 |
71d7b5ed08a0
patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents:
11631
diff
changeset
|
350 /* Don't run any timers while exiting or dealing with an error. */ |
71d7b5ed08a0
patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents:
11631
diff
changeset
|
351 if (exiting || aborting()) |
11631
3b53bb2a0e39
patch 8.0.0698: crash on exit when using Python function in timer.
Christian Brabandt <cb@256bit.org>
parents:
11595
diff
changeset
|
352 return next_due; |
3b53bb2a0e39
patch 8.0.0698: crash on exit when using Python function in timer.
Christian Brabandt <cb@256bit.org>
parents:
11595
diff
changeset
|
353 |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
354 profile_start(&now); |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
355 for (timer = first_timer; timer != NULL && !got_int; timer = timer_next) |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
356 { |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
357 timer_next = timer->tr_next; |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
358 |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
359 if (timer->tr_id == -1 || timer->tr_firing || timer->tr_paused) |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
360 continue; |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
361 this_due = proftime_time_left(&timer->tr_due, &now); |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
362 if (this_due <= 1) |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
363 { |
13892
eadecbe4e390
patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
364 /* Save and restore a lot of flags, because the timer fires while |
eadecbe4e390
patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
365 * waiting for a character, which might be halfway a command. */ |
11575
0ec755ff1fe2
patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents:
11457
diff
changeset
|
366 int save_timer_busy = timer_busy; |
0ec755ff1fe2
patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents:
11457
diff
changeset
|
367 int save_vgetc_busy = vgetc_busy; |
12375
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
368 int save_did_emsg = did_emsg; |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
369 int save_called_emsg = called_emsg; |
12244
d0b039e2ed56
patch 8.0.1002: unnecessarily updating screen after timer callback
Christian Brabandt <cb@256bit.org>
parents:
12206
diff
changeset
|
370 int save_must_redraw = must_redraw; |
12375
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
371 int save_trylevel = trylevel; |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
372 int save_did_throw = did_throw; |
12459
937356f8f8d6
patch 8.0.1109: timer causes error on exit from Ex mode
Christian Brabandt <cb@256bit.org>
parents:
12375
diff
changeset
|
373 int save_ex_pressedreturn = get_pressedreturn(); |
12375
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
374 except_T *save_current_exception = current_exception; |
13892
eadecbe4e390
patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
375 vimvars_save_T vvsave; |
12375
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
376 |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
377 /* Create a scope for running the timer callback, ignoring most of |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
378 * the current scope, such as being inside a try/catch. */ |
11575
0ec755ff1fe2
patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents:
11457
diff
changeset
|
379 timer_busy = timer_busy > 0 || vgetc_busy > 0; |
0ec755ff1fe2
patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents:
11457
diff
changeset
|
380 vgetc_busy = 0; |
11639
71d7b5ed08a0
patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents:
11631
diff
changeset
|
381 called_emsg = FALSE; |
12375
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
382 did_emsg = FALSE; |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
383 did_uncaught_emsg = FALSE; |
12244
d0b039e2ed56
patch 8.0.1002: unnecessarily updating screen after timer callback
Christian Brabandt <cb@256bit.org>
parents:
12206
diff
changeset
|
384 must_redraw = 0; |
12375
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
385 trylevel = 0; |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
386 did_throw = FALSE; |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
387 current_exception = NULL; |
13892
eadecbe4e390
patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
388 save_vimvars(&vvsave); |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
389 timer->tr_firing = TRUE; |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
390 timer_callback(timer); |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
391 timer->tr_firing = FALSE; |
12375
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
392 |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
393 timer_next = timer->tr_next; |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
394 did_one = TRUE; |
11575
0ec755ff1fe2
patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents:
11457
diff
changeset
|
395 timer_busy = save_timer_busy; |
0ec755ff1fe2
patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents:
11457
diff
changeset
|
396 vgetc_busy = save_vgetc_busy; |
12375
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
397 if (did_uncaught_emsg) |
11639
71d7b5ed08a0
patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents:
11631
diff
changeset
|
398 ++timer->tr_emsg_count; |
12375
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
399 did_emsg = save_did_emsg; |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
400 called_emsg = save_called_emsg; |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
401 trylevel = save_trylevel; |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
402 did_throw = save_did_throw; |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12244
diff
changeset
|
403 current_exception = save_current_exception; |
13892
eadecbe4e390
patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
404 restore_vimvars(&vvsave); |
12244
d0b039e2ed56
patch 8.0.1002: unnecessarily updating screen after timer callback
Christian Brabandt <cb@256bit.org>
parents:
12206
diff
changeset
|
405 if (must_redraw != 0) |
d0b039e2ed56
patch 8.0.1002: unnecessarily updating screen after timer callback
Christian Brabandt <cb@256bit.org>
parents:
12206
diff
changeset
|
406 need_update_screen = TRUE; |
d0b039e2ed56
patch 8.0.1002: unnecessarily updating screen after timer callback
Christian Brabandt <cb@256bit.org>
parents:
12206
diff
changeset
|
407 must_redraw = must_redraw > save_must_redraw |
d0b039e2ed56
patch 8.0.1002: unnecessarily updating screen after timer callback
Christian Brabandt <cb@256bit.org>
parents:
12206
diff
changeset
|
408 ? must_redraw : save_must_redraw; |
12459
937356f8f8d6
patch 8.0.1109: timer causes error on exit from Ex mode
Christian Brabandt <cb@256bit.org>
parents:
12375
diff
changeset
|
409 set_pressedreturn(save_ex_pressedreturn); |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
410 |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
411 /* Only fire the timer again if it repeats and stop_timer() wasn't |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
412 * called while inside the callback (tr_id == -1). */ |
11639
71d7b5ed08a0
patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents:
11631
diff
changeset
|
413 if (timer->tr_repeat != 0 && timer->tr_id != -1 |
71d7b5ed08a0
patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents:
11631
diff
changeset
|
414 && timer->tr_emsg_count < 3) |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
415 { |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
416 profile_setlimit(timer->tr_interval, &timer->tr_due); |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
417 this_due = proftime_time_left(&timer->tr_due, &now); |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
418 if (this_due < 1) |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
419 this_due = 1; |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
420 if (timer->tr_repeat > 0) |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
421 --timer->tr_repeat; |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
422 } |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
423 else |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
424 { |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
425 this_due = -1; |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
426 remove_timer(timer); |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
427 free_timer(timer); |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
428 } |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
429 } |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
430 if (this_due > 0 && (next_due == -1 || next_due > this_due)) |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
431 next_due = this_due; |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
432 } |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
433 |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
434 if (did_one) |
12244
d0b039e2ed56
patch 8.0.1002: unnecessarily updating screen after timer callback
Christian Brabandt <cb@256bit.org>
parents:
12206
diff
changeset
|
435 redraw_after_callback(need_update_screen); |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
436 |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
437 #ifdef FEAT_BEVAL_TERM |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
438 if (bevalexpr_due_set) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
439 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
440 this_due = proftime_time_left(&bevalexpr_due, &now); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
441 if (this_due <= 1) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
442 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
443 bevalexpr_due_set = FALSE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
444 if (balloonEval == NULL) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
445 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
446 balloonEval = ALLOC_CLEAR_ONE(BalloonEval); |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
447 balloonEvalForTerm = TRUE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
448 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
449 if (balloonEval != NULL) |
16594
6f52e82d9d4e
patch 8.1.1300: in a terminal 'ballooneval' does not work right away
Bram Moolenaar <Bram@vim.org>
parents:
16515
diff
changeset
|
450 { |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
451 general_beval_cb(balloonEval, 0); |
16594
6f52e82d9d4e
patch 8.1.1300: in a terminal 'ballooneval' does not work right away
Bram Moolenaar <Bram@vim.org>
parents:
16515
diff
changeset
|
452 setcursor(); |
6f52e82d9d4e
patch 8.1.1300: in a terminal 'ballooneval' does not work right away
Bram Moolenaar <Bram@vim.org>
parents:
16515
diff
changeset
|
453 out_flush(); |
6f52e82d9d4e
patch 8.1.1300: in a terminal 'ballooneval' does not work right away
Bram Moolenaar <Bram@vim.org>
parents:
16515
diff
changeset
|
454 } |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
455 } |
13762
9de2b25932eb
patch 8.0.1753: various warnings from a static analyser
Christian Brabandt <cb@256bit.org>
parents:
13736
diff
changeset
|
456 else if (next_due == -1 || next_due > this_due) |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
457 next_due = this_due; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
458 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
459 #endif |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
460 #ifdef FEAT_TERMINAL |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
461 /* Some terminal windows may need their buffer updated. */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
462 next_due = term_check_timers(next_due, &now); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
463 #endif |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
464 |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
465 return current_id != last_timer_id ? 1 : next_due; |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
466 } |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
467 |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
468 /* |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
469 * Find a timer by ID. Returns NULL if not found; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
470 */ |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
471 timer_T * |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
472 find_timer(long id) |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
473 { |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
474 timer_T *timer; |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
475 |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
476 if (id >= 0) |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
477 { |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
478 for (timer = first_timer; timer != NULL; timer = timer->tr_next) |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
479 if (timer->tr_id == id) |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
480 return timer; |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
481 } |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
482 return NULL; |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
483 } |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
484 |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
485 |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
486 /* |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
487 * Stop a timer and delete it. |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
488 */ |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
489 void |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
490 stop_timer(timer_T *timer) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
491 { |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
492 if (timer->tr_firing) |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
493 /* Free the timer after the callback returns. */ |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
494 timer->tr_id = -1; |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
495 else |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
496 { |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
497 remove_timer(timer); |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
498 free_timer(timer); |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
499 } |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
500 } |
9153
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
501 |
9790
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
502 void |
9810
6a28d0c6f929
commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents:
9792
diff
changeset
|
503 stop_all_timers(void) |
6a28d0c6f929
commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents:
9792
diff
changeset
|
504 { |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
505 timer_T *timer; |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
506 timer_T *timer_next; |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
507 |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
508 for (timer = first_timer; timer != NULL; timer = timer_next) |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
509 { |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
510 timer_next = timer->tr_next; |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
511 stop_timer(timer); |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
512 } |
9810
6a28d0c6f929
commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents:
9792
diff
changeset
|
513 } |
6a28d0c6f929
commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents:
9792
diff
changeset
|
514 |
6a28d0c6f929
commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents:
9792
diff
changeset
|
515 void |
9790
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
516 add_timer_info(typval_T *rettv, timer_T *timer) |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
517 { |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
518 list_T *list = rettv->vval.v_list; |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
519 dict_T *dict = dict_alloc(); |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
520 dictitem_T *di; |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
521 long remaining; |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
522 proftime_T now; |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
523 |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
524 if (dict == NULL) |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
525 return; |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
526 list_append_dict(list, dict); |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
527 |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14208
diff
changeset
|
528 dict_add_number(dict, "id", timer->tr_id); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14208
diff
changeset
|
529 dict_add_number(dict, "time", (long)timer->tr_interval); |
9790
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
530 |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
531 profile_start(&now); |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12678
diff
changeset
|
532 remaining = proftime_time_left(&timer->tr_due, &now); |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14208
diff
changeset
|
533 dict_add_number(dict, "remaining", (long)remaining); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14208
diff
changeset
|
534 |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14208
diff
changeset
|
535 dict_add_number(dict, "repeat", |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14208
diff
changeset
|
536 (long)(timer->tr_repeat < 0 ? -1 : timer->tr_repeat + 1)); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14208
diff
changeset
|
537 dict_add_number(dict, "paused", (long)(timer->tr_paused)); |
9790
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
538 |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
539 di = dictitem_alloc((char_u *)"callback"); |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
540 if (di != NULL) |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
541 { |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
542 if (dict_add(dict, di) == FAIL) |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
543 vim_free(di); |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
544 else |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
545 put_callback(&timer->tr_callback, &di->di_tv); |
9790
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
546 } |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
547 } |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
548 |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
549 void |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
550 add_timer_info_all(typval_T *rettv) |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
551 { |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
552 timer_T *timer; |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
553 |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
554 for (timer = first_timer; timer != NULL; timer = timer->tr_next) |
10122
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
555 if (timer->tr_id != -1) |
3db463d4df25
commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents:
10078
diff
changeset
|
556 add_timer_info(rettv, timer); |
9790
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
557 } |
34cc6a101340
commit https://github.com/vim/vim/commit/8e97bd74b5377753597e3d98e7123d8985c7fffd
Christian Brabandt <cb@256bit.org>
parents:
9778
diff
changeset
|
558 |
9153
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
559 /* |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
560 * Mark references in partials of timers. |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
561 */ |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
562 int |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
563 set_ref_in_timer(int copyID) |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
564 { |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
565 int abort = FALSE; |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
566 timer_T *timer; |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
567 typval_T tv; |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
568 |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
569 for (timer = first_timer; timer != NULL; timer = timer->tr_next) |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
570 { |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
571 if (timer->tr_callback.cb_partial != NULL) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
572 { |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
573 tv.v_type = VAR_PARTIAL; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
574 tv.vval.v_partial = timer->tr_callback.cb_partial; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
575 } |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
576 else |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
577 { |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
578 tv.v_type = VAR_FUNC; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
579 tv.vval.v_string = timer->tr_callback.cb_name; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
580 } |
9153
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
581 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
582 } |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
583 return abort; |
c2fe86f2bda1
commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents:
9112
diff
changeset
|
584 } |
9709
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
585 |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
586 # if defined(EXITFREE) || defined(PROTO) |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
587 void |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
588 timer_free_all() |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
589 { |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
590 timer_T *timer; |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
591 |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
592 while (first_timer != NULL) |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
593 { |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
594 timer = first_timer; |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
595 remove_timer(timer); |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
596 free_timer(timer); |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
597 } |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
598 } |
cce76af1cc6a
commit https://github.com/vim/vim/commit/623e263ffb998acacd6fd0de18c44e03af2a47d1
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
599 # endif |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
600 # endif |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8526
diff
changeset
|
601 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
602 #if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME) && defined(FEAT_FLOAT) && defined(FEAT_PROFILE) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
603 # if defined(HAVE_MATH_H) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
604 # include <math.h> |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
605 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
606 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
607 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
608 * Divide the time "tm" by "count" and store in "tm2". |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
609 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
610 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
611 profile_divide(proftime_T *tm, int count, proftime_T *tm2) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
612 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
613 if (count == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
614 profile_zero(tm2); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
615 else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
616 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
617 # ifdef MSWIN |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
618 tm2->QuadPart = tm->QuadPart / count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
619 # else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
620 double usec = (tm->tv_sec * 1000000.0 + tm->tv_usec) / count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
621 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
622 tm2->tv_sec = floor(usec / 1000000.0); |
4825
208a6c04e6b8
updated for version 7.3.1159
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
623 tm2->tv_usec = vim_round(usec - (tm2->tv_sec * 1000000.0)); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
624 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
625 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
626 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
627 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
628 |
1496 | 629 # if defined(FEAT_PROFILE) || defined(PROTO) |
630 /* | |
631 * Functions for profiling. | |
632 */ | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
633 static void script_dump_profile(FILE *fd); |
1496 | 634 static proftime_T prof_wait_time; |
635 | |
794 | 636 /* |
170 | 637 * Add the time "tm2" to "tm". |
638 */ | |
639 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
640 profile_add(proftime_T *tm, proftime_T *tm2) |
170 | 641 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
642 # ifdef MSWIN |
177 | 643 tm->QuadPart += tm2->QuadPart; |
644 # else | |
170 | 645 tm->tv_usec += tm2->tv_usec; |
646 tm->tv_sec += tm2->tv_sec; | |
647 if (tm->tv_usec >= 1000000) | |
648 { | |
649 tm->tv_usec -= 1000000; | |
650 ++tm->tv_sec; | |
651 } | |
177 | 652 # endif |
170 | 653 } |
654 | |
655 /* | |
720 | 656 * Add the "self" time from the total time and the children's time. |
657 */ | |
658 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
659 profile_self(proftime_T *self, proftime_T *total, proftime_T *children) |
720 | 660 { |
661 /* Check that the result won't be negative. Can happen with recursive | |
662 * calls. */ | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
663 #ifdef MSWIN |
720 | 664 if (total->QuadPart <= children->QuadPart) |
665 return; | |
666 #else | |
667 if (total->tv_sec < children->tv_sec | |
668 || (total->tv_sec == children->tv_sec | |
669 && total->tv_usec <= children->tv_usec)) | |
670 return; | |
671 #endif | |
672 profile_add(self, total); | |
673 profile_sub(self, children); | |
674 } | |
675 | |
676 /* | |
170 | 677 * Get the current waittime. |
678 */ | |
679 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
680 profile_get_wait(proftime_T *tm) |
170 | 681 { |
682 *tm = prof_wait_time; | |
683 } | |
684 | |
685 /* | |
686 * Subtract the passed waittime since "tm" from "tma". | |
687 */ | |
688 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
689 profile_sub_wait(proftime_T *tm, proftime_T *tma) |
170 | 690 { |
691 proftime_T tm3 = prof_wait_time; | |
692 | |
693 profile_sub(&tm3, tm); | |
694 profile_sub(tma, &tm3); | |
695 } | |
696 | |
697 /* | |
698 * Return TRUE if "tm1" and "tm2" are equal. | |
699 */ | |
700 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
701 profile_equal(proftime_T *tm1, proftime_T *tm2) |
170 | 702 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
703 # ifdef MSWIN |
177 | 704 return (tm1->QuadPart == tm2->QuadPart); |
705 # else | |
170 | 706 return (tm1->tv_usec == tm2->tv_usec && tm1->tv_sec == tm2->tv_sec); |
177 | 707 # endif |
708 } | |
709 | |
710 /* | |
711 * Return <0, 0 or >0 if "tm1" < "tm2", "tm1" == "tm2" or "tm1" > "tm2" | |
712 */ | |
713 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
714 profile_cmp(const proftime_T *tm1, const proftime_T *tm2) |
177 | 715 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
716 # ifdef MSWIN |
177 | 717 return (int)(tm2->QuadPart - tm1->QuadPart); |
718 # else | |
719 if (tm1->tv_sec == tm2->tv_sec) | |
720 return tm2->tv_usec - tm1->tv_usec; | |
721 return tm2->tv_sec - tm1->tv_sec; | |
722 # endif | |
170 | 723 } |
724 | |
725 static char_u *profile_fname = NULL; | |
790 | 726 static proftime_T pause_time; |
170 | 727 |
728 /* | |
729 * ":profile cmd args" | |
730 */ | |
731 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
732 ex_profile(exarg_T *eap) |
170 | 733 { |
734 char_u *e; | |
735 int len; | |
736 | |
737 e = skiptowhite(eap->arg); | |
835 | 738 len = (int)(e - eap->arg); |
170 | 739 e = skipwhite(e); |
740 | |
741 if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL) | |
742 { | |
743 vim_free(profile_fname); | |
6749 | 744 profile_fname = expand_env_save_opt(e, TRUE); |
790 | 745 do_profiling = PROF_YES; |
170 | 746 profile_zero(&prof_wait_time); |
747 set_vim_var_nr(VV_PROFILING, 1L); | |
748 } | |
790 | 749 else if (do_profiling == PROF_NONE) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
750 emsg(_("E750: First use \":profile start {fname}\"")); |
790 | 751 else if (STRCMP(eap->arg, "pause") == 0) |
752 { | |
753 if (do_profiling == PROF_YES) | |
754 profile_start(&pause_time); | |
755 do_profiling = PROF_PAUSED; | |
756 } | |
757 else if (STRCMP(eap->arg, "continue") == 0) | |
758 { | |
759 if (do_profiling == PROF_PAUSED) | |
760 { | |
761 profile_end(&pause_time); | |
762 profile_add(&prof_wait_time, &pause_time); | |
763 } | |
764 do_profiling = PROF_YES; | |
765 } | |
170 | 766 else |
767 { | |
768 /* The rest is similar to ":breakadd". */ | |
769 ex_breakadd(eap); | |
770 } | |
771 } | |
772 | |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
773 /* Command line expansion for :profile. */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
774 static enum |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
775 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
776 PEXP_SUBCMD, /* expand :profile sub-commands */ |
2711 | 777 PEXP_FUNC /* expand :profile func {funcname} */ |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
778 } pexpand_what; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
779 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
780 static char *pexpand_cmds[] = { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
781 "start", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
782 #define PROFCMD_START 0 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
783 "pause", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
784 #define PROFCMD_PAUSE 1 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
785 "continue", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
786 #define PROFCMD_CONTINUE 2 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
787 "func", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
788 #define PROFCMD_FUNC 3 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
789 "file", |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
790 #define PROFCMD_FILE 4 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
791 NULL |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
792 #define PROFCMD_LAST 5 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
793 }; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
794 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
795 /* |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
796 * Function given to ExpandGeneric() to obtain the profile command |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
797 * specific expansion. |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
798 */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
799 char_u * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
800 get_profile_name(expand_T *xp UNUSED, int idx) |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
801 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
802 switch (pexpand_what) |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
803 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
804 case PEXP_SUBCMD: |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
805 return (char_u *)pexpand_cmds[idx]; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
806 /* case PEXP_FUNC: TODO */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
807 default: |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
808 return NULL; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
809 } |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
810 } |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
811 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
812 /* |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
813 * Handle command line completion for :profile command. |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
814 */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
815 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
816 set_context_in_profile_cmd(expand_T *xp, char_u *arg) |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
817 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
818 char_u *end_subcmd; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
819 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
820 /* Default: expand subcommands. */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
821 xp->xp_context = EXPAND_PROFILE; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
822 pexpand_what = PEXP_SUBCMD; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
823 xp->xp_pattern = arg; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
824 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
825 end_subcmd = skiptowhite(arg); |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
826 if (*end_subcmd == NUL) |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
827 return; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
828 |
2100
7d121c69f540
updated for version 7.2.383
Bram Moolenaar <bram@zimbu.org>
parents:
2085
diff
changeset
|
829 if (end_subcmd - arg == 5 && STRNCMP(arg, "start", 5) == 0) |
2068
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
830 { |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
831 xp->xp_context = EXPAND_FILES; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
832 xp->xp_pattern = skipwhite(end_subcmd); |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
833 return; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
834 } |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
835 |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
836 /* TODO: expand function names after "func" */ |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
837 xp->xp_context = EXPAND_NOTHING; |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
838 } |
98a2a6e6b966
updated for version 7.2.353
Bram Moolenaar <bram@zimbu.org>
parents:
2058
diff
changeset
|
839 |
170 | 840 /* |
841 * Dump the profiling info. | |
842 */ | |
843 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
844 profile_dump(void) |
170 | 845 { |
846 FILE *fd; | |
847 | |
848 if (profile_fname != NULL) | |
849 { | |
531 | 850 fd = mch_fopen((char *)profile_fname, "w"); |
170 | 851 if (fd == NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
852 semsg(_(e_notopen), profile_fname); |
170 | 853 else |
854 { | |
177 | 855 script_dump_profile(fd); |
170 | 856 func_dump_profile(fd); |
857 fclose(fd); | |
858 } | |
859 } | |
860 } | |
861 | |
862 /* | |
863 * Start profiling script "fp". | |
864 */ | |
865 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
866 script_do_profile(scriptitem_T *si) |
170 | 867 { |
868 si->sn_pr_count = 0; | |
869 profile_zero(&si->sn_pr_total); | |
870 profile_zero(&si->sn_pr_self); | |
871 | |
872 ga_init2(&si->sn_prl_ga, sizeof(sn_prl_T), 100); | |
873 si->sn_prl_idx = -1; | |
874 si->sn_prof_on = TRUE; | |
875 si->sn_pr_nest = 0; | |
876 } | |
877 | |
878 /* | |
12658
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
879 * Save time when starting to invoke another script or function. |
170 | 880 */ |
881 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
882 script_prof_save( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
883 proftime_T *tm) /* place to store wait time */ |
170 | 884 { |
885 scriptitem_T *si; | |
886 | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
887 if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= script_items.ga_len) |
170 | 888 { |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
889 si = &SCRIPT_ITEM(current_sctx.sc_sid); |
170 | 890 if (si->sn_prof_on && si->sn_pr_nest++ == 0) |
891 profile_start(&si->sn_pr_child); | |
892 } | |
893 profile_get_wait(tm); | |
894 } | |
895 | |
896 /* | |
897 * Count time spent in children after invoking another script or function. | |
898 */ | |
899 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
900 script_prof_restore(proftime_T *tm) |
170 | 901 { |
902 scriptitem_T *si; | |
903 | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
904 if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= script_items.ga_len) |
170 | 905 { |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
906 si = &SCRIPT_ITEM(current_sctx.sc_sid); |
170 | 907 if (si->sn_prof_on && --si->sn_pr_nest == 0) |
908 { | |
909 profile_end(&si->sn_pr_child); | |
910 profile_sub_wait(tm, &si->sn_pr_child); /* don't count wait time */ | |
911 profile_add(&si->sn_pr_children, &si->sn_pr_child); | |
912 profile_add(&si->sn_prl_children, &si->sn_pr_child); | |
913 } | |
914 } | |
915 } | |
916 | |
917 static proftime_T inchar_time; | |
918 | |
919 /* | |
920 * Called when starting to wait for the user to type a character. | |
921 */ | |
922 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
923 prof_inchar_enter(void) |
170 | 924 { |
925 profile_start(&inchar_time); | |
926 } | |
927 | |
928 /* | |
929 * Called when finished waiting for the user to type a character. | |
930 */ | |
931 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
932 prof_inchar_exit(void) |
170 | 933 { |
934 profile_end(&inchar_time); | |
935 profile_add(&prof_wait_time, &inchar_time); | |
936 } | |
937 | |
938 /* | |
939 * Dump the profiling results for all scripts in file "fd". | |
940 */ | |
941 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
942 script_dump_profile(FILE *fd) |
170 | 943 { |
944 int id; | |
945 scriptitem_T *si; | |
946 int i; | |
947 FILE *sfd; | |
948 sn_prl_T *pp; | |
949 | |
950 for (id = 1; id <= script_items.ga_len; ++id) | |
951 { | |
952 si = &SCRIPT_ITEM(id); | |
953 if (si->sn_prof_on) | |
954 { | |
955 fprintf(fd, "SCRIPT %s\n", si->sn_name); | |
956 if (si->sn_pr_count == 1) | |
957 fprintf(fd, "Sourced 1 time\n"); | |
958 else | |
959 fprintf(fd, "Sourced %d times\n", si->sn_pr_count); | |
960 fprintf(fd, "Total time: %s\n", profile_msg(&si->sn_pr_total)); | |
961 fprintf(fd, " Self time: %s\n", profile_msg(&si->sn_pr_self)); | |
962 fprintf(fd, "\n"); | |
963 fprintf(fd, "count total (s) self (s)\n"); | |
964 | |
531 | 965 sfd = mch_fopen((char *)si->sn_name, "r"); |
170 | 966 if (sfd == NULL) |
967 fprintf(fd, "Cannot open file!\n"); | |
968 else | |
969 { | |
12658
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
970 /* Keep going till the end of file, so that trailing |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
971 * continuation lines are listed. */ |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
972 for (i = 0; ; ++i) |
170 | 973 { |
974 if (vim_fgets(IObuff, IOSIZE, sfd)) | |
975 break; | |
12992
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
976 /* When a line has been truncated, append NL, taking care |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
977 * of multi-byte characters . */ |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
978 if (IObuff[IOSIZE - 2] != NUL && IObuff[IOSIZE - 2] != NL) |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
979 { |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
980 int n = IOSIZE - 2; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
981 |
12992
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
982 if (enc_utf8) |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
983 { |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
984 /* Move to the first byte of this char. |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
985 * utf_head_off() doesn't work, because it checks |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
986 * for a truncated character. */ |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
987 while (n > 0 && (IObuff[n] & 0xc0) == 0x80) |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
988 --n; |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
989 } |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
990 else if (has_mbyte) |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
991 n -= mb_head_off(IObuff, IObuff + n); |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
992 IObuff[n] = NL; |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
993 IObuff[n + 1] = NUL; |
5532b5176870
patch 8.0.1372: profile log may be truncated halfway a character
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
994 } |
12658
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
995 if (i < si->sn_prl_ga.ga_len |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
996 && (pp = &PRL_ITEM(si, i))->snp_count > 0) |
170 | 997 { |
998 fprintf(fd, "%5d ", pp->snp_count); | |
999 if (profile_equal(&pp->sn_prl_total, &pp->sn_prl_self)) | |
1000 fprintf(fd, " "); | |
1001 else | |
1002 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_total)); | |
1003 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_self)); | |
1004 } | |
1005 else | |
1006 fprintf(fd, " "); | |
1007 fprintf(fd, "%s", IObuff); | |
1008 } | |
1009 fclose(sfd); | |
1010 } | |
1011 fprintf(fd, "\n"); | |
1012 } | |
1013 } | |
1014 } | |
1015 | |
1016 /* | |
1017 * Return TRUE when a function defined in the current script should be | |
1018 * profiled. | |
1019 */ | |
1020 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1021 prof_def_func(void) |
170 | 1022 { |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
1023 if (current_sctx.sc_sid > 0) |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
1024 return SCRIPT_ITEM(current_sctx.sc_sid).sn_pr_force; |
391 | 1025 return FALSE; |
170 | 1026 } |
1027 | |
1028 # endif | |
7 | 1029 #endif |
1030 | |
1031 /* | |
1032 * If 'autowrite' option set, try to write the file. | |
1033 * Careful: autocommands may make "buf" invalid! | |
1034 * | |
1035 * return FAIL for failure, OK otherwise | |
1036 */ | |
1037 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1038 autowrite(buf_T *buf, int forceit) |
7 | 1039 { |
1069 | 1040 int r; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1041 bufref_T bufref; |
1069 | 1042 |
7 | 1043 if (!(p_aw || p_awa) || !p_write |
1044 #ifdef FEAT_QUICKFIX | |
1069 | 1045 /* never autowrite a "nofile" or "nowrite" buffer */ |
1046 || bt_dontwrite(buf) | |
7 | 1047 #endif |
1069 | 1048 || (!forceit && buf->b_p_ro) || buf->b_ffname == NULL) |
7 | 1049 return FAIL; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1050 set_bufref(&bufref, buf); |
1069 | 1051 r = buf_write_all(buf, forceit); |
1052 | |
1053 /* Writing may succeed but the buffer still changed, e.g., when there is a | |
1054 * conversion error. We do want to return FAIL then. */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1055 if (bufref_valid(&bufref) && bufIsChanged(buf)) |
1069 | 1056 r = FAIL; |
1057 return r; | |
7 | 1058 } |
1059 | |
1060 /* | |
14642
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1061 * Flush all buffers, except the ones that are readonly or are never written. |
7 | 1062 */ |
1063 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1064 autowrite_all(void) |
7 | 1065 { |
1066 buf_T *buf; | |
1067 | |
1068 if (!(p_aw || p_awa) || !p_write) | |
1069 return; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9626
diff
changeset
|
1070 FOR_ALL_BUFFERS(buf) |
14642
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1071 if (bufIsChanged(buf) && !buf->b_p_ro && !bt_dontwrite(buf)) |
7 | 1072 { |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1073 bufref_T bufref; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1074 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1075 set_bufref(&bufref, buf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1076 |
7 | 1077 (void)buf_write_all(buf, FALSE); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1078 |
7 | 1079 /* an autocommand may have deleted the buffer */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1080 if (!bufref_valid(&bufref)) |
7 | 1081 buf = firstbuf; |
1082 } | |
1083 } | |
1084 | |
1085 /* | |
5464 | 1086 * Return TRUE if buffer was changed and cannot be abandoned. |
1087 * For flags use the CCGD_ values. | |
7 | 1088 */ |
1089 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1090 check_changed(buf_T *buf, int flags) |
7 | 1091 { |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1092 int forceit = (flags & CCGD_FORCEIT); |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1093 bufref_T bufref; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1094 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1095 set_bufref(&bufref, buf); |
5464 | 1096 |
7 | 1097 if ( !forceit |
1098 && bufIsChanged(buf) | |
5464 | 1099 && ((flags & CCGD_MULTWIN) || buf->b_nwindows <= 1) |
1100 && (!(flags & CCGD_AW) || autowrite(buf, forceit) == FAIL)) | |
7 | 1101 { |
1102 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
1103 if ((p_confirm || cmdmod.confirm) && p_write) | |
1104 { | |
1105 buf_T *buf2; | |
1106 int count = 0; | |
1107 | |
5464 | 1108 if (flags & CCGD_ALLBUF) |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9626
diff
changeset
|
1109 FOR_ALL_BUFFERS(buf2) |
7 | 1110 if (bufIsChanged(buf2) |
1111 && (buf2->b_ffname != NULL | |
1112 # ifdef FEAT_BROWSE | |
1113 || cmdmod.browse | |
1114 # endif | |
1115 )) | |
1116 ++count; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1117 if (!bufref_valid(&bufref)) |
7 | 1118 /* Autocommand deleted buffer, oops! It's not changed now. */ |
1119 return FALSE; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1120 |
7 | 1121 dialog_changed(buf, count > 1); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1122 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1123 if (!bufref_valid(&bufref)) |
7 | 1124 /* Autocommand deleted buffer, oops! It's not changed now. */ |
1125 return FALSE; | |
1126 return bufIsChanged(buf); | |
1127 } | |
1128 #endif | |
5464 | 1129 if (flags & CCGD_EXCMD) |
12146
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12039
diff
changeset
|
1130 no_write_message(); |
5464 | 1131 else |
13302
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13274
diff
changeset
|
1132 no_write_message_nobang(curbuf); |
7 | 1133 return TRUE; |
1134 } | |
1135 return FALSE; | |
1136 } | |
1137 | |
1138 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) || defined(PROTO) | |
1139 | |
1140 #if defined(FEAT_BROWSE) || defined(PROTO) | |
1141 /* | |
1142 * When wanting to write a file without a file name, ask the user for a name. | |
1143 */ | |
1144 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1145 browse_save_fname(buf_T *buf) |
7 | 1146 { |
1147 if (buf->b_fname == NULL) | |
1148 { | |
1149 char_u *fname; | |
1150 | |
29 | 1151 fname = do_browse(BROWSE_SAVE, (char_u *)_("Save As"), |
1152 NULL, NULL, NULL, NULL, buf); | |
7 | 1153 if (fname != NULL) |
1154 { | |
1155 if (setfname(buf, fname, NULL, TRUE) == OK) | |
1156 buf->b_flags |= BF_NOTEDITED; | |
1157 vim_free(fname); | |
1158 } | |
1159 } | |
1160 } | |
1161 #endif | |
1162 | |
1163 /* | |
2849 | 1164 * Ask the user what to do when abandoning a changed buffer. |
7 | 1165 * Must check 'write' option first! |
1166 */ | |
1167 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1168 dialog_changed( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1169 buf_T *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1170 int checkall) /* may abandon all changed buffers */ |
7 | 1171 { |
2770 | 1172 char_u buff[DIALOG_MSG_SIZE]; |
7 | 1173 int ret; |
1174 buf_T *buf2; | |
3486 | 1175 exarg_T ea; |
7 | 1176 |
12206
bd8d767fb36f
patch 8.0.0983: unnecessary check for NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
1177 dialog_msg(buff, _("Save changes to \"%s\"?"), buf->b_fname); |
7 | 1178 if (checkall) |
1179 ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, buff, 1); | |
1180 else | |
1181 ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1); | |
1182 | |
16619
8f0ea605ec96
patch 8.1.1312: Coverity warning for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
16594
diff
changeset
|
1183 // Init ea pseudo-structure, this is needed for the check_overwrite() |
8f0ea605ec96
patch 8.1.1312: Coverity warning for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
16594
diff
changeset
|
1184 // function. |
8f0ea605ec96
patch 8.1.1312: Coverity warning for using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
16594
diff
changeset
|
1185 vim_memset(&ea, 0, sizeof(ea)); |
3486 | 1186 |
7 | 1187 if (ret == VIM_YES) |
1188 { | |
1189 #ifdef FEAT_BROWSE | |
1190 /* May get file name, when there is none */ | |
1191 browse_save_fname(buf); | |
1192 #endif | |
3486 | 1193 if (buf->b_fname != NULL && check_overwrite(&ea, buf, |
1194 buf->b_fname, buf->b_ffname, FALSE) == OK) | |
1195 /* didn't hit Cancel */ | |
7 | 1196 (void)buf_write_all(buf, FALSE); |
1197 } | |
1198 else if (ret == VIM_NO) | |
1199 { | |
1200 unchanged(buf, TRUE); | |
1201 } | |
1202 else if (ret == VIM_ALL) | |
1203 { | |
1204 /* | |
1205 * Write all modified files that can be written. | |
1206 * Skip readonly buffers, these need to be confirmed | |
1207 * individually. | |
1208 */ | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9626
diff
changeset
|
1209 FOR_ALL_BUFFERS(buf2) |
7 | 1210 { |
1211 if (bufIsChanged(buf2) | |
1212 && (buf2->b_ffname != NULL | |
1213 #ifdef FEAT_BROWSE | |
1214 || cmdmod.browse | |
1215 #endif | |
1216 ) | |
1217 && !buf2->b_p_ro) | |
1218 { | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1219 bufref_T bufref; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1220 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1221 set_bufref(&bufref, buf2); |
7 | 1222 #ifdef FEAT_BROWSE |
1223 /* May get file name, when there is none */ | |
1224 browse_save_fname(buf2); | |
1225 #endif | |
3486 | 1226 if (buf2->b_fname != NULL && check_overwrite(&ea, buf2, |
1227 buf2->b_fname, buf2->b_ffname, FALSE) == OK) | |
1228 /* didn't hit Cancel */ | |
7 | 1229 (void)buf_write_all(buf2, FALSE); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1230 |
7 | 1231 /* an autocommand may have deleted the buffer */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1232 if (!bufref_valid(&bufref)) |
7 | 1233 buf2 = firstbuf; |
1234 } | |
1235 } | |
1236 } | |
1237 else if (ret == VIM_DISCARDALL) | |
1238 { | |
1239 /* | |
1240 * mark all buffers as unchanged | |
1241 */ | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9626
diff
changeset
|
1242 FOR_ALL_BUFFERS(buf2) |
7 | 1243 unchanged(buf2, TRUE); |
1244 } | |
1245 } | |
1246 #endif | |
1247 | |
1248 /* | |
1249 * Return TRUE if the buffer "buf" can be abandoned, either by making it | |
1250 * hidden, autowriting it or unloading it. | |
1251 */ | |
1252 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1253 can_abandon(buf_T *buf, int forceit) |
7 | 1254 { |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11935
diff
changeset
|
1255 return ( buf_hide(buf) |
7 | 1256 || !bufIsChanged(buf) |
1257 || buf->b_nwindows > 1 | |
1258 || autowrite(buf, forceit) == OK | |
1259 || forceit); | |
1260 } | |
1261 | |
3429 | 1262 /* |
1263 * Add a buffer number to "bufnrs", unless it's already there. | |
1264 */ | |
1265 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1266 add_bufnum(int *bufnrs, int *bufnump, int nr) |
3429 | 1267 { |
1268 int i; | |
1269 | |
1270 for (i = 0; i < *bufnump; ++i) | |
1271 if (bufnrs[i] == nr) | |
1272 return; | |
1273 bufnrs[*bufnump] = nr; | |
1274 *bufnump = *bufnump + 1; | |
1275 } | |
1276 | |
7 | 1277 /* |
1278 * Return TRUE if any buffer was changed and cannot be abandoned. | |
1279 * That changed buffer becomes the current buffer. | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1280 * When "unload" is TRUE the current buffer is unloaded instead of making it |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7107
diff
changeset
|
1281 * hidden. This is used for ":q!". |
7 | 1282 */ |
1283 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1284 check_changed_any( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1285 int hidden, /* Only check hidden buffers */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1286 int unload) |
7 | 1287 { |
3429 | 1288 int ret = FALSE; |
7 | 1289 buf_T *buf; |
1290 int save; | |
3429 | 1291 int i; |
1292 int bufnum = 0; | |
1293 int bufcount = 0; | |
1294 int *bufnrs; | |
1295 tabpage_T *tp; | |
7 | 1296 win_T *wp; |
1297 | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1298 /* Make a list of all buffers, with the most important ones first. */ |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9626
diff
changeset
|
1299 FOR_ALL_BUFFERS(buf) |
3429 | 1300 ++bufcount; |
1301 | |
1302 if (bufcount == 0) | |
1303 return FALSE; | |
1304 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1305 bufnrs = ALLOC_MULT(int, bufcount); |
3429 | 1306 if (bufnrs == NULL) |
1307 return FALSE; | |
1308 | |
1309 /* curbuf */ | |
1310 bufnrs[bufnum++] = curbuf->b_fnum; | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1311 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1312 /* buffers in current tab */ |
3429 | 1313 FOR_ALL_WINDOWS(wp) |
1314 if (wp->w_buffer != curbuf) | |
1315 add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum); | |
1316 | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1317 /* buffers in other tabs */ |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9626
diff
changeset
|
1318 FOR_ALL_TABPAGES(tp) |
3429 | 1319 if (tp != curtab) |
1320 for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) | |
1321 add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum); | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1322 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1323 /* any other buffer */ |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9626
diff
changeset
|
1324 FOR_ALL_BUFFERS(buf) |
3429 | 1325 add_bufnum(bufnrs, &bufnum, buf->b_fnum); |
1326 | |
1327 for (i = 0; i < bufnum; ++i) | |
7 | 1328 { |
3429 | 1329 buf = buflist_findnr(bufnrs[i]); |
1330 if (buf == NULL) | |
1331 continue; | |
1332 if ((!hidden || buf->b_nwindows == 0) && bufIsChanged(buf)) | |
7 | 1333 { |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1334 bufref_T bufref; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1335 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1336 set_bufref(&bufref, buf); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1337 #ifdef FEAT_TERMINAL |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1338 if (term_job_running(buf->b_term)) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1339 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1340 if (term_try_stop_job(buf) == FAIL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1341 break; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1342 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1343 else |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1344 #endif |
3429 | 1345 /* Try auto-writing the buffer. If this fails but the buffer no |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
1346 * longer exists it's not changed, that's OK. */ |
5464 | 1347 if (check_changed(buf, (p_awa ? CCGD_AW : 0) |
1348 | CCGD_MULTWIN | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1349 | CCGD_ALLBUF) && bufref_valid(&bufref)) |
3429 | 1350 break; /* didn't save - still changes */ |
7 | 1351 } |
1352 } | |
1353 | |
3429 | 1354 if (i >= bufnum) |
1355 goto theend; | |
1356 | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1357 /* Get here if "buf" cannot be abandoned. */ |
3429 | 1358 ret = TRUE; |
7 | 1359 exiting = FALSE; |
1360 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
1361 /* | |
1362 * When ":confirm" used, don't give an error message. | |
1363 */ | |
1364 if (!(p_confirm || cmdmod.confirm)) | |
1365 #endif | |
1366 { | |
1367 /* There must be a wait_return for this message, do_buffer() | |
1368 * may cause a redraw. But wait_return() is a no-op when vgetc() | |
1369 * is busy (Quit used from window menu), then make sure we don't | |
1370 * cause a scroll up. */ | |
823 | 1371 if (vgetc_busy > 0) |
7 | 1372 { |
1373 msg_row = cmdline_row; | |
1374 msg_col = 0; | |
1375 msg_didout = FALSE; | |
1376 } | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11935
diff
changeset
|
1377 if ( |
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11935
diff
changeset
|
1378 #ifdef FEAT_TERMINAL |
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11935
diff
changeset
|
1379 term_job_running(buf->b_term) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
1380 ? semsg(_("E947: Job still running in buffer \"%s\""), |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11935
diff
changeset
|
1381 buf->b_fname) |
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11935
diff
changeset
|
1382 : |
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11935
diff
changeset
|
1383 #endif |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
1384 semsg(_("E162: No write since last change for buffer \"%s\""), |
3839 | 1385 buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname)) |
7 | 1386 { |
1387 save = no_wait_return; | |
1388 no_wait_return = FALSE; | |
1389 wait_return(FALSE); | |
1390 no_wait_return = save; | |
1391 } | |
1392 } | |
1393 | |
1394 /* Try to find a window that contains the buffer. */ | |
1395 if (buf != curbuf) | |
3429 | 1396 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 1397 if (wp->w_buffer == buf) |
1398 { | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1399 bufref_T bufref; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1400 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1401 set_bufref(&bufref, buf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1402 |
3429 | 1403 goto_tabpage_win(tp, wp); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1404 |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
1405 // Paranoia: did autocmd wipe out the buffer with changes? |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9410
diff
changeset
|
1406 if (!bufref_valid(&bufref)) |
3429 | 1407 goto theend; |
1408 goto buf_found; | |
7 | 1409 } |
3429 | 1410 buf_found: |
7 | 1411 |
1412 /* Open the changed buffer in the current window. */ | |
1413 if (buf != curbuf) | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7107
diff
changeset
|
1414 set_curbuf(buf, unload ? DOBUF_UNLOAD : DOBUF_GOTO); |
7 | 1415 |
3429 | 1416 theend: |
1417 vim_free(bufnrs); | |
1418 return ret; | |
7 | 1419 } |
1420 | |
1421 /* | |
1422 * return FAIL if there is no file name, OK if there is one | |
1423 * give error message for FAIL | |
1424 */ | |
1425 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1426 check_fname(void) |
7 | 1427 { |
1428 if (curbuf->b_ffname == NULL) | |
1429 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
1430 emsg(_(e_noname)); |
7 | 1431 return FAIL; |
1432 } | |
1433 return OK; | |
1434 } | |
1435 | |
1436 /* | |
1437 * flush the contents of a buffer, unless it has no file name | |
1438 * | |
1439 * return FAIL for failure, OK otherwise | |
1440 */ | |
1441 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1442 buf_write_all(buf_T *buf, int forceit) |
7 | 1443 { |
1444 int retval; | |
1445 buf_T *old_curbuf = curbuf; | |
1446 | |
1447 retval = (buf_write(buf, buf->b_ffname, buf->b_fname, | |
1448 (linenr_T)1, buf->b_ml.ml_line_count, NULL, | |
1449 FALSE, forceit, TRUE, FALSE)); | |
1450 if (curbuf != old_curbuf) | |
16 | 1451 { |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1452 msg_source(HL_ATTR(HLF_W)); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1453 msg(_("Warning: Entered other buffer unexpectedly (check autocommands)")); |
16 | 1454 } |
7 | 1455 return retval; |
1456 } | |
1457 | |
1458 /* | |
1459 * Code to handle the argument list. | |
1460 */ | |
1461 | |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
1462 static int do_arglist(char_u *str, int what, int after, int will_edit); |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
1463 static void alist_check_arg_idx(void); |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
1464 static void alist_add_list(int count, char_u **files, int after, int will_edit); |
39 | 1465 #define AL_SET 1 |
1466 #define AL_ADD 2 | |
1467 #define AL_DEL 3 | |
1468 | |
7 | 1469 /* |
39 | 1470 * Isolate one argument, taking backticks. |
1471 * Changes the argument in-place, puts a NUL after it. Backticks remain. | |
7 | 1472 * Return a pointer to the start of the next argument. |
1473 */ | |
39 | 1474 static char_u * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1475 do_one_arg(char_u *str) |
7 | 1476 { |
1477 char_u *p; | |
1478 int inbacktick; | |
1479 | |
1480 inbacktick = FALSE; | |
1481 for (p = str; *str; ++str) | |
1482 { | |
39 | 1483 /* When the backslash is used for escaping the special meaning of a |
1484 * character we need to keep it until wildcard expansion. */ | |
7 | 1485 if (rem_backslash(str)) |
1486 { | |
1487 *p++ = *str++; | |
1488 *p++ = *str; | |
1489 } | |
1490 else | |
1491 { | |
39 | 1492 /* An item ends at a space not in backticks */ |
1493 if (!inbacktick && vim_isspace(*str)) | |
7 | 1494 break; |
39 | 1495 if (*str == '`') |
7 | 1496 inbacktick ^= TRUE; |
39 | 1497 *p++ = *str; |
7 | 1498 } |
1499 } | |
1500 str = skipwhite(str); | |
1501 *p = NUL; | |
1502 | |
1503 return str; | |
1504 } | |
1505 | |
41 | 1506 /* |
1507 * Separate the arguments in "str" and return a list of pointers in the | |
1508 * growarray "gap". | |
1509 */ | |
11935
976b480ced9a
patch 8.0.0847: :argadd without argument can't handle space in file name
Christian Brabandt <cb@256bit.org>
parents:
11676
diff
changeset
|
1510 static int |
976b480ced9a
patch 8.0.0847: :argadd without argument can't handle space in file name
Christian Brabandt <cb@256bit.org>
parents:
11676
diff
changeset
|
1511 get_arglist(garray_T *gap, char_u *str, int escaped) |
41 | 1512 { |
1513 ga_init2(gap, (int)sizeof(char_u *), 20); | |
1514 while (*str != NUL) | |
1515 { | |
1516 if (ga_grow(gap, 1) == FAIL) | |
1517 { | |
1518 ga_clear(gap); | |
1519 return FAIL; | |
1520 } | |
1521 ((char_u **)gap->ga_data)[gap->ga_len++] = str; | |
1522 | |
11935
976b480ced9a
patch 8.0.0847: :argadd without argument can't handle space in file name
Christian Brabandt <cb@256bit.org>
parents:
11676
diff
changeset
|
1523 /* If str is escaped, don't handle backslashes or spaces */ |
976b480ced9a
patch 8.0.0847: :argadd without argument can't handle space in file name
Christian Brabandt <cb@256bit.org>
parents:
11676
diff
changeset
|
1524 if (!escaped) |
976b480ced9a
patch 8.0.0847: :argadd without argument can't handle space in file name
Christian Brabandt <cb@256bit.org>
parents:
11676
diff
changeset
|
1525 return OK; |
976b480ced9a
patch 8.0.0847: :argadd without argument can't handle space in file name
Christian Brabandt <cb@256bit.org>
parents:
11676
diff
changeset
|
1526 |
41 | 1527 /* Isolate one argument, change it in-place, put a NUL after it. */ |
1528 str = do_one_arg(str); | |
1529 } | |
1530 return OK; | |
1531 } | |
1532 | |
642 | 1533 #if defined(FEAT_QUICKFIX) || defined(FEAT_SYN_HL) || defined(PROTO) |
237 | 1534 /* |
1535 * Parse a list of arguments (file names), expand them and return in | |
3620 | 1536 * "fnames[fcountp]". When "wig" is TRUE, removes files matching 'wildignore'. |
237 | 1537 * Return FAIL or OK. |
1538 */ | |
1539 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1540 get_arglist_exp( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1541 char_u *str, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1542 int *fcountp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1543 char_u ***fnamesp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1544 int wig) |
237 | 1545 { |
1546 garray_T ga; | |
1547 int i; | |
1548 | |
11935
976b480ced9a
patch 8.0.0847: :argadd without argument can't handle space in file name
Christian Brabandt <cb@256bit.org>
parents:
11676
diff
changeset
|
1549 if (get_arglist(&ga, str, TRUE) == FAIL) |
237 | 1550 return FAIL; |
3620 | 1551 if (wig == TRUE) |
1552 i = expand_wildcards(ga.ga_len, (char_u **)ga.ga_data, | |
1553 fcountp, fnamesp, EW_FILE|EW_NOTFOUND); | |
1554 else | |
1555 i = gen_expand_wildcards(ga.ga_len, (char_u **)ga.ga_data, | |
1556 fcountp, fnamesp, EW_FILE|EW_NOTFOUND); | |
1557 | |
237 | 1558 ga_clear(&ga); |
1559 return i; | |
1560 } | |
1561 #endif | |
1562 | |
7 | 1563 /* |
1564 * Redefine the argument list. | |
1565 */ | |
1566 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1567 set_arglist(char_u *str) |
7 | 1568 { |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
1569 do_arglist(str, AL_SET, 0, FALSE); |
7 | 1570 } |
1571 | |
1572 /* | |
1573 * "what" == AL_SET: Redefine the argument list to 'str'. | |
1574 * "what" == AL_ADD: add files in 'str' to the argument list after "after". | |
1575 * "what" == AL_DEL: remove files in 'str' from the argument list. | |
1576 * | |
1577 * Return FAIL for failure, OK otherwise. | |
1578 */ | |
1579 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1580 do_arglist( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1581 char_u *str, |
8368
db2a07b710ed
commit https://github.com/vim/vim/commit/f1d2501ebe33e148886c2914acd33140e20ee222
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1582 int what, |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
1583 int after UNUSED, // 0 means before first one |
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
1584 int will_edit) // will edit added argument |
7 | 1585 { |
1586 garray_T new_ga; | |
1587 int exp_count; | |
1588 char_u **exp_files; | |
1589 int i; | |
1590 char_u *p; | |
1591 int match; | |
11935
976b480ced9a
patch 8.0.0847: :argadd without argument can't handle space in file name
Christian Brabandt <cb@256bit.org>
parents:
11676
diff
changeset
|
1592 int arg_escaped = TRUE; |
7 | 1593 |
1594 /* | |
7726
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
1595 * Set default argument for ":argadd" command. |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
1596 */ |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
1597 if (what == AL_ADD && *str == NUL) |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
1598 { |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
1599 if (curbuf->b_ffname == NULL) |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
1600 return FAIL; |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
1601 str = curbuf->b_fname; |
11935
976b480ced9a
patch 8.0.0847: :argadd without argument can't handle space in file name
Christian Brabandt <cb@256bit.org>
parents:
11676
diff
changeset
|
1602 arg_escaped = FALSE; |
7726
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
1603 } |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
1604 |
f6311c321411
commit https://github.com/vim/vim/commit/2faa29f896252073b53f387406109e331fbbe5f8
Christian Brabandt <cb@256bit.org>
parents:
7647
diff
changeset
|
1605 /* |
7 | 1606 * Collect all file name arguments in "new_ga". |
1607 */ | |
11935
976b480ced9a
patch 8.0.0847: :argadd without argument can't handle space in file name
Christian Brabandt <cb@256bit.org>
parents:
11676
diff
changeset
|
1608 if (get_arglist(&new_ga, str, arg_escaped) == FAIL) |
41 | 1609 return FAIL; |
7 | 1610 |
1611 if (what == AL_DEL) | |
1612 { | |
1613 regmatch_T regmatch; | |
1614 int didone; | |
1615 | |
1616 /* | |
1617 * Delete the items: use each item as a regexp and find a match in the | |
1618 * argument list. | |
1619 */ | |
4242 | 1620 regmatch.rm_ic = p_fic; /* ignore case when 'fileignorecase' is set */ |
7 | 1621 for (i = 0; i < new_ga.ga_len && !got_int; ++i) |
1622 { | |
1623 p = ((char_u **)new_ga.ga_data)[i]; | |
1624 p = file_pat_to_reg_pat(p, NULL, NULL, FALSE); | |
1625 if (p == NULL) | |
1626 break; | |
1627 regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); | |
1628 if (regmatch.regprog == NULL) | |
1629 { | |
1630 vim_free(p); | |
1631 break; | |
1632 } | |
1633 | |
1634 didone = FALSE; | |
1635 for (match = 0; match < ARGCOUNT; ++match) | |
1636 if (vim_regexec(®match, alist_name(&ARGLIST[match]), | |
1637 (colnr_T)0)) | |
1638 { | |
1639 didone = TRUE; | |
1640 vim_free(ARGLIST[match].ae_fname); | |
1641 mch_memmove(ARGLIST + match, ARGLIST + match + 1, | |
1642 (ARGCOUNT - match - 1) * sizeof(aentry_T)); | |
1643 --ALIST(curwin)->al_ga.ga_len; | |
1644 if (curwin->w_arg_idx > match) | |
1645 --curwin->w_arg_idx; | |
1646 --match; | |
1647 } | |
1648 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
1649 vim_regfree(regmatch.regprog); |
7 | 1650 vim_free(p); |
1651 if (!didone) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
1652 semsg(_(e_nomatch2), ((char_u **)new_ga.ga_data)[i]); |
7 | 1653 } |
1654 ga_clear(&new_ga); | |
1655 } | |
1656 else | |
1657 { | |
1658 i = expand_wildcards(new_ga.ga_len, (char_u **)new_ga.ga_data, | |
1659 &exp_count, &exp_files, EW_DIR|EW_FILE|EW_ADDSLASH|EW_NOTFOUND); | |
1660 ga_clear(&new_ga); | |
7625
b4384c581806
commit https://github.com/vim/vim/commit/2db5c3b3ceeaded7fb5a64dc5cb22b0cb95b78a1
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
1661 if (i == FAIL || exp_count == 0) |
7 | 1662 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
1663 emsg(_(e_nomatch)); |
7 | 1664 return FAIL; |
1665 } | |
1666 | |
1667 if (what == AL_ADD) | |
1668 { | |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
1669 alist_add_list(exp_count, exp_files, after, will_edit); |
7 | 1670 vim_free(exp_files); |
1671 } | |
1672 else /* what == AL_SET */ | |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
1673 alist_set(ALIST(curwin), exp_count, exp_files, will_edit, NULL, 0); |
7 | 1674 } |
1675 | |
1676 alist_check_arg_idx(); | |
1677 | |
1678 return OK; | |
1679 } | |
1680 | |
1681 /* | |
1682 * Check the validity of the arg_idx for each other window. | |
1683 */ | |
1684 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1685 alist_check_arg_idx(void) |
7 | 1686 { |
1687 win_T *win; | |
671 | 1688 tabpage_T *tp; |
1689 | |
1690 FOR_ALL_TAB_WINDOWS(tp, win) | |
7 | 1691 if (win->w_alist == curwin->w_alist) |
1692 check_arg_idx(win); | |
1693 } | |
1694 | |
1695 /* | |
3312 | 1696 * Return TRUE if window "win" is editing the file at the current argument |
22 | 1697 * index. |
1698 */ | |
1699 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1700 editing_arg_idx(win_T *win) |
22 | 1701 { |
1702 return !(win->w_arg_idx >= WARGCOUNT(win) | |
1703 || (win->w_buffer->b_fnum | |
1704 != WARGLIST(win)[win->w_arg_idx].ae_fnum | |
1705 && (win->w_buffer->b_ffname == NULL | |
1706 || !(fullpathcmp( | |
1707 alist_name(&WARGLIST(win)[win->w_arg_idx]), | |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16722
diff
changeset
|
1708 win->w_buffer->b_ffname, TRUE, TRUE) & FPC_SAME)))); |
22 | 1709 } |
1710 | |
1711 /* | |
7 | 1712 * Check if window "win" is editing the w_arg_idx file in its argument list. |
1713 */ | |
1714 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1715 check_arg_idx(win_T *win) |
7 | 1716 { |
22 | 1717 if (WARGCOUNT(win) > 1 && !editing_arg_idx(win)) |
7 | 1718 { |
1719 /* We are not editing the current entry in the argument list. | |
1720 * Set "arg_had_last" if we are editing the last one. */ | |
1721 win->w_arg_idx_invalid = TRUE; | |
1722 if (win->w_arg_idx != WARGCOUNT(win) - 1 | |
1723 && arg_had_last == FALSE | |
1724 && ALIST(win) == &global_alist | |
1725 && GARGCOUNT > 0 | |
1726 && win->w_arg_idx < GARGCOUNT | |
1727 && (win->w_buffer->b_fnum == GARGLIST[GARGCOUNT - 1].ae_fnum | |
1728 || (win->w_buffer->b_ffname != NULL | |
1729 && (fullpathcmp(alist_name(&GARGLIST[GARGCOUNT - 1]), | |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16722
diff
changeset
|
1730 win->w_buffer->b_ffname, TRUE, TRUE) & FPC_SAME)))) |
7 | 1731 arg_had_last = TRUE; |
1732 } | |
1733 else | |
1734 { | |
1735 /* We are editing the current entry in the argument list. | |
1736 * Set "arg_had_last" if it's also the last one */ | |
1737 win->w_arg_idx_invalid = FALSE; | |
1738 if (win->w_arg_idx == WARGCOUNT(win) - 1 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12459
diff
changeset
|
1739 && win->w_alist == &global_alist) |
7 | 1740 arg_had_last = TRUE; |
1741 } | |
1742 } | |
1743 | |
1744 /* | |
1745 * ":args", ":argslocal" and ":argsglobal". | |
1746 */ | |
1747 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1748 ex_args(exarg_T *eap) |
7 | 1749 { |
1750 int i; | |
1751 | |
1752 if (eap->cmdidx != CMD_args) | |
1753 { | |
1754 alist_unlink(ALIST(curwin)); | |
1755 if (eap->cmdidx == CMD_argglobal) | |
1756 ALIST(curwin) = &global_alist; | |
1757 else /* eap->cmdidx == CMD_arglocal */ | |
1758 alist_new(); | |
1759 } | |
1760 | |
15286
d2a162896a2a
patch 8.1.0651: :args "foo works like :args without argument
Bram Moolenaar <Bram@vim.org>
parents:
15085
diff
changeset
|
1761 if (*eap->arg != NUL) |
7 | 1762 { |
1763 /* | |
1764 * ":args file ..": define new argument list, handle like ":next" | |
1765 * Also for ":argslocal file .." and ":argsglobal file ..". | |
1766 */ | |
1767 ex_next(eap); | |
1768 } | |
13553
04019fc3de93
patch 8.0.1650: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
1769 else if (eap->cmdidx == CMD_args) |
7 | 1770 { |
1771 /* | |
1772 * ":args": list arguments. | |
1773 */ | |
1774 if (ARGCOUNT > 0) | |
1775 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1776 char_u **items = ALLOC_MULT(char_u *, ARGCOUNT); |
13732
8ca1da2a043b
patch 8.0.1738: ":args" output is hard to read
Christian Brabandt <cb@256bit.org>
parents:
13724
diff
changeset
|
1777 |
8ca1da2a043b
patch 8.0.1738: ":args" output is hard to read
Christian Brabandt <cb@256bit.org>
parents:
13724
diff
changeset
|
1778 if (items != NULL) |
7 | 1779 { |
13732
8ca1da2a043b
patch 8.0.1738: ":args" output is hard to read
Christian Brabandt <cb@256bit.org>
parents:
13724
diff
changeset
|
1780 /* Overwrite the command, for a short list there is no |
8ca1da2a043b
patch 8.0.1738: ":args" output is hard to read
Christian Brabandt <cb@256bit.org>
parents:
13724
diff
changeset
|
1781 * scrolling required and no wait_return(). */ |
8ca1da2a043b
patch 8.0.1738: ":args" output is hard to read
Christian Brabandt <cb@256bit.org>
parents:
13724
diff
changeset
|
1782 gotocmdline(TRUE); |
8ca1da2a043b
patch 8.0.1738: ":args" output is hard to read
Christian Brabandt <cb@256bit.org>
parents:
13724
diff
changeset
|
1783 |
8ca1da2a043b
patch 8.0.1738: ":args" output is hard to read
Christian Brabandt <cb@256bit.org>
parents:
13724
diff
changeset
|
1784 for (i = 0; i < ARGCOUNT; ++i) |
13736
f340b53422c2
patch 8.0.1740: warning for signed-unsigned incompatibility
Christian Brabandt <cb@256bit.org>
parents:
13732
diff
changeset
|
1785 items[i] = alist_name(&ARGLIST[i]); |
13732
8ca1da2a043b
patch 8.0.1738: ":args" output is hard to read
Christian Brabandt <cb@256bit.org>
parents:
13724
diff
changeset
|
1786 list_in_columns(items, ARGCOUNT, curwin->w_arg_idx); |
8ca1da2a043b
patch 8.0.1738: ":args" output is hard to read
Christian Brabandt <cb@256bit.org>
parents:
13724
diff
changeset
|
1787 vim_free(items); |
7 | 1788 } |
1789 } | |
1790 } | |
1791 else if (eap->cmdidx == CMD_arglocal) | |
1792 { | |
1793 garray_T *gap = &curwin->w_alist->al_ga; | |
1794 | |
1795 /* | |
1796 * ":argslocal": make a local copy of the global argument list. | |
1797 */ | |
1798 if (ga_grow(gap, GARGCOUNT) == OK) | |
1799 for (i = 0; i < GARGCOUNT; ++i) | |
1800 if (GARGLIST[i].ae_fname != NULL) | |
1801 { | |
1802 AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname = | |
1803 vim_strsave(GARGLIST[i].ae_fname); | |
1804 AARGLIST(curwin->w_alist)[gap->ga_len].ae_fnum = | |
1805 GARGLIST[i].ae_fnum; | |
1806 ++gap->ga_len; | |
1807 } | |
1808 } | |
1809 } | |
1810 | |
1811 /* | |
1812 * ":previous", ":sprevious", ":Next" and ":sNext". | |
1813 */ | |
1814 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1815 ex_previous(exarg_T *eap) |
7 | 1816 { |
1817 /* If past the last one already, go to the last one. */ | |
1818 if (curwin->w_arg_idx - (int)eap->line2 >= ARGCOUNT) | |
1819 do_argfile(eap, ARGCOUNT - 1); | |
1820 else | |
1821 do_argfile(eap, curwin->w_arg_idx - (int)eap->line2); | |
1822 } | |
1823 | |
1824 /* | |
1825 * ":rewind", ":first", ":sfirst" and ":srewind". | |
1826 */ | |
1827 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1828 ex_rewind(exarg_T *eap) |
7 | 1829 { |
1830 do_argfile(eap, 0); | |
1831 } | |
1832 | |
1833 /* | |
1834 * ":last" and ":slast". | |
1835 */ | |
1836 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1837 ex_last(exarg_T *eap) |
7 | 1838 { |
1839 do_argfile(eap, ARGCOUNT - 1); | |
1840 } | |
1841 | |
1842 /* | |
1843 * ":argument" and ":sargument". | |
1844 */ | |
1845 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1846 ex_argument(exarg_T *eap) |
7 | 1847 { |
1848 int i; | |
1849 | |
1850 if (eap->addr_count > 0) | |
1851 i = eap->line2 - 1; | |
1852 else | |
1853 i = curwin->w_arg_idx; | |
1854 do_argfile(eap, i); | |
1855 } | |
1856 | |
1857 /* | |
1858 * Edit file "argn" of the argument lists. | |
1859 */ | |
1860 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1861 do_argfile(exarg_T *eap, int argn) |
7 | 1862 { |
1863 int other; | |
1864 char_u *p; | |
271 | 1865 int old_arg_idx = curwin->w_arg_idx; |
7 | 1866 |
1867 if (argn < 0 || argn >= ARGCOUNT) | |
1868 { | |
1869 if (ARGCOUNT <= 1) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
1870 emsg(_("E163: There is only one file to edit")); |
7 | 1871 else if (argn < 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
1872 emsg(_("E164: Cannot go before first file")); |
7 | 1873 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
1874 emsg(_("E165: Cannot go beyond last file")); |
7 | 1875 } |
1876 else | |
1877 { | |
1878 setpcmark(); | |
1879 #ifdef FEAT_GUI | |
1880 need_mouse_correct = TRUE; | |
1881 #endif | |
1882 | |
683 | 1883 /* split window or create new tab page first */ |
1884 if (*eap->cmd == 's' || cmdmod.tab != 0) | |
7 | 1885 { |
1886 if (win_split(0, 0) == FAIL) | |
1887 return; | |
2583 | 1888 RESET_BINDING(curwin); |
7 | 1889 } |
1890 else | |
1891 { | |
1892 /* | |
1893 * if 'hidden' set, only check for changed file when re-editing | |
1894 * the same buffer | |
1895 */ | |
1896 other = TRUE; | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11935
diff
changeset
|
1897 if (buf_hide(curbuf)) |
7 | 1898 { |
1899 p = fix_fname(alist_name(&ARGLIST[argn])); | |
1900 other = otherfile(p); | |
1901 vim_free(p); | |
1902 } | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11935
diff
changeset
|
1903 if ((!buf_hide(curbuf) || !other) |
5464 | 1904 && check_changed(curbuf, CCGD_AW |
1905 | (other ? 0 : CCGD_MULTWIN) | |
1906 | (eap->forceit ? CCGD_FORCEIT : 0) | |
1907 | CCGD_EXCMD)) | |
7 | 1908 return; |
1909 } | |
1910 | |
1911 curwin->w_arg_idx = argn; | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12459
diff
changeset
|
1912 if (argn == ARGCOUNT - 1 && curwin->w_alist == &global_alist) |
7 | 1913 arg_had_last = TRUE; |
1914 | |
271 | 1915 /* Edit the file; always use the last known line number. |
1916 * When it fails (e.g. Abort for already edited file) restore the | |
1917 * argument index. */ | |
1918 if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL, | |
7 | 1919 eap, ECMD_LAST, |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11935
diff
changeset
|
1920 (buf_hide(curwin->w_buffer) ? ECMD_HIDE : 0) |
1743 | 1921 + (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL) |
271 | 1922 curwin->w_arg_idx = old_arg_idx; |
7 | 1923 /* like Vi: set the mark where the cursor is in the file. */ |
271 | 1924 else if (eap->cmdidx != CMD_argdo) |
7 | 1925 setmark('\''); |
1926 } | |
1927 } | |
1928 | |
1929 /* | |
1930 * ":next", and commands that behave like it. | |
1931 */ | |
1932 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1933 ex_next(exarg_T *eap) |
7 | 1934 { |
1935 int i; | |
1936 | |
1937 /* | |
1938 * check for changed buffer now, if this fails the argument list is not | |
1939 * redefined. | |
1940 */ | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11935
diff
changeset
|
1941 if ( buf_hide(curbuf) |
7 | 1942 || eap->cmdidx == CMD_snext |
5464 | 1943 || !check_changed(curbuf, CCGD_AW |
1944 | (eap->forceit ? CCGD_FORCEIT : 0) | |
1945 | CCGD_EXCMD)) | |
7 | 1946 { |
1947 if (*eap->arg != NUL) /* redefine file list */ | |
1948 { | |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
1949 if (do_arglist(eap->arg, AL_SET, 0, TRUE) == FAIL) |
7 | 1950 return; |
1951 i = 0; | |
1952 } | |
1953 else | |
1954 i = curwin->w_arg_idx + (int)eap->line2; | |
1955 do_argfile(eap, i); | |
1956 } | |
1957 } | |
1958 | |
1959 /* | |
1960 * ":argedit" | |
1961 */ | |
1962 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1963 ex_argedit(exarg_T *eap) |
7 | 1964 { |
11676
f87c43fca41d
patch 8.0.0721: :argedit can only have one argument
Christian Brabandt <cb@256bit.org>
parents:
11645
diff
changeset
|
1965 int i = eap->addr_count ? (int)eap->line2 : curwin->w_arg_idx + 1; |
13782
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1966 // Whether curbuf will be reused, curbuf->b_ffname will be set. |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1967 int curbuf_is_reusable = curbuf_reusable(); |
11676
f87c43fca41d
patch 8.0.0721: :argedit can only have one argument
Christian Brabandt <cb@256bit.org>
parents:
11645
diff
changeset
|
1968 |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
1969 if (do_arglist(eap->arg, AL_ADD, i, TRUE) == FAIL) |
11676
f87c43fca41d
patch 8.0.0721: :argedit can only have one argument
Christian Brabandt <cb@256bit.org>
parents:
11645
diff
changeset
|
1970 return; |
f87c43fca41d
patch 8.0.0721: :argedit can only have one argument
Christian Brabandt <cb@256bit.org>
parents:
11645
diff
changeset
|
1971 #ifdef FEAT_TITLE |
f87c43fca41d
patch 8.0.0721: :argedit can only have one argument
Christian Brabandt <cb@256bit.org>
parents:
11645
diff
changeset
|
1972 maketitle(); |
f87c43fca41d
patch 8.0.0721: :argedit can only have one argument
Christian Brabandt <cb@256bit.org>
parents:
11645
diff
changeset
|
1973 #endif |
f87c43fca41d
patch 8.0.0721: :argedit can only have one argument
Christian Brabandt <cb@256bit.org>
parents:
11645
diff
changeset
|
1974 |
13782
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1975 if (curwin->w_arg_idx == 0 |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1976 && (curbuf->b_ml.ml_flags & ML_EMPTY) |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1977 && (curbuf->b_ffname == NULL || curbuf_is_reusable)) |
11676
f87c43fca41d
patch 8.0.0721: :argedit can only have one argument
Christian Brabandt <cb@256bit.org>
parents:
11645
diff
changeset
|
1978 i = 0; |
7 | 1979 /* Edit the argument. */ |
11676
f87c43fca41d
patch 8.0.0721: :argedit can only have one argument
Christian Brabandt <cb@256bit.org>
parents:
11645
diff
changeset
|
1980 if (i < ARGCOUNT) |
f87c43fca41d
patch 8.0.0721: :argedit can only have one argument
Christian Brabandt <cb@256bit.org>
parents:
11645
diff
changeset
|
1981 do_argfile(eap, i); |
7 | 1982 } |
1983 | |
1984 /* | |
1985 * ":argadd" | |
1986 */ | |
1987 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1988 ex_argadd(exarg_T *eap) |
7 | 1989 { |
1990 do_arglist(eap->arg, AL_ADD, | |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
1991 eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1, |
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
1992 FALSE); |
7 | 1993 #ifdef FEAT_TITLE |
1994 maketitle(); | |
1995 #endif | |
1996 } | |
1997 | |
1998 /* | |
1999 * ":argdelete" | |
2000 */ | |
2001 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2002 ex_argdelete(exarg_T *eap) |
7 | 2003 { |
2004 int i; | |
2005 int n; | |
2006 | |
2007 if (eap->addr_count > 0) | |
2008 { | |
2009 /* ":1,4argdel": Delete all arguments in the range. */ | |
2010 if (eap->line2 > ARGCOUNT) | |
2011 eap->line2 = ARGCOUNT; | |
2012 n = eap->line2 - eap->line1 + 1; | |
11103
3335c3c75611
patch 8.0.0439: ":%argdel" gives an error for an empty arglist
Christian Brabandt <cb@256bit.org>
parents:
10837
diff
changeset
|
2013 if (*eap->arg != NUL) |
3335c3c75611
patch 8.0.0439: ":%argdel" gives an error for an empty arglist
Christian Brabandt <cb@256bit.org>
parents:
10837
diff
changeset
|
2014 /* Can't have both a range and an argument. */ |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
2015 emsg(_(e_invarg)); |
11103
3335c3c75611
patch 8.0.0439: ":%argdel" gives an error for an empty arglist
Christian Brabandt <cb@256bit.org>
parents:
10837
diff
changeset
|
2016 else if (n <= 0) |
3335c3c75611
patch 8.0.0439: ":%argdel" gives an error for an empty arglist
Christian Brabandt <cb@256bit.org>
parents:
10837
diff
changeset
|
2017 { |
3335c3c75611
patch 8.0.0439: ":%argdel" gives an error for an empty arglist
Christian Brabandt <cb@256bit.org>
parents:
10837
diff
changeset
|
2018 /* Don't give an error for ":%argdel" if the list is empty. */ |
3335c3c75611
patch 8.0.0439: ":%argdel" gives an error for an empty arglist
Christian Brabandt <cb@256bit.org>
parents:
10837
diff
changeset
|
2019 if (eap->line1 != 1 || eap->line2 != 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
2020 emsg(_(e_invrange)); |
11103
3335c3c75611
patch 8.0.0439: ":%argdel" gives an error for an empty arglist
Christian Brabandt <cb@256bit.org>
parents:
10837
diff
changeset
|
2021 } |
7 | 2022 else |
2023 { | |
2024 for (i = eap->line1; i <= eap->line2; ++i) | |
2025 vim_free(ARGLIST[i - 1].ae_fname); | |
2026 mch_memmove(ARGLIST + eap->line1 - 1, ARGLIST + eap->line2, | |
2027 (size_t)((ARGCOUNT - eap->line2) * sizeof(aentry_T))); | |
2028 ALIST(curwin)->al_ga.ga_len -= n; | |
2029 if (curwin->w_arg_idx >= eap->line2) | |
2030 curwin->w_arg_idx -= n; | |
2031 else if (curwin->w_arg_idx > eap->line1) | |
2032 curwin->w_arg_idx = eap->line1; | |
7639
0ecb62a66a7a
commit https://github.com/vim/vim/commit/72defda84eb26be9e2ade56c7877b912f818026e
Christian Brabandt <cb@256bit.org>
parents:
7625
diff
changeset
|
2033 if (ARGCOUNT == 0) |
0ecb62a66a7a
commit https://github.com/vim/vim/commit/72defda84eb26be9e2ade56c7877b912f818026e
Christian Brabandt <cb@256bit.org>
parents:
7625
diff
changeset
|
2034 curwin->w_arg_idx = 0; |
0ecb62a66a7a
commit https://github.com/vim/vim/commit/72defda84eb26be9e2ade56c7877b912f818026e
Christian Brabandt <cb@256bit.org>
parents:
7625
diff
changeset
|
2035 else if (curwin->w_arg_idx >= ARGCOUNT) |
0ecb62a66a7a
commit https://github.com/vim/vim/commit/72defda84eb26be9e2ade56c7877b912f818026e
Christian Brabandt <cb@256bit.org>
parents:
7625
diff
changeset
|
2036 curwin->w_arg_idx = ARGCOUNT - 1; |
7 | 2037 } |
2038 } | |
2039 else if (*eap->arg == NUL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
2040 emsg(_(e_argreq)); |
7 | 2041 else |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
2042 do_arglist(eap->arg, AL_DEL, 0, FALSE); |
7 | 2043 #ifdef FEAT_TITLE |
2044 maketitle(); | |
2045 #endif | |
2046 } | |
2047 | |
2048 /* | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2049 * ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo" |
7 | 2050 */ |
2051 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2052 ex_listdo(exarg_T *eap) |
7 | 2053 { |
2054 int i; | |
685 | 2055 win_T *wp; |
2056 tabpage_T *tp; | |
6641 | 2057 buf_T *buf = curbuf; |
7 | 2058 int next_fnum = 0; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2059 #if defined(FEAT_SYN_HL) |
7 | 2060 char_u *save_ei = NULL; |
2061 #endif | |
39 | 2062 char_u *p_shm_save; |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2063 #ifdef FEAT_QUICKFIX |
7107
84efaf06f195
commit https://github.com/vim/vim/commit/ed84b76021df763619cabaedddc44eb5ee849136
Christian Brabandt <cb@256bit.org>
parents:
7092
diff
changeset
|
2064 int qf_size = 0; |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2065 int qf_idx; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2066 #endif |
7 | 2067 |
8220
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2068 #ifndef FEAT_QUICKFIX |
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2069 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo || |
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2070 eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) |
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2071 { |
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2072 ex_ni(eap); |
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2073 return; |
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2074 } |
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2075 #endif |
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2076 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2077 #if defined(FEAT_SYN_HL) |
819 | 2078 if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo) |
123 | 2079 /* Don't do syntax HL autocommands. Skipping the syntax file is a |
2080 * great speed improvement. */ | |
2081 save_ei = au_event_disable(",Syntax"); | |
7 | 2082 #endif |
6116 | 2083 #ifdef FEAT_CLIPBOARD |
2084 start_global_changes(); | |
2085 #endif | |
7 | 2086 |
2087 if (eap->cmdidx == CMD_windo | |
685 | 2088 || eap->cmdidx == CMD_tabdo |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11935
diff
changeset
|
2089 || buf_hide(curbuf) |
5464 | 2090 || !check_changed(curbuf, CCGD_AW |
2091 | (eap->forceit ? CCGD_FORCEIT : 0) | |
2092 | CCGD_EXCMD)) | |
7 | 2093 { |
2094 i = 0; | |
6474 | 2095 /* start at the eap->line1 argument/window/buffer */ |
685 | 2096 wp = firstwin; |
2097 tp = first_tabpage; | |
6474 | 2098 switch (eap->cmdidx) |
2099 { | |
2100 case CMD_windo: | |
2101 for ( ; wp != NULL && i + 1 < eap->line1; wp = wp->w_next) | |
2102 i++; | |
2103 break; | |
2104 case CMD_tabdo: | |
2105 for( ; tp != NULL && i + 1 < eap->line1; tp = tp->tp_next) | |
2106 i++; | |
2107 break; | |
2108 case CMD_argdo: | |
2109 i = eap->line1 - 1; | |
2110 break; | |
2111 default: | |
2112 break; | |
2113 } | |
7 | 2114 /* set pcmark now */ |
2115 if (eap->cmdidx == CMD_bufdo) | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2116 { |
6641 | 2117 /* Advance to the first listed buffer after "eap->line1". */ |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2118 for (buf = firstbuf; buf != NULL && (buf->b_fnum < eap->line1 |
6641 | 2119 || !buf->b_p_bl); buf = buf->b_next) |
2120 if (buf->b_fnum > eap->line2) | |
2121 { | |
2122 buf = NULL; | |
2123 break; | |
2124 } | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2125 if (buf != NULL) |
6641 | 2126 goto_buffer(eap, DOBUF_FIRST, FORWARD, buf->b_fnum); |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2127 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2128 #ifdef FEAT_QUICKFIX |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2129 else if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2130 || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2131 { |
16515
6e87a69b8e0c
patch 8.1.1261: no error for quickfix commands with negative range
Bram Moolenaar <Bram@vim.org>
parents:
16381
diff
changeset
|
2132 qf_size = qf_get_valid_size(eap); |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2133 if (qf_size <= 0 || eap->line1 > qf_size) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2134 buf = NULL; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2135 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2136 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2137 ex_cc(eap); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2138 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2139 buf = curbuf; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2140 i = eap->line1 - 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2141 if (eap->addr_count <= 0) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2142 /* default is all the quickfix/location list entries */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2143 eap->line2 = qf_size; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2144 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2145 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2146 #endif |
7 | 2147 else |
2148 setpcmark(); | |
2149 listcmd_busy = TRUE; /* avoids setting pcmark below */ | |
2150 | |
6641 | 2151 while (!got_int && buf != NULL) |
7 | 2152 { |
2153 if (eap->cmdidx == CMD_argdo) | |
2154 { | |
2155 /* go to argument "i" */ | |
2156 if (i == ARGCOUNT) | |
2157 break; | |
2158 /* Don't call do_argfile() when already there, it will try | |
2159 * reloading the file. */ | |
22 | 2160 if (curwin->w_arg_idx != i || !editing_arg_idx(curwin)) |
39 | 2161 { |
2162 /* Clear 'shm' to avoid that the file message overwrites | |
2163 * any output from the command. */ | |
2164 p_shm_save = vim_strsave(p_shm); | |
2165 set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); | |
7 | 2166 do_argfile(eap, i); |
39 | 2167 set_option_value((char_u *)"shm", 0L, p_shm_save, 0); |
2168 vim_free(p_shm_save); | |
2169 } | |
7 | 2170 if (curwin->w_arg_idx != i) |
2171 break; | |
2172 } | |
2173 else if (eap->cmdidx == CMD_windo) | |
2174 { | |
685 | 2175 /* go to window "wp" */ |
2176 if (!win_valid(wp)) | |
7 | 2177 break; |
685 | 2178 win_goto(wp); |
1115 | 2179 if (curwin != wp) |
2180 break; /* something must be wrong */ | |
685 | 2181 wp = curwin->w_next; |
2182 } | |
2183 else if (eap->cmdidx == CMD_tabdo) | |
2184 { | |
2185 /* go to window "tp" */ | |
2186 if (!valid_tabpage(tp)) | |
2187 break; | |
4354 | 2188 goto_tabpage_tp(tp, TRUE, TRUE); |
685 | 2189 tp = tp->tp_next; |
7 | 2190 } |
2191 else if (eap->cmdidx == CMD_bufdo) | |
2192 { | |
2193 /* Remember the number of the next listed buffer, in case | |
2194 * ":bwipe" is used or autocommands do something strange. */ | |
2195 next_fnum = -1; | |
2196 for (buf = curbuf->b_next; buf != NULL; buf = buf->b_next) | |
2197 if (buf->b_p_bl) | |
2198 { | |
2199 next_fnum = buf->b_fnum; | |
2200 break; | |
2201 } | |
2202 } | |
2203 | |
6474 | 2204 ++i; |
2205 | |
7 | 2206 /* execute the command */ |
2207 do_cmdline(eap->arg, eap->getline, eap->cookie, | |
2208 DOCMD_VERBOSE + DOCMD_NOWAIT); | |
2209 | |
2210 if (eap->cmdidx == CMD_bufdo) | |
2211 { | |
2212 /* Done? */ | |
6474 | 2213 if (next_fnum < 0 || next_fnum > eap->line2) |
7 | 2214 break; |
2215 /* Check if the buffer still exists. */ | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9626
diff
changeset
|
2216 FOR_ALL_BUFFERS(buf) |
7 | 2217 if (buf->b_fnum == next_fnum) |
2218 break; | |
2219 if (buf == NULL) | |
2220 break; | |
39 | 2221 |
2222 /* Go to the next buffer. Clear 'shm' to avoid that the file | |
2223 * message overwrites any output from the command. */ | |
2224 p_shm_save = vim_strsave(p_shm); | |
2225 set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); | |
7 | 2226 goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); |
39 | 2227 set_option_value((char_u *)"shm", 0L, p_shm_save, 0); |
2228 vim_free(p_shm_save); | |
2229 | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2230 /* If autocommands took us elsewhere, quit here. */ |
7 | 2231 if (curbuf->b_fnum != next_fnum) |
2232 break; | |
2233 } | |
2234 | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2235 #ifdef FEAT_QUICKFIX |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2236 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2237 || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2238 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2239 if (i >= qf_size || i >= eap->line2) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2240 break; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2241 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2242 qf_idx = qf_get_cur_idx(eap); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2243 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2244 ex_cnext(eap); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2245 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2246 /* If jumping to the next quickfix entry fails, quit here */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2247 if (qf_get_cur_idx(eap) == qf_idx) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2248 break; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2249 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2250 #endif |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2251 |
7 | 2252 if (eap->cmdidx == CMD_windo) |
2253 { | |
2254 validate_cursor(); /* cursor may have moved */ | |
13384
6740c499de13
patch 8.0.1566: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2255 |
7 | 2256 /* required when 'scrollbind' has been set */ |
2257 if (curwin->w_p_scb) | |
2258 do_check_scrollbind(TRUE); | |
2259 } | |
6474 | 2260 |
2261 if (eap->cmdidx == CMD_windo || eap->cmdidx == CMD_tabdo) | |
2262 if (i+1 > eap->line2) | |
2263 break; | |
2264 if (eap->cmdidx == CMD_argdo && i >= eap->line2) | |
2265 break; | |
7 | 2266 } |
2267 listcmd_busy = FALSE; | |
2268 } | |
2269 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2270 #if defined(FEAT_SYN_HL) |
154 | 2271 if (save_ei != NULL) |
2272 { | |
2273 au_event_restore(save_ei); | |
2274 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, | |
2275 curbuf->b_fname, TRUE, curbuf); | |
2276 } | |
7 | 2277 #endif |
6116 | 2278 #ifdef FEAT_CLIPBOARD |
2279 end_global_changes(); | |
2280 #endif | |
7 | 2281 } |
2282 | |
2283 /* | |
2284 * Add files[count] to the arglist of the current window after arg "after". | |
2285 * The file names in files[count] must have been allocated and are taken over. | |
2286 * Files[] itself is not taken over. | |
2287 */ | |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
2288 static void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2289 alist_add_list( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2290 int count, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2291 char_u **files, |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
2292 int after, // where to add: 0 = before first one |
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
2293 int will_edit) // will edit adding argument |
7 | 2294 { |
2295 int i; | |
7647
65b2d593c203
commit https://github.com/vim/vim/commit/a24f0a550fed3d9773800cf6be4efd072fff20ec
Christian Brabandt <cb@256bit.org>
parents:
7639
diff
changeset
|
2296 int old_argcount = ARGCOUNT; |
7 | 2297 |
2298 if (ga_grow(&ALIST(curwin)->al_ga, count) == OK) | |
2299 { | |
2300 if (after < 0) | |
2301 after = 0; | |
2302 if (after > ARGCOUNT) | |
2303 after = ARGCOUNT; | |
2304 if (after < ARGCOUNT) | |
2305 mch_memmove(&(ARGLIST[after + count]), &(ARGLIST[after]), | |
2306 (ARGCOUNT - after) * sizeof(aentry_T)); | |
2307 for (i = 0; i < count; ++i) | |
2308 { | |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
2309 int flags = BLN_LISTED | (will_edit ? BLN_CURBUF : 0); |
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
2310 |
7 | 2311 ARGLIST[after + i].ae_fname = files[i]; |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
2312 ARGLIST[after + i].ae_fnum = buflist_add(files[i], flags); |
7 | 2313 } |
2314 ALIST(curwin)->al_ga.ga_len += count; | |
7647
65b2d593c203
commit https://github.com/vim/vim/commit/a24f0a550fed3d9773800cf6be4efd072fff20ec
Christian Brabandt <cb@256bit.org>
parents:
7639
diff
changeset
|
2315 if (old_argcount > 0 && curwin->w_arg_idx >= after) |
65b2d593c203
commit https://github.com/vim/vim/commit/a24f0a550fed3d9773800cf6be4efd072fff20ec
Christian Brabandt <cb@256bit.org>
parents:
7639
diff
changeset
|
2316 curwin->w_arg_idx += count; |
14656
0d5726f2913b
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Christian Brabandt <cb@256bit.org>
parents:
14642
diff
changeset
|
2317 return; |
7 | 2318 } |
2319 | |
2320 for (i = 0; i < count; ++i) | |
2321 vim_free(files[i]); | |
2322 } | |
2323 | |
13551
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2324 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2325 /* |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2326 * Function given to ExpandGeneric() to obtain the possible arguments of the |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2327 * argedit and argdelete commands. |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2328 */ |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2329 char_u * |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2330 get_arglist_name(expand_T *xp UNUSED, int idx) |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2331 { |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2332 if (idx >= ARGCOUNT) |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2333 return NULL; |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2334 |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2335 return alist_name(&ARGLIST[idx]); |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2336 } |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2337 #endif |
1fd0f8392946
patch 8.0.1649: no completion for argument list commands
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
2338 |
13553
04019fc3de93
patch 8.0.1650: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
2339 |
7 | 2340 #ifdef FEAT_EVAL |
2341 /* | |
2342 * ":compiler[!] {name}" | |
2343 */ | |
2344 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2345 ex_compiler(exarg_T *eap) |
7 | 2346 { |
2347 char_u *buf; | |
2348 char_u *old_cur_comp = NULL; | |
2349 char_u *p; | |
2350 | |
2351 if (*eap->arg == NUL) | |
2352 { | |
2353 /* List all compiler scripts. */ | |
2354 do_cmdline_cmd((char_u *)"echo globpath(&rtp, 'compiler/*.vim')"); | |
2355 /* ) keep the indenter happy... */ | |
2356 } | |
2357 else | |
2358 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
2359 buf = alloc(STRLEN(eap->arg) + 14); |
7 | 2360 if (buf != NULL) |
2361 { | |
2362 if (eap->forceit) | |
2363 { | |
2364 /* ":compiler! {name}" sets global options */ | |
2365 do_cmdline_cmd((char_u *) | |
2366 "command -nargs=* CompilerSet set <args>"); | |
2367 } | |
2368 else | |
2369 { | |
2370 /* ":compiler! {name}" sets local options. | |
2371 * To remain backwards compatible "current_compiler" is always | |
2372 * used. A user's compiler plugin may set it, the distributed | |
2373 * plugin will then skip the settings. Afterwards set | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2374 * "b:current_compiler" and restore "current_compiler". |
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2375 * Explicitly prepend "g:" to make it work in a function. */ |
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2376 old_cur_comp = get_var_value((char_u *)"g:current_compiler"); |
7 | 2377 if (old_cur_comp != NULL) |
2378 old_cur_comp = vim_strsave(old_cur_comp); | |
2379 do_cmdline_cmd((char_u *) | |
2380 "command -nargs=* CompilerSet setlocal <args>"); | |
2381 } | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2382 do_unlet((char_u *)"g:current_compiler", TRUE); |
148 | 2383 do_unlet((char_u *)"b:current_compiler", TRUE); |
7 | 2384 |
2385 sprintf((char *)buf, "compiler/%s.vim", eap->arg); | |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2386 if (source_runtime(buf, DIP_ALL) == FAIL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
2387 semsg(_("E666: compiler not supported: %s"), eap->arg); |
7 | 2388 vim_free(buf); |
2389 | |
2390 do_cmdline_cmd((char_u *)":delcommand CompilerSet"); | |
2391 | |
2392 /* Set "b:current_compiler" from "current_compiler". */ | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2393 p = get_var_value((char_u *)"g:current_compiler"); |
7 | 2394 if (p != NULL) |
2395 set_internal_string_var((char_u *)"b:current_compiler", p); | |
2396 | |
2397 /* Restore "current_compiler" for ":compiler {name}". */ | |
2398 if (!eap->forceit) | |
2399 { | |
2400 if (old_cur_comp != NULL) | |
2401 { | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2402 set_internal_string_var((char_u *)"g:current_compiler", |
7 | 2403 old_cur_comp); |
2404 vim_free(old_cur_comp); | |
2405 } | |
2406 else | |
2051
ef2890033e88
updated for version 7.2.337
Bram Moolenaar <bram@zimbu.org>
parents:
1882
diff
changeset
|
2407 do_unlet((char_u *)"g:current_compiler", TRUE); |
7 | 2408 } |
2409 } | |
2410 } | |
2411 } | |
2412 #endif | |
2413 | |
2414 /* | |
8526
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2415 * ":runtime [what] {name}" |
7 | 2416 */ |
2417 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2418 ex_runtime(exarg_T *eap) |
7 | 2419 { |
8526
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2420 char_u *arg = eap->arg; |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2421 char_u *p = skiptowhite(arg); |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2422 int len = (int)(p - arg); |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2423 int flags = eap->forceit ? DIP_ALL : 0; |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2424 |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2425 if (STRNCMP(arg, "START", len) == 0) |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2426 { |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2427 flags += DIP_START + DIP_NORTP; |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2428 arg = skipwhite(arg + len); |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2429 } |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2430 else if (STRNCMP(arg, "OPT", len) == 0) |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2431 { |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2432 flags += DIP_OPT + DIP_NORTP; |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2433 arg = skipwhite(arg + len); |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2434 } |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2435 else if (STRNCMP(arg, "PACK", len) == 0) |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2436 { |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2437 flags += DIP_START + DIP_OPT + DIP_NORTP; |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2438 arg = skipwhite(arg + len); |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2439 } |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2440 else if (STRNCMP(arg, "ALL", len) == 0) |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2441 { |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2442 flags += DIP_START + DIP_OPT; |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2443 arg = skipwhite(arg + len); |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2444 } |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2445 |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2446 source_runtime(arg, flags); |
7 | 2447 } |
2448 | |
2449 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2450 source_callback(char_u *fname, void *cookie UNUSED) |
7 | 2451 { |
819 | 2452 (void)do_source(fname, FALSE, DOSO_NONE); |
7 | 2453 } |
2454 | |
2455 /* | |
8416
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2456 * Find the file "name" in all directories in "path" and invoke |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2457 * "callback(fname, cookie)". |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2458 * "name" can contain wildcards. |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2459 * When "flags" has DIP_ALL: source all files, otherwise only the first one. |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2460 * When "flags" has DIP_DIR: find directories instead of files. |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2461 * When "flags" has DIP_ERR: give an error message if there is no match. |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2462 * |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2463 * return FAIL when no file could be sourced, OK otherwise. |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2464 */ |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8520
diff
changeset
|
2465 int |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2466 do_in_path( |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2467 char_u *path, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2468 char_u *name, |
8376
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2469 int flags, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2470 void (*callback)(char_u *fname, void *ck), |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2471 void *cookie) |
7 | 2472 { |
2473 char_u *rtp; | |
2474 char_u *np; | |
2475 char_u *buf; | |
2476 char_u *rtp_copy; | |
2477 char_u *tail; | |
2478 int num_files; | |
2479 char_u **files; | |
2480 int i; | |
2481 int did_one = FALSE; | |
2482 #ifdef AMIGA | |
2483 struct Process *proc = (struct Process *)FindTask(0L); | |
2484 APTR save_winptr = proc->pr_WindowPtr; | |
2485 | |
2486 /* Avoid a requester here for a volume that doesn't exist. */ | |
2487 proc->pr_WindowPtr = (APTR)-1L; | |
2488 #endif | |
2489 | |
2490 /* Make a copy of 'runtimepath'. Invoking the callback may change the | |
2491 * value. */ | |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2492 rtp_copy = vim_strsave(path); |
7 | 2493 buf = alloc(MAXPATHL); |
2494 if (buf != NULL && rtp_copy != NULL) | |
2495 { | |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2496 if (p_verbose > 1 && name != NULL) |
294 | 2497 { |
2498 verbose_enter(); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
2499 smsg(_("Searching for \"%s\" in \"%s\""), |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2500 (char *)name, (char *)path); |
294 | 2501 verbose_leave(); |
2502 } | |
271 | 2503 |
7 | 2504 /* Loop over all entries in 'runtimepath'. */ |
2505 rtp = rtp_copy; | |
8376
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2506 while (*rtp != NUL && ((flags & DIP_ALL) || !did_one)) |
7 | 2507 { |
9778
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2508 size_t buflen; |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2509 |
7 | 2510 /* Copy the path from 'runtimepath' to buf[]. */ |
2511 copy_option_part(&rtp, buf, MAXPATHL, ","); | |
9778
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2512 buflen = STRLEN(buf); |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2513 |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2514 /* Skip after or non-after directories. */ |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2515 if (flags & (DIP_NOAFTER | DIP_AFTER)) |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2516 { |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2517 int is_after = buflen >= 5 |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2518 && STRCMP(buf + buflen - 5, "after") == 0; |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2519 |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2520 if ((is_after && (flags & DIP_NOAFTER)) |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2521 || (!is_after && (flags & DIP_AFTER))) |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2522 continue; |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2523 } |
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2524 |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2525 if (name == NULL) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2526 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2527 (*callback)(buf, (void *) &cookie); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2528 if (!did_one) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2529 did_one = (cookie == NULL); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4825
diff
changeset
|
2530 } |
9778
4360b2b46125
commit https://github.com/vim/vim/commit/66459b7c98c67f8a9d39de8f08e8e8f1fca0e359
Christian Brabandt <cb@256bit.org>
parents:
9709
diff
changeset
|
2531 else if (buflen + STRLEN(name) + 2 < MAXPATHL) |
7 | 2532 { |
2533 add_pathsep(buf); | |
2534 tail = buf + STRLEN(buf); | |
2535 | |
2536 /* Loop over all patterns in "name" */ | |
2537 np = name; | |
8376
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2538 while (*np != NUL && ((flags & DIP_ALL) || !did_one)) |
7 | 2539 { |
2540 /* Append the pattern from "name" to buf[]. */ | |
2541 copy_option_part(&np, tail, (int)(MAXPATHL - (tail - buf)), | |
2542 "\t "); | |
2543 | |
2544 if (p_verbose > 2) | |
294 | 2545 { |
2546 verbose_enter(); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
2547 smsg(_("Searching for \"%s\""), buf); |
294 | 2548 verbose_leave(); |
2549 } | |
7 | 2550 |
2551 /* Expand wildcards, invoke the callback for each match. */ | |
2552 if (gen_expand_wildcards(1, &buf, &num_files, &files, | |
8376
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2553 (flags & DIP_DIR) ? EW_DIR : EW_FILE) == OK) |
7 | 2554 { |
2555 for (i = 0; i < num_files; ++i) | |
2556 { | |
237 | 2557 (*callback)(files[i], cookie); |
7 | 2558 did_one = TRUE; |
8376
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2559 if (!(flags & DIP_ALL)) |
7 | 2560 break; |
2561 } | |
2562 FreeWild(num_files, files); | |
2563 } | |
2564 } | |
2565 } | |
2566 } | |
2567 } | |
2568 vim_free(buf); | |
2569 vim_free(rtp_copy); | |
8416
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2570 if (!did_one && name != NULL) |
294 | 2571 { |
8416
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2572 char *basepath = path == p_rtp ? "runtimepath" : "packpath"; |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2573 |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2574 if (flags & DIP_ERR) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
2575 semsg(_(e_dirnotf), basepath, name); |
8416
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2576 else if (p_verbose > 0) |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2577 { |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2578 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
2579 smsg(_("not found in '%s': \"%s\""), basepath, name); |
8416
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2580 verbose_leave(); |
1a6527cce675
commit https://github.com/vim/vim/commit/be82c254862e475a582c0717455e1db6bf96b0d0
Christian Brabandt <cb@256bit.org>
parents:
8388
diff
changeset
|
2581 } |
294 | 2582 } |
7 | 2583 |
2584 #ifdef AMIGA | |
2585 proc->pr_WindowPtr = save_winptr; | |
2586 #endif | |
2587 | |
2588 return did_one ? OK : FAIL; | |
2589 } | |
2590 | |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2591 /* |
11595
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2592 * Find "name" in "path". When found, invoke the callback function for |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2593 * it: callback(fname, "cookie") |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2594 * When "flags" has DIP_ALL repeat for all matches, otherwise only the first |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2595 * one is used. |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2596 * Returns OK when at least one match found, FAIL otherwise. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2597 * |
11595
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2598 * If "name" is NULL calls callback for each entry in "path". Cookie is |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2599 * passed by reference in this case, setting it to NULL indicates that callback |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2600 * has done its job. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2601 */ |
11595
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2602 static int |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2603 do_in_path_and_pp( |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2604 char_u *path, |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2605 char_u *name, |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2606 int flags, |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2607 void (*callback)(char_u *fname, void *ck), |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2608 void *cookie) |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2609 { |
8526
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2610 int done = FAIL; |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2611 char_u *s; |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2612 int len; |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2613 char *start_dir = "pack/*/start/*/%s"; |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2614 char *opt_dir = "pack/*/opt/*/%s"; |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2615 |
8526
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2616 if ((flags & DIP_NORTP) == 0) |
11595
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2617 done = do_in_path(path, name, flags, callback, cookie); |
8526
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2618 |
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2619 if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START)) |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2620 { |
8595
887b378f29d1
commit https://github.com/vim/vim/commit/1c8b4edb9b6cd5248925f3f06ec82486be9fb4ea
Christian Brabandt <cb@256bit.org>
parents:
8587
diff
changeset
|
2621 len = (int)(STRLEN(start_dir) + STRLEN(name)); |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2622 s = alloc(len); |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2623 if (s == NULL) |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2624 return FAIL; |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2625 vim_snprintf((char *)s, len, start_dir, name); |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2626 done = do_in_path(p_pp, s, flags, callback, cookie); |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2627 vim_free(s); |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2628 } |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2629 |
8526
981cc3bef9f3
commit https://github.com/vim/vim/commit/8dcf259d904cfb965d31841dc74a5cfaf5a351d9
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2630 if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_OPT)) |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2631 { |
8595
887b378f29d1
commit https://github.com/vim/vim/commit/1c8b4edb9b6cd5248925f3f06ec82486be9fb4ea
Christian Brabandt <cb@256bit.org>
parents:
8587
diff
changeset
|
2632 len = (int)(STRLEN(opt_dir) + STRLEN(name)); |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2633 s = alloc(len); |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2634 if (s == NULL) |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2635 return FAIL; |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2636 vim_snprintf((char *)s, len, opt_dir, name); |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2637 done = do_in_path(p_pp, s, flags, callback, cookie); |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2638 vim_free(s); |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2639 } |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2640 |
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8522
diff
changeset
|
2641 return done; |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2642 } |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2643 |
8372
ce791ff9e0da
commit https://github.com/vim/vim/commit/1bdd42627d619258d0e847f217cfc1c2795f1ac5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
2644 /* |
11595
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2645 * Just like do_in_path_and_pp(), using 'runtimepath' for "path". |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2646 */ |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2647 int |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2648 do_in_runtimepath( |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2649 char_u *name, |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2650 int flags, |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2651 void (*callback)(char_u *fname, void *ck), |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2652 void *cookie) |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2653 { |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2654 return do_in_path_and_pp(p_rtp, name, flags, callback, cookie); |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2655 } |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2656 |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2657 /* |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2658 * Source the file "name" from all directories in 'runtimepath'. |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2659 * "name" can contain wildcards. |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2660 * When "flags" has DIP_ALL: source all files, otherwise only the first one. |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2661 * |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2662 * return FAIL when no file could be sourced, OK otherwise. |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2663 */ |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2664 int |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2665 source_runtime(char_u *name, int flags) |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2666 { |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2667 return source_in_path(p_rtp, name, flags); |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2668 } |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2669 |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2670 /* |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2671 * Just like source_runtime(), but use "path" instead of 'runtimepath'. |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2672 */ |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2673 int |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2674 source_in_path(char_u *path, char_u *name, int flags) |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2675 { |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2676 return do_in_path_and_pp(path, name, flags, source_callback, NULL); |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2677 } |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2678 |
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2679 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2680 #if defined(FEAT_EVAL) || defined(PROTO) |
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2681 |
11595
42cd59477698
patch 8.0.0680: plugins in start packages are sourced twice
Christian Brabandt <cb@256bit.org>
parents:
11575
diff
changeset
|
2682 /* |
8388
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2683 * Expand wildcards in "pat" and invoke do_source() for each match. |
8372
ce791ff9e0da
commit https://github.com/vim/vim/commit/1bdd42627d619258d0e847f217cfc1c2795f1ac5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
2684 */ |
ce791ff9e0da
commit https://github.com/vim/vim/commit/1bdd42627d619258d0e847f217cfc1c2795f1ac5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
2685 static void |
8388
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2686 source_all_matches(char_u *pat) |
8372
ce791ff9e0da
commit https://github.com/vim/vim/commit/1bdd42627d619258d0e847f217cfc1c2795f1ac5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
2687 { |
8388
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2688 int num_files; |
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2689 char_u **files; |
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2690 int i; |
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2691 |
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2692 if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK) |
8372
ce791ff9e0da
commit https://github.com/vim/vim/commit/1bdd42627d619258d0e847f217cfc1c2795f1ac5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
2693 { |
8388
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2694 for (i = 0; i < num_files; ++i) |
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2695 (void)do_source(files[i], FALSE, DOSO_NONE); |
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2696 FreeWild(num_files, files); |
8372
ce791ff9e0da
commit https://github.com/vim/vim/commit/1bdd42627d619258d0e847f217cfc1c2795f1ac5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
2697 } |
ce791ff9e0da
commit https://github.com/vim/vim/commit/1bdd42627d619258d0e847f217cfc1c2795f1ac5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
2698 } |
ce791ff9e0da
commit https://github.com/vim/vim/commit/1bdd42627d619258d0e847f217cfc1c2795f1ac5
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
2699 |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2700 /* |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2701 * Add the package directory to 'runtimepath'. |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2702 */ |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2703 static int |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2704 add_pack_dir_to_rtp(char_u *fname) |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2705 { |
8388
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2706 char_u *p4, *p3, *p2, *p1, *p; |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2707 char_u *entry; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2708 char_u *insp = NULL; |
8376
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2709 int c; |
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2710 char_u *new_rtp; |
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2711 int keep; |
9155
e4d7e6d1a0f1
commit https://github.com/vim/vim/commit/b055066a1daf12c349d6c575aff22ae4d999a157
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
2712 size_t oldlen; |
e4d7e6d1a0f1
commit https://github.com/vim/vim/commit/b055066a1daf12c349d6c575aff22ae4d999a157
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
2713 size_t addlen; |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2714 size_t new_rtp_len; |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2715 char_u *afterdir = NULL; |
9155
e4d7e6d1a0f1
commit https://github.com/vim/vim/commit/b055066a1daf12c349d6c575aff22ae4d999a157
Christian Brabandt <cb@256bit.org>
parents:
9153
diff
changeset
|
2716 size_t afterlen = 0; |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2717 char_u *after_insp = NULL; |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2718 char_u *ffname = NULL; |
9410
5a095f9e77ed
commit https://github.com/vim/vim/commit/fef524bbff9aa186838c35212b2f89f61d627cf8
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2719 size_t fname_len; |
10837
437cf0fe2138
patch 8.0.0308: 'runtimepath' not update correctly when using symbolic link
Christian Brabandt <cb@256bit.org>
parents:
10722
diff
changeset
|
2720 char_u *buf = NULL; |
437cf0fe2138
patch 8.0.0308: 'runtimepath' not update correctly when using symbolic link
Christian Brabandt <cb@256bit.org>
parents:
10722
diff
changeset
|
2721 char_u *rtp_ffname; |
437cf0fe2138
patch 8.0.0308: 'runtimepath' not update correctly when using symbolic link
Christian Brabandt <cb@256bit.org>
parents:
10722
diff
changeset
|
2722 int match; |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2723 int retval = FAIL; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2724 |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2725 p4 = p3 = p2 = p1 = get_past_head(fname); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2726 for (p = p1; *p; MB_PTR_ADV(p)) |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2727 if (vim_ispathsep_nocolon(*p)) |
9383
2547ef419123
commit https://github.com/vim/vim/commit/4c5717ed8a81f5ae9dfe4f38b17a61fc8421054b
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
2728 { |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2729 p4 = p3; p3 = p2; p2 = p1; p1 = p; |
9383
2547ef419123
commit https://github.com/vim/vim/commit/4c5717ed8a81f5ae9dfe4f38b17a61fc8421054b
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
2730 } |
2547ef419123
commit https://github.com/vim/vim/commit/4c5717ed8a81f5ae9dfe4f38b17a61fc8421054b
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
2731 |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2732 /* now we have: |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2733 * rtp/pack/name/start/name |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2734 * p4 p3 p2 p1 |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2735 * |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2736 * find the part up to "pack" in 'runtimepath' */ |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2737 c = *++p4; /* append pathsep in order to expand symlink */ |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2738 *p4 = NUL; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2739 ffname = fix_fname(fname); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2740 *p4 = c; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2741 if (ffname == NULL) |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2742 return FAIL; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2743 |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2744 // Find "ffname" in "p_rtp", ignoring '/' vs '\' differences. |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2745 // Also stop at the first "after" directory. |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2746 fname_len = STRLEN(ffname); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2747 buf = alloc(MAXPATHL); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2748 if (buf == NULL) |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2749 goto theend; |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2750 for (entry = p_rtp; *entry != NUL; ) |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2751 { |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2752 char_u *cur_entry = entry; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2753 |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2754 copy_option_part(&entry, buf, MAXPATHL, ","); |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2755 if (insp == NULL) |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2756 { |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2757 add_pathsep(buf); |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2758 rtp_ffname = fix_fname(buf); |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2759 if (rtp_ffname == NULL) |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2760 goto theend; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2761 match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2762 vim_free(rtp_ffname); |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2763 if (match) |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2764 // Insert "ffname" after this entry (and comma). |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2765 insp = entry; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2766 } |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2767 |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2768 if ((p = (char_u *)strstr((char *)buf, "after")) != NULL |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2769 && p > buf |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2770 && vim_ispathsep(p[-1]) |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2771 && (vim_ispathsep(p[5]) || p[5] == NUL || p[5] == ',')) |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2772 { |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2773 if (insp == NULL) |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2774 // Did not find "ffname" before the first "after" directory, |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2775 // insert it before this entry. |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2776 insp = cur_entry; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2777 after_insp = cur_entry; |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2778 break; |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2779 } |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2780 } |
8388
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2781 |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2782 if (insp == NULL) |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2783 // Both "fname" and "after" not found, append at the end. |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2784 insp = p_rtp + STRLEN(p_rtp); |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2785 |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2786 // check if rtp/pack/name/start/name/after exists |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2787 afterdir = concat_fnames(fname, (char_u *)"after", TRUE); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2788 if (afterdir != NULL && mch_isdir(afterdir)) |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2789 afterlen = STRLEN(afterdir) + 1; // add one for comma |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2790 |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2791 oldlen = STRLEN(p_rtp); |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2792 addlen = STRLEN(fname) + 1; // add one for comma |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2793 new_rtp = alloc(oldlen + addlen + afterlen + 1); // add one for NUL |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2794 if (new_rtp == NULL) |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2795 goto theend; |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2796 |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2797 // We now have 'rtp' parts: {keep}{keep_after}{rest}. |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2798 // Create new_rtp, first: {keep},{fname} |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2799 keep = (int)(insp - p_rtp); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2800 mch_memmove(new_rtp, p_rtp, keep); |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2801 new_rtp_len = keep; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2802 if (*insp == NUL) |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2803 new_rtp[new_rtp_len++] = ','; // add comma before |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2804 mch_memmove(new_rtp + new_rtp_len, fname, addlen - 1); |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2805 new_rtp_len += addlen - 1; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2806 if (*insp != NUL) |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2807 new_rtp[new_rtp_len++] = ','; // add comma after |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2808 |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2809 if (afterlen > 0 && after_insp != NULL) |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2810 { |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2811 int keep_after = (int)(after_insp - p_rtp); |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2812 |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2813 // Add to new_rtp: {keep},{fname}{keep_after},{afterdir} |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2814 mch_memmove(new_rtp + new_rtp_len, p_rtp + keep, |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2815 keep_after - keep); |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2816 new_rtp_len += keep_after - keep; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2817 mch_memmove(new_rtp + new_rtp_len, afterdir, afterlen - 1); |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2818 new_rtp_len += afterlen - 1; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2819 new_rtp[new_rtp_len++] = ','; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2820 keep = keep_after; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2821 } |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2822 |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2823 if (p_rtp[keep] != NUL) |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2824 // Append rest: {keep},{fname}{keep_after},{afterdir}{rest} |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2825 mch_memmove(new_rtp + new_rtp_len, p_rtp + keep, oldlen - keep + 1); |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2826 else |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2827 new_rtp[new_rtp_len] = NUL; |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2828 |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2829 if (afterlen > 0 && after_insp == NULL) |
8388
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2830 { |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2831 // Append afterdir when "after" was not found: |
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2832 // {keep},{fname}{rest},{afterdir} |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2833 STRCAT(new_rtp, ","); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2834 STRCAT(new_rtp, afterdir); |
8388
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2835 } |
14681
285b051979a6
patch 8.1.0353: an "after" directory of a package is appended to 'rtp'
Christian Brabandt <cb@256bit.org>
parents:
14656
diff
changeset
|
2836 |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2837 set_option_value((char_u *)"rtp", 0L, new_rtp, 0); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2838 vim_free(new_rtp); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2839 retval = OK; |
8388
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2840 |
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2841 theend: |
10837
437cf0fe2138
patch 8.0.0308: 'runtimepath' not update correctly when using symbolic link
Christian Brabandt <cb@256bit.org>
parents:
10722
diff
changeset
|
2842 vim_free(buf); |
8376
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2843 vim_free(ffname); |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2844 vim_free(afterdir); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2845 return retval; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2846 } |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2847 |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2848 /* |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2849 * Load scripts in "plugin" and "ftdetect" directories of the package. |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2850 */ |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2851 static int |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2852 load_pack_plugin(char_u *fname) |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2853 { |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2854 static char *plugpat = "%s/plugin/**/*.vim"; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2855 static char *ftpat = "%s/ftdetect/*.vim"; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2856 int len; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2857 char_u *ffname = fix_fname(fname); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2858 char_u *pat = NULL; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2859 int retval = FAIL; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2860 |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2861 if (ffname == NULL) |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2862 return FAIL; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2863 len = (int)STRLEN(ffname) + (int)STRLEN(ftpat); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2864 pat = alloc(len); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2865 if (pat == NULL) |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2866 goto theend; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2867 vim_snprintf((char *)pat, len, plugpat, ffname); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2868 source_all_matches(pat); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2869 |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2870 { |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2871 char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes"); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2872 |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2873 /* If runtime/filetype.vim wasn't loaded yet, the scripts will be |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2874 * found when it loads. */ |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2875 if (cmd != NULL && eval_to_number(cmd) > 0) |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2876 { |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2877 do_cmdline_cmd((char_u *)"augroup filetypedetect"); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2878 vim_snprintf((char *)pat, len, ftpat, ffname); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2879 source_all_matches(pat); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2880 do_cmdline_cmd((char_u *)"augroup END"); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2881 } |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2882 vim_free(cmd); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2883 } |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2884 vim_free(pat); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2885 retval = OK; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2886 |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2887 theend: |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2888 vim_free(ffname); |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2889 return retval; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2890 } |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2891 |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2892 /* used for "cookie" of add_pack_plugin() */ |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2893 static int APP_ADD_DIR; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2894 static int APP_LOAD; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2895 static int APP_BOTH; |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2896 |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2897 static void |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2898 add_pack_plugin(char_u *fname, void *cookie) |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2899 { |
13724
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2900 if (cookie != &APP_LOAD) |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2901 { |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2902 char_u *buf = alloc(MAXPATHL); |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2903 char_u *p; |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2904 int found = FALSE; |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2905 |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2906 if (buf == NULL) |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2907 return; |
13724
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2908 p = p_rtp; |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2909 while (*p != NUL) |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2910 { |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2911 copy_option_part(&p, buf, MAXPATHL, ","); |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2912 if (pathcmp((char *)buf, (char *)fname, -1) == 0) |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2913 { |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2914 found = TRUE; |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2915 break; |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2916 } |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2917 } |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2918 vim_free(buf); |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2919 if (!found) |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2920 /* directory is not yet in 'runtimepath', add it */ |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2921 if (add_pack_dir_to_rtp(fname) == FAIL) |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2922 return; |
5ef1e6170589
patch 8.0.1734: package directory not added to 'rtp' if prefix matches
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
2923 } |
13190
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2924 |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2925 if (cookie != &APP_ADD_DIR) |
9fccd578ce1f
patch 8.0.1469: when package path is a symlink 'runtimepath' is wrong
Christian Brabandt <cb@256bit.org>
parents:
13045
diff
changeset
|
2926 load_pack_plugin(fname); |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2927 } |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2928 |
11457
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2929 /* |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2930 * Add all packages in the "start" directory to 'runtimepath'. |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2931 */ |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2932 void |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2933 add_pack_start_dirs(void) |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2934 { |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2935 do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2936 add_pack_plugin, &APP_ADD_DIR); |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2937 } |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2938 |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2939 /* |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2940 * Load plugins from all packages in the "start" directory. |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2941 */ |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2942 void |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2943 load_start_packages(void) |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2944 { |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2945 did_source_packages = TRUE; |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2946 do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2947 add_pack_plugin, &APP_LOAD); |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2948 } |
8520
b4350a4d1e01
commit https://github.com/vim/vim/commit/2d8f56acb32428d0f965d42dd13b27100b46fa15
Christian Brabandt <cb@256bit.org>
parents:
8475
diff
changeset
|
2949 |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2950 /* |
8520
b4350a4d1e01
commit https://github.com/vim/vim/commit/2d8f56acb32428d0f965d42dd13b27100b46fa15
Christian Brabandt <cb@256bit.org>
parents:
8475
diff
changeset
|
2951 * ":packloadall" |
8388
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2952 * Find plugins in the package directories and source them. |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2953 */ |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2954 void |
8520
b4350a4d1e01
commit https://github.com/vim/vim/commit/2d8f56acb32428d0f965d42dd13b27100b46fa15
Christian Brabandt <cb@256bit.org>
parents:
8475
diff
changeset
|
2955 ex_packloadall(exarg_T *eap) |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2956 { |
11457
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2957 if (!did_source_packages || eap->forceit) |
8520
b4350a4d1e01
commit https://github.com/vim/vim/commit/2d8f56acb32428d0f965d42dd13b27100b46fa15
Christian Brabandt <cb@256bit.org>
parents:
8475
diff
changeset
|
2958 { |
8849
9f40a379ff1e
commit https://github.com/vim/vim/commit/49b27326447d0827c59c6cd201d58f65c1163086
Christian Brabandt <cb@256bit.org>
parents:
8823
diff
changeset
|
2959 /* First do a round to add all directories to 'runtimepath', then load |
9f40a379ff1e
commit https://github.com/vim/vim/commit/49b27326447d0827c59c6cd201d58f65c1163086
Christian Brabandt <cb@256bit.org>
parents:
8823
diff
changeset
|
2960 * the plugins. This allows for plugins to use an autoload directory |
9f40a379ff1e
commit https://github.com/vim/vim/commit/49b27326447d0827c59c6cd201d58f65c1163086
Christian Brabandt <cb@256bit.org>
parents:
8823
diff
changeset
|
2961 * of another plugin. */ |
11457
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2962 add_pack_start_dirs(); |
5a1656d79707
patch 8.0.0612: pack dirs are added to 'runtimepath' too late
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2963 load_start_packages(); |
8520
b4350a4d1e01
commit https://github.com/vim/vim/commit/2d8f56acb32428d0f965d42dd13b27100b46fa15
Christian Brabandt <cb@256bit.org>
parents:
8475
diff
changeset
|
2964 } |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2965 } |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2966 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
2967 /* |
8388
f5972de59001
commit https://github.com/vim/vim/commit/f3654827368e6204608036353a0360e9e7c21e02
Christian Brabandt <cb@256bit.org>
parents:
8378
diff
changeset
|
2968 * ":packadd[!] {name}" |
8376
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2969 */ |
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2970 void |
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2971 ex_packadd(exarg_T *eap) |
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2972 { |
13045
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2973 static char *plugpat = "pack/*/%s/%s"; |
8376
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2974 int len; |
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2975 char *pat; |
13045
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2976 int round; |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2977 int res = OK; |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2978 |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2979 /* Round 1: use "start", round 2: use "opt". */ |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2980 for (round = 1; round <= 2; ++round) |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2981 { |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2982 /* Only look under "start" when loading packages wasn't done yet. */ |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2983 if (round == 1 && did_source_packages) |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2984 continue; |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2985 |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2986 len = (int)STRLEN(plugpat) + (int)STRLEN(eap->arg) + 5; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2987 pat = alloc(len); |
13045
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2988 if (pat == NULL) |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2989 return; |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2990 vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg); |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2991 /* The first round don't give a "not found" error, in the second round |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2992 * only when nothing was found in the first round. */ |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2993 res = do_in_path(p_pp, (char_u *)pat, |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2994 DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0), |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2995 add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH); |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2996 vim_free(pat); |
afd60028f7b7
patch 8.0.1398: :packadd does not load packages from the "start" directory
Christian Brabandt <cb@256bit.org>
parents:
12992
diff
changeset
|
2997 } |
8376
e448f2a5d45b
commit https://github.com/vim/vim/commit/91715873d19a1859c08eeded7848113596e2f2bd
Christian Brabandt <cb@256bit.org>
parents:
8374
diff
changeset
|
2998 } |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2999 #endif |
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
3000 |
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
3001 #if defined(FEAT_EVAL) || defined(PROTO) |
7 | 3002 /* |
3003 * ":options" | |
3004 */ | |
3005 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3006 ex_options( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3007 exarg_T *eap UNUSED) |
7 | 3008 { |
16722
19ca17f9e155
patch 8.1.1363: ":vert options" does not make a vertical split
Bram Moolenaar <Bram@vim.org>
parents:
16634
diff
changeset
|
3009 vim_setenv((char_u *)"OPTWIN_CMD", |
19ca17f9e155
patch 8.1.1363: ":vert options" does not make a vertical split
Bram Moolenaar <Bram@vim.org>
parents:
16634
diff
changeset
|
3010 (char_u *)(cmdmod.tab ? "tab" |
19ca17f9e155
patch 8.1.1363: ":vert options" does not make a vertical split
Bram Moolenaar <Bram@vim.org>
parents:
16634
diff
changeset
|
3011 : (cmdmod.split & WSP_VERT) ? "vert" : "")); |
7 | 3012 cmd_source((char_u *)SYS_OPTWIN_FILE, NULL); |
3013 } | |
3014 #endif | |
3015 | |
10722
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3016 #if defined(FEAT_PYTHON3) || defined(FEAT_PYTHON) || defined(PROTO) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3017 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3018 # if (defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)) || defined(PROTO) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3019 /* |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3020 * Detect Python 3 or 2, and initialize 'pyxversion'. |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3021 */ |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3022 void |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3023 init_pyxversion(void) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3024 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3025 if (p_pyx == 0) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3026 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3027 if (python3_enabled(FALSE)) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3028 p_pyx = 3; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3029 else if (python_enabled(FALSE)) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3030 p_pyx = 2; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3031 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3032 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3033 # endif |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3034 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3035 /* |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3036 * Does a file contain one of the following strings at the beginning of any |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3037 * line? |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3038 * "#!(any string)python2" => returns 2 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3039 * "#!(any string)python3" => returns 3 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3040 * "# requires python 2.x" => returns 2 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3041 * "# requires python 3.x" => returns 3 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3042 * otherwise return 0. |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3043 */ |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3044 static int |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3045 requires_py_version(char_u *filename) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3046 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3047 FILE *file; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3048 int requires_py_version = 0; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3049 int i, lines; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3050 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3051 lines = (int)p_mls; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3052 if (lines < 0) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3053 lines = 5; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3054 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3055 file = mch_fopen((char *)filename, "r"); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3056 if (file != NULL) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3057 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3058 for (i = 0; i < lines; i++) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3059 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3060 if (vim_fgets(IObuff, IOSIZE, file)) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3061 break; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3062 if (i == 0 && IObuff[0] == '#' && IObuff[1] == '!') |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3063 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3064 /* Check shebang. */ |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3065 if (strstr((char *)IObuff + 2, "python2") != NULL) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3066 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3067 requires_py_version = 2; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3068 break; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3069 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3070 if (strstr((char *)IObuff + 2, "python3") != NULL) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3071 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3072 requires_py_version = 3; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3073 break; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3074 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3075 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3076 IObuff[21] = '\0'; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3077 if (STRCMP("# requires python 2.x", IObuff) == 0) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3078 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3079 requires_py_version = 2; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3080 break; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3081 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3082 if (STRCMP("# requires python 3.x", IObuff) == 0) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3083 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3084 requires_py_version = 3; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3085 break; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3086 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3087 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3088 fclose(file); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3089 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3090 return requires_py_version; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3091 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3092 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3093 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3094 /* |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3095 * Source a python file using the requested python version. |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3096 */ |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3097 static void |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3098 source_pyx_file(exarg_T *eap, char_u *fname) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3099 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3100 exarg_T ex; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3101 int v = requires_py_version(fname); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3102 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3103 # if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3104 init_pyxversion(); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3105 # endif |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3106 if (v == 0) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3107 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3108 # if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3109 /* user didn't choose a preference, 'pyx' is used */ |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3110 v = p_pyx; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3111 # elif defined(FEAT_PYTHON) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3112 v = 2; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3113 # elif defined(FEAT_PYTHON3) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3114 v = 3; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3115 # endif |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3116 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3117 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3118 /* |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3119 * now source, if required python version is not supported show |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3120 * unobtrusive message. |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3121 */ |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3122 if (eap == NULL) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3123 vim_memset(&ex, 0, sizeof(ex)); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3124 else |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3125 ex = *eap; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3126 ex.arg = fname; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3127 ex.cmd = (char_u *)(v == 2 ? "pyfile" : "pyfile3"); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3128 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3129 if (v == 2) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3130 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3131 # ifdef FEAT_PYTHON |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3132 ex_pyfile(&ex); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3133 # else |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3134 vim_snprintf((char *)IObuff, IOSIZE, |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3135 _("W20: Required python version 2.x not supported, ignoring file: %s"), |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3136 fname); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3137 msg((char *)IObuff); |
10722
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3138 # endif |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3139 return; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3140 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3141 else |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3142 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3143 # ifdef FEAT_PYTHON3 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3144 ex_py3file(&ex); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3145 # else |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3146 vim_snprintf((char *)IObuff, IOSIZE, |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3147 _("W21: Required python version 3.x not supported, ignoring file: %s"), |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3148 fname); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3149 msg((char *)IObuff); |
10722
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3150 # endif |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3151 return; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3152 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3153 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3154 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3155 /* |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3156 * ":pyxfile {fname}" |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3157 */ |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3158 void |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3159 ex_pyxfile(exarg_T *eap) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3160 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3161 source_pyx_file(eap, eap->arg); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3162 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3163 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3164 /* |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3165 * ":pyx" |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3166 */ |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3167 void |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3168 ex_pyx(exarg_T *eap) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3169 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3170 # if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3171 init_pyxversion(); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3172 if (p_pyx == 2) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3173 ex_python(eap); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3174 else |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3175 ex_py3(eap); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3176 # elif defined(FEAT_PYTHON) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3177 ex_python(eap); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3178 # elif defined(FEAT_PYTHON3) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3179 ex_py3(eap); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3180 # endif |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3181 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3182 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3183 /* |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3184 * ":pyxdo" |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3185 */ |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3186 void |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3187 ex_pyxdo(exarg_T *eap) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3188 { |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3189 # if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3190 init_pyxversion(); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3191 if (p_pyx == 2) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3192 ex_pydo(eap); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3193 else |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3194 ex_py3do(eap); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3195 # elif defined(FEAT_PYTHON) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3196 ex_pydo(eap); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3197 # elif defined(FEAT_PYTHON3) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3198 ex_py3do(eap); |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3199 # endif |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3200 } |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3201 |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3202 #endif |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
10569
diff
changeset
|
3203 |
7 | 3204 /* |
3205 * ":source {fname}" | |
3206 */ | |
3207 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3208 ex_source(exarg_T *eap) |
7 | 3209 { |
3210 #ifdef FEAT_BROWSE | |
3211 if (cmdmod.browse) | |
3212 { | |
3213 char_u *fname = NULL; | |
3214 | |
29 | 3215 fname = do_browse(0, (char_u *)_("Source Vim script"), eap->arg, |
13802
378f9f8e6d8f
patch 8.0.1773: dialog messages are not translated
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3216 NULL, NULL, |
378f9f8e6d8f
patch 8.0.1773: dialog messages are not translated
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3217 (char_u *)_(BROWSE_FILTER_MACROS), NULL); |
7 | 3218 if (fname != NULL) |
3219 { | |
3220 cmd_source(fname, eap); | |
3221 vim_free(fname); | |
3222 } | |
3223 } | |
3224 else | |
3225 #endif | |
3226 cmd_source(eap->arg, eap); | |
3227 } | |
3228 | |
3229 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3230 cmd_source(char_u *fname, exarg_T *eap) |
7 | 3231 { |
3232 if (*fname == NUL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3233 emsg(_(e_argreq)); |
7 | 3234 |
3235 else if (eap != NULL && eap->forceit) | |
4352 | 3236 /* ":source!": read Normal mode commands |
716 | 3237 * Need to execute the commands directly. This is required at least |
3238 * for: | |
7 | 3239 * - ":g" command busy |
3240 * - after ":argdo", ":windo" or ":bufdo" | |
3241 * - another command follows | |
3242 * - inside a loop | |
3243 */ | |
3244 openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL | |
3245 #ifdef FEAT_EVAL | |
3246 || eap->cstack->cs_idx >= 0 | |
3247 #endif | |
3248 ); | |
3249 | |
3250 /* ":source" read ex commands */ | |
819 | 3251 else if (do_source(fname, FALSE, DOSO_NONE) == FAIL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3252 semsg(_(e_notopen), fname); |
7 | 3253 } |
3254 | |
3255 /* | |
3256 * ":source" and associated commands. | |
3257 */ | |
3258 /* | |
3259 * Structure used to store info for each sourced file. | |
3260 * It is shared between do_source() and getsourceline(). | |
3261 * This is required, because it needs to be handed to do_cmdline() and | |
3262 * sourcing can be done recursively. | |
3263 */ | |
3264 struct source_cookie | |
3265 { | |
3266 FILE *fp; /* opened file for sourcing */ | |
3267 char_u *nextline; /* if not NULL: line that was read ahead */ | |
3268 int finished; /* ":finish" used */ | |
15840
734b1928a5aa
patch 8.1.0927: USE_CR is never defined
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3269 #ifdef USE_CRNL |
7 | 3270 int fileformat; /* EOL_UNKNOWN, EOL_UNIX or EOL_DOS */ |
3271 int error; /* TRUE if LF found after CR-LF */ | |
3272 #endif | |
3273 #ifdef FEAT_EVAL | |
3274 linenr_T breakpoint; /* next line with breakpoint or zero */ | |
3275 char_u *fname; /* name of sourced file */ | |
3276 int dbg_tick; /* debug_tick when breakpoint was set */ | |
3277 int level; /* top nesting level of sourced file */ | |
3278 #endif | |
3279 vimconv_T conv; /* type of conversion */ | |
3280 }; | |
3281 | |
3282 #ifdef FEAT_EVAL | |
3283 /* | |
3284 * Return the address holding the next breakpoint line for a source cookie. | |
3285 */ | |
3286 linenr_T * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3287 source_breakpoint(void *cookie) |
7 | 3288 { |
3289 return &((struct source_cookie *)cookie)->breakpoint; | |
3290 } | |
3291 | |
3292 /* | |
3293 * Return the address holding the debug tick for a source cookie. | |
3294 */ | |
3295 int * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3296 source_dbg_tick(void *cookie) |
7 | 3297 { |
3298 return &((struct source_cookie *)cookie)->dbg_tick; | |
3299 } | |
3300 | |
3301 /* | |
3302 * Return the nesting level for a source cookie. | |
3303 */ | |
3304 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3305 source_level(void *cookie) |
7 | 3306 { |
3307 return ((struct source_cookie *)cookie)->level; | |
3308 } | |
3309 #endif | |
3310 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7726
diff
changeset
|
3311 static char_u *get_one_sourceline(struct source_cookie *sp); |
7 | 3312 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
3313 #if (defined(MSWIN) && defined(FEAT_CSCOPE)) || defined(HAVE_FD_CLOEXEC) |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3314 # define USE_FOPEN_NOINH |
7 | 3315 /* |
3316 * Special function to open a file without handle inheritance. | |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3317 * When possible the handle is closed on exec(). |
7 | 3318 */ |
3319 static FILE * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3320 fopen_noinh_readbin(char *filename) |
7 | 3321 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
3322 # ifdef MSWIN |
2058
fb1222c880fc
updated for version 7.2.344
Bram Moolenaar <bram@zimbu.org>
parents:
2057
diff
changeset
|
3323 int fd_tmp = mch_open(filename, O_RDONLY | O_BINARY | O_NOINHERIT, 0); |
fb1222c880fc
updated for version 7.2.344
Bram Moolenaar <bram@zimbu.org>
parents:
2057
diff
changeset
|
3324 # else |
fb1222c880fc
updated for version 7.2.344
Bram Moolenaar <bram@zimbu.org>
parents:
2057
diff
changeset
|
3325 int fd_tmp = mch_open(filename, O_RDONLY, 0); |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3326 # endif |
7 | 3327 |
3328 if (fd_tmp == -1) | |
3329 return NULL; | |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3330 |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3331 # ifdef HAVE_FD_CLOEXEC |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3332 { |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3333 int fdflags = fcntl(fd_tmp, F_GETFD); |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3334 if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0) |
7009 | 3335 (void)fcntl(fd_tmp, F_SETFD, fdflags | FD_CLOEXEC); |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3336 } |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3337 # endif |
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3338 |
7 | 3339 return fdopen(fd_tmp, READBIN); |
3340 } | |
3341 #endif | |
3342 | |
3343 | |
3344 /* | |
3345 * do_source: Read the file "fname" and execute its lines as EX commands. | |
3346 * | |
3347 * This function may be called recursively! | |
3348 * | |
3349 * return FAIL if file could not be opened, OK otherwise | |
3350 */ | |
3351 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3352 do_source( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3353 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3354 int check_other, /* check for .vimrc and _vimrc */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3355 int is_vimrc) /* DOSO_ value */ |
7 | 3356 { |
3357 struct source_cookie cookie; | |
3358 char_u *save_sourcing_name; | |
3359 linenr_T save_sourcing_lnum; | |
3360 char_u *p; | |
3361 char_u *fname_exp; | |
1802 | 3362 char_u *firstline = NULL; |
7 | 3363 int retval = FAIL; |
3364 #ifdef FEAT_EVAL | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3365 sctx_T save_current_sctx; |
7 | 3366 static scid_T last_current_SID = 0; |
15008
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15002
diff
changeset
|
3367 static int last_current_SID_seq = 0; |
14927
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3368 funccal_entry_T funccalp_entry; |
7 | 3369 int save_debug_break_level = debug_break_level; |
170 | 3370 scriptitem_T *si = NULL; |
7 | 3371 # ifdef UNIX |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9383
diff
changeset
|
3372 stat_T st; |
7 | 3373 int stat_ok; |
3374 # endif | |
3375 #endif | |
3376 #ifdef STARTUPTIME | |
3377 struct timeval tv_rel; | |
3378 struct timeval tv_start; | |
3379 #endif | |
170 | 3380 #ifdef FEAT_PROFILE |
3381 proftime_T wait_start; | |
3382 #endif | |
15442
3e2e1608efa4
patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
15286
diff
changeset
|
3383 int trigger_source_post = FALSE; |
7 | 3384 |
3385 p = expand_env_save(fname); | |
3386 if (p == NULL) | |
3387 return retval; | |
3388 fname_exp = fix_fname(p); | |
3389 vim_free(p); | |
3390 if (fname_exp == NULL) | |
3391 return retval; | |
3392 if (mch_isdir(fname_exp)) | |
3393 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3394 smsg(_("Cannot source a directory: \"%s\""), fname); |
7 | 3395 goto theend; |
3396 } | |
3397 | |
1061 | 3398 /* Apply SourceCmd autocommands, they should get the file and source it. */ |
3399 if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL) | |
3400 && apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp, | |
3401 FALSE, curbuf)) | |
1515 | 3402 { |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
3403 #ifdef FEAT_EVAL |
1515 | 3404 retval = aborting() ? FAIL : OK; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
3405 #else |
1515 | 3406 retval = OK; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
3407 #endif |
15442
3e2e1608efa4
patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
15286
diff
changeset
|
3408 if (retval == OK) |
3e2e1608efa4
patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
15286
diff
changeset
|
3409 // Apply SourcePost autocommands. |
3e2e1608efa4
patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
15286
diff
changeset
|
3410 apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp, |
3e2e1608efa4
patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
15286
diff
changeset
|
3411 FALSE, curbuf); |
1515 | 3412 goto theend; |
3413 } | |
1061 | 3414 |
3415 /* Apply SourcePre autocommands, they may get the file. */ | |
716 | 3416 apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf); |
3417 | |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3418 #ifdef USE_FOPEN_NOINH |
7 | 3419 cookie.fp = fopen_noinh_readbin((char *)fname_exp); |
3420 #else | |
3421 cookie.fp = mch_fopen((char *)fname_exp, READBIN); | |
3422 #endif | |
3423 if (cookie.fp == NULL && check_other) | |
3424 { | |
3425 /* | |
3426 * Try again, replacing file name ".vimrc" by "_vimrc" or vice versa, | |
3427 * and ".exrc" by "_exrc" or vice versa. | |
3428 */ | |
3429 p = gettail(fname_exp); | |
3430 if ((*p == '.' || *p == '_') | |
3431 && (STRICMP(p + 1, "vimrc") == 0 | |
3432 || STRICMP(p + 1, "gvimrc") == 0 | |
3433 || STRICMP(p + 1, "exrc") == 0)) | |
3434 { | |
3435 if (*p == '_') | |
3436 *p = '.'; | |
3437 else | |
3438 *p = '_'; | |
2052
057029bf3470
updated for version 7.2.338
Bram Moolenaar <bram@zimbu.org>
parents:
2051
diff
changeset
|
3439 #ifdef USE_FOPEN_NOINH |
7 | 3440 cookie.fp = fopen_noinh_readbin((char *)fname_exp); |
3441 #else | |
3442 cookie.fp = mch_fopen((char *)fname_exp, READBIN); | |
3443 #endif | |
3444 } | |
3445 } | |
3446 | |
3447 if (cookie.fp == NULL) | |
3448 { | |
3449 if (p_verbose > 0) | |
3450 { | |
294 | 3451 verbose_enter(); |
7 | 3452 if (sourcing_name == NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3453 smsg(_("could not source \"%s\""), fname); |
7 | 3454 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3455 smsg(_("line %ld: could not source \"%s\""), |
274 | 3456 sourcing_lnum, fname); |
294 | 3457 verbose_leave(); |
7 | 3458 } |
3459 goto theend; | |
3460 } | |
3461 | |
3462 /* | |
3463 * The file exists. | |
3464 * - In verbose mode, give a message. | |
3465 * - For a vimrc file, may want to set 'compatible', call vimrc_found(). | |
3466 */ | |
3467 if (p_verbose > 1) | |
3468 { | |
294 | 3469 verbose_enter(); |
7 | 3470 if (sourcing_name == NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3471 smsg(_("sourcing \"%s\""), fname); |
7 | 3472 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3473 smsg(_("line %ld: sourcing \"%s\""), |
274 | 3474 sourcing_lnum, fname); |
294 | 3475 verbose_leave(); |
7 | 3476 } |
819 | 3477 if (is_vimrc == DOSO_VIMRC) |
3478 vimrc_found(fname_exp, (char_u *)"MYVIMRC"); | |
3479 else if (is_vimrc == DOSO_GVIMRC) | |
3480 vimrc_found(fname_exp, (char_u *)"MYGVIMRC"); | |
7 | 3481 |
3482 #ifdef USE_CRNL | |
3483 /* If no automatic file format: Set default to CR-NL. */ | |
3484 if (*p_ffs == NUL) | |
3485 cookie.fileformat = EOL_DOS; | |
3486 else | |
3487 cookie.fileformat = EOL_UNKNOWN; | |
3488 cookie.error = FALSE; | |
3489 #endif | |
3490 | |
3491 cookie.nextline = NULL; | |
3492 cookie.finished = FALSE; | |
3493 | |
3494 #ifdef FEAT_EVAL | |
3495 /* | |
3496 * Check if this script has a breakpoint. | |
3497 */ | |
3498 cookie.breakpoint = dbg_find_breakpoint(TRUE, fname_exp, (linenr_T)0); | |
3499 cookie.fname = fname_exp; | |
3500 cookie.dbg_tick = debug_tick; | |
3501 | |
3502 cookie.level = ex_nesting_level; | |
3503 #endif | |
3504 | |
3505 /* | |
3506 * Keep the sourcing name/lnum, for recursive calls. | |
3507 */ | |
3508 save_sourcing_name = sourcing_name; | |
3509 sourcing_name = fname_exp; | |
3510 save_sourcing_lnum = sourcing_lnum; | |
3511 sourcing_lnum = 0; | |
3512 | |
3513 #ifdef STARTUPTIME | |
2053
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3514 if (time_fd != NULL) |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3515 time_push(&tv_rel, &tv_start); |
7 | 3516 #endif |
3517 | |
3518 #ifdef FEAT_EVAL | |
170 | 3519 # ifdef FEAT_PROFILE |
790 | 3520 if (do_profiling == PROF_YES) |
170 | 3521 prof_child_enter(&wait_start); /* entering a child now */ |
3522 # endif | |
3523 | |
3524 /* Don't use local function variables, if called from a function. | |
3525 * Also starts profiling timer for nested script. */ | |
14927
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3526 save_funccal(&funccalp_entry); |
170 | 3527 |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
3528 save_current_sctx = current_sctx; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
3529 current_sctx.sc_lnum = 0; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
3530 current_sctx.sc_version = 1; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
3531 |
15008
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15002
diff
changeset
|
3532 // Check if this script was sourced before to finds its SID. |
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15002
diff
changeset
|
3533 // If it's new, generate a new SID. |
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15002
diff
changeset
|
3534 // Always use a new sequence number. |
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15002
diff
changeset
|
3535 current_sctx.sc_seq = ++last_current_SID_seq; |
7 | 3536 # ifdef UNIX |
3537 stat_ok = (mch_stat((char *)fname_exp, &st) >= 0); | |
3538 # endif | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3539 for (current_sctx.sc_sid = script_items.ga_len; current_sctx.sc_sid > 0; |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3540 --current_sctx.sc_sid) |
170 | 3541 { |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3542 si = &SCRIPT_ITEM(current_sctx.sc_sid); |
170 | 3543 if (si->sn_name != NULL |
7 | 3544 && ( |
3545 # ifdef UNIX | |
161 | 3546 /* Compare dev/ino when possible, it catches symbolic |
3547 * links. Also compare file names, the inode may change | |
3548 * when the file was edited. */ | |
1882 | 3549 ((stat_ok && si->sn_dev_valid) |
170 | 3550 && (si->sn_dev == st.st_dev |
3551 && si->sn_ino == st.st_ino)) || | |
7 | 3552 # endif |
170 | 3553 fnamecmp(si->sn_name, fname_exp) == 0)) |
7 | 3554 break; |
170 | 3555 } |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3556 if (current_sctx.sc_sid == 0) |
7 | 3557 { |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3558 current_sctx.sc_sid = ++last_current_SID; |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3559 if (ga_grow(&script_items, |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3560 (int)(current_sctx.sc_sid - script_items.ga_len)) == FAIL) |
170 | 3561 goto almosttheend; |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3562 while (script_items.ga_len < current_sctx.sc_sid) |
7 | 3563 { |
170 | 3564 ++script_items.ga_len; |
3565 SCRIPT_ITEM(script_items.ga_len).sn_name = NULL; | |
3566 # ifdef FEAT_PROFILE | |
3567 SCRIPT_ITEM(script_items.ga_len).sn_prof_on = FALSE; | |
3568 # endif | |
3569 } | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3570 si = &SCRIPT_ITEM(current_sctx.sc_sid); |
170 | 3571 si->sn_name = fname_exp; |
15448
4880dc2ccc3f
patch 8.1.0732: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
3572 fname_exp = vim_strsave(si->sn_name); // used for autocmd |
7 | 3573 # ifdef UNIX |
170 | 3574 if (stat_ok) |
3575 { | |
1882 | 3576 si->sn_dev_valid = TRUE; |
170 | 3577 si->sn_dev = st.st_dev; |
3578 si->sn_ino = st.st_ino; | |
3579 } | |
3580 else | |
1882 | 3581 si->sn_dev_valid = FALSE; |
7 | 3582 # endif |
170 | 3583 |
7 | 3584 /* Allocate the local script variables to use for this script. */ |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3585 new_script_vars(current_sctx.sc_sid); |
7 | 3586 } |
3587 | |
170 | 3588 # ifdef FEAT_PROFILE |
790 | 3589 if (do_profiling == PROF_YES) |
170 | 3590 { |
3591 int forceit; | |
3592 | |
3593 /* Check if we do profiling for this script. */ | |
3594 if (!si->sn_prof_on && has_profiling(TRUE, si->sn_name, &forceit)) | |
3595 { | |
3596 script_do_profile(si); | |
3597 si->sn_pr_force = forceit; | |
3598 } | |
3599 if (si->sn_prof_on) | |
3600 { | |
3601 ++si->sn_pr_count; | |
3602 profile_start(&si->sn_pr_start); | |
3603 profile_zero(&si->sn_pr_children); | |
3604 } | |
3605 } | |
3606 # endif | |
7 | 3607 #endif |
3608 | |
12658
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3609 cookie.conv.vc_type = CONV_NONE; /* no conversion */ |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3610 |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3611 /* Read the first line so we can check for a UTF-8 BOM. */ |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3612 firstline = getsourceline(0, (void *)&cookie, 0); |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3613 if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3614 && firstline[1] == 0xbb && firstline[2] == 0xbf) |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3615 { |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3616 /* Found BOM; setup conversion, skip over BOM and recode the line. */ |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3617 convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc); |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3618 p = string_convert(&cookie.conv, firstline + 3, NULL); |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3619 if (p == NULL) |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3620 p = vim_strsave(firstline + 3); |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3621 if (p != NULL) |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3622 { |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3623 vim_free(firstline); |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3624 firstline = p; |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3625 } |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3626 } |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
3627 |
7 | 3628 /* |
3629 * Call do_cmdline, which will call getsourceline() to get the lines. | |
3630 */ | |
1802 | 3631 do_cmdline(firstline, getsourceline, (void *)&cookie, |
7 | 3632 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); |
3633 retval = OK; | |
170 | 3634 |
3635 #ifdef FEAT_PROFILE | |
790 | 3636 if (do_profiling == PROF_YES) |
170 | 3637 { |
3638 /* Get "si" again, "script_items" may have been reallocated. */ | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3639 si = &SCRIPT_ITEM(current_sctx.sc_sid); |
170 | 3640 if (si->sn_prof_on) |
3641 { | |
3642 profile_end(&si->sn_pr_start); | |
3643 profile_sub_wait(&wait_start, &si->sn_pr_start); | |
3644 profile_add(&si->sn_pr_total, &si->sn_pr_start); | |
720 | 3645 profile_self(&si->sn_pr_self, &si->sn_pr_start, |
3646 &si->sn_pr_children); | |
170 | 3647 } |
3648 } | |
7 | 3649 #endif |
3650 | |
3651 if (got_int) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3652 emsg(_(e_interr)); |
7 | 3653 sourcing_name = save_sourcing_name; |
3654 sourcing_lnum = save_sourcing_lnum; | |
3655 if (p_verbose > 1) | |
3656 { | |
294 | 3657 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3658 smsg(_("finished sourcing %s"), fname); |
7 | 3659 if (sourcing_name != NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3660 smsg(_("continuing in %s"), sourcing_name); |
294 | 3661 verbose_leave(); |
7 | 3662 } |
3663 #ifdef STARTUPTIME | |
2053
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3664 if (time_fd != NULL) |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3665 { |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3666 vim_snprintf((char *)IObuff, IOSIZE, "sourcing %s", fname); |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3667 time_msg((char *)IObuff, &tv_start); |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3668 time_pop(&tv_rel); |
94f44da44d2e
updated for version 7.2.339
Bram Moolenaar <bram@zimbu.org>
parents:
2052
diff
changeset
|
3669 } |
7 | 3670 #endif |
3671 | |
15442
3e2e1608efa4
patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
15286
diff
changeset
|
3672 if (!got_int) |
3e2e1608efa4
patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
15286
diff
changeset
|
3673 trigger_source_post = TRUE; |
3e2e1608efa4
patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
15286
diff
changeset
|
3674 |
7 | 3675 #ifdef FEAT_EVAL |
3676 /* | |
3677 * After a "finish" in debug mode, need to break at first command of next | |
3678 * sourced file. | |
3679 */ | |
3680 if (save_debug_break_level > ex_nesting_level | |
3681 && debug_break_level == ex_nesting_level) | |
3682 ++debug_break_level; | |
3683 #endif | |
3684 | |
170 | 3685 #ifdef FEAT_EVAL |
3686 almosttheend: | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
3687 current_sctx = save_current_sctx; |
14927
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3688 restore_funccal(); |
170 | 3689 # ifdef FEAT_PROFILE |
790 | 3690 if (do_profiling == PROF_YES) |
170 | 3691 prof_child_exit(&wait_start); /* leaving a child now */ |
3692 # endif | |
3693 #endif | |
3694 fclose(cookie.fp); | |
3695 vim_free(cookie.nextline); | |
1802 | 3696 vim_free(firstline); |
170 | 3697 convert_setup(&cookie.conv, NULL, NULL); |
3698 | |
15442
3e2e1608efa4
patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
15286
diff
changeset
|
3699 if (trigger_source_post) |
15448
4880dc2ccc3f
patch 8.1.0732: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
3700 apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp, FALSE, curbuf); |
15442
3e2e1608efa4
patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
15286
diff
changeset
|
3701 |
7 | 3702 theend: |
3703 vim_free(fname_exp); | |
3704 return retval; | |
3705 } | |
3706 | |
3707 #if defined(FEAT_EVAL) || defined(PROTO) | |
356 | 3708 |
7 | 3709 /* |
3710 * ":scriptnames" | |
3711 */ | |
3712 void | |
15085
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3713 ex_scriptnames(exarg_T *eap) |
7 | 3714 { |
3715 int i; | |
3716 | |
15085
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3717 if (eap->addr_count > 0) |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3718 { |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3719 // :script {scriptId}: edit the script |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3720 if (eap->line2 < 1 || eap->line2 > script_items.ga_len) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3721 emsg(_(e_invarg)); |
15085
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3722 else |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3723 { |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3724 eap->arg = SCRIPT_ITEM(eap->line2).sn_name; |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3725 do_exedit(eap, NULL); |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3726 } |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3727 return; |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3728 } |
1783c0b6bc2e
patch 8.1.0553: it is not easy to edit a script that was sourced
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
3729 |
170 | 3730 for (i = 1; i <= script_items.ga_len && !got_int; ++i) |
3731 if (SCRIPT_ITEM(i).sn_name != NULL) | |
2921 | 3732 { |
3733 home_replace(NULL, SCRIPT_ITEM(i).sn_name, | |
3734 NameBuff, MAXPATHL, TRUE); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3735 smsg("%3d: %s", i, NameBuff); |
3429 | 3736 } |
7 | 3737 } |
3738 | |
3739 # if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) | |
3740 /* | |
3741 * Fix slashes in the list of script names for 'shellslash'. | |
3742 */ | |
3743 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3744 scriptnames_slash_adjust(void) |
7 | 3745 { |
3746 int i; | |
3747 | |
170 | 3748 for (i = 1; i <= script_items.ga_len; ++i) |
3749 if (SCRIPT_ITEM(i).sn_name != NULL) | |
3750 slash_adjust(SCRIPT_ITEM(i).sn_name); | |
7 | 3751 } |
3752 # endif | |
3753 | |
3754 /* | |
3755 * Get a pointer to a script name. Used for ":verbose set". | |
3756 */ | |
3757 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3758 get_scriptname(scid_T id) |
7 | 3759 { |
3760 if (id == SID_MODELINE) | |
681 | 3761 return (char_u *)_("modeline"); |
7 | 3762 if (id == SID_CMDARG) |
681 | 3763 return (char_u *)_("--cmd argument"); |
7 | 3764 if (id == SID_CARG) |
681 | 3765 return (char_u *)_("-c argument"); |
7 | 3766 if (id == SID_ENV) |
681 | 3767 return (char_u *)_("environment variable"); |
3768 if (id == SID_ERROR) | |
3769 return (char_u *)_("error handler"); | |
170 | 3770 return SCRIPT_ITEM(id).sn_name; |
3771 } | |
3772 | |
356 | 3773 # if defined(EXITFREE) || defined(PROTO) |
3774 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3775 free_scriptnames(void) |
356 | 3776 { |
3777 int i; | |
3778 | |
3779 for (i = script_items.ga_len; i > 0; --i) | |
3780 vim_free(SCRIPT_ITEM(i).sn_name); | |
3781 ga_clear(&script_items); | |
3782 } | |
3783 # endif | |
3784 | |
7 | 3785 #endif |
3786 | |
3787 /* | |
3788 * Get one full line from a sourced file. | |
3789 * Called by do_cmdline() when it's called from do_source(). | |
3790 * | |
3791 * Return a pointer to the line in allocated memory. | |
3792 * Return NULL for end-of-file or some error. | |
3793 */ | |
3794 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3795 getsourceline(int c UNUSED, void *cookie, int indent UNUSED) |
7 | 3796 { |
3797 struct source_cookie *sp = (struct source_cookie *)cookie; | |
3798 char_u *line; | |
3336 | 3799 char_u *p; |
7 | 3800 |
3801 #ifdef FEAT_EVAL | |
3802 /* If breakpoints have been added/deleted need to check for it. */ | |
3803 if (sp->dbg_tick < debug_tick) | |
3804 { | |
3805 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum); | |
3806 sp->dbg_tick = debug_tick; | |
3807 } | |
170 | 3808 # ifdef FEAT_PROFILE |
790 | 3809 if (do_profiling == PROF_YES) |
170 | 3810 script_line_end(); |
3811 # endif | |
7 | 3812 #endif |
3813 /* | |
3814 * Get current line. If there is a read-ahead line, use it, otherwise get | |
3815 * one now. | |
3816 */ | |
3817 if (sp->finished) | |
3818 line = NULL; | |
3819 else if (sp->nextline == NULL) | |
3820 line = get_one_sourceline(sp); | |
3821 else | |
3822 { | |
3823 line = sp->nextline; | |
3824 sp->nextline = NULL; | |
3825 ++sourcing_lnum; | |
205 | 3826 } |
170 | 3827 #ifdef FEAT_PROFILE |
790 | 3828 if (line != NULL && do_profiling == PROF_YES) |
205 | 3829 script_line_start(); |
3830 #endif | |
7 | 3831 |
3832 /* Only concatenate lines starting with a \ when 'cpoptions' doesn't | |
3833 * contain the 'C' flag. */ | |
3834 if (line != NULL && (vim_strchr(p_cpo, CPO_CONCAT) == NULL)) | |
3835 { | |
3836 /* compensate for the one line read-ahead */ | |
3837 --sourcing_lnum; | |
3332 | 3838 |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3839 // Get the next line and concatenate it when it starts with a |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3840 // backslash. We always need to read the next line, keep it in |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3841 // sp->nextline. |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3842 /* Also check for a comment in between continuation lines: "\ */ |
3332 | 3843 sp->nextline = get_one_sourceline(sp); |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3844 if (sp->nextline != NULL |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3845 && (*(p = skipwhite(sp->nextline)) == '\\' |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3846 || (p[0] == '"' && p[1] == '\\' && p[2] == ' '))) |
7 | 3847 { |
3332 | 3848 garray_T ga; |
3849 | |
3378 | 3850 ga_init2(&ga, (int)sizeof(char_u), 400); |
3332 | 3851 ga_concat(&ga, line); |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3852 if (*p == '\\') |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3853 ga_concat(&ga, p + 1); |
3332 | 3854 for (;;) |
3855 { | |
3856 vim_free(sp->nextline); | |
3857 sp->nextline = get_one_sourceline(sp); | |
3858 if (sp->nextline == NULL) | |
3859 break; | |
3860 p = skipwhite(sp->nextline); | |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3861 if (*p == '\\') |
3378 | 3862 { |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3863 // Adjust the growsize to the current length to speed up |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3864 // concatenating many lines. |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3865 if (ga.ga_len > 400) |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3866 { |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3867 if (ga.ga_len > 8000) |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3868 ga.ga_growsize = 8000; |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3869 else |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3870 ga.ga_growsize = ga.ga_len; |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3871 } |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3872 ga_concat(&ga, p + 1); |
3378 | 3873 } |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3874 else if (p[0] != '"' || p[1] != '\\' || p[2] != ' ') |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3875 break; |
3332 | 3876 } |
3877 ga_append(&ga, NUL); | |
7 | 3878 vim_free(line); |
3332 | 3879 line = ga.ga_data; |
7 | 3880 } |
3881 } | |
3882 | |
3883 if (line != NULL && sp->conv.vc_type != CONV_NONE) | |
3884 { | |
3336 | 3885 char_u *s; |
3886 | |
7 | 3887 /* Convert the encoding of the script line. */ |
3888 s = string_convert(&sp->conv, line, NULL); | |
3889 if (s != NULL) | |
3890 { | |
3891 vim_free(line); | |
3892 line = s; | |
3893 } | |
3894 } | |
3895 | |
3896 #ifdef FEAT_EVAL | |
3897 /* Did we encounter a breakpoint? */ | |
3898 if (sp->breakpoint != 0 && sp->breakpoint <= sourcing_lnum) | |
3899 { | |
3900 dbg_breakpoint(sp->fname, sourcing_lnum); | |
3901 /* Find next breakpoint. */ | |
3902 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum); | |
3903 sp->dbg_tick = debug_tick; | |
3904 } | |
3905 #endif | |
3906 | |
3907 return line; | |
3908 } | |
3909 | |
3910 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3911 get_one_sourceline(struct source_cookie *sp) |
7 | 3912 { |
3913 garray_T ga; | |
3914 int len; | |
3915 int c; | |
3916 char_u *buf; | |
3917 #ifdef USE_CRNL | |
3918 int has_cr; /* CR-LF found */ | |
3919 #endif | |
3920 int have_read = FALSE; | |
3921 | |
3922 /* use a growarray to store the sourced line */ | |
154 | 3923 ga_init2(&ga, 1, 250); |
7 | 3924 |
3925 /* | |
3926 * Loop until there is a finished line (or end-of-file). | |
3927 */ | |
3928 sourcing_lnum++; | |
3929 for (;;) | |
3930 { | |
154 | 3931 /* make room to read at least 120 (more) characters */ |
3932 if (ga_grow(&ga, 120) == FAIL) | |
7 | 3933 break; |
3934 buf = (char_u *)ga.ga_data; | |
3935 | |
15840
734b1928a5aa
patch 8.1.0927: USE_CR is never defined
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3936 if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len, |
41 | 3937 sp->fp) == NULL) |
15840
734b1928a5aa
patch 8.1.0927: USE_CR is never defined
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3938 break; |
154 | 3939 len = ga.ga_len + (int)STRLEN(buf + ga.ga_len); |
7 | 3940 #ifdef USE_CRNL |
3941 /* Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the | |
3942 * CTRL-Z by its own, or after a NL. */ | |
3943 if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n')) | |
3944 && sp->fileformat == EOL_DOS | |
3945 && buf[len - 1] == Ctrl_Z) | |
3946 { | |
3947 buf[len - 1] = NUL; | |
3948 break; | |
3949 } | |
3950 #endif | |
3951 | |
3952 have_read = TRUE; | |
3953 ga.ga_len = len; | |
3954 | |
3955 /* If the line was longer than the buffer, read more. */ | |
41 | 3956 if (ga.ga_maxlen - ga.ga_len == 1 && buf[len - 1] != '\n') |
7 | 3957 continue; |
3958 | |
3959 if (len >= 1 && buf[len - 1] == '\n') /* remove trailing NL */ | |
3960 { | |
3961 #ifdef USE_CRNL | |
3962 has_cr = (len >= 2 && buf[len - 2] == '\r'); | |
3963 if (sp->fileformat == EOL_UNKNOWN) | |
3964 { | |
3965 if (has_cr) | |
3966 sp->fileformat = EOL_DOS; | |
3967 else | |
3968 sp->fileformat = EOL_UNIX; | |
3969 } | |
3970 | |
3971 if (sp->fileformat == EOL_DOS) | |
3972 { | |
3973 if (has_cr) /* replace trailing CR */ | |
3974 { | |
3975 buf[len - 2] = '\n'; | |
3976 --len; | |
3977 --ga.ga_len; | |
3978 } | |
3979 else /* lines like ":map xx yy^M" will have failed */ | |
3980 { | |
3981 if (!sp->error) | |
16 | 3982 { |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3983 msg_source(HL_ATTR(HLF_W)); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
3984 emsg(_("W15: Warning: Wrong line separator, ^M may be missing")); |
16 | 3985 } |
7 | 3986 sp->error = TRUE; |
3987 sp->fileformat = EOL_UNIX; | |
3988 } | |
3989 } | |
3990 #endif | |
3991 /* The '\n' is escaped if there is an odd number of ^V's just | |
3992 * before it, first set "c" just before the 'V's and then check | |
3993 * len&c parities (is faster than ((len-c)%2 == 0)) -- Acevedo */ | |
3994 for (c = len - 2; c >= 0 && buf[c] == Ctrl_V; c--) | |
3995 ; | |
3996 if ((len & 1) != (c & 1)) /* escaped NL, read more */ | |
3997 { | |
3998 sourcing_lnum++; | |
3999 continue; | |
4000 } | |
4001 | |
4002 buf[len - 1] = NUL; /* remove the NL */ | |
4003 } | |
4004 | |
4005 /* | |
4006 * Check for ^C here now and then, so recursive :so can be broken. | |
4007 */ | |
4008 line_breakcheck(); | |
4009 break; | |
4010 } | |
4011 | |
4012 if (have_read) | |
4013 return (char_u *)ga.ga_data; | |
4014 | |
4015 vim_free(ga.ga_data); | |
4016 return NULL; | |
4017 } | |
4018 | |
170 | 4019 #if defined(FEAT_PROFILE) || defined(PROTO) |
4020 /* | |
4021 * Called when starting to read a script line. | |
4022 * "sourcing_lnum" must be correct! | |
4023 * When skipping lines it may not actually be executed, but we won't find out | |
4024 * until later and we need to store the time now. | |
4025 */ | |
4026 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4027 script_line_start(void) |
170 | 4028 { |
4029 scriptitem_T *si; | |
4030 sn_prl_T *pp; | |
4031 | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
4032 if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) |
170 | 4033 return; |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
4034 si = &SCRIPT_ITEM(current_sctx.sc_sid); |
170 | 4035 if (si->sn_prof_on && sourcing_lnum >= 1) |
4036 { | |
1624 | 4037 /* Grow the array before starting the timer, so that the time spent |
170 | 4038 * here isn't counted. */ |
12658
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
4039 (void)ga_grow(&si->sn_prl_ga, |
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
4040 (int)(sourcing_lnum - si->sn_prl_ga.ga_len)); |
170 | 4041 si->sn_prl_idx = sourcing_lnum - 1; |
4042 while (si->sn_prl_ga.ga_len <= si->sn_prl_idx | |
4043 && si->sn_prl_ga.ga_len < si->sn_prl_ga.ga_maxlen) | |
4044 { | |
4045 /* Zero counters for a line that was not used before. */ | |
4046 pp = &PRL_ITEM(si, si->sn_prl_ga.ga_len); | |
4047 pp->snp_count = 0; | |
4048 profile_zero(&pp->sn_prl_total); | |
4049 profile_zero(&pp->sn_prl_self); | |
4050 ++si->sn_prl_ga.ga_len; | |
4051 } | |
4052 si->sn_prl_execed = FALSE; | |
4053 profile_start(&si->sn_prl_start); | |
4054 profile_zero(&si->sn_prl_children); | |
4055 profile_get_wait(&si->sn_prl_wait); | |
4056 } | |
4057 } | |
4058 | |
4059 /* | |
4060 * Called when actually executing a function line. | |
4061 */ | |
4062 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4063 script_line_exec(void) |
170 | 4064 { |
4065 scriptitem_T *si; | |
4066 | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
4067 if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) |
170 | 4068 return; |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
4069 si = &SCRIPT_ITEM(current_sctx.sc_sid); |
170 | 4070 if (si->sn_prof_on && si->sn_prl_idx >= 0) |
4071 si->sn_prl_execed = TRUE; | |
4072 } | |
4073 | |
4074 /* | |
12658
20aacdca367d
patch 8.0.1207: profiling skips the first and last script line
Christian Brabandt <cb@256bit.org>
parents:
12495
diff
changeset
|
4075 * Called when done with a script line. |
170 | 4076 */ |
4077 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4078 script_line_end(void) |
170 | 4079 { |
4080 scriptitem_T *si; | |
4081 sn_prl_T *pp; | |
4082 | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
4083 if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) |
170 | 4084 return; |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14681
diff
changeset
|
4085 si = &SCRIPT_ITEM(current_sctx.sc_sid); |
170 | 4086 if (si->sn_prof_on && si->sn_prl_idx >= 0 |
4087 && si->sn_prl_idx < si->sn_prl_ga.ga_len) | |
4088 { | |
4089 if (si->sn_prl_execed) | |
4090 { | |
4091 pp = &PRL_ITEM(si, si->sn_prl_idx); | |
4092 ++pp->snp_count; | |
4093 profile_end(&si->sn_prl_start); | |
4094 profile_sub_wait(&si->sn_prl_wait, &si->sn_prl_start); | |
4095 profile_add(&pp->sn_prl_total, &si->sn_prl_start); | |
720 | 4096 profile_self(&pp->sn_prl_self, &si->sn_prl_start, |
4097 &si->sn_prl_children); | |
170 | 4098 } |
4099 si->sn_prl_idx = -1; | |
4100 } | |
4101 } | |
4102 #endif | |
4103 | |
7 | 4104 /* |
4105 * ":scriptencoding": Set encoding conversion for a sourced script. | |
4106 */ | |
4107 void | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4108 ex_scriptencoding(exarg_T *eap) |
7 | 4109 { |
4110 struct source_cookie *sp; | |
4111 char_u *name; | |
4112 | |
4113 if (!getline_equal(eap->getline, eap->cookie, getsourceline)) | |
4114 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
4115 emsg(_("E167: :scriptencoding used outside of a sourced file")); |
7 | 4116 return; |
4117 } | |
4118 | |
4119 if (*eap->arg != NUL) | |
4120 { | |
4121 name = enc_canonize(eap->arg); | |
4122 if (name == NULL) /* out of memory */ | |
4123 return; | |
4124 } | |
4125 else | |
4126 name = eap->arg; | |
4127 | |
4128 /* Setup for conversion from the specified encoding to 'encoding'. */ | |
4129 sp = (struct source_cookie *)getline_cookie(eap->getline, eap->cookie); | |
4130 convert_setup(&sp->conv, name, p_enc); | |
4131 | |
4132 if (name != eap->arg) | |
4133 vim_free(name); | |
4134 } | |
4135 | |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4136 /* |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4137 * ":scriptversion": Set Vim script version for a sourced script. |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4138 */ |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4139 void |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4140 ex_scriptversion(exarg_T *eap UNUSED) |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4141 { |
16225
9cbc5ff516ee
patch 8.1.1117: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
16223
diff
changeset
|
4142 #ifdef FEAT_EVAL |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4143 int nr; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4144 |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4145 if (!getline_equal(eap->getline, eap->cookie, getsourceline)) |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4146 { |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4147 emsg(_("E984: :scriptversion used outside of a sourced file")); |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4148 return; |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4149 } |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4150 |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4151 nr = getdigits(&eap->arg); |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4152 if (nr == 0 || *eap->arg != NUL) |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4153 emsg(_(e_invarg)); |
16366
6ee80f3b5ea9
patch 8.1.1188: not all Vim variables require the v: prefix
Bram Moolenaar <Bram@vim.org>
parents:
16225
diff
changeset
|
4154 else if (nr > 3) |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4155 semsg(_("E999: scriptversion not supported: %d"), nr); |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4156 else |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4157 current_sctx.sc_version = nr; |
16225
9cbc5ff516ee
patch 8.1.1117: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
16223
diff
changeset
|
4158 #endif |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4159 } |
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
4160 |
7 | 4161 #if defined(FEAT_EVAL) || defined(PROTO) |
4162 /* | |
4163 * ":finish": Mark a sourced file as finished. | |
4164 */ | |
4165 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4166 ex_finish(exarg_T *eap) |
7 | 4167 { |
4168 if (getline_equal(eap->getline, eap->cookie, getsourceline)) | |
4169 do_finish(eap, FALSE); | |
4170 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
4171 emsg(_("E168: :finish used outside of a sourced file")); |
7 | 4172 } |
4173 | |
4174 /* | |
4175 * Mark a sourced file as finished. Possibly makes the ":finish" pending. | |
4176 * Also called for a pending finish at the ":endtry" or after returning from | |
4177 * an extra do_cmdline(). "reanimate" is used in the latter case. | |
4178 */ | |
4179 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4180 do_finish(exarg_T *eap, int reanimate) |
7 | 4181 { |
4182 int idx; | |
4183 | |
4184 if (reanimate) | |
4185 ((struct source_cookie *)getline_cookie(eap->getline, | |
4186 eap->cookie))->finished = FALSE; | |
4187 | |
4188 /* | |
4189 * Cleanup (and inactivate) conditionals, but stop when a try conditional | |
4190 * not in its finally clause (which then is to be executed next) is found. | |
4191 * In this case, make the ":finish" pending for execution at the ":endtry". | |
4192 * Otherwise, finish normally. | |
4193 */ | |
4194 idx = cleanup_conditionals(eap->cstack, 0, TRUE); | |
4195 if (idx >= 0) | |
4196 { | |
4197 eap->cstack->cs_pending[idx] = CSTP_FINISH; | |
4198 report_make_pending(CSTP_FINISH, NULL); | |
4199 } | |
4200 else | |
4201 ((struct source_cookie *)getline_cookie(eap->getline, | |
4202 eap->cookie))->finished = TRUE; | |
4203 } | |
4204 | |
4205 | |
4206 /* | |
4207 * Return TRUE when a sourced file had the ":finish" command: Don't give error | |
4208 * message for missing ":endif". | |
4209 * Return FALSE when not sourcing a file. | |
4210 */ | |
4211 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4212 source_finished( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4213 char_u *(*fgetline)(int, void *, int), |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4214 void *cookie) |
7 | 4215 { |
944 | 4216 return (getline_equal(fgetline, cookie, getsourceline) |
7 | 4217 && ((struct source_cookie *)getline_cookie( |
944 | 4218 fgetline, cookie))->finished); |
7 | 4219 } |
4220 #endif | |
4221 | |
4222 /* | |
4223 * ":checktime [buffer]" | |
4224 */ | |
4225 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4226 ex_checktime(exarg_T *eap) |
7 | 4227 { |
4228 buf_T *buf; | |
4229 int save_no_check_timestamps = no_check_timestamps; | |
4230 | |
4231 no_check_timestamps = 0; | |
4232 if (eap->addr_count == 0) /* default is all buffers */ | |
4233 check_timestamps(FALSE); | |
4234 else | |
4235 { | |
4236 buf = buflist_findnr((int)eap->line2); | |
4237 if (buf != NULL) /* cannot happen? */ | |
4238 (void)buf_check_timestamp(buf, FALSE); | |
4239 } | |
4240 no_check_timestamps = save_no_check_timestamps; | |
4241 } | |
4242 | |
4243 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
4244 && (defined(FEAT_EVAL) || defined(FEAT_MULTI_LANG)) | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4245 # define HAVE_GET_LOCALE_VAL |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4246 static char_u * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4247 get_locale_val(int what) |
7 | 4248 { |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4249 char_u *loc; |
7 | 4250 |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8206
diff
changeset
|
4251 /* Obtain the locale value from the libraries. */ |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4252 loc = (char_u *)setlocale(what, NULL); |
7 | 4253 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
4254 # ifdef MSWIN |
7 | 4255 if (loc != NULL) |
4256 { | |
4257 char_u *p; | |
4258 | |
823 | 4259 /* setocale() returns something like "LC_COLLATE=<name>;LC_..." when |
4260 * one of the values (e.g., LC_CTYPE) differs. */ | |
7 | 4261 p = vim_strchr(loc, '='); |
4262 if (p != NULL) | |
4263 { | |
4264 loc = ++p; | |
4265 while (*p != NUL) /* remove trailing newline */ | |
4266 { | |
823 | 4267 if (*p < ' ' || *p == ';') |
7 | 4268 { |
4269 *p = NUL; | |
4270 break; | |
4271 } | |
4272 ++p; | |
4273 } | |
4274 } | |
4275 } | |
4276 # endif | |
4277 | |
4278 return loc; | |
4279 } | |
4280 #endif | |
4281 | |
4282 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
4283 #ifdef MSWIN |
7 | 4284 /* |
4285 * On MS-Windows locale names are strings like "German_Germany.1252", but | |
4286 * gettext expects "de". Try to translate one into another here for a few | |
4287 * supported languages. | |
4288 */ | |
4289 static char_u * | |
4290 gettext_lang(char_u *name) | |
4291 { | |
4292 int i; | |
4293 static char *(mtable[]) = { | |
4294 "afrikaans", "af", | |
4295 "czech", "cs", | |
4296 "dutch", "nl", | |
4297 "german", "de", | |
4298 "english_united kingdom", "en_GB", | |
4299 "spanish", "es", | |
4300 "french", "fr", | |
4301 "italian", "it", | |
4302 "japanese", "ja", | |
4303 "korean", "ko", | |
4304 "norwegian", "no", | |
4305 "polish", "pl", | |
4306 "russian", "ru", | |
4307 "slovak", "sk", | |
4308 "swedish", "sv", | |
4309 "ukrainian", "uk", | |
4310 "chinese_china", "zh_CN", | |
4311 "chinese_taiwan", "zh_TW", | |
4312 NULL}; | |
4313 | |
4314 for (i = 0; mtable[i] != NULL; i += 2) | |
4315 if (STRNICMP(mtable[i], name, STRLEN(mtable[i])) == 0) | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4316 return (char_u *)mtable[i + 1]; |
7 | 4317 return name; |
4318 } | |
4319 #endif | |
4320 | |
4321 #if defined(FEAT_MULTI_LANG) || defined(PROTO) | |
4322 /* | |
15002
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4323 * Return TRUE when "lang" starts with a valid language name. |
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4324 * Rejects NULL, empty string, "C", "C.UTF-8" and others. |
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4325 */ |
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4326 static int |
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4327 is_valid_mess_lang(char_u *lang) |
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4328 { |
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4329 return lang != NULL && ASCII_ISALPHA(lang[0]) && ASCII_ISALPHA(lang[1]); |
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4330 } |
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4331 |
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4332 /* |
7 | 4333 * Obtain the current messages language. Used to set the default for |
4334 * 'helplang'. May return NULL or an empty string. | |
4335 */ | |
4336 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4337 get_mess_lang(void) |
7 | 4338 { |
4339 char_u *p; | |
4340 | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4341 # ifdef HAVE_GET_LOCALE_VAL |
7 | 4342 # if defined(LC_MESSAGES) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4343 p = get_locale_val(LC_MESSAGES); |
7 | 4344 # else |
4345 /* This is necessary for Win32, where LC_MESSAGES is not defined and $LANG | |
823 | 4346 * may be set to the LCID number. LC_COLLATE is the best guess, LC_TIME |
4347 * and LC_MONETARY may be set differently for a Japanese working in the | |
4348 * US. */ | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4349 p = get_locale_val(LC_COLLATE); |
7 | 4350 # endif |
4351 # else | |
4352 p = mch_getenv((char_u *)"LC_ALL"); | |
15002
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4353 if (!is_valid_mess_lang(p)) |
7 | 4354 { |
4355 p = mch_getenv((char_u *)"LC_MESSAGES"); | |
15002
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4356 if (!is_valid_mess_lang(p)) |
7 | 4357 p = mch_getenv((char_u *)"LANG"); |
4358 } | |
4359 # endif | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
4360 # ifdef MSWIN |
7 | 4361 p = gettext_lang(p); |
4362 # endif | |
15002
9ae60773dd03
patch 8.1.0512: 'helplang' default is inconsistent for C and C.UTF-8
Bram Moolenaar <Bram@vim.org>
parents:
14927
diff
changeset
|
4363 return is_valid_mess_lang(p) ? p : NULL; |
7 | 4364 } |
4365 #endif | |
4366 | |
45 | 4367 /* Complicated #if; matches with where get_mess_env() is used below. */ |
4368 #if (defined(FEAT_EVAL) && !((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
4369 && defined(LC_MESSAGES))) \ | |
4370 || ((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
4371 && !defined(LC_MESSAGES)) | |
7 | 4372 /* |
4373 * Get the language used for messages from the environment. | |
4374 */ | |
4375 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4376 get_mess_env(void) |
7 | 4377 { |
4378 char_u *p; | |
4379 | |
4380 p = mch_getenv((char_u *)"LC_ALL"); | |
4381 if (p == NULL || *p == NUL) | |
4382 { | |
4383 p = mch_getenv((char_u *)"LC_MESSAGES"); | |
4384 if (p == NULL || *p == NUL) | |
4385 { | |
4386 p = mch_getenv((char_u *)"LANG"); | |
4387 if (p != NULL && VIM_ISDIGIT(*p)) | |
4388 p = NULL; /* ignore something like "1043" */ | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4389 # ifdef HAVE_GET_LOCALE_VAL |
7 | 4390 if (p == NULL || *p == NUL) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4391 p = get_locale_val(LC_CTYPE); |
7 | 4392 # endif |
4393 } | |
4394 } | |
4395 return p; | |
4396 } | |
4397 #endif | |
4398 | |
4399 #if defined(FEAT_EVAL) || defined(PROTO) | |
4400 | |
4401 /* | |
4402 * Set the "v:lang" variable according to the current locale setting. | |
4403 * Also do "v:lc_time"and "v:ctype". | |
4404 */ | |
4405 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4406 set_lang_var(void) |
7 | 4407 { |
4408 char_u *loc; | |
4409 | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4410 # ifdef HAVE_GET_LOCALE_VAL |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4411 loc = get_locale_val(LC_CTYPE); |
7 | 4412 # else |
4413 /* setlocale() not supported: use the default value */ | |
4414 loc = (char_u *)"C"; | |
4415 # endif | |
4416 set_vim_var_string(VV_CTYPE, loc, -1); | |
4417 | |
4418 /* When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall | |
4419 * back to LC_CTYPE if it's empty. */ | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4420 # if defined(HAVE_GET_LOCALE_VAL) && defined(LC_MESSAGES) |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4421 loc = get_locale_val(LC_MESSAGES); |
7 | 4422 # else |
4423 loc = get_mess_env(); | |
4424 # endif | |
4425 set_vim_var_string(VV_LANG, loc, -1); | |
4426 | |
2419
f579b934f51d
Fix build warnings and problems for tiny/small Win32 build. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4427 # ifdef HAVE_GET_LOCALE_VAL |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7979
diff
changeset
|
4428 loc = get_locale_val(LC_TIME); |
7 | 4429 # endif |
4430 set_vim_var_string(VV_LC_TIME, loc, -1); | |
4431 } | |
4432 #endif | |
4433 | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15595
diff
changeset
|
4434 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) \ |
7 | 4435 /* |
4436 * ":language": Set the language (locale). | |
4437 */ | |
4438 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4439 ex_language(exarg_T *eap) |
7 | 4440 { |
4441 char *loc; | |
4442 char_u *p; | |
4443 char_u *name; | |
4444 int what = LC_ALL; | |
4445 char *whatstr = ""; | |
4446 #ifdef LC_MESSAGES | |
4447 # define VIM_LC_MESSAGES LC_MESSAGES | |
4448 #else | |
4449 # define VIM_LC_MESSAGES 6789 | |
4450 #endif | |
4451 | |
4452 name = eap->arg; | |
4453 | |
4454 /* Check for "messages {name}", "ctype {name}" or "time {name}" argument. | |
4455 * Allow abbreviation, but require at least 3 characters to avoid | |
4456 * confusion with a two letter language name "me" or "ct". */ | |
4457 p = skiptowhite(eap->arg); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4458 if ((*p == NUL || VIM_ISWHITE(*p)) && p - eap->arg >= 3) |
7 | 4459 { |
4460 if (STRNICMP(eap->arg, "messages", p - eap->arg) == 0) | |
4461 { | |
4462 what = VIM_LC_MESSAGES; | |
4463 name = skipwhite(p); | |
4464 whatstr = "messages "; | |
4465 } | |
4466 else if (STRNICMP(eap->arg, "ctype", p - eap->arg) == 0) | |
4467 { | |
4468 what = LC_CTYPE; | |
4469 name = skipwhite(p); | |
4470 whatstr = "ctype "; | |
4471 } | |
4472 else if (STRNICMP(eap->arg, "time", p - eap->arg) == 0) | |
4473 { | |
4474 what = LC_TIME; | |
4475 name = skipwhite(p); | |
4476 whatstr = "time "; | |
4477 } | |
4478 } | |
4479 | |
4480 if (*name == NUL) | |
4481 { | |
4482 #ifndef LC_MESSAGES | |
4483 if (what == VIM_LC_MESSAGES) | |
4484 p = get_mess_env(); | |
4485 else | |
4486 #endif | |
4487 p = (char_u *)setlocale(what, NULL); | |
4488 if (p == NULL || *p == NUL) | |
4489 p = (char_u *)"Unknown"; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
4490 smsg(_("Current %slanguage: \"%s\""), whatstr, p); |
7 | 4491 } |
4492 else | |
4493 { | |
4494 #ifndef LC_MESSAGES | |
4495 if (what == VIM_LC_MESSAGES) | |
4496 loc = ""; | |
4497 else | |
4498 #endif | |
1624 | 4499 { |
7 | 4500 loc = setlocale(what, (char *)name); |
1624 | 4501 #if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
4502 /* Make sure strtod() uses a decimal point, not a comma. */ | |
4503 setlocale(LC_NUMERIC, "C"); | |
4504 #endif | |
4505 } | |
7 | 4506 if (loc == NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15448
diff
changeset
|
4507 semsg(_("E197: Cannot set language to \"%s\""), name); |
7 | 4508 else |
4509 { | |
4510 #ifdef HAVE_NL_MSG_CAT_CNTR | |
4511 /* Need to do this for GNU gettext, otherwise cached translations | |
4512 * will be used again. */ | |
4513 extern int _nl_msg_cat_cntr; | |
4514 | |
4515 ++_nl_msg_cat_cntr; | |
4516 #endif | |
1222 | 4517 /* Reset $LC_ALL, otherwise it would overrule everything. */ |
7 | 4518 vim_setenv((char_u *)"LC_ALL", (char_u *)""); |
4519 | |
4520 if (what != LC_TIME) | |
4521 { | |
4522 /* Tell gettext() what to translate to. It apparently doesn't | |
4523 * use the currently effective locale. Also do this when | |
4524 * FEAT_GETTEXT isn't defined, so that shell commands use this | |
4525 * value. */ | |
4526 if (what == LC_ALL) | |
534 | 4527 { |
7 | 4528 vim_setenv((char_u *)"LANG", name); |
5027
5751284311f3
updated for version 7.3.1257
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
4529 |
5751284311f3
updated for version 7.3.1257
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
4530 /* Clear $LANGUAGE because GNU gettext uses it. */ |
5751284311f3
updated for version 7.3.1257
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
4531 vim_setenv((char_u *)"LANGUAGE", (char_u *)""); |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
4532 # ifdef MSWIN |
534 | 4533 /* Apparently MS-Windows printf() may cause a crash when |
4534 * we give it 8-bit text while it's expecting text in the | |
4535 * current locale. This call avoids that. */ | |
4536 setlocale(LC_CTYPE, "C"); | |
4537 # endif | |
4538 } | |
7 | 4539 if (what != LC_CTYPE) |
4540 { | |
4541 char_u *mname; | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
4542 #ifdef MSWIN |
7 | 4543 mname = gettext_lang(name); |
4544 #else | |
4545 mname = name; | |
4546 #endif | |
4547 vim_setenv((char_u *)"LC_MESSAGES", mname); | |
4548 #ifdef FEAT_MULTI_LANG | |
4549 set_helplang_default(mname); | |
4550 #endif | |
4551 } | |
4552 } | |
4553 | |
4554 # ifdef FEAT_EVAL | |
4555 /* Set v:lang, v:lc_time and v:ctype to the final result. */ | |
4556 set_lang_var(); | |
4557 # endif | |
3149 | 4558 # ifdef FEAT_TITLE |
4559 maketitle(); | |
4560 # endif | |
7 | 4561 } |
4562 } | |
4563 } | |
4564 | |
4565 # if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
2849 | 4566 |
4567 static char_u **locales = NULL; /* Array of all available locales */ | |
10569
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4568 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
4569 # ifndef MSWIN |
2849 | 4570 static int did_init_locales = FALSE; |
4571 | |
4572 /* Return an array of strings for all available locales + NULL for the | |
4573 * last element. Return NULL in case of error. */ | |
4574 static char_u ** | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4575 find_locales(void) |
2849 | 4576 { |
4577 garray_T locales_ga; | |
4578 char_u *loc; | |
4579 | |
4580 /* Find all available locales by running command "locale -a". If this | |
4581 * doesn't work we won't have completion. */ | |
4582 char_u *locale_a = get_cmd_output((char_u *)"locale -a", | |
5808 | 4583 NULL, SHELL_SILENT, NULL); |
2849 | 4584 if (locale_a == NULL) |
4585 return NULL; | |
4586 ga_init2(&locales_ga, sizeof(char_u *), 20); | |
4587 | |
4588 /* Transform locale_a string where each locale is separated by "\n" | |
4589 * into an array of locale strings. */ | |
4590 loc = (char_u *)strtok((char *)locale_a, "\n"); | |
4591 | |
4592 while (loc != NULL) | |
4593 { | |
4594 if (ga_grow(&locales_ga, 1) == FAIL) | |
4595 break; | |
4596 loc = vim_strsave(loc); | |
4597 if (loc == NULL) | |
4598 break; | |
4599 | |
4600 ((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc; | |
4601 loc = (char_u *)strtok(NULL, "\n"); | |
4602 } | |
4603 vim_free(locale_a); | |
4604 if (ga_grow(&locales_ga, 1) == FAIL) | |
4605 { | |
4606 ga_clear(&locales_ga); | |
4607 return NULL; | |
4608 } | |
4609 ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; | |
4610 return (char_u **)locales_ga.ga_data; | |
4611 } | |
10569
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4612 # endif |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4613 |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4614 /* |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4615 * Lazy initialization of all available locales. |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4616 */ |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4617 static void |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4618 init_locales(void) |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4619 { |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15842
diff
changeset
|
4620 # ifndef MSWIN |
10569
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4621 if (!did_init_locales) |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4622 { |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4623 did_init_locales = TRUE; |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4624 locales = find_locales(); |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4625 } |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4626 # endif |
0bf064e7917a
patch 8.0.0174: executing "locale -a" on MS-Windows needlessly
Christian Brabandt <cb@256bit.org>
parents:
10262
diff
changeset
|
4627 } |
2849 | 4628 |
4629 # if defined(EXITFREE) || defined(PROTO) | |
4630 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4631 free_locales(void) |
2849 | 4632 { |
4633 int i; | |
4634 if (locales != NULL) | |
4635 { | |
4636 for (i = 0; locales[i] != NULL; i++) | |
4637 vim_free(locales[i]); | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13190
diff
changeset
|
4638 VIM_CLEAR(locales); |
2849 | 4639 } |
4640 } | |
4641 # endif | |
4642 | |
7 | 4643 /* |
4644 * Function given to ExpandGeneric() to obtain the possible arguments of the | |
4645 * ":language" command. | |
4646 */ | |
4647 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4648 get_lang_arg(expand_T *xp UNUSED, int idx) |
7 | 4649 { |
4650 if (idx == 0) | |
4651 return (char_u *)"messages"; | |
4652 if (idx == 1) | |
4653 return (char_u *)"ctype"; | |
4654 if (idx == 2) | |
4655 return (char_u *)"time"; | |
2849 | 4656 |
4657 init_locales(); | |
4658 if (locales == NULL) | |
4659 return NULL; | |
4660 return locales[idx - 3]; | |
4661 } | |
4662 | |
4663 /* | |
4664 * Function given to ExpandGeneric() to obtain the available locales. | |
4665 */ | |
4666 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4667 get_locales(expand_T *xp UNUSED, int idx) |
2849 | 4668 { |
4669 init_locales(); | |
4670 if (locales == NULL) | |
4671 return NULL; | |
4672 return locales[idx]; | |
7 | 4673 } |
4674 # endif | |
4675 | |
4676 #endif |