summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
authorOmar Polo <op@cvs.openbsd.org>2023-04-21 14:14:14 +0000
committerOmar Polo <op@cvs.openbsd.org>2023-04-21 14:14:14 +0000
commit868b12117f4dbcbe6004159b3b889642e5ae2e5c (patch)
tree3ca3fb599f50580cea03ef1378f71add0676b9b2 /usr.bin/mg
parent2f8d66befccee4b86ddaed3aa13d7c6a4c96c224 (diff)
mg: fix space_to_tabstop
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@
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/util.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/usr.bin/mg/util.c b/usr.bin/mg/util.c
index 6168f51144b..acb3714b28d 100644
--- a/usr.bin/mg/util.c
+++ b/usr.bin/mg/util.c
@@ -1,4 +1,4 @@
-/* $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. */
@@ -482,17 +482,17 @@ backdel(int f, int n)
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, ' '));
}
/*