lbuf: store marks for each modification more compactly
[neatvi.git] / vi.h
blobdd9df3c7c6629959b2d2b1c2f697bd677f4daa48
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 beg, int end);
12 void lbuf_wr(struct lbuf *lbuf, int fd, int beg, int end);
13 void lbuf_edit(struct lbuf *lbuf, char *s, int beg, int end);
14 char *lbuf_cp(struct lbuf *lbuf, int beg, int end);
15 char *lbuf_get(struct lbuf *lbuf, int pos);
16 int lbuf_len(struct lbuf *lbuf);
17 void lbuf_mark(struct lbuf *lbuf, int mark, int pos, int off);
18 int lbuf_jump(struct lbuf *lbuf, int mark, int *pos, int *off);
19 int lbuf_undo(struct lbuf *lbuf);
20 int lbuf_redo(struct lbuf *lbuf);
21 int lbuf_modified(struct lbuf *lb);
22 void lbuf_saved(struct lbuf *lb, int clear);
23 int lbuf_indents(struct lbuf *lb, int r);
24 int lbuf_eol(struct lbuf *lb, int r);
25 /* motions */
26 int lbuf_findchar(struct lbuf *lb, char *cs, int cmd, int n, int *r, int *o);
27 int lbuf_search(struct lbuf *lb, char *kw, int dir, int *r, int *o, int *len);
28 int lbuf_paragraphbeg(struct lbuf *lb, int dir, int *row, int *off);
29 int lbuf_sectionbeg(struct lbuf *lb, int dir, int *row, int *off);
30 int lbuf_wordbeg(struct lbuf *lb, int big, int dir, int *row, int *off);
31 int lbuf_wordend(struct lbuf *lb, int big, int dir, int *row, int *off);
32 int lbuf_pair(struct lbuf *lb, int *row, int *off);
34 /* string buffer, variable-sized string */
35 struct sbuf *sbuf_make(void);
36 void sbuf_free(struct sbuf *sb);
37 char *sbuf_done(struct sbuf *sb);
38 char *sbuf_buf(struct sbuf *sb);
39 void sbuf_chr(struct sbuf *sb, int c);
40 void sbuf_str(struct sbuf *sb, char *s);
41 void sbuf_mem(struct sbuf *sb, char *s, int len);
42 void sbuf_printf(struct sbuf *sbuf, char *s, ...);
43 int sbuf_len(struct sbuf *sb);
44 void sbuf_cut(struct sbuf *s, int len);
46 /* regular expression sets */
47 #define RE_ICASE 1
48 #define RE_NOTBOL 2
49 #define RE_NOTEOL 4
51 struct rset *rset_make(int n, char **pat, int flg);
52 int rset_find(struct rset *re, char *s, int n, int *grps, int flg);
53 void rset_free(struct rset *re);
55 /* rendering lines */
56 int *ren_position(char *s);
57 int ren_next(char *s, int p, int dir);
58 int ren_eol(char *s, int dir);
59 int ren_pos(char *s, int off);
60 int ren_cursor(char *s, int pos);
61 int ren_noeol(char *s, int p);
62 int ren_off(char *s, int pos);
63 int ren_wid(char *s);
64 int ren_region(char *s, int c1, int c2, int *l1, int *l2, int closed);
65 char *ren_translate(char *s, char *ln);
66 int ren_cwid(char *s, int pos);
68 /* text direction */
69 int dir_context(char *s);
70 void dir_reorder(char *s, int *ord);
71 void dir_init(void);
72 void dir_done(void);
74 /* string registers */
75 char *reg_get(int c, int *lnmode);
76 void reg_put(int c, char *s, int lnmode);
77 void reg_done(void);
79 /* utf-8 helper functions */
80 int uc_len(char *s);
81 int uc_wid(char *s);
82 int uc_slen(char *s);
83 int uc_code(char *s);
84 char *uc_chr(char *s, int off);
85 int uc_off(char *s, int off);
86 char *uc_sub(char *s, int beg, int end);
87 char *uc_dup(char *s);
88 int uc_isspace(char *s);
89 int uc_isprint(char *s);
90 int uc_isdigit(char *s);
91 int uc_isalpha(char *s);
92 int uc_kind(char *c);
93 char **uc_chop(char *s, int *n);
94 char *uc_next(char *s);
95 char *uc_prev(char *beg, char *s);
96 char *uc_beg(char *beg, char *s);
97 char *uc_end(char *s);
98 char *uc_shape(char *beg, char *s);
99 char *uc_lastline(char *s);
101 /* managing the terminal */
102 #define xrows (term_rows() - 1)
103 #define xcols (term_cols())
105 void term_init(void);
106 void term_done(void);
107 void term_suspend(void);
108 void term_str(char *s);
109 void term_chr(int ch);
110 void term_pos(int r, int c);
111 void term_clear(void);
112 void term_kill(void);
113 void term_room(int n);
114 int term_rows(void);
115 int term_cols(void);
116 int term_read(void);
117 void term_record(void);
118 void term_commit(void);
119 char *term_att(int att, int old);
120 void term_push(char *s, int n);
121 char *term_cmd(int *n);
123 #define TK_CTL(x) ((x) & 037)
124 #define TK_INT(c) ((c) < 0 || (c) == TK_ESC || (c) == TK_CTL('c'))
125 #define TK_ESC (TK_CTL('['))
127 /* line-oriented input and output */
128 char *led_prompt(char *pref, char *post, char **kmap);
129 char *led_input(char *pref, char *post, char **kmap);
130 char *led_read(char **kmap);
131 void led_print(char *msg, int row);
132 int led_pos(char *s, int pos);
134 /* ex commands */
135 void ex(void);
136 void ex_command(char *cmd);
137 char *ex_read(char *msg);
138 void ex_print(char *line);
139 void ex_show(char *msg);
140 int ex_init(char **files);
141 void ex_done(void);
142 char *ex_path(void);
143 char *ex_filetype(void);
144 char **ex_kmap(void);
145 char *ex_kmapalt(void);
146 struct lbuf *ex_lbuf(void);
148 #define xb ex_lbuf()
150 /* process management */
151 char *cmd_pipe(char *cmd, char *s, int iproc, int oproc);
152 int cmd_exec(char *cmd);
154 /* syntax highlighting */
155 #define SYN_BD 0x010000
156 #define SYN_IT 0x020000
157 #define SYN_RV 0x040000
158 #define SYN_FGMK(f) (0x100000 | (f))
159 #define SYN_BGMK(b) (0x200000 | ((b) << 8))
161 #define SYN_FLG 0xff0000
162 #define SYN_FGSET(a) ((a) & 0x1000ff)
163 #define SYN_BGSET(a) ((a) & 0x20ff00)
164 #define SYN_FG(a) ((a) & 0xff)
165 #define SYN_BG(a) (((a) >> 8) & 0xff)
167 int *syn_highlight(char *ft, char *s);
168 char *syn_filetype(char *path);
169 int syn_merge(int old, int new);
170 void syn_init(void);
171 void syn_done(void);
173 /* configuration variables */
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);
180 char **conf_kmap(char *name);
181 char *conf_digraph(int c1, int c2);
183 /* global variables */
184 extern int xrow;
185 extern int xoff;
186 extern int xtop;
187 extern int xleft;
188 extern int xvis;
189 extern int xled;
190 extern int xquit;
191 extern int xic;
192 extern int xai;
193 extern int xdir;
194 extern int xshape;
195 extern int xorder;
196 extern int xhl;
198 #define EXLEN 512 /* ex line length */
200 extern char xfindkwd[EXLEN];
201 extern int xfinddir;