Latest tab completion update, sort of works =)

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@281 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Chris Allegretta 2000-11-14 17:46:06 +00:00
parent 0468612b4d
commit 442f2c5156
4 changed files with 113 additions and 43 deletions

93
files.c
View File

@ -551,10 +551,13 @@ char **cwd_tab_completion(char *buf, int *num_matches)
tmp = buf + strlen(buf); tmp = buf + strlen(buf);
while (*tmp != '/' && tmp != buf) while (*tmp != '/' && tmp != buf)
tmp--; tmp--;
strncpy(dirName, buf, tmp - buf);
dirName[tmp - buf] = 0;
tmp++; tmp++;
strncpy(dirName, buf, tmp - buf + 1);
dirName[tmp - buf] = 0;
/* tmp++; */
} else { } else {
if ((dirName = getcwd(NULL, 0)) == NULL) if ((dirName = getcwd(NULL, 0)) == NULL)
return matches; return matches;
@ -602,20 +605,21 @@ char **cwd_tab_completion(char *buf, int *num_matches)
return (matches); return (matches);
} }
/* This function now return an int 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.
*/ */
int input_tab(char *buf, int place, int lastWasTab) 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;
static char **matches = (char **) NULL; static char **matches = (char **) NULL;
int pos = place, newplace = 0, i = 0, col = 0, editline = 0; int pos = place, i = 0, col = 0, editline = 0;
int longestname = 0; int longestname = 0;
char *foo; char *foo;
struct stat fileinfo;
if (lastWasTab == FALSE) { if (lastWasTab == FALSE) {
char *tmp, *matchBuf; char *tmp, *copyto, *matchBuf;
/* 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
@ -636,6 +640,8 @@ int input_tab(char *buf, int place, int lastWasTab)
/* Free up any memory already allocated */ /* Free up any memory already allocated */
if (matches != NULL) { if (matches != NULL) {
for (i = i; i < num_matches; i++)
free(matches[i]);
free(matches); free(matches);
matches = (char **) NULL; matches = (char **) NULL;
num_matches = 0; num_matches = 0;
@ -656,22 +662,80 @@ int input_tab(char *buf, int place, int lastWasTab)
/* Don't leak memory */ /* Don't leak memory */
free(matchBuf); free(matchBuf);
#ifdef DEBUG
fprintf(stderr, "%d matches found...\n", num_matches);
#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;
case 1: case 1:
buf = nrealloc(buf, strlen(buf) + strlen(matches[0]) - pos + 1);
buf = nrealloc(buf, strlen(buf) + strlen(matches[0]) + 1);
if (strcmp(buf, "") && strstr(buf, "/")) {
for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf; tmp--)
;
tmp++;
}
else
tmp = buf;
if (!strcmp(tmp, matches[0])) {
/* Is it a directory? */
if (stat(buf, &fileinfo) == -1)
break;
else if (S_ISDIR(fileinfo.st_mode)) {
strncat(buf, "/", 1);
*newplace += 1;
}
break;
}
copyto = tmp;
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 */ /* write out the matched command */
strncpy(buf + pos, matches[0] + pos, strncpy(copyto, matches[0], strlen(matches[0]) + 1);
strlen(matches[0]) - pos); *newplace += strlen(matches[0]) - pos;
newplace += strlen(matches[0]) - pos;
if (stat(buf, &fileinfo) == -1)
;
else if (S_ISDIR(fileinfo.st_mode)) {
strncat(buf, "/", 1);
*newplace += 1;
}
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, "/")) {
for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf; tmp--)
;
tmp++;
}
else
tmp = buf;
for (pos = 0; *tmp == matches[0][pos] && *tmp != 0 &&
pos <= strlen(matches[0]); pos++)
tmp++;
while (1) { while (1) {
match_matches = 0; match_matches = 0;
@ -686,8 +750,8 @@ int input_tab(char *buf, int place, int lastWasTab)
/* 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);
strncpy(buf + pos, matches[0] + pos, 1); strncat(buf, matches[0] + pos, 1);
newplace++; *newplace += 1;
pos++; pos++;
} else { } else {
beep(); beep();
@ -728,6 +792,8 @@ int input_tab(char *buf, int place, int lastWasTab)
strcat(foo, " "); strcat(foo, " ");
/* Disable el cursor */
curs_set(0);
/* now, put the match on the screen */ /* now, put the match on the screen */
waddnstr(edit, foo, strlen(foo)); waddnstr(edit, foo, strlen(foo));
col += strlen(foo); col += strlen(foo);
@ -752,5 +818,6 @@ int input_tab(char *buf, int place, int lastWasTab)
} }
edit_refresh(); edit_refresh();
return newplace; curs_set(1);
return buf;
} }

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-09 23:23-0500\n" "POT-Creation-Date: 2000-11-13 23:13-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:741 #: files.c:807
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:1008 #: global.c:405 global.c:411 winio.c:1011
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:536 search.c:552 #: search.c:443 search.c:538 search.c:554
msgid "Replace Cancelled" msgid "Replace Cancelled"
msgstr "" msgstr ""
#: search.c:486 #: search.c:488
msgid "Replace this instance?" msgid "Replace this instance?"
msgstr "" msgstr ""
#: search.c:494 #: search.c:496
msgid "Replace failed: unknown subexpression!" msgid "Replace failed: unknown subexpression!"
msgstr "" msgstr ""
#: search.c:569 #: search.c:571
#, c-format #, c-format
msgid "Replace with [%s]" msgid "Replace with [%s]"
msgstr "" msgstr ""
#: search.c:573 search.c:577 #: search.c:575 search.c:579
msgid "Replace with" msgid "Replace with"
msgstr "" msgstr ""
#. Ask for it #. Ask for it
#: search.c:612 #: search.c:614
msgid "Enter line number" msgid "Enter line number"
msgstr "" msgstr ""
#: search.c:614 #: search.c:616
msgid "Aborted" msgid "Aborted"
msgstr "" msgstr ""
#: search.c:634 #: search.c:636
msgid "Come on, be reasonable" msgid "Come on, be reasonable"
msgstr "" msgstr ""
#: search.c:639 #: search.c:641
#, 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:421 #: winio.c:424
#, c-format #, c-format
msgid "input '%c' (%d)\n" msgid "input '%c' (%d)\n"
msgstr "" msgstr ""
#: winio.c:459 #: winio.c:462
msgid "New Buffer" msgid "New Buffer"
msgstr "" msgstr ""
#: winio.c:462 #: winio.c:465
msgid " File: ..." msgid " File: ..."
msgstr "" msgstr ""
#: winio.c:470 #: winio.c:473
msgid "Modified" msgid "Modified"
msgstr "" msgstr ""
#: winio.c:922 #: winio.c:925
#, 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:933 #: winio.c:936
#, c-format #, c-format
msgid "current->data = \"%s\"\n" msgid "current->data = \"%s\"\n"
msgstr "" msgstr ""
#: winio.c:978 #: winio.c:981
#, c-format #, c-format
msgid "I got \"%s\"\n" msgid "I got \"%s\"\n"
msgstr "" msgstr ""
#: winio.c:1003 #: winio.c:1006
msgid "Yes" msgid "Yes"
msgstr "" msgstr ""
#: winio.c:1005 #: winio.c:1008
msgid "All" msgid "All"
msgstr "" msgstr ""
#: winio.c:1007 #: winio.c:1010
msgid "No" msgid "No"
msgstr "" msgstr ""
#: winio.c:1144 #: winio.c:1147
#, c-format #, c-format
msgid "do_cursorpos: linepct = %f, bytepct = %f\n" msgid "do_cursorpos: linepct = %f, bytepct = %f\n"
msgstr "" msgstr ""
#: winio.c:1148 #: winio.c:1151
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:1276 #: winio.c:1279
msgid "Dumping file buffer to stderr...\n" msgid "Dumping file buffer to stderr...\n"
msgstr "" msgstr ""
#: winio.c:1278 #: winio.c:1281
msgid "Dumping cutbuffer to stderr...\n" msgid "Dumping cutbuffer to stderr...\n"
msgstr "" msgstr ""
#: winio.c:1280 #: winio.c:1283
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);
int input_tab(char *buf, int place, int lastWasTab); 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

@ -248,7 +248,7 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
int start_x) int start_x)
{ {
int kbinput = 0, j = 0, x = 0, xend; int kbinput = 0, j = 0, x = 0, xend;
int x_left = 0, inputlen, tabbed = 0; int x_left = 0, inputlen, tabbed = 0, shift = 0;
char *inputbuf; char *inputbuf;
inputbuf = nmalloc(strlen(def) + 1); inputbuf = nmalloc(strlen(def) + 1);
@ -332,7 +332,10 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
case NANO_CONTROL_I: case NANO_CONTROL_I:
if (allowtabs) { if (allowtabs) {
tabbed++; tabbed++;
x += input_tab(inputbuf, (x - x_left), tabbed - 1); shift = 0;
inputbuf = input_tab(inputbuf, (x - x_left),
tabbed - 1, &shift);
x += shift;
nanoget_repaint(buf, inputbuf, x); nanoget_repaint(buf, inputbuf, x);
tabbed = 1; tabbed = 1;
} }