@@ -1357,6 +1357,7 @@ do_source_ext(
13571357{
13581358 source_cookie_T cookie ;
13591359 char_u * p ;
1360+ char_u * fname_not_fixed = NULL ;
13601361 char_u * fname_exp ;
13611362 char_u * firstline = NULL ;
13621363 int retval = FAIL ;
@@ -1389,13 +1390,12 @@ do_source_ext(
13891390 }
13901391 else
13911392 {
1392- p = expand_env_save (fname );
1393- if (p == NULL )
1394- return retval ;
1395- fname_exp = fix_fname (p );
1396- vim_free (p );
1393+ fname_not_fixed = expand_env_save (fname );
1394+ if (fname_not_fixed == NULL )
1395+ goto theend ;
1396+ fname_exp = fix_fname (fname_not_fixed );
13971397 if (fname_exp == NULL )
1398- return retval ;
1398+ goto theend ;
13991399 if (mch_isdir (fname_exp ))
14001400 {
14011401 smsg (_ ("Cannot source a directory: \"%s\"" ), fname );
@@ -1602,14 +1602,15 @@ do_source_ext(
16021602 int error = OK ;
16031603
16041604 // It's new, generate a new SID and initialize the scriptitem.
1605- current_sctx .sc_sid = get_new_scriptitem (& error );
1605+ sid = get_new_scriptitem (& error );
1606+ current_sctx .sc_sid = sid ;
16061607 if (error == FAIL )
16071608 goto almosttheend ;
1608- si = SCRIPT_ITEM (current_sctx . sc_sid );
1609+ si = SCRIPT_ITEM (sid );
16091610 si -> sn_name = fname_exp ;
16101611 fname_exp = vim_strsave (si -> sn_name ); // used for autocmd
16111612 if (ret_sid != NULL )
1612- * ret_sid = current_sctx . sc_sid ;
1613+ * ret_sid = sid ;
16131614
16141615 // Remember the "is_vimrc" flag for when the file is sourced again.
16151616 si -> sn_is_vimrc = is_vimrc ;
@@ -1668,7 +1669,7 @@ do_source_ext(
16681669 if (do_profiling == PROF_YES )
16691670 {
16701671 // Get "si" again, "script_items" may have been reallocated.
1671- si = SCRIPT_ITEM (current_sctx . sc_sid );
1672+ si = SCRIPT_ITEM (sid );
16721673 if (si -> sn_prof_on )
16731674 {
16741675 profile_end (& si -> sn_pr_start );
@@ -1719,7 +1720,7 @@ do_source_ext(
17191720 // If "sn_save_cpo" is set that means we encountered "vim9script": restore
17201721 // 'cpoptions', unless in the main .vimrc file.
17211722 // Get "si" again, "script_items" may have been reallocated.
1722- si = SCRIPT_ITEM (current_sctx . sc_sid );
1723+ si = SCRIPT_ITEM (sid );
17231724 if (si -> sn_save_cpo != NULL && si -> sn_is_vimrc == DOSO_NONE )
17241725 {
17251726 if (STRCMP (p_cpo , CPO_VIM ) != 0 )
@@ -1774,6 +1775,19 @@ do_source_ext(
17741775 apply_autocmds (EVENT_SOURCEPOST , fname_exp , fname_exp , FALSE, curbuf );
17751776
17761777theend :
1778+ if (sid > 0 && ret_sid != NULL
1779+ && fname_not_fixed != NULL && fname_exp != NULL )
1780+ {
1781+ int not_fixed_sid = find_script_by_name (fname_not_fixed );
1782+
1783+ // If "fname_not_fixed" is a symlink then we source the linked file.
1784+ // If the original name is in the script list we add the ID of the
1785+ // script that was actually sourced.
1786+ if (SCRIPT_ID_VALID (not_fixed_sid ) && not_fixed_sid != sid )
1787+ SCRIPT_ITEM (not_fixed_sid )-> sn_sourced_sid = sid ;
1788+ }
1789+
1790+ vim_free (fname_not_fixed );
17771791 vim_free (fname_exp );
17781792 sticky_cmdmod_flags = save_sticky_cmdmod_flags ;
17791793#ifdef FEAT_EVAL
@@ -1787,7 +1801,7 @@ do_source(
17871801 char_u * fname ,
17881802 int check_other , // check for .vimrc and _vimrc
17891803 int is_vimrc , // DOSO_ value
1790- int * ret_sid UNUSED )
1804+ int * ret_sid )
17911805{
17921806 return do_source_ext (fname , check_other , is_vimrc , ret_sid , NULL , FALSE);
17931807}
@@ -1828,9 +1842,16 @@ ex_scriptnames(exarg_T *eap)
18281842
18291843 if (si -> sn_name != NULL )
18301844 {
1845+ char sourced_buf [20 ];
1846+
18311847 home_replace (NULL , si -> sn_name , NameBuff , MAXPATHL , TRUE);
1832- vim_snprintf ((char * )IObuff , IOSIZE , "%3d%s: %s" ,
1848+ if (si -> sn_sourced_sid > 0 )
1849+ vim_snprintf (sourced_buf , 20 , "->%d" , si -> sn_sourced_sid );
1850+ else
1851+ sourced_buf [0 ] = NUL ;
1852+ vim_snprintf ((char * )IObuff , IOSIZE , "%3d%s%s: %s" ,
18331853 i ,
1854+ sourced_buf ,
18341855 si -> sn_state == SN_STATE_NOT_LOADED ? " A" : "" ,
18351856 NameBuff );
18361857 if (!message_filtered (IObuff ))
@@ -1946,6 +1967,7 @@ f_getscriptinfo(typval_T *argvars UNUSED, typval_T *rettv)
19461967 || list_append_dict (l , d ) == FAIL
19471968 || dict_add_string (d , "name" , si -> sn_name ) == FAIL
19481969 || dict_add_number (d , "sid" , i ) == FAIL
1970+ || dict_add_number (d , "sourced" , si -> sn_sourced_sid ) == FAIL
19491971 || dict_add_bool (d , "autoload" ,
19501972 si -> sn_state == SN_STATE_NOT_LOADED ) == FAIL )
19511973 return ;
0 commit comments