Since the import of mg in the tree, space_to_tabstop used curbp->w_doto
(the byte offset in the current line) as mean to deduce the current
column for indentation. This is wrong because it doesn't account for
tab, control characters and octets > 127 (which are all rendered with
more than one column.) Use instead getcolpos().
ok tb@
-/* $OpenBSD: util.c,v 1.48 2023/04/21 13:39:37 op Exp $ */
+/* $OpenBSD: util.c,v 1.49 2023/04/21 14:14:13 op Exp $ */
/* This file is in the public domain. */
int
space_to_tabstop(int f, int n)
{
- int c;
+ int col, target;
if (n < 0)
return (FALSE);
if (n == 0)
return (TRUE);
- c = curwp->w_doto;
+ col = target = getcolpos(curwp);
while (n-- > 0)
- c = ntabstop(c, curbp->b_tabw);
- return (linsert(c - curwp->w_doto, ' '));
+ target = ntabstop(target, curbp->b_tabw);
+ return (linsert(target - col, ' '));
}
/*