]> granicus.if.org Git - neomutt/commitdiff
eliminate MuttIndexWindow from deep functions
authorRichard Russon <rich@flatcap.org>
Mon, 21 Oct 2019 10:45:27 +0000 (11:45 +0100)
committerRichard Russon <rich@flatcap.org>
Wed, 23 Oct 2019 10:37:44 +0000 (11:37 +0100)
These functions needed an extra parameter:

- `mutt_help()`
- `dump_unbound()`
- `dump_menu()`
- `format_line()`

These functions used the new `State.wraplen` member:

- `quote_width()`
- `text_enriched_handler()`

enriched.c
help.c
index.c
menu.c
pager.c
protos.h
rfc3676.c

index 6cf6ad043044ff39134167235ab8975f733aed9d..abd715ba895d5a401cf04117ddc38744f7158810 100644 (file)
@@ -477,10 +477,9 @@ int text_enriched_handler(struct Body *a, struct State *s)
   wchar_t tag[1024 + 1];
 
   stte.s = s;
-  stte.wrap_margin =
-      ((s->flags & MUTT_DISPLAY) ?
-           (MuttIndexWindow->cols - 4) :
-           ((MuttIndexWindow->cols - 4) < 72) ? (MuttIndexWindow->cols - 4) : 72);
+  stte.wrap_margin = ((s->flags & MUTT_DISPLAY) ?
+                          (s->wraplen - 4) :
+                          ((s->wraplen - 4) < 72) ? (s->wraplen - 4) : 72);
   stte.line_max = stte.wrap_margin * 4;
   stte.line = mutt_mem_calloc((stte.line_max + 1), sizeof(wchar_t));
   stte.param = mutt_mem_calloc(256, sizeof(wchar_t));
diff --git a/help.c b/help.c
index 1df2e77d653b917461fe8b4878195bfaa7b88b48..a3b12115f3efe3cedace83afefe0a5a2fd47b685 100644 (file)
--- a/help.c
+++ b/help.c
@@ -274,6 +274,7 @@ static int pad(FILE *fp, int col, int i)
  * @param t1      Text part 1
  * @param t2      Text part 2
  * @param t3      Text part 3
+ * @param wraplen Width to wrap to
  *
  * Assemble the three columns of text.
  *
@@ -282,7 +283,8 @@ static int pad(FILE *fp, int col, int i)
  * *  0 : Non-macro
  * * -1 : Macro with no description
  */
-static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, const char *t3)
+static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2,
+                        const char *t3, int wraplen)
 {
   int col;
   int col_b;
@@ -290,7 +292,7 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, c
   fputs(t1, fp);
 
   /* don't try to press string into one line with less than 40 characters. */
-  bool split = (MuttIndexWindow->cols < 40);
+  bool split = (wraplen < 40);
   if (split)
   {
     col = 0;
@@ -299,9 +301,8 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, c
   }
   else
   {
-    const int col_a =
-        (MuttIndexWindow->cols > 83) ? (MuttIndexWindow->cols - 32) >> 2 : 12;
-    col_b = (MuttIndexWindow->cols > 49) ? (MuttIndexWindow->cols - 10) >> 1 : 19;
+    const int col_a = (wraplen > 83) ? (wraplen - 32) >> 2 : 12;
+    col_b = (wraplen > 49) ? (wraplen - 10) >> 1 : 19;
     col = pad(fp, mutt_strwidth(t1), col_a);
   }
 
@@ -335,7 +336,7 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, c
   {
     while (*t3)
     {
-      int n = MuttIndexWindow->cols - col;
+      int n = wraplen - col;
 
       if (ismacro >= 0)
       {
@@ -354,7 +355,7 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, c
         }
         else
         {
-          n += col - MuttIndexWindow->cols;
+          n += col - wraplen;
           if (C_Markers)
             n++;
         }
@@ -368,10 +369,11 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, c
 
 /**
  * dump_menu - Write all the key bindings to a file
- * @param fp   File to write to
- * @param menu Current Menu, e.g. #MENU_PAGER
+ * @param fp      File to write to
+ * @param menu    Current Menu, e.g. #MENU_PAGER
+ * @param wraplen Width to wrap to
  */
-static void dump_menu(FILE *fp, enum MenuType menu)
+static void dump_menu(FILE *fp, enum MenuType menu, int wraplen)
 {
   struct Keymap *map = NULL;
   const struct Binding *b = NULL;
@@ -387,15 +389,15 @@ static void dump_menu(FILE *fp, enum MenuType menu)
       if (map->op == OP_MACRO)
       {
         if (map->desc)
-          format_line(fp, 1, buf, map->macro, map->desc);
+          format_line(fp, 1, buf, map->macro, map->desc, wraplen);
         else
-          format_line(fp, -1, buf, "macro", map->macro);
+          format_line(fp, -1, buf, "macro", map->macro, wraplen);
       }
       else
       {
         b = help_lookup_function(map->op, menu);
         format_line(fp, 0, buf, b ? b->name : "UNKNOWN",
-                    b ? _(HelpStrings[b->op]) : _("ERROR: please report this bug"));
+                    b ? _(HelpStrings[b->op]) : _("ERROR: please report this bug"), wraplen);
       }
     }
   }
@@ -417,26 +419,28 @@ static bool is_bound(struct Keymap *map, int op)
 
 /**
  * dump_unbound - Write out all the operations with no key bindings
- * @param fp    File to write to
- * @param funcs All the bindings for the current menu
- * @param map   First key map to consider
- * @param aux   Second key map to consider
+ * @param fp      File to write to
+ * @param funcs   All the bindings for the current menu
+ * @param map     First key map to consider
+ * @param aux     Second key map to consider
+ * @param wraplen Width to wrap to
  */
 static void dump_unbound(FILE *fp, const struct Binding *funcs,
-                         struct Keymap *map, struct Keymap *aux)
+                         struct Keymap *map, struct Keymap *aux, int wraplen)
 {
   for (int i = 0; funcs[i].name; i++)
   {
     if (!is_bound(map, funcs[i].op) && (!aux || !is_bound(aux, funcs[i].op)))
-      format_line(fp, 0, funcs[i].name, "", _(HelpStrings[funcs[i].op]));
+      format_line(fp, 0, funcs[i].name, "", _(HelpStrings[funcs[i].op]), wraplen);
   }
 }
 
 /**
  * mutt_help - Display the help menu
- * @param menu Current Menu
+ * @param menu    Current Menu
+ * @param wraplen Width to wrap to
  */
