text: remove text_iterate macro
[vis.git] / text-motions.h
blobe5f76bd472d9d700878c341523b34a0a5df5cc22
1 #ifndef TEXT_MOTIONS_H
2 #define TEXT_MOTIONS_H
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. */
8 #include <stddef.h>
9 #include "text.h"
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 size_t text_codepoint_next(Text*, size_t pos);
20 size_t text_codepoint_prev(Text*, size_t pos);
22 /* find the given substring either in forward or backward direction.
23 * does not wrap around at file start / end. if no match is found return
24 * original position */
25 size_t text_find_next(Text*, size_t pos, const char *s);
26 size_t text_find_prev(Text*, size_t pos, const char *s);
27 /* same as above but limit searched range to the line containing pos */
28 size_t text_line_find_next(Text*, size_t pos, const char *s);
29 size_t text_line_find_prev(Text*, size_t pos, const char *s);
31 /* begin finish next
32 * v v v
33 * \n I am a line! \n
34 * ^ ^ ^
35 * prev start end
37 size_t text_line_prev(Text*, size_t pos);
38 size_t text_line_begin(Text*, size_t pos);
39 size_t text_line_start(Text*, size_t pos);
40 size_t text_line_finish(Text*, size_t pos);
41 size_t text_line_end(Text*, size_t pos);
42 size_t text_line_next(Text*, size_t pos);
43 size_t text_line_offset(Text*, size_t pos, size_t off);
44 /* get grapheme count of the line upto `pos' */
45 int text_line_char_get(Text*, size_t pos);
46 /* get position of the `count' grapheme in the line containing `pos' */
47 size_t text_line_char_set(Text*, size_t pos, int count);
48 /* get display width of line upto `pos' */
49 int text_line_width_get(Text*, size_t pos);
50 /* get position of character being displayed at `width' in line containing `pos' */
51 size_t text_line_width_set(Text*, size_t pos, int width);
52 /* move to the next/previous grapheme on the same line */
53 size_t text_line_char_next(Text*, size_t pos);
54 size_t text_line_char_prev(Text*, size_t pos);
55 /* move to the next/previous empty line */
56 size_t text_line_empty_next(Text*, size_t pos);
57 size_t text_line_empty_prev(Text*, size_t pos);
58 /* move to same offset in previous/next line */
59 size_t text_line_up(Text*, size_t pos);
60 size_t text_line_down(Text*, size_t pos);
61 /* functions to iterate over all line beginnings in a given range */
62 size_t text_range_line_first(Text*, Filerange*);
63 size_t text_range_line_last(Text*, Filerange*);
64 size_t text_range_line_next(Text*, Filerange*, size_t pos);
65 size_t text_range_line_prev(Text*, Filerange*, size_t pos);
67 * A longword consists of a sequence of non-blank characters, separated with
68 * white space. TODO?: An empty line is also considered to be a word.
69 * This is equivalant to a WORD in vim terminology.
71 size_t text_longword_end_next(Text*, size_t pos);
72 size_t text_longword_end_prev(Text*, size_t pos);
73 size_t text_longword_start_next(Text*, size_t pos);
74 size_t text_longword_start_prev(Text*, size_t pos);
76 * A word consists of a sequence of letters, digits and underscores, or a
77 * sequence of other non-blank characters, separated with white space.
78 * TODO?: An empty line is also considered to be a word.
79 * This is equivalant to a word (lowercase) in vim terminology.
81 size_t text_word_end_next(Text*, size_t pos);
82 size_t text_word_end_prev(Text*, size_t pos);
83 size_t text_word_start_next(Text*, size_t pos);
84 size_t text_word_start_prev(Text*, size_t pos);
86 * More general versions of the above, define your own word boundaries.
88 size_t text_customword_start_next(Text*, size_t pos, int (*isboundary)(int));
89 size_t text_customword_start_prev(Text*, size_t pos, int (*isboundary)(int));
90 size_t text_customword_end_next(Text*, size_t pos, int (*isboundary)(int));
91 size_t text_customword_end_prev(Text*, size_t pos, int (*isboundary)(int));
92 /* TODO: implement the following semantics
93 * A sentence is defined as ending at a '.', '!' or '?' followed by either the
94 * end of a line, or by a space or tab. Any number of closing ')', ']', '"'
95 * and ''' characters may appear after the '.', '!' or '?' before the spaces,
96 * tabs or end of line. A paragraph and section boundary is also a sentence
97 * boundary.
99 size_t text_sentence_next(Text*, size_t pos);
100 size_t text_sentence_prev(Text*, size_t pos);
101 /* TODO: implement the following semantics
102 * A paragraph begins after each empty line. A section boundary is also a
103 * paragraph boundary. Note that a blank line (only containing white space)
104 * is NOT a paragraph boundary.
106 size_t text_paragraph_next(Text*, size_t pos);
107 size_t text_paragraph_prev(Text*, size_t pos);
108 /* A section begins after a form-feed in the first column.
109 size_t text_section_next(Text*, size_t pos);
110 size_t text_section_prev(Text*, size_t pos);
112 size_t text_block_start(Text*, size_t pos);
113 size_t text_block_end(Text*, size_t pos);
114 size_t text_parenthese_start(Text*, size_t pos);
115 size_t text_parenthese_end(Text*, size_t pos);
116 /* search coresponding '(', ')', '{', '}', '[', ']', '>', '<', '"', ''' */
117 size_t text_bracket_match(Text*, size_t pos);
118 /* same as above but explicitly specify symbols to match */
119 size_t text_bracket_match_symbol(Text*, size_t pos, const char *symbols);
121 /* search the given regex pattern in either forward or backward direction,
122 * starting from pos. does wrap around if no match was found. */
123 size_t text_search_forward(Text *txt, size_t pos, Regex *regex);
124 size_t text_search_backward(Text *txt, size_t pos, Regex *regex);
126 /* is c a special symbol delimiting a word? */
127 int is_word_boundary(int c);
129 #endif