Currently the statusline in mg shows the line and column numbers, which is
nice but doesn't let you know your relative position in the file.

Emacs shows 'top', 'bot', 'all' or your relative position like '42%'. This
diff implements that behaviour in mg too.

From:
 (fundamental-fill)--L3--C31
to:
 (fundamental-fill)--9%--L69--C0
 or
 (fundamental-fill)--all--L1--C0

you get the idea.

Index: display.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/display.c,v
retrieving revision 1.37
diff -p -u -r1.37 display.c
--- display.c   4 Jun 2009 02:23:37 -0000       1.37
+++ display.c   10 Oct 2012 11:56:51 -0000
@@ -835,8 +835,21 @@ modeline(struct mgwin *wp)
        ++n;
 
        if (linenos) {
-               len = snprintf(sl, sizeof(sl), "--L%d--C%d", wp->w_dotline,
-                   getcolpos());
+               char location[4], r_location[4];
+
+               if (bp->b_lines <= wp->w_ntrows) {
+                       strlcpy(location, "all", sizeof(location));
+               } else if (wp->w_dotline <= wp->w_ntrows) {
+                       strlcpy(location, "top", sizeof(location));
+               } else if (wp->w_dotline >= (bp->b_lines - wp->w_ntrows)) {
+                       strlcpy(location, "bot", sizeof(location));
+               } else {
+                       snprintf(r_location, sizeof(r_location), "%d%%", (100 * 
wp->w_dotline) / bp->b_lines);
+                       strlcpy(location, r_location, sizeof(location));
+               }
+
+               len = snprintf(sl, sizeof(sl), "--%s--L%d--C%d",
+                              location, wp->w_dotline, getcolpos());
                if (len < sizeof(sl) && len != -1)
                        n += vtputs(sl);
        }


-- 
Cheers,
Jasper

"Stay Hungry. Stay Foolish"

Reply via email to