]> granicus.if.org Git - neomutt/commitdiff
Simplify mutt_label_complete(). 385/head
authorKevin McCarthy <kevin@8t8.us>
Tue, 31 Jan 2017 22:27:36 +0000 (14:27 -0800)
committerRichard Russon <rich@flatcap.org>
Fri, 10 Feb 2017 03:32:55 +0000 (03:32 +0000)
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.

enter.c
init.c
protos.h

diff --git a/enter.c b/enter.c
index bbc29ed6038a4163f7d45a535d1818b11716fe42..6b44e9c2831d582b213fd25a8ea70eae1551ade4 100644 (file)
--- a/enter.c
+++ b/enter.c
@@ -574,7 +574,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int col,
            for (; i < state->lastchar && state->wbuf[i] == ' '; i++)
              ;
            my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i);
-           r = mutt_label_complete (buf, buflen, strlen (buf), state->tabs);
+           r = mutt_label_complete (buf, buflen, state->tabs);
            replace_part (state, i, buf);
            if (!r)
            {
@@ -591,7 +591,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int col,
             {
               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)
               {
diff --git a/init.c b/init.c
index 6f6ec9196522520f8c7a79c0ee8dc9f10878d97b..26b292d909cdfbab8743c310583f2dab454eb316 100644 (file)
--- a/init.c
+++ b/init.c
@@ -4143,7 +4143,7 @@ static const char* myvar_get (const char* var)
   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 */
@@ -4154,10 +4154,6 @@ int mutt_label_complete (char *buffer, size_t len, int pos, int numtabs)
   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)
   {
@@ -4165,7 +4161,7 @@ int mutt_label_complete (char *buffer, size_t len, int pos, int numtabs)
     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));
index 1304e40351b9b6756c52a836870147bc29ae2409..eb50f3098ca5b0b349baf39effeea04d0aa2ec8f 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -200,7 +200,7 @@ int mutt_label_message (HEADER *);
 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);