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 /* get display width of line upto `pos' */
47 int text_line_width_get(Text
*, size_t pos
);
48 /* get position of character being displayed at `width' in line containing `pos' */
49 size_t text_line_width_set(Text
*, size_t pos
, int width
);
50 /* move to the next/previous grapheme on the same line */
51 size_t text_line_char_next(Text
*, size_t pos
);
52 size_t text_line_char_prev(Text
*, size_t pos
);
53 /* move to the next/previous empty line */
54 size_t text_line_empty_next(Text
*, size_t pos
);
55 size_t text_line_empty_prev(Text
*, size_t pos
);
56 /* move to same offset in previous/next line */
57 size_t text_line_up(Text
*, size_t pos
);
58 size_t text_line_down(Text
*, size_t pos
);
59 /* functions to iterate over all line beginnings in a given range */
60 size_t text_range_line_first(Text
*, Filerange
*);
61 size_t text_range_line_last(Text
*, Filerange
*);
62 size_t text_range_line_next(Text
*, Filerange
*, size_t pos
);
63 size_t text_range_line_prev(Text
*, Filerange
*, size_t pos
);
65 * A longword consists of a sequence of non-blank characters, separated with
66 * white space. TODO?: An empty line is also considered to be a word.
67 * This is equivalant to a WORD in vim terminology.
69 size_t text_longword_end_next(Text
*, size_t pos
);
70 size_t text_longword_end_prev(Text
*, size_t pos
);
71 size_t text_longword_start_next(Text
*, size_t pos
);
72 size_t text_longword_start_prev(Text
*, size_t pos
);
74 * A word consists of a sequence of letters, digits and underscores, or a
75 * sequence of other non-blank characters, separated with white space.
76 * TODO?: An empty line is also considered to be a word.
77 * This is equivalant to a word (lowercase) in vim terminology.
79 size_t text_word_end_next(Text
*, size_t pos
);
80 size_t text_word_end_prev(Text
*, size_t pos
);
81 size_t text_word_start_next(Text
*, size_t pos
);
82 size_t text_word_start_prev(Text
*, size_t pos
);
84 * More general versions of the above, define your own word boundaries.
86 size_t text_customword_start_next(Text
*, size_t pos
, int (*isboundary
)(int));
87 size_t text_customword_start_prev(Text
*, size_t pos
, int (*isboundary
)(int));
88 size_t text_customword_end_next(Text
*, size_t pos
, int (*isboundary
)(int));
89 size_t text_customword_end_prev(Text
*, size_t pos
, int (*isboundary
)(int));
90 /* TODO: implement the following semantics
91 * A sentence is defined as ending at a '.', '!' or '?' followed by either the
92 * end of a line, or by a space or tab. Any number of closing ')', ']', '"'
93 * and ''' characters may appear after the '.', '!' or '?' before the spaces,
94 * tabs or end of line. A paragraph and section boundary is also a sentence
97 size_t text_sentence_next(Text
*, size_t pos
);
98 size_t text_sentence_prev(Text
*, size_t pos
);
99 /* TODO: implement the following semantics
100 * A paragraph begins after each empty line. A section boundary is also a
101 * paragraph boundary. Note that a blank line (only containing white space)
102 * is NOT a paragraph boundary.
104 size_t text_paragraph_next(Text
*, size_t pos
);
105 size_t text_paragraph_prev(Text
*, size_t pos
);
106 /* Find next/previous start/end of a C like function definition */
107 size_t text_function_start_next(Text
*, size_t pos
);
108 size_t text_function_start_prev(Text
*, size_t pos
);
109 size_t text_function_end_next(Text
*, size_t pos
);
110 size_t text_function_end_prev(Text
*, size_t pos
);
111 /* A section begins after a form-feed in the first column.
112 size_t text_section_next(Text*, size_t pos);
113 size_t text_section_prev(Text*, size_t pos);
115 /* search coresponding '(', ')', '{', '}', '[', ']', '>', '<', '"', ''' */
116 size_t text_bracket_match(Text
*, size_t pos
);
117 /* same as above but explicitly specify symbols to match */
118 size_t text_bracket_match_symbol(Text
*, size_t pos
, const char *symbols
);
120 /* search the given regex pattern in either forward or backward direction,
121 * starting from pos. does wrap around if no match was found. */
122 size_t text_search_forward(Text
*txt
, size_t pos
, Regex
*regex
);
123 size_t text_search_backward(Text
*txt
, size_t pos
, Regex
*regex
);
125 /* is c a special symbol delimiting a word? */
126 int is_word_boundry(int c
);