For the issue of not being able to force-insert tabs in c-mode conveniently
I had two potential solutions, one to simply make the tab key selfinsert after
fixing the indentation (if one wants only the indentation fix and not the
self-insert, they can backspace the tab immediately), and one to bind
something like C-M-i (ESC TAB) to a function that inserts a tab without regard
for proper indentation, however I couldn't quite figure out how to make that
work as a binding registered by c-mode itself, without modifying the
fundamental keymap; the keymap structures are a bit confusing...

I would appreciate some words from someone more familiar with mg internals
(op@?) on my ideas and thoughts on trying to improve c-mode in general :)

The below is a diff that makes TAB also self-insert in c-mode:

Index: cmode.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/cmode.c,v
diff -u -p -r1.23 cmode.c
--- cmode.c     21 May 2024 05:00:48 -0000      1.23
+++ cmode.c     10 Nov 2026 16:41:00 -0000
@@ -147,11 +147,12 @@ cc_tab(int f, int n)
 
        inwhitep = in_whitespace(curwp->w_dotp, llength(curwp->w_dotp));
 
-       /* If empty line, or in whitespace */
-       if (llength(curwp->w_dotp) == 0 || inwhitep)
-               return (selfinsert(f, n));
+       /* Indent unless empty line, or in whitespace */
+       if (llength(curwp->w_dotp) != 0 && !inwhitep &&
+           cc_indent(FFRAND, 1) == FALSE)
+               return FALSE;
 
-       return (cc_indent(FFRAND, 1));
+       return selfinsert(f, n);
 }
 
 /*

Reply via email to