<<< Date Index >>>     <<< Thread Index >>>

PATCH: index_context: like pager_context



A long time ago, i wrote a patch that adds a variable, index_context, which
works like pager_context: When moving the indicator through the index,
scrolling will start happening n lines early -- in other words, before you
reach the end of the screen. This is useful for exactly the same reason
pager_context is useful -- it allows you to always see a few messages ahead
and it lets you know when you're getting close to the end.

I've been using this for years, and it seems to work great. But it sure
would be nice if it was included into mutt so i wouldn't have to keep
applying the patch myself.

See attached.
Index: globals.h
===================================================================
RCS file: /home/roessler/cvs/mutt/globals.h,v
retrieving revision 3.6
diff -u -r3.6 globals.h
--- globals.h   15 Jul 2003 11:41:32 -0000      3.6
+++ globals.h   18 Jan 2004 23:25:19 -0000
@@ -142,6 +142,7 @@
 
 WHERE short ConnectTimeout;
 WHERE short HistSize;
+WHERE short IndexContext;
 WHERE short PagerContext;
 WHERE short PagerIndexLines;
 WHERE short ReadInc;
Index: init.h
===================================================================
RCS file: /home/roessler/cvs/mutt/init.h,v
retrieving revision 3.42
diff -u -r3.42 init.h
--- init.h      4 Jan 2004 10:55:20 -0000       3.42
+++ init.h      18 Jan 2004 23:25:22 -0000
@@ -883,6 +883,12 @@
   { "indent_str",      DT_SYN,  R_NONE, UL "indent_string", 0 },
   /*
   */
+  { "index_context",   DT_NUM,  R_NONE, UL &IndexContext, 0 },
+  /*
+  ** .pp
+  ** This variable controls the number of lines of context that are given
+  ** when scrolling through the message index.
+  */
   { "index_format",    DT_STR,  R_BOTH, UL &HdrFmt, UL "%4C %Z %{%b %d} 
%-15.15L (%?l?%4l&%4c?) %s" },
   /*
   ** .pp
Index: menu.c
===================================================================
RCS file: /home/roessler/cvs/mutt/menu.c,v
retrieving revision 3.11
diff -u -r3.11 menu.c
--- menu.c      4 Jan 2004 10:25:13 -0000       3.11
+++ menu.c      18 Jan 2004 23:25:22 -0000
@@ -373,32 +373,34 @@
 
 void menu_check_recenter (MUTTMENU *menu)
 {
+  int ic = MIN (IndexContext, menu->pagelen / 2);
+  int old_top = menu->top;
+
   if (menu->max <= menu->pagelen && menu->top != 0)
   {
     menu->top = 0;
     set_option (OPTNEEDREDRAW);
-    menu->redraw |= REDRAW_INDEX;
   }
-  else if (menu->current >= menu->top + menu->pagelen)
+  else if (menu->current >= menu->top + menu->pagelen - ic)
   {
     if (option (OPTMENUSCROLL) || (menu->pagelen <= 0))
-      menu->top = menu->current - menu->pagelen + 1;
+      menu->top = menu->current - menu->pagelen + ic + 1;
     else
       menu->top += menu->pagelen * ((menu->current - menu->top) / 
menu->pagelen);
-    menu->redraw |= REDRAW_INDEX;
   }
-  else if (menu->current < menu->top)
+  else if (menu->current < menu->top + ic)
   {
     if (option (OPTMENUSCROLL) || (menu->pagelen <= 0))
-      menu->top = menu->current;
+      menu->top = menu->current - ic;
     else
-    {
       menu->top -= menu->pagelen * ((menu->top + menu->pagelen - 1 - 
menu->current) / menu->pagelen);
-      if (menu->top < 0)
-       menu->top = 0;
-    }
-    menu->redraw |= REDRAW_INDEX;
   }
+
+  menu->top = MIN (menu->top, menu->max - menu->pagelen);
+  menu->top = MAX (menu->top, 0);
+
+  if (menu->top != old_top) 
+    menu->redraw |= REDRAW_INDEX;  
 }
 
 void menu_jump (MUTTMENU *menu)
@@ -482,7 +484,9 @@
 
 void menu_prev_page (MUTTMENU *menu)
 {
-  if (menu->top > 0)
+  int ic = MIN (IndexContext, menu->pagelen / 2);
+
+  if (menu->top > ic)
   {
     if ((menu->top -= menu->pagelen) < 0)
       menu->top = 0;