On Wednesday, November 27, 2013 8:29:28 PM UTC+5:30, Ken Takata wrote:
> Hi,
> 
> 2013/11/27 Wed 23:34:12 UTC+9 ZyX wrote:
> > On Nov 27, 2013 10:56 AM, "hari.g" <[email protected]> wrote:
> > >
> > > Hi,
> > >
> > > The attached patch adds a 'listchars' option 'lsp' which marks leading 
> > > space at 'shiftwidth' with the defined characer so that you can follow 
> > > the indent level in a bit too much nested code when you also have 
> > > 'expandtab' option set and use spaces for indentation (e.g. Python code 
> > > in many repos enforce a 'spaces only indenting' policy).
> > 
> > This functionality would be good to have and I see it constantly seeked in 
> > vim-use and stackoverflow. But there are some issues though:
> > 
> > 0. No tests. There is screenchar()/screenattr() pair for the tests.

I've added a test for this change (Haven't been able to run the testsuite 
though).

> > 1. I fail to comprehend what "lsp" stands for. Guess it is abbreviation: 
> > Leading Space P... Pwhat?

'lsp' was just a take on 'nbsp' (No-Break SPace), I also feel that it isn't 
much meaningful (since the substition happens only for some space characters). 
Any suggestions?

> > 2. Your patch strips out meaningful trailing spaces from documentation.
> > 3. It also adds something to Make_mvc.mak which is not related (if you have 
> > to use it to compile it should be a separate patch).

Reverted.

> > 4. No interline tabs in nw_seen declaration.
> > 5. Tabs are not used in line
> >     +            nw_seen = nw_seen || !vim_iswhite(c);
> > 
Fixed.

> 
> I found two more issues:
> 
> 6. `:set sw=0` causes a crash.
> 7. C99 style comment should not be used.
> 
Fixed.

A modified patch is attached.

Thanks for the input.

--
hari.g

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff -r fe4feaa73453 runtime/doc/options.txt
@@ -4690,6 +4690,11 @@
 	  nbsp:c	Character to show for a non-breakable space (character
 			0xA0, 160).  Left blank when omitted.

+	  						*lcs-lsp*
+	  lsp:c	Character to show for leading space characters which
+			are part of the indentation. Useful when you have
+			'expandtab' also specified.
+
 	The characters ':' and ',' should not be used.  UTF-8 characters can
 	be used when 'encoding' is "utf-8", otherwise only printable
 	characters are allowed.  All characters must be single width.
diff -r fe4feaa73453 src/globals.h
--- a/src/globals.h	Mon Nov 18 14:42:51 2013 +0530
+++ b/src/globals.h	Wed Nov 27 22:59:25 2013 +0530
@@ -1157,6 +1157,7 @@
 EXTERN int	lcs_eol INIT(= '$');
 EXTERN int	lcs_ext INIT(= NUL);
 EXTERN int	lcs_prec INIT(= NUL);
+EXTERN int	lcs_lsp INIT(= NUL);
 EXTERN int	lcs_nbsp INIT(= NUL);
 EXTERN int	lcs_tab1 INIT(= NUL);
 EXTERN int	lcs_tab2 INIT(= NUL);
diff -r fe4feaa73453 src/option.c
--- a/src/option.c	Mon Nov 18 14:42:51 2013 +0530
+++ b/src/option.c	Wed Nov 27 22:59:25 2013 +0530
@@ -7284,6 +7284,7 @@
 	{&lcs_ext,	"extends"},
 	{&lcs_nbsp,	"nbsp"},
 	{&lcs_prec,	"precedes"},
+	{&lcs_lsp,	"lsp"},
 	{&lcs_tab2,	"tab"},
 	{&lcs_trail,	"trail"},
 #ifdef FEAT_CONCEAL
