]> granicus.if.org Git - neomutt/commitdiff
Gero Treuner's help-wrap patch.
authorThomas Roessler <roessler@does-not-exist.org>
Wed, 28 Oct 1998 16:39:53 +0000 (16:39 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Wed, 28 Oct 1998 16:39:53 +0000 (16:39 +0000)
OPS
attach.c
commands.c
curs_main.c
doc/manual.sgml.in
help.c
keymap.c
mutt_menu.h
pager.c
pager.h

diff --git a/OPS b/OPS
index d3b32c4c2e148535bca77048458625f73ca827a6..f228113fb55d4ea106c43bc7859d1cf161eb1467 100644 (file)
--- a/OPS
+++ b/OPS
@@ -123,6 +123,7 @@ OP_QUERY_APPEND "append new query results to current results"
 OP_QUIT "save changes to mailbox and quit"
 OP_RECALL_MESSAGE "recall a postponed message"
 OP_REDRAW "clear and redraw the screen"
+OP_REFORMAT_WINCH "{internal}"
 OP_REPLY "reply to a message"
 OP_SAVE "save message/attachment to a file"
 OP_SEARCH "search for a regular expression"
index b3b19f33c9ab62de0f8070189bb41b77ed120244..b6a613e70b7b576d0ecd9610e58f2161f40083cd 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -506,7 +506,8 @@ int mutt_view_attachment (FILE *fp, BODY *a, int flag)
     info.fp = fp;
     info.bdy = a;
     info.ctx = Context;
-    rc = mutt_do_pager (descrip, pagerfile, is_message, &info);
+    rc = mutt_do_pager (descrip, pagerfile,
+                       is_message ? M_PAGER_MESSAGE : 0, &info);
   }
   else
     rc = 0;
index e2084c8e57b31eb8a13a861e79b7c9c12961449b..c7a08923ee0a397d09010458d52da8fbbb90b635 100644 (file)
@@ -210,7 +210,7 @@ int mutt_display_message (HEADER *cur)
     memset (&info, 0, sizeof (pager_t));
     info.hdr = cur;
     info.ctx = Context;
