summaryrefslogtreecommitdiff
path: root/usr.bin/mg/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/mg/main.c')
-rw-r--r--usr.bin/mg/main.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c
index b67c08b53ad..961690f2b02 100644
--- a/usr.bin/mg/main.c
+++ b/usr.bin/mg/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.58 2008/06/12 01:58:44 kjell Exp $ */
+/* $OpenBSD: main.c,v 1.59 2008/06/13 18:41:57 kjell Exp $ */
/* This file is in the public domain. */
@@ -46,6 +46,7 @@ main(int argc, char **argv)
PF init_fcn = NULL;
int o, i, nfiles;
int nobackups = 0;
+ struct buffer *bp;
while ((o = getopt(argc, argv, "nf:")) != -1)
switch (o) {
@@ -107,6 +108,20 @@ main(int argc, char **argv)
(void)load(cp);
#endif /* !NO_STARTUP */
+ /*
+ * Create scratch buffer now, killing old *init* buffer.
+ * This causes *scratch* to be created and made curbp,
+ * ensuring default modes are inherited from the startup
+ * file correctly
+ */
+
+ if ((bp = bfind("*init*", FALSE)) != NULL)
+ killbuffer(bp);
+
+ /* Force FFOTHARG=1 so that this mode is enabled, not simply toggled */
+ if (init_fcn)
+ init_fcn(FFOTHARG, 1);
+
if (nobackups)
makebkfile(FFARG, 0);
@@ -134,8 +149,9 @@ notnum:
if (readin(cp) != TRUE)
killbuffer(curbp);
else {
+ /* Ensure enabled, not just toggled */
if (init_fcn_name)
- init_fcn(0, 1);
+ init_fcn(FFOTHARG, 1);
nfiles++;
}
}
@@ -178,6 +194,8 @@ notnum:
/*
* Initialize default buffer and window.
+ * Initially, buffer is named *init*. This is changed later
+ * to *scratch* after the startup files are read.
*/
static void
edinit(PF init_fcn)
@@ -186,7 +204,7 @@ edinit(PF init_fcn)
struct mgwin *wp;
bheadp = NULL;
- bp = bfind("*scratch*", TRUE); /* Text buffer. */
+ bp = bfind("*init*", TRUE); /* Text buffer. */
wp = new_window(bp);
if (wp == NULL)
panic("Out of memory");
@@ -199,9 +217,6 @@ edinit(PF init_fcn)
wp->w_linep = wp->w_dotp = bp->b_headp;
wp->w_ntrows = nrow - 2; /* 2 = mode, echo. */
wp->w_flag = WFMODE | WFFULL; /* Full. */
-
- if (init_fcn)
- init_fcn(0, 1);
}
/*