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