Open flux77 opened 2 years ago
I'll have a look, but essentially no time, unfortunately. So this may take quite a while. Or someone has a pull-request meanwhile.
Good news: I have a patch for The Traditional Vi release 050325.
Bad news:
genbuf
and linebuf
are always able to accommodate all the extra space characters inserted as a result of expandtab. Use at your own risk.For ex-vi version 050325, apply the patch below like this:
cd ex-050325
patch -p1 < /path/to/the.patch
sh makeoptions
diff -Naur ex-050325-orig/ex.1 ex-050325/ex.1
--- ex-050325-orig/ex.1
+++ ex-050325/ex.1
@@ -1607,6 +1607,10 @@
If possible the editor always places the error message in a standout mode of the
terminal (such as inverse video) instead of ringing the bell.
.TP
+\fBexpandtab\fR, \fBet\fR default: noet
+Expand tab characters to space characters when inserting, replacing or shifting
+text, autoindenting, indenting with \fB^T\fR, or outdenting with \fB^D\fR.
+.TP
\fBexrc\fR default: noexrc
If set, the current directory is searched for a
.I .exrc
diff -Naur ex-050325-orig/ex_data.c ex-050325/ex_data.c
--- ex-050325-orig/ex_data.c
+++ ex-050325/ex_data.c
@@ -128,6 +128,7 @@
{ "directory", "dir", STRING, 0, 0, direct, },
{ "edcompatible","ed", ONOFF, 0, 0, 0, },
{ "errorbells", "eb", ONOFF, 0, 0, 0, },
+ { "expandtab", "et", ONOFF, 0, 0, 0, },
{ "exrc", "ex", ONOFF, 0, 0, 0, },
{ "flash", "fl", ONOFF, 1, 1, 0, },
{ "hardtabs", "ht", NUMERIC, 8, 8, 0, },
diff -Naur ex-050325-orig/ex_subr.c ex-050325/ex_subr.c
--- ex-050325-orig/ex_subr.c
+++ ex-050325/ex_subr.c
@@ -235,10 +235,12 @@
char *
genindent(register int indent)
{
- register char *cp;
+ register char *cp = genbuf;
- for (cp = genbuf; indent >= value(TABSTOP); indent -= value(TABSTOP))
- *cp++ = '\t';
+ if (!value(EXPANDTAB)) {
+ for (; indent >= value(TABSTOP); indent -= value(TABSTOP))
+ *cp++ = '\t';
+ }
for (; indent > 0; indent--)
*cp++ = ' ';
return (cp);
diff -Naur ex-050325-orig/ex_vops2.c ex-050325/ex_vops2.c
--- ex-050325-orig/ex_vops2.c
+++ ex-050325/ex_vops2.c
@@ -1007,7 +1007,11 @@
}
if (gcursor > &genbuf[LBSIZE - 2])
error(catgets(catd, 1, 235, "Line too long"));
- gappend(c & TRIM);
+ if (value(EXPANDTAB) && c == '\t') {
+ for (int i = 0; i < value(TABSTOP); i++)
+ gappend(' ');
+ } else
+ gappend(c & TRIM);
vcsync();
if (value(SHOWMATCH) && !iglobp)
if (c == ')' || c == '}')
@flux77 @n-t-roff
@cwfoo any chance you have that in a branch so I can get that into https://github.com/traditional-vi/ex-vi with attribution?
@josephholsten No, I do not have that in a Git branch. I have added license information to the patch. I hope that it is sufficient for you.
Are you familiar with ex-vi's code? If so, I'd be interested to know whether or not my patch is reasonable.
Would it be possible to add an
expandtab
option like that in nvi (FreeBSD, NetBSD, OpenBSD) and Vim? This would be useful for those who prefer to use spaces rather than tabs for indentation.Which function(s) should I edit to insert spaces when I press Tab?