vi: use ren_noeol() in vc_replace()
[neatvi.git] / vi.h
blobe331525240961632b38d1a1d554248ebaa5c2d4e
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);
19 int lbuf_markpos(struct lbuf *lbuf, int mark);
20 void lbuf_undo(struct lbuf *lbuf);
21 void lbuf_redo(struct lbuf *lbuf);
22 void lbuf_undomark(struct lbuf *lbuf);
23 void lbuf_undofree(struct lbuf *lbuf);
25 /* string buffer, variable-sized string */
26 struct sbuf *sbuf_make(void);
27 void sbuf_free(struct sbuf *sb);
28 char *sbuf_done(struct sbuf *sb);
29 char *sbuf_buf(struct sbuf *sb);
30 void sbuf_chr(struct sbuf *sb, int c);
31 void sbuf_str(struct sbuf *sb, char *s);
32 void sbuf_mem(struct sbuf *sb, char *s, int len);
33 void sbuf_printf(struct sbuf *sbuf, char *s, ...);
34 int sbuf_len(struct sbuf *sb);
35 void sbuf_cut(struct sbuf *s, int len);
37 /* regular expression sets */
38 #define RE_ICASE 1
39 #define RE_NOTBOL 2
40 #define RE_NOTEOL 4
42 struct rset *rset_make(int n, char **pat, int flg);
43 int rset_find(struct rset *re, char *s, int n, int *grps, int flg);
44 void rset_free(struct rset *re);
46 /* rendering lines */
47 int *ren_position(char *s);
48 int ren_next(char *s, int p, int dir);
49 int ren_eol(char *s, int dir);
50 int ren_pos(char *s, int off);
51 int ren_cursor(char *s, int pos);
52 int ren_noeol(char *s, int p);
53 int ren_off(char *s, int pos);
54 int ren_wid(char *s);
55 int ren_region(char *s, int c1, int c2, int *l1, int *l2, int closed);
56 char *ren_translate(char *s, char *ln);
57 int ren_cwid(char *s, int pos);
59 /* text direction */
60 int dir_context(char *s);
61 void dir_reorder(char *s, int *ord);
62 void dir_init(void);
63 void dir_done(void);
65 /* string registers */
66 char *reg_get(int c, int *lnmode);
67 void reg_put(int c, char *s, int lnmode);
68 void reg_done(void);
70 /* utf-8 helper functions */
71 int uc_len(char *s);
72 int uc_wid(char *s);
73 int uc_slen(char *s);
74 int uc_code(char *s);
75 char *uc_chr(char *s, int off);
76 int uc_off(char *s, int off);
77 char *uc_sub(char *s, int beg, int end);
78 char *uc_dup(char *s);
79 int uc_isspace(char *s);
80 int uc_isprint(char *s);
81 int uc_isdigit(char *s);
82 int uc_isalpha(char *s);
83 int uc_kind(char *c);
84 char **uc_chop(char *s, int *n);
85 char *uc_next(char *s);
86 char *uc_beg(char *beg, char *s);
87 char *uc_end(char *beg, char *s);
88 char *uc_shape(char *beg, char *s);
90 /* managing the terminal */
91 #define xrows (term_rows() - 1)
92 #define xcols (term_cols())
94 void term_init(void);
95 void term_done(void);
96 void term_str(char *s);
97 void term_chr(int ch);
98 void term_pos(int r, int c);
99 void term_clear(void);
100 void term_kill(void);
101 int term_rows(void);
102 int term_cols(void);
103 int term_read(int timeout);
104 void term_record(void);
105 void term_commit(void);
106 char *term_att(int att, int old);
108 #define TK_CTL(x) ((x) & 037)
109 #define TK_INT(c) ((c) < 0 || (c) == TK_ESC || (c) == TK_CTL('c'))
110 #define TK_ESC (TK_CTL('['))
112 /* line-oriented input and output */
113 char *led_prompt(char *pref, char *post, char **kmap);
114 char *led_input(char *pref, char *post, char *ai, int ai_max, char **kmap);
115 void led_print(char *msg, int row);
116 char *led_keymap(char *kmap, int c);
117 int led_pos(char *s, int pos);
119 /* ex commands */
120 void ex(void);
121 void ex_command(char *cmd);
122 char *ex_read(char *msg);
123 void ex_show(char *msg);
125 /* process management */
126 char *cmd_pipe(char *cmd, char *s);
128 /* syntax highlighting */
129 #define SYN_BD 0x100
130 #define SYN_IT 0x200
131 #define SYN_RV 0x400
132 #define SYN_ATTR(f, b) (((b) << 16) | (f))
133 #define SYN_FG(a) ((a) & 0xffff)
134 #define SYN_BG(a) ((a) >> 16)
136 int *syn_highlight(char *ft, char *s);
137 char *syn_filetype(char *path);
138 void syn_init(void);
139 void syn_done(void);
141 /* configuration variables */
142 char *conf_kmapalt(void);
143 int conf_dirmark(int idx, char **pat, int *ctx, int *dir, int *grp);
144 int conf_dircontext(int idx, char **pat, int *ctx);
145 int conf_placeholder(int idx, char **s, char **d, int *wid);
146 int conf_highlight(int idx, char **ft, int *att, int *grp, char **pat);
147 int conf_filetype(int idx, char **ft, char **pat);
149 /* global variables */
150 #define PATHLEN 512
152 extern int xvis;
153 extern struct lbuf *xb;
154 extern int xrow;
155 extern int xcol;
156 extern int xtop;
157 extern int xled;
158 extern int xrow_alt;
159 extern char xpath[];
160 extern char xpath_alt[];
161 extern int xquit;
162 extern int xic;
163 extern int xai;
164 extern int xdir;
165 extern int xshape;
166 extern int xorder;
167 extern char xft[];