mot: skipping zero-length matches in lbuf_search()
[neatvi.git] / vi.h
blob2b2afdfcda20db0d07ecaf52f07531f797f40ca7
1 /* neatvi main header */
3 /* helper macros */
4 #define LEN(a) (sizeof(a) / sizeof((a)[0]))
5 #define MIN(a, b) ((a) < (b) ? (a) : (b))
6 #define MAX(a, b) ((a) < (b) ? (b) : (a))
8 /* line buffer, managing a number of lines */
9 struct lbuf *lbuf_make(void);
10 void lbuf_free(struct lbuf *lbuf);
11 void lbuf_rd(struct lbuf *lbuf, int fd, int pos);
12 void lbuf_wr(struct lbuf *lbuf, int fd, int beg, int end);
13 void lbuf_rm(struct lbuf *lbuf, int beg, int end);
14 char *lbuf_cp(struct lbuf *lbuf, int beg, int end);
15 void lbuf_put(struct lbuf *lbuf, int pos, char *s);
16 char *lbuf_get(struct lbuf *lbuf, int pos);
17 int lbuf_len(struct lbuf *lbuf);
18 void lbuf_mark(struct lbuf *lbuf, int mark, int pos, int off);
19 int lbuf_jump(struct lbuf *lbuf, int mark, int *pos, int *off);
20 int lbuf_undo(struct lbuf *lbuf);
21 int lbuf_redo(struct lbuf *lbuf);
22 int lbuf_modified(struct lbuf *lb);
23 void lbuf_saved(struct lbuf *lb, int clear);
24 int lbuf_indents(struct lbuf *lb, int r);
25 int lbuf_eol(struct lbuf *lb, int r);
26 /* motions */
27 int lbuf_findchar(struct lbuf *lb, char *cs, int cmd, int n, int *r, int *o);
28 int lbuf_search(struct lbuf *lb, char *kw, int dir, int *r, int *o, int *len);
29 int lbuf_paragraphbeg(struct lbuf *lb, int dir, int *row, int *off);
30 int lbuf_sectionbeg(struct lbuf *lb, int dir, int *row, int *off);
31 int lbuf_wordbeg(struct lbuf *lb, int big, int dir, int *row, int *off);
32 int lbuf_wordend(struct lbuf *lb, int big, int dir, int *row, int *off);
33 int lbuf_pair(struct lbuf *lb, int *row, int *off);
35 /* string buffer, variable-sized string */
36 struct sbuf *sbuf_make(void);
37 void sbuf_free(struct sbuf *sb);
38 char *sbuf_done(struct sbuf *sb);
39 char *sbuf_buf(struct sbuf *sb);
40 void sbuf_chr(struct sbuf *sb, int c);
41 void sbuf_str(struct sbuf *sb, char *s);
42 void sbuf_mem(struct sbuf *sb, char *s, int len);
43 void sbuf_printf(struct sbuf *sbuf, char *s, ...);
44 int sbuf_len(struct sbuf *sb);
45 void sbuf_cut(struct sbuf *s, int len);
47 /* regular expression sets */
48 #define RE_ICASE 1
49 #define RE_NOTBOL 2
50 #define RE_NOTEOL 4
52 struct rset *rset_make(int n, char **pat, int flg);
53 int rset_find(struct rset *re, char *s, int n, int *grps, int flg);
54 void rset_free(struct rset *re);
56 /* rendering lines */
57 int *ren_position(char *s);
58 int ren_next(char *s, int p, int dir);
59 int ren_eol(char *s, int dir);
60 int ren_pos(char *s, int off);
61 int ren_cursor(char *s, int pos);
62 int ren_noeol(char *s, int p);
63 int ren_off(char *s, int pos);
64 int ren_wid(char *s);
65 int ren_region(char *s, int c1, int c2, int *l1, int *l2, int closed);
66 char *ren_translate(char *s, char *ln);
67 int ren_cwid(char *s, int pos);
69 /* text direction */
70 int dir_context(char *s);
71 void dir_reorder(char *s, int *ord);
72 void dir_init(void);
73 void dir_done(void);
75 /* string registers */
76 char *reg_get(int c, int *lnmode);
77 void reg_put(int c, char *s, int lnmode);
78 void reg_done(void);
80 /* utf-8 helper functions */
81 int uc_len(char *s);
82 int uc_wid(char *s);
83 int uc_slen(char *s);
84 int uc_code(char *s);
85 char *uc_chr(char *s, int off);
86 int uc_off(char *s, int off);
87 char *uc_sub(char *s, int beg, int end);
88 char *uc_dup(char *s);
89 int uc_isspace(char *s);
90 int uc_isprint(char *s);
91 int uc_isdigit(char *s);
92 int uc_isalpha(char *s);
93 int uc_kind(char *c);
94 char **uc_chop(char *s, int *n);
95 char *uc_next(char *s);
96 char *uc_prev(char *beg, char *s);
97 char *uc_beg(char *beg, char *s);
98 char *uc_end(char *s);
99 char *uc_shape(char *beg, char *s);
100 char *uc_lastline(char *s);
102 /* managing the terminal */
103 #define xrows (term_rows() - 1)
104 #define xcols (term_cols())
106 void term_init(void);
107 void term_done(void);
108 void term_suspend(void);
109 void term_str(char *s);
110 void term_chr(int ch);
111 void term_pos(int r, int c);
112 void term_clear(void);
113 void term_kill(void);
114 void term_room(int n);
115 int term_rows(void);
116 int term_cols(void);
117 int term_read(void);
118 void term_record(void);
119 void term_commit(void);
120 char *term_att(int att, int old);
121 void term_push(char *s, int n);
122 char *term_cmd(int *n);
124 #define TK_CTL(x) ((x) & 037)
125 #define TK_INT(c) ((c) < 0 || (c) == TK_ESC || (c) == TK_CTL('c'))
126 #define TK_ESC (TK_CTL('['))
128 /* line-oriented input and output */
129 char *led_prompt(char *pref, char *post, char **kmap);
130 char *led_input(char *pref, char *post, char *ai, int ai_max, char **kmap);
131 char *led_read(char **kmap);
132 void led_print(char *msg, int row);
133 int led_pos(char *s, int pos);
135 /* ex commands */
136 void ex(void);
137 void ex_command(char *cmd);
138 char *ex_read(char *msg);
139 void ex_print(char *line);
140 void ex_show(char *msg);
141 int ex_init(char **files);
142 void ex_done(void);
143 char *ex_path(void);
144 char *ex_filetype(void);
145 struct lbuf *ex_lbuf(void);
147 #define xb ex_lbuf()
149 /* process management */
150 char *cmd_pipe(char *cmd, char *s, int iproc, int oproc);
151 int cmd_exec(char *cmd);
153 /* syntax highlighting */
154 #define SYN_BD 0x010000
155 #define SYN_IT 0x020000
156 #define SYN_RV 0x040000
157 #define SYN_FGMK(f) (0x100000 | (f))
158 #define SYN_BGMK(b) (0x200000 | ((b) << 8))
160 #define SYN_FLG 0xff0000
161 #define SYN_FGSET(a) ((a) & 0x1000ff)
162 #define SYN_BGSET(a) ((a) & 0x20ff00)
163 #define SYN_FG(a) ((a) & 0xff)
164 #define SYN_BG(a) (((a) >> 8) & 0xff)
166 int *syn_highlight(char *ft, char *s);
167 char *syn_filetype(char *path);
168 int syn_merge(int old, int new);
169 void syn_init(void);
170 void syn_done(void);
172 /* configuration variables */
173 char *conf_kmapalt(void);
174 int conf_dirmark(int idx, char **pat, int *ctx, int *dir, int *grp);
175 int conf_dircontext(int idx, char **pat, int *ctx);
176 int conf_placeholder(int idx, char **s, char **d, int *wid);
177 int conf_highlight(int idx, char **ft, int **att, char **pat, int *end);
178 int conf_filetype(int idx, char **ft, char **pat);
179 int conf_highlight_revdir(int *att);
181 /* global variables */
182 extern int xrow;
183 extern int xoff;
184 extern int xtop;
185 extern int xvis;
186 extern int xled;
187 extern int xquit;
188 extern int xic;
189 extern int xai;
190 extern int xdir;
191 extern int xshape;
192 extern int xorder;
193 extern int xhl;
195 #define EXLEN 512 /* ex line length */
197 extern char xfindkwd[EXLEN];
198 extern int xfinddir;