[PATCH] the third char of the 'tab' option of 'listchars'.

279 views
Skip to first unread message

starwing

unread,
Dec 17, 2010, 12:34:22 AM12/17/10
to vim_dev
hi all.

I made this patch to support the third char of the tab. if given the
optional third char to tab option, then the third char will appeared
at end of tab.
e.g. se lcs=tab:<->, then a four space tab will display as "<-->".


diff -r 916c90b37ea9 runtime/doc/options.txt
--- a/runtime/doc/options.txt Fri Dec 10 20:35:50 2010 +0100
+++ b/runtime/doc/options.txt Fri Dec 17 13:32:29 2010 +0800
@@ -4534,11 +4534,14 @@
eol:c Character to show at the end of each line. When
omitted, there is no extra character at the end of the
line.
- tab:xy Two characters to be used to show a tab. The first
- char is used once. The second char is repeated to
- fill the space that the tab normally occupies.
+ tab:xyz Two or three characters to be used to show a tab. The
+ first char is used once. The second char is repeated
+ to fill the space that the tab normally occupies. the
+ third char is optional, if given, it will used once at
+ last of tab.
"tab:>-" will show a tab that takes four spaces as
- ">---". When omitted, a tab is show as ^I.
+ ">---". "tab:<->" will show a tab as "<-->". When
+ omitted, a tab is show as ^I.
trail:c Character to show for trailing spaces. When omitted,
trailing spaces are blank.
extends:c Character to show in the last column, when 'wrap' is
diff -r 916c90b37ea9 src/globals.h
--- a/src/globals.h Fri Dec 10 20:35:50 2010 +0100
+++ b/src/globals.h Fri Dec 17 13:32:29 2010 +0800
@@ -1149,6 +1149,7 @@
EXTERN int lcs_nbsp INIT(= NUL);
EXTERN int lcs_tab1 INIT(= NUL);
EXTERN int lcs_tab2 INIT(= NUL);
+EXTERN int lcs_tab3 INIT(= NUL);
EXTERN int lcs_trail INIT(= NUL);
#ifdef FEAT_CONCEAL
EXTERN int lcs_conceal INIT(= '-');
diff -r 916c90b37ea9 src/message.c
--- a/src/message.c Fri Dec 10 20:35:50 2010 +0100
+++ b/src/message.c Fri Dec 17 13:32:29 2010 +0800
@@ -1598,6 +1598,7 @@
int col = 0;
int n_extra = 0;
int c_extra = 0;
+ int c_end = 0;
char_u *p_extra = NULL; /* init to make SASC shut up */
int n;
int attr = 0;
@@ -1628,8 +1629,13 @@
if (n_extra > 0)
{
--n_extra;
- if (c_extra)
+ if (n_extra > 0 && c_extra)
c = c_extra;
+ else if (n_extra == 0 && c_end)
+ {
+ c = c_end;
+ c_end = 0;
+ }
else
c = *p_extra++;
}
@@ -1656,11 +1662,13 @@
{
c = ' ';
c_extra = ' ';
+ c_end = ' ';
}
else
{
c = lcs_tab1;
c_extra = lcs_tab2;
+ c_end = lcs_tab3;
attr = hl_attr(HLF_8);
}
}
diff -r 916c90b37ea9 src/option.c
--- a/src/option.c Fri Dec 10 20:35:50 2010 +0100
+++ b/src/option.c Fri Dec 17 13:32:29 2010 +0800
@@ -7104,7 +7104,7 @@
{
int round, i, len, entries;
char_u *p, *s;
- int c1, c2 = 0;
+ int c1, c2 = 0, c3 = 0;
struct charstab
{
int *cp;
@@ -7197,6 +7197,16 @@
#else
c2 = *s++;
#endif
+ if (!(*s == ',' || *s == NUL))
+ {
+#ifdef FEAT_MBYTE
+ c3 = mb_ptr2char_adv(&s);
+ if (mb_char2cells(c2) > 1)
+ continue;
+#else
+ c3 = *s++;
+#endif
+ }
}
if (*s == ',' || *s == NUL)
{
@@ -7206,6 +7216,7 @@
{
lcs_tab1 = c1;
lcs_tab2 = c2;
+ lcs_tab3 = c3;
}
else if (tab[i].cp != NULL)
*(tab[i].cp) = c1;
@@ -7322,7 +7333,7 @@
new_unnamed |= CLIP_UNNAMED;
p += 7;
}
- else if (STRNCMP(p, "unnamedplus", 11) == 0
+ else if (STRNCMP(p, "unnamedplus", 11) == 0
&& (p[11] == ',' || p[11] == NUL))
{
new_unnamed |= CLIP_UNNAMED_PLUS;
diff -r 916c90b37ea9 src/screen.c
--- a/src/screen.c Fri Dec 10 20:35:50 2010 +0100
+++ b/src/screen.c Fri Dec 17 13:32:29 2010 +0800
@@ -2682,6 +2682,7 @@
int n_extra = 0; /* number of extra chars */
char_u *p_extra = NULL; /* string of extra chars, plus NUL */
int c_extra = NUL; /* extra chars, all the same */
+ int c_end = NUL; /* end char, for tab char */
int extra_attr = 0; /* attributes when n_extra != 0 */
static char_u *at_end_str = (char_u *)""; /* used for p_extra when
displaying lcs_eol at end-of-line */
@@ -3750,9 +3751,12 @@
*/
if (n_extra > 0)
{
- if (c_extra != NUL)
- {
- c = c_extra;
+ if (c_extra != NUL || (n_extra == 1 && c_end != NUL))
+ {
+ if (n_extra == 1 && c_end != NUL)
+ c = c_end;
+ else
+ c = c_extra;
#ifdef FEAT_MBYTE
mb_c = c; /* doesn't handle non-utf-8 multi-byte! */
if (enc_utf8 && (*mb_char2len)(c) > 1)
@@ -4261,6 +4265,7 @@
{
c = lcs_tab1;
c_extra = lcs_tab2;
+ c_end = lcs_tab3;
n_attr = n_extra + 1;
extra_attr = hl_attr(HLF_8);
saved_attr2 = char_attr; /* save current attr */
@@ -4277,6 +4282,7 @@
else
{
c_extra = ' ';
+ c_end = ' ';
c = ' ';
}
}

starwing

unread,
Dec 17, 2010, 1:06:01 AM12/17/10
to vim_dev
2010/12/17 starwing <weasl...@gmail.com>:

sorry for my careless, this is the final patch. previous patch has a issue:


+               if (n_extra == 1 && c_end != NUL)
+                   c = c_end;

this should be:


+               if (n_extra == 1 && c_end != NUL)

+ {
+                   c = c_end;

+ c_end = NUL;
+ }

patch

Bram Moolenaar

unread,
Dec 17, 2010, 8:06:51 AM12/17/10
to starwing, vim_dev

Starwing wrote:

> I made this patch to support the third char of the tab. if given the
> optional third char to tab option, then the third char will appeared
> at end of tab.
> e.g. se lcs=tab:<->, then a four space tab will display as "<-->".

Is there a specific reason to show it this way? I don't think I would
use it.

Looking at the patch, I think you need to reset c_end to NUL in more
places.

--
How To Keep A Healthy Level Of Insanity:
8. Don't use any punctuation marks.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Message has been deleted

Anonimiy Anonimov

unread,
Feb 26, 2014, 6:47:21 AM2/26/14
to vim...@googlegroups.com, starwing
Hello.

On Friday, December 17, 2010 5:06:51 PM UTC+4, Bram Moolenaar wrote:
> Is there a specific reason to show it this way? I don't think I would
> use it.

One user told me that "vim even cannot do elementary things, for example mcedit-like tabs". So, seems that somebody needs that. :)

> Looking at the patch, I think you need to reset c_end to NUL in more
> places.

So, the patch won't be approved, right?

Nathaniel Braun

unread,
Feb 26, 2014, 7:27:49 AM2/26/14
to vim...@googlegroups.com, starwing
Hello,

Well, I made a fix for that - you can see my patch there:
https://groups.google.com/forum/#!searchin/vim_dev/tab/vim_dev/AZQWFbgnMIo/4lDupl_9JB0J

I don't know whether it has been approved yet - but I did implement it.

Pragmb

On Wed, Feb 26, 2014 at 12:44 PM, Anonimiy Anonimov <xaio...@gmail.com> wrote:
> Hello.
>
> On Friday, December 17, 2010 5:06:51 PM UTC+4, Bram Moolenaar wrote:
>> Is there a specific reason to show it this way? I don't think I would
>> use it.
>
> One user told me that "vim cannot do elementary things, for example mcedit-like tabs". Seems, that somebody needs that.
>
>> Looking at the patch, I think you need to reset c_end to NUL in more
>> places.
>
> Well. The patch won't be approved, right? :)
>
> --
> --
> 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 a topic in the Google Groups "vim_dev" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_dev/bq9vyCYm7CU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to vim_dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Anonimiy Anonimov

unread,
Feb 26, 2014, 7:38:04 AM2/26/14
to vim...@googlegroups.com, starwing
On Wednesday, February 26, 2014 4:27:49 PM UTC+4, Nathaniel Braun wrote:
> Hello,
>
>
>
> Well, I made a fix for that - you can see my patch there:
>
> https://groups.google.com/forum/#!searchin/vim_dev/tab/vim_dev/AZQWFbgnMIo/4lDupl_9JB0J

Sorry if I'm wrong, but that patch doesn't allow "<------>" tabs (mcedit-like).
Also your way of configuration is much more complicated. I like StarWing's solution much more. Examples:
">-"
"<->"
"-->"

Nathaniel Braun

unread,
Feb 26, 2014, 7:44:00 AM2/26/14
to vim...@googlegroups.com, starwing
Well, I guess I can tweak my code to perform that (and simplify the
configuration) and submit a new patch, so I'll meet both requirements
:)

Nathaniel Braun

unread,
Feb 27, 2014, 3:32:40 AM2/27/14
to vim...@googlegroups.com, starwing
> > For more options, visit https://groups.google.com/groups/opt_out.

Hello,
I just implemented the feature and I have a patch ready to be reviewed and tested. It implements the following procedure:

If the tab is at least two chars wide then:
- the first char is used once at the beginning
- the second char is repeated to fill the tab
- if the third char is specified, it is used once at the end

If the tab is one char wide then:
- if the third char is specified, then the third char is used
- if the third char is not specified, then the first char is used

Cheers

Nathaniel Braun

unread,
Mar 3, 2014, 8:56:47 AM3/3/14
to vim...@googlegroups.com
Hello everyone,

Quick reminder to tell you that if you want to review and test the
'third tab char' option, you can see my commit there:
https://code.google.com/r/pragmb-vim/source/detail?r=427b709517fcd5b86ec57c90c4cba37d4a0778db

The code is based on vim HEAD.
Thanks for your feedback!

Regards,
Pragmb
> To unsubscribe from this group and all its topics, send an email to vim_dev+u...@googlegroups.com.

Davit Samvelyan

unread,
Mar 26, 2014, 5:02:09 AM3/26/14
to vim...@googlegroups.com
I would love to have this option.
It would be nice to have "--->" style for the tabs rather then ">---", the first one is more intuitive to me.
Reply all
Reply to author
Forward
0 new messages