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

[PATCH] Re: Commands should not stop and cause an error



On Fri, 11 Jun 2004, Jens Paulus wrote:
> > I disagree, but shouldn't "pager_stop" control their behavior?
> 
> this may be a good idea. The varialbe pager_stop could make all these
> commands stop or not stop at the beginning or end of the message.
> 
> pager next-line
> pager previous-line
> pager next-page
> pager previous-page
> 
> Maybe this is the right solution.

My patch (a dirty hack) is attached.
I wrote this hack with 1.4.1.
But you can apply this to 1.5.6 or CVS HEAD.

Try these settings:
 set pager_linestop
 set pager_prevstop

I made two additional variables
in order not to break compatibility.

-- 
tamo
--- OPS.BAK     Thu Jul  8 17:39:15 2004
+++ OPS Thu Jul  8 18:32:35 2004
@@ -112,6 +112,7 @@
 OP_MAIN_PREV_THREAD "jump to previous thread"
 OP_MAIN_PREV_SUBTHREAD "jump to previous subthread"
 OP_MAIN_PREV_UNDELETED "move to the previous undeleted message"
+OP_MAIN_PREV_UNDELETED_BOTTOM "view the bottom of the prev-undeleted msg"
 OP_MAIN_PREV_NEW "jump to the previous new message"
 OP_MAIN_PREV_UNREAD "jump to the previous unread message"
 OP_MAIN_READ_THREAD "mark the current thread as read"
--- commands.c.BAK      Thu Jul  8 17:55:38 2004
+++ commands.c  Thu Jul  8 18:32:36 2004
@@ -60,7 +60,7 @@
 /* The folder the user last saved to.  Used by ci_save_message() */
 static char LastSaveFolder[_POSIX_PATH_MAX] = "";
 
-int mutt_display_message (HEADER *cur)
+int mutt_display_message (HEADER *cur, int bottom)
 {
   char tempfile[_POSIX_PATH_MAX], buf[LONG_STRING];
   int rc = 0, builtin = 0;
@@ -178,7 +178,7 @@
     memset (&info, 0, sizeof (pager_t));
     info.hdr = cur;
     info.ctx = Context;
-    rc = mutt_pager (NULL, tempfile, M_PAGER_MESSAGE, &info);
+    rc = mutt_pager (NULL, tempfile, (M_PAGER_MESSAGE | bottom), &info);
   }
   else
   {
--- curs_main.c.BAK     Thu Jul  8 19:32:07 2004
+++ curs_main.c Thu Jul  8 19:27:37 2004
@@ -24,6 +24,7 @@
 #include "sort.h"
 #include "buffy.h"
 #include "mx.h"
+#include "pager.h"
 
 #ifdef USE_POP
 #include "pop.h"
@@ -424,6 +425,7 @@
   int do_buffy_notify = 1;
   int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
   int attach_msg = option(OPTATTACHMSG);
+  int bottom = 0;
   
   menu = mutt_new_menu ();
   menu->menu = MENU_MAIN;
@@ -1067,7 +1069,7 @@
            menu->current = mutt_thread_next_unread (Context, CURHDR);
        }
  
-       if ((op = mutt_display_message (CURHDR)) == -1)
+       if ((op = mutt_display_message (CURHDR, bottom)) == -1)
        {
          unset_option (OPTNEEDRESORT);
          break;
@@ -1075,6 +1077,7 @@
 
        menu->menu = MENU_PAGER;
        menu->oldcurrent = menu->current;
+       bottom = 0;
        continue;
 
       case OP_EXIT:
@@ -1160,6 +1163,7 @@
          menu->redraw = REDRAW_MOTION;
        break;
 
+      case OP_MAIN_PREV_UNDELETED_BOTTOM:
       case OP_MAIN_PREV_UNDELETED:
 
        CHECK_MSGCOUNT;
@@ -1177,6 +1181,9 @@
        }
        else if (menu->menu == MENU_PAGER)
        {
+         bottom = 0;
+         if (op == OP_MAIN_PREV_UNDELETED_BOTTOM)
+           bottom = M_PAGER_BOTTOM;
          op = OP_DISPLAY_MESSAGE;
          continue;
        }
--- init.h.BAK  Thu Jul  8 17:14:09 2004
+++ init.h      Thu Jul  8 17:23:03 2004
@@ -1165,6 +1165,21 @@
   ** when you are at the end of a message and invoke the \fInext-page\fP
   ** function.
   */
+  { "pager_linestop",  DT_BOOL, R_NONE, OPTPAGERLINESTOP, 1 },
+  /*
+  ** .pp
+  ** When set, the internal-pager will \fBnot\fP move to the next message
+  ** when you are at the end of a message and invoke the \fInext-line\fP
+  ** function.
+  */
+  { "pager_prevstop",  DT_BOOL, R_NONE, OPTPAGERPREVSTOP, 1 },
+  /*
+  ** .pp
+  ** When set, the internal-pager will \fBnot\fP move to the previous message
+  ** when you are at the top of a message and invoke the \fIprevious-page\fP
+  ** function (when $$pager_stop is set). This affects the \fIprevious-line\fP
+  ** function, too (when $$pager_linestop is set).
+  */
   
 
 #ifdef HAVE_PGP
