From b5b89aeb93cf14f22f4980732573085f98cd6986 Mon Sep 17 00:00:00 2001
From: Chris Allegretta <chrisa@asty.org>
Date: Tue, 14 Nov 2000 18:25:26 +0000
Subject: [PATCH] Aha, works even better now.  Made input_tab much more grabby,
 it touches lastWasTab now also...

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@283 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 files.c     | 92 +++++++++++++++++++++++++----------------------------
 po/nano.pot | 54 +++++++++++++++----------------
 proto.h     |  2 +-
 winio.c     |  4 +--
 4 files changed, 72 insertions(+), 80 deletions(-)

diff --git a/files.c b/files.c
index 9afed011..e01bf3ab 100644
--- a/files.c
+++ b/files.c
@@ -550,7 +550,7 @@ char **cwd_tab_completion(char *buf, int *num_matches)
 	dirName = malloc(strlen(buf) + 1);
 	tmp = buf + strlen(buf);
 	while (*tmp != '/' && tmp != buf)
-	   tmp--;
+	    tmp--;
 
 	tmp++;
 
@@ -570,7 +570,7 @@ char **cwd_tab_completion(char *buf, int *num_matches)
     fprintf(stderr, "\nbuf = %s\n", buf);
     fprintf(stderr, "\ntmp = %s\n", tmp);
 #endif
-    
+
     dir = opendir(dirName);
     if (!dir) {
 	/* Don't print an error, just shut up and return */
@@ -608,7 +608,7 @@ char **cwd_tab_completion(char *buf, int *num_matches)
 /* This function now has an arg which refers to how much the 
  * statusbar (place) should be advanced, i.e. the new cursor pos.
  */
-char *input_tab(char *buf, int place, int lastWasTab, int *newplace)
+char *input_tab(char *buf, int place, int *lastWasTab, int *newplace)
 {
     /* Do TAB completion */
     static int num_matches = 0, match_matches = 0;
@@ -618,9 +618,11 @@ char *input_tab(char *buf, int place, int lastWasTab, int *newplace)
     char *foo;
     struct stat fileinfo;
 
-    if (lastWasTab == FALSE) {
+    if (*lastWasTab == FALSE) {
 	char *tmp, *copyto, *matchBuf;
 
+	*lastWasTab = 1;
+
 	/* For now, we will not bother with trying to distinguish
 	 * whether the cursor is in/at a command extression -- we
 	 * will always try all possible matches.  If you don't like
@@ -651,8 +653,8 @@ char *input_tab(char *buf, int place, int lastWasTab, int *newplace)
 	 * then try completing this word as a username. */
 
 	/* FIXME -- this check is broken!
-	if (*tmp == '~' && !strchr(tmp, '/'))
-	    matches = username_tab_completion(tmp, &num_matches); */
+	   if (*tmp == '~' && !strchr(tmp, '/'))
+	   matches = username_tab_completion(tmp, &num_matches); */
 
 	/* Try to match everything in the current working directory that
 	 * matches.  */
@@ -666,7 +668,7 @@ char *input_tab(char *buf, int place, int lastWasTab, int *newplace)
 	fprintf(stderr, "%d matches found...\n", num_matches);
 #endif
 	/* Did we find exactly one match? */
-	switch(num_matches) {
+	switch (num_matches) {
 	case 0:
 	    blank_edit();
 	    break;
@@ -675,65 +677,57 @@ char *input_tab(char *buf, int place, int lastWasTab, int *newplace)
 	    buf = nrealloc(buf, strlen(buf) + strlen(matches[0]) + 1);
 
 	    if (strcmp(buf, "") && strstr(buf, "/")) {
-		for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf; tmp--)
-		    ;
+		for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf;
+		     tmp--);
 		tmp++;
-	    }
-	    else
+	    } else
 		tmp = buf;
 
 	    if (!strcmp(tmp, matches[0])) {
 
 		/* Is it a directory? */
 		if (stat(buf, &fileinfo) == -1)
-			break;
+		    break;
 		else if (S_ISDIR(fileinfo.st_mode)) {
-			strncat(buf, "/", 1);
-			*newplace += 1;
+		    strncat(buf, "/", 1);
+		    *newplace += 1;
+		    /* now we start over again with # of tabs so far */
+		    *lastWasTab = 0;
 		}
 		break;
 	    }
 
 	    copyto = tmp;
-	    for (pos = 0; *tmp == matches[0][pos] && 
-			pos <= strlen(matches[0]); pos++)
+	    for (pos = 0; *tmp == matches[0][pos] &&
+		 pos <= strlen(matches[0]); pos++)
 		tmp++;
 
-
-#ifdef DEBUG
-	    fprintf(stderr, "buf = \'%s\'\n", buf);
-/*	    fprintf(stderr, "copyto = \'%s\'\n", copyto); */
-	    fprintf(stderr, "matches[0] = \'%s\'\n", matches[0]);
-	    fprintf(stderr, "pos = %d\n", pos);
-	    fflush(stderr);
-#endif
-
 	    /* write out the matched command */
-	    strncpy(copyto, matches[0],  strlen(matches[0]) + 1);
+	    strncpy(copyto, matches[0], strlen(matches[0]) + 1);
 	    *newplace += strlen(matches[0]) - pos;
 
-		if (stat(buf, &fileinfo) == -1)
-		    ;
-		else if (S_ISDIR(fileinfo.st_mode)) {
-			strncat(buf, "/", 1);
-			*newplace += 1;
-		}
+	    if (stat(buf, &fileinfo) == -1);
+	    else if (S_ISDIR(fileinfo.st_mode)) {
+		strncat(buf, "/", 1);
+		*newplace += 1;
+		/* now we start over again with # of tabs so far */
+		*lastWasTab = 0;
+	    }
 
 	    break;
 	default:
 	    /* Check to see if all matches share a beginning, and if so
-		tack it onto buf and then beep */
+	       tack it onto buf and then beep */
 
 	    if (strcmp(buf, "") && strstr(buf, "/")) {
-		for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf; tmp--)
-		    ;
+		for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf;
+		     tmp--);
 		tmp++;
-	    }
-	    else
+	    } else
 		tmp = buf;
 
 	    for (pos = 0; *tmp == matches[0][pos] && *tmp != 0 &&
-			pos <= strlen(matches[0]); pos++)
+		 pos <= strlen(matches[0]); pos++)
 		tmp++;
 
 	    while (1) {
@@ -745,13 +739,13 @@ char *input_tab(char *buf, int place, int lastWasTab, int *newplace)
 		    else if (matches[i][pos] == matches[0][pos])
 			match_matches++;
 		}
