]> granicus.if.org Git - vim/commitdiff
patch 8.2.0690: line number of option set by modeline is wrong v8.2.0690
authorBram Moolenaar <Bram@vim.org>
Sun, 3 May 2020 15:19:33 +0000 (17:19 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 3 May 2020 15:19:33 +0000 (17:19 +0200)
Problem:    Line number of option set by modeline is wrong.
Solution:   Do not double the line number. (Ozaki Kiichi, closes #6035)

src/option.c
src/testdir/test_modeline.vim
src/version.c

index 3f97c3cd157b4c949e01f6dbf99645814fdb7134..8574f7f7cb47aa991a6bb54de201e5b1cdd918a0 100644 (file)
@@ -2460,7 +2460,9 @@ set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
     int                indir = (int)options[opt_idx].indir;
     sctx_T     new_script_ctx = script_ctx;
 
-    new_script_ctx.sc_lnum += SOURCING_LNUM;
+    // Modeline already has the line number set.
+    if (!(opt_flags & OPT_MODELINE))
+       new_script_ctx.sc_lnum += SOURCING_LNUM;
 
     // Remember where the option was set.  For local options need to do that
     // in the buffer or window structure.
index 05a146019821c860162fe67cb3b826e4dec08a9f..546c30c668a76c0085bdce422c106fbc8434735d 100644 (file)
@@ -279,3 +279,59 @@ func Test_modeline_fails_modelineexpr()
   call s:modeline_fails('tabline', 'tabline=Something()', 'E992:')
   call s:modeline_fails('titlestring', 'titlestring=Something()', 'E992:')
 endfunc
+
+func Test_modeline_setoption_verbose()
+  let modeline = &modeline
+  set modeline
+
+  let lines =<< trim END
+  1 vim:ts=2
+  2 two
+  3 three
+  4 four
+  5 five
+  6 six
+  7 seven
+  8 eight
+  END
+  call writefile(lines, 'Xmodeline')
+  edit Xmodeline
+  let info = split(execute('verbose set tabstop?'), "\n")
+  call assert_match('^\s*Last set from modeline line 1$', info[-1])
+  bwipe!
+
+  let lines =<< trim END
+  1 one
+  2 two
+  3 three
+  4 vim:ts=4
+  5 five
+  6 six
+  7 seven
+  8 eight
+  END
+  call writefile(lines, 'Xmodeline')
+  edit Xmodeline
+  let info = split(execute('verbose set tabstop?'), "\n")
+  call assert_match('^\s*Last set from modeline line 4$', info[-1])
+  bwipe!
+
+  let lines =<< trim END
+  1 one
+  2 two
+  3 three
+  4 four
+  5 five
+  6 six
+  7 seven
+  8 vim:ts=8
+  END
+  call writefile(lines, 'Xmodeline')
+  edit Xmodeline
+  let info = split(execute('verbose set tabstop?'), "\n")
+  call assert_match('^\s*Last set from modeline line 8$', info[-1])
+  bwipe!
+
+  let &modeline = modeline
+  call delete('Xmodeline')
+endfunc
index c083372006f6843cb139006721d76d06a5258b0c..6dc86b96434bd614b78c8595895cbd86b1161c70 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    690,
 /**/
     689,
 /**/