--- mutt.h.BAK  Thu Jul  8 19:34:33 2004
+++ mutt.h      Thu Jul  8 19:35:00 2004
@@ -375,6 +375,8 @@
   OPTMHPURGE,
   OPTMIMEFORWDECODE,
   OPTPAGERSTOP,
+  OPTPAGERLINESTOP,
+  OPTPAGERPREVSTOP,
   OPTPIPEDECODE,
   OPTPIPESPLIT,
 #ifdef USE_POP
--- pager.c.BAK Thu Jul  8 17:14:39 2004
+++ pager.c     Thu Jul  8 20:39:55 2004
@@ -1485,6 +1485,10 @@
   int indicator = indexlen / 3;        /* the indicator line of the PI */
   int old_PagerIndexLines;             /* some people want to resize it
                                         * while inside the pager... */
+  int bottom = 0;
+
+  if (flags & M_PAGER_BOTTOM)
+     bottom = 1;
 
   if (!(flags & M_SHOWCOLOR))
     flags |= M_SHOWFLAT;
@@ -1654,6 +1658,21 @@
 
     if ((redraw & REDRAW_BODY) || topline != oldtopline)
     {
+      if (bottom == 1)
+      {
+       if (lineInfo[topline].offset < sb.st_size - 1)
+       {
+         i = topline;
+         while (display_line (fp, &last_pos, &lineInfo, i, &lastLine, 
+                               &maxLine, has_types, 
+                               &QuoteList, &q_level, &force_redraw,
+                               &SearchRE) == 0)
+           i++;
+         topline = upNLines (bodylen, lineInfo, lastLine, hideQuoted);
+       }
+       bottom = 0;
+      }
+
       do {
        move (bodyoffset, 0);
        curline = oldtopline = topline;
@@ -1834,8 +1853,14 @@
        {
          topline = upNLines (bodylen-PagerContext, lineInfo, topline, 
hideQuoted);
        }
-       else
+       else if ((option (OPTPAGERSTOP)) || (option (OPTPAGERPREVSTOP)))
          mutt_error _("Top of message is shown.");
+       else
+       {
+         /* top of the current message, so display the previous message. */
+         rc = OP_MAIN_PREV_UNDELETED_BOTTOM;
+         ch = -1;
+       }
        break;
 
       case OP_NEXT_LINE:
@@ -1849,15 +1874,27 @@
              topline++;
          }
        }
-       else
+       else if (option (OPTPAGERLINESTOP))
          mutt_error _("Bottom of message is shown.");
+       else
+       {
+         /* end of the current message, so display the next message. */
+         rc = OP_MAIN_NEXT_UNDELETED;
+         ch = -1;
+       }
        break;
 
       case OP_PREV_LINE:
        if (topline)
          topline = upNLines (1, lineInfo, topline, hideQuoted);
-       else
+       else if ((option (OPTPAGERLINESTOP)) || (option (OPTPAGERPREVSTOP)))
          mutt_error _("Top of message is shown.");
+       else
+       {
+         /* top of the current message, so display the previous message. */
+         rc = OP_MAIN_PREV_UNDELETED_BOTTOM;
+         ch = -1;
+       }
        break;
 
       case OP_PAGER_TOP:
--- pager.h.BAK Thu Jul  8 20:26:33 2004
+++ pager.h     Thu Jul  8 18:32:34 2004
@@ -30,6 +30,7 @@
 #define M_PAGER_RETWINCH       (1<<7)  /* need reformatting on SIGWINCH */
 #define M_PAGER_MESSAGE                (M_SHOWCOLOR | M_PAGER_MARKER)
 #define M_PAGER_ATTACHMENT     (1<<8)
+#define M_PAGER_BOTTOM         (1<<9)  /* jump to the bottom */
 
 #define M_DISPLAYFLAGS (M_SHOW | M_PAGER_NSKIP | M_PAGER_MARKER)
 
--- protos.h.BAK        Thu Jul  8 19:08:54 2004
+++ protos.h    Thu Jul  8 19:08:41 2004
@@ -253,7 +253,7 @@
 int mutt_compose_attachment (BODY *a);
 int mutt_copy_body (FILE *, BODY **, BODY *);
 int mutt_decode_save_attachment (FILE *, BODY *, char *, int, int);
-int mutt_display_message (HEADER *h);
+int mutt_display_message (HEADER *h, int);
 int mutt_edit_attachment(BODY *);
 int mutt_edit_message (CONTEXT *, HEADER *);
 int mutt_fetch_recips (ENVELOPE *out, ENVELOPE *in, int flags);