コード例 #1
0
ファイル: repl-readline.c プロジェクト: SatoHiroki/julia
int complete_method_table()
{
    if (rl_point < 2 || rl_line_buffer[rl_point-1] != '(') return 0;

    // extract the token preceding the (
    int tokenstart = rl_point-2;

    // check for special operators
    if (strchr("\\><=|&+-*/%^~", rl_line_buffer[tokenstart])){
        while (tokenstart>0 && strchr("<>=!", rl_line_buffer[tokenstart-1])){
            tokenstart--;
        }
    }
    else{
        // check for functions that might contain ! but not start with !
        while (tokenstart>=0 && (jl_word_char(rl_line_buffer[tokenstart]) ||
              rl_line_buffer[tokenstart] == '!')) {
            tokenstart--;
        }
        tokenstart++;
        // ! can't be the first character of a function, unless it's the only character
        if (tokenstart != rl_point-2 && rl_line_buffer[tokenstart] == '!'){
            tokenstart ++;
        }
    }

    jl_value_t* result = call_jl_function_with_string("repl_methods",
                                                      &rl_line_buffer[tokenstart],
                                                      rl_point-tokenstart-1);

    if (!jl_is_byte_string(result)) return 0;
    char *completions = jl_string_data(result);

    int nallocmethods = 0;
    size_t nchars = strlen(completions);
    for (size_t i=0; i<nchars; i++) nallocmethods += completions[i] == '\n';

    char **methods = malloc(sizeof(char *)*(nallocmethods+1));
    methods[0] = NULL;
    methods[1] = strtok_r(completions, "\n", &strtok_saveptr);
    if (methods[1] == NULL) return 0;
    int maxlen = strlen(methods[1]);
    int nmethods = 1;

    char *method;
    while (nmethods < nallocmethods &&
           (method = strtok_r(NULL, "\n", &strtok_saveptr))) {
        int len = strlen(method);
        if (len > maxlen) maxlen = len;
        methods[nmethods+1] = method;
        nmethods++;
    }

    rl_display_match_list(methods, nmethods, maxlen);
    free(methods);
    rl_forced_update_display();
    return 1;
}
コード例 #2
0
ファイル: repl-readline.c プロジェクト: BenoitKnecht/julia
int tab_complete(const char *line, char **answer, int *plen)
{
    int len = *plen;

    while (len>=0) {
        if (!jl_word_char(line[len])) {
            break;
        }
        len--;
    }
    len++;
    *plen = len;

    return symtab_get_matches(jl_get_root_symbol(), &line[len], answer);
}