diff src/userfunc.c @ 17251:984eef966002 v8.1.1625

patch 8.1.1625: script line numbers are not exactly right commit https://github.com/vim/vim/commit/bc2cfe4672d370330b8698d4d025697a9a6ec569 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jul 4 14:57:12 2019 +0200 patch 8.1.1625: script line numbers are not exactly right Problem: Script line numbers are not exactly right. Solution: Handle heredoc and continuation lines better. (Ozaki Kiichi, closes #4611, closes #4511)
author Bram Moolenaar <Bram@vim.org>
date Thu, 04 Jul 2019 15:00:07 +0200
parents 40c4cb095d53
children ba06a1c42274
line wrap: on
line diff
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -2008,7 +2008,8 @@ ex_function(exarg_T *eap)
     int		todo;
     hashitem_T	*hi;
     int		do_concat = TRUE;
-    int		sourcing_lnum_off;
+    linenr_T	sourcing_lnum_off;
+    linenr_T	sourcing_lnum_top;
 
     /*
      * ":function" without argument: list functions.
@@ -2275,6 +2276,9 @@ ex_function(exarg_T *eap)
 	cmdline_row = msg_row;
     }
 
+    // Save the starting line number.
+    sourcing_lnum_top = sourcing_lnum;
+
     indent = 2;
     nesting = 0;
     for (;;)
@@ -2285,7 +2289,6 @@ ex_function(exarg_T *eap)
 	    saved_wait_return = FALSE;
 	}
 	need_wait_return = FALSE;
-	sourcing_lnum_off = sourcing_lnum;
 
 	if (line_arg != NULL)
 	{
@@ -2318,8 +2321,9 @@ ex_function(exarg_T *eap)
 	}
 
 	/* Detect line continuation: sourcing_lnum increased more than one. */
-	if (sourcing_lnum > sourcing_lnum_off + 1)
-	    sourcing_lnum_off = sourcing_lnum - sourcing_lnum_off - 1;
+	sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie);
+	if (sourcing_lnum < sourcing_lnum_off)
+	    sourcing_lnum_off -= sourcing_lnum;
 	else
 	    sourcing_lnum_off = 0;
 
@@ -2670,7 +2674,7 @@ ex_function(exarg_T *eap)
     fp->uf_flags = flags;
     fp->uf_calls = 0;
     fp->uf_script_ctx = current_sctx;
-    fp->uf_script_ctx.sc_lnum += sourcing_lnum - newlines.ga_len - 1;
+    fp->uf_script_ctx.sc_lnum += sourcing_lnum_top;
     goto ret_free;
 
 erret: