shithub: lola

Download patch

ref: 9a21ad603320dba6d17d507a0eb168a772d83c37
parent: 56008bbe96df8235a0633d6221b0e8809337fe41
author: aap <[email protected]>
date: Mon Sep 30 15:46:59 EDT 2024

implemented $tabstop.

--- a/inc.h
+++ b/inc.h
@@ -64,7 +64,7 @@
 	int posx;
 };
 
-void xinit(Text *x, Rectangle textr, Rectangle scrollr, Font *ft, Image *b, Image **cols);
+void xinit(Text *x, Rectangle textr, Rectangle scrollr, int tabwidth, Font *ft, Image *b, Image **cols);
 void xsetrects(Text *x, Rectangle textr, Rectangle scrollr);
 void xclear(Text *x);
 void xredraw(Text *x);
@@ -109,6 +109,7 @@
 extern Cursor *corners[9];
 void initdata(void);
 
+extern int tabwidth;
 extern bool scrolling;
 extern bool notitle;
 extern int ndeskx;
--- a/main.c
+++ b/main.c
@@ -1,5 +1,6 @@
 #include "inc.h"
 
+int tabwidth;
 bool scrolling;
 bool notitle;
 int ndeskx = 3;
@@ -1019,7 +1020,7 @@
 void
 threadmain(int argc, char *argv[])
 {
-	char *initstr;
+	char *initstr, *s;
 	char buf[256];
 if(strcmp(argv[0]+1, ".out") == 0){
 rfork(RFENVG);
@@ -1048,6 +1049,13 @@
 		startdir = estrdup(".");
 	else
 		startdir = estrdup(buf);
+	s = getenv("tabstop");
+	if(s)
+		tabwidth = strtol(s, nil, 0);
+	if(tabwidth == 0)
+		tabwidth = 4;
+	free(s);
+
 	if(initdraw(nil, nil, "lola") < 0)
 		sysfatal("initdraw: %r");
 	kbctl = initkbd(nil, nil);
--- a/text.c
+++ b/text.c
@@ -8,10 +8,11 @@
 };
 
 void
-xinit(Text *x, Rectangle textr, Rectangle scrollr, Font *ft, Image *b, Image **cols)
+xinit(Text *x, Rectangle textr, Rectangle scrollr, int tabwidth, Font *ft, Image *b, Image **cols)
 {
 	frclear(x, FALSE);
 	frinit(x, textr, ft, b, cols);
+	x->maxtab = x->maxtab/8*tabwidth;
 	x->i = b;
 	x->scrollr = scrollr;
 	x->lastsr = ZR;
--- a/wind.c
+++ b/wind.c
@@ -121,7 +121,7 @@
 	t->content = allocwindow(w->screen, w->contrect, Refbackup, DNofill);
 	assert(t->content);
 	draw(t->content, t->content->r, colors[BACK], nil, ZP);
-	xinit(&t->text, w->textr, w->scrollr, font, t->content, colors);
+	xinit(&t->text, w->textr, w->scrollr, tabwidth, font, t->content, colors);
 }
 
 static void