]> granicus.if.org Git - neomutt/commitdiff
Add TAB completion of tag names in <modify-labels>*
authorTim Stoakes <tim@stoakes.net>
Sat, 22 Sep 2012 07:31:54 +0000 (09:31 +0200)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 15:30:06 +0000 (16:30 +0100)
<modify-labels> and <modify-labels-then-hide> can now use TAB completion of tag
names supplied after + and -.

README.notmuch
curs_main.c
enter.c
init.c
mutt.h
protos.h

index c6a19508a3f798ce516c622f8b5cd2c505bf7f27..0822b2063d22b90d5f9a5a98ba4ed7e877991d8b 100644 (file)
@@ -87,11 +87,13 @@ notmuch support for mutt
    modify-labels:
       - add or remove notmuch tags; [+]<tag> to add, -<tag> to remove
       - default key: `
+      - note: TAB completion of tag names is available
       - example: "+AAA +BBB -CCC"
 
    modify-labels-then-hide:
       - same as <modify-labels> but message is marked by <quasi-delete>
       - not mapped to any key
+      - note: TAB completion of tag names is available
       - example (add "archive" notmuch tag and remove message from screen):
 
        macro index A "<modify-labels-then-hide>+archive -inbox\n<sync-mailbox>"
index 25341a03c549a475a8b8aea74dbb13499f2453d8..618e06de42a2105fb88f14cd2944b546be26aad5 100644 (file)
@@ -1394,7 +1394,7 @@ int mutt_index_menu (void)
        CHECK_MSGCOUNT;
         CHECK_VISIBLE;
        *buf = '\0';
-       if (mutt_get_field ("Add/remove labels: ", buf, sizeof (buf), 0) || !*buf)
+       if (mutt_get_field ("Add/remove labels: ", buf, sizeof (buf), M_NM_TAG) || !*buf)
        {
           mutt_message _("No label specified, aborting.");
           break;
diff --git a/enter.c b/enter.c
index e07a901ffadd9b84daa0b354d945598bc884fd08..e2604b9d73d1f612d175a52ddf7a1ce09fc7f853 100644 (file)
--- a/enter.c
+++ b/enter.c
@@ -640,6 +640,16 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x,
 
            replace_part (state, 0, buf);
          }
+         else if (flags & M_NM_TAG)
+         {
+           my_wcstombs (buf, buflen, state->wbuf, state->curpos);
+           i = strlen (buf);
+           if (!mutt_nm_tag_complete(buf, buflen, i, state->tabs))
+             BEEP ();
+
+           replace_part (state, 0, buf);
+         }
+
 #endif
          else
            goto self_insert;
diff --git a/init.c b/init.c
index e356ae44ce4278a77e5e5192f0b0572fae395540..edce026705dd8c02446e682b1d7583966b492281 100644 (file)
--- a/init.c
+++ b/init.c
@@ -2762,6 +2762,28 @@ int mutt_nm_query_complete (char *buffer, size_t len, int pos, int numtabs)
   return 1;
 }
 
+/* Complete the nearest "+" or "-" -prefixed string previous to pos. */
+int mutt_nm_tag_complete (char *buffer, size_t len, int pos, int numtabs)
+{
+  char *pt = buffer;
+  int spaces;
+  const char *first_plus = NULL;
+  const char *first_minus = NULL;
+
+  SKIPWS (buffer);
+  spaces = buffer - pt;
+
+  first_plus = rstrnstr((char *)buffer, pos, "+");
+  first_minus = rstrnstr((char *)buffer, pos, "-");
+  pt = (char *)MAX(first_plus, first_minus);
+
+  if (pt != NULL) {
+    pt++;
+
+    if (numtabs == 1)
+    {
+      /* First TAB. Collect all the matches */
+      complete_all_nm_tags(pt);
 
       /* All matches are stored. Longest non-ambiguous string is ""
        * i.e. don't change 'buffer'. Fake successful return this time.
diff --git a/mutt.h b/mutt.h
index faed9fbbe5b36bd98f9d7d87f6855e44c93ba93f..35c59a8aa08f329d49c3bcb6d1da2951c36d8be5 100644 (file)
--- a/mutt.h
+++ b/mutt.h
 #define  M_PATTERN (1<<7) /* pattern mode - only used for history classes */
 #if USE_NOTMUCH
 #define  M_NM_QUERY (1<<8) /* Notmuch query mode. */
+#define  M_NM_TAG   (1<<9) /* Notmuch tag +/- mode. */
 #endif
 
 /* flags for mutt_get_token() */
index 6bcb28c901eea3d3b3861a3a177343cda50c2ee7..c00de1be0bc97e0daa5b7bfe98bf6253fa7470e2 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -291,6 +291,7 @@ int mutt_command_complete (char *, size_t, int, int);
 int mutt_var_value_complete (char *, size_t, int);
 #if USE_NOTMUCH
 int mutt_nm_query_complete (char *buffer, size_t len, int pos, int numtabs);
+int mutt_nm_tag_complete (char *buffer, size_t len, int pos, int numtabs);
 #endif
 int mutt_complete (char *, size_t);
 int mutt_compose_attachment (BODY *a);