Re: make mg statusline a bit more informative

2012-10-10 Thread Mark Kettenis
> Date: Wed, 10 Oct 2012 15:39:39 +0200
> From: Jasper Lievisse Adriaanse 
> 
> 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 
> > > 
> > > 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 :)

Fine with me, but I'm neither an mg hacker or an mg user.  So I think
a more authoritive ok is needed.

> 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 -   1.37
> +++ display.c 10 Oct 2012 13:39:00 -
> @@ -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);
>   }



Re: make mg statusline a bit more informative

2012-10-10 Thread Otto Moerbeek
On Wed, Oct 10, 2012 at 03:39:39PM +0200, Jasper Lievisse Adriaanse wrote:

> 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 
> > > 
> > > 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 :)

The info tends to get cut off. Using emacs in a 80 column window shows
the style part (the stuff within parentheses) and the counts more to
the left. 

Also, mg seem to compute the percentage based on line numbers and cursor
position. But emacs computes a number based the top line being shown
and the total number of lines in the file. Emacs updates the number
only when the top line changes due to cursor or other movement.

-Otto


> 
> 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 -   1.37
> +++ display.c 10 Oct 2012 13:39:00 -
> @@ -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"



Re: make mg statusline a bit more informative

2012-10-10 Thread Jasper Lievisse Adriaanse
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 
> > 
> > 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 -   1.37
+++ display.c   10 Oct 2012 13:39:00 -
@@ -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"



Re: make mg statusline a bit more informative

2012-10-10 Thread Mark Kettenis
> Date: Wed, 10 Oct 2012 15:12:59 +0200
> From: Jasper Lievisse Adriaanse 
> 
> 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--



make mg statusline a bit more informative

2012-10-10 Thread Jasper Lievisse Adriaanse
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 -   1.37
+++ display.c   10 Oct 2012 11:56:51 -
@@ -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"