4 /* these function all take a position in bytes from the start of the file,
5 * perform a certain movement and return the new postion. if the movement
6 * is not possible the original position is returned unchanged. */
10 #include "text-regex.h"
12 size_t text_begin(Text
*, size_t pos
);
13 size_t text_end(Text
*, size_t pos
);
15 /* char refers to a grapheme (might skip over multiple Unicode codepoints) */
16 size_t text_char_next(Text
*, size_t pos
);
17 size_t text_char_prev(Text
*, size_t pos
);
19 /* find the given substring either in forward or backward direction.
20 * does not wrap around at file start / end. if no match is found return
21 * original position */
22 size_t text_find_next(Text
*, size_t pos
, const char *s
);
23 size_t text_find_prev(Text
*, size_t pos
, const char *s
);
24 /* same as above but limit searched range to the line containing pos */
25 size_t text_line_find_next(Text
*, size_t pos
, const char *s
);
26 size_t text_line_find_prev(Text
*, size_t pos
, const char *s
);
28 /* begin finish end next
30 * [\r]\n I am a line! [\r]\n
34 size_t text_line_prev(Text
*, size_t pos
);
35 size_t text_line_begin(Text
*, size_t pos
);
36 size_t text_line_start(Text
*, size_t pos
);
37 size_t text_line_finish(Text
*, size_t pos
);
38 size_t text_line_lastchar(Text
*, size_t pos
);
39 size_t text_line_end(Text
*, size_t pos
);
40 size_t text_line_next(Text
*, size_t pos
);
41 size_t text_line_offset(Text
*, size_t pos
, size_t off
);
42 /* get grapheme count of the line upto `pos' */
43 int text_line_char_get(Text
*, size_t pos
);
44 /* get position of the `count' grapheme in the line containing `pos' */
45 size_t text_line_char_set(Text
*, size_t pos
, int count
);
46 /* move to the next/previous grapheme on the same line */
47 size_t text_line_char_next(Text
*, size_t pos
);
48 size_t text_line_char_prev(Text
*, size_t pos
);
49 /* move to the next/previous empty line */
50 size_t text_line_empty_next(Text
*, size_t pos
);
51 size_t text_line_empty_prev(Text
*, size_t pos
);
52 /* move to same offset in previous/next line */
53 size_t text_line_up(Text
*, size_t pos
);
54 size_t text_line_down(Text
*, size_t pos
);
55 /* functions to iterate over all line beginnings in a given range */
56 size_t text_range_line_first(Text
*, Filerange
*);
57 size_t text_range_line_last(Text
*, Filerange
*);
58 size_t text_range_line_next(Text
*, Filerange
*, size_t pos
);
59 size_t text_range_line_prev(Text
*, Filerange
*, size_t pos
);
61 * A longword consists of a sequence of non-blank characters, separated with
62 * white space. TODO?: An empty line is also considered to be a word.
63 * This is equivalant to a WORD in vim terminology.
65 size_t text_longword_end_next(Text
*, size_t pos
);
66 size_t text_longword_end_prev(Text
*, size_t pos
);
67 size_t text_longword_start_next(Text
*, size_t pos
);
68 size_t text_longword_start_prev(Text
*, size_t pos
);
70 * A word consists of a sequence of letters, digits and underscores, or a
71 * sequence of other non-blank characters, separated with white space.
72 * TODO?: An empty line is also considered to be a word.
73 * This is equivalant to a word (lowercase) in vim terminology.
75 size_t text_word_end_next(Text
*, size_t pos
);
76 size_t text_word_end_prev(Text
*, size_t pos
);
77 size_t text_word_start_next(Text
*, size_t pos
);
78 size_t text_word_start_prev(Text
*, size_t pos
);
80 * More general versions of the above, define your own word boundaries.
82 size_t text_customword_start_next(Text
*, size_t pos
, int (*isboundary
)(int));
83 size_t text_customword_start_prev(Text
*, size_t pos
, int (*isboundary
)(int));
84 size_t text_customword_end_next(Text
*, size_t pos
, int (*isboundary
)(int));
85 size_t text_customword_end_prev(Text
*, size_t pos
, int (*isboundary
)(int));
86 /* TODO: implement the following semantics
87 * A sentence is defined as ending at a '.', '!' or '?' followed by either the
88 * end of a line, or by a space or tab. Any number of closing ')', ']', '"'
89 * and ''' characters may appear after the '.', '!' or '?' before the spaces,
90 * tabs or end of line. A paragraph and section boundary is also a sentence
93 size_t text_sentence_next(Text
*, size_t pos
);
94 size_t text_sentence_prev(Text
*, size_t pos
);
95 /* TODO: implement the following semantics
96 * A paragraph begins after each empty line. A section boundary is also a
97 * paragraph boundary. Note that a blank line (only containing white space)
98 * is NOT a paragraph boundary.
100 size_t text_paragraph_next(Text
*, size_t pos
);
101 size_t text_paragraph_prev(Text
*, size_t pos
);
102 /* Find next/previous start/end of a C like function definition */
103 size_t text_function_start_next(Text
*, size_t pos
);
104 size_t text_function_start_prev(Text
*, size_t pos
);
105 size_t text_function_end_next(Text
*, size_t pos
);
106 size_t text_function_end_prev(Text
*, size_t pos
);
107 /* A section begins after a form-feed in the first column.
108 size_t text_section_next(Text*, size_t pos);
109 size_t text_section_prev(Text*, size_t pos);
111 /* search coresponding '(', ')', '{', '}', '[', ']', '>', '<', '"', ''' */
112 size_t text_bracket_match(Text
*, size_t pos
);
113 /* same as above but explicitly specify symbols to match */
114 size_t text_bracket_match_symbol(Text
*, size_t pos
, const char *symbols
);
116 /* search the given regex pattern in either forward or backward direction,
117 * starting from pos. does wrap around if no match was found. */
118 size_t text_search_forward(Text
*txt
, size_t pos
, Regex
*regex
);
119 size_t text_search_backward(Text
*txt
, size_t pos
, Regex
*regex
);
121 /* is c a special symbol delimiting a word? */
122 int is_word_boundry(int c
);