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

Re: For 1.5.9: menu_move_off (was: Change in behavior <current-middle>)



On Thu, Mar 31, 2005 at 01:40:21PM +0900, Tamotsu Takahashi wrote:

> On Wed, Mar 30, 2005 at 02:56:39PM +0200, Alain Bench wrote:

> >     Unfortunately yes, worse. Cursor seems to sometimes behave as "fixed
> > altitude", and sometimes as "pushed by boundaries" (?!?) where it is
> > placed at nearest possible of previous position (always at $menu_context
> > from top when paging down, from bottom when paging up). Both behaviours
> > have their own internal coherence, but we have to choose one only (No
> > no: I won't shout "Yet Another Variable!"). The mix is illogical. I like
> > equally both: Fixed was new and interesting, but pushed surely more
> > consistent with legacy behaviour. And with reversed behaviour: When you
> > cursor jump (say to next new) the boundaries are pushed.
> 
> I was stupid.
> The previous patch had these lines:
> |
> |    if ((menu->top -= jumplen) < 0);
> |      menu->top = 0;
> |

And I have misread you. Sorry.
Please test v5 instead of v4.
This behaves the same as 1.5.6.

Surprisingly, v5 decreases the amount of the code.


> > | This variable controls the number of lines of context that are given
> > | when displaying the next or previous page in menus (index, browser,
> > | alias selector, ...). By default, Mutt will display the line after the
> > | last one on the screen at the top of the next page (0 lines of
> > | context). Identical to ````$pager_context'''' for the internal pager.
> > 
> >     Hoping nobody will notice I'm a lazy copy/paster... :-)
> 
> Not included in v4 yet.

Your one is good, but I don't want to use
        "Identical to ``$pager_context'' for the internal pager."
unless $menu_context is changed.

-- 
tamo
--- ../mutt-1.5.9/globals.h     2005-02-13 05:01:02.000000000 +0900
+++ ./globals.h 2005-03-31 08:32:00.000000000 +0900
@@ -166,6 +166,7 @@
 WHERE short ConnectTimeout;
 WHERE short HistSize;
 WHERE short MenuContext;
+WHERE short MenuJumpContext;
 WHERE short PagerContext;
 WHERE short PagerIndexLines;
 WHERE short ReadInc;
--- ../mutt-1.5.9/init.h        2005-03-25 20:29:51.000000000 +0900
+++ ./init.h    2005-03-31 21:52:38.000000000 +0900
@@ -1096,7 +1096,16 @@
   ** This variable controls the number of lines of context that are given
   ** when scrolling through menus. (Similar to ``$$pager_context''.)
   */
-  { "menu_move_off",   DT_BOOL, R_NONE, OPTMENUMOVEOFF, 0 },
+  { "menu_jump_context",       DT_NUM,  R_NONE, UL &MenuJumpContext, 0 },
+  /*
+  ** .pp
+  ** In menus (eg. index), the number of lines PageUp or PageDown jumps is
+  ** usually the same as the number of menu-items your screen shows. If you
+  ** set $$$menu_jump_context to a non-zero number, PageUp or PageDown
+  ** will jump less. For example, the value "1" will let PageDown keep the
+  ** last item of the previous screen as the first item on the next screen.
+  */
+  { "menu_move_off",   DT_BOOL, R_NONE, OPTMENUMOVEOFF, 1 },
   /*
   ** .pp
   ** When \fIunset\fP, the bottom entry of menus will never scroll up past
--- ../mutt-1.5.9/menu.c        2005-03-25 20:29:51.000000000 +0900
+++ ./menu.c    2005-03-31 21:50:18.000000000 +0900
@@ -381,19 +381,19 @@
       set_option (OPTNEEDREDRAW);
     }
   }
-  else if (menu->current >= menu->top + menu->pagelen - c) /* indicator below 
bottom threshold */
+  else if (menu->current > menu->top + (menu->pagelen - 1) - c) /* indicator 
below bottom threshold */
   {
     if (option (OPTMENUSCROLL) || (menu->pagelen <= 0))
-      menu->top = menu->current - menu->pagelen + c + 1;
+      menu->top = menu->current - (menu->pagelen - 1) + c;
     else
-      menu->top += (menu->pagelen - c) * ((menu->current - menu->top) / 
(menu->pagelen - c)) - c;
+      menu->top = menu->current - c;
   }
   else if (menu->current < menu->top + c) /* indicator above top threshold */
   {
     if (option (OPTMENUSCROLL) || (menu->pagelen <= 0))
       menu->top = menu->current - c;
     else
-      menu->top -= (menu->pagelen - c) * ((menu->top + menu->pagelen - 1 - 
menu->current) / (menu->pagelen - c)) - c;
+      menu->top = menu->current - (menu->pagelen - 1) + c;
   }
 
   if (!option (OPTMENUMOVEOFF)) /* make entries stick to bottom */
@@ -465,48 +465,75 @@
     mutt_error _("You cannot scroll up farther.");
 }
 
-void menu_next_page (MUTTMENU *menu)
+/* 
+ * pageup:   jumplen == -pagelen
+ * pagedown: jumplen == pagelen
+ * halfup:   jumplen == -pagelen/2
+ * halfdown: jumplen == pagelen/2
+ */
+#define DIRECTION ((neg * 2) + 1)
+void menu_length_jump (MUTTMENU *menu, int jumplen)
 {
+  int tmp, neg = (jumplen >= 0) ? 0 : -1;
+  int c = MIN (MenuContext, menu->pagelen / 2);
+
   if (menu->max)
   {
-    if (menu->top + menu->pagelen < menu->max)
-    {
-      menu->top += menu->pagelen;
-      if (menu->current < menu->top)
-       menu->current = menu->top;
+    /* possible to scroll? */
+    if (DIRECTION * menu->top <
+       (tmp = (neg ? 0 : menu->max /* -1 */ - menu->pagelen /* -1 */)))
+    {
+      menu->top += jumplen;
+
+      /* jumped too long? */
+      if ((neg || !option (OPTMENUMOVEOFF)) &&
+         DIRECTION * menu->top > tmp)
+       menu->top = tmp;
+
+      /* need to move the cursor? */
+      if ((DIRECTION *
+          (tmp = (menu->current -
+                  (menu->top + (neg ? (menu->pagelen - 1) - c : c))
+         ))) < 0)
+       menu->current -= tmp;
+
       menu->redraw = REDRAW_INDEX;
     }
-    else if (menu->current != menu->max - 1 && !menu->dialog)
+    else if (menu->current != (neg ? 0 : menu->max - 1) && !menu->dialog)
     {
-      menu->current = menu->max - 1;
+      menu->current += jumplen;
       menu->redraw = REDRAW_MOTION;
     }
     else
-      mutt_error _("You are on the last page.");
+      mutt_error (neg ? _("You are on the first page.")
+                     : _("You are on the last page."));
+
+    menu->current = MIN (menu->current, menu->max - 1);
+    menu->current = MAX (menu->current, 0);
   }
   else
     mutt_error _("No entries.");
 }
+#undef DIRECTION
+
+void menu_next_page (MUTTMENU *menu)
+{
+  menu_length_jump (menu, MAX (menu->pagelen - MenuJumpContext, 0));
+}
 
 void menu_prev_page (MUTTMENU *menu)
 {
-  int c = MIN (MenuContext, menu->pagelen / 2);
+  menu_length_jump (menu, 0 - MAX (menu->pagelen - MenuJumpContext, 0));
+}
 
-  if (menu->top > c)
-  {
-    if ((menu->top -= menu->pagelen) < 0)
-      menu->top = 0;
-    if (menu->current >= menu->top + menu->pagelen)
-      menu->current = menu->top + menu->pagelen - 1;
-    menu->redraw = REDRAW_INDEX;
-  }
-  else if (menu->current && !menu->dialog)
-  {
-    menu->current = 0;
-    menu->redraw = REDRAW_MOTION;
-  }
-  else
-    mutt_error _("You are on the first page.");
+void menu_half_down (MUTTMENU *menu)
+{
+  menu_length_jump (menu, menu->pagelen / 2);
+}
+
+void menu_half_up (MUTTMENU *menu)
+{
+  menu_length_jump (menu, 0 - menu->pagelen / 2);
 }
 
 void menu_top_page (MUTTMENU *menu)
@@ -569,48 +596,6 @@
     mutt_error _("No entries.");
 }
 
-void menu_half_up (MUTTMENU *menu)
-{
-  if (menu->top > 0)
-  {
-    if ((menu->top -= menu->pagelen / 2) < 0)
-      menu->top = 0;
-    if (menu->current >= menu->top + menu->pagelen)
-      menu->current = menu->top + menu->pagelen - 1;
-    menu->redraw = REDRAW_INDEX;
-  }
-  else if (menu->current && !menu->dialog)
-  {
-    menu->current = 0;
-    menu->redraw = REDRAW_MOTION;
-  }
-  else
-    mutt_error _("First entry is shown.");
-}
-
-void menu_half_down (MUTTMENU *menu)
-{
-  if (menu->max)
-  {
-    if (menu->top + menu->pagelen < menu->max)
-    {
-      menu->top += menu->pagelen / 2;
-      if (menu->current < menu->top)
-       menu->current = menu->top;
-      menu->redraw = REDRAW_INDEX;
-    }
-    else if (menu->current != menu->max - 1 && !menu->dialog)
-    {
-      menu->current = menu->max - 1;
-      menu->redraw = REDRAW_INDEX;
-    }
-    else
-      mutt_error _("Last entry is shown.");
-  }
-  else
-    mutt_error _("No entries.");
-}
-
 void menu_current_top (MUTTMENU *menu)
 {
   if (menu->max)