]> granicus.if.org Git - neomutt/commitdiff
listeners
authorRichard Russon <rich@flatcap.org>
Thu, 14 Jun 2018 14:23:56 +0000 (15:23 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 23 Jul 2018 15:00:57 +0000 (16:00 +0100)
curs_main.c
main.c
menu.c
menu.h
mutt/history.h
mutt_history.c
mutt_logging.c
protos.h

index f2dfe8b3b2d61d72eed3719d4969fe9cc15601aa..6d8a32e2946fbe8638093367843716a2699c33ff 100644 (file)
@@ -3395,3 +3395,42 @@ void mutt_set_header_color(struct Context *ctx, struct Header *curhdr)
   }
   curhdr->pair = ColorDefs[MT_COLOR_NORMAL];
 }
+
+/**
+ * mutt_reply_listener - Listen for config changes to "reply_regex"
+ * @param cs   Config items
+ * @param he   HashElem representing config item
+ * @param name Name of the config item
+ * @param ev   Event type, e.g. #CE_SET
+ * @retval true Continue notifying
+ */
+bool mutt_reply_listener(const struct ConfigSet *cs, struct HashElem *he,
+                         const char *name, enum ConfigEvent ev)
+{
+  if (mutt_str_strcmp(name, "reply_regex") != 0)
+    return true;
+
+  if (!Context)
+    return true;
+
+  regmatch_t pmatch[1];
+
+  for (int i = 0; i < Context->msgcount; i++)
+  {
+    struct Envelope *e = Context->hdrs[i]->env;
+    if (!e || !e->subject)
+      continue;
+
+    if (ReplyRegex && ReplyRegex->regex &&
+        (regexec(ReplyRegex->regex, e->subject, 1, pmatch, 0) == 0))
+    {
+      e->real_subj = e->subject + pmatch[0].rm_eo;
+      continue;
+    }
+
+    e->real_subj = e->subject;
+  }
+
+  OptResortInit = true; /* trigger a redraw of the index */
+  return true;
+}
diff --git a/main.c b/main.c
index 91e64f2f6e707cf27a8ef5914c476b6fe930db44..dbe41e05dfd04a326ae50609019281533433af14 100644 (file)
--- a/main.c
+++ b/main.c
@@ -56,7 +56,9 @@
 #include "hook.h"
 #include "keymap.h"
 #include "mailbox.h"
+#include "menu.h"
 #include "mutt_curses.h"
+#include "mutt_history.h"
 #include "mutt_logging.h"
 #include "mutt_window.h"
 #include "muttlib.h"
@@ -737,6 +739,11 @@ int main(int argc, char *argv[], char *envp[])
     goto main_ok; // TEST22: neomutt -B
   }
 
+  cs_add_listener(Config, mutt_hist_listener);
+  cs_add_listener(Config, mutt_log_listener);
+  cs_add_listener(Config, mutt_menu_listener);
+  cs_add_listener(Config, mutt_reply_listener);
+
   if (sendflags & SEND_POSTPONED)
   {
     if (!OptNoCurses)
diff --git a/menu.c b/menu.c
index ab305c5fc200733ef3d6e96747fb63f462b1b53f..88a88fd3260f33918bfb2ddec677c582c7e259c8 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -1571,3 +1571,51 @@ int mutt_menu_loop(struct Menu *menu)
   }
   /* not reached */
 }
+
+/**
+ * mutt_menu_listener - Listen for config changes affecting the menu
+ * @param cs   Config items
+ * @param he   HashElem representing config item
+ * @param name Name of the config item
+ * @param ev   Event type, e.g. #CE_SET
+ * @retval true Continue notifying
+ */
+bool mutt_menu_listener(const struct ConfigSet *cs, struct HashElem *he,
+                        const char *name, enum ConfigEvent ev)
+{
+  const struct ConfigDef *cdef = he->data;
+  int flags = cdef->flags;
+
+  if (flags == 0)
+    return true;
+
+  if (flags & R_INDEX)
+    mutt_menu_set_redraw_full(MENU_MAIN);
+  if (flags & R_PAGER)
+    mutt_menu_set_redraw_full(MENU_PAGER);
+  if (flags & R_PAGER_FLOW)
+  {
+    mutt_menu_set_redraw_full(MENU_PAGER);
+    mutt_menu_set_redraw(MENU_PAGER, REDRAW_FLOW);
+  }
+
+  if (flags & R_RESORT_SUB)
+    OptSortSubthreads = true;
+  if (flags & R_RESORT)
+    OptNeedResort = true;
+  if (flags & R_RESORT_INIT)
+    OptResortInit = true;
+  if (flags & R_TREE)
+    OptRedrawTree = true;
+
+  if (flags & R_REFLOW)
+    mutt_window_reflow();
+#ifdef USE_SIDEBAR
+  if (flags & R_SIDEBAR)
+    mutt_menu_set_current_redraw(REDRAW_SIDEBAR);
+#endif
+  if (flags & R_MENU)
+    mutt_menu_set_current_redraw_full();
+
+  return true;
+}
diff --git a/menu.h b/menu.h
index 73ac94130715b4da669f71ddb8645bfc9cb65888..2f9fbe5076ece7a26f885750326163f21a0508e2 100644 (file)
--- a/menu.h
+++ b/menu.h
 #include <regex.h>
 #include <stdbool.h>
 #include <stdio.h>
