mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
vim-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 vim/vim#4611, closes vim/vim#4511)
bc2cfe4672
This commit is contained in:
@@ -97,10 +97,11 @@ typedef struct sn_prl_S {
|
||||
struct source_cookie {
|
||||
FILE *fp; ///< opened file for sourcing
|
||||
char_u *nextline; ///< if not NULL: line that was read ahead
|
||||
linenr_T sourcing_lnum; ///< line number of the source file
|
||||
int finished; ///< ":finish" used
|
||||
#if defined(USE_CRNL)
|
||||
int fileformat; ///< EOL_UNKNOWN, EOL_UNIX or EOL_DOS
|
||||
bool error; ///< true if LF found after CR-LF
|
||||
bool error; ///< true if LF found after CR-LF
|
||||
#endif
|
||||
linenr_T breakpoint; ///< next line with breakpoint or zero
|
||||
char_u *fname; ///< name of sourced file
|
||||
@@ -3124,6 +3125,7 @@ int do_source(char_u *fname, int check_other, int is_vimrc)
|
||||
#endif
|
||||
|
||||
cookie.nextline = NULL;
|
||||
cookie.sourcing_lnum = 0;
|
||||
cookie.finished = false;
|
||||
|
||||
// Check if this script has a breakpoint.
|
||||
@@ -3375,6 +3377,13 @@ void free_scriptnames(void)
|
||||
}
|
||||
# endif
|
||||
|
||||
linenr_T get_sourced_lnum(LineGetter fgetline, void *cookie)
|
||||
{
|
||||
return fgetline == getsourceline
|
||||
? ((struct source_cookie *)cookie)->sourcing_lnum
|
||||
: sourcing_lnum;
|
||||
}
|
||||
|
||||
|
||||
/// Get one full line from a sourced file.
|
||||
/// Called by do_cmdline() when it's called from do_source().
|
||||
@@ -3395,6 +3404,8 @@ char_u *getsourceline(int c, void *cookie, int indent, bool do_concat)
|
||||
if (do_profiling == PROF_YES) {
|
||||
script_line_end();
|
||||
}
|
||||
// Set the current sourcing line number.
|
||||
sourcing_lnum = sp->sourcing_lnum + 1;
|
||||
// Get current line. If there is a read-ahead line, use it, otherwise get
|
||||
// one now.
|
||||
if (sp->finished) {
|
||||
@@ -3404,7 +3415,7 @@ char_u *getsourceline(int c, void *cookie, int indent, bool do_concat)
|
||||
} else {
|
||||
line = sp->nextline;
|
||||
sp->nextline = NULL;
|
||||
sourcing_lnum++;
|
||||
sp->sourcing_lnum++;
|
||||
}
|
||||
if (line != NULL && do_profiling == PROF_YES) {
|
||||
script_line_start();
|
||||
@@ -3414,7 +3425,7 @@ char_u *getsourceline(int c, void *cookie, int indent, bool do_concat)
|
||||
// contain the 'C' flag.
|
||||
if (line != NULL && do_concat && (vim_strchr(p_cpo, CPO_CONCAT) == NULL)) {
|
||||
// compensate for the one line read-ahead
|
||||
sourcing_lnum--;
|
||||
sp->sourcing_lnum--;
|
||||
|
||||
// Get the next line and concatenate it when it starts with a
|
||||
// backslash. We always need to read the next line, keep it in
|
||||
@@ -3492,7 +3503,7 @@ static char_u *get_one_sourceline(struct source_cookie *sp)
|
||||
ga_init(&ga, 1, 250);
|
||||
|
||||
// Loop until there is a finished line (or end-of-file).
|
||||
sourcing_lnum++;
|
||||
sp->sourcing_lnum++;
|
||||
for (;; ) {
|
||||
// make room to read at least 120 (more) characters
|
||||
ga_grow(&ga, 120);
|
||||
@@ -3559,7 +3570,7 @@ retry:
|
||||
// len&c parities (is faster than ((len-c)%2 == 0)) -- Acevedo
|
||||
for (c = len - 2; c >= 0 && buf[c] == Ctrl_V; c--) {}
|
||||
if ((len & 1) != (c & 1)) { // escaped NL, read more
|
||||
sourcing_lnum++;
|
||||
sp->sourcing_lnum++;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user