]> granicus.if.org Git - vim/commitdiff
patch 8.1.0553: it is not easy to edit a script that was sourced v8.1.0553
authorBram Moolenaar <Bram@vim.org>
Fri, 30 Nov 2018 21:48:32 +0000 (22:48 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 30 Nov 2018 21:48:32 +0000 (22:48 +0100)
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.

runtime/doc/repeat.txt
src/Make_all.mak
src/ex_cmds.h
src/ex_cmds2.c
src/testdir/Make_all.mak
src/testdir/test_scriptnames.vim [new file with mode: 0644]
src/version.c

index 8538d0c2f2e180797f13414d4a1a6ab66cc5c52f..6e652202b8ee2021001db6d2e85ca30dc015afb8 100644 (file)
@@ -334,6 +334,9 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
                        {not in Vi} {not available when compiled without the
                        |+eval| feature}
 
+:scr[iptnames][!] {scriptId}                   *:script*
+                       Edit script {scriptId}.  Suggested name is ":script".
+
                                                *:fini* *:finish* *E168*
 :fini[sh]              Stop sourcing a script.  Can only be used in a Vim
                        script file.  This is a quick way to skip the rest of
index da3a62ca8baed634a3ea6ee4f1b807845b67e743..466f17e9e2d8267b5643fea17db28a2271b5c71d 100644 (file)
@@ -153,6 +153,7 @@ NEW_TESTS = \
        test_reltime \
        test_retab \
        test_ruby \
+       test_scriptnames \
        test_scroll_opt \
        test_scrollbind \
        test_search \
index c5e0bf4495abb1a39bd9bd1eec05f316f850feda..335871a01baca3831c720e131408ec6c98e29997 100644 (file)
 #define FILE1  (FILES | NOSPC) /* 1 file allowed, defaults to current file */
 
 /* values for cmd_addr_type */
-#define ADDR_LINES             0
-#define ADDR_WINDOWS           1
-#define ADDR_ARGUMENTS         2
-#define ADDR_LOADED_BUFFERS    3
-#define ADDR_BUFFERS           4
-#define ADDR_TABS              5
-#define ADDR_TABS_RELATIVE     6   /* Tab page that only relative */
-#define ADDR_QUICKFIX          7
-#define ADDR_OTHER             99
+#define ADDR_LINES             0   // buffer line numbers
+#define ADDR_WINDOWS           1   // window number
+#define ADDR_ARGUMENTS         2   // argument number
+#define ADDR_LOADED_BUFFERS    3   // buffer number of loaded buffer
+#define ADDR_BUFFERS           4   // buffer number
+#define ADDR_TABS              5   // tab page number
+#define ADDR_TABS_RELATIVE     6   // Tab page that only relative
+#define ADDR_QUICKFIX          7   // quickfix list entry number
+#define ADDR_OTHER             99  // something else
 
 #ifndef DO_DECLARE_EXCMD
 typedef struct exarg exarg_T;
@@ -1260,8 +1260,8 @@ EX(CMD_sbrewind,  "sbrewind",     ex_brewind,
                        EDITCMD|TRLBAR,
                        ADDR_LINES),
 EX(CMD_scriptnames,    "scriptnames",  ex_scriptnames,
-                       TRLBAR|CMDWIN,
-                       ADDR_LINES),
+                       BANG|RANGE|NOTADR|COUNT|TRLBAR|CMDWIN,
+                       ADDR_OTHER),
 EX(CMD_scriptencoding, "scriptencoding", ex_scriptencoding,
                        WORD1|TRLBAR|CMDWIN,
                        ADDR_LINES),
index d6b6f5bf89a36654748f4c63449fc5f7686cebcc..c3f26b64c5738e97ee491db21328b9c23549e844 100644 (file)
@@ -4690,10 +4690,23 @@ theend:
  * ":scriptnames"
  */
     void
-ex_scriptnames(exarg_T *eap UNUSED)
+ex_scriptnames(exarg_T *eap)
 {
     int i;
 
+    if (eap->addr_count > 0)
+    {
+       // :script {scriptId}: edit the script
+       if (eap->line2 < 1 || eap->line2 > script_items.ga_len)
+           EMSG(_(e_invarg));
+       else
+       {
+           eap->arg = SCRIPT_ITEM(eap->line2).sn_name;
+           do_exedit(eap, NULL);
+       }
+       return;
+    }
+
     for (i = 1; i <= script_items.ga_len && !got_int; ++i)
        if (SCRIPT_ITEM(i).sn_name != NULL)
        {
index 45f45d7fd8a46e0de57fc10e8f96ec7e393574e3..5b851567376c74b5e2881ddb1c20c0df350067b5 100644 (file)
@@ -158,6 +158,7 @@ NEW_TESTS = test_arabic.res \
            test_registers.res \
            test_retab.res \
            test_ruby.res \
+           test_scriptnames.res \
            test_scrollbind.res \
            test_search.res \
            test_shortpathname.res \
diff --git a/src/testdir/test_scriptnames.vim b/src/testdir/test_scriptnames.vim
new file mode 100644 (file)
index 0000000..fc6c910
--- /dev/null
@@ -0,0 +1,26 @@
+" Test for :scriptnames
+
+func Test_scriptnames()
+  call writefile(['let did_load_script = 123'], 'Xscripting')
+  source Xscripting
+  call assert_equal(123, g:did_load_script)
+
+  let scripts = split(execute('scriptnames'), "\n")
+  let last = scripts[-1]
+  call assert_match('\<Xscripting\>', last)
+  let lastnr = substitute(last, '\D*\(\d\+\):.*', '\1', '')
+  exe 'script ' . lastnr
+  call assert_equal('Xscripting', expand('%:t'))
+
+  call assert_fails('script ' . (lastnr + 1), 'E474:')
+  call assert_fails('script 0', 'E939:')
+
+  new
+  call setline(1, 'nothing')
+  call assert_fails('script ' . lastnr, 'E37:')
+  exe 'script! ' . lastnr
+  call assert_equal('Xscripting', expand('%:t'))
+
+  bwipe
+  call delete('Xscripting')
+endfunc
index 1fc35edd73de9c8291eca6eedca2850f32f1e2eb..5f61775ac0ff4609cef85b984ad63010922c870f 100644 (file)
@@ -792,6 +792,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    553,
 /**/
     552,
 /**/