+#include "config/lib.h"
 
 /* These Config Variables are only used in menu.c */
 extern short MenuContext;
 extern bool  MenuMoveOff; /**< allow menu to scroll past last entry */
 extern bool  MenuScroll;  /**< scroll menu instead of implicit next-page */
 
+struct ConfigSet;
+struct HashElem;
+enum ConfigEvent;
+
 #define REDRAW_INDEX          (1 << 0)
 #define REDRAW_MOTION         (1 << 1)
 #define REDRAW_MOTION_RESYNCH (1 << 2)
@@ -136,4 +141,6 @@ void         mutt_menu_set_current_redraw(int redraw);
 void         mutt_menu_set_redraw_full(int menu_type);
 void         mutt_menu_set_redraw(int menu_type, int redraw);
 
+bool mutt_menu_listener(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+
 #endif /* MUTT_MENU_H */
index 0c83d51db4d89b1d9f57b61854f58ace8ffd8eb9..e36556c6b7e10e229a2c7cd4e80668b3597b5444 100644 (file)
@@ -24,6 +24,8 @@
 #define _MUTT_HISTORY_H
 
 #include <stdbool.h>
+#include <stdio.h>
+#include "config/lib.h"
 
 /* These Config Variables are only used in mutt/history.c */
 extern short History;
@@ -58,4 +60,6 @@ void  mutt_hist_reset_state(enum HistoryClass hclass);
 void  mutt_hist_save_scratch(enum HistoryClass hclass, const char *str);
 int   mutt_hist_search(char *search_buf, enum HistoryClass hclass, char **matches);
 
+bool mutt_hist_listener(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+
 #endif /* _MUTT_HISTORY_H */
index 55e1853e96264157423e04755108a8d842a59324..a2fbad335f0878368f16b327c59b4eec1105a1db 100644 (file)
@@ -155,3 +155,21 @@ void mutt_hist_complete(char *buf, size_t buflen, enum HistoryClass hclass)
   }
   FREE(&matches);
 }
+
+/**
+ * mutt_hist_listener - Listen for config changes affecting the history
+ * @param cs   Config items
+ * @param he   HashElem representing config item
+ * @param name Name of the config item
+ * @param ev   Event type, e.g. #CE_SET
+ * @retval true Continue notifying
+ */
+bool mutt_hist_listener(const struct ConfigSet *cs, struct HashElem *he,
+                        const char *name, enum ConfigEvent ev)
+{
+  if (mutt_str_strcmp(name, "history") != 0)
+    return true;
+
+  mutt_hist_init();
+  return true;
+}
index 71ef5a73c7134c13ed0f337e25b0ba17202e2b83..977a407bc24b577901cd9adaae5b3cc7a3072c59 100644 (file)
@@ -340,3 +340,22 @@ int level_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
 
   return CSR_SUCCESS;
 }
+
+/**
+ * mutt_log_listener - Listen for config changes affecting the log file
+ * @param cs   Config items
+ * @param he   HashElem representing config item
+ * @param name Name of the config item
+ * @param ev   Event type, e.g. #CE_SET
+ * @retval true Continue notifying
+ */
+bool mutt_log_listener(const struct ConfigSet *cs, struct HashElem *he,
+                       const char *name, enum ConfigEvent ev)
+{
+  if (mutt_str_strcmp(name, "debug_file") == 0)
+    mutt_log_set_file(DebugFile, true);
+  else if (mutt_str_strcmp(name, "debug_level") == 0)
+    mutt_log_set_level(DebugLevel, true);
+
+  return true;
+}
index 4d9f0d586cad8e4be5ea34bd53e52e98da50b731..5b4aa6df2a58f680563dfc8c1f251d1b564e00b3 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -27,6 +27,8 @@
 #include <stddef.h>
 #include <stdbool.h>
 #include <stdio.h>
+#include <time.h>
+#include "config/lib.h"
 
 struct Context;
 struct EnterState;
@@ -71,4 +73,7 @@ int url_parse_mailto(struct Envelope *e, char **body, const char *src);
 int wcscasecmp(const wchar_t *a, const wchar_t *b);
 #endif
 
+bool mutt_reply_listener(const struct ConfigSet *cs, struct HashElem *he,
+                         const char *name, enum ConfigEvent ev);
+
 #endif /* _MUTT_PROTOS_H */