-void mutt_help(enum MenuType menu)
+void mutt_help(enum MenuType menu, int wraplen)
 {
   char buf[128];
   FILE *fp = NULL;
@@ -459,18 +463,18 @@ void mutt_help(enum MenuType menu)
       goto cleanup;
     }
 
-    dump_menu(fp, menu);
+    dump_menu(fp, menu, wraplen);
     if ((menu != MENU_EDITOR) && (menu != MENU_PAGER))
     {
       fprintf(fp, "\n%s\n\n", _("Generic bindings:"));
-      dump_menu(fp, MENU_GENERIC);
+      dump_menu(fp, MENU_GENERIC, wraplen);
     }
 
     fprintf(fp, "\n%s\n\n", _("Unbound functions:"));
     if (funcs)
-      dump_unbound(fp, funcs, Keymaps[menu], NULL);
+      dump_unbound(fp, funcs, Keymaps[menu], NULL, wraplen);
     if (menu != MENU_PAGER)
-      dump_unbound(fp, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]);
+      dump_unbound(fp, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu], wraplen);
 
     mutt_file_fclose(&fp);
 
diff --git a/index.c b/index.c
index 132fbfcb85674603b762a62208b26bb54f87a0f8..e9399268040e027a3bdff088870b71ef2391f81e 100644 (file)
--- a/index.c
+++ b/index.c
@@ -1632,7 +1632,7 @@ int mutt_index_menu(void)
       }
 
       case OP_HELP:
-        mutt_help(MENU_MAIN);
+        mutt_help(MENU_MAIN, MuttIndexWindow->cols);
         menu->redraw = REDRAW_FULL;
         break;
 
diff --git a/menu.c b/menu.c
index dc948f0038866b0fb7cdba9e79cfde35fa316b5f..d32418f385853a6b8b18b690aa6f832e783079bf 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -1573,7 +1573,7 @@ int mutt_menu_loop(struct Menu *menu)
         break;
 
       case OP_HELP:
-        mutt_help(menu->type);
+        mutt_help(menu->type, menu->indexwin->cols);
         menu->redraw = REDRAW_FULL;
         break;
 
diff --git a/pager.c b/pager.c
index c617cdc19b1d720c74960b6a4916d219b53c891f..70f6bd3b65326e07bc1e537e5b4a3eede74419a6 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -2833,7 +2833,7 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P
         if (!InHelp)
         {
           InHelp = true;
-          mutt_help(MENU_PAGER);
+          mutt_help(MENU_PAGER, MuttIndexWindow->cols);
           pager_menu->redraw = REDRAW_FULL;
           InHelp = false;
         }
index 9ad5b65bbeb787b6e16e2c20238695ac2511bcd9..58b5ea71b82b8db1444efcff5aaed77a53a11ba6 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -63,7 +63,7 @@ int mutt_ev_message(struct Mailbox *m, struct EmailList *el, enum EvMessage acti
 int mutt_system(const char *cmd);
 
 int mutt_set_xdg_path(enum XdgType type, char *buf, size_t bufsize);
-void mutt_help(enum MenuType menu);
+void mutt_help(enum MenuType menu, int wraplan);
 void mutt_make_help(char *d, size_t dlen, const char *txt, enum MenuType menu, int op);
 void mutt_set_flag_update(struct Mailbox *m, struct Email *e, int flag, bool bf, bool upd_mbox);
 #define mutt_set_flag(m, e, flag, bf) mutt_set_flag_update(m, e, flag, bf, true)
index 65186f5687fa3d2c3a0f492ecdfae27c3cd84825..325dee14d28553e448a1f0f84bffc87eae35ce65 100644 (file)
--- a/rfc3676.c
+++ b/rfc3676.c
@@ -191,7 +191,8 @@ static void flush_par(struct State *s, struct FlowedState *fst)
  */
 static int quote_width(struct State *s, int ql)
 {
-  int width = mutt_window_wrap_cols(MuttIndexWindow->cols, C_ReflowWrap);
+  const int screen_width = (s->flags & MUTT_DISPLAY) ? s->wraplen : 80;
+  int width = mutt_window_wrap_cols(screen_width, C_ReflowWrap);
   if (C_TextFlowed && (s->flags & MUTT_REPLYING))
   {
     /* When replying, force a wrap at FLOWED_MAX to comply with RFC3676