Fix and change for scroll at the end of the line.
[eco.git] / buffer.h
blob3280ce2a42d343977fb357f294a9bf5fdcf84806
1 /*
2 * Copyright (C) 2008 Diego Hernan Borghetti.
3 * Eco
4 */
6 #ifndef _ECO_BUFFER_H
7 #define _ECO_BUFFER_H
9 struct E_File_Path;
11 typedef struct _E_Line {
12 struct _E_Line *next;
13 struct _E_Line *prev;
15 /* line flags. */
16 char flag;
18 /* chunk of text. */
19 char *text;
21 /* chunk size. */
22 int size;
24 /* memory used. */
25 int used;
26 } E_Line;
28 typedef struct _E_Buffer {
29 struct _E_Buffer *next;
31 /* file paths. */
32 struct E_File_Path *paths;
34 /* file name or untitled */
35 char *name;
37 /* line list. */
38 E_Line *lines;
40 /* "top-level" line. */
41 E_Line *first;
43 /* current "edit" line. */
44 E_Line *line;
46 /* cursor position in the "current line" */
47 short dot;
49 /* real pad for big lines. */
50 short dot_pad;
52 /* buffer flags. */
53 char flag;
55 /* number of lines in this buffer. */
56 int nlines;
58 /* current line number. */
59 int nl;
60 } E_Buffer;
62 /* buffer->flag */
63 #define BUFFER_FLUSH (1<<0)
64 #define BUFFER_CMODE (1<<1)
65 #define BUFFER_UP (1<<2)
66 #define BUFFER_DOWN (1<<3)
68 /* buffer search mode. */
69 #define BUFFER_SEARCH_FORWARD 0
70 #define BUFFER_SEARCH_BACKWARD 1
72 /* set/unset buffer flags */
73 #define BUFFER_SET(b, f) \
74 if (!(b->flag & f)) \
75 b->flag|= (f)
77 #define BUFFER_UNSET(b, f) \
78 if (b->flag & f) \
79 b->flag&= ~(f)
81 E_Buffer *e_buffer_new(char *file);
82 void e_buffer_free(E_Buffer *bf);
84 void e_buffer_newline(E_Buffer *bf);
85 void e_buffer_newline_first(E_Buffer *bf);
86 void e_buffer_joinline(E_Buffer *bf);
87 void e_buffer_splitline(E_Buffer *bf);
88 void e_buffer_cleanline(E_Buffer *bf);
89 void e_buffer_insert(E_Buffer *bf, int c);
90 void e_buffer_backspace(E_Buffer *bf);
91 void e_buffer_del(E_Buffer *bf);
92 void e_buffer_killline(E_Buffer *bf, int cut);
94 void e_buffer_up(E_Buffer *bf);
95 void e_buffer_down(E_Buffer *bf);
96 void e_buffer_left(E_Buffer *bf);
97 void e_buffer_right(E_Buffer *bf);
99 void e_buffer_goto(E_Buffer *bf, int line);
100 void e_buffer_goto_begin(E_Buffer *bf);
101 void e_buffer_goto_end(E_Buffer *bf);
102 void e_buffer_bol(E_Buffer *bf);
103 void e_buffer_eol(E_Buffer *bf);
104 void e_buffer_scroll(E_Buffer *bf, int nline, int dir);
106 void e_buffer_search(E_Buffer *bf, char *pattern, int dir);
107 int e_buffer_replace(E_Buffer *bf, char *pattern, char *replace);
109 #endif /* _ECO_BUFFER_H */