On Wed, Oct 10, 2012 at 03:31:30PM +0200, Mark Kettenis wrote:
> > Date: Wed, 10 Oct 2012 15:12:59 +0200
> > From: Jasper Lievisse Adriaanse <jas...@openbsd.org>
> > 
> > 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.
> 
> Emacs uses 'Top', 'Bot' and 'All' and:
> 
> > From:
> >  (fundamental-fill)--L3--C31
> > to:
> >  (fundamental-fill)--9%--L69--C0
>  --L69--C0--9%--
> 
> >  or
> >  (fundamental-fill)--all--L1--C0
> 
>  --L1--C0--All--
Sure, let's go all the way then :)

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 13:39:00 -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), "--L%d--C%d--%s",
+                              wp->w_dotline, getcolpos(), location);
                if (len < sizeof(sl) && len != -1)
                        n += vtputs(sl);
        }


-- 
Cheers,
Jasper

"Stay Hungry. Stay Foolish"

Reply via email to