-    rc = mutt_pager (NULL, tempfile, 1, &info);
+    rc = mutt_pager (NULL, tempfile, M_PAGER_MESSAGE, &info);
   }
   else
   {
index ea210992168d4ee4b3972e9093d37a6697615645..d1e0f96e1489422a4d5c2fdad0085fd2cf0cb94f 100644 (file)
@@ -243,7 +243,6 @@ int mutt_index_menu (void)
 {
   char buf[LONG_STRING], helpstr[SHORT_STRING];
   int op = OP_NULL;
-  event_t event = {-1, 0};
   int done = 0;                /* controls when to exit the "event" loop */
   int i = 0, j;
   int tag = 0;                 /* has the tag-prefix command been pressed? */
@@ -473,24 +472,7 @@ int mutt_index_menu (void)
        move (menu->current - menu->top + menu->offset, COLS - 1);
       mutt_refresh ();
 
-      if (Timeout > 0)
-      {
-       timeout (Timeout * 1000); /* milliseconds */      
-       event = mutt_getch ();
-       dprint(4, (debugfile, "mutt_index_menu[%d]: Got event (%d, %d)\n", __LINE__,
-                  event.ch, event.op));
-       timeout (-1); /* restore blocking operation */
-       op = event.ch;
-       if (op != -1)
-       {
-         dprint(4, (debugfile, "mutt_index_menu[%d]: Pushing event (%d, %d)\n", __LINE__,
-                    event.ch, event.op));
-         mutt_ungetch (event.ch, event.op);
-         op = km_dokey (MENU_MAIN);
-       }
-      }
-      else
-       op = km_dokey (MENU_MAIN);
+      op = km_dokey (MENU_MAIN);
 
       dprint(4, (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op));
 
index 03e34cd626d5e2788d9540c953aef99a3a76feba..c843c545a2a7a1a53a029723af53a06011cf9f05 100644 (file)
@@ -3199,6 +3199,11 @@ This variable specifies which pager you would like to use to view messages.
 <tt/builtin/ means to use the builtin pager, otherwise this variable should
 specify the pathname of the external pager you would like to use.
 
+Using an external pager may have some disadvantages: Additional keystrokes
+are necessary because you can't call mutt functions directly from the
+pager, and screen resizes cause lines longer than the screen width to be
+badly formatted in the help menu.
+
 <sect2>pager&lowbar;context<label id="pager_context">
 <p>
 Type: number<newline>
diff --git a/help.c b/help.c
index fbdd8dc852f5ea1fbcf730bb3a2bafd59f5df6a5..75ecd7fb7d6f4f55dd6a34444f8535aa7931b59c 100644 (file)
--- a/help.c
+++ b/help.c
@@ -85,54 +85,166 @@ mutt_compile_help (char *buf, size_t buflen, int menu, struct mapping_t *items)
   return buf;
 }
 
-static int print_macro (FILE *f, int maxchar, const char *macro)
+static int print_macro (FILE *f, int maxchar, const char **macro)
 {
-  int i;
+  int c = **macro;
+  int n = maxchar;
 
-  for (i = 0; *macro && i < maxchar; macro++, i++)
+  while (c)
   {
-    switch (*macro)
+    if (!IsPrint(c))
+    {
+      if (c >= ' ')
+       c = '?';
+      else if (n < 2)
+       c = 0;
+      else
+      {
+       --n;
+       switch (c)
+       {
+         case '\033':
+           fputc ('\\', f);
+           c = 'e';
+           break;
+         case '\n':
+           fputc ('\\', f);
+           c = 'n';
+           break;
+         case '\r':
+           fputc ('\\', f);
+           c = 'r';
+           break;
+         case '\t':
+           fputc ('\\', f);
+           c = 't';
+           break;
+         default:
+           fputc ('^', f);
+           c += '@';
+           break;
+       }
+      }
+    }
+
+    if (c && n > 0)
     {
-      case '\033':
-       fputs ("\\e", f);
-       i++;
-       break;
-      case '\n':
-       fputs ("\\n", f);
-       i++;
-       break;
-      case '\r':
-       fputs ("\\r", f);
-       i++;
-       break;
-      case '\t':
-       fputs ("\\t", f);
-       i++;
-       break;
-      default:
-       fputc (*macro, f);
-       break;
+      --n;
+      fputc(c, f);
+      c = *++*macro;
     }
+    else
+      c = 0;
   }
-  return (i);
+
+  return (maxchar - n);
 }
 
 static int pad (FILE *f, int col, int i)
 {
   char fmt[8];
 
-  if (i < col)
+  if (col < i)
   {
-    snprintf (fmt, sizeof(fmt), "%%-%ds", col - i);
+    snprintf (fmt, sizeof(fmt), "%%-%ds", i - col);
     fprintf (f, fmt, "");
-    i = col;
+    return (i);
+  }
+  fputc (' ', f);
+  return (col + 1);
+}
+
+static void format_line (FILE *f, int ismacro,
+                        const char *t1, const char *t2, const char *t3)
+{
+  int col;
+  int col_a, col_b;
+  int split;
+  int n;
+
+  fputs (t1, f);
+
+  /* don't try to press string into one line with less than 40 characters.
+     The double paranthesis avoid a gcc warning, sigh ... */
+  if ((split = COLS < 40))
+  {
+    col_a = col = 0;
+    col_b = LONG_STRING;
+    fputc ('\n', f);
   }
   else
   {
-    fputc (' ', f);
-    ++i;
+    col_a = 12 + (COLS > 83 ? (COLS - 80) >> 2 : 0);
+    col_b = 19 + (COLS > 43 ? (COLS - 16) >> 2 : 0);
+    col = pad (f, strlen(t1), col_a);
   }
-  return (i);
+
+  if (ismacro > 0)
+  {
+    if (!strcmp (Pager, "builtin"))
+      fputs ("_\010", f);
+    fputs ("M ", f);
+    col += 2;
+
+    if (!split)
+    {
+      col += print_macro (f, col_b - col - 4, &t2);
+      if (strlen (t2) > col_b - col)
+       t2 = "...";
+    }
+  }
+
+  col += print_macro (f, col_b - col - 1, &t2);
+  if (split)
+    fputc ('\n', f);
+  else
+    col = pad (f, col, col_b);
+
+  if (split)
+  {
+    print_macro (f, LONG_STRING, &t3);
+    fputc ('\n', f);
+  }
+  else
+  {
+    while (*t3)
+    {
+      n = COLS - col;
+
+      if (ismacro >= 0)
+      {
+       SKIPWS(t3);
+
+       if ((n = strlen (t3)) > COLS - col)
+       {
+         n = COLS - col;
+         for (col_a = n; col_a > 0 && t3[col_a] != ' '; col_a--) ;
+         if (col_a)
+           n = col_a;
+       }
+      }
+
+      print_macro (f, n, &t3);
+
+      if (*t3)
+      {
+        if (strcmp (Pager, "builtin"))
+       {
+         fputc ('\n', f);
+         n = 0;
+       }
+       else
+       {
+         n += col - COLS;
+         if (option (OPTMARKERS))
+           ++n;
+       }
+       col = pad (f, n, col_b);
+      }
+    }
+  }
+
+  fputc ('\n', f);
 }
 
 static void dump_menu (FILE *f, int menu)
@@ -140,7 +252,6 @@ static void dump_menu (FILE *f, int menu)
   struct keymap_t *map;
   struct binding_t *b;
   char buf[SHORT_STRING];
-  int col;
 
   /* browse through the keymap table */
   for (map = Keymaps[menu]; map; map = map->next)
@@ -148,41 +259,18 @@ static void dump_menu (FILE *f, int menu)
     if (map->op != OP_NULL)
     {
       km_expand_key (buf, sizeof (buf), map);
-      fputs (buf, f);
-      col = pad (f, 12, strlen (buf));
 
       if (map->op == OP_MACRO)
       {
        if (map->descr == NULL)
-       {
-         fputs ("macro ", f);
-         col = pad (f, 35, col + 6);
-         print_macro (f, COLS - col, map->macro);
-       }
-       else
-       {
-         fputs ("macro: ", f);
-         col += 7;
-         if (strlen (map->macro) < (34 - col))
-         {
-           col += print_macro (f, 34 - col, map->macro);
-           col = pad (f, 35, col);
-         }
-         else
-         {
-           if (col < 31)
-             col += print_macro (f, 31 - col, map->macro);
-           fputs ("... ", f);
-           col += 4;
-         }
-         print_macro (f, COLS - col, map->descr);
-       }
-       fputc ('\n', f);
+         format_line (f, -1, buf, "macro", map->macro);
+        else
+         format_line (f, 1, buf, map->macro, map->descr);
       }
       else
       {
        b = help_lookupFunction (map->op, menu);
-       fprintf (f, "%-22s %s\n", b ? b->name : "UNKNOWN",
+       format_line (f, 0, buf, b ? b->name : "UNKNOWN",
              b ? _(HelpStrings[b->op]) : _("ERROR: please report this bug"));
       }
     }
@@ -208,7 +296,7 @@ static void dump_unbound (FILE *f,
   {
     if (! is_bound (map, funcs[i].op) &&
        (!aux || ! is_bound (aux, funcs[i].op)))
-      fprintf (f, "%-35s%s\n", funcs[i].name, _(HelpStrings[funcs[i].op]));
+      format_line (f, 0, funcs[i].name, "", _(HelpStrings[funcs[i].op]));
   }
 }
 
@@ -221,32 +309,39 @@ void mutt_help (int menu)
   struct binding_t *funcs;
 
   mutt_mktemp (t);
-  if ((f = safe_fopen (t, "w")) == NULL)
-  {
-    mutt_perror (t);
-    return;
-  }
 
   funcs = km_get_table (menu);
   desc = mutt_getnamebyvalue (menu, Menus);
   if (!desc)
     desc = _("<UNKNOWN>");
   
-  dump_menu (f, menu);
-  if (menu != MENU_EDITOR && menu != MENU_PAGER)
-  {
-    fputs (_("\nGeneric bindings:\n\n"), f);
-    dump_menu (f, MENU_GENERIC);
+  do {
+    if ((f = safe_fopen (t, "w")) == NULL)
+    {
+      mutt_perror (t);
+      return;
+    }
+  
+    dump_menu (f, menu);
+    if (menu != MENU_EDITOR && menu != MENU_PAGER)
+    {
+      fputs (_("\nGeneric bindings:\n\n"), f);
+      dump_menu (f, MENU_GENERIC);
+    }
+  
+    fputs (_("\nUnbound functions:\n\n"), f);
+    if (funcs)
+      dump_unbound (f, funcs, Keymaps[menu], NULL);
+    if (menu != MENU_PAGER)
+      dump_unbound (f, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]);
+  
+    fclose (f);
+  
+    snprintf (buf, sizeof (buf), _("Help for %s"), desc);
   }
-
-  fputs (_("\nUnbound functions:\n\n"), f);
-  if (funcs)
-    dump_unbound (f, funcs, Keymaps[menu], NULL);
-  if (menu != MENU_PAGER)
-    dump_unbound (f, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]);
-
-  fclose (f);
-
-  snprintf (buf, sizeof (buf), _("Help for %s"), desc);
-  mutt_do_pager (buf, t, 0, NULL);
+  while
+    (mutt_do_pager (buf, t,
+                   M_PAGER_RETWINCH | M_PAGER_MARKER | M_PAGER_NSKIP,
+                   NULL)
+     == OP_REFORMAT_WINCH);
 }
