=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mg/main.c,v retrieving revision 1.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- src/usr.bin/mg/main.c 2008/06/12 01:58:44 1.58 +++ src/usr.bin/mg/main.c 2008/06/13 18:41:57 1.59 @@ -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 @@ 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 @@ (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 @@ 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 @@ /* * 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 @@ 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 @@ 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); } /*