Mercurial > vim
comparison src/scriptfile.c @ 22208:a607f02fd17a v8.2.1653
patch 8.2.1653: expand('<stack>') does not include the final line number
Commit: https://github.com/vim/vim/commit/4f25b1aba050b85fa97ca2316aa04dd4b0b22530
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 10 19:25:05 2020 +0200
patch 8.2.1653: expand('<stack>') does not include the final line number
Problem: Expand('<stack>') does not include the final line number.
Solution: Add the line nuber. (closes https://github.com/vim/vim/issues/6927)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 10 Sep 2020 19:30:05 +0200 |
parents | a98211c3e14e |
children | 195a617b405a |
comparison
equal
deleted
inserted
replaced
22207:d32eb3b1201e | 22208:a607f02fd17a |
---|---|
109 return ((estack_T *)exestack.ga_data) + exestack.ga_len; | 109 return ((estack_T *)exestack.ga_data) + exestack.ga_len; |
110 } | 110 } |
111 | 111 |
112 /* | 112 /* |
113 * Get the current value for <sfile> in allocated memory. | 113 * Get the current value for <sfile> in allocated memory. |
114 * "is_sfile" is TRUE for <sfile> itself. | 114 * "which" is ESTACK_SFILE for <sfile> and ESTACK_STACK for <stack>. |
115 */ | 115 */ |
116 char_u * | 116 char_u * |
117 estack_sfile(int is_sfile UNUSED) | 117 estack_sfile(estack_arg_T which UNUSED) |
118 { | 118 { |
119 estack_T *entry; | 119 estack_T *entry; |
120 #ifdef FEAT_EVAL | 120 #ifdef FEAT_EVAL |
121 garray_T ga; | 121 garray_T ga; |
122 size_t len; | 122 size_t len; |
125 char *type_name; | 125 char *type_name; |
126 #endif | 126 #endif |
127 | 127 |
128 entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; | 128 entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; |
129 #ifdef FEAT_EVAL | 129 #ifdef FEAT_EVAL |
130 if (is_sfile && entry->es_type != ETYPE_UFUNC) | 130 if (which == ESTACK_SFILE && entry->es_type != ETYPE_UFUNC) |
131 #endif | 131 #endif |
132 { | 132 { |
133 if (entry->es_name == NULL) | 133 if (entry->es_name == NULL) |
134 return NULL; | 134 return NULL; |
135 return vim_strsave(entry->es_name); | 135 return vim_strsave(entry->es_name); |
142 for (idx = 0; idx < exestack.ga_len; ++idx) | 142 for (idx = 0; idx < exestack.ga_len; ++idx) |
143 { | 143 { |
144 entry = ((estack_T *)exestack.ga_data) + idx; | 144 entry = ((estack_T *)exestack.ga_data) + idx; |
145 if (entry->es_name != NULL) | 145 if (entry->es_name != NULL) |
146 { | 146 { |
147 long lnum = 0; | |
148 | |
147 len = STRLEN(entry->es_name) + 15; | 149 len = STRLEN(entry->es_name) + 15; |
148 type_name = ""; | 150 type_name = ""; |
149 if (entry->es_type != last_type) | 151 if (entry->es_type != last_type) |
150 { | 152 { |
151 switch (entry->es_type) | 153 switch (entry->es_type) |
157 last_type = entry->es_type; | 159 last_type = entry->es_type; |
158 } | 160 } |
159 len += STRLEN(type_name); | 161 len += STRLEN(type_name); |
160 if (ga_grow(&ga, (int)len) == FAIL) | 162 if (ga_grow(&ga, (int)len) == FAIL) |
161 break; | 163 break; |
162 if (idx == exestack.ga_len - 1 || entry->es_lnum == 0) | 164 if (idx == exestack.ga_len - 1) |
163 // For the bottom entry: do not add the line number, it is used | 165 lnum = which == ESTACK_STACK ? SOURCING_LNUM : 0; |
164 // in <slnum>. Also leave it out when the number is not set. | 166 else |
167 lnum = entry->es_lnum; | |
168 if (lnum == 0) | |
169 // For the bottom entry of <sfile>: do not add the line number, | |
170 // it is used in <slnum>. Also leave it out when the number is | |
171 // not set. | |
165 vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s%s", | 172 vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s%s", |
166 type_name, entry->es_name, | 173 type_name, entry->es_name, |
167 idx == exestack.ga_len - 1 ? "" : ".."); | 174 idx == exestack.ga_len - 1 ? "" : ".."); |
168 else | 175 else |
169 vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s[%ld]..", | 176 vim_snprintf((char *)ga.ga_data + ga.ga_len, len, "%s%s[%ld]..", |
170 type_name, entry->es_name, entry->es_lnum); | 177 type_name, entry->es_name, lnum); |
171 ga.ga_len += (int)STRLEN((char *)ga.ga_data + ga.ga_len); | 178 ga.ga_len += (int)STRLEN((char *)ga.ga_data + ga.ga_len); |
172 } | 179 } |
173 } | 180 } |
174 | 181 |
175 return (char_u *)ga.ga_data; | 182 return (char_u *)ga.ga_data; |