Patch: support for the "space" argument for "listchars"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Patch: support for the "space" argument for "listchars"

Jérémie Roquet

Hello,

I've just started to use Vim, and missed the possibility to display
middle-dots (or any other visible character) instead of spaces, so I
made the following patch.
It adds "space" in the allowed "listchars" arguments.

Just in case someone find this useful ; I found easier to patch Vim
than to look for another existing solution ;-)

Best regards,

Index: option.c
===================================================================
--- option.c (revision 1626)
+++ option.c (working copy)
@@ -6847,6 +6847,7 @@
  {&lcs_ext, "extends"},
  {&lcs_nbsp, "nbsp"},
  {&lcs_prec, "precedes"},
+ {&lcs_space, "space"},
  {&lcs_tab2, "tab"},
  {&lcs_trail, "trail"},
     };
Index: screen.c
===================================================================
--- screen.c (revision 1626)
+++ screen.c (working copy)
@@ -3886,6 +3886,18 @@
 #endif
     }

+    /* 'list' : change space to lcs_space. */
+    if (wp->w_p_list && c == ' ' && lcs_space)
+    {
+ c = lcs_space;
+ if (area_attr == 0 && search_attr == 0)
+ {
+    n_attr = 1;
+    extra_attr = hl_attr(HLF_8);
+    saved_attr2 = char_attr; /* save current attr */
+ }
+    }
+
     if (extra_check)
     {
 #ifdef FEAT_SPELL
@@ -4040,7 +4052,7 @@
  }
 #endif

- if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
+ if (trailcol != MAXCOL && ptr > line + trailcol && (c == ' ' || c
== lcs_space))
  {
     c = lcs_trail;
     if (!attr_pri)
Index: globals.h
===================================================================
--- globals.h (revision 1626)
+++ globals.h (working copy)
@@ -1146,6 +1146,7 @@
 EXTERN int lcs_tab1 INIT(= NUL);
 EXTERN int lcs_tab2 INIT(= NUL);
 EXTERN int lcs_trail INIT(= NUL);
+EXTERN int lcs_space INIT(= NUL);

 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) \
  || defined(FEAT_FOLDING)

--
Jérémie Roquet - Arkanosis
Programming artist
Developer in natural language processing - Exalead

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Patch: support for the "space" argument for "listchars"

Steve Hall-3

From: Jérémie_Roquet, Wed, October 21, 2009 10:26 am
>
> I've just started to use Vim, and missed the possibility to display
> middle-dots (or any other visible character) instead of spaces, so I
> made the following patch.
> It adds "space" in the allowed "listchars" arguments.

Nice! Bram, any chance this could become official?


--
Steve Hall  [ digitect dancingpaper com ]



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Patch: support for the "space" argument for "listchars"

Jérémie Roquet
In reply to this post by Jérémie Roquet

2009/10/21 Jérémie Roquet <[hidden email]>:
> I've just started to use Vim, and missed the possibility to display
> middle-dots (or any other visible character) instead of spaces, so I
> made the following patch.
> [...]

I'm sorry, the previous patch cause a segmentation fault if you don't
use the "space" argument.
The following fixes this (added "&& lcs_space" in screen.c).

Again, sorry for this.

Best regards,

Index: option.c
===================================================================
--- option.c (revision 1626)
+++ option.c (working copy)
@@ -6847,6 +6847,7 @@
  {&lcs_ext, "extends"},
  {&lcs_nbsp, "nbsp"},
  {&lcs_prec, "precedes"},
+ {&lcs_space, "space"},
  {&lcs_tab2, "tab"},
  {&lcs_trail, "trail"},
     };
Index: screen.c
===================================================================
--- screen.c (revision 1626)
+++ screen.c (working copy)
@@ -3886,6 +3886,18 @@
 #endif
     }

+    /* 'list' : change space to lcs_space. */
+    if (wp->w_p_list && c == ' ' && lcs_space)
+    {
+ c = lcs_space;
+ if (area_attr == 0 && search_attr == 0)
+ {
+    n_attr = 1;
+    extra_attr = hl_attr(HLF_8);
+    saved_attr2 = char_attr; /* save current attr */
+ }
+    }
+
     if (extra_check)
     {
 #ifdef FEAT_SPELL
@@ -4040,7 +4052,7 @@
  }
 #endif

- if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
+ if (trailcol != MAXCOL && ptr > line + trailcol && (c == ' ' || c
== lcs_space && lcs_space))
  {
     c = lcs_trail;
     if (!attr_pri)
Index: globals.h
===================================================================
--- globals.h (revision 1626)
+++ globals.h (working copy)
@@ -1146,6 +1146,7 @@
 EXTERN int lcs_tab1 INIT(= NUL);
 EXTERN int lcs_tab2 INIT(= NUL);
 EXTERN int lcs_trail INIT(= NUL);
+EXTERN int lcs_space INIT(= NUL);

 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) \
  || defined(FEAT_FOLDING)

