summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorOmar Polo <op@cvs.openbsd.org>2023-04-17 09:49:05 +0000
committerOmar Polo <op@cvs.openbsd.org>2023-04-17 09:49:05 +0000
commit181c8c991bf298c1b271a09cf5182cbeea4bae5e (patch)
tree0a1446291f67a5bf70ddeb9a2d99b7ad2b5c2e6e /usr.bin
parent0441ee96acf9f17b42b288204bfde0ac325b073a (diff)
resurrect mg' no-tab-mode
It's a mode that makes mg insert spaces up to the next tab stop upon pressing TAB, along with the various tweaks needed in other places so for e.g. auto-indent-mode also uses spaces. This is not just an unifdef NOTAB: even under no-tab-mode mg should consider literal TAB characters wide up to the next tab stop, while the hidden code considered hard tabs to be just control character (i.e. ^I) with width of two columns. I'm also introducing the helper function doindent() in utils.c to de-obfuscate the insertion of tabs/spaces until the given column. ok tb@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mg/basic.c9
-rw-r--r--usr.bin/mg/cmode.c14
-rw-r--r--usr.bin/mg/def.h6
-rw-r--r--usr.bin/mg/display.c20
-rw-r--r--usr.bin/mg/funmap.c6
-rw-r--r--usr.bin/mg/keymap.c6
-rw-r--r--usr.bin/mg/match.c8
-rw-r--r--usr.bin/mg/mg.110
-rw-r--r--usr.bin/mg/modes.c6
-rw-r--r--usr.bin/mg/paragraph.c8
-rw-r--r--usr.bin/mg/util.c43
11 files changed, 44 insertions, 92 deletions
diff --git a/usr.bin/mg/basic.c b/usr.bin/mg/basic.c
index 4a170480432..ed7d475c494 100644
--- a/usr.bin/mg/basic.c
+++ b/usr.bin/mg/basic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: basic.c,v 1.52 2023/03/08 04:43:11 guenther Exp $ */
+/* $OpenBSD: basic.c,v 1.53 2023/04/17 09:49:04 op Exp $ */
/* This file is in the public domain */
@@ -274,14 +274,9 @@ getgoal(struct line *dlp)
int c, i, col = 0;
char tmp[5];
-
for (i = 0; i < llength(dlp); i++) {
c = lgetc(dlp, i);
- if (c == '\t'
-#ifdef NOTAB
- && !(curbp->b_flag & BFNOTAB)
-#endif
- ) {
+ if (c == '\t') {
col |= 0x07;
col++;
} else if (ISCTRL(c) != FALSE) {
diff --git a/usr.bin/mg/cmode.c b/usr.bin/mg/cmode.c
index 9f5ffd72f80..e5442a2b6ed 100644
--- a/usr.bin/mg/cmode.c
+++ b/usr.bin/mg/cmode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmode.c,v 1.20 2022/12/26 19:16:02 jmc Exp $ */
+/* $OpenBSD: cmode.c,v 1.21 2023/04/17 09:49:04 op Exp $ */
/*
* This file is in the public domain.
*
@@ -245,11 +245,7 @@ getindent(const struct line *lp, int *curi)
for (lo = 0; lo < llength(lp); lo++) {
if (!isspace(c = lgetc(lp, lo)))
break;
- if (c == '\t'
-#ifdef NOTAB
- && !(curbp->b_flag & BFNOTAB)
-#endif /* NOTAB */
- ) {
+ if (c == '\t') {
nicol |= 0x07;
}
nicol++;
@@ -414,11 +410,7 @@ findcolpos(const struct buffer *bp, const struct line *lp, int lo)
for (i = 0; i < lo; ++i) {
c = lgetc(lp, i);
- if (c == '\t'
-#ifdef NOTAB
- && !(bp->b_flag & BFNOTAB)
-#endif /* NOTAB */
- ) {
+ if (c == '\t') {
col |= 0x07;
col++;
} else if (ISCTRL(c) != FALSE)
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 5475b513036..8cfaada0300 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.178 2023/03/30 19:00:02 op Exp $ */
+/* $OpenBSD: def.h,v 1.179 2023/04/17 09:49:04 op Exp $ */
/* This file is in the public domain. */
@@ -285,9 +285,7 @@ struct buffer {
#define BFCHG 0x01 /* Changed. */
#define BFBAK 0x02 /* Need to make a backup. */
-#ifdef NOTAB
#define BFNOTAB 0x04 /* no tab mode */
-#endif
#define BFOVERWRITE 0x08 /* overwrite mode */
#define BFREADONLY 0x10 /* read only mode */
#define BFDIRTY 0x20 /* Buffer was modified elsewhere */
@@ -676,9 +674,7 @@ int executemacro(int, int);
/* modes.c X */
int indentmode(int, int);
int fillmode(int, int);
-#ifdef NOTAB
int notabmode(int, int);
-#endif /* NOTAB */
int overwrite_mode(int, int);
int set_default_mode(int,int);
diff --git a/usr.bin/mg/display.c b/usr.bin/mg/display.c
index 1751b5ead13..3814a0bd29b 100644
--- a/usr.bin/mg/display.c
+++ b/usr.bin/mg/display.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: display.c,v 1.50 2023/03/08 04:43:11 guenther Exp $ */
+/* $OpenBSD: display.c,v 1.51 2023/04/17 09:49:04 op Exp $ */
/* This file is in the public domain. */
@@ -317,11 +317,7 @@ vtputc(int c)
vp = vscreen[vtrow];
if (vtcol >= ncol)
vp->v_text[ncol - 1] = '$';
- else if (c == '\t'
-#ifdef NOTAB
- && !(curbp->b_flag & BFNOTAB)
-#endif
- ) {
+ else if (c == '\t') {
do {
vtputc(' ');
} while (vtcol < ncol && (vtcol & 0x07) != 0);
@@ -353,11 +349,7 @@ vtpute(int c)
vp = vscreen[vtrow];
if (vtcol >= ncol)
vp->v_text[ncol - 1] = '$';
- else if (c == '\t'
-#ifdef NOTAB
- && !(curbp->b_flag & BFNOTAB)
-#endif
- ) {
+ else if (c == '\t') {
do {
vtpute(' ');
} while (((vtcol + lbound) & 0x07) != 0 && vtcol < ncol);
@@ -516,11 +508,7 @@ update(int modelinecolor)
i = 0;
while (i < curwp->w_doto) {
c = lgetc(lp, i++);
- if (c == '\t'
-#ifdef NOTAB
- && !(curbp->b_flag & BFNOTAB)
-#endif
- ) {
+ if (c == '\t') {
curcol |= 0x07;
curcol++;
} else if (ISCTRL(c) != FALSE)
diff --git a/usr.bin/mg/funmap.c b/usr.bin/mg/funmap.c
index e1c59fa0fb4..fbf41217328 100644
--- a/usr.bin/mg/funmap.c
+++ b/usr.bin/mg/funmap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: funmap.c,v 1.65 2022/12/26 19:16:02 jmc Exp $ */
+/* $OpenBSD: funmap.c,v 1.66 2023/04/17 09:49:04 op Exp $ */
/* This file is in the public domain */
@@ -157,9 +157,7 @@ static struct funmap functnames[] = {
{enewline, "newline", 1},
{lfindent, "newline-and-indent", 1},
{forwline, "next-line", 1},
-#ifdef NOTAB
{notabmode, "no-tab-mode", 0},
-#endif /* NOTAB */
{notmodified, "not-modified", 0},
{openline, "open-line", 1},
{nextwind, "other-window", 0},
@@ -212,9 +210,7 @@ static struct funmap functnames[] = {
{shellcommand, "shell-command", 1},
{piperegion, "shell-command-on-region", 1},
{shrinkwind, "shrink-window", 1},
-#ifdef NOTAB
{space_to_tabstop, "space-to-tabstop", 0},
-#endif /* NOTAB */
{splitwind, "split-window-vertically", 0},
{definemacro, "start-kbd-macro", 0},
{spawncli, "suspend-emacs", 0},
diff --git a/usr.bin/mg/keymap.c b/usr.bin/mg/keymap.c
index 6e47e4f66cb..83e8b54d921 100644
--- a/usr.bin/mg/keymap.c
+++ b/usr.bin/mg/keymap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: keymap.c,v 1.60 2022/10/20 18:59:24 op Exp $ */
+/* $OpenBSD: keymap.c,v 1.61 2023/04/17 09:49:04 op Exp $ */
/* This file is in the public domain. */
@@ -464,7 +464,6 @@ static struct KEYMAPE (1) indntmap = {
}
};
-#ifdef NOTAB
static PF notab_tab[] = {
space_to_tabstop /* ^I */
};
@@ -479,7 +478,6 @@ static struct KEYMAPE (1) notabmap = {
}
}
};
-#endif /* NOTAB */
static struct KEYMAPE (1) overwmap = {
0,
@@ -511,9 +509,7 @@ struct maps_s fundamental_mode = { (KEYMAP *)&fundmap, "fundamental" };
static struct maps_s map_table[] = {
{(KEYMAP *) &fillmap, "fill",},
{(KEYMAP *) &indntmap, "indent",},
-#ifdef NOTAB
{(KEYMAP *) &notabmap, "notab",},
-#endif /* NOTAB */
{(KEYMAP *) &overwmap, "overwrite",},
{(KEYMAP *) &metamap, "esc prefix",},
{(KEYMAP *) &cXmap, "c-x prefix",},
diff --git a/usr.bin/mg/match.c b/usr.bin/mg/match.c
index d35fcfdb66e..cc293f1d8a9 100644
--- a/usr.bin/mg/match.c
+++ b/usr.bin/mg/match.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: match.c,v 1.22 2021/03/01 10:51:14 lum Exp $ */
+/* $OpenBSD: match.c,v 1.23 2023/04/17 09:49:04 op Exp $ */
/* This file is in the public domain. */
@@ -169,11 +169,7 @@ displaymatch(struct line *clp, int cbo)
bufo = 0;
for (cp = 0; cp < llength(clp); cp++) {
c = lgetc(clp, cp);
- if (c != '\t'
-#ifdef NOTAB
- || (curbp->b_flag & BFNOTAB)
-#endif
- )
+ if (c != '\t')
if (ISCTRL(c)) {
buf[bufo++] = '^';
buf[bufo++] = CCHR(c);
diff --git a/usr.bin/mg/mg.1 b/usr.bin/mg/mg.1
index beb85f1151f..d2edd289cc5 100644
--- a/usr.bin/mg/mg.1
+++ b/usr.bin/mg/mg.1
@@ -1,7 +1,7 @@
-.\" $OpenBSD: mg.1,v 1.128 2023/03/29 07:29:17 op Exp $
+.\" $OpenBSD: mg.1,v 1.129 2023/04/17 09:49:04 op Exp $
.\" This file is in the public domain.
.\"
-.Dd $Mdocdate: March 29 2023 $
+.Dd $Mdocdate: April 17 2023 $
.Dt MG 1
.Os
.Sh NAME
@@ -738,9 +738,9 @@ Assumes tabs are every eight characters.
Move forward
.Va n
lines.
-.\" .It no-tab-mode
-.\" Toggle notab mode.
-.\" In this mode, spaces are inserted rather than tabs.
+.It no-tab-mode
+Toggle notab mode.
+In this mode, spaces are inserted rather than tabs.
.It not-modified
Turn off the modified flag in the current buffer.
.It open-line
diff --git a/usr.bin/mg/modes.c b/usr.bin/mg/modes.c
index 9d5e4ce5373..c95e1fdb03c 100644
--- a/usr.bin/mg/modes.c
+++ b/usr.bin/mg/modes.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: modes.c,v 1.21 2017/05/30 07:05:22 florian Exp $ */
+/* $OpenBSD: modes.c,v 1.22 2023/04/17 09:49:04 op Exp $ */
/* This file is in the public domain. */
@@ -78,7 +78,6 @@ fillmode(int f, int n)
return (changemode(f, n, "fill"));
}
-#ifdef NOTAB
int
notabmode(int f, int n)
{
@@ -93,7 +92,6 @@ notabmode(int f, int n)
curbp->b_flag ^= BFNOTAB;
return (TRUE);
}
-#endif /* NOTAB */
int
overwrite_mode(int f, int n)
@@ -162,13 +160,11 @@ set_default_mode(int f, int n)
else
defb_flag |= BFOVERWRITE;
}
-#ifdef NOTAB
if (strcmp(modebuf, "notab") == 0) {
if (n <= 0)
defb_flag &= ~BFNOTAB;
else
defb_flag |= BFNOTAB;
}
-#endif /* NOTAB */
return (TRUE);
}
diff --git a/usr.bin/mg/paragraph.c b/usr.bin/mg/paragraph.c
index b49a488a041..1455295f90d 100644
--- a/usr.bin/mg/paragraph.c
+++ b/usr.bin/mg/paragraph.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: paragraph.c,v 1.47 2023/03/08 04:43:11 guenther Exp $ */
+/* $OpenBSD: paragraph.c,v 1.48 2023/04/17 09:49:04 op Exp $ */
/* This file is in the public domain. */
@@ -412,11 +412,7 @@ fillword(int f, int n)
if (i == curwp->w_doto)
return selfinsert(f, n);
c = lgetc(curwp->w_dotp, i);
- if (c == '\t'
-#ifdef NOTAB
- && !(curbp->b_flag & BFNOTAB)
-#endif
- )
+ if (c == '\t')
col |= 0x07;
else if (ISCTRL(c) != FALSE)
++col;
diff --git a/usr.bin/mg/util.c b/usr.bin/mg/util.c
index 5899b8a29b0..5fb0bd757c9 100644
--- a/usr.bin/mg/util.c
+++ b/usr.bin/mg/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.45 2023/03/08 04:43:11 guenther Exp $ */
+/* $OpenBSD: util.c,v 1.46 2023/04/17 09:49:04 op Exp $ */
/* This file is in the public domain. */
@@ -100,11 +100,7 @@ getcolpos(struct mgwin *wp)
for (i = 0; i < wp->w_doto; ++i) {
c = lgetc(wp->w_dotp, i);
- if (c == '\t'
-#ifdef NOTAB
- && !(wp->w_bufp->b_flag & BFNOTAB)
-#endif /* NOTAB */
- ) {
+ if (c == '\t') {
col |= 0x07;
col++;
} else if (ISCTRL(c) != FALSE)
@@ -336,7 +332,23 @@ deltrailwhite(int f, int n)
return (TRUE);
}
+/*
+ * Raw indent routine. Use spaces and tabs to fill the given number of
+ * cols, but respect no-tab-mode.
+ */
+int
+doindent(int cols)
+{
+ int n;
+ if (curbp->b_flag & BFNOTAB)
+ return (linsert(cols, ' '));
+ if ((n = cols / 8) != 0 && linsert(n, '\t') == FALSE)
+ return (FALSE);
+ if ((n = cols % 8) != 0 && linsert(n, ' ') == FALSE)
+ return (FALSE);
+ return (TRUE);
+}
/*
* Insert a newline, then enough tabs and spaces to duplicate the indentation
@@ -367,12 +379,8 @@ lfindent(int f, int n)
++nicol;
}
(void)delwhite(FFRAND, 1);
- if (lnewline() == FALSE || ((
-#ifdef NOTAB
- curbp->b_flag & BFNOTAB) ? linsert(nicol, ' ') == FALSE : (
-#endif /* NOTAB */
- ((i = nicol / 8) != 0 && linsert(i, '\t') == FALSE) ||
- ((i = nicol % 8) != 0 && linsert(i, ' ') == FALSE)))) {
+
+ if (lnewline() == FALSE || doindent(nicol) == FALSE) {
s = FALSE;
break;
}
@@ -389,7 +397,7 @@ lfindent(int f, int n)
int
indent(int f, int n)
{
- int soff, i;
+ int soff;
if (n < 0)
return (FALSE);
@@ -403,12 +411,7 @@ indent(int f, int n)
/* insert appropriate whitespace */
soff = curwp->w_doto;
(void)gotobol(FFRAND, 1);
- if (
-#ifdef NOTAB
- (curbp->b_flag & BFNOTAB) ? linsert(n, ' ') == FALSE :
-#endif /* NOTAB */
- (((i = n / 8) != 0 && linsert(i, '\t') == FALSE) ||
- ((i = n % 8) != 0 && linsert(i, ' ') == FALSE)))
+ if (doindent(n) == FALSE)
return (FALSE);
forwchar(FFRAND, soff);
@@ -464,7 +467,6 @@ backdel(int f, int n)
return (s);
}
-#ifdef NOTAB
int
space_to_tabstop(int f, int n)
{
@@ -474,7 +476,6 @@ space_to_tabstop(int f, int n)
return (TRUE);
return (linsert((n << 3) - (curwp->w_doto & 7), ' '));
}
-#endif /* NOTAB */
/*
* Move the dot to the first non-whitespace character of the current line.