The R Project SVN R

Rev

Rev 72455 | Rev 83463 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 72455 Rev 82340
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  file rt_complete.c
3
 *  file rt_complete.c
4
 *  Copyright (C) 2007-2017 The R Core Team.
4
 *  Copyright (C) 2007-2022 The R Core Team.
5
 *
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
9
 *  (at your option) any later version.
Line 58... Line 58...
58
    int i, alen, cursor_position = *loc;
58
    int i, alen, cursor_position = *loc;
59
    char *partial_line = buf;
59
    char *partial_line = buf;
60
    const char *additional_text;
60
    const char *additional_text;
61
    SEXP cmdSexp, cmdexpr, ans = R_NilValue;
61
    SEXP cmdSexp, cmdexpr, ans = R_NilValue;
62
    ParseStatus status;
62
    ParseStatus status;
-
 
63
    const void *vmax = NULL;
63
 
64
 
64
    if(!completion_available) return gl_tab(buf, offset, loc);
65
    if(!completion_available) return gl_tab(buf, offset, loc);
65
 
66
 
66
    if(completion_available < 0) {
67
    if(completion_available < 0) {
67
	char *p = getenv("R_COMPLETION");
68
	char *p = getenv("R_COMPLETION");
Line 116... Line 117...
116
    }
117
    }
117
    /* Loop is needed here as EXPRSEXP will be of length > 1 */
118
    /* Loop is needed here as EXPRSEXP will be of length > 1 */
118
    for(i = 0; i < length(cmdexpr); i++)
119
    for(i = 0; i < length(cmdexpr); i++)
119
	ans = eval(VECTOR_ELT(cmdexpr, i), R_GlobalEnv);
120
	ans = eval(VECTOR_ELT(cmdexpr, i), R_GlobalEnv);
120
    UNPROTECT(2);
121
    UNPROTECT(2);
-
 
122
    PROTECT(ans);
121
 
123
 
122
    /* ans has the form list(addition, possible), where 'addition' is
124
    /* ans has the form list(addition, possible), where 'addition' is
123
       unique additional text if any, and 'possible' is a character
125
       unique additional text if any, and 'possible' is a character
124
       vector holding possible completions if any (already formatted
126
       vector holding possible completions if any (already formatted
125
       for linewise printing in the current implementation).  If
127
       for linewise printing in the current implementation).  If
Line 128... Line 130...
128
       at the cursor */
130
       at the cursor */
129
 
131
 
130
#define ADDITION 0
132
#define ADDITION 0
131
#define POSSIBLE 1
133
#define POSSIBLE 1
132
 
134
 
-
 
135
    vmax = vmaxget();
133
    alen = length(VECTOR_ELT(ans, POSSIBLE));
136
    alen = length(VECTOR_ELT(ans, POSSIBLE));
134
    if (alen) {
137
    if (alen) {
135
	int max_show = 10;
138
	int max_show = 10;
136
	printf("\n"); /* finish current line */
139
	printf("\n"); /* finish current line */
137
	for (i = 0; i < min(alen, max_show); i++) {
140
	for (i = 0; i < min(alen, max_show); i++) {
138
	    printf("%s\n", CHAR(STRING_ELT(VECTOR_ELT(ans, POSSIBLE), i)));
141
	    printf("%s\n", translateChar(STRING_ELT(VECTOR_ELT(ans, POSSIBLE), i)));
139
	}
142
	}
140
	if (alen > max_show)
143
	if (alen > max_show)
141
	    printf("\n[...truncated]\n");
144
	    printf("\n[...truncated]\n");
142
	cursor_position = -2; /* Need to redisplay whole line */
145
	cursor_position = -2; /* Need to redisplay whole line */
143
    }
146
    }
144
    additional_text = CHAR(STRING_ELT( VECTOR_ELT(ans, ADDITION), 0 ));
147
    additional_text = translateChar(STRING_ELT( VECTOR_ELT(ans, ADDITION), 0 ));
145
    alen = strlen(additional_text);
148
    alen = strlen(additional_text);
146
    if (alen) {
149
    if (alen) {
147
	int cp = *loc;
150
	int cp = *loc;
148
	memcpy(buf+cp, additional_text, alen+1);
151
	memcpy(buf+cp, additional_text, alen+1);
149
	*loc = cp + alen;
152
	*loc = cp + alen;
150
    }
153
    }
-
 
154
    vmaxset(vmax);
-
 
155
    UNPROTECT(1); /* ans */
151
    return cursor_position;
156
    return cursor_position;
152
}
157
}
153
 
158
 
154
 
159
 
155
void R_gl_tab_set(void)
160
void R_gl_tab_set(void)