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
This commit is contained in:
Chris Allegretta 2000-11-14 18:25:26 +00:00
parent 022b96f941
commit b5b89aeb93
4 changed files with 72 additions and 80 deletions

92
files.c
View File

@ -550,7 +550,7 @@ char **cwd_tab_completion(char *buf, int *num_matches)
dirName = malloc(strlen(buf) + 1); dirName = malloc(strlen(buf) + 1);
tmp = buf + strlen(buf); tmp = buf + strlen(buf);
while (*tmp != '/' && tmp != buf) while (*tmp != '/' && tmp != buf)
tmp--; tmp--;
tmp++; tmp++;
@ -570,7 +570,7 @@ char **cwd_tab_completion(char *buf, int *num_matches)
fprintf(stderr, "\nbuf = %s\n", buf); fprintf(stderr, "\nbuf = %s\n", buf);
fprintf(stderr, "\ntmp = %s\n", tmp); fprintf(stderr, "\ntmp = %s\n", tmp);
#endif #endif
dir = opendir(dirName); dir = opendir(dirName);
if (!dir) { if (!dir) {
/* Don't print an error, just shut up and return */ /* 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 /* This function now has an arg which refers to how much the
* statusbar (place) should be advanced, i.e. the new cursor pos. * 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 */ /* Do TAB completion */
static int num_matches = 0, match_matches = 0; 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; char *foo;
struct stat fileinfo; struct stat fileinfo;
if (lastWasTab == FALSE) { if (*lastWasTab == FALSE) {
char *tmp, *copyto, *matchBuf; char *tmp, *copyto, *matchBuf;
*lastWasTab = 1;
/* For now, we will not bother with trying to distinguish /* For now, we will not bother with trying to distinguish
* whether the cursor is in/at a command extression -- we * whether the cursor is in/at a command extression -- we
* will always try all possible matches. If you don't like * 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. */ * then try completing this word as a username. */
/* FIXME -- this check is broken! /* FIXME -- this check is broken!
if (*tmp == '~' && !strchr(tmp, '/')) if (*tmp == '~' && !strchr(tmp, '/'))
matches = username_tab_completion(tmp, &num_matches); */ matches = username_tab_completion(tmp, &num_matches); */
/* Try to match everything in the current working directory that /* Try to match everything in the current working directory that
* matches. */ * matches. */
@ -666,7 +668,7 @@ char *input_tab(char *buf, int place, int lastWasTab, int *newplace)
fprintf(stderr, "%d matches found...\n", num_matches); fprintf(stderr, "%d matches found...\n", num_matches);
#endif #endif
/* Did we find exactly one match? */ /* Did we find exactly one match? */
switch(num_matches) { switch (num_matches) {
case 0: case 0:
blank_edit(); blank_edit();
break; 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); buf = nrealloc(buf, strlen(buf) + strlen(matches[0]) + 1);
if (strcmp(buf, "") && strstr(buf, "/")) { if (strcmp(buf, "") && strstr(buf, "/")) {
for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf; tmp--) for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf;
; tmp--);
tmp++; tmp++;
} } else
else
tmp = buf; tmp = buf;
if (!strcmp(tmp, matches[0])) { if (!strcmp(tmp, matches[0])) {
/* Is it a directory? */ /* Is it a directory? */
if (stat(buf, &fileinfo) == -1) if (stat(buf, &fileinfo) == -1)
break; break;
else if (S_ISDIR(fileinfo.st_mode)) { else if (S_ISDIR(fileinfo.st_mode)) {
strncat(buf, "/", 1); strncat(buf, "/", 1);
*newplace += 1; *newplace += 1;
/* now we start over again with # of tabs so far */
*lastWasTab = 0;
} }
break; break;
} }
copyto = tmp; copyto = tmp;
for (pos = 0; *tmp == matches[0][pos] && for (pos = 0; *tmp == matches[0][pos] &&
pos <= strlen(matches[0]); pos++) pos <= strlen(matches[0]); pos++)
tmp++; 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 */ /* 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; *newplace += strlen(matches[0]) - pos;
if (stat(buf, &fileinfo) == -1) if (stat(buf, &fileinfo) == -1);
; else if (S_ISDIR(fileinfo.st_mode)) {
else if (S_ISDIR(fileinfo.st_mode)) { strncat(buf, "/", 1);
strncat(buf, "/", 1); *newplace += 1;
*newplace += 1; /* now we start over again with # of tabs so far */
} *lastWasTab = 0;
}
break; break;
default: default:
/* Check to see if all matches share a beginning, and if so /* 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, "/")) { if (strcmp(buf, "") && strstr(buf, "/")) {
for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf; tmp--) for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf;
; tmp--);
tmp++; tmp++;
} } else
else
tmp = buf; tmp = buf;
for (pos = 0; *tmp == matches[0][pos] && *tmp != 0 && for (pos = 0; *tmp == matches[0][pos] && *tmp != 0 &&
pos <= strlen(matches[0]); pos++) pos <= strlen(matches[0]); pos++)
tmp++; tmp++;
while (1) { 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]) else if (matches[i][pos] == matches[0][pos])
match_matches++; match_matches++;
} }
if (match_matches == num_matches && if (match_matches == num_matches &&
(i == num_matches || matches[i] != 0)) { (i == num_matches || matches[i] != 0)) {
/* All the matches have the same character at pos+1, /* 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); buf = nrealloc(buf, strlen(buf) + 2);
strncat(buf, matches[0] + pos, 1); strncat(buf, matches[0] + pos, 1);
*newplace += 1; *newplace += 1;
pos++; pos++;
} else { } else {
beep(); beep();
@ -783,9 +777,9 @@ char *input_tab(char *buf, int place, int lastWasTab, int *newplace)
/* Print the list of matches */ /* Print the list of matches */
for (i = 0, col = 0; i < num_matches; i++) { for (i = 0, col = 0; i < num_matches; i++) {
/* make each filename shown be the same length as the longest /* 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]); snprintf(foo, longestname + 1, matches[i]);
while (strlen(foo) < longestname) while (strlen(foo) < longestname)
strcat(foo, " "); 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 /* And if the next match isn't going to fit on the
line, move to the next one */ line, move to the next one */
if (col > (COLS - longestname) && matches[i + 1] != NULL) { if (col > (COLS - longestname) && matches[i + 1] != NULL) {
editline++; editline++;
wmove(edit, editline, 0); wmove(edit, editline, 0);
if (editline == editwinrows - 1) { if (editline == editwinrows - 1) {
waddstr(edit, _("(more)")); waddstr(edit, _("(more)"));
break; break;
} }
col = 0; col = 0;
} }
} }

View File

@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -107,7 +107,7 @@ msgstr ""
msgid "File exists, OVERWRITE ?" msgid "File exists, OVERWRITE ?"
msgstr "" msgstr ""
#: files.c:807 #: files.c:801
msgid "(more)" msgid "(more)"
msgstr "" msgstr ""
@ -384,7 +384,7 @@ msgid "Case Sens"
msgstr "" msgstr ""
#: global.c:344 global.c:364 global.c:375 global.c:385 global.c:401 #: 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" msgid "Cancel"
msgstr "" msgstr ""
@ -773,41 +773,41 @@ msgstr ""
msgid "Replaced 1 occurence" msgid "Replaced 1 occurence"
msgstr "" msgstr ""
#: search.c:443 search.c:538 search.c:554 #: search.c:443 search.c:536 search.c:552
msgid "Replace Cancelled" msgid "Replace Cancelled"
msgstr "" msgstr ""
#: search.c:488 #: search.c:486
msgid "Replace this instance?" msgid "Replace this instance?"
msgstr "" msgstr ""
#: search.c:496 #: search.c:494
msgid "Replace failed: unknown subexpression!" msgid "Replace failed: unknown subexpression!"
msgstr "" msgstr ""
#: search.c:571 #: search.c:569
#, c-format #, c-format
msgid "Replace with [%s]" msgid "Replace with [%s]"
msgstr "" msgstr ""
#: search.c:575 search.c:579 #: search.c:573 search.c:577
msgid "Replace with" msgid "Replace with"
msgstr "" msgstr ""
#. Ask for it #. Ask for it
#: search.c:614 #: search.c:612
msgid "Enter line number" msgid "Enter line number"
msgstr "" msgstr ""
#: search.c:616 #: search.c:614
msgid "Aborted" msgid "Aborted"
msgstr "" msgstr ""
#: search.c:636 #: search.c:634
msgid "Come on, be reasonable" msgid "Come on, be reasonable"
msgstr "" msgstr ""
#: search.c:641 #: search.c:639
#, c-format #, c-format
msgid "Only %d lines available, skipping to last line" msgid "Only %d lines available, skipping to last line"
msgstr "" msgstr ""
@ -817,67 +817,67 @@ msgstr ""
msgid "actual_x_from_start for xplus=%d returned %d\n" msgid "actual_x_from_start for xplus=%d returned %d\n"
msgstr "" msgstr ""
#: winio.c:424 #: winio.c:425
#, c-format #, c-format
msgid "input '%c' (%d)\n" msgid "input '%c' (%d)\n"
msgstr "" msgstr ""
#: winio.c:462 #: winio.c:463
msgid "New Buffer" msgid "New Buffer"
msgstr "" msgstr ""
#: winio.c:465 #: winio.c:466
msgid " File: ..." msgid " File: ..."
msgstr "" msgstr ""
#: winio.c:473 #: winio.c:474
msgid "Modified" msgid "Modified"
msgstr "" msgstr ""
#: winio.c:925 #: winio.c:926
#, c-format #, c-format
msgid "Moved to (%d, %d) in edit buffer\n" msgid "Moved to (%d, %d) in edit buffer\n"
msgstr "" msgstr ""
#: winio.c:936 #: winio.c:937
#, c-format #, c-format
msgid "current->data = \"%s\"\n" msgid "current->data = \"%s\"\n"
msgstr "" msgstr ""
#: winio.c:981 #: winio.c:982
#, c-format #, c-format
msgid "I got \"%s\"\n" msgid "I got \"%s\"\n"
msgstr "" msgstr ""
#: winio.c:1006 #: winio.c:1007
msgid "Yes" msgid "Yes"
msgstr "" msgstr ""
#: winio.c:1008 #: winio.c:1009
msgid "All" msgid "All"
msgstr "" msgstr ""
#: winio.c:1010 #: winio.c:1011
msgid "No" msgid "No"
msgstr "" msgstr ""
#: winio.c:1147 #: winio.c:1148
#, c-format #, c-format
msgid "do_cursorpos: linepct = %f, bytepct = %f\n" msgid "do_cursorpos: linepct = %f, bytepct = %f\n"
msgstr "" msgstr ""
#: winio.c:1151 #: winio.c:1152
msgid "line %d of %d (%.0f%%), character %d of %d (%.0f%%)" msgid "line %d of %d (%.0f%%), character %d of %d (%.0f%%)"
msgstr "" msgstr ""
#: winio.c:1279 #: winio.c:1280
msgid "Dumping file buffer to stderr...\n" msgid "Dumping file buffer to stderr...\n"
msgstr "" msgstr ""
#: winio.c:1281 #: winio.c:1282
msgid "Dumping cutbuffer to stderr...\n" msgid "Dumping cutbuffer to stderr...\n"
msgstr "" msgstr ""
#: winio.c:1283 #: winio.c:1284
msgid "Dumping a buffer to stderr...\n" msgid "Dumping a buffer to stderr...\n"
msgstr "" msgstr ""

View File

@ -88,7 +88,7 @@ int do_down(void);
int do_left(void); int do_left(void);
int do_right(void); int do_right(void);
int check_wildcard_match(const char *text, const char *pattern); 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 shortcut_init(void);
void lowercase(char *src); void lowercase(char *src);

View File

@ -334,13 +334,11 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
break; break;
case NANO_CONTROL_I: case NANO_CONTROL_I:
if (allowtabs) { if (allowtabs) {
tabbed++;
shift = 0; shift = 0;
inputbuf = input_tab(inputbuf, (x - x_left), inputbuf = input_tab(inputbuf, (x - x_left),
tabbed - 1, &shift); &tabbed, &shift);
x += shift; x += shift;
nanoget_repaint(buf, inputbuf, x); nanoget_repaint(buf, inputbuf, x);
tabbed = 1;
} }
break; break;
case KEY_LEFT: case KEY_LEFT: