Skip to content

Commit 07dc18f

Browse files
committed
patch 8.1.0553: it is not easy to edit a script that was sourced
Problem: It is not easy to edit a script that was sourced. Solution: Add a count to ":scriptnames", so that ":script 40" edits the script with script ID 40.
1 parent 01a060d commit 07dc18f

7 files changed

Lines changed: 58 additions & 12 deletions

File tree

runtime/doc/repeat.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
334334
{not in Vi} {not available when compiled without the
335335
|+eval| feature}
336336

337+
:scr[iptnames][!] {scriptId} *:script*
338+
Edit script {scriptId}. Suggested name is ":script".
339+
337340
*:fini* *:finish* *E168*
338341
:fini[sh] Stop sourcing a script. Can only be used in a Vim
339342
script file. This is a quick way to skip the rest of

src/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ NEW_TESTS = \
153153
test_reltime \
154154
test_retab \
155155
test_ruby \
156+
test_scriptnames \
156157
test_scroll_opt \
157158
test_scrollbind \
158159
test_search \

src/ex_cmds.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@
6262
#define FILE1 (FILES | NOSPC) /* 1 file allowed, defaults to current file */
6363

6464
/* values for cmd_addr_type */
65-
#define ADDR_LINES 0
66-
#define ADDR_WINDOWS 1
67-
#define ADDR_ARGUMENTS 2
68-
#define ADDR_LOADED_BUFFERS 3
69-
#define ADDR_BUFFERS 4
70-
#define ADDR_TABS 5
71-
#define ADDR_TABS_RELATIVE 6 /* Tab page that only relative */
72-
#define ADDR_QUICKFIX 7
73-
#define ADDR_OTHER 99
65+
#define ADDR_LINES 0 // buffer line numbers
66+
#define ADDR_WINDOWS 1 // window number
67+
#define ADDR_ARGUMENTS 2 // argument number
68+
#define ADDR_LOADED_BUFFERS 3 // buffer number of loaded buffer
69+
#define ADDR_BUFFERS 4 // buffer number
70+
#define ADDR_TABS 5 // tab page number
71+
#define ADDR_TABS_RELATIVE 6 // Tab page that only relative
72+
#define ADDR_QUICKFIX 7 // quickfix list entry number
73+
#define ADDR_OTHER 99 // something else
7474

7575
#ifndef DO_DECLARE_EXCMD
7676
typedef struct exarg exarg_T;
@@ -1260,8 +1260,8 @@ EX(CMD_sbrewind, "sbrewind", ex_brewind,
12601260
EDITCMD|TRLBAR,
12611261
ADDR_LINES),
12621262
EX(CMD_scriptnames, "scriptnames", ex_scriptnames,
1263-
TRLBAR|CMDWIN,
1264-
ADDR_LINES),
1263+
BANG|RANGE|NOTADR|COUNT|TRLBAR|CMDWIN,
1264+
ADDR_OTHER),
12651265
EX(CMD_scriptencoding, "scriptencoding", ex_scriptencoding,
12661266
WORD1|TRLBAR|CMDWIN,
12671267
ADDR_LINES),

src/ex_cmds2.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4690,10 +4690,23 @@ do_source(
46904690
* ":scriptnames"
46914691
*/
46924692
void
4693-
ex_scriptnames(exarg_T *eap UNUSED)
4693+
ex_scriptnames(exarg_T *eap)
46944694
{
46954695
int i;
46964696

4697+
if (eap->addr_count > 0)
4698+
{
4699+
// :script {scriptId}: edit the script
4700+
if (eap->line2 < 1 || eap->line2 > script_items.ga_len)
4701+
EMSG(_(e_invarg));
4702+
else
4703+
{
4704+
eap->arg = SCRIPT_ITEM(eap->line2).sn_name;
4705+
do_exedit(eap, NULL);
4706+
}
4707+
return;
4708+
}
4709+
46974710
for (i = 1; i <= script_items.ga_len && !got_int; ++i)
46984711
if (SCRIPT_ITEM(i).sn_name != NULL)
46994712
{

src/testdir/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ NEW_TESTS = test_arabic.res \
158158
test_registers.res \
159159
test_retab.res \
160160
test_ruby.res \
161+
test_scriptnames.res \
161162
test_scrollbind.res \
162163
test_search.res \
163164
test_shortpathname.res \

src/testdir/test_scriptnames.vim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
" Test for :scriptnames
2+
3+
func Test_scriptnames()
4+
call writefile(['let did_load_script = 123'], 'Xscripting')
5+
source Xscripting
6+
call assert_equal(123, g:did_load_script)
7+
8+
let scripts = split(execute('scriptnames'), "\n")
9+
let last = scripts[-1]
10+
call assert_match('\<Xscripting\>', last)
11+
let lastnr = substitute(last, '\D*\(\d\+\):.*', '\1', '')
12+
exe 'script ' . lastnr
13+
call assert_equal('Xscripting', expand('%:t'))
14+
15+
call assert_fails('script ' . (lastnr + 1), 'E474:')
16+
call assert_fails('script 0', 'E939:')
17+
18+
new
19+
call setline(1, 'nothing')
20+
call assert_fails('script ' . lastnr, 'E37:')
21+
exe 'script! ' . lastnr
22+
call assert_equal('Xscripting', expand('%:t'))
23+
24+
bwipe
25+
call delete('Xscripting')
26+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ static char *(features[]) =
792792

793793
static int included_patches[] =
794794
{ /* Add new patch number below this line */
795+
/**/
796+
553,
795797
/**/
796798
552,
797799
/**/

0 commit comments

Comments
 (0)