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

[PATCH] menu_context (was: Re: index_context: like pager_context)



Re: Mun Johl in <20040215002700.GP29098@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
> Interesting.  After reading this, I first thought that perhaps one of my
> other installed patches was interfering.  But that is not the case.  I
> took a fresh 1.5.6 and only installed the
> patch-1.5.5.1.mgs.index-context.5 patch.  I then opened my mailbox and
> jumped to the last message in the index.  I typed my command for
> current-middle (zz) and ... well, nothing.  That is, the display didn't
> change at all.

I've written an improved version of Mike's index_context patch (that is
now called menu_context to be consistent with $menu_scroll) that
addresses this issue. The new $menu_move_off option controls whether the
menu entries are allowed to move off from the bottom of the menu. The
new patch also makes $menu_context work with $menu_scroll unset.

Christoph
-- 
cb@xxxxxxxx | http://www.df7cb.de/
patch-1.5.6.cb.menu_context.6
-----------------------------

This patch introduces two new options, menu_context and menu_move_off. It is an
improved version of patch-1.5.5.1.mgs.index-context.5 my Mike Schiraldi (where
menu_context was called index_context).

  6.3.101.  menu_context

  Type: number
  Default: 0

  This variable controls the number of lines of context that are given
  when scrolling through menus. (Similar to ````$pager_context''''.)

  6.3.103.  menu_move_off

  Type: boolean
  Default: yes

  When unset, the bottom entry of menus will never scroll up past the
  bottom of the screen, unless there are less entries than lines.  When
  set, the bottom entry may move off the bottom.

Patch homepage: http://www.df7cb.de/projects/mutt/

Christoph Berg <cb@xxxxxxxx>

------------------------------------------------------------------------

diff -ur ../MUTT/mutt/PATCHES mutt/PATCHES
--- ../MUTT/mutt/PATCHES        2002-12-09 18:44:54.000000000 +0100
+++ mutt/PATCHES        2004-03-06 14:32:11.000000000 +0100
@@ -0,0 +1 @@
+patch-1.5.6.cb.menu_context.6
diff -ur ../MUTT/mutt/globals.h mutt/globals.h
--- ../MUTT/mutt/globals.h      2004-02-13 16:08:31.000000000 +0100
+++ mutt/globals.h      2004-03-06 13:51:46.000000000 +0100
@@ -144,6 +144,7 @@
 
 WHERE short ConnectTimeout;
 WHERE short HistSize;
+WHERE short MenuContext;
 WHERE short PagerContext;
 WHERE short PagerIndexLines;
 WHERE short ReadInc;
diff -ur ../MUTT/mutt/init.h mutt/init.h
--- ../MUTT/mutt/init.h 2004-02-13 16:08:31.000000000 +0100
+++ mutt/init.h 2004-03-06 14:45:50.000000000 +0100
@@ -1030,6 +1030,12 @@
   ** If unset, Mutt will remove your address (see the ``alternates''
   ** command) from the list of recipients when replying to a message.
   */
+  { "menu_context",    DT_NUM,  R_NONE, UL &MenuContext, 0 },
+  /*
+  ** .pp
+  ** This variable controls the number of lines of context that are given
+  ** when scrolling through menus. (Similar to ``$$pager_context''.)
+  */
   { "menu_scroll",     DT_BOOL, R_NONE, OPTMENUSCROLL, 0 },
   /*
   ** .pp
@@ -1038,6 +1044,13 @@
   ** is cleared and the next or previous page of the menu is displayed
   ** (useful for slow links to avoid many redraws).
   */
+  { "menu_move_off",   DT_BOOL, R_NONE, OPTMENUMOVEOFF, 1 },
+  /*
+  ** .pp
+  ** When \fIunset\fP, the bottom entry of menus will never scroll up past
+  ** the bottom of the screen, unless there are less entries than lines.
+  ** When \fIset\fP, the bottom entry may move off the bottom.
+  */
   { "meta_key",                DT_BOOL, R_NONE, OPTMETAKEY, 0 },
   /*
   ** .pp
diff -ur ../MUTT/mutt/menu.c mutt/menu.c
--- ../MUTT/mutt/menu.c 2004-02-13 16:08:31.000000000 +0100
+++ mutt/menu.c 2004-03-06 14:32:11.000000000 +0100
@@ -367,32 +367,35 @@
 
 void menu_check_recenter (MUTTMENU *menu)
 {
+  int c = MIN (MenuContext, 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 - c)
   {
     if (option (OPTMENUSCROLL) || (menu->pagelen <= 0))
-      menu->top = menu->current - menu->pagelen + 1;
+      menu->top = menu->current - menu->pagelen + c + 1;
     else
-      menu->top += menu->pagelen * ((menu->current - menu->top) / 
menu->pagelen);
-    menu->redraw |= REDRAW_INDEX;
+      menu->top += (menu->pagelen - c) * ((menu->current - menu->top) / 
(menu->pagelen - c)) - c;
   }
-  else if (menu->current < menu->top)
+  else if (menu->current < menu->top + c)
   {
     if (option (OPTMENUSCROLL) || (menu->pagelen <= 0))
-      menu->top = menu->current;
+      menu->top = menu->current - c;
     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 -= (menu->pagelen - c) * ((menu->top + menu->pagelen - 1 - 
menu->current) / (menu->pagelen - c)) - c;
   }
+
+  if (!option (OPTMENUMOVEOFF))
+    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)
@@ -476,7 +479,9 @@
 
 void menu_prev_page (MUTTMENU *menu)
 {
-  if (menu->top > 0)
+  int c = MIN (MenuContext, menu->pagelen / 2);
+
+  if (menu->top > c)
   {
     if ((menu->top -= menu->pagelen) < 0)
       menu->top = 0;
diff -ur ../MUTT/mutt/mutt.h mutt/mutt.h
--- ../MUTT/mutt/mutt.h 2004-02-13 16:08:32.000000000 +0100
+++ mutt/mutt.h 2004-03-06 14:39:56.000000000 +0100
@@ -376,6 +376,7 @@
   OPTMARKERS,
   OPTMARKOLD,
   OPTMENUSCROLL,       /* scroll menu instead of implicit next-page */
+  OPTMENUMOVEOFF,      /* allow menu to scroll past last entry */
   OPTMETAKEY,          /* interpret ALT-x as ESC-x */
   OPTMETOO,
   OPTMHPURGE,

Attachment: signature.asc
Description: Digital signature