If I am opening a lot of files into an editor but with the intention
of not changing the contents (or more usually only amending a couple
of files), a la:

> mg *

I like to open them all read-only, then change the ones I want to edit
to read-write as required, that way I know when I close them all I
know that any changes are there because I wanted to make them. Instead
of thinking 'did I really want that change' when I'm asked to save a
file I didn't want to edit, but edited it accidentally. 

This diff allows mg to open all command specified files read-only:

> mg -R *

ok?

Mark

Index: mg.1
===================================================================
RCS file: /cvs/src/usr.bin/mg/mg.1,v
retrieving revision 1.96
diff -u -p -r1.96 mg.1
--- mg.1        21 Dec 2015 09:04:52 -0000      1.96
+++ mg.1        23 Dec 2015 15:53:03 -0000
@@ -10,6 +10,7 @@
 .Sh SYNOPSIS
 .Nm mg
 .Op Fl n
+.Op Fl R
 .Op Fl f Ar mode
 .Op + Ns Ar number
 .Op Ar
@@ -40,6 +41,8 @@ arguments on the command line, including
 scratch buffer and all files.
 .It Fl n
 Turn off backup file generation.
+.It Fl R
+Files specified on the command line will be opened read-only.
 .El
 .Sh WINDOWS AND BUFFERS
 When a file is loaded into
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/main.c,v
retrieving revision 1.80
diff -u -p -r1.80 main.c
--- main.c      19 Nov 2015 19:30:44 -0000      1.80
+++ main.c      23 Dec 2015 15:53:03 -0000
@@ -53,14 +53,17 @@ main(int argc, char **argv)
        char            *cp, *init_fcn_name = NULL;
        PF               init_fcn = NULL;
        int              o, i, nfiles;
-       int              nobackups = 0;
+       int              nobackups = 0, bro = 0;
        struct buffer   *bp = NULL;
 
        if (pledge("stdio rpath wpath cpath fattr getpw tty proc exec", NULL) 
== -1)
                err(1, "pledge");
 
-       while ((o = getopt(argc, argv, "nf:")) != -1)
+       while ((o = getopt(argc, argv, "Rnf:")) != -1)
                switch (o) {
+               case 'R':
+                       bro = 1;
+                       break;
                case 'n':
                        nobackups = 1;
                        break;
@@ -170,6 +173,8 @@ notnum:
                                                init_fcn(FFOTHARG, 1);
                                        nfiles++;
                                }
+                               if (bro)
+                                       curbp->b_flag |= BFREADONLY;
                        }
                }
        }

Reply via email to