--
Jérémie Roquet - Arkanosis
Programming artist
Developer in natural language processing - Exalead

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Patch: support for the "space" argument for "listchars"

Bram Moolenaar
In reply to this post by Jérémie Roquet


Jérémie Roquet wrote:

> I've just started to use Vim, and missed the possibility to display
> middle-dots (or any other visible character) instead of spaces, so I
> made the following patch.
> It adds "space" in the allowed "listchars" arguments.
>
> Just in case someone find this useful ; I found easier to patch Vim
> than to look for another existing solution ;-)

I'm confused.  It appears the "space" character is both used to display
instead of a space character when 'list' is on, and to find this
character after the end of the line and replace it with "trail".
To me these are two unrelated things.

I'm not sure how useful it is to show something instead of a space.
Isn't it obvious that there is a space when there is nothing?

--
Two cows are standing together in a field.  One asks the other:
"So what do you think about this Mad Cow Disease?"
The other replies: "That doesn't concern me. I'm a helicopter."

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Patch: support for the "space" argument for "listchars"

Steve Hall-3

On Wed, 2009-10-28 at 22:06 +0100, Bram Moolenaar wrote:
>
> I'm not sure how useful it is to show something instead of a space.
> Isn't it obvious that there is a space when there is nothing?

Bram, I can't speak for the author, but I'd like this feature to make
it easy to visualize:

* other non-printing characters that look like dec 032
* double spaces
* spaces after chars at window edges with wrap on
* every char as a byte

Currently, Vim can show every "invisible" character except
intermediate spaces, why not add it and be complete? :)

--
Steve Hall  [ digitect dancingpaper com ]



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Patch: support for the "space" argument for "listchars"

Jérémie Roquet
In reply to this post by Bram Moolenaar

Hello,

2009/10/28 Bram Moolenaar <[hidden email]>:
>> It adds "space" in the allowed "listchars" arguments.
> I'm confused.  It appears the "space" character is both used to display
> instead of a space character when 'list' is on, and to find this
> character after the end of the line and replace it with "trail".
> To me these are two unrelated things.

You are right. This was because spaces were already replaced at that
point, making the replacement with "trail" impossible.
But it leads to side effects if the "space replacement" character is
actually used in the edited file.

Here is a new patch without this annoying side-effect.

> I'm not sure how useful it is to show something instead of a space.
> Isn't it obvious that there is a space when there is nothing?

Sometimes it's not : I'm using a visible character for the first
column of tabs, but an invisible one for the remaining columns.
So cases where a tab is followed by a space are not that obvious.
And as Steve pointed out, double spaces are not always obvious either.

2009/10/29 Steve Hall <[hidden email]>
> Bram, I can't speak for the author, but I'd like this feature to make
> it easy to visualize:
> * other non-printing characters that look like dec 032
> * double spaces
> * spaces after chars at window edges with wrap on
> * every char as a byte

As for now, only the ' ' character is displayed, but it'd easy to support more.

Best regards,

Index: src/option.c
===================================================================
--- src/option.c (revision 1626)
+++ src/option.c (working copy)
@@ -6847,6 +6847,7 @@
  {&lcs_ext, "extends"},
  {&lcs_nbsp, "nbsp"},
  {&lcs_prec, "precedes"},
+ {&lcs_space, "space"},
  {&lcs_tab2, "tab"},
  {&lcs_trail, "trail"},
     };
Index: src/screen.c
===================================================================
--- src/screen.c (revision 1626)
+++ src/screen.c (working copy)
@@ -3886,6 +3886,29 @@
 #endif
     }

+    /* 'list' : change space to lcs_space. */
+    if (wp->w_p_list && c == ' ' && lcs_space && ptr <= line + trailcol)
+    {
+ c = lcs_space;
+ if (area_attr == 0 && search_attr == 0)
+ {
+    n_attr = 1;
+    extra_attr = hl_attr(HLF_8);
+    saved_attr2 = char_attr; /* save current attr */
+ }
+#ifdef FEAT_MBYTE
+ mb_c = c;
+ if (enc_utf8 && (*mb_char2len)(c) > 1)
+ {
+    mb_utf8 = TRUE;
+    u8cc[0] = 0;
+    c = 0xc0;
+ }
+ else
+    mb_utf8 = FALSE;
+#endif
+    }
+
     if (extra_check)
     {
 #ifdef FEAT_SPELL
Index: src/globals.h
===================================================================
--- src/globals.h (revision 1626)
+++ src/globals.h (working copy)
@@ -1146,6 +1146,7 @@
 EXTERN int lcs_tab1 INIT(= NUL);
 EXTERN int lcs_tab2 INIT(= NUL);
 EXTERN int lcs_trail INIT(= NUL);
+EXTERN int lcs_space INIT(= NUL);

 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) \
  || defined(FEAT_FOLDING)


