Hi! If we don't have to follow what GNU Emacs is doing anyway, let's just change behavior of {beginning,end}-of-buffer to this instead of implementing a useless mode:
Index: basic.c =================================================================== RCS file: /cvs/src/usr.bin/mg/basic.c,v retrieving revision 1.48 diff -u -p -r1.48 basic.c --- basic.c 3 Jun 2019 16:26:30 -0000 1.48 +++ basic.c 11 Jun 2019 15:15:15 -0000 @@ -124,7 +124,8 @@ forwchar(int f, int n) int gotobob(int f, int n) { - (void) setmark(f, n); + if (!curwp->w_markp) + (void) setmark(f, n); curwp->w_dotp = bfirstlp(curbp); curwp->w_doto = 0; curwp->w_rflag |= WFFULL; @@ -150,7 +151,8 @@ gotoeob(int f, int n) int ln; struct line *lp; - (void) setmark(f, n); + if (!curwp->w_markp) + (void) setmark(f, n); curwp->w_dotp = blastlp(curbp); curwp->w_doto = llength(curwp->w_dotp); curwp->w_dotline = curwp->w_bufp->b_lines; Index: mg.1 =================================================================== RCS file: /cvs/src/usr.bin/mg/mg.1,v retrieving revision 1.114 diff -u -p -r1.114 mg.1 --- mg.1 6 Jun 2019 18:17:34 -0000 1.114 +++ mg.1 11 Jun 2019 15:15:15 -0000 @@ -1,7 +1,7 @@ .\" $OpenBSD: mg.1,v 1.114 2019/06/06 18:17:34 jmc Exp $ .\" This file is in the public domain. .\" -.Dd $Mdocdate: June 6 2019 $ +.Dd $Mdocdate: June 11 2019 $ .Dt MG 1 .Os .Sh NAME @@ -408,6 +408,7 @@ Move cursor to the top of the buffer. A numeric argument .Va n will move n/10th of the way from the top. +Set mark at previous position if mark is not set. .It beginning-of-line Move cursor to the beginning of the line. .It blink-and-insert @@ -532,6 +533,7 @@ Move cursor to the end of the buffer. A numeric argument .Va n will move n/10th of the way from the end. +Set mark at previous position if mark is not set. .It end-of-line Move cursor to the end of the line. .It enlarge-window Index: region.c =================================================================== RCS file: /cvs/src/usr.bin/mg/region.c,v retrieving revision 1.37 diff -u -p -r1.37 region.c --- region.c 9 Sep 2016 06:05:51 -0000 1.37 +++ region.c 11 Jun 2019 15:15:15 -0000 @@ -405,6 +405,7 @@ markbuffer(int f, int n) { if (gotoeob(f,n) == FALSE) return (FALSE); + (void) clearmark(f, n); if (gotobob(f,n) == FALSE) return (FALSE); return (TRUE);