vis: implement :set cursorline
[vis.git] / text-motions.h
blobd65bdf234bfadf46ae6b0cb7df7af655e50422ac
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 /* move to start of next / previous UTF-8 character */
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
29 * v v v v
30 * [\r]\n I am a line! [\r]\n
31 * ^ ^ ^
32 * prev start lastchar
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 character count of the line upto `pos' */
43 int text_line_char_get(Text*, size_t pos);
44 /* get position of the `count' character in the line containing `pos' */
45 size_t text_line_char_set(Text*, size_t pos, int count);
46 /* move to the next/previous character 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);
79 /* TODO: implement the following semantics
80 * A sentence is defined as ending at a '.', '!' or '?' followed by either the
81 * end of a line, or by a space or tab. Any number of closing ')', ']', '"'
82 * and ''' characters may appear after the '.', '!' or '?' before the spaces,
83 * tabs or end of line. A paragraph and section boundary is also a sentence
84 * boundary.
86 size_t text_sentence_next(Text*, size_t pos);
87 size_t text_sentence_prev(Text*, size_t pos);
88 /* TODO: implement the following semantics
89 * A paragraph begins after each empty line. A section boundary is also a
90 * paragraph boundary. Note that a blank line (only containing white space)
91 * is NOT a paragraph boundary.
93 size_t text_paragraph_next(Text*, size_t pos);
94 size_t text_paragraph_prev(Text*, size_t pos);
95 /* Find next/previous start/end of a C like function definition */
96 size_t text_function_start_next(Text*, size_t pos);
97 size_t text_function_start_prev(Text*, size_t pos);
98 size_t text_function_end_next(Text*, size_t pos);
99 size_t text_function_end_prev(Text*, size_t pos);
100 /* A section begins after a form-feed in the first column.
101 size_t text_section_next(Text*, size_t pos);
102 size_t text_section_prev(Text*, size_t pos);
104 /* search coresponding '(', ')', '{', '}', '[', ']', '>', '<', '"', ''' */
105 size_t text_bracket_match(Text*, size_t pos);
106 /* same as above but ignore symbols contained in last argument */
107 size_t text_bracket_match_except(Text*, size_t pos, const char *except);
109 /* search the given regex pattern in either forward or backward direction,
110 * starting from pos. does wrap around if no match was found. */
111 size_t text_search_forward(Text *txt, size_t pos, Regex *regex);
112 size_t text_search_backward(Text *txt, size_t pos, Regex *regex);
114 /* is c a special symbol delimiting a word? */
115 int is_word_boundry(int c);
117 #endif