Mercurial > vim
annotate src/scriptfile.c @ 28232:d041bcc0d3d6
Added tag v8.2.4642 for changeset 66b245d84f377ee2352f9780a6d6eb77b9b3b09b
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 28 Mar 2022 16:30:04 +0200 |
parents | 2b595cee4c85 |
children | 5bf82b918cb2 |
rev | line source |
---|---|
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * scriptfile.c: functions for dealing with the runtime directories/files |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
16 #if defined(FEAT_EVAL) || defined(PROTO) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
17 // The names of packages that once were loaded are remembered. |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
18 static garray_T ga_loaded = {0, 0, sizeof(char_u *), 4, NULL}; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
19 #endif |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
20 |
28139
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
21 // last used sequence number for sourcing scripts (current_sctx.sc_seq) |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
22 #ifdef FEAT_EVAL |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
23 static int last_current_SID_seq = 0; |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
24 #endif |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
25 |
28164
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
26 static int do_source_ext(char_u *fname, int check_other, int is_vimrc, int *ret_sid, exarg_T *eap, int clearvars); |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
27 |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 /* |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
29 * Initialize the execution stack. |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
30 */ |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
31 void |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
32 estack_init(void) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
33 { |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
34 estack_T *entry; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
35 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
36 if (ga_grow(&exestack, 10) == FAIL) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
37 mch_exit(0); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
38 entry = ((estack_T *)exestack.ga_data) + exestack.ga_len; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
39 entry->es_type = ETYPE_TOP; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
40 entry->es_name = NULL; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
41 entry->es_lnum = 0; |
18993
dcbc559510f6
patch 8.2.0057: cannot build with small features
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
42 #ifdef FEAT_EVAL |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
43 entry->es_info.ufunc = NULL; |
18993
dcbc559510f6
patch 8.2.0057: cannot build with small features
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
44 #endif |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
45 ++exestack.ga_len; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
46 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
47 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
48 /* |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
49 * Add an item to the execution stack. |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
50 * Returns the new entry or NULL when out of memory. |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
51 */ |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
52 estack_T * |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
53 estack_push(etype_T type, char_u *name, long lnum) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
54 { |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
55 estack_T *entry; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
56 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
57 // If memory allocation fails then we'll pop more than we push, eventually |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
58 // at the top level it will be OK again. |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
59 if (ga_grow(&exestack, 1) == OK) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
60 { |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
61 entry = ((estack_T *)exestack.ga_data) + exestack.ga_len; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
62 entry->es_type = type; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
63 entry->es_name = name; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
64 entry->es_lnum = lnum; |
18993
dcbc559510f6
patch 8.2.0057: cannot build with small features
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
65 #ifdef FEAT_EVAL |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
66 entry->es_info.ufunc = NULL; |
18993
dcbc559510f6
patch 8.2.0057: cannot build with small features
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
67 #endif |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
68 ++exestack.ga_len; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
69 return entry; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
70 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
71 return NULL; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
72 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
73 |
18993
dcbc559510f6
patch 8.2.0057: cannot build with small features
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
74 #if defined(FEAT_EVAL) || defined(PROTO) |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
75 /* |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
76 * Add a user function to the execution stack. |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
77 */ |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
78 estack_T * |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
79 estack_push_ufunc(ufunc_T *ufunc, long lnum) |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
80 { |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
81 estack_T *entry = estack_push(ETYPE_UFUNC, |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
82 ufunc->uf_name_exp != NULL |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
83 ? ufunc->uf_name_exp : ufunc->uf_name, lnum); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
84 if (entry != NULL) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
85 entry->es_info.ufunc = ufunc; |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
86 return entry; |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
87 } |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
88 |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
89 /* |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
90 * Return TRUE if "ufunc" with "lnum" is already at the top of the exe stack. |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
91 */ |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
92 int |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
93 estack_top_is_ufunc(ufunc_T *ufunc, long lnum) |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
94 { |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
95 estack_T *entry; |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
96 |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
97 if (exestack.ga_len == 0) |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
98 return FALSE; |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
99 entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
100 return entry->es_type == ETYPE_UFUNC |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
101 && STRCMP( entry->es_name, ufunc->uf_name_exp != NULL |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
102 ? ufunc->uf_name_exp : ufunc->uf_name) == 0 |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
103 && entry->es_lnum == lnum; |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20536
diff
changeset
|
104 } |
18993
dcbc559510f6
patch 8.2.0057: cannot build with small features
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
105 #endif |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
106 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
107 /* |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
108 * Take an item off of the execution stack and return it. |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
109 */ |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
110 estack_T * |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
111 estack_pop(void) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
112 { |
21206
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
113 if (exestack.ga_len == 0) |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
114 return NULL; |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
115 --exestack.ga_len; |
caab594592cc
patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
116 return ((estack_T *)exestack.ga_data) + exestack.ga_len; |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
117 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
118 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
119 /* |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
120 * Get the current value for <sfile> in allocated memory. |
22208
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
121 * "which" is ESTACK_SFILE for <sfile> and ESTACK_STACK for <stack>. |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
122 */ |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
123 char_u * |
22208
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
124 estack_sfile(estack_arg_T which UNUSED) |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
125 { |
18997
6b2d93436388
patch 8.2.0059: compiler warnings for unused variables in small build
Bram Moolenaar <Bram@vim.org>
parents:
18993
diff
changeset
|
126 estack_T *entry; |
6b2d93436388
patch 8.2.0059: compiler warnings for unused variables in small build
Bram Moolenaar <Bram@vim.org>
parents:
18993
diff
changeset
|
127 #ifdef FEAT_EVAL |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
128 garray_T ga; |
19061
5a62b4a0c961
patch 8.2.0091: compiler warnings for size_t / int types
Bram Moolenaar <Bram@vim.org>
parents:
18997
diff
changeset
|
129 size_t len; |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
130 int idx; |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
131 etype_T last_type = ETYPE_SCRIPT; |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
132 char *type_name; |
18997
6b2d93436388
patch 8.2.0059: compiler warnings for unused variables in small build
Bram Moolenaar <Bram@vim.org>
parents:
18993
diff
changeset
|
133 #endif |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
134 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
135 entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; |
18993
dcbc559510f6
patch 8.2.0057: cannot build with small features
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
136 #ifdef FEAT_EVAL |
22208
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
137 if (which == ESTACK_SFILE && entry->es_type != ETYPE_UFUNC) |
18993
dcbc559510f6
patch 8.2.0057: cannot build with small features
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
138 #endif |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
139 { |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
140 if (entry->es_name == NULL) |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
141 return NULL; |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
142 return vim_strsave(entry->es_name); |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
143 } |
18993
dcbc559510f6
patch 8.2.0057: cannot build with small features
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
144 #ifdef FEAT_EVAL |
26230
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
145 // expand('<sfile>') works in a function for backwards compatibility, but |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
146 // may give an unexpected result. Disallow it in Vim 9 script. |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
147 if (which == ESTACK_SFILE && in_vim9script()) |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
148 { |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
149 int save_emsg_off = emsg_off; |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
150 |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
151 if (emsg_off == 1) |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
152 // f_expand() silences errors but we do want this one |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
153 emsg_off = 0; |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
154 emsg(_(e_cannot_expand_sfile_in_vim9_function)); |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
155 emsg_off = save_emsg_off; |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
156 return NULL; |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
157 } |
8b8470b511f5
patch 8.2.3646: using <sfile> in a function gives an unexpected result
Bram Moolenaar <Bram@vim.org>
parents:
24876
diff
changeset
|
158 |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
159 // Give information about each stack entry up to the root. |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
160 // For a function we compose the call stack, as it was done in the past: |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
161 // "function One[123]..Two[456]..Three" |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
162 ga_init2(&ga, sizeof(char), 100); |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
163 for (idx = 0; idx < exestack.ga_len; ++idx) |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
164 { |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
165 entry = ((estack_T *)exestack.ga_data) + idx; |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
166 if (entry->es_name != NULL) |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
167 { |
22218
195a617b405a
patch 8.2.1658: expand('<stack>') has trailing ".."
Bram Moolenaar <Bram@vim.org>
parents:
22208
diff
changeset
|
168 long lnum = 0; |
195a617b405a
patch 8.2.1658: expand('<stack>') has trailing ".."
Bram Moolenaar <Bram@vim.org>
parents:
22208
diff
changeset
|
169 char *dots; |
22208
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
170 |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
171 len = STRLEN(entry->es_name) + 15; |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
172 type_name = ""; |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
173 if (entry->es_type != last_type) |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
174 { |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
175 switch (entry->es_type) |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
176 { |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
177 case ETYPE_SCRIPT: type_name = "script "; break; |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
178 case ETYPE_UFUNC: type_name = "function "; break; |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
179 default: type_name = ""; break; |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
180 } |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
181 last_type = entry->es_type; |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
182 } |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
183 len += STRLEN(type_name); |
21497
766839794e09
patch 8.2.1299: compiler warning for using size_t for int and void pointer
Bram Moolenaar <Bram@vim.org>
parents:
21495
diff
changeset
|
184 if (ga_grow(&ga, (int)len) == FAIL) |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
185 break; |
22208
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
186 if (idx == exestack.ga_len - 1) |
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
187 lnum = which == ESTACK_STACK ? SOURCING_LNUM : 0; |
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
188 else |
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
189 lnum = entry->es_lnum; |
22218
195a617b405a
patch 8.2.1658: expand('<stack>') has trailing ".."
Bram Moolenaar <Bram@vim.org>
parents:
22208
diff
changeset
|
190 dots = idx == exestack.ga_len - 1 ? "" : ".."; |
22208
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
191 if (lnum == 0) |
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
192 // For the bottom entry of <sfile>: do not add the line number, |
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
193 // it is used in <slnum>. Also leave it out when the number is |
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
21979
diff
changeset
|
194 // not set. |
21497
766839794e09
patch 8.2.1299: compiler warning for using size_t for int and void pointer
Bram Moolenaar <Bram@vim.org>
parents:
21495
diff
changeset
|
195 vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s%s", |
22218
195a617b405a
patch 8.2.1658: expand('<stack>') has trailing ".."
Bram Moolenaar <Bram@vim.org>
parents:
22208
diff
changeset
|
196 type_name, entry->es_name, dots); |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
197 else |
22218
195a617b405a
patch 8.2.1658: expand('<stack>') has trailing ".."
Bram Moolenaar <Bram@vim.org>
parents:
22208
diff
changeset
|
198 vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s[%ld]%s", |
195a617b405a
patch 8.2.1658: expand('<stack>') has trailing ".."
Bram Moolenaar <Bram@vim.org>
parents:
22208
diff
changeset
|
199 type_name, entry->es_name, lnum, dots); |
21497
766839794e09
patch 8.2.1299: compiler warning for using size_t for int and void pointer
Bram Moolenaar <Bram@vim.org>
parents:
21495
diff
changeset
|
200 ga.ga_len += (int)STRLEN((char *)ga.ga_data + ga.ga_len); |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
201 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
202 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
203 |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
21389
diff
changeset
|
204 return (char_u *)ga.ga_data; |
18993
dcbc559510f6
patch 8.2.0057: cannot build with small features
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
205 #endif |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
206 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
207 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
208 /* |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 * ":runtime [what] {name}" |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 ex_runtime(exarg_T *eap) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 char_u *arg = eap->arg; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 char_u *p = skiptowhite(arg); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 int len = (int)(p - arg); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 int flags = eap->forceit ? DIP_ALL : 0; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 if (STRNCMP(arg, "START", len) == 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 flags += DIP_START + DIP_NORTP; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 arg = skipwhite(arg + len); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 else if (STRNCMP(arg, "OPT", len) == 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 flags += DIP_OPT + DIP_NORTP; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 arg = skipwhite(arg + len); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 else if (STRNCMP(arg, "PACK", len) == 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 flags += DIP_START + DIP_OPT + DIP_NORTP; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 arg = skipwhite(arg + len); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 else if (STRNCMP(arg, "ALL", len) == 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 flags += DIP_START + DIP_OPT; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 arg = skipwhite(arg + len); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 source_runtime(arg, flags); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 static void |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
244 source_callback(char_u *fname, void *cookie) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
246 (void)do_source(fname, FALSE, DOSO_NONE, cookie); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
249 #ifdef FEAT_EVAL |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
250 /* |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
251 * Find an already loaded script "name". |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
252 * If found returns its script ID. If not found returns -1. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
253 */ |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
254 static int |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
255 find_script_by_name(char_u *name) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
256 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
257 int sid; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
258 scriptitem_T *si; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
259 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
260 for (sid = script_items.ga_len; sid > 0; --sid) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
261 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
262 // We used to check inode here, but that doesn't work: |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
263 // - If a script is edited and written, it may get a different |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
264 // inode number, even though to the user it is the same script. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
265 // - If a script is deleted and another script is written, with a |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
266 // different name, the inode may be re-used. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
267 si = SCRIPT_ITEM(sid); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
268 if (si->sn_name != NULL && fnamecmp(si->sn_name, name) == 0) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
269 return sid; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
270 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
271 return -1; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
272 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
273 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
274 /* |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
275 * Add a new scriptitem with all items initialized. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
276 * When running out of memory "error" is set to FAIL. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
277 * Returns the script ID. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
278 */ |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
279 static int |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
280 get_new_scriptitem(int *error) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
281 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
282 static scid_T last_current_SID = 0; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
283 int sid = ++last_current_SID; |
27045
d31bd8607975
patch 8.2.4051: compiler complains about possibly uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
284 scriptitem_T *si = NULL; |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
285 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
286 if (ga_grow(&script_items, (int)(sid - script_items.ga_len)) == FAIL) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
287 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
288 *error = FAIL; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
289 return sid; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
290 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
291 while (script_items.ga_len < sid) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
292 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
293 si = ALLOC_CLEAR_ONE(scriptitem_T); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
294 if (si == NULL) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
295 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
296 *error = FAIL; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
297 return sid; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
298 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
299 ++script_items.ga_len; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
300 SCRIPT_ITEM(script_items.ga_len) = si; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
301 si->sn_name = NULL; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
302 si->sn_version = 1; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
303 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
304 // Allocate the local script variables to use for this script. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
305 new_script_vars(script_items.ga_len); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
306 ga_init2(&si->sn_var_vals, sizeof(svar_T), 10); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
307 hash_init(&si->sn_all_vars.dv_hashtab); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
308 ga_init2(&si->sn_imports, sizeof(imported_T), 10); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
309 ga_init2(&si->sn_type_list, sizeof(type_T), 10); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
310 # ifdef FEAT_PROFILE |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
311 si->sn_prof_on = FALSE; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
312 # endif |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
313 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
314 |
27045
d31bd8607975
patch 8.2.4051: compiler complains about possibly uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
315 // "si" can't be NULL, check only to avoid a compiler warning |
d31bd8607975
patch 8.2.4051: compiler complains about possibly uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
316 if (si != NULL) |
d31bd8607975
patch 8.2.4051: compiler complains about possibly uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
317 // Used to check script variable index is still valid. |
d31bd8607975
patch 8.2.4051: compiler complains about possibly uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
318 si->sn_script_seq = current_sctx.sc_seq; |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
319 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
320 return sid; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
321 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
322 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
323 static void |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
324 find_script_callback(char_u *fname, void *cookie) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
325 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
326 int sid; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
327 int error = OK; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
328 int *ret_sid = cookie; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
329 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
330 sid = find_script_by_name(fname); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
331 if (sid < 0) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
332 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
333 // script does not exist yet, create a new scriptitem |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
334 sid = get_new_scriptitem(&error); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
335 if (error == OK) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
336 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
337 scriptitem_T *si = SCRIPT_ITEM(sid); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
338 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
339 si->sn_name = vim_strsave(fname); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
340 si->sn_state = SN_STATE_NOT_LOADED; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
341 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
342 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
343 *ret_sid = sid; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
344 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
345 #endif |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
346 |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 * Find the file "name" in all directories in "path" and invoke |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
349 * "callback(fname, cookie)". |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 * "name" can contain wildcards. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 * When "flags" has DIP_ALL: source all files, otherwise only the first one. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
352 * When "flags" has DIP_DIR: find directories instead of files. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 * When "flags" has DIP_ERR: give an error message if there is no match. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
354 * |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 * return FAIL when no file could be sourced, OK otherwise. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
357 int |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 do_in_path( |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 char_u *path, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 char_u *name, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 int flags, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 void (*callback)(char_u *fname, void *ck), |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
363 void *cookie) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
365 char_u *rtp; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 char_u *np; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 char_u *buf; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 char_u *rtp_copy; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
369 char_u *tail; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 int num_files; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 char_u **files; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 int i; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 int did_one = FALSE; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 #ifdef AMIGA |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 struct Process *proc = (struct Process *)FindTask(0L); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 APTR save_winptr = proc->pr_WindowPtr; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 // Avoid a requester here for a volume that doesn't exist. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 proc->pr_WindowPtr = (APTR)-1L; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 // Make a copy of 'runtimepath'. Invoking the callback may change the |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 // value. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 rtp_copy = vim_strsave(path); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 buf = alloc(MAXPATHL); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
386 if (buf != NULL && rtp_copy != NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 { |
20265
d821c03b890c
patch 8.2.0688: output clobbered if setting 'verbose' to see shell commands
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
388 if (p_verbose > 10 && name != NULL) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 verbose_enter(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 smsg(_("Searching for \"%s\" in \"%s\""), |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 (char *)name, (char *)path); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 verbose_leave(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 // Loop over all entries in 'runtimepath'. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 rtp = rtp_copy; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 while (*rtp != NUL && ((flags & DIP_ALL) || !did_one)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
400 size_t buflen; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 // Copy the path from 'runtimepath' to buf[]. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
403 copy_option_part(&rtp, buf, MAXPATHL, ","); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 buflen = STRLEN(buf); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 // Skip after or non-after directories. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 if (flags & (DIP_NOAFTER | DIP_AFTER)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 int is_after = buflen >= 5 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 && STRCMP(buf + buflen - 5, "after") == 0; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 if ((is_after && (flags & DIP_NOAFTER)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 || (!is_after && (flags & DIP_AFTER))) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 continue; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 if (name == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 (*callback)(buf, (void *) &cookie); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 if (!did_one) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 did_one = (cookie == NULL); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 else if (buflen + STRLEN(name) + 2 < MAXPATHL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 add_pathsep(buf); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 tail = buf + STRLEN(buf); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 // Loop over all patterns in "name" |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 np = name; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 while (*np != NUL && ((flags & DIP_ALL) || !did_one)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 // Append the pattern from "name" to buf[]. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 copy_option_part(&np, tail, (int)(MAXPATHL - (tail - buf)), |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 "\t "); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 |
20265
d821c03b890c
patch 8.2.0688: output clobbered if setting 'verbose' to see shell commands
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
436 if (p_verbose > 10) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 verbose_enter(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 smsg(_("Searching for \"%s\""), buf); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 verbose_leave(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 // Expand wildcards, invoke the callback for each match. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 if (gen_expand_wildcards(1, &buf, &num_files, &files, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 (flags & DIP_DIR) ? EW_DIR : EW_FILE) == OK) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 for (i = 0; i < num_files; ++i) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 (*callback)(files[i], cookie); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 did_one = TRUE; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 if (!(flags & DIP_ALL)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 break; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 FreeWild(num_files, files); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 vim_free(buf); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 vim_free(rtp_copy); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 if (!did_one && name != NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 char *basepath = path == p_rtp ? "runtimepath" : "packpath"; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 if (flags & DIP_ERR) |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
467 semsg(_(e_directory_not_found_in_str_str), basepath, name); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 else if (p_verbose > 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 verbose_enter(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 smsg(_("not found in '%s': \"%s\""), basepath, name); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 verbose_leave(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
473 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 #ifdef AMIGA |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 proc->pr_WindowPtr = save_winptr; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
478 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 return did_one ? OK : FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 * Find "name" in "path". When found, invoke the callback function for |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 * it: callback(fname, "cookie") |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 * When "flags" has DIP_ALL repeat for all matches, otherwise only the first |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 * one is used. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 * Returns OK when at least one match found, FAIL otherwise. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 * |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 * If "name" is NULL calls callback for each entry in "path". Cookie is |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 * passed by reference in this case, setting it to NULL indicates that callback |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 * has done its job. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 static int |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 do_in_path_and_pp( |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 char_u *path, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 char_u *name, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 int flags, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 void (*callback)(char_u *fname, void *ck), |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 void *cookie) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 int done = FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 char_u *s; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 int len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 char *start_dir = "pack/*/start/*/%s"; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 char *opt_dir = "pack/*/opt/*/%s"; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 if ((flags & DIP_NORTP) == 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 done = do_in_path(path, name, flags, callback, cookie); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 len = (int)(STRLEN(start_dir) + STRLEN(name)); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 s = alloc(len); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 if (s == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 return FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 vim_snprintf((char *)s, len, start_dir, name); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 done = do_in_path(p_pp, s, flags, callback, cookie); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 vim_free(s); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_OPT)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 len = (int)(STRLEN(opt_dir) + STRLEN(name)); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 s = alloc(len); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 if (s == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 return FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
528 vim_snprintf((char *)s, len, opt_dir, name); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 done = do_in_path(p_pp, s, flags, callback, cookie); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 vim_free(s); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 return done; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 * Just like do_in_path_and_pp(), using 'runtimepath' for "path". |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 int |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 do_in_runtimepath( |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 char_u *name, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 int flags, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 void (*callback)(char_u *fname, void *ck), |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 void *cookie) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
546 return do_in_path_and_pp(p_rtp, name, flags, callback, cookie); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
548 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
549 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 * Source the file "name" from all directories in 'runtimepath'. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
551 * "name" can contain wildcards. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 * When "flags" has DIP_ALL: source all files, otherwise only the first one. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 * |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 * return FAIL when no file could be sourced, OK otherwise. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
555 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 int |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 source_runtime(char_u *name, int flags) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
559 return source_in_path(p_rtp, name, flags, NULL); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 /* |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
563 * Just like source_runtime(), but use "path" instead of 'runtimepath' |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
564 * and return the script ID in "ret_sid". |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 int |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
567 source_in_path(char_u *path, char_u *name, int flags, int *ret_sid) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
569 return do_in_path_and_pp(path, name, flags, source_callback, ret_sid); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
572 #if defined(FEAT_EVAL) || defined(PROTO) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
574 /* |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
575 * Find "name" in 'runtimepath'. If found a new scriptitem is created for it |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
576 * and it's script ID is returned. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
577 * If not found returns -1. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
578 */ |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
579 int |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
580 find_script_in_rtp(char_u *name) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
581 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
582 int sid = -1; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
583 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
584 (void)do_in_path_and_pp(p_rtp, name, DIP_NOAFTER, |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
585 find_script_callback, &sid); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
586 return sid; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
587 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
589 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 * Expand wildcards in "pat" and invoke do_source() for each match. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 static void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 source_all_matches(char_u *pat) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
594 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
595 int num_files; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 char_u **files; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
597 int i; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
598 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 for (i = 0; i < num_files; ++i) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
602 (void)do_source(files[i], FALSE, DOSO_NONE, NULL); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 FreeWild(num_files, files); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
607 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 * Add the package directory to 'runtimepath'. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
610 static int |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
611 add_pack_dir_to_rtp(char_u *fname) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 char_u *p4, *p3, *p2, *p1, *p; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
614 char_u *entry; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
615 char_u *insp = NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 int c; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
617 char_u *new_rtp; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
618 int keep; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
619 size_t oldlen; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 size_t addlen; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
621 size_t new_rtp_len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 char_u *afterdir = NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
623 size_t afterlen = 0; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
624 char_u *after_insp = NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
625 char_u *ffname = NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 size_t fname_len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 char_u *buf = NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 char_u *rtp_ffname; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 int match; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 int retval = FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
631 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
632 p4 = p3 = p2 = p1 = get_past_head(fname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 for (p = p1; *p; MB_PTR_ADV(p)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
634 if (vim_ispathsep_nocolon(*p)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 p4 = p3; p3 = p2; p2 = p1; p1 = p; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 // now we have: |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
640 // rtp/pack/name/start/name |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 // p4 p3 p2 p1 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 // |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 // find the part up to "pack" in 'runtimepath' |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 c = *++p4; // append pathsep in order to expand symlink |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
645 *p4 = NUL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 ffname = fix_fname(fname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 *p4 = c; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
648 if (ffname == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
649 return FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
650 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
651 // Find "ffname" in "p_rtp", ignoring '/' vs '\' differences. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 // Also stop at the first "after" directory. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 fname_len = STRLEN(ffname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 buf = alloc(MAXPATHL); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
655 if (buf == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
656 goto theend; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
657 for (entry = p_rtp; *entry != NUL; ) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
659 char_u *cur_entry = entry; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 copy_option_part(&entry, buf, MAXPATHL, ","); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 if (insp == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
663 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 add_pathsep(buf); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 rtp_ffname = fix_fname(buf); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 if (rtp_ffname == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 goto theend; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 vim_free(rtp_ffname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 if (match) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 // Insert "ffname" after this entry (and comma). |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 insp = entry; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 if ((p = (char_u *)strstr((char *)buf, "after")) != NULL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 && p > buf |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 && vim_ispathsep(p[-1]) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 && (vim_ispathsep(p[5]) || p[5] == NUL || p[5] == ',')) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 if (insp == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 // Did not find "ffname" before the first "after" directory, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 // insert it before this entry. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
683 insp = cur_entry; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 after_insp = cur_entry; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 break; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
688 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 if (insp == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 // Both "fname" and "after" not found, append at the end. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 insp = p_rtp + STRLEN(p_rtp); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 // check if rtp/pack/name/start/name/after exists |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 afterdir = concat_fnames(fname, (char_u *)"after", TRUE); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 if (afterdir != NULL && mch_isdir(afterdir)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 afterlen = STRLEN(afterdir) + 1; // add one for comma |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
697 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 oldlen = STRLEN(p_rtp); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 addlen = STRLEN(fname) + 1; // add one for comma |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
700 new_rtp = alloc(oldlen + addlen + afterlen + 1); // add one for NUL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 if (new_rtp == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 goto theend; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
704 // We now have 'rtp' parts: {keep}{keep_after}{rest}. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 // Create new_rtp, first: {keep},{fname} |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
706 keep = (int)(insp - p_rtp); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 mch_memmove(new_rtp, p_rtp, keep); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 new_rtp_len = keep; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 if (*insp == NUL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
710 new_rtp[new_rtp_len++] = ','; // add comma before |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 mch_memmove(new_rtp + new_rtp_len, fname, addlen - 1); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
712 new_rtp_len += addlen - 1; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
713 if (*insp != NUL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
714 new_rtp[new_rtp_len++] = ','; // add comma after |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
716 if (afterlen > 0 && after_insp != NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
717 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 int keep_after = (int)(after_insp - p_rtp); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
719 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
720 // Add to new_rtp: {keep},{fname}{keep_after},{afterdir} |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
721 mch_memmove(new_rtp + new_rtp_len, p_rtp + keep, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
722 keep_after - keep); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
723 new_rtp_len += keep_after - keep; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
724 mch_memmove(new_rtp + new_rtp_len, afterdir, afterlen - 1); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 new_rtp_len += afterlen - 1; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
726 new_rtp[new_rtp_len++] = ','; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 keep = keep_after; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
729 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
730 if (p_rtp[keep] != NUL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 // Append rest: {keep},{fname}{keep_after},{afterdir}{rest} |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
732 mch_memmove(new_rtp + new_rtp_len, p_rtp + keep, oldlen - keep + 1); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 new_rtp[new_rtp_len] = NUL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 if (afterlen > 0 && after_insp == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 // Append afterdir when "after" was not found: |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 // {keep},{fname}{rest},{afterdir} |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
740 STRCAT(new_rtp, ","); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 STRCAT(new_rtp, afterdir); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
742 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 set_option_value((char_u *)"rtp", 0L, new_rtp, 0); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
745 vim_free(new_rtp); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 retval = OK; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
748 theend: |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 vim_free(buf); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
750 vim_free(ffname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 vim_free(afterdir); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
752 return retval; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
753 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
754 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 * Load scripts in "plugin" and "ftdetect" directories of the package. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 static int |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 load_pack_plugin(char_u *fname) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
760 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 static char *plugpat = "%s/plugin/**/*.vim"; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 static char *ftpat = "%s/ftdetect/*.vim"; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
763 int len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
764 char_u *ffname = fix_fname(fname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
765 char_u *pat = NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
766 int retval = FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
768 if (ffname == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
769 return FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
770 len = (int)STRLEN(ffname) + (int)STRLEN(ftpat); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
771 pat = alloc(len); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 if (pat == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 goto theend; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 vim_snprintf((char *)pat, len, plugpat, ffname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
775 source_all_matches(pat); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes"); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
779 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 // If runtime/filetype.vim wasn't loaded yet, the scripts will be |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
781 // found when it loads. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 if (cmd != NULL && eval_to_number(cmd) > 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
783 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 do_cmdline_cmd((char_u *)"augroup filetypedetect"); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 vim_snprintf((char *)pat, len, ftpat, ffname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
786 source_all_matches(pat); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
787 do_cmdline_cmd((char_u *)"augroup END"); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
788 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 vim_free(cmd); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
790 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
791 vim_free(pat); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
792 retval = OK; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
793 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
794 theend: |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
795 vim_free(ffname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
796 return retval; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
797 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
798 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
799 // used for "cookie" of add_pack_plugin() |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
800 static int APP_ADD_DIR; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
801 static int APP_LOAD; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
802 static int APP_BOTH; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
803 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
804 static void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
805 add_pack_plugin(char_u *fname, void *cookie) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 if (cookie != &APP_LOAD) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
809 char_u *buf = alloc(MAXPATHL); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
810 char_u *p; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 int found = FALSE; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
813 if (buf == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
814 return; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
815 p = p_rtp; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
816 while (*p != NUL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 copy_option_part(&p, buf, MAXPATHL, ","); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
819 if (pathcmp((char *)buf, (char *)fname, -1) == 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
821 found = TRUE; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 break; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
824 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 vim_free(buf); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
826 if (!found) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
827 // directory is not yet in 'runtimepath', add it |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
828 if (add_pack_dir_to_rtp(fname) == FAIL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 return; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 if (cookie != &APP_ADD_DIR) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 load_pack_plugin(fname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 * Add all packages in the "start" directory to 'runtimepath'. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
839 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 add_pack_start_dirs(void) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
841 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 add_pack_plugin, &APP_ADD_DIR); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 * Load plugins from all packages in the "start" directory. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
849 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
850 load_start_packages(void) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
851 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 did_source_packages = TRUE; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 add_pack_plugin, &APP_LOAD); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 * ":packloadall" |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 * Find plugins in the package directories and source them. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
860 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
861 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
862 ex_packloadall(exarg_T *eap) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
863 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 if (!did_source_packages || eap->forceit) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 // First do a round to add all directories to 'runtimepath', then load |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 // the plugins. This allows for plugins to use an autoload directory |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 // of another plugin. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
869 add_pack_start_dirs(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
870 load_start_packages(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
871 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 * ":packadd[!] {name}" |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
878 ex_packadd(exarg_T *eap) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
879 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 static char *plugpat = "pack/*/%s/%s"; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
881 int len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
882 char *pat; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
883 int round; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
884 int res = OK; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
885 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 // Round 1: use "start", round 2: use "opt". |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
887 for (round = 1; round <= 2; ++round) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
888 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 // Only look under "start" when loading packages wasn't done yet. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
890 if (round == 1 && did_source_packages) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 continue; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
893 len = (int)STRLEN(plugpat) + (int)STRLEN(eap->arg) + 5; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 pat = alloc(len); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 if (pat == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
896 return; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
897 vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
898 // The first round don't give a "not found" error, in the second round |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 // only when nothing was found in the first round. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 res = do_in_path(p_pp, (char_u *)pat, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
901 DIP_ALL + DIP_DIR + (round == 2 && res == FAIL ? DIP_ERR : 0), |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
902 add_pack_plugin, eap->forceit ? &APP_ADD_DIR : &APP_BOTH); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
903 vim_free(pat); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
907 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 /* |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
909 * Sort "gap" and remove duplicate entries. "gap" is expected to contain a |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
910 * list of file names in allocated memory. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
911 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
912 void |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
913 remove_duplicates(garray_T *gap) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
914 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
915 int i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
916 int j; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
917 char_u **fnames = (char_u **)gap->ga_data; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
918 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
919 sort_strings(fnames, gap->ga_len); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
920 for (i = gap->ga_len - 1; i > 0; --i) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
921 if (fnamecmp(fnames[i - 1], fnames[i]) == 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
922 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
923 vim_free(fnames[i]); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
924 for (j = i + 1; j < gap->ga_len; ++j) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
925 fnames[j - 1] = fnames[j]; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
926 --gap->ga_len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
927 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
928 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
929 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
930 /* |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
931 * Expand color scheme, compiler or filetype names. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 * Search from 'runtimepath': |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 * 'runtimepath'/{dirnames}/{pat}.vim |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 * When "flags" has DIP_START: search also from 'start' of 'packpath': |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 * 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 * When "flags" has DIP_OPT: search also from 'opt' of 'packpath': |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
937 * 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 * "dirnames" is an array with one or more directory names. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 int |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 ExpandRTDir( |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 char_u *pat, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 int flags, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 int *num_file, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 char_u ***file, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 char *dirnames[]) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
948 char_u *s; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
949 char_u *e; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 char_u *match; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
951 garray_T ga; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 int i; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 int pat_len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
954 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
955 *num_file = 0; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 *file = NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
957 pat_len = (int)STRLEN(pat); |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
958 ga_init2(&ga, sizeof(char *), 10); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
959 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
960 for (i = 0; dirnames[i] != NULL; ++i) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 s = alloc(STRLEN(dirnames[i]) + pat_len + 7); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 if (s == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 ga_clear_strings(&ga); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 return FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 globpath(p_rtp, s, &ga, 0); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 vim_free(s); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 if (flags & DIP_START) { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 for (i = 0; dirnames[i] != NULL; ++i) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 s = alloc(STRLEN(dirnames[i]) + pat_len + 22); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 if (s == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 ga_clear_strings(&ga); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 return FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 sprintf((char *)s, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 globpath(p_pp, s, &ga, 0); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 vim_free(s); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 if (flags & DIP_OPT) { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 for (i = 0; dirnames[i] != NULL; ++i) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 s = alloc(STRLEN(dirnames[i]) + pat_len + 20); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 if (s == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 ga_clear_strings(&ga); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 return FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 sprintf((char *)s, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 globpath(p_pp, s, &ga, 0); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 vim_free(s); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 for (i = 0; i < ga.ga_len; ++i) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 match = ((char_u **)ga.ga_data)[i]; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 s = match; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 e = s + STRLEN(s); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 e -= 4; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 for (s = e; s > match; MB_PTR_BACK(match, s)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 if (s < match || vim_ispathsep(*s)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 break; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 ++s; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 *e = NUL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 mch_memmove(match, s, e - s + 1); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 if (ga.ga_len == 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 return FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 // Sort and remove duplicates which can happen when specifying multiple |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 // directories in dirnames. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 remove_duplicates(&ga); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 *file = ga.ga_data; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 *num_file = ga.ga_len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 return OK; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 * Expand loadplugin names: |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 * 'packpath'/pack/ * /opt/{pat} |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 int |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 ExpandPackAddDir( |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 char_u *pat, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 int *num_file, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 char_u ***file) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 char_u *s; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 char_u *e; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 char_u *match; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 garray_T ga; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 int i; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 int pat_len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 *num_file = 0; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 *file = NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 pat_len = (int)STRLEN(pat); |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
1052 ga_init2(&ga, sizeof(char *), 10); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 s = alloc(pat_len + 26); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 if (s == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 ga_clear_strings(&ga); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 return FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 sprintf((char *)s, "pack/*/opt/%s*", pat); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 globpath(p_pp, s, &ga, 0); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 vim_free(s); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 for (i = 0; i < ga.ga_len; ++i) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 match = ((char_u **)ga.ga_data)[i]; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 s = gettail(match); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 e = s + STRLEN(s); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 mch_memmove(match, s, e - s + 1); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 if (ga.ga_len == 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 return FAIL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 // Sort and remove duplicates which can happen when specifying multiple |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 // directories in dirnames. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 remove_duplicates(&ga); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 *file = ga.ga_data; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 *num_file = ga.ga_len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 return OK; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 static void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 cmd_source(char_u *fname, exarg_T *eap) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 { |
28164
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1087 int clearvars = FALSE; |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1088 |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1089 if (*fname != NUL && STRNCMP(fname, "++clear", 7) == 0) |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1090 { |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1091 // ++clear argument is supplied |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1092 clearvars = TRUE; |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1093 fname = fname + 7; |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1094 if (*fname != NUL) |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1095 { |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1096 semsg(_(e_invalid_argument_str), eap->arg); |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1097 return; |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1098 } |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1099 } |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1100 |
28139
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1101 if (*fname != NUL && eap != NULL && eap->addr_count > 0) |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1102 { |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1103 // if a filename is specified to :source, then a range is not allowed |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1104 emsg(_(e_no_range_allowed)); |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1105 return; |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1106 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 |
28139
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1108 if (eap != NULL && *fname == NUL) |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1109 { |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1110 if (eap->forceit) |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1111 // a file name is needed to source normal mode commands |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1112 emsg(_(e_argument_required)); |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1113 else |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1114 // source ex commands from the current buffer |
28164
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1115 do_source_ext(NULL, FALSE, FALSE, NULL, eap, clearvars); |
28139
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
1116 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 else if (eap != NULL && eap->forceit) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 // ":source!": read Normal mode commands |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 // Need to execute the commands directly. This is required at least |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 // for: |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 // - ":g" command busy |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 // - after ":argdo", ":windo" or ":bufdo" |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 // - another command follows |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 // - inside a loop |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 #ifdef FEAT_EVAL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 || eap->cstack->cs_idx >= 0 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 ); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 // ":source" read ex commands |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1132 else if (do_source(fname, FALSE, DOSO_NONE, NULL) == FAIL) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1133 semsg(_(e_cant_open_file_str), fname); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1136 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 * ":source {fname}" |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 ex_source(exarg_T *eap) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 #ifdef FEAT_BROWSE |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22594
diff
changeset
|
1143 if (cmdmod.cmod_flags & CMOD_BROWSE) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1144 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 char_u *fname = NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1146 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 fname = do_browse(0, (char_u *)_("Source Vim script"), eap->arg, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 NULL, NULL, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1149 (char_u *)_(BROWSE_FILTER_MACROS), NULL); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 if (fname != NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 cmd_source(fname, eap); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 vim_free(fname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 cmd_source(eap->arg, eap); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 #if defined(FEAT_EVAL) || defined(PROTO) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 * ":options" |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 ex_options( |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 exarg_T *eap UNUSED) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 { |
20043
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
19822
diff
changeset
|
1169 char_u buf[500]; |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
19822
diff
changeset
|
1170 int multi_mods = 0; |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
19822
diff
changeset
|
1171 |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
19822
diff
changeset
|
1172 buf[0] = NUL; |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1173 (void)add_win_cmd_modifers(buf, &cmdmod, &multi_mods); |
20043
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
19822
diff
changeset
|
1174 |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
19822
diff
changeset
|
1175 vim_setenv((char_u *)"OPTWIN_CMD", buf); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 cmd_source((char_u *)SYS_OPTWIN_FILE, NULL); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 * ":source" and associated commands. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1183 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 #ifdef FEAT_EVAL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 * Return the address holding the next breakpoint line for a source cookie. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 linenr_T * |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 source_breakpoint(void *cookie) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1190 { |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
1191 return &((source_cookie_T *)cookie)->breakpoint; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1193 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 * Return the address holding the debug tick for a source cookie. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1197 int * |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 source_dbg_tick(void *cookie) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 { |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
1200 return &((source_cookie_T *)cookie)->dbg_tick; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 * Return the nesting level for a source cookie. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 int |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 source_level(void *cookie) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 { |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
1209 return ((source_cookie_T *)cookie)->level; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 } |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
1211 |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
1212 /* |
21865
c16af87df654
patch 8.2.1482: Vim9: crash when using a nested lambda
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1213 * Return the readahead line. Note that the pointer may become invalid when |
c16af87df654
patch 8.2.1482: Vim9: crash when using a nested lambda
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
1214 * getting the next line, if it's concatenated with the next one. |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
1215 */ |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
1216 char_u * |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
1217 source_nextline(void *cookie) |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
1218 { |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
1219 return ((source_cookie_T *)cookie)->nextline; |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
1220 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 #if (defined(MSWIN) && defined(FEAT_CSCOPE)) || defined(HAVE_FD_CLOEXEC) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1224 # define USE_FOPEN_NOINH |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1225 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 * Special function to open a file without handle inheritance. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 * When possible the handle is closed on exec(). |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 static FILE * |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1230 fopen_noinh_readbin(char *filename) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 # ifdef MSWIN |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 int fd_tmp = mch_open(filename, O_RDONLY | O_BINARY | O_NOINHERIT, 0); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 # else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1235 int fd_tmp = mch_open(filename, O_RDONLY, 0); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 # endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 if (fd_tmp == -1) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 return NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 # ifdef HAVE_FD_CLOEXEC |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 int fdflags = fcntl(fd_tmp, F_GETFD); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1244 if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1245 (void)fcntl(fd_tmp, F_SETFD, fdflags | FD_CLOEXEC); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1246 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 # endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1248 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 return fdopen(fd_tmp, READBIN); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1253 /* |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1254 * Initialization for sourcing lines from the current buffer. Reads all the |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1255 * lines from the buffer and stores it in the cookie grow array. |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1256 * Returns a pointer to the name ":source buffer=<n>" on success and NULL on |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1257 * failure. |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1258 */ |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1259 static char_u * |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1260 do_source_buffer_init(source_cookie_T *sp, exarg_T *eap) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1261 { |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1262 linenr_T curr_lnum; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1263 char_u *line = NULL; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1264 char_u *fname; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1265 |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1266 CLEAR_FIELD(*sp); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1267 |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1268 if (curbuf == NULL) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1269 return NULL; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1270 |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1271 // Use ":source buffer=<num>" as the script name |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1272 vim_snprintf((char *)IObuff, IOSIZE, ":source buffer=%d", curbuf->b_fnum); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1273 fname = vim_strsave(IObuff); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1274 if (fname == NULL) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1275 return NULL; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1276 |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1277 ga_init2(&sp->buflines, sizeof(char_u *), 100); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1278 |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1279 // Copy the lines from the buffer into a grow array |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1280 for (curr_lnum = eap->line1; curr_lnum <= eap->line2; curr_lnum++) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1281 { |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1282 line = vim_strsave(ml_get(curr_lnum)); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1283 if (line == NULL) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1284 goto errret; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1285 if (ga_add_string(&sp->buflines, line) == FAIL) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1286 goto errret; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1287 line = NULL; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1288 } |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1289 sp->buf_lnum = 0; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1290 sp->source_from_buf = TRUE; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1291 |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1292 return fname; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1293 |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1294 errret: |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1295 vim_free(fname); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1296 vim_free(line); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1297 ga_clear_strings(&sp->buflines); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1298 return NULL; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1299 } |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1300 |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1301 /* |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1302 * Read the file "fname" and execute its lines as EX commands. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1303 * When "ret_sid" is not NULL and we loaded the script before, don't load it |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1304 * again. |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1305 * |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1306 * The 'eap' argument is used when sourcing lines from a buffer instead of a |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1307 * file. |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1308 * |
28164
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1309 * If 'clearvars' is TRUE, then for scripts which are loaded more than |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1310 * once, clear all the functions and variables previously defined in that |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1311 * script. |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1312 * |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 * This function may be called recursively! |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1314 * |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1315 * Return FAIL if file could not be opened, OK otherwise. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1316 * If a scriptitem_T was found or created "*ret_sid" is set to the SID. |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 */ |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1318 static int |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1319 do_source_ext( |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1320 char_u *fname, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1321 int check_other, // check for .vimrc and _vimrc |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1322 int is_vimrc, // DOSO_ value |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1323 int *ret_sid UNUSED, |
28164
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1324 exarg_T *eap, |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1325 int clearvars UNUSED) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 { |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
1327 source_cookie_T cookie; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1328 char_u *p; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 char_u *fname_exp; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 char_u *firstline = NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 int retval = FAIL; |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23386
diff
changeset
|
1332 sctx_T save_current_sctx; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 #ifdef FEAT_EVAL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1334 funccal_entry_T funccalp_entry; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1335 int save_debug_break_level = debug_break_level; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1336 int sid; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1337 scriptitem_T *si = NULL; |
24876
c4ad84c7e15f
patch 8.2.2976: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
1338 int save_estack_compiling = estack_compiling; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1339 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1340 #ifdef STARTUPTIME |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1341 struct timeval tv_rel; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1342 struct timeval tv_start; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1343 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1344 #ifdef FEAT_PROFILE |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1345 proftime_T wait_start; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1346 #endif |
27663
df84fac1e9a4
patch 8.2.4357: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27619
diff
changeset
|
1347 int save_sticky_cmdmod_flags = sticky_cmdmod_flags; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1348 int trigger_source_post = FALSE; |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
19061
diff
changeset
|
1349 ESTACK_CHECK_DECLARATION |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1350 |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1351 CLEAR_FIELD(cookie); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1352 if (fname == NULL) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1353 { |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1354 // sourcing lines from a buffer |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1355 fname_exp = do_source_buffer_init(&cookie, eap); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1356 if (fname_exp == NULL) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1357 return FAIL; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1358 } |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1359 else |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1360 { |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1361 p = expand_env_save(fname); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1362 if (p == NULL) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1363 return retval; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1364 fname_exp = fix_fname(p); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1365 vim_free(p); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1366 if (fname_exp == NULL) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1367 return retval; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1368 if (mch_isdir(fname_exp)) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1369 { |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1370 smsg(_("Cannot source a directory: \"%s\""), fname); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1371 goto theend; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1372 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 } |
24876
c4ad84c7e15f
patch 8.2.2976: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
1374 #ifdef FEAT_EVAL |
24874
14b0b35d8488
patch 8.2.2975: Vim9: can only use an autoload function name as a string
Bram Moolenaar <Bram@vim.org>
parents:
24786
diff
changeset
|
1375 estack_compiling = FALSE; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1377 // See if we loaded this script before. |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1378 sid = find_script_by_name(fname_exp); |
27078
94e38672014a
patch 8.2.4068: Vim9: import test fails
Bram Moolenaar <Bram@vim.org>
parents:
27055
diff
changeset
|
1379 if (sid > 0 && ret_sid != NULL |
94e38672014a
patch 8.2.4068: Vim9: import test fails
Bram Moolenaar <Bram@vim.org>
parents:
27055
diff
changeset
|
1380 && SCRIPT_ITEM(sid)->sn_state != SN_STATE_NOT_LOADED) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1381 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1382 // Already loaded and no need to load again, return here. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1383 *ret_sid = sid; |
19685
d64f403289db
patch 8.2.0399: various memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19507
diff
changeset
|
1384 retval = OK; |
d64f403289db
patch 8.2.0399: various memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19507
diff
changeset
|
1385 goto theend; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1386 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1387 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1388 |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1389 // Apply SourceCmd autocommands, they should get the file and source it. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 && apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 FALSE, curbuf)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1393 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1394 #ifdef FEAT_EVAL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 retval = aborting() ? FAIL : OK; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 #else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 retval = OK; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 if (retval == OK) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 // Apply SourcePost autocommands. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1402 FALSE, curbuf); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1403 goto theend; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1404 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 // Apply SourcePre autocommands, they may get the file. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1408 |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1409 if (!cookie.source_from_buf) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1410 { |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1411 #ifdef USE_FOPEN_NOINH |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1412 cookie.fp = fopen_noinh_readbin((char *)fname_exp); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 #else |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1414 cookie.fp = mch_fopen((char *)fname_exp, READBIN); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 #endif |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1416 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1417 if (cookie.fp == NULL && check_other) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1418 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1419 // Try again, replacing file name ".vimrc" by "_vimrc" or vice versa, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1420 // and ".exrc" by "_exrc" or vice versa. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1421 p = gettail(fname_exp); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 if ((*p == '.' || *p == '_') |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1423 && (STRICMP(p + 1, "vimrc") == 0 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1424 || STRICMP(p + 1, "gvimrc") == 0 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 || STRICMP(p + 1, "exrc") == 0)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 if (*p == '_') |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 *p = '.'; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 *p = '_'; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1431 #ifdef USE_FOPEN_NOINH |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 cookie.fp = fopen_noinh_readbin((char *)fname_exp); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 #else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 cookie.fp = mch_fopen((char *)fname_exp, READBIN); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1436 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1439 if (cookie.fp == NULL && !cookie.source_from_buf) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 if (p_verbose > 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1442 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1443 verbose_enter(); |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
1444 if (SOURCING_NAME == NULL) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 smsg(_("could not source \"%s\""), fname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1446 else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1447 smsg(_("line %ld: could not source \"%s\""), |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
1448 SOURCING_LNUM, fname); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1449 verbose_leave(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1450 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 goto theend; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1452 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1453 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1454 // The file exists. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1455 // - In verbose mode, give a message. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 // - For a vimrc file, may want to set 'compatible', call vimrc_found(). |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 if (p_verbose > 1) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1458 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1459 verbose_enter(); |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
1460 if (SOURCING_NAME == NULL) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 smsg(_("sourcing \"%s\""), fname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 else |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
1463 smsg(_("line %ld: sourcing \"%s\""), SOURCING_LNUM, fname); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 verbose_leave(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1465 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 if (is_vimrc == DOSO_VIMRC) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 vimrc_found(fname_exp, (char_u *)"MYVIMRC"); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 else if (is_vimrc == DOSO_GVIMRC) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1469 vimrc_found(fname_exp, (char_u *)"MYGVIMRC"); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1470 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 #ifdef USE_CRNL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 // If no automatic file format: Set default to CR-NL. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 if (*p_ffs == NUL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1474 cookie.fileformat = EOL_DOS; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1476 cookie.fileformat = EOL_UNKNOWN; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1477 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1478 |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1479 if (fname == NULL) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1480 // When sourcing a range of lines from a buffer, use the buffer line |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1481 // number. |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1482 cookie.sourcing_lnum = eap->line1 - 1; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1483 else |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1484 cookie.sourcing_lnum = 0; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1485 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1486 #ifdef FEAT_EVAL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1487 // Check if this script has a breakpoint. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1488 cookie.breakpoint = dbg_find_breakpoint(TRUE, fname_exp, (linenr_T)0); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1489 cookie.fname = fname_exp; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 cookie.dbg_tick = debug_tick; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1491 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1492 cookie.level = ex_nesting_level; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1494 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1495 // Keep the sourcing name/lnum, for recursive calls. |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
1496 estack_push(ETYPE_SCRIPT, fname_exp, 0); |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
19061
diff
changeset
|
1497 ESTACK_CHECK_SETUP |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1498 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1499 #ifdef STARTUPTIME |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1500 if (time_fd != NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1501 time_push(&tv_rel, &tv_start); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1502 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1503 |
27663
df84fac1e9a4
patch 8.2.4357: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27619
diff
changeset
|
1504 // "legacy" does not apply to commands in the script |
df84fac1e9a4
patch 8.2.4357: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27619
diff
changeset
|
1505 sticky_cmdmod_flags = 0; |
df84fac1e9a4
patch 8.2.4357: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27619
diff
changeset
|
1506 |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23386
diff
changeset
|
1507 save_current_sctx = current_sctx; |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1508 if (cmdmod.cmod_flags & CMOD_VIM9CMD) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1509 // When the ":vim9cmd" command modifier is used, source the script as a |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1510 // Vim9 script. |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1511 current_sctx.sc_version = SCRIPT_VERSION_VIM9; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1512 else |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1513 current_sctx.sc_version = 1; // default script version |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23386
diff
changeset
|
1514 |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1515 #ifdef FEAT_EVAL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1516 # ifdef FEAT_PROFILE |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1517 if (do_profiling == PROF_YES) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1518 prof_child_enter(&wait_start); // entering a child now |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1519 # endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1520 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 // Don't use local function variables, if called from a function. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1522 // Also starts profiling timer for nested script. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1523 save_funccal(&funccalp_entry); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1524 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1525 current_sctx.sc_lnum = 0; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1526 |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26745
diff
changeset
|
1527 // Check if this script was sourced before to find its SID. |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1528 // Always use a new sequence number. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1529 current_sctx.sc_seq = ++last_current_SID_seq; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1530 if (sid > 0) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1531 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1532 hashtab_T *ht; |
23358
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23330
diff
changeset
|
1533 int todo; |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23330
diff
changeset
|
1534 hashitem_T *hi; |
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23330
diff
changeset
|
1535 dictitem_T *di; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1536 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1537 // loading the same script again |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1538 current_sctx.sc_sid = sid; |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1539 si = SCRIPT_ITEM(sid); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1540 if (si->sn_state == SN_STATE_NOT_LOADED) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1541 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1542 // this script was found but not loaded yet |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1543 si->sn_state = SN_STATE_NEW; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1544 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1545 else |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1546 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1547 si->sn_state = SN_STATE_RELOAD; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1548 |
28164
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1549 if (!clearvars) |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1550 { |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1551 // Script-local variables remain but "const" can be set again. |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1552 // In Vim9 script variables will be cleared when "vim9script" |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1553 // is encountered without the "noclear" argument. |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1554 ht = &SCRIPT_VARS(sid); |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1555 todo = (int)ht->ht_used; |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1556 for (hi = ht->ht_array; todo > 0; ++hi) |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1557 if (!HASHITEM_EMPTY(hi)) |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1558 { |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1559 --todo; |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1560 di = HI2DI(hi); |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1561 di->di_flags |= DI_FLAGS_RELOAD; |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1562 } |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1563 // imports can be redefined once |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1564 mark_imports_for_reload(sid); |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1565 } |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1566 else |
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1567 clear_vim9_scriptlocal_vars(sid); |
23886
eef0cffbdb94
patch 8.2.2485: when sourcing a script again the script version isn't reset
Bram Moolenaar <Bram@vim.org>
parents:
23580
diff
changeset
|
1568 |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1569 // reset version, "vim9script" may have been added or removed. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1570 si->sn_version = 1; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1571 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1572 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1573 else |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1574 { |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1575 int error = OK; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1576 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1577 // It's new, generate a new SID and initialize the scriptitem. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1578 current_sctx.sc_sid = get_new_scriptitem(&error); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1579 if (error == FAIL) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1580 goto almosttheend; |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1581 si = SCRIPT_ITEM(current_sctx.sc_sid); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1582 si->sn_name = fname_exp; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1583 fname_exp = vim_strsave(si->sn_name); // used for autocmd |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1584 if (ret_sid != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1585 *ret_sid = current_sctx.sc_sid; |
23358
b3142fc0a414
patch 8.2.2222: Vim9: cannot keep script variables when reloading
Bram Moolenaar <Bram@vim.org>
parents:
23330
diff
changeset
|
1586 |
26745
dcd1c244e332
patch 8.2.3901: Vim9: Cannot set 'cpo' in main .vimrc if using Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
26230
diff
changeset
|
1587 // Remember the "is_vimrc" flag for when the file is sourced again. |
dcd1c244e332
patch 8.2.3901: Vim9: Cannot set 'cpo' in main .vimrc if using Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
26230
diff
changeset
|
1588 si->sn_is_vimrc = is_vimrc; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1589 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1590 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1591 # ifdef FEAT_PROFILE |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1592 if (do_profiling == PROF_YES) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1593 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1594 int forceit; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1595 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1596 // Check if we do profiling for this script. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1597 if (!si->sn_prof_on && has_profiling(TRUE, si->sn_name, &forceit)) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1598 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1599 script_do_profile(si); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1600 si->sn_pr_force = forceit; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1601 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1602 if (si->sn_prof_on) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1603 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1604 ++si->sn_pr_count; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1605 profile_start(&si->sn_pr_start); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1606 profile_zero(&si->sn_pr_children); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1607 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1608 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1609 # endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1610 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1611 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1612 cookie.conv.vc_type = CONV_NONE; // no conversion |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1613 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1614 // Read the first line so we can check for a UTF-8 BOM. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1615 firstline = getsourceline(0, (void *)&cookie, 0, TRUE); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1616 if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1617 && firstline[1] == 0xbb && firstline[2] == 0xbf) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1618 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1619 // Found BOM; setup conversion, skip over BOM and recode the line. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1620 convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1621 p = string_convert(&cookie.conv, firstline + 3, NULL); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1622 if (p == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1623 p = vim_strsave(firstline + 3); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1624 if (p != NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1625 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 vim_free(firstline); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1627 firstline = p; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1628 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1629 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1630 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1631 // Call do_cmdline, which will call getsourceline() to get the lines. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1632 do_cmdline(firstline, getsourceline, (void *)&cookie, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1633 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1634 retval = OK; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1635 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1636 #ifdef FEAT_PROFILE |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1637 if (do_profiling == PROF_YES) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1638 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1639 // Get "si" again, "script_items" may have been reallocated. |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1640 si = SCRIPT_ITEM(current_sctx.sc_sid); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1641 if (si->sn_prof_on) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1642 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1643 profile_end(&si->sn_pr_start); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1644 profile_sub_wait(&wait_start, &si->sn_pr_start); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1645 profile_add(&si->sn_pr_total, &si->sn_pr_start); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1646 profile_self(&si->sn_pr_self, &si->sn_pr_start, |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1647 &si->sn_pr_children); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1648 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1649 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1650 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1651 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1652 if (got_int) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
1653 emsg(_(e_interrupted)); |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
19061
diff
changeset
|
1654 ESTACK_CHECK_NOW |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
1655 estack_pop(); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1656 if (p_verbose > 1) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1657 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1658 verbose_enter(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1659 smsg(_("finished sourcing %s"), fname); |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
1660 if (SOURCING_NAME != NULL) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
1661 smsg(_("continuing in %s"), SOURCING_NAME); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1662 verbose_leave(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1663 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1664 #ifdef STARTUPTIME |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1665 if (time_fd != NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1666 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1667 vim_snprintf((char *)IObuff, IOSIZE, "sourcing %s", fname); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1668 time_msg((char *)IObuff, &tv_start); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1669 time_pop(&tv_rel); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1670 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1671 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1672 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1673 if (!got_int) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1674 trigger_source_post = TRUE; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1675 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1676 #ifdef FEAT_EVAL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1677 // After a "finish" in debug mode, need to break at first command of next |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1678 // sourced file. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1679 if (save_debug_break_level > ex_nesting_level |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1680 && debug_break_level == ex_nesting_level) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1681 ++debug_break_level; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1682 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1683 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1684 #ifdef FEAT_EVAL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1685 almosttheend: |
26745
dcd1c244e332
patch 8.2.3901: Vim9: Cannot set 'cpo' in main .vimrc if using Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
26230
diff
changeset
|
1686 // If "sn_save_cpo" is set that means we encountered "vim9script": restore |
dcd1c244e332
patch 8.2.3901: Vim9: Cannot set 'cpo' in main .vimrc if using Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
26230
diff
changeset
|
1687 // 'cpoptions', unless in the main .vimrc file. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1688 // Get "si" again, "script_items" may have been reallocated. |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1689 si = SCRIPT_ITEM(current_sctx.sc_sid); |
26745
dcd1c244e332
patch 8.2.3901: Vim9: Cannot set 'cpo' in main .vimrc if using Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
26230
diff
changeset
|
1690 if (si->sn_save_cpo != NULL && si->sn_is_vimrc == DOSO_NONE) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1691 { |
24150
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1692 if (STRCMP(p_cpo, CPO_VIM) != 0) |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1693 { |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1694 char_u *f; |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1695 char_u *t; |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1696 |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1697 // 'cpo' was changed in the script. Apply the same change to the |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1698 // saved value, if possible. |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1699 for (f = (char_u *)CPO_VIM; *f != NUL; ++f) |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1700 if (vim_strchr(p_cpo, *f) == NULL |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1701 && (t = vim_strchr(si->sn_save_cpo, *f)) != NULL) |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1702 // flag was removed, also remove it from the saved 'cpo' |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1703 mch_memmove(t, t + 1, STRLEN(t)); |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1704 for (f = p_cpo; *f != NUL; ++f) |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1705 if (vim_strchr((char_u *)CPO_VIM, *f) == NULL |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1706 && vim_strchr(si->sn_save_cpo, *f) == NULL) |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1707 { |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1708 // flag was added, also add it to the saved 'cpo' |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1709 t = alloc(STRLEN(si->sn_save_cpo) + 2); |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1710 if (t != NULL) |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1711 { |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1712 *t = *f; |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1713 STRCPY(t + 1, si->sn_save_cpo); |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1714 vim_free(si->sn_save_cpo); |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1715 si->sn_save_cpo = t; |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1716 } |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1717 } |
4919f2d8d7fd
patch 8.2.2616: Vim9: if 'cpo' is change in Vim9 script it may be restored
Bram Moolenaar <Bram@vim.org>
parents:
24079
diff
changeset
|
1718 } |
24079
a9ff8368d35f
patch 8.2.2581: Vim9: sourcing Vim9 script triggers a redraw
Bram Moolenaar <Bram@vim.org>
parents:
23886
diff
changeset
|
1719 set_option_value((char_u *)"cpo", 0L, si->sn_save_cpo, OPT_NO_REDRAW); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1720 } |
26745
dcd1c244e332
patch 8.2.3901: Vim9: Cannot set 'cpo' in main .vimrc if using Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
26230
diff
changeset
|
1721 VIM_CLEAR(si->sn_save_cpo); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1722 |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1723 restore_funccal(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1724 # ifdef FEAT_PROFILE |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1725 if (do_profiling == PROF_YES) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1726 prof_child_exit(&wait_start); // leaving a child now |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1727 # endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1728 #endif |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23386
diff
changeset
|
1729 current_sctx = save_current_sctx; |
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23386
diff
changeset
|
1730 |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1731 if (cookie.fp != NULL) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1732 fclose(cookie.fp); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1733 if (cookie.source_from_buf) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1734 ga_clear_strings(&cookie.buflines); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1735 vim_free(cookie.nextline); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1736 vim_free(firstline); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1737 convert_setup(&cookie.conv, NULL, NULL); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1738 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1739 if (trigger_source_post) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1740 apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp, FALSE, curbuf); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1741 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1742 theend: |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1743 vim_free(fname_exp); |
27663
df84fac1e9a4
patch 8.2.4357: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27619
diff
changeset
|
1744 sticky_cmdmod_flags = save_sticky_cmdmod_flags; |
24876
c4ad84c7e15f
patch 8.2.2976: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
1745 #ifdef FEAT_EVAL |
24874
14b0b35d8488
patch 8.2.2975: Vim9: can only use an autoload function name as a string
Bram Moolenaar <Bram@vim.org>
parents:
24786
diff
changeset
|
1746 estack_compiling = save_estack_compiling; |
24876
c4ad84c7e15f
patch 8.2.2976: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
24874
diff
changeset
|
1747 #endif |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1748 return retval; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1749 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1750 |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1751 int |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1752 do_source( |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1753 char_u *fname, |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1754 int check_other, // check for .vimrc and _vimrc |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1755 int is_vimrc, // DOSO_ value |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1756 int *ret_sid UNUSED) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1757 { |
28164
b0b712d48225
patch 8.2.4607: sourcing buffer lines may lead to errors for conflicts
Bram Moolenaar <Bram@vim.org>
parents:
28158
diff
changeset
|
1758 return do_source_ext(fname, check_other, is_vimrc, ret_sid, NULL, FALSE); |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1759 } |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1760 |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1761 |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1762 #if defined(FEAT_EVAL) || defined(PROTO) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1763 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1764 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1765 * ":scriptnames" |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1766 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1767 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1768 ex_scriptnames(exarg_T *eap) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1769 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1770 int i; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1771 |
28183
2b595cee4c85
patch 8.2.4617: no completion for :scriptnames
Bram Moolenaar <Bram@vim.org>
parents:
28164
diff
changeset
|
1772 if (eap->addr_count > 0 || *eap->arg != NUL) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1773 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1774 // :script {scriptId}: edit the script |
28183
2b595cee4c85
patch 8.2.4617: no completion for :scriptnames
Bram Moolenaar <Bram@vim.org>
parents:
28164
diff
changeset
|
1775 if (eap->addr_count > 0 && !SCRIPT_ID_VALID(eap->line2)) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
1776 emsg(_(e_invalid_argument)); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1777 else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1778 { |
28183
2b595cee4c85
patch 8.2.4617: no completion for :scriptnames
Bram Moolenaar <Bram@vim.org>
parents:
28164
diff
changeset
|
1779 if (eap->addr_count > 0) |
2b595cee4c85
patch 8.2.4617: no completion for :scriptnames
Bram Moolenaar <Bram@vim.org>
parents:
28164
diff
changeset
|
1780 eap->arg = SCRIPT_ITEM(eap->line2)->sn_name; |
2b595cee4c85
patch 8.2.4617: no completion for :scriptnames
Bram Moolenaar <Bram@vim.org>
parents:
28164
diff
changeset
|
1781 else |
2b595cee4c85
patch 8.2.4617: no completion for :scriptnames
Bram Moolenaar <Bram@vim.org>
parents:
28164
diff
changeset
|
1782 { |
2b595cee4c85
patch 8.2.4617: no completion for :scriptnames
Bram Moolenaar <Bram@vim.org>
parents:
28164
diff
changeset
|
1783 expand_env(eap->arg, NameBuff, MAXPATHL); |
2b595cee4c85
patch 8.2.4617: no completion for :scriptnames
Bram Moolenaar <Bram@vim.org>
parents:
28164
diff
changeset
|
1784 eap->arg = NameBuff; |
2b595cee4c85
patch 8.2.4617: no completion for :scriptnames
Bram Moolenaar <Bram@vim.org>
parents:
28164
diff
changeset
|
1785 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1786 do_exedit(eap, NULL); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1787 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1788 return; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1789 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1790 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1791 for (i = 1; i <= script_items.ga_len && !got_int; ++i) |
27213
42561e956a70
patch 8.2.4135: Vim9: ":scriptnames" shows unloaded imported autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
1792 { |
42561e956a70
patch 8.2.4135: Vim9: ":scriptnames" shows unloaded imported autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
1793 scriptitem_T *si = SCRIPT_ITEM(i); |
42561e956a70
patch 8.2.4135: Vim9: ":scriptnames" shows unloaded imported autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
1794 |
42561e956a70
patch 8.2.4135: Vim9: ":scriptnames" shows unloaded imported autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
1795 if (si->sn_name != NULL) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1796 { |
27213
42561e956a70
patch 8.2.4135: Vim9: ":scriptnames" shows unloaded imported autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
1797 home_replace(NULL, si->sn_name, NameBuff, MAXPATHL, TRUE); |
42561e956a70
patch 8.2.4135: Vim9: ":scriptnames" shows unloaded imported autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
1798 vim_snprintf((char *)IObuff, IOSIZE, "%3d%s: %s", |
42561e956a70
patch 8.2.4135: Vim9: ":scriptnames" shows unloaded imported autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
1799 i, |
42561e956a70
patch 8.2.4135: Vim9: ":scriptnames" shows unloaded imported autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
1800 si->sn_state == SN_STATE_NOT_LOADED ? " A" : "", |
42561e956a70
patch 8.2.4135: Vim9: ":scriptnames" shows unloaded imported autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
1801 NameBuff); |
27619
fa7ac1e66026
patch 8.2.4336: using :filter for :scriptnames does not work
Bram Moolenaar <Bram@vim.org>
parents:
27495
diff
changeset
|
1802 if (!message_filtered(IObuff)) |
fa7ac1e66026
patch 8.2.4336: using :filter for :scriptnames does not work
Bram Moolenaar <Bram@vim.org>
parents:
27495
diff
changeset
|
1803 { |
fa7ac1e66026
patch 8.2.4336: using :filter for :scriptnames does not work
Bram Moolenaar <Bram@vim.org>
parents:
27495
diff
changeset
|
1804 msg_putchar('\n'); |
fa7ac1e66026
patch 8.2.4336: using :filter for :scriptnames does not work
Bram Moolenaar <Bram@vim.org>
parents:
27495
diff
changeset
|
1805 msg_outtrans(IObuff); |
fa7ac1e66026
patch 8.2.4336: using :filter for :scriptnames does not work
Bram Moolenaar <Bram@vim.org>
parents:
27495
diff
changeset
|
1806 out_flush(); // output one line at a time |
fa7ac1e66026
patch 8.2.4336: using :filter for :scriptnames does not work
Bram Moolenaar <Bram@vim.org>
parents:
27495
diff
changeset
|
1807 ui_breakcheck(); |
fa7ac1e66026
patch 8.2.4336: using :filter for :scriptnames does not work
Bram Moolenaar <Bram@vim.org>
parents:
27495
diff
changeset
|
1808 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1809 } |
27213
42561e956a70
patch 8.2.4135: Vim9: ":scriptnames" shows unloaded imported autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27209
diff
changeset
|
1810 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1811 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1812 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1813 # if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1814 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1815 * Fix slashes in the list of script names for 'shellslash'. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1816 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1817 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1818 scriptnames_slash_adjust(void) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1819 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1820 int i; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1821 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1822 for (i = 1; i <= script_items.ga_len; ++i) |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1823 if (SCRIPT_ITEM(i)->sn_name != NULL) |
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1824 slash_adjust(SCRIPT_ITEM(i)->sn_name); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1825 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1826 # endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1827 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1828 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1829 * Get a pointer to a script name. Used for ":verbose set". |
23386
3105546b941f
patch 8.2.2236: 'scroll' option can change when setting the statusline
Bram Moolenaar <Bram@vim.org>
parents:
23366
diff
changeset
|
1830 * Message appended to "Last set from " |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1831 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1832 char_u * |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1833 get_scriptname(scid_T id) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1834 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1835 if (id == SID_MODELINE) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1836 return (char_u *)_("modeline"); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1837 if (id == SID_CMDARG) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1838 return (char_u *)_("--cmd argument"); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1839 if (id == SID_CARG) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1840 return (char_u *)_("-c argument"); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1841 if (id == SID_ENV) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1842 return (char_u *)_("environment variable"); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1843 if (id == SID_ERROR) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1844 return (char_u *)_("error handler"); |
23386
3105546b941f
patch 8.2.2236: 'scroll' option can change when setting the statusline
Bram Moolenaar <Bram@vim.org>
parents:
23366
diff
changeset
|
1845 if (id == SID_WINLAYOUT) |
3105546b941f
patch 8.2.2236: 'scroll' option can change when setting the statusline
Bram Moolenaar <Bram@vim.org>
parents:
23366
diff
changeset
|
1846 return (char_u *)_("changed window size"); |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1847 return SCRIPT_ITEM(id)->sn_name; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1848 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1849 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1850 # if defined(EXITFREE) || defined(PROTO) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1851 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1852 free_scriptnames(void) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1853 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1854 int i; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1855 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1856 for (i = script_items.ga_len; i > 0; --i) |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
1857 { |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1858 scriptitem_T *si = SCRIPT_ITEM(i); |
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1859 |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1860 // the variables themselves are cleared in evalvars_clear() |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1861 vim_free(si->sn_vars); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
1862 |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1863 vim_free(si->sn_name); |
22594
209c7aa56325
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Bram Moolenaar <Bram@vim.org>
parents:
22218
diff
changeset
|
1864 free_imports_and_script_vars(i); |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1865 free_string_option(si->sn_save_cpo); |
18410
b5b2e3b824c2
patch 8.1.2199: build failure when using normal features without GUI
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
1866 # ifdef FEAT_PROFILE |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1867 ga_clear(&si->sn_prl_ga); |
18410
b5b2e3b824c2
patch 8.1.2199: build failure when using normal features without GUI
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
1868 # endif |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
1869 vim_free(si->sn_autoload_prefix); |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
1870 vim_free(si); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18080
diff
changeset
|
1871 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1872 ga_clear(&script_items); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1873 } |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
1874 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
1875 void |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
1876 free_autoload_scriptnames(void) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
1877 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
1878 ga_clear_strings(&ga_loaded); |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
1879 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1880 # endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1881 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1882 linenr_T |
21883
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21865
diff
changeset
|
1883 get_sourced_lnum( |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21865
diff
changeset
|
1884 char_u *(*fgetline)(int, void *, int, getline_opt_T), |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21865
diff
changeset
|
1885 void *cookie) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1886 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1887 return fgetline == getsourceline |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
1888 ? ((source_cookie_T *)cookie)->sourcing_lnum |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
1889 : SOURCING_LNUM; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1890 } |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1891 #endif |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1892 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1893 static char_u * |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
1894 get_one_sourceline(source_cookie_T *sp) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1895 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1896 garray_T ga; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1897 int len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1898 int c; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1899 char_u *buf; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1900 #ifdef USE_CRNL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1901 int has_cr; // CR-LF found |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1902 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1903 int have_read = FALSE; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1904 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1905 // use a growarray to store the sourced line |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1906 ga_init2(&ga, 1, 250); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1907 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1908 // Loop until there is a finished line (or end-of-file). |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1909 ++sp->sourcing_lnum; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1910 for (;;) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1911 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1912 // make room to read at least 120 (more) characters |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1913 if (ga_grow(&ga, 120) == FAIL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1914 break; |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1915 if (sp->source_from_buf) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1916 { |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1917 if (sp->buf_lnum >= sp->buflines.ga_len) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1918 break; // all the lines are processed |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1919 ga_concat(&ga, ((char_u **)sp->buflines.ga_data)[sp->buf_lnum]); |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1920 sp->buf_lnum++; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1921 buf = (char_u *)ga.ga_data; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1922 } |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1923 else |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1924 { |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1925 buf = (char_u *)ga.ga_data; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1926 if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len, |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1927 sp->fp) == NULL) |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1928 break; |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
1929 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1930 len = ga.ga_len + (int)STRLEN(buf + ga.ga_len); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 #ifdef USE_CRNL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1932 // Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1933 // CTRL-Z by its own, or after a NL. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1934 if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n')) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1935 && sp->fileformat == EOL_DOS |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1936 && buf[len - 1] == Ctrl_Z) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1937 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1938 buf[len - 1] = NUL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1939 break; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1940 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1941 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1942 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1943 have_read = TRUE; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1944 ga.ga_len = len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1945 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1946 // If the line was longer than the buffer, read more. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1947 if (ga.ga_maxlen - ga.ga_len == 1 && buf[len - 1] != '\n') |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1948 continue; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1949 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1950 if (len >= 1 && buf[len - 1] == '\n') // remove trailing NL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1951 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1952 #ifdef USE_CRNL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1953 has_cr = (len >= 2 && buf[len - 2] == '\r'); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1954 if (sp->fileformat == EOL_UNKNOWN) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1955 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1956 if (has_cr) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1957 sp->fileformat = EOL_DOS; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1958 else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1959 sp->fileformat = EOL_UNIX; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1960 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1961 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1962 if (sp->fileformat == EOL_DOS) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1963 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1964 if (has_cr) // replace trailing CR |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1965 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1966 buf[len - 2] = '\n'; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1967 --len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1968 --ga.ga_len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1969 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1970 else // lines like ":map xx yy^M" will have failed |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1971 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1972 if (!sp->error) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1973 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1974 msg_source(HL_ATTR(HLF_W)); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1975 emsg(_("W15: Warning: Wrong line separator, ^M may be missing")); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1976 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1977 sp->error = TRUE; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1978 sp->fileformat = EOL_UNIX; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1979 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1980 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1981 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1982 // The '\n' is escaped if there is an odd number of ^V's just |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1983 // before it, first set "c" just before the 'V's and then check |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1984 // len&c parities (is faster than ((len-c)%2 == 0)) -- Acevedo |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1985 for (c = len - 2; c >= 0 && buf[c] == Ctrl_V; c--) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1986 ; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1987 if ((len & 1) != (c & 1)) // escaped NL, read more |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1988 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1989 ++sp->sourcing_lnum; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1990 continue; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1991 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1992 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1993 buf[len - 1] = NUL; // remove the NL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1994 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1995 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1996 // Check for ^C here now and then, so recursive :so can be broken. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1997 line_breakcheck(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1998 break; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1999 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2000 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2001 if (have_read) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2002 return (char_u *)ga.ga_data; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2003 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2004 vim_free(ga.ga_data); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2005 return NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2006 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2007 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2008 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2009 * Get one full line from a sourced file. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2010 * Called by do_cmdline() when it's called from do_source(). |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2011 * |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2012 * Return a pointer to the line in allocated memory. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2013 * Return NULL for end-of-file or some error. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2014 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2015 char_u * |
21883
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21865
diff
changeset
|
2016 getsourceline( |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21865
diff
changeset
|
2017 int c UNUSED, |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21865
diff
changeset
|
2018 void *cookie, |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21865
diff
changeset
|
2019 int indent UNUSED, |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21865
diff
changeset
|
2020 getline_opt_T options) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2021 { |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
2022 source_cookie_T *sp = (source_cookie_T *)cookie; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2023 char_u *line; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2024 char_u *p; |
23392
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2025 int do_vim9_all = in_vim9script() |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2026 && options == GETLINE_CONCAT_ALL; |
23398
40f824f5c7c7
patch 8.2.2242: Vim9: bar line continuation does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
23392
diff
changeset
|
2027 int do_bar_cont = do_vim9_all |
40f824f5c7c7
patch 8.2.2242: Vim9: bar line continuation does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
23392
diff
changeset
|
2028 || options == GETLINE_CONCAT_CONTBAR; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2029 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2030 #ifdef FEAT_EVAL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2031 // If breakpoints have been added/deleted need to check for it. |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
2032 if ((sp->dbg_tick < debug_tick) && !sp->source_from_buf) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2033 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
2034 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, SOURCING_LNUM); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2035 sp->dbg_tick = debug_tick; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2036 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2037 # ifdef FEAT_PROFILE |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2038 if (do_profiling == PROF_YES) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2039 script_line_end(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2040 # endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2041 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2042 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2043 // Set the current sourcing line number. |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
2044 SOURCING_LNUM = sp->sourcing_lnum + 1; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2045 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2046 // Get current line. If there is a read-ahead line, use it, otherwise get |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
2047 // one now. "fp" is NULL if actually using a string. |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
2048 if (sp->finished || (!sp->source_from_buf && sp->fp == NULL)) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2049 line = NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2050 else if (sp->nextline == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2051 line = get_one_sourceline(sp); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2052 else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2053 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2054 line = sp->nextline; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2055 sp->nextline = NULL; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2056 ++sp->sourcing_lnum; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2057 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2058 #ifdef FEAT_PROFILE |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2059 if (line != NULL && do_profiling == PROF_YES) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2060 script_line_start(); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2061 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2062 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2063 // Only concatenate lines starting with a \ when 'cpoptions' doesn't |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2064 // contain the 'C' flag. |
21883
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21865
diff
changeset
|
2065 if (line != NULL && options != GETLINE_NONE |
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21865
diff
changeset
|
2066 && vim_strchr(p_cpo, CPO_CONCAT) == NULL) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2067 { |
24786
524120691c3d
patch 8.2.2931: Vim9: line continuation comment uses legacy syntax
Bram Moolenaar <Bram@vim.org>
parents:
24774
diff
changeset
|
2068 int comment_char = in_vim9script() ? '#' : '"'; |
524120691c3d
patch 8.2.2931: Vim9: line continuation comment uses legacy syntax
Bram Moolenaar <Bram@vim.org>
parents:
24774
diff
changeset
|
2069 |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2070 // compensate for the one line read-ahead |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2071 --sp->sourcing_lnum; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2072 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2073 // Get the next line and concatenate it when it starts with a |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2074 // backslash. We always need to read the next line, keep it in |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2075 // sp->nextline. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2076 /* Also check for a comment in between continuation lines: "\ */ |
23392
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2077 // Also check for a Vim9 comment, empty line, line starting with '|', |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2078 // but not "||". |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2079 sp->nextline = get_one_sourceline(sp); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2080 if (sp->nextline != NULL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2081 && (*(p = skipwhite(sp->nextline)) == '\\' |
24786
524120691c3d
patch 8.2.2931: Vim9: line continuation comment uses legacy syntax
Bram Moolenaar <Bram@vim.org>
parents:
24774
diff
changeset
|
2082 || (p[0] == comment_char |
524120691c3d
patch 8.2.2931: Vim9: line continuation comment uses legacy syntax
Bram Moolenaar <Bram@vim.org>
parents:
24774
diff
changeset
|
2083 && p[1] == '\\' && p[2] == ' ') |
23392
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2084 || (do_vim9_all && (*p == NUL |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2085 || vim9_comment_start(p))) |
23398
40f824f5c7c7
patch 8.2.2242: Vim9: bar line continuation does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
23392
diff
changeset
|
2086 || (do_bar_cont && p[0] == '|' && p[1] != '|'))) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2087 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2088 garray_T ga; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2089 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
2090 ga_init2(&ga, sizeof(char_u), 400); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2091 ga_concat(&ga, line); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2092 if (*p == '\\') |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2093 ga_concat(&ga, p + 1); |
23392
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2094 else if (*p == '|') |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2095 { |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2096 ga_concat(&ga, (char_u *)" "); |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2097 ga_concat(&ga, p); |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2098 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2099 for (;;) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2100 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2101 vim_free(sp->nextline); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2102 sp->nextline = get_one_sourceline(sp); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2103 if (sp->nextline == NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2104 break; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2105 p = skipwhite(sp->nextline); |
23398
40f824f5c7c7
patch 8.2.2242: Vim9: bar line continuation does not work at script level
Bram Moolenaar <Bram@vim.org>
parents:
23392
diff
changeset
|
2106 if (*p == '\\' || (do_bar_cont && p[0] == '|' && p[1] != '|')) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2107 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2108 // Adjust the growsize to the current length to speed up |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2109 // concatenating many lines. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2110 if (ga.ga_len > 400) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2111 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2112 if (ga.ga_len > 8000) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2113 ga.ga_growsize = 8000; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2114 else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2115 ga.ga_growsize = ga.ga_len; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2116 } |
23392
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2117 if (*p == '\\') |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2118 ga_concat(&ga, p + 1); |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2119 else |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2120 { |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2121 ga_concat(&ga, (char_u *)" "); |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2122 ga_concat(&ga, p); |
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2123 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2124 } |
24786
524120691c3d
patch 8.2.2931: Vim9: line continuation comment uses legacy syntax
Bram Moolenaar <Bram@vim.org>
parents:
24774
diff
changeset
|
2125 else if (!(p[0] == (comment_char) |
24774
8bf9726097d8
patch 8.2.2925: Vim9: line continuation comment uses legacy syntax
Bram Moolenaar <Bram@vim.org>
parents:
24150
diff
changeset
|
2126 && p[1] == '\\' && p[2] == ' ') |
23392
517fca70e084
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
2127 && !(do_vim9_all && (*p == NUL || vim9_comment_start(p)))) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2128 break; |
21385
54a304e4dc57
patch 8.2.1243: Vim9: cannot have a comment line halfway a list
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
2129 /* drop a # comment or "\ comment line */ |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2130 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2131 ga_append(&ga, NUL); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2132 vim_free(line); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2133 line = ga.ga_data; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2134 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2135 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2136 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2137 if (line != NULL && sp->conv.vc_type != CONV_NONE) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2138 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2139 char_u *s; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2140 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2141 // Convert the encoding of the script line. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2142 s = string_convert(&sp->conv, line, NULL); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2143 if (s != NULL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2144 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2145 vim_free(line); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2146 line = s; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2147 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2148 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2149 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2150 #ifdef FEAT_EVAL |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2151 // Did we encounter a breakpoint? |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
2152 if (!sp->source_from_buf && sp->breakpoint != 0 |
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
2153 && sp->breakpoint <= SOURCING_LNUM) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2154 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
2155 dbg_breakpoint(sp->fname, SOURCING_LNUM); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2156 // Find next breakpoint. |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18410
diff
changeset
|
2157 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, SOURCING_LNUM); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2158 sp->dbg_tick = debug_tick; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2159 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2160 #endif |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2161 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2162 return line; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2163 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2164 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2165 /* |
28139
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
2166 * Returns TRUE if sourcing a script either from a file or a buffer. |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
2167 * Otherwise returns FALSE. |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
2168 */ |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
2169 int |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
2170 sourcing_a_script(exarg_T *eap) |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
2171 { |
28158
e1d1fa6ba1ed
patch 8.2.4603: sourcing buffer lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
28139
diff
changeset
|
2172 return (getline_equal(eap->getline, eap->cookie, getsourceline)); |
28139
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
2173 } |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
2174 |
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
2175 /* |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2176 * ":scriptencoding": Set encoding conversion for a sourced script. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2177 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2178 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2179 ex_scriptencoding(exarg_T *eap) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2180 { |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
2181 source_cookie_T *sp; |
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
2182 char_u *name; |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2183 |
28139
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
2184 if (!sourcing_a_script(eap)) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2185 { |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
2186 emsg(_(e_scriptencoding_used_outside_of_sourced_file)); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2187 return; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2188 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2189 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2190 if (*eap->arg != NUL) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2191 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2192 name = enc_canonize(eap->arg); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2193 if (name == NULL) // out of memory |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2194 return; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2195 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2196 else |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2197 name = eap->arg; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2198 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2199 // Setup for conversion from the specified encoding to 'encoding'. |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
2200 sp = (source_cookie_T *)getline_cookie(eap->getline, eap->cookie); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2201 convert_setup(&sp->conv, name, p_enc); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2202 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2203 if (name != eap->arg) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2204 vim_free(name); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2205 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2206 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2207 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2208 * ":scriptversion": Set Vim script version for a sourced script. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2209 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2210 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2211 ex_scriptversion(exarg_T *eap UNUSED) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2212 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2213 int nr; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2214 |
28139
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
2215 if (!sourcing_a_script(eap)) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2216 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
2217 emsg(_(e_scriptversion_used_outside_of_sourced_file)); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2218 return; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2219 } |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21206
diff
changeset
|
2220 if (in_vim9script()) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
2221 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21753
diff
changeset
|
2222 emsg(_(e_cannot_use_scriptversion_after_vim9script)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
2223 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19145
diff
changeset
|
2224 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2225 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2226 nr = getdigits(&eap->arg); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2227 if (nr == 0 || *eap->arg != NUL) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
2228 emsg(_(e_invalid_argument)); |
20945
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20921
diff
changeset
|
2229 else if (nr > SCRIPT_VERSION_MAX) |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
2230 semsg(_(e_scriptversion_not_supported_nr), nr); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2231 else |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2232 { |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2233 current_sctx.sc_version = nr; |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23386
diff
changeset
|
2234 #ifdef FEAT_EVAL |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19185
diff
changeset
|
2235 SCRIPT_ITEM(current_sctx.sc_sid)->sn_version = nr; |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
23386
diff
changeset
|
2236 #endif |
19108
44c6498535c9
patch 8.2.0114: info about sourced scripts is scattered
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2237 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2238 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2239 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2240 #if defined(FEAT_EVAL) || defined(PROTO) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2241 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2242 * ":finish": Mark a sourced file as finished. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2243 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2244 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2245 ex_finish(exarg_T *eap) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2246 { |
28139
f34afadbef47
patch 8.2.4594: need to write script to a file to be able to source them
Bram Moolenaar <Bram@vim.org>
parents:
27663
diff
changeset
|
2247 if (sourcing_a_script(eap)) |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2248 do_finish(eap, FALSE); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2249 else |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
2250 emsg(_(e_finish_used_outside_of_sourced_file)); |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2251 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2252 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2253 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2254 * Mark a sourced file as finished. Possibly makes the ":finish" pending. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2255 * Also called for a pending finish at the ":endtry" or after returning from |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2256 * an extra do_cmdline(). "reanimate" is used in the latter case. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2257 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2258 void |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2259 do_finish(exarg_T *eap, int reanimate) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2260 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2261 int idx; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2262 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2263 if (reanimate) |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
2264 ((source_cookie_T *)getline_cookie(eap->getline, |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2265 eap->cookie))->finished = FALSE; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2266 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2267 // Cleanup (and inactivate) conditionals, but stop when a try conditional |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2268 // not in its finally clause (which then is to be executed next) is found. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2269 // In this case, make the ":finish" pending for execution at the ":endtry". |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2270 // Otherwise, finish normally. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2271 idx = cleanup_conditionals(eap->cstack, 0, TRUE); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2272 if (idx >= 0) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2273 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2274 eap->cstack->cs_pending[idx] = CSTP_FINISH; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2275 report_make_pending(CSTP_FINISH, NULL); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2276 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2277 else |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
2278 ((source_cookie_T *)getline_cookie(eap->getline, |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2279 eap->cookie))->finished = TRUE; |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2280 } |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2281 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2282 |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2283 /* |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2284 * Return TRUE when a sourced file had the ":finish" command: Don't give error |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2285 * message for missing ":endif". |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2286 * Return FALSE when not sourcing a file. |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2287 */ |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2288 int |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2289 source_finished( |
21883
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21865
diff
changeset
|
2290 char_u *(*fgetline)(int, void *, int, getline_opt_T), |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2291 void *cookie) |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2292 { |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2293 return (getline_equal(fgetline, cookie, getsourceline) |
23580
dc3b7a31c29f
patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
2294 && ((source_cookie_T *)getline_cookie( |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2295 fgetline, cookie))->finished); |
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2296 } |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2297 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2298 /* |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2299 * Find the path of a script below the "autoload" directory. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2300 * Returns NULL if there is no "/autoload/" in the script name. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2301 */ |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2302 char_u * |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2303 script_name_after_autoload(scriptitem_T *si) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2304 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2305 char_u *p = si->sn_name; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2306 char_u *res = NULL; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2307 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2308 for (;;) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2309 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2310 char_u *n = (char_u *)strstr((char *)p, "autoload"); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2311 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2312 if (n == NULL) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2313 break; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2314 if (n > p && vim_ispathsep(n[-1]) && vim_ispathsep(n[8])) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2315 res = n + 9; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2316 p = n + 8; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2317 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2318 return res; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2319 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2320 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2321 /* |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2322 * For an autoload script "autoload/dir/script.vim" return the prefix |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2323 * "dir#script#" in allocated memory. |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2324 * Returns NULL if anything is wrong. |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2325 */ |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2326 char_u * |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2327 get_autoload_prefix(scriptitem_T *si) |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2328 { |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2329 char_u *p = script_name_after_autoload(si); |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2330 char_u *prefix; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2331 |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2332 if (p == NULL) |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2333 return NULL; |
27106
d7e6b85dd89d
patch 8.2.4082: check for autoload file name and prefix fails
Bram Moolenaar <Bram@vim.org>
parents:
27080
diff
changeset
|
2334 prefix = vim_strsave(p); |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2335 if (prefix == NULL) |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2336 return NULL; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2337 |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2338 // replace all '/' with '#' and locate ".vim" at the end |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2339 for (p = prefix; *p != NUL; p += mb_ptr2len(p)) |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2340 { |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2341 if (vim_ispathsep(*p)) |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2342 *p = '#'; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2343 else if (STRCMP(p, ".vim") == 0) |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2344 { |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2345 p[0] = '#'; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2346 p[1] = NUL; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2347 return prefix; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2348 } |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2349 } |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2350 |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2351 // did not find ".vim" at the end |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2352 vim_free(prefix); |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2353 return NULL; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2354 } |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2355 |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2356 /* |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2357 * If in a Vim9 autoload script return "name" with the autoload prefix for the |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27213
diff
changeset
|
2358 * script. If successful the returned name is allocated. |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2359 * Otherwise it returns "name" unmodified. |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2360 */ |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2361 char_u * |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2362 may_prefix_autoload(char_u *name) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2363 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2364 if (SCRIPT_ID_VALID(current_sctx.sc_sid)) |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2365 { |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2366 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2367 |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2368 if (si->sn_autoload_prefix != NULL) |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2369 { |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2370 char_u *basename = name; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2371 size_t len; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2372 char_u *res; |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2373 |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2374 if (*name == K_SPECIAL) |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2375 { |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2376 char_u *p = vim_strchr(name, '_'); |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2377 |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2378 // skip over "<SNR>99_" |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2379 if (p != NULL) |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2380 basename = p + 1; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2381 } |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2382 |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2383 len = STRLEN(si->sn_autoload_prefix) + STRLEN(basename) + 2; |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2384 res = alloc(len); |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2385 if (res != NULL) |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2386 { |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2387 vim_snprintf((char *)res, len, "%s%s", |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2388 si->sn_autoload_prefix, basename); |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27045
diff
changeset
|
2389 return res; |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2390 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2391 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2392 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2393 return name; |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2394 } |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2395 |
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2396 /* |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2397 * Return the autoload script name for a function or variable name. |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2398 * Returns NULL when out of memory. |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2399 * Caller must make sure that "name" contains AUTOLOAD_CHAR. |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2400 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2401 char_u * |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2402 autoload_name(char_u *name) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2403 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2404 char_u *p, *q = NULL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2405 char_u *scriptname; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2406 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2407 // Get the script file name: replace '#' with '/', append ".vim". |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2408 scriptname = alloc(STRLEN(name) + 14); |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2409 if (scriptname == NULL) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2410 return NULL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2411 STRCPY(scriptname, "autoload/"); |
21753
9ef7ae8ab51c
patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents:
21697
diff
changeset
|
2412 STRCAT(scriptname, name[0] == 'g' && name[1] == ':' ? name + 2: name); |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2413 for (p = scriptname + 9; (p = vim_strchr(p, AUTOLOAD_CHAR)) != NULL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2414 q = p, ++p) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2415 *p = '/'; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2416 STRCPY(q, ".vim"); |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2417 return scriptname; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2418 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2419 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2420 /* |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2421 * If "name" has a package name try autoloading the script for it. |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2422 * Return TRUE if a package was loaded. |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2423 */ |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2424 int |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2425 script_autoload( |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2426 char_u *name, |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2427 int reload) // load script again when already loaded |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2428 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2429 char_u *p; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2430 char_u *scriptname, *tofree; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2431 int ret = FALSE; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2432 int i; |
21697
6c477989f9a4
patch 8.2.1398: autoload script sourced twice if sourced directly
Bram Moolenaar <Bram@vim.org>
parents:
21497
diff
changeset
|
2433 int ret_sid; |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2434 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2435 // If there is no '#' after name[0] there is no package name. |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2436 p = vim_strchr(name, AUTOLOAD_CHAR); |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2437 if (p == NULL || p == name) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2438 return FALSE; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2439 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2440 tofree = scriptname = autoload_name(name); |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2441 if (scriptname == NULL) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2442 return FALSE; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2443 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2444 // Find the name in the list of previously loaded package names. Skip |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2445 // "autoload/", it's always the same. |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2446 for (i = 0; i < ga_loaded.ga_len; ++i) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2447 if (STRCMP(((char_u **)ga_loaded.ga_data)[i] + 9, scriptname + 9) == 0) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2448 break; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2449 if (!reload && i < ga_loaded.ga_len) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2450 ret = FALSE; // was loaded already |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2451 else |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2452 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2453 // Remember the name if it wasn't loaded already. |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2454 if (i == ga_loaded.ga_len && ga_grow(&ga_loaded, 1) == OK) |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2455 { |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2456 ((char_u **)ga_loaded.ga_data)[ga_loaded.ga_len++] = scriptname; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2457 tofree = NULL; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2458 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2459 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2460 // Try loading the package from $VIMRUNTIME/autoload/<name>.vim |
21697
6c477989f9a4
patch 8.2.1398: autoload script sourced twice if sourced directly
Bram Moolenaar <Bram@vim.org>
parents:
21497
diff
changeset
|
2461 // Use "ret_sid" to avoid loading the same script again. |
27495
b98c20b53a2d
patch 8.2.4275: cannot use an autoload function from a package under start
Bram Moolenaar <Bram@vim.org>
parents:
27267
diff
changeset
|
2462 if (source_in_path(p_rtp, scriptname, DIP_START, &ret_sid) == OK) |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2463 ret = TRUE; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2464 } |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2465 |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2466 vim_free(tofree); |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2467 return ret; |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17861
diff
changeset
|
2468 } |
17861
0a5c615cd949
patch 8.1.1927: code for dealing with script files is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2469 #endif |