diff src/message.c @ 23825:0bd44e94dd14 v8.2.2454

patch 8.2.2454: leading space can not be made visible Commit: https://github.com/vim/vim/commit/91478ae49a1b2dc1de63821db731a343e855dcc0 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 3 15:58:13 2021 +0100 patch 8.2.2454: leading space can not be made visible Problem: Leading space can not be made visible. Solution: Add "lead:" to 'listchars'. (closes https://github.com/vim/vim/issues/7772)
author Bram Moolenaar <Bram@vim.org>
date Wed, 03 Feb 2021 16:00:07 +0100
parents 3239b0f3c592
children 0b1f5717dc4d
line wrap: on
line diff
--- a/src/message.c
+++ b/src/message.c
@@ -1831,18 +1831,32 @@ msg_prt_line(char_u *s, int list)
     int		n;
     int		attr = 0;
     char_u	*trail = NULL;
+    char_u	*lead = NULL;
     int		l;
     char_u	buf[MB_MAXBYTES + 1];
 
     if (curwin->w_p_list)
 	list = TRUE;
 
-    // find start of trailing whitespace
-    if (list && lcs_trail)
+    if (list)
     {
-	trail = s + STRLEN(s);
-	while (trail > s && VIM_ISWHITE(trail[-1]))
-	    --trail;
+	// find start of trailing whitespace
+	if (lcs_trail)
+	{
+	    trail = s + STRLEN(s);
+	    while (trail > s && VIM_ISWHITE(trail[-1]))
+		--trail;
+	}
+	// find end of leading whitespace
+	if (lcs_lead)
+	{
+	    lead = s;
+	    while (VIM_ISWHITE(lead[0]))
+		lead++;
+	    // in a line full of spaces all of them are treated as trailing
+	    if (*lead == NUL)
+		lead = NULL;
+	}
     }
 
     // output a space for an empty line, otherwise the line will be
@@ -1938,6 +1952,11 @@ msg_prt_line(char_u *s, int list)
 		// the same in plain text.
 		attr = HL_ATTR(HLF_8);
 	    }
+	    else if (c == ' ' && lead != NULL && s <= lead)
+	    {
+		c = lcs_lead;
+		attr = HL_ATTR(HLF_8);
+	    }
 	    else if (c == ' ' && trail != NULL && s > trail)
 	    {
 		c = lcs_trail;