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

tag-push and tag-pop for tag-prefixing macros



Folks,

Mr Rachinsky asked about tag-prefixing macros; I decided that what was
needed was <tag-push> and <tag-pop> and that this would be a good way to
explore more of mutt's code.

The attached patch implements these two directives and it's known to
work for the index menu; the two new directives can be used as:
 macro index r "<tag-push><enter-command>set from=\"Phil Test 
<mutt-users+test@xxxxxxxxxxxxxxxxx>\"\n<tag-pop><reply>"

the patch is not quite ready for prime-time, because I got confused over
the menu-handling stuff and which file has jurisdiction over which
areas.

The patch adds an "#if 0" block to menu.c, because that's where I tried
going first; I don't know if this might be needed in some sub-menus or
how tagging is supposed to work in sub-menus, etc.

I welcome correction and pointers so that I can improve the patch.  In
particular, information about where tag-prefix is supposed to "make
sense" and where not, and where a better place to put the logic might
be; my impression, perhaps badly formed (I'm about to quit for the
night) is that the menu.c code is newer and functionality has been
migrated to it, but that this is ongoing?  Or am I completely missing a
nuance (very possible).

Once the patch has been refined by feedback, I'll add some documentation
to go with it.

Thanks,
-- 
I am keeping international relations on a peaceable footing.
You are biding your time before acting.
He is coddling tyrants.
 -- Roger BW on topic of verb conjugation
diff -urp mutt/OPS mutt-workingcopy/OPS
--- mutt/OPS    2005-07-24 18:51:38.000000000 +0200
+++ mutt-workingcopy/OPS        2006-01-15 18:40:04.000000000 +0100
@@ -161,6 +161,8 @@ OP_SORT_REVERSE "sort messages in revers
 OP_TAG "tag the current entry"
 OP_TAG_PREFIX "apply next function to tagged messages"
 OP_TAG_PREFIX_COND "apply next function ONLY to tagged messages"
+OP_TAG_POP "restore tag-prefix state saved with tag-push"
+OP_TAG_PUSH "remember if we should be applied to tagged messages"
 OP_TAG_SUBTHREAD "tag the current subthread"
 OP_TAG_THREAD "tag the current thread"
 OP_TOGGLE_NEW "toggle a message's 'new' flag"
diff -urp mutt/curs_main.c mutt-workingcopy/curs_main.c
--- mutt/curs_main.c    2005-11-24 13:50:27.000000000 +0100
+++ mutt-workingcopy/curs_main.c        2006-01-15 20:03:41.000000000 +0100
@@ -616,6 +616,21 @@ int mutt_index_menu (void)
       
       mutt_curs_set (1);
       
+      /* tag-prefix state is remembered in this function and reset every time,
+       * so we need to grab more input if we're in tag-prefix state
+       */
+
+      if (op == OP_TAG_POP)
+      {
+       if (menu->tag_pushed)
+         op = OP_TAG_PREFIX;
+       else
+       {
+         op = OP_NULL;
+         continue;
+       }
+      }
+
       /* special handling for the tag-prefix function */
       if (op == OP_TAG_PREFIX)
       {
@@ -693,9 +708,17 @@ int mutt_index_menu (void)
       mutt_curs_set (1);       /* fallback from the pager */
     }
 
+    dprint(6, (debugfile, " tag=%d\n", tag));
+
     switch (op)
     {
 
+      /* one final tag-modifying command */
+      case OP_TAG_PUSH:
+       dprint(6, (debugfile, "mutt_index_menu[%d]: TAG_PUSH: tag=%d 
tagprefix=%d tag_pushed=%d\n", __LINE__, tag, menu->tagprefix, 
menu->tag_pushed));
+       menu->tag_pushed = tag;
+       break;
+
       /* ----------------------------------------------------------------------
        * movement commands
        */
diff -urp mutt/functions.h mutt-workingcopy/functions.h
--- mutt/functions.h    2005-09-17 22:46:10.000000000 +0200
+++ mutt-workingcopy/functions.h        2006-01-15 18:37:37.000000000 +0100
@@ -52,6 +52,8 @@ struct binding_t OpGeneric[] = {
   { "help",            OP_HELP,                "?" },
   { "tag-prefix",      OP_TAG_PREFIX,          ";" },
   { "tag-prefix-cond", OP_TAG_PREFIX_COND,     NULL },
+  { "tag-push",                OP_TAG_PUSH,            NULL },
+  { "tag-pop",         OP_TAG_POP,             NULL },
   { "end-cond",                OP_END_COND,            NULL },
   { "shell-escape",    OP_SHELL_ESCAPE,        "!" },
   { "select-entry",    OP_GENERIC_SELECT_ENTRY,M_ENTER_S },
diff -urp mutt/menu.c mutt-workingcopy/menu.c
--- mutt/menu.c 2005-11-17 19:40:50.000000000 +0100
+++ mutt-workingcopy/menu.c     2006-01-15 19:42:26.000000000 +0100
@@ -1044,6 +1044,16 @@ int mutt_menuLoop (MUTTMENU *menu)
          mutt_error _("Tagging is not supported.");
        break;
 
+#if 0
+      case OP_TAG_PUSH:
+       menu->tag_pushed = menu->tagprefix;
+       break;
+
+      case OP_TAG_POP:
+       menu->tagprefix = menu->tag_pushed;
+       break;
+#endif
+
       case OP_SHELL_ESCAPE:
        mutt_shell_escape ();
        MAYBE_REDRAW (menu->redraw);
diff -urp mutt/mutt_menu.h mutt-workingcopy/mutt_menu.h
--- mutt/mutt_menu.h    2005-09-17 22:46:10.000000000 +0200
+++ mutt-workingcopy/mutt_menu.h        2006-01-15 19:10:23.000000000 +0100
@@ -48,7 +48,8 @@ typedef struct menu_t
   int menu;    /* menu definition for keymap entries. */
   int offset;  /* which screen row to start the index */
   int pagelen; /* number of entries per screen */
-  int tagprefix;
+  int tagprefix;       /* are we in a tag-prefix state */
+  int tag_pushed;      /* saved copy of tagprefix */
 
   /* Setting dialog != NULL overrides normal menu behaviour. 
    * In dialog mode menubar is hidden and prompt keys are checked before
--- mutt/PATCHES~    Tue Nov  6 19:59:33 2001
+++ mutt/PATCHES     Tue Nov  6 19:59:42 2001
@@ -1,0 +1 @@
+patch-1.5.11.pdp.tagsave.1