diff options
author | Jurica Bradaric <jbradaric@gmail.com> | 2019-10-12 09:48:48 +0200 |
---|---|---|
committer | Jurica Bradaric <jbradaric@gmail.com> | 2019-10-13 00:03:27 +0200 |
commit | 6c012b0624935b93e92a0b12d86d49ef695210ba (patch) | |
tree | 130a76cb21add8fc2a175ac318eb5d598ca783b5 /src/nvim/eval.c | |
parent | 9af0fe529d2d91640e4d3388ab9f28159553f14c (diff) | |
download | rneovim-6c012b0624935b93e92a0b12d86d49ef695210ba.tar.gz rneovim-6c012b0624935b93e92a0b12d86d49ef695210ba.tar.bz2 rneovim-6c012b0624935b93e92a0b12d86d49ef695210ba.zip |
vim-patch:8.1.1585: :let-heredoc does not trim enough
Problem: :let-heredoc does not trim enough.
Solution: Trim indent from the contents based on the indent of the first
line. Use let-heredoc in more tests.
https://github.com/vim/vim/commit/e7eb92708ec2092a2fc11e78703b5dcf83844412
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a899dbcd3a..bedfe2d6d0 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1521,7 +1521,9 @@ heredoc_get(exarg_T *eap, char_u *cmd) { char_u *marker; char_u *p; - int indent_len = 0; + int marker_indent_len = 0; + int text_indent_len = 0; + char_u *text_indent = NULL; if (eap->getline == NULL) { EMSG(_("E991: cannot use =<< here")); @@ -1534,14 +1536,16 @@ heredoc_get(exarg_T *eap, char_u *cmd) && (cmd[4] == NUL || ascii_iswhite(cmd[4]))) { cmd = skipwhite(cmd + 4); - // Trim the indentation from all the lines in the here document + // Trim the indentation from all the lines in the here document. // The amount of indentation trimmed is the same as the indentation of - // the :let command line. + // the first line after the :let command line. To find the end marker + // the indent of the :let command line is trimmed. p = *eap->cmdlinep; while (ascii_iswhite(*p)) { p++; - indent_len++; + marker_indent_len++; } + text_indent_len = -1; } // The marker is the next word. Default marker is "." @@ -1559,28 +1563,48 @@ heredoc_get(exarg_T *eap, char_u *cmd) list_T *l = tv_list_alloc(0); for (;;) { - int i = 0; + int mi = 0; + int ti = 0; char_u *theline = eap->getline(NUL, eap->cookie, 0, false); - if (theline != NULL && indent_len > 0) { - // trim the indent matching the first line - if (STRNCMP(theline, *eap->cmdlinep, indent_len) == 0) { - i = indent_len; - } - } - if (theline == NULL) { EMSG2(_("E990: Missing end marker '%s'"), marker); break; } - if (STRCMP(marker, theline + i) == 0) { + + // with "trim": skip the indent matching the :let line to find the + // marker + if (marker_indent_len > 0 + && STRNCMP(theline, *eap->cmdlinep, marker_indent_len) == 0) { + mi = marker_indent_len; + } + if (STRCMP(marker, theline + mi) == 0) { xfree(theline); break; } + if (text_indent_len == -1 && *theline != NUL) { + // set the text indent from the first line. + p = theline; + text_indent_len = 0; + while (ascii_iswhite(*p)) { + p++; + text_indent_len++; + } + text_indent = vim_strnsave(theline, text_indent_len); + } + // with "trim": skip the indent matching the first line + if (text_indent != NULL) { + for (ti = 0; ti < text_indent_len; ti++) { + if (theline[ti] != text_indent[ti]) { + break; + } + } + } - tv_list_append_string(l, (char *)(theline + i), -1); + tv_list_append_string(l, (char *)(theline + ti), -1); xfree(theline); } + xfree(text_indent); return l; } |