Mercurial > vim
comparison src/scriptfile.c @ 28158:e1d1fa6ba1ed v8.2.4603
patch 8.2.4603: sourcing buffer lines is too complicated
Commit: https://github.com/vim/vim/commit/85b43c6cb7d56919e245622f4e42db6d8bee4194
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Mon Mar 21 19:45:17 2022 +0000
patch 8.2.4603: sourcing buffer lines is too complicated
Problem: Sourcing buffer lines is too complicated.
Solution: Simplify the code. Make it possible to source Vim9 script lines.
(Yegappan Lakshmanan, closes #9974)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 21 Mar 2022 21:00:04 +0100 |
parents | f34afadbef47 |
children | b0b712d48225 |
comparison
equal
deleted
inserted
replaced
28157:81034dff92a4 | 28158:e1d1fa6ba1ed |
---|---|
20 | 20 |
21 // last used sequence number for sourcing scripts (current_sctx.sc_seq) | 21 // last used sequence number for sourcing scripts (current_sctx.sc_seq) |
22 #ifdef FEAT_EVAL | 22 #ifdef FEAT_EVAL |
23 static int last_current_SID_seq = 0; | 23 static int last_current_SID_seq = 0; |
24 #endif | 24 #endif |
25 | |
26 static int do_source_ext(char_u *fname, int check_other, int is_vimrc, int *ret_sid, exarg_T *eap); | |
25 | 27 |
26 /* | 28 /* |
27 * Initialize the execution stack. | 29 * Initialize the execution stack. |
28 */ | 30 */ |
29 void | 31 void |
1077 *file = ga.ga_data; | 1079 *file = ga.ga_data; |
1078 *num_file = ga.ga_len; | 1080 *num_file = ga.ga_len; |
1079 return OK; | 1081 return OK; |
1080 } | 1082 } |
1081 | 1083 |
1082 /* | |
1083 * Cookie used to source Ex commands from a buffer. | |
1084 */ | |
1085 typedef struct | |
1086 { | |
1087 garray_T lines_to_source; | |
1088 int lnum; | |
1089 linenr_T sourcing_lnum; | |
1090 } bufline_cookie_T; | |
1091 | |
1092 /* | |
1093 * Concatenate a Vim script line if it starts with a line continuation into a | |
1094 * growarray (excluding the continuation chars and leading whitespace). | |
1095 * Growsize of the growarray may be changed to speed up concatenations! | |
1096 * | |
1097 * Returns TRUE if this line did begin with a continuation (the next line | |
1098 * should also be considered, if it exists); FALSE otherwise. | |
1099 */ | |
1100 static int | |
1101 concat_continued_line( | |
1102 garray_T *ga, | |
1103 int init_growsize, | |
1104 char_u *nextline, | |
1105 int options) | |
1106 { | |
1107 int comment_char = in_vim9script() ? '#' : '"'; | |
1108 char_u *p = skipwhite(nextline); | |
1109 int contline; | |
1110 int do_vim9_all = in_vim9script() | |
1111 && options == GETLINE_CONCAT_ALL; | |
1112 int do_bar_cont = do_vim9_all | |
1113 || options == GETLINE_CONCAT_CONTBAR; | |
1114 | |
1115 if (*p == NUL) | |
1116 return FALSE; | |
1117 | |
1118 // Concatenate the next line when it starts with a backslash. | |
1119 /* Also check for a comment in between continuation lines: "\ */ | |
1120 // Also check for a Vim9 comment, empty line, line starting with '|', | |
1121 // but not "||". | |
1122 if ((p[0] == comment_char && p[1] == '\\' && p[2] == ' ') | |
1123 || (do_vim9_all && (*p == NUL | |
1124 || vim9_comment_start(p)))) | |
1125 return TRUE; | |
1126 | |
1127 contline = (*p == '\\' || (do_bar_cont && p[0] == '|' && p[1] != '|')); | |
1128 if (!contline) | |
1129 return FALSE; | |
1130 | |
1131 // Adjust the growsize to the current length to speed up concatenating many | |
1132 // lines. | |
1133 if (ga->ga_len > init_growsize) | |
1134 ga->ga_growsize = ga->ga_len > 8000 ? 8000 : ga->ga_len; | |
1135 if (*p == '\\') | |
1136 ga_concat(ga, (char_u *)p + 1); | |
1137 else if (*p == '|') | |
1138 { | |
1139 ga_concat(ga, (char_u *)" "); | |
1140 ga_concat(ga, p); | |
1141 } | |
1142 | |
1143 return TRUE; | |
1144 } | |
1145 | |
1146 /* | |
1147 * Get one full line from a sourced string (in-memory, no file). | |
1148 * Called by do_cmdline() when it's called from source_using_linegetter(). | |
1149 * | |
1150 * Returns a pointer to allocated line, or NULL for end-of-file. | |
1151 */ | |
1152 static char_u * | |
1153 source_getbufline( | |
1154 int c UNUSED, | |
1155 void *cookie, | |
1156 int indent UNUSED, | |
1157 getline_opt_T opts) | |
1158 { | |
1159 bufline_cookie_T *p = cookie; | |
1160 char_u *line; | |
1161 garray_T ga; | |
1162 | |
1163 SOURCING_LNUM = p->sourcing_lnum + 1; | |
1164 | |
1165 if (p->lnum >= p->lines_to_source.ga_len) | |
1166 return NULL; | |
1167 line = ((char_u **)p->lines_to_source.ga_data)[p->lnum]; | |
1168 | |
1169 ga_init2(&ga, sizeof(char_u), 400); | |
1170 ga_concat(&ga, (char_u *)line); | |
1171 p->lnum++; | |
1172 | |
1173 if ((opts != GETLINE_NONE) && vim_strchr(p_cpo, CPO_CONCAT) == NULL) | |
1174 { | |
1175 while (p->lnum < p->lines_to_source.ga_len) | |
1176 { | |
1177 line = ((char_u **)p->lines_to_source.ga_data)[p->lnum]; | |
1178 if (!concat_continued_line(&ga, 400, line, opts)) | |
1179 break; | |
1180 p->sourcing_lnum++; | |
1181 p->lnum++; | |
1182 } | |
1183 } | |
1184 ga_append(&ga, NUL); | |
1185 p->sourcing_lnum++; | |
1186 | |
1187 return ga.ga_data; | |
1188 } | |
1189 | |
1190 /* | |
1191 * Source Ex commands from the lines in 'cookie'. | |
1192 */ | |
1193 static int | |
1194 do_sourcebuffer( | |
1195 void *cookie, | |
1196 char_u *scriptname) | |
1197 { | |
1198 char_u *save_sourcing_name = SOURCING_NAME; | |
1199 linenr_T save_sourcing_lnum = SOURCING_LNUM; | |
1200 char_u sourcing_name_buf[256]; | |
1201 sctx_T save_current_sctx; | |
1202 #ifdef FEAT_EVAL | |
1203 int sid; | |
1204 funccal_entry_T funccalp_entry; | |
1205 int save_estack_compiling = estack_compiling; | |
1206 scriptitem_T *si = NULL; | |
1207 #endif | |
1208 int save_sticky_cmdmod_flags = sticky_cmdmod_flags; | |
1209 int retval = FAIL; | |
1210 ESTACK_CHECK_DECLARATION | |
1211 | |
1212 if (save_sourcing_name == NULL) | |
1213 SOURCING_NAME = (char_u *)scriptname; | |
1214 else | |
1215 { | |
1216 vim_snprintf((char *)sourcing_name_buf, sizeof(sourcing_name_buf), | |
1217 "%s called at %s:%ld", scriptname, save_sourcing_name, | |
1218 save_sourcing_lnum); | |
1219 SOURCING_NAME = sourcing_name_buf; | |
1220 } | |
1221 SOURCING_LNUM = 0; | |
1222 | |
1223 // Keep the sourcing name/lnum, for recursive calls. | |
1224 estack_push(ETYPE_SCRIPT, scriptname, 0); | |
1225 ESTACK_CHECK_SETUP | |
1226 | |
1227 // "legacy" does not apply to commands in the script | |
1228 sticky_cmdmod_flags = 0; | |
1229 | |
1230 save_current_sctx = current_sctx; | |
1231 current_sctx.sc_version = 1; // default script version | |
1232 #ifdef FEAT_EVAL | |
1233 estack_compiling = FALSE; | |
1234 // Always use a new sequence number. | |
1235 current_sctx.sc_seq = ++last_current_SID_seq; | |
1236 current_sctx.sc_lnum = save_sourcing_lnum; | |
1237 save_funccal(&funccalp_entry); | |
1238 | |
1239 sid = find_script_by_name(scriptname); | |
1240 if (sid < 0) | |
1241 { | |
1242 int error = OK; | |
1243 | |
1244 // First time sourcing this buffer, create a new script item. | |
1245 | |
1246 sid = get_new_scriptitem(&error); | |
1247 if (error == FAIL) | |
1248 goto theend; | |
1249 current_sctx.sc_sid = sid; | |
1250 si = SCRIPT_ITEM(current_sctx.sc_sid); | |
1251 si->sn_name = vim_strsave(scriptname); | |
1252 si->sn_state = SN_STATE_NEW; | |
1253 } | |
1254 else | |
1255 { | |
1256 // the buffer was sourced previously, reuse the script ID. | |
1257 current_sctx.sc_sid = sid; | |
1258 si = SCRIPT_ITEM(current_sctx.sc_sid); | |
1259 si->sn_state = SN_STATE_RELOAD; | |
1260 } | |
1261 #endif | |
1262 | |
1263 retval = do_cmdline(NULL, source_getbufline, cookie, | |
1264 DOCMD_VERBOSE | DOCMD_NOWAIT | DOCMD_REPEAT); | |
1265 | |
1266 if (got_int) | |
1267 emsg(_(e_interrupted)); | |
1268 | |
1269 #ifdef FEAT_EVAL | |
1270 theend: | |
1271 #endif | |
1272 ESTACK_CHECK_NOW | |
1273 estack_pop(); | |
1274 current_sctx = save_current_sctx; | |
1275 SOURCING_LNUM = save_sourcing_lnum; | |
1276 SOURCING_NAME = save_sourcing_name; | |
1277 sticky_cmdmod_flags = save_sticky_cmdmod_flags; | |
1278 #ifdef FEAT_EVAL | |
1279 restore_funccal(); | |
1280 estack_compiling = save_estack_compiling; | |
1281 #endif | |
1282 | |
1283 return retval; | |
1284 } | |
1285 | |
1286 /* | |
1287 * :source Ex commands from the current buffer | |
1288 */ | |
1289 static void | |
1290 cmd_source_buffer(exarg_T *eap) | |
1291 { | |
1292 char_u *line = NULL; | |
1293 linenr_T curr_lnum; | |
1294 bufline_cookie_T cp; | |
1295 char_u sname[32]; | |
1296 | |
1297 if (curbuf == NULL) | |
1298 return; | |
1299 | |
1300 // Use ":source buffer=<num>" as the script name | |
1301 vim_snprintf((char *)sname, sizeof(sname), ":source buffer=%d", | |
1302 curbuf->b_fnum); | |
1303 | |
1304 ga_init2(&cp.lines_to_source, sizeof(char_u *), 100); | |
1305 | |
1306 // Copy the lines from the buffer into a grow array | |
1307 for (curr_lnum = eap->line1; curr_lnum <= eap->line2; curr_lnum++) | |
1308 { | |
1309 line = vim_strsave(ml_get(curr_lnum)); | |
1310 if (line == NULL) | |
1311 goto errret; | |
1312 if (ga_add_string(&cp.lines_to_source, line) == FAIL) | |
1313 goto errret; | |
1314 line = NULL; | |
1315 } | |
1316 cp.sourcing_lnum = 0; | |
1317 cp.lnum = 0; | |
1318 | |
1319 // Execute the Ex commands | |
1320 do_sourcebuffer((void *)&cp, (char_u *)sname); | |
1321 | |
1322 errret: | |
1323 vim_free(line); | |
1324 ga_clear_strings(&cp.lines_to_source); | |
1325 } | |
1326 | |
1327 static void | 1084 static void |
1328 cmd_source(char_u *fname, exarg_T *eap) | 1085 cmd_source(char_u *fname, exarg_T *eap) |
1329 { | 1086 { |
1330 if (*fname != NUL && eap != NULL && eap->addr_count > 0) | 1087 if (*fname != NUL && eap != NULL && eap->addr_count > 0) |
1331 { | 1088 { |
1339 if (eap->forceit) | 1096 if (eap->forceit) |
1340 // a file name is needed to source normal mode commands | 1097 // a file name is needed to source normal mode commands |
1341 emsg(_(e_argument_required)); | 1098 emsg(_(e_argument_required)); |
1342 else | 1099 else |
1343 // source ex commands from the current buffer | 1100 // source ex commands from the current buffer |
1344 cmd_source_buffer(eap); | 1101 do_source_ext(NULL, FALSE, FALSE, NULL, eap); |
1345 } | 1102 } |
1346 else if (eap != NULL && eap->forceit) | 1103 else if (eap != NULL && eap->forceit) |
1347 // ":source!": read Normal mode commands | 1104 // ":source!": read Normal mode commands |
1348 // Need to execute the commands directly. This is required at least | 1105 // Need to execute the commands directly. This is required at least |
1349 // for: | 1106 // for: |
1478 return fdopen(fd_tmp, READBIN); | 1235 return fdopen(fd_tmp, READBIN); |
1479 } | 1236 } |
1480 #endif | 1237 #endif |
1481 | 1238 |
1482 /* | 1239 /* |
1483 * do_source: Read the file "fname" and execute its lines as EX commands. | 1240 * Initialization for sourcing lines from the current buffer. Reads all the |
1241 * lines from the buffer and stores it in the cookie grow array. | |
1242 * Returns a pointer to the name ":source buffer=<n>" on success and NULL on | |
1243 * failure. | |
1244 */ | |
1245 static char_u * | |
1246 do_source_buffer_init(source_cookie_T *sp, exarg_T *eap) | |
1247 { | |
1248 linenr_T curr_lnum; | |
1249 char_u *line = NULL; | |
1250 char_u *fname; | |
1251 | |
1252 CLEAR_FIELD(*sp); | |
1253 | |
1254 if (curbuf == NULL) | |
1255 return NULL; | |
1256 | |
1257 // Use ":source buffer=<num>" as the script name | |
1258 vim_snprintf((char *)IObuff, IOSIZE, ":source buffer=%d", curbuf->b_fnum); | |
1259 fname = vim_strsave(IObuff); | |
1260 if (fname == NULL) | |
1261 return NULL; | |
1262 | |
1263 ga_init2(&sp->buflines, sizeof(char_u *), 100); | |
1264 | |
1265 // Copy the lines from the buffer into a grow array | |
1266 for (curr_lnum = eap->line1; curr_lnum <= eap->line2; curr_lnum++) | |
1267 { | |
1268 line = vim_strsave(ml_get(curr_lnum)); | |
1269 if (line == NULL) | |
1270 goto errret; | |
1271 if (ga_add_string(&sp->buflines, line) == FAIL) | |
1272 goto errret; | |
1273 line = NULL; | |
1274 } | |
1275 sp->buf_lnum = 0; | |
1276 sp->source_from_buf = TRUE; | |
1277 | |
1278 return fname; | |
1279 | |
1280 errret: | |
1281 vim_free(fname); | |
1282 vim_free(line); | |
1283 ga_clear_strings(&sp->buflines); | |
1284 return NULL; | |
1285 } | |
1286 | |
1287 /* | |
1288 * Read the file "fname" and execute its lines as EX commands. | |
1484 * When "ret_sid" is not NULL and we loaded the script before, don't load it | 1289 * When "ret_sid" is not NULL and we loaded the script before, don't load it |
1485 * again. | 1290 * again. |
1291 * | |
1292 * The 'eap' argument is used when sourcing lines from a buffer instead of a | |
1293 * file. | |
1486 * | 1294 * |
1487 * This function may be called recursively! | 1295 * This function may be called recursively! |
1488 * | 1296 * |
1489 * Return FAIL if file could not be opened, OK otherwise. | 1297 * Return FAIL if file could not be opened, OK otherwise. |
1490 * If a scriptitem_T was found or created "*ret_sid" is set to the SID. | 1298 * If a scriptitem_T was found or created "*ret_sid" is set to the SID. |
1491 */ | 1299 */ |
1492 int | 1300 static int |
1493 do_source( | 1301 do_source_ext( |
1494 char_u *fname, | 1302 char_u *fname, |
1495 int check_other, // check for .vimrc and _vimrc | 1303 int check_other, // check for .vimrc and _vimrc |
1496 int is_vimrc, // DOSO_ value | 1304 int is_vimrc, // DOSO_ value |
1497 int *ret_sid UNUSED) | 1305 int *ret_sid UNUSED, |
1306 exarg_T *eap) | |
1498 { | 1307 { |
1499 source_cookie_T cookie; | 1308 source_cookie_T cookie; |
1500 char_u *p; | 1309 char_u *p; |
1501 char_u *fname_exp; | 1310 char_u *fname_exp; |
1502 char_u *firstline = NULL; | 1311 char_u *firstline = NULL; |
1518 #endif | 1327 #endif |
1519 int save_sticky_cmdmod_flags = sticky_cmdmod_flags; | 1328 int save_sticky_cmdmod_flags = sticky_cmdmod_flags; |
1520 int trigger_source_post = FALSE; | 1329 int trigger_source_post = FALSE; |
1521 ESTACK_CHECK_DECLARATION | 1330 ESTACK_CHECK_DECLARATION |
1522 | 1331 |
1523 p = expand_env_save(fname); | 1332 CLEAR_FIELD(cookie); |
1524 if (p == NULL) | 1333 if (fname == NULL) |
1525 return retval; | 1334 { |
1526 fname_exp = fix_fname(p); | 1335 // sourcing lines from a buffer |
1527 vim_free(p); | 1336 fname_exp = do_source_buffer_init(&cookie, eap); |
1528 if (fname_exp == NULL) | 1337 if (fname_exp == NULL) |
1529 return retval; | 1338 return FAIL; |
1530 if (mch_isdir(fname_exp)) | 1339 } |
1531 { | 1340 else |
1532 smsg(_("Cannot source a directory: \"%s\""), fname); | 1341 { |
1533 goto theend; | 1342 p = expand_env_save(fname); |
1343 if (p == NULL) | |
1344 return retval; | |
1345 fname_exp = fix_fname(p); | |
1346 vim_free(p); | |
1347 if (fname_exp == NULL) | |
1348 return retval; | |
1349 if (mch_isdir(fname_exp)) | |
1350 { | |
1351 smsg(_("Cannot source a directory: \"%s\""), fname); | |
1352 goto theend; | |
1353 } | |
1534 } | 1354 } |
1535 #ifdef FEAT_EVAL | 1355 #ifdef FEAT_EVAL |
1536 estack_compiling = FALSE; | 1356 estack_compiling = FALSE; |
1537 | 1357 |
1538 // See if we loaded this script before. | 1358 // See if we loaded this script before. |
1565 } | 1385 } |
1566 | 1386 |
1567 // Apply SourcePre autocommands, they may get the file. | 1387 // Apply SourcePre autocommands, they may get the file. |
1568 apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf); | 1388 apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf); |
1569 | 1389 |
1390 if (!cookie.source_from_buf) | |
1391 { | |
1570 #ifdef USE_FOPEN_NOINH | 1392 #ifdef USE_FOPEN_NOINH |
1571 cookie.fp = fopen_noinh_readbin((char *)fname_exp); | 1393 cookie.fp = fopen_noinh_readbin((char *)fname_exp); |
1572 #else | 1394 #else |
1573 cookie.fp = mch_fopen((char *)fname_exp, READBIN); | 1395 cookie.fp = mch_fopen((char *)fname_exp, READBIN); |
1574 #endif | 1396 #endif |
1397 } | |
1575 if (cookie.fp == NULL && check_other) | 1398 if (cookie.fp == NULL && check_other) |
1576 { | 1399 { |
1577 // Try again, replacing file name ".vimrc" by "_vimrc" or vice versa, | 1400 // Try again, replacing file name ".vimrc" by "_vimrc" or vice versa, |
1578 // and ".exrc" by "_exrc" or vice versa. | 1401 // and ".exrc" by "_exrc" or vice versa. |
1579 p = gettail(fname_exp); | 1402 p = gettail(fname_exp); |
1592 cookie.fp = mch_fopen((char *)fname_exp, READBIN); | 1415 cookie.fp = mch_fopen((char *)fname_exp, READBIN); |
1593 #endif | 1416 #endif |
1594 } | 1417 } |
1595 } | 1418 } |
1596 | 1419 |
1597 if (cookie.fp == NULL) | 1420 if (cookie.fp == NULL && !cookie.source_from_buf) |
1598 { | 1421 { |
1599 if (p_verbose > 0) | 1422 if (p_verbose > 0) |
1600 { | 1423 { |
1601 verbose_enter(); | 1424 verbose_enter(); |
1602 if (SOURCING_NAME == NULL) | 1425 if (SOURCING_NAME == NULL) |
1630 // If no automatic file format: Set default to CR-NL. | 1453 // If no automatic file format: Set default to CR-NL. |
1631 if (*p_ffs == NUL) | 1454 if (*p_ffs == NUL) |
1632 cookie.fileformat = EOL_DOS; | 1455 cookie.fileformat = EOL_DOS; |
1633 else | 1456 else |
1634 cookie.fileformat = EOL_UNKNOWN; | 1457 cookie.fileformat = EOL_UNKNOWN; |
1635 cookie.error = FALSE; | 1458 #endif |
1636 #endif | 1459 |
1637 | 1460 if (fname == NULL) |
1638 cookie.nextline = NULL; | 1461 // When sourcing a range of lines from a buffer, use the buffer line |
1639 cookie.sourcing_lnum = 0; | 1462 // number. |
1640 cookie.finished = FALSE; | 1463 cookie.sourcing_lnum = eap->line1 - 1; |
1464 else | |
1465 cookie.sourcing_lnum = 0; | |
1641 | 1466 |
1642 #ifdef FEAT_EVAL | 1467 #ifdef FEAT_EVAL |
1643 // Check if this script has a breakpoint. | 1468 // Check if this script has a breakpoint. |
1644 cookie.breakpoint = dbg_find_breakpoint(TRUE, fname_exp, (linenr_T)0); | 1469 cookie.breakpoint = dbg_find_breakpoint(TRUE, fname_exp, (linenr_T)0); |
1645 cookie.fname = fname_exp; | 1470 cookie.fname = fname_exp; |
1659 | 1484 |
1660 // "legacy" does not apply to commands in the script | 1485 // "legacy" does not apply to commands in the script |
1661 sticky_cmdmod_flags = 0; | 1486 sticky_cmdmod_flags = 0; |
1662 | 1487 |
1663 save_current_sctx = current_sctx; | 1488 save_current_sctx = current_sctx; |
1664 current_sctx.sc_version = 1; // default script version | 1489 if (cmdmod.cmod_flags & CMOD_VIM9CMD) |
1490 // When the ":vim9cmd" command modifier is used, source the script as a | |
1491 // Vim9 script. | |
1492 current_sctx.sc_version = SCRIPT_VERSION_VIM9; | |
1493 else | |
1494 current_sctx.sc_version = 1; // default script version | |
1665 | 1495 |
1666 #ifdef FEAT_EVAL | 1496 #ifdef FEAT_EVAL |
1667 # ifdef FEAT_PROFILE | 1497 # ifdef FEAT_PROFILE |
1668 if (do_profiling == PROF_YES) | 1498 if (do_profiling == PROF_YES) |
1669 prof_child_enter(&wait_start); // entering a child now | 1499 prof_child_enter(&wait_start); // entering a child now |
1872 prof_child_exit(&wait_start); // leaving a child now | 1702 prof_child_exit(&wait_start); // leaving a child now |
1873 # endif | 1703 # endif |
1874 #endif | 1704 #endif |
1875 current_sctx = save_current_sctx; | 1705 current_sctx = save_current_sctx; |
1876 | 1706 |
1877 fclose(cookie.fp); | 1707 if (cookie.fp != NULL) |
1708 fclose(cookie.fp); | |
1709 if (cookie.source_from_buf) | |
1710 ga_clear_strings(&cookie.buflines); | |
1878 vim_free(cookie.nextline); | 1711 vim_free(cookie.nextline); |
1879 vim_free(firstline); | 1712 vim_free(firstline); |
1880 convert_setup(&cookie.conv, NULL, NULL); | 1713 convert_setup(&cookie.conv, NULL, NULL); |
1881 | 1714 |
1882 if (trigger_source_post) | 1715 if (trigger_source_post) |
1888 #ifdef FEAT_EVAL | 1721 #ifdef FEAT_EVAL |
1889 estack_compiling = save_estack_compiling; | 1722 estack_compiling = save_estack_compiling; |
1890 #endif | 1723 #endif |
1891 return retval; | 1724 return retval; |
1892 } | 1725 } |
1726 | |
1727 int | |
1728 do_source( | |
1729 char_u *fname, | |
1730 int check_other, // check for .vimrc and _vimrc | |
1731 int is_vimrc, // DOSO_ value | |
1732 int *ret_sid UNUSED) | |
1733 { | |
1734 return do_source_ext(fname, check_other, is_vimrc, ret_sid, NULL); | |
1735 } | |
1736 | |
1893 | 1737 |
1894 #if defined(FEAT_EVAL) || defined(PROTO) | 1738 #if defined(FEAT_EVAL) || defined(PROTO) |
1895 | 1739 |
1896 /* | 1740 /* |
1897 * ":scriptnames" | 1741 * ":scriptnames" |
2036 for (;;) | 1880 for (;;) |
2037 { | 1881 { |
2038 // make room to read at least 120 (more) characters | 1882 // make room to read at least 120 (more) characters |
2039 if (ga_grow(&ga, 120) == FAIL) | 1883 if (ga_grow(&ga, 120) == FAIL) |
2040 break; | 1884 break; |
2041 buf = (char_u *)ga.ga_data; | 1885 if (sp->source_from_buf) |
2042 | 1886 { |
2043 if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len, | 1887 if (sp->buf_lnum >= sp->buflines.ga_len) |
2044 sp->fp) == NULL) | 1888 break; // all the lines are processed |
2045 break; | 1889 ga_concat(&ga, ((char_u **)sp->buflines.ga_data)[sp->buf_lnum]); |
1890 sp->buf_lnum++; | |
1891 buf = (char_u *)ga.ga_data; | |
1892 } | |
1893 else | |
1894 { | |
1895 buf = (char_u *)ga.ga_data; | |
1896 if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len, | |
1897 sp->fp) == NULL) | |
1898 break; | |
1899 } | |
2046 len = ga.ga_len + (int)STRLEN(buf + ga.ga_len); | 1900 len = ga.ga_len + (int)STRLEN(buf + ga.ga_len); |
2047 #ifdef USE_CRNL | 1901 #ifdef USE_CRNL |
2048 // Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the | 1902 // Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the |
2049 // CTRL-Z by its own, or after a NL. | 1903 // CTRL-Z by its own, or after a NL. |
2050 if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n')) | 1904 if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n')) |
2143 int do_bar_cont = do_vim9_all | 1997 int do_bar_cont = do_vim9_all |
2144 || options == GETLINE_CONCAT_CONTBAR; | 1998 || options == GETLINE_CONCAT_CONTBAR; |
2145 | 1999 |
2146 #ifdef FEAT_EVAL | 2000 #ifdef FEAT_EVAL |
2147 // If breakpoints have been added/deleted need to check for it. | 2001 // If breakpoints have been added/deleted need to check for it. |
2148 if (sp->dbg_tick < debug_tick) | 2002 if ((sp->dbg_tick < debug_tick) && !sp->source_from_buf) |
2149 { | 2003 { |
2150 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, SOURCING_LNUM); | 2004 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, SOURCING_LNUM); |
2151 sp->dbg_tick = debug_tick; | 2005 sp->dbg_tick = debug_tick; |
2152 } | 2006 } |
2153 # ifdef FEAT_PROFILE | 2007 # ifdef FEAT_PROFILE |
2159 // Set the current sourcing line number. | 2013 // Set the current sourcing line number. |
2160 SOURCING_LNUM = sp->sourcing_lnum + 1; | 2014 SOURCING_LNUM = sp->sourcing_lnum + 1; |
2161 | 2015 |
2162 // Get current line. If there is a read-ahead line, use it, otherwise get | 2016 // Get current line. If there is a read-ahead line, use it, otherwise get |
2163 // one now. "fp" is NULL if actually using a string. | 2017 // one now. "fp" is NULL if actually using a string. |
2164 if (sp->finished || sp->fp == NULL) | 2018 if (sp->finished || (!sp->source_from_buf && sp->fp == NULL)) |
2165 line = NULL; | 2019 line = NULL; |
2166 else if (sp->nextline == NULL) | 2020 else if (sp->nextline == NULL) |
2167 line = get_one_sourceline(sp); | 2021 line = get_one_sourceline(sp); |
2168 else | 2022 else |
2169 { | 2023 { |
2263 } | 2117 } |
2264 } | 2118 } |
2265 | 2119 |
2266 #ifdef FEAT_EVAL | 2120 #ifdef FEAT_EVAL |
2267 // Did we encounter a breakpoint? | 2121 // Did we encounter a breakpoint? |
2268 if (sp->breakpoint != 0 && sp->breakpoint <= SOURCING_LNUM) | 2122 if (!sp->source_from_buf && sp->breakpoint != 0 |
2123 && sp->breakpoint <= SOURCING_LNUM) | |
2269 { | 2124 { |
2270 dbg_breakpoint(sp->fname, SOURCING_LNUM); | 2125 dbg_breakpoint(sp->fname, SOURCING_LNUM); |
2271 // Find next breakpoint. | 2126 // Find next breakpoint. |
2272 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, SOURCING_LNUM); | 2127 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, SOURCING_LNUM); |
2273 sp->dbg_tick = debug_tick; | 2128 sp->dbg_tick = debug_tick; |
2282 * Otherwise returns FALSE. | 2137 * Otherwise returns FALSE. |
2283 */ | 2138 */ |
2284 int | 2139 int |
2285 sourcing_a_script(exarg_T *eap) | 2140 sourcing_a_script(exarg_T *eap) |
2286 { | 2141 { |
2287 return (getline_equal(eap->getline, eap->cookie, getsourceline) | 2142 return (getline_equal(eap->getline, eap->cookie, getsourceline)); |
2288 || getline_equal(eap->getline, eap->cookie, source_getbufline)); | |
2289 } | 2143 } |
2290 | 2144 |
2291 /* | 2145 /* |
2292 * ":scriptencoding": Set encoding conversion for a sourced script. | 2146 * ":scriptencoding": Set encoding conversion for a sourced script. |
2293 */ | 2147 */ |