The man page for mg says this about blink-and-insert:
blink-and-insert
Self-insert a character, then search backwards and blink its matching
delimiter. For delimiters other than parenthesis, brackets, and braces,
the character itself is used as its own match.
However, if you do 'M-x blink-and-insert', mg inserts an 'x' character at
the cursor and then tries to find the previous 'x' character. By, 'x', I
mean a literal 'x' character, not a user typed character. The 'x' would
seem to come from the keystroke 'M-x'. Which is very handy if you want to
insert an 'x' and find a match with the previous 'x' (if there is one).
This diff attempts to make blink-and-insert do as the man page says it
should do.
If you do 'M-x blink-and-insert', you are asked for a character. mg will
then insert it at the current cursor position and then search backwards
for a corresponding match.
The normal behaviour of typing a ),] or } hasn't changed.
Comments/ok?
Mark
Index: def.h
===================================================================
RCS file: /cvs/src/usr.bin/mg/def.h,v
retrieving revision 1.159
diff -u -p -u -p -r1.159 def.h
--- def.h 22 Jun 2019 15:38:15 -0000 1.159
+++ def.h 24 Jun 2019 19:20:11 -0000
@@ -642,6 +642,7 @@ void ttykeymapinit(void);
void ttykeymaptidy(void);
/* match.c X */
+int ask_showmatch(int, int);
int showmatch(int, int);
/* version.c X */
Index: funmap.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/funmap.c,v
retrieving revision 1.55
diff -u -p -u -p -r1.55 funmap.c
--- funmap.c 13 Dec 2018 14:59:16 -0000 1.55
+++ funmap.c 24 Jun 2019 19:20:11 -0000
@@ -39,7 +39,7 @@ static struct funmap functnames[] = {
{backword, "backward-word",},
{gotobob, "beginning-of-buffer",},
{gotobol, "beginning-of-line",},
- {showmatch, "blink-and-insert",},
+ {ask_showmatch, "blink-and-insert",},
{bsmap, "bsmap-mode",},
{NULL, "c-x 4 prefix",},
{NULL, "c-x prefix",},
Index: match.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/match.c,v
retrieving revision 1.19
diff -u -p -u -p -r1.19 match.c
--- match.c 3 Jun 2015 23:40:01 -0000 1.19
+++ match.c 24 Jun 2019 19:20:11 -0000
@@ -35,9 +35,30 @@ static struct balance {
{ '\0', '\0' }
};
+
/*
- * Hack to show matching paren. Self-insert character, then show matching
- * character, if any. Bound to "blink-and-insert".
+ * Self-insert character, then show matching character.
+ * Bound to "blink-and-insert".
+ */
+int
+ask_showmatch(int f, int n)
+{
+ char *c, cbuf[2];
+
+ if ((c = eread("Insert a character: ", cbuf, sizeof(cbuf),
+ EFNEW)) == NULL || (c[0] == '\0'))
+ return (ABORT);
+
+ key.k_chars[0] = *c;
+ key.k_chars[1] = '\0';
+ key.k_count = 1;
+
+ return (showmatch(FFRAND, 1));
+}
+
+
+/*
+ * Hack to show matching paren. Bound to balance stucture chars ),],}.
*/
int
showmatch(int f, int n)