diff -r fe4feaa73453 src/screen.c
--- a/src/screen.c	Mon Nov 18 14:42:51 2013 +0530
+++ b/src/screen.c	Wed Nov 27 22:59:25 2013 +0530
@@ -2847,6 +2847,7 @@
     long	vcol_prev = -1;		/* "vcol" of previous character */
     char_u	*line;			/* current line */
     char_u	*ptr;			/* current position in "line" */
+    int         nw_seen = 0;		/* Seen a non-white character */
     int		row;			/* row in the window, excl w_winrow */
     int		screen_row;		/* row on the screen, incl w_winrow */

@@ -3251,6 +3252,7 @@

     line = ml_get_buf(wp->w_buffer, lnum, FALSE);
     ptr = line;
+    nw_seen = 0; /* Reset for each line */

 #ifdef FEAT_SPELL
     if (has_spell)
@@ -4035,6 +4037,7 @@
 	     * Get a character from the line itself.
 	     */
 	    c = *ptr;
+	    nw_seen = nw_seen || !vim_iswhite(c);
 #ifdef FEAT_MBYTE
 	    if (has_mbyte)
 	    {
@@ -4228,13 +4231,37 @@
 	    ++ptr;

 	    /* 'list' : change char 160 to lcs_nbsp. */
-	    if (wp->w_p_list && (c == 160
+	    if (wp->w_p_list && ((c == 160
 #ifdef FEAT_MBYTE
 			|| (mb_utf8 && mb_c == 160)
 #endif
 			) && lcs_nbsp)
-	    {
-		c = lcs_nbsp;
+		    /* :set listchar=lsp:+ marks leading spaces used f.e.
+		     * in indenting of Python
+		     */
+		    || (!nw_seen && (c == 32
+#ifdef FEAT_MBYTE
+			|| (mb_utf8 && mb_c == 32)
+#endif
+			) && lcs_lsp))
+	    {
+		if (c == 160
+#ifdef FEAT_MBYTE
+			|| (mb_utf8 && mb_c == 160)
+#endif
+		   )
+		{
+		    c = lcs_nbsp;
+		}
+		else
+		{
+		    /* Display substitute for each space character */
+		    if (curbuf->b_p_sw == 0)
+			c = lcs_lsp;
+		    /* Substitute space after each sw */
+		    else if (vcol && vcol % curbuf->b_p_sw == 0)
+			c = lcs_lsp;
+		}
 		if (area_attr == 0 && search_attr == 0)
 		{
 		    n_attr = 1;
diff -r fe4feaa73453 src/testdir/Makefile
--- a/src/testdir/Makefile	Mon Nov 18 14:42:51 2013 +0530
+++ b/src/testdir/Makefile	Wed Nov 27 23:15:23 2013 +0530
@@ -30,7 +30,8 @@
 		test84.out test85.out test86.out test87.out test88.out \
 		test89.out test90.out test91.out test92.out test93.out \
 		test94.out test95.out test96.out test97.out test98.out \
-		test99.out test100.out test101.out test102.out test103.out
+		test99.out test100.out test101.out test102.out test103.out \
+		test104.out
 
 SCRIPTS_GUI = test16.out
 
diff -r fe4feaa73453 src/testdir/test104.in
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/testdir/test104.in	Wed Nov 27 22:59:25 2013 +0530
@@ -0,0 +1,10 @@
+Test for 'listchars' options
+STARTTEST
+:so small.vim
+:enew
+:call setline(1, '          A     B ')
+:set list sts=4 ts=4 sw=4 nolazyredraw nonumber listchars=lsp:+
+:let r = ['start', screenchar(1,5), screenchar(1,9), screenchar(1,13), 'end']
+:call append(line('$'), r)
+:2,$wq! test.out
+ENDTEST
diff -r fe4feaa73453 src/testdir/test104.ok
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/testdir/test104.ok	Wed Nov 27 22:59:25 2013 +0530
@@ -0,0 +1,5 @@
+start
+43
+43
+32
+end

Raspunde prin e-mail lui