changeset: 6919:9ca99f2b1205
user:      Kevin McCarthy <ke...@8t8.us>
date:      Tue Jan 31 14:27:09 2017 -0800
link:      http://dev.mutt.org/hg/mutt/rev/9ca99f2b1205

Fix the mutt_label_complete() pos parameter.

i is the state->wbuf index, not the end of the buf.  It was "working"
only because the contents of buf past the null were not "space" most
of the time.

changeset: 6920:298654f1d70c
user:      Kevin McCarthy <ke...@8t8.us>
date:      Tue Jan 31 14:27:28 2017 -0800
link:      http://dev.mutt.org/hg/mutt/rev/298654f1d70c

Permit tab completion of pattern expressions with ~y (labels).

Thanks to David Champion for the original patch.  This version is
slightly different, as I couldn't get the original patch working.
This version simply scans backward for the first ~, and if it is ~y,
invokes completion.

changeset: 6921:82034c72b6da
user:      Kevin McCarthy <ke...@8t8.us>
date:      Tue Jan 31 14:27:36 2017 -0800
link:      http://dev.mutt.org/hg/mutt/rev/82034c72b6da

Simplify mutt_label_complete().

It was derived from mutt_command_complete(), which had more complex
requirements.  For labels, we just need to skip whitespace and
complete based on the passed in buffer.

Therefore, we don't need the pos parameter, or to work backwards from
the end of the buffer.

diffs (90 lines):

diff -r ab2f8882633b -r 82034c72b6da enter.c
--- a/enter.c   Sun Jan 29 11:02:50 2017 -0800
+++ b/enter.c   Tue Jan 31 14:27:36 2017 -0800
@@ -568,14 +568,13 @@
          }
          else if (flags & MUTT_LABEL && ch == OP_EDITOR_COMPLETE)
          {
-           /* invoke the alias-menu to get more addresses */
            for (i = state->curpos; i && state->wbuf[i-1] != ',' && 
                 state->wbuf[i-1] != ':'; i--)
              ;
            for (; i < state->lastchar && state->wbuf[i] == ' '; i++)
              ;
            my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i);
-           r = mutt_label_complete (buf, buflen, i, state->tabs);
+           r = mutt_label_complete (buf, buflen, state->tabs);
            replace_part (state, i, buf);
            if (!r)
            {
@@ -584,6 +583,26 @@
            }
            break;
          }
+          else if (flags & MUTT_PATTERN && ch == OP_EDITOR_COMPLETE)
+          {
+            for (i = state->curpos; i && state->wbuf[i-1] != '~'; i--)
+              ;
+            if (i && state->wbuf[i-1] == '~' && state->wbuf[i] == 'y')
+            {
+              i++;
+              my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i);
+              r = mutt_label_complete (buf, buflen, state->tabs);
+              replace_part (state, i, buf);
+              if (!r)
+              {
+                rv = 1;
+                goto bye;
+              }
+            }
+            else
+              goto self_insert;
+            break;
+          }
          else if (flags & MUTT_ALIAS && ch == OP_EDITOR_COMPLETE_QUERY)
          {
            /* invoke the query-menu to get more addresses */
diff -r ab2f8882633b -r 82034c72b6da init.c
--- a/init.c    Sun Jan 29 11:02:50 2017 -0800
+++ b/init.c    Tue Jan 31 14:27:36 2017 -0800
@@ -3630,7 +3630,7 @@
   return NULL;
 }
 
-int mutt_label_complete (char *buffer, size_t len, int pos, int numtabs)
+int mutt_label_complete (char *buffer, size_t len, int numtabs)
 {
   char *pt = buffer;
   int spaces; /* keep track of the number of leading spaces on the line */
@@ -3641,10 +3641,6 @@
   SKIPWS (buffer);
   spaces = buffer - pt;
 
-  pt = buffer + pos - spaces;
-  while ((pt > buffer) && !isspace ((unsigned char) *pt))
-    pt--;
-
   /* first TAB. Collect all the matches */
   if (numtabs == 1)
   {
@@ -3652,7 +3648,7 @@
     struct hash_walk_state state;
 
     Num_matched = 0;
-    strfcpy (User_typed, pt, sizeof (User_typed));
+    strfcpy (User_typed, buffer, sizeof (User_typed));
     memset (Matches, 0, Matches_listsize);
     memset (Completed, 0, sizeof (Completed));
     memset (&state, 0, sizeof(state));
diff -r ab2f8882633b -r 82034c72b6da protos.h
--- a/protos.h  Sun Jan 29 11:02:50 2017 -0800
+++ b/protos.h  Tue Jan 31 14:27:36 2017 -0800
@@ -190,7 +190,7 @@
 void mutt_make_label_hash (CONTEXT *);
 void mutt_label_hash_add (CONTEXT *ctx, HEADER *hdr);
 void mutt_label_hash_remove (CONTEXT *ctx, HEADER *hdr);
-int mutt_label_complete (char *, size_t, int, int);
+int mutt_label_complete (char *, size_t, int);
 void mutt_curses_error (const char *, ...);
 void mutt_curses_message (const char *, ...);
 void mutt_encode_descriptions (BODY *, short);

Reply via email to