index a58b699f64bb1dd297f9a3afaa964f23ed21418f..91bd2a69fc73b41a146d122386aa4f5b89689862 100644 (file)
--- a/keymap.c
+++ b/keymap.c
@@ -343,7 +343,24 @@ int km_dokey (int menu)
 
   FOREVER
   {
+/* ncurses doesn't return on resized screen when timeout is set to zero */
+#if !defined (USE_SLANG_CURSES) && defined (HAVE_RESIZETERM)
+    if (menu == MENU_MAIN || menu == MENU_PAGER)
+      timeout (menu == MENU_MAIN && Timeout > 0 ? Timeout * 1000 : INT_MAX);
+#else
+    if (menu == MENU_MAIN && Timeout > 0)
+      timeout (Timeout * 1000); /* milliseconds */
+#endif
+
     tmp = mutt_getch();
+
+#if !defined (USE_SLANG_CURSES) && defined (HAVE_RESIZETERM)
+    if (menu == MENU_MAIN || menu == MENU_PAGER)
+#else
+    if (menu == MENU_MAIN && Timeout > 0)
+#endif
+      timeout (-1); /* restore blocking operation */
+
     LastKey = tmp.ch;
     if (LastKey == -1)
       return -1;
index 10419ea0a6734d68292e9261548628f6df65c90f..0a480aef92aeddbfaafa0f781a081c1e7b7112e4 100644 (file)
@@ -31,6 +31,7 @@
 #define REDRAW_STATUS          (1<<4)
 #define REDRAW_FULL            (1<<5)
 #define REDRAW_BODY            (1<<6)
+#define REDRAW_SIGWINCH                (1<<7)
 
 #define M_MODEFMT "-- Mutt: %s"
 
diff --git a/pager.c b/pager.c
index 0de5232265e7ff2e0810a1427dde2274e56fe298..7fa7130122bbe54565c298ddf993cb78dd6293a6 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -47,14 +47,6 @@ static const char rcsid[]="$Id$";
 #include <stdlib.h>
 #include <string.h>
 
-#define M_NOSHOW       0
-#define M_SHOWFLAT     (1 << 0)
-#define M_SHOWCOLOR    (1 << 1)
-#define M_HIDE         (1 << 2)
-#define M_SEARCH       (1 << 3)
-#define M_TYPES                (1 << 4)
-#define M_SHOW         (M_SHOWCOLOR | M_SHOWFLAT)
-
 #define ISHEADER(x) ((x) == MT_COLOR_HEADER || (x) == MT_COLOR_HDEFAULT)
 
 #define IsAttach(x) (x && (x)->bdy)
@@ -126,6 +118,14 @@ typedef struct _ansi_attr {
 
 static short InHelp = 0;
 
+#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
+static struct resize {
+  int line;
+  int SearchCompiled;
+  int SearchBack;
+} *Resize = NULL;
+#endif
+
 #define NumSigLines 4
 
 static int check_sig (const char *s, struct line_t *info, int n)
@@ -955,12 +955,14 @@ static int grok_ansi(unsigned char *buf, int pos, ansi_attr *a)
 
 /*
  * Args:
- *     flags   M_NOSHOW, don't show characters
- *             M_SHOWFLAT, show characters (used for displaying help)
+ *     flags   M_SHOWFLAT, show characters (used for displaying help)
  *             M_SHOWCOLOR, show characters in color
+ *                     otherwise don't show characters
  *             M_HIDE, don't show quoted text
  *             M_SEARCH, resolve search patterns
  *             M_TYPES, compute line's type
+ *             M_PAGER_NSKIP, keeps leading whitespace
+ *             M_PAGER_MARKER, eventually show markers
  *
  * Return values:
  *     -1      EOF was reached
@@ -1022,7 +1024,7 @@ display_line (FILE *f, long *last_pos, struct line_t **lineInfo, int n,
 
     /* this also prevents searching through the hidden lines */
     if ((flags & M_HIDE) && (*lineInfo)[n].type == MT_COLOR_QUOTED)
-      flags = M_NOSHOW;
+      flags = 0; /* M_NOSHOW */
   }
 
   /* At this point, (*lineInfo[n]).quote may still be undefined. We 
@@ -1082,12 +1084,12 @@ display_line (FILE *f, long *last_pos, struct line_t **lineInfo, int n,
   if (!(flags & M_SHOW) && (*lineInfo)[n+1].offset > 0)
   {
     /* we've already scanned this line, so just exit */
-    return 0;
+    return (0);
   }
   if ((flags & M_SHOWCOLOR) && *force_redraw && (*lineInfo)[n+1].offset > 0)
   {
     /* no need to try to display this line... */
-    return 1; /* fake display */
+    return (1); /* fake display */
   }
 
   if ((b_read = fill_buffer (f, last_pos, (*lineInfo)[n].offset, buf, fmt, 
@@ -1178,9 +1180,10 @@ display_line (FILE *f, long *last_pos, struct line_t **lineInfo, int n,
       else
        buf_ptr = buf + cnt; /* a very long word... */
     }
-    /* skip leading blanks on the next line too */
-    while (*buf_ptr == ' ' || *buf_ptr == '\t') 
-      buf_ptr++;
+    if (!(flags & M_PAGER_NSKIP))
+      /* skip leading blanks on the next line too */
+      while (*buf_ptr == ' ' || *buf_ptr == '\t') 
+       buf_ptr++;
   }
 
   if (*buf_ptr == '\r')
@@ -1255,7 +1258,8 @@ display_line (FILE *f, long *last_pos, struct line_t **lineInfo, int n,
 
     if (c == '\t')
     {
-      if ((flags & (M_SHOWCOLOR | M_SEARCH)) || last_special || a.attr)
+      if ((flags & (M_SHOWCOLOR | M_SEARCH | M_PAGER_MARKER)) || last_special
+         || a.attr)
       {
        resolve_color (*lineInfo, n, vch, flags, special, &a);
        if (!special)
@@ -1271,8 +1275,8 @@ display_line (FILE *f, long *last_pos, struct line_t **lineInfo, int n,
     }
     else if (IsPrint (c))
     {
-      if ((flags & (M_SHOWCOLOR | M_SEARCH)) || special || last_special 
-         || a.attr)
+      if ((flags & (M_SHOWCOLOR | M_SEARCH | M_PAGER_MARKER)) || special
+         || last_special || a.attr)
        resolve_color (*lineInfo, n, vch, flags, special, &a);
       if (!special)
        last_special = 0;
@@ -1284,7 +1288,8 @@ display_line (FILE *f, long *last_pos, struct line_t **lineInfo, int n,
     {
       if ((c != '\r' && c !='\n') || (buf[ch+1] != '\n' && buf[ch+1] != '\0'))
       {
-       if ((flags & (M_SHOWCOLOR | M_SEARCH)) || last_special || a.attr)
+       if ((flags & (M_SHOWCOLOR | M_SEARCH | M_PAGER_MARKER)) || last_special
+           || a.attr)
        {
          resolve_color (*lineInfo, n, vch, flags, special, &a);
          if (!special)
@@ -1298,7 +1303,8 @@ display_line (FILE *f, long *last_pos, struct line_t **lineInfo, int n,
     }
     else
     {
-      if ((flags & (M_SHOWCOLOR | M_SEARCH)) || last_special || a.attr)
+      if ((flags & (M_SHOWCOLOR | M_SEARCH | M_PAGER_MARKER)) || last_special
+         || a.attr)
       {
        resolve_color (*lineInfo, n, vch, flags, special, &a);
        if (!special)
@@ -1377,7 +1383,7 @@ static struct mapping_t PagerHelpExtra[] = {
    is there so that we can do operations on the current message without the
    need to pop back out to the main-menu.  */
 int 
-mutt_pager (const char *banner, const char *fname, int do_color, pager_t *extra)
+mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
 {
   static char searchbuf[STRING];
   char buffer[LONG_STRING];
@@ -1395,7 +1401,7 @@ mutt_pager (const char *banner, const char *fname, int do_color, pager_t *extra)
   struct stat sb;
   regex_t SearchRE;
   int SearchCompiled = 0, SearchFlag = 0, SearchBack = 0;
-  int has_types = (IsHeader(extra) || do_color); /* main message or rfc822 attachment */
+  int has_types = (IsHeader(extra) || (flags & M_SHOWCOLOR)) ? M_TYPES : 0; /* main message or rfc822 attachment */
 
   int bodyoffset = 1;                  /* offset of first line of real text */
   int statusoffset = 0;                /* offset for the status bar */
@@ -1409,7 +1415,8 @@ mutt_pager (const char *banner, const char *fname, int do_color, pager_t *extra)
   int old_PagerIndexLines;             /* some people want to resize it
                                         * while inside the pager... */
 
-  do_color = do_color ? M_SHOWCOLOR : M_SHOWFLAT;
+  if (!(flags & M_SHOWCOLOR))
+    flags |= M_SHOWFLAT;
 
   if ((fp = fopen (fname, "r")) == NULL)
   {
@@ -1503,6 +1510,23 @@ mutt_pager (const char *banner, const char *fname, int do_color, pager_t *extra)
        SETCOLOR (MT_COLOR_NORMAL);
       }
 
+#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
+      if (Resize != NULL)
+      {
+       if ((SearchCompiled = Resize->SearchCompiled))
+       {
+         REGCOMP
+           (&SearchRE, searchbuf, REG_NEWLINE | mutt_which_case (searchbuf));
+         SearchFlag = M_SEARCH;
+         SearchBack = Resize->SearchBack;
+       }
+       lines = Resize->line;
+       redraw |= REDRAW_SIGWINCH;
+
+       safe_free ((void **) &Resize);
+      }
+#endif
+
       if (IsHeader (extra) && PagerIndexLines)
       {
        if (index == NULL)
@@ -1537,6 +1561,21 @@ mutt_pager (const char *banner, const char *fname, int do_color, pager_t *extra)
       mutt_show_error ();
     }
 
+    if (redraw & REDRAW_SIGWINCH)
+    {
+      i = -1;
+      j = -1;
+      while (display_line (fp, &last_pos, &lineInfo, ++i, &lastLine, &maxLine,
+            has_types | SearchFlag, &QuoteList, &q_level, &force_redraw,
+            &SearchRE) == 0)
+       if (!lineInfo[i].continuation && ++j == lines)
+       {
+         topline = i;
+         if (!SearchFlag)
+           break;
+       }
+    }
+
     if ((redraw & REDRAW_BODY) || topline != oldtopline)
     {
       do {
@@ -1548,7 +1587,8 @@ mutt_pager (const char *banner, const char *fname, int do_color, pager_t *extra)
        while (lines < bodylen && lineInfo[curline].offset <= sb.st_size - 1)
        {
          if (display_line (fp, &last_pos, &lineInfo, curline, &lastLine, 
-                           &maxLine, do_color | hideQuoted | SearchFlag, 
+                           &maxLine,
+                           (flags & M_DISPLAYFLAGS) | hideQuoted | SearchFlag, 
                            &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
            lines++;
          curline++;
@@ -1626,33 +1666,48 @@ mutt_pager (const char *banner, const char *fname, int do_color, pager_t *extra)
     {
       mutt_resize_screen ();
 
-      for (i = 0; i < maxLine; i++)
-      {
-       lineInfo[i].offset = 0;
-       lineInfo[i].type = -1;
-       lineInfo[i].continuation = 0;
-       lineInfo[i].chunks = 0;
-       lineInfo[i].search_cnt = -1;
-       lineInfo[i].quote = NULL;
-
-       safe_realloc ((void **)&(lineInfo[i].syntax), sizeof (struct syntax_t));
-       if (SearchCompiled && lineInfo[i].search)
-           safe_free ((void **) &(lineInfo[i].search));
-      }
+      /* Store current position. */
+      lines = -1;
+      for (i = 0; i <= topline; i++)
+       if (!lineInfo[i].continuation)
+         lines++;
 
-      if (SearchCompiled)
+      if (flags & M_PAGER_RETWINCH)
       {
-       regfree (&SearchRE);
-       SearchCompiled = 0;
-       SearchFlag = 0;
+       Resize = safe_malloc (sizeof (struct resize));
+
+       Resize->line = lines;
+       Resize->SearchCompiled = SearchCompiled;
+       Resize->SearchBack = SearchBack;
+
+       ch = -1;
+       rc = OP_REFORMAT_WINCH;
       }
+      else
+      {
+       for (i = 0; i < maxLine; i++)
+       {
+         lineInfo[i].offset = 0;
+         lineInfo[i].type = -1;
+         lineInfo[i].continuation = 0;
+         lineInfo[i].chunks = 0;
+         lineInfo[i].search_cnt = -1;
+         lineInfo[i].quote = NULL;
+
+         safe_realloc ((void **)&(lineInfo[i].syntax),
+                       sizeof (struct syntax_t));
+         if (SearchCompiled && lineInfo[i].search)
+             safe_free ((void **) &(lineInfo[i].search));
+       }
 
-      lastLine = 0;
-      topline = 0;
+       lastLine = 0;
+       topline = 0;
+
+       redraw = REDRAW_FULL | REDRAW_SIGWINCH;
+       ch = 0;
+      }
 
-      redraw = REDRAW_FULL;
       Signals &= ~S_SIGWINCH;
-      ch = 0;
       continue;
     }
 #endif
@@ -1902,7 +1957,7 @@ mutt_pager (const char *banner, const char *fname, int do_color, pager_t *extra)
       case OP_PAGER_HIDE_QUOTED:
        if (has_types)
        {
-         hideQuoted = hideQuoted ? 0 : M_HIDE;
+         hideQuoted ^= M_HIDE;
          if (hideQuoted && lineInfo[topline].type == MT_COLOR_QUOTED)
            topline = upNLines (1, lineInfo, topline, hideQuoted);
          else
@@ -1951,7 +2006,7 @@ mutt_pager (const char *banner, const char *fname, int do_color, pager_t *extra)
          i = curline;
          /* make sure the types are defined to the end of file */
          while (display_line (fp, &last_pos, &lineInfo, i, &lastLine, 
-                               &maxLine, (has_types ? M_TYPES : M_NOSHOW)
+                               &maxLine, has_types
                                &QuoteList, &q_level, &force_redraw,
                                &SearchRE) == 0)
            i++;
@@ -2053,6 +2108,13 @@ mutt_pager (const char *banner, const char *fname, int do_color, pager_t *extra)
        if (option (OPTWRAP) != old_smart_wrap || 
            option (OPTMARKERS) != old_markers)
        {
+         if (flags & M_PAGER_RETWINCH)
+         {
+           ch = -1;
+           rc = OP_REFORMAT_WINCH;
+           continue;
+         }
+
          /* count the real lines above */
          j = 0;
          for (i = 0; i <= topline; i++)
diff --git a/pager.h b/pager.h
index 02f529bbcaf5774f1161b7a26bc53e341183abec..5801232a0c7a938e650853bce1e3b6d70a7372f5 100644 (file)
--- a/pager.h
+++ b/pager.h
  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */ 
 
+/* dynamic internal flags */
+#define M_SHOWFLAT     (1<<0)
+#define M_SHOWCOLOR    (1<<1)
+#define M_HIDE         (1<<2)
+#define M_SEARCH       (1<<3)
+#define M_TYPES                (1<<4)
+#define M_SHOW         (M_SHOWCOLOR | M_SHOWFLAT)
+
+/* exported flags for mutt_(do_)?pager */
+#define M_PAGER_NSKIP          (1<<5)  /* preserve whitespace with smartwrap */
+#define M_PAGER_MARKER         (1<<6)  /* use markers if option is set */
+#define M_PAGER_RETWINCH       (1<<7)  /* need reformatting on SIGWINCH */
+#define M_PAGER_MESSAGE                (M_SHOWCOLOR | M_PAGER_MARKER)
+
+#define M_DISPLAYFLAGS (M_SHOW | M_PAGER_NSKIP | M_PAGER_MARKER)
+
 typedef struct
 {
   CONTEXT *ctx;        /* current mailbox */