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:
> I hope it has been fixed in v4.
Forgot to attach it.
--
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 08:32:00.000000000 +0900
@@ -1096,7 +1096,15 @@
** 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, the next-page and prev-page functions usually jumps exactly
+ ** how many menu items your screen shows. $$$menu_jump_context decreases the
+ ** length of jumps. When this is set to 1, the last entry will be the first
+ ** entry of the next page.
+ */
+ { "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 11:26:21.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,80 @@
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 neg = (jumplen >= 0) ? 0 : -1;
+ int c = MIN (MenuContext, menu->pagelen / 2);
+ int adj = 0;
+ if (menu->current < menu->top + c)
+ adj = (menu->top + c) - menu->current;
+ else if (menu->current > menu->top + (menu->pagelen - 1) - c)
+ adj = (menu->top + (menu->pagelen - 1) - c) - menu->current;
+
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 <
+ (neg ? 0 : menu->max /* -1 */ - menu->pagelen /* -1 */))
+ {
+ menu->top += jumplen;
+
+ /* jumped too long? */
+ if ((neg || !option (OPTMENUMOVEOFF)) &&
+ DIRECTION * menu->top >
+ (neg ? 0 : menu->max /* -1 */ - menu->pagelen /* -1 */))
+ menu->top = neg ? 0 : menu->max /* -1 */ - menu->pagelen /* -1 */;
+
+ /* need to move the cursor? */
+ if (DIRECTION *
+ (menu->current - (menu->top + (neg ? (menu->pagelen - 1) - c : c)))
+ < 0)
+ menu->current = (menu->current + jumplen) + adj;
+
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 +601,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)