-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemsys.h
266 lines (243 loc) · 4.46 KB
/
emsys.h
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#ifndef EMSYS_H
#define EMSYS_H 1
#include <stdint.h>
#include <termios.h>
#include <time.h>
#include "config.h"
/*** util ***/
#define EMSYS_TAB_STOP 8
#ifndef EMSYS_VERSION
#define EMSYS_VERSION "unknown"
#endif
#ifndef EMSYS_BUILD_DATE
#define EMSYS_BUILD_DATE "unknown"
#endif
#define ESC "\033"
#define CSI ESC "["
#define CRLF "\r\n"
#define ISCTRL(c) ((0 < c && c < 0x20) || c == 0x7f)
#if !defined(CTRL)
#define CTRL(x) ((x) & 0x1f)
#endif
enum editorKey {
BACKSPACE = 127,
ARROW_LEFT = 1000,
ARROW_RIGHT,
ARROW_UP,
ARROW_DOWN,
HOME_KEY,
DEL_KEY,
END_KEY,
PAGE_UP,
PAGE_DOWN,
UNICODE,
UNICODE_ERROR,
END_OF_FILE,
BEG_OF_FILE,
QUIT,
SAVE,
COPY,
CUT,
REDO,
FORWARD_WORD,
BACKWARD_WORD,
FORWARD_PARA,
BACKWARD_PARA,
SWITCH_BUFFER,
NEXT_BUFFER,
PREVIOUS_BUFFER,
MARK_BUFFER,
DELETE_WORD,
BACKSPACE_WORD,
OTHER_WINDOW,
CREATE_WINDOW,
DESTROY_WINDOW,
DESTROY_OTHER_WINDOWS,
KILL_BUFFER,
MACRO_RECORD,
MACRO_END,
MACRO_EXEC,
ALT_0,
ALT_1,
ALT_2,
ALT_3,
ALT_4,
ALT_5,
ALT_6,
ALT_7,
ALT_8,
ALT_9,
SUSPEND,
UPCASE_WORD,
DOWNCASE_WORD,
CAPCASE_WORD,
UPCASE_REGION,
DOWNCASE_REGION,
TOGGLE_TRUNCATE_LINES,
TRANSPOSE_WORDS,
EXEC_CMD,
FIND_FILE,
WHAT_CURSOR,
PIPE_CMD,
CUSTOM_INFO_MESSAGE,
QUERY_REPLACE,
GOTO_LINE,
BACKTAB,
SWAP_MARK,
JUMP_REGISTER,
MACRO_REGISTER,
POINT_REGISTER,
NUMBER_REGISTER,
REGION_REGISTER,
INC_REGISTER,
INSERT_REGISTER,
VIEW_REGISTER,
STRING_RECT,
COPY_RECT,
KILL_RECT,
YANK_RECT,
RECT_REGISTER,
EXPAND,
UNIVERSAL_ARGUMENT,
};
enum promptType {
PROMPT_BASIC,
PROMPT_FILES,
};
/*** data ***/
typedef struct erow {
int size;
int rsize;
int renderwidth;
uint8_t *chars;
uint8_t *render;
} erow;
struct editorUndo {
struct editorUndo *prev;
int startx;
int starty;
int endx;
int endy;
int append;
int datalen;
int datasize;
int delete;
int paired;
uint8_t *data;
};
struct editorBuffer {
int indent;
int cx, cy;
int markx, marky;
int numrows;
int end;
int dirty;
int uarg;
int uarg_active;
int special_buffer;
int truncate_lines; // 0 for wrapped, 1 for unwrapped
int word_wrap;
erow *row;
char *filename;
uint8_t *query;
uint8_t match;
struct editorUndo *undo;
struct editorUndo *redo;
struct editorBuffer *next;
};
struct editorWindow {
int focused;
struct editorBuffer *buf;
int scx, scy;
int cx, cy; // Buffer cx,cy (only updated when switching windows)
int rowoff;
int coloff;
int height;
};
struct editorMacro {
int *keys;
int nkeys;
int skeys;
};
struct editorConfig;
struct editorCommand {
const char *key;
void (*cmd)(struct editorConfig *, struct editorBuffer *);
};
enum registerType {
REGISTER_NULL,
REGISTER_REGION,
REGISTER_NUMBER,
REGISTER_POINT,
REGISTER_MACRO,
REGISTER_RECTANGLE,
};
struct editorPoint {
int cx;
int cy;
struct editorBuffer *buf;
};
struct editorRectangle {
int rx;
int ry;
uint8_t *rect;
};
union registerData {
uint8_t *region;
int64_t number;
struct editorMacro *macro;
struct editorPoint *point;
struct editorRectangle *rect;
};
struct editorRegister {
enum registerType rtype;
union registerData rdata;
};
struct editorConfig {
uint8_t *kill;
uint8_t *rectKill;
int rx;
int ry;
int screenrows;
int screencols;
uint8_t unicode[4];
int nunicode;
char minibuffer[80];
time_t statusmsg_time;
struct termios orig_termios;
struct editorBuffer *firstBuf;
struct editorBuffer *focusBuf;
int nwindows;
struct editorWindow **windows;
int recording;
struct editorMacro macro;
int playback;
int micro;
struct editorCommand *cmd;
int cmd_count;
struct editorRegister registers[127];
struct editorBuffer *lastVisitedBuffer;
};
/*** prototypes ***/
void editorSetStatusMessage(const char *fmt, ...);
void editorRefreshScreen();
uint8_t *editorPrompt(struct editorBuffer *bufr, uint8_t *prompt,
enum promptType t,
void (*callback)(struct editorBuffer *, uint8_t *, int));
void editorCursorBottomLine(int);
void editorCursorBottomLineLong(long);
void editorUpdateBuffer(struct editorBuffer *buf);
void editorInsertNewline(struct editorBuffer *bufr);
void editorInsertChar(struct editorBuffer *bufr, int c);
void editorOpen(struct editorBuffer *bufr, char *filename);
void die(const char *s);
struct editorBuffer *newBuffer();
void destroyBuffer(struct editorBuffer *);
int editorReadKey();
void editorRecordKey(int c);
void editorRecenter(struct editorWindow *win);
void editorExecMacro(struct editorMacro *macro);
char *stringdup(const char *s);
int windowFocusedIdx(struct editorConfig *ed);
void editorScroll();
#endif