--
Jérémie Roquet - Arkanosis
Programming artist
Developer in natural language processing - Exalead

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Patch: support for the "space" argument for "listchars"

Bram Moolenaar


Jérémie Roquet wrote:

> 2009/10/28 Bram Moolenaar <[hidden email]>:
> >> It adds "space" in the allowed "listchars" arguments.
> > I'm confused.  It appears the "space" character is both used to display
> > instead of a space character when 'list' is on, and to find this
> > character after the end of the line and replace it with "trail".
> > To me these are two unrelated things.
>
> You are right. This was because spaces were already replaced at that
> point, making the replacement with "trail" impossible.
> But it leads to side effects if the "space replacement" character is
> actually used in the edited file.
>
> Here is a new patch without this annoying side-effect.
>
> > I'm not sure how useful it is to show something instead of a space.
> > Isn't it obvious that there is a space when there is nothing?
>
> Sometimes it's not : I'm using a visible character for the first
> column of tabs, but an invisible one for the remaining columns.
> So cases where a tab is followed by a space are not that obvious.
> And as Steve pointed out, double spaces are not always obvious either.
>
> 2009/10/29 Steve Hall <[hidden email]>
> > Bram, I can't speak for the author, but I'd like this feature to make
> > it easy to visualize:
> > * other non-printing characters that look like dec 032
> > * double spaces
> > * spaces after chars at window edges with wrap on
> > * every char as a byte
>
> As for now, only the ' ' character is displayed, but it'd easy to
> support more.

Well, I might consider including this.  Can you write a patch for the
documentation as well?

--
TALL KNIGHT: When you have found the shrubbery, then you must cut down the
             mightiest tree in the forest ... with a herring.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Patch: support for the "space" argument for "listchars"

Jérémie Roquet

2009/10/29 Bram Moolenaar <[hidden email]>:

> Jérémie Roquet wrote:
>> 2009/10/28 Bram Moolenaar <[hidden email]>:
>> >> It adds "space" in the allowed "listchars" arguments.
>> > I'm not sure how useful it is to show something instead of a space.
>> > Isn't it obvious that there is a space when there is nothing?
>> Sometimes it's not : I'm using a visible character for the first
>> column of tabs, but an invisible one for the remaining columns.
>> So cases where a tab is followed by a space are not that obvious.
>> And as Steve pointed out, double spaces are not always obvious either.
> Well, I might consider including this.  Can you write a patch for the
> documentation as well?

Sure.

Here is what I supposed was to be updated; please let me know if there
is some other documentation to patch.

Best regards,

Index: runtime/doc/options.txt
===================================================================
--- runtime/doc/options.txt (revision 1626)
+++ runtime/doc/options.txt (working copy)
@@ -4360,17 +4360,19 @@
  visible in the first column.
   nbsp:c Character to show for a non-breakable space (character
  0xA0, 160).  Left blank when omitted.
+  space:c Character to show for a space (character 0x20, 32). Left
+ blank when omitted.

  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.

  Examples: >
-    :set lcs=tab:>-,trail:-
+    :set lcs=tab:>-,trail:-,space:.
     :set lcs=tab:>-,eol:<,nbsp:%
     :set lcs=extends:>,precedes:<
 < The "NonText" highlighting will be used for "eol", "extends" and
- "precedes".  "SpecialKey" for "nbsp", "tab" and "trail".
+ "precedes".  "SpecialKey" for "nbsp", "space", "tab" and "trail".
  |hl-NonText| |hl-SpecialKey|

  *'lpl'* *'nolpl'* *'loadplugins'* *'noloadplugins'*

--
Jérémie Roquet - Arkanosis
Programming artist
Developer in natural language processing - Exalead

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Patch: support for the "space" argument for "listchars"

jpetrie
This post has NOT been accepted by the mailing list yet.
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Patch: support for the "space" argument for "listchars"

dearvivekkumar
This post has NOT been accepted by the mailing list yet.
In reply to this post by Jérémie Roquet
@Jérémie Roquet

Can you please provide me your gvim.exe file.

or you can please let me know how to build vim from source on windows7. I have mingw with gcc/g++ 4.7

Thanks in anticipation
Loading...