diff options
author | Mark Lumsden <lum@cvs.openbsd.org> | 2018-12-13 14:59:17 +0000 |
---|---|---|
committer | Mark Lumsden <lum@cvs.openbsd.org> | 2018-12-13 14:59:17 +0000 |
commit | 900eed1ec714253d6c2f2f15ca4adbe281098bb5 (patch) | |
tree | 73044eff07d23bc8c38f146941a5f3f09a38e3b1 /usr.bin | |
parent | 3d4212dae69e5feb6eb917aa6aebf66e59ff25b0 (diff) |
Allow all non-ephemeral buffers to be toggled writable or read-only
while mg is running: toggle-read-only-all
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mg/buffer.c | 24 | ||||
-rw-r--r-- | usr.bin/mg/def.h | 4 | ||||
-rw-r--r-- | usr.bin/mg/funmap.c | 3 | ||||
-rw-r--r-- | usr.bin/mg/main.c | 9 | ||||
-rw-r--r-- | usr.bin/mg/mg.1 | 8 |
5 files changed, 39 insertions, 9 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c index 3057882cc1f..e1e3da2b2cf 100644 --- a/usr.bin/mg/buffer.c +++ b/usr.bin/mg/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.104 2017/08/06 04:39:45 bcallah Exp $ */ +/* $OpenBSD: buffer.c,v 1.105 2018/12/13 14:59:16 lum Exp $ */ /* This file is in the public domain. */ @@ -31,6 +31,28 @@ extern int globalwd; /* ARGSUSED */ int +togglereadonlyall(int f, int n) +{ + struct buffer *bp = NULL; + int len = 0; + + allbro = !allbro; + for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { + len = strlen(bp->b_bname); + if (bp->b_bname[0] != '*' && bp->b_bname[len - 1] != '*') { + if (allbro) + bp->b_flag |= BFREADONLY; + else + bp->b_flag &= ~BFREADONLY; + } + } + curwp->w_rflag |= WFMODE; + + return (TRUE); +} + +/* ARGSUSED */ +int togglereadonly(int f, int n) { int s; diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index 86c606f7ff4..c7a134f8513 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.156 2018/08/29 07:50:16 reyk Exp $ */ +/* $OpenBSD: def.h,v 1.157 2018/12/13 14:59:16 lum Exp $ */ /* This file is in the public domain. */ @@ -417,6 +417,7 @@ int delwind(int, int); /* buffer.c */ int togglereadonly(int, int); +int togglereadonlyall(int, int); struct buffer *bfind(const char *, int); int poptobuffer(int, int); int killbuffer(struct buffer *); @@ -737,6 +738,7 @@ extern int defb_flag; extern int doaudiblebell; extern int dovisiblebell; extern int dblspace; +extern int allbro; extern char cinfo[]; extern char *keystrings[]; extern char pat[NPAT]; diff --git a/usr.bin/mg/funmap.c b/usr.bin/mg/funmap.c index def40477262..a4c49858614 100644 --- a/usr.bin/mg/funmap.c +++ b/usr.bin/mg/funmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: funmap.c,v 1.54 2018/08/29 07:50:16 reyk Exp $ */ +/* $OpenBSD: funmap.c,v 1.55 2018/12/13 14:59:16 lum Exp $ */ /* This file is in the public domain */ @@ -201,6 +201,7 @@ static struct funmap functnames[] = { {usebuffer, "switch-to-buffer",}, {poptobuffer, "switch-to-buffer-other-window",}, {togglereadonly, "toggle-read-only" }, + {togglereadonlyall, "toggle-read-only-all" }, {twiddle, "transpose-chars",}, {transposepara, "transpose-paragraphs",}, {transposeword, "transpose-words",}, diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c index f11d2658c5e..b4cf96d426b 100644 --- a/usr.bin/mg/main.c +++ b/usr.bin/mg/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.84 2016/09/16 17:17:40 tedu Exp $ */ +/* $OpenBSD: main.c,v 1.85 2018/12/13 14:59:16 lum Exp $ */ /* This file is in the public domain. */ @@ -28,6 +28,7 @@ int startrow; /* row to start */ int doaudiblebell; /* audible bell toggle */ int dovisiblebell; /* visible bell toggle */ int dblspace; /* sentence end #spaces */ +int allbro; /* all buffs read-only */ struct buffer *curbp; /* current buffer */ struct buffer *bheadp; /* BUFFER list head */ struct mgwin *curwp; /* current window */ @@ -54,7 +55,7 @@ main(int argc, char **argv) char *cp, *init_fcn_name = NULL; PF init_fcn = NULL; int o, i, nfiles; - int nobackups = 0, bro = 0; + int nobackups = 0; struct buffer *bp = NULL; if (pledge("stdio rpath wpath cpath fattr chown getpw tty proc exec", @@ -64,7 +65,7 @@ main(int argc, char **argv) while ((o = getopt(argc, argv, "nRf:")) != -1) switch (o) { case 'R': - bro = 1; + allbro = 1; break; case 'n': nobackups = 1; @@ -174,7 +175,7 @@ notnum: init_fcn(FFOTHARG, 1); nfiles++; } - if (bro) + if (allbro) curbp->b_flag |= BFREADONLY; } } diff --git a/usr.bin/mg/mg.1 b/usr.bin/mg/mg.1 index 2a4d962dfe4..6d4f22ff1f2 100644 --- a/usr.bin/mg/mg.1 +++ b/usr.bin/mg/mg.1 @@ -1,7 +1,7 @@ -.\" $OpenBSD: mg.1,v 1.108 2018/11/18 07:57:28 lum Exp $ +.\" $OpenBSD: mg.1,v 1.109 2018/12/13 14:59:16 lum Exp $ .\" This file is in the public domain. .\" -.Dd $Mdocdate: November 18 2018 $ +.Dd $Mdocdate: December 13 2018 $ .Dt MG 1 .Os .Sh NAME @@ -884,6 +884,10 @@ Prompt and switch to a new buffer in the current window. Switch to buffer in another window. .It toggle-read-only Toggle the read-only flag on the current buffer. +.It toggle-read-only-all +Toggle the read-only flag on all non-ephemeral buffers. +A simple toggle that switches a global read-only flag either on +or off. .It transpose-chars Transpose the two characters in front of and under dot, then move forward one character. |