aboutsummaryrefslogtreecommitdiff
path: root/text-motions.h
blob: 84f6eccb04b4de7ba7d207c6e6442b11f022c525 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef TEXT_MOTIONS_H
#define TEXT_MOTIONS_H

/* these function all take a position in bytes from the start of the file,
 * perform a certain movement and return the new postion. if the movement
 * is not possible the original position is returned unchanged. */

#include <stddef.h>
#include "text.h"

size_t text_begin(Text*, size_t pos);
size_t text_end(Text*, size_t pos);

/* move to start of next / previous UTF-8 character */
size_t text_char_next(Text*, size_t pos);
size_t text_char_prev(Text*, size_t pos);

/* find the given substring either in forward or backward direction.
 * does not wrap around at file start / end. */
size_t text_find_char_next(Text*, size_t pos, const char *s, size_t len);
size_t text_find_char_prev(Text*, size_t pos, const char *s, size_t len);

/*        begin            finish        next
 *        v                v             v
 *  \n[\r]      I am a line!       \n[\r]
 *              ^                  ^
 *              start              end
 */
size_t text_line_begin(Text*, size_t pos);
size_t text_line_start(Text*, size_t pos);
size_t text_line_finish(Text*, size_t pos);
size_t text_line_end(Text*, size_t pos);
size_t text_line_next(Text*, size_t pos);
/*
 * A word consists of a sequence of non-blank characters, separated with white
 * space. TODO?: An empty line is also considered to be a word.
 * This is equivalant to a WORD in vim terminology.
 */
size_t text_word_end_next(Text*, size_t pos);
size_t text_word_end_prev(Text*, size_t pos);
size_t text_word_start_next(Text*, size_t pos);
size_t text_word_start_prev(Text*, size_t pos);
/*
 * These are variants of the above with the additional possibility to implement
 * a custom word detection logic. Can be used to implment the equivalent of a
 * what vim reconizes as a word (lowercase).
 */
size_t text_word_boundry_end_next(Text*, size_t pos, int (*isboundry)(int));
size_t text_word_boundry_end_prev(Text*, size_t pos, int (*isboundry)(int));
size_t text_word_boundry_start_next(Text*, size_t pos, int (*isboundry)(int));
size_t text_word_boundry_start_prev(Text*, size_t pos, int (*isboundry)(int));
/* TODO: implement the following semantics
 * A sentence is defined as ending at a '.', '!' or '?' followed by either the
 * end of a line, or by a space or tab.  Any number of closing ')', ']', '"'
 * and ''' characters may appear after the '.', '!' or '?' before the spaces,
 * tabs or end of line.  A paragraph and section boundary is also a sentence
 * boundary.
 */
size_t text_sentence_next(Text*, size_t pos);
size_t text_sentence_prev(Text*, size_t pos);
/* TODO: implement the following semantics
 * A paragraph begins after each empty line. A section boundary is also a
 * paragraph boundary. Note that a blank line (only containing white space)
 * is NOT a paragraph boundary.
 */
size_t text_paragraph_next(Text*, size_t pos);
size_t text_paragraph_prev(Text*, size_t pos);
/* A section begins after a form-feed in the first column.
size_t text_section_next(Text*, size_t pos);
size_t text_section_prev(Text*, size_t pos);
*/
/* search coresponding '(', ')', '{', '}', '[', ']', '>', '<', '"', ''' */
size_t text_bracket_match(Text*, size_t pos);

/* search the given regex pattern in either forward or backward direction,
 * starting from pos. does wrap around if no match was found. */
size_t text_search_forward(Text *txt, size_t pos, Regex *regex);
size_t text_search_backward(Text *txt, size_t pos, Regex *regex);

#endif