Beispiel #1
0
Filerange text_object_function(Text *txt, size_t pos) {
	size_t a = text_function_start_prev(txt, pos);
	size_t b = text_function_end_next(txt, pos);
	if (text_function_end_next(txt, a) == b) {
		Filerange r = text_range_new(a, b+1);
		return text_range_linewise(txt, &r);
	}
	return text_range_empty();
}
Beispiel #2
0
static Filerange object_function(Text *txt, size_t pos) {
    size_t start_prev = text_function_start_prev(txt, pos);
    size_t end_next = text_function_end_next(txt, pos);
    size_t start = text_function_start_next(txt, start_prev);
    size_t end = text_function_end_prev(txt, end_next);
    if (start == pos)
        start_prev = pos;
    if (end == pos)
        end_next = pos;
    if (text_function_end_next(txt, start_prev) == end_next &&
            text_function_start_prev(txt, end_next) == start_prev) {
        return text_range_new(start_prev, end_next);
    }
    return text_range_empty();
}
Beispiel #3
0
Filerange text_object_function_inner(Text *txt, size_t pos) {
	Filerange r = text_object_function(txt, pos);
	if (!text_range_valid(&r))
		return r;
	size_t b = text_function_end_next(txt, pos);
	size_t a = text_bracket_match(txt, b);
	return text_range_new(a+1, b-1);
}
Beispiel #4
0
size_t text_function_start_prev(Text *txt, size_t pos) {
	char c;
	size_t apos = text_byte_get(txt, pos, &c) && c == '}' && pos > 0 ? pos - 1 : pos;
	size_t a = text_function_end_next(txt, apos);
	size_t b = text_function_end_prev(txt, pos);
	if (a != apos) {
		size_t match = text_bracket_match(txt, a);
		a = match != a ? text_line_next(txt, text_line_empty_prev(txt, match)) : pos;
	}
	if (b != pos) {
		size_t match = text_bracket_match(txt, b);
		b = match != b ? text_line_next(txt, text_line_empty_prev(txt, match)) : pos;
	}
	if (a >= pos && b >= pos)
		return pos;
	else if (a >= pos)
		return b;
	else if (b >= pos)
		return a;
	else
		return MAX(a, b);
}
Beispiel #5
0
size_t text_function_start_next(Text *txt, size_t pos) {
	size_t a = text_function_end_next(txt, pos);
	size_t b = a;
	char c;
	if (a != pos) {
		Iterator it = text_iterator_get(txt, a);
		while (text_iterator_byte_next(&it, &c) && (c == '\r' || c == '\n'));
		a = it.pos;
	}
	if (b != pos) {
		size_t match = text_bracket_match(txt, b);
		b = match != b ? text_line_next(txt, text_line_empty_prev(txt, match)) : pos;
	}
	if (a <= pos && b <= pos)
		return pos;
	else if (a <= pos)
		return b;
	else if (b <= pos)
		return a;
	else
		return MIN(a, b);
}