vi: move xoff before EOL after motions
[neatvi.git] / vi.h
blobea2d615b3150a9198601723233c2d7d3cfc6700d
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);
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);
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_str(char *s);
108 void term_chr(int ch);
109 void term_pos(int r, int c);
110 void term_clear(void);
111 void term_kill(void);
112 int term_rows(void);
113 int term_cols(void);
114 int term_read(int timeout);
115 void term_record(void);
116 void term_commit(void);
117 char *term_att(int att, int old);
119 #define TK_CTL(x) ((x) & 037)
120 #define TK_INT(c) ((c) < 0 || (c) == TK_ESC || (c) == TK_CTL('c'))
121 #define TK_ESC (TK_CTL('['))
123 /* line-oriented input and output */
124 char *led_prompt(char *pref, char *post, char **kmap);
125 char *led_input(char *pref, char *post, char *ai, int ai_max, char **kmap);
126 char *led_read(char **kmap);
127 void led_print(char *msg, int row);
128 int led_pos(char *s, int pos);
130 /* ex commands */
131 void ex(void);
132 void ex_command(char *cmd);
133 char *ex_read(char *msg);
134 void ex_show(char *msg);
136 /* process management */
137 char *cmd_pipe(char *cmd, char *s);
139 /* syntax highlighting */
140 #define SYN_BD 0x100
141 #define SYN_IT 0x200
142 #define SYN_RV 0x400
143 #define SYN_BGMK(b) ((b) << 16)
144 #define SYN_FG(a) ((a) & 0xffff)
145 #define SYN_BG(a) ((a) >> 16)
147 int *syn_highlight(char *ft, char *s);
148 char *syn_filetype(char *path);
149 void syn_init(void);
150 void syn_done(void);
152 /* configuration variables */
153 char *conf_kmapalt(void);
154 int conf_dirmark(int idx, char **pat, int *ctx, int *dir, int *grp);
155 int conf_dircontext(int idx, char **pat, int *ctx);
156 int conf_placeholder(int idx, char **s, char **d, int *wid);
157 int conf_highlight(int idx, char **ft, int *att, int *grp, char **pat);
158 int conf_filetype(int idx, char **ft, char **pat);
159 int conf_highlight_revdir(int *att);
161 /* global variables */
162 #define PATHLEN 512
164 extern int xvis;
165 extern struct lbuf *xb;
166 extern int xrow;
167 extern int xoff;
168 extern int xtop;
169 extern int xled;
170 extern int xrow_alt;
171 extern char xpath[];
172 extern char xpath_alt[];
173 extern int xquit;
174 extern int xic;
175 extern int xai;
176 extern int xdir;
177 extern int xshape;
178 extern int xorder;
179 extern char xft[];