-		if (match_matches == num_matches && 
-			(i == num_matches || matches[i] != 0)) {
+		if (match_matches == num_matches &&
+		    (i == num_matches || matches[i] != 0)) {
 		    /* All the matches have the same character at pos+1,
-			so paste it into buf... */
+		       so paste it into buf... */
 		    buf = nrealloc(buf, strlen(buf) + 2);
 		    strncat(buf, matches[0] + pos, 1);
-	 	    *newplace += 1;
+		    *newplace += 1;
 		    pos++;
 		} else {
 		    beep();
@@ -783,9 +777,9 @@ char *input_tab(char *buf, int place, int lastWasTab, int *newplace)
 
 	    /* Print the list of matches */
 	    for (i = 0, col = 0; i < num_matches; i++) {
-		
+
 		/* make each filename shown be the same length as the longest
-			filename, with two spaces at the end */
+		   filename, with two spaces at the end */
 		snprintf(foo, longestname + 1, matches[i]);
 		while (strlen(foo) < longestname)
 		    strcat(foo, " ");
@@ -800,13 +794,13 @@ char *input_tab(char *buf, int place, int lastWasTab, int *newplace)
 
 		/* And if the next match isn't going to fit on the
 		   line, move to the next one */
-		if (col > (COLS - longestname)  && matches[i + 1] != NULL) {
+		if (col > (COLS - longestname) && matches[i + 1] != NULL) {
 		    editline++;
 		    wmove(edit, editline, 0);
-                    if (editline == editwinrows - 1) {
-                        waddstr(edit, _("(more)"));
-                        break;
-                    }
+		    if (editline == editwinrows - 1) {
+			waddstr(edit, _("(more)"));
+			break;
+		    }
 		    col = 0;
 		}
 	    }
diff --git a/po/nano.pot b/po/nano.pot
index b761475e..cfcbfe48 100644
--- a/po/nano.pot
+++ b/po/nano.pot
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 2000-11-13 23:13-0500\n"
+"POT-Creation-Date: 2000-11-14 13:25-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -107,7 +107,7 @@ msgstr ""
 msgid "File exists, OVERWRITE ?"
 msgstr ""
 
-#: files.c:807
+#: files.c:801
 msgid "(more)"
 msgstr ""
 
@@ -384,7 +384,7 @@ msgid "Case Sens"
 msgstr ""
 
 #: global.c:344 global.c:364 global.c:375 global.c:385 global.c:401
-#: global.c:405 global.c:411 winio.c:1011
+#: global.c:405 global.c:411 winio.c:1012
 msgid "Cancel"
 msgstr ""
 
@@ -773,41 +773,41 @@ msgstr ""
 msgid "Replaced 1 occurence"
 msgstr ""
 
-#: search.c:443 search.c:538 search.c:554
+#: search.c:443 search.c:536 search.c:552
 msgid "Replace Cancelled"
 msgstr ""
 
-#: search.c:488
+#: search.c:486
 msgid "Replace this instance?"
 msgstr ""
 
-#: search.c:496
+#: search.c:494
 msgid "Replace failed: unknown subexpression!"
 msgstr ""
 
-#: search.c:571
+#: search.c:569
 #, c-format
 msgid "Replace with [%s]"
 msgstr ""
 
-#: search.c:575 search.c:579
+#: search.c:573 search.c:577
 msgid "Replace with"
 msgstr ""
 
 #. Ask for it
-#: search.c:614
+#: search.c:612
 msgid "Enter line number"
 msgstr ""
 
-#: search.c:616
+#: search.c:614
 msgid "Aborted"
 msgstr ""
 
-#: search.c:636
+#: search.c:634
 msgid "Come on, be reasonable"
 msgstr ""
 
-#: search.c:641
+#: search.c:639
 #, c-format
 msgid "Only %d lines available, skipping to last line"
 msgstr ""
@@ -817,67 +817,67 @@ msgstr ""
 msgid "actual_x_from_start for xplus=%d returned %d\n"
 msgstr ""
 
-#: winio.c:424
+#: winio.c:425
 #, c-format
 msgid "input '%c' (%d)\n"
 msgstr ""
 
-#: winio.c:462
+#: winio.c:463
 msgid "New Buffer"
 msgstr ""
 
-#: winio.c:465
+#: winio.c:466
 msgid "  File: ..."
 msgstr ""
 
-#: winio.c:473
+#: winio.c:474
 msgid "Modified"
 msgstr ""
 
-#: winio.c:925
+#: winio.c:926
 #, c-format
 msgid "Moved to (%d, %d) in edit buffer\n"
 msgstr ""
 
-#: winio.c:936
+#: winio.c:937
 #, c-format
 msgid "current->data = \"%s\"\n"
 msgstr ""
 
-#: winio.c:981
+#: winio.c:982
 #, c-format
 msgid "I got \"%s\"\n"
 msgstr ""
 
-#: winio.c:1006
+#: winio.c:1007
 msgid "Yes"
 msgstr ""
 
-#: winio.c:1008
+#: winio.c:1009
 msgid "All"
 msgstr ""
 
-#: winio.c:1010
+#: winio.c:1011
 msgid "No"
 msgstr ""
 
-#: winio.c:1147
+#: winio.c:1148
 #, c-format
 msgid "do_cursorpos: linepct = %f, bytepct = %f\n"
 msgstr ""
 
-#: winio.c:1151
+#: winio.c:1152
 msgid "line %d of %d (%.0f%%), character %d of %d (%.0f%%)"
 msgstr ""
 
-#: winio.c:1279
+#: winio.c:1280
 msgid "Dumping file buffer to stderr...\n"
 msgstr ""
 
-#: winio.c:1281
+#: winio.c:1282
 msgid "Dumping cutbuffer to stderr...\n"
 msgstr ""
 
-#: winio.c:1283
+#: winio.c:1284
 msgid "Dumping a buffer to stderr...\n"
 msgstr ""
diff --git a/proto.h b/proto.h
index 55691dda..dcb03c70 100644
--- a/proto.h
+++ b/proto.h
@@ -88,7 +88,7 @@ int do_down(void);
 int do_left(void);
 int do_right(void);
 int check_wildcard_match(const char *text, const char *pattern);
-char *input_tab(char *buf, int place, int lastWasTab, int *newplace);
+char *input_tab(char *buf, int place, int *lastWasTab, int *newplace);
 
 void shortcut_init(void);
 void lowercase(char *src);
diff --git a/winio.c b/winio.c
index 15a6045c..69e1b647 100644
--- a/winio.c
+++ b/winio.c
@@ -334,13 +334,11 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
 	    break;
 	case NANO_CONTROL_I:
 	    if (allowtabs) {
-		tabbed++;
 		shift = 0;
 		inputbuf = input_tab(inputbuf, (x - x_left), 
-				tabbed - 1, &shift);
+				&tabbed, &shift);
 		x += shift;
 		nanoget_repaint(buf, inputbuf, x);
-		tabbed = 1;
 	    }
 	    break;
 	case KEY_LEFT:
-- 
GitLab