summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-02 00:18:46 -0500
committerpommicket <pommicket@gmail.com>2023-01-02 00:18:46 -0500
commit636ea84bc7fa738c179168664ea22118ecc89ab3 (patch)
treef0e811c08533d21fddaa2d4aaa7193257890e0d4
parent43b8a9cb106d50265f5a6c1307e77d4642710f07 (diff)
restructure ted.c, node.c
-rw-r--r--find.c4
-rw-r--r--gl.c9
-rw-r--r--main.c14
-rw-r--r--node.c35
-rw-r--r--ted.c6
-rw-r--r--ted.h52
6 files changed, 83 insertions, 37 deletions
diff --git a/find.c b/find.c
index fc53f95..78ec85e 100644
--- a/find.c
+++ b/find.c
@@ -1,5 +1,9 @@
+#define PCRE2_STATIC
+#define PCRE2_CODE_UNIT_WIDTH 32
+#include <pcre2.h>
#define FIND_MAX_GROUPS 50
+
static u32 find_compilation_flags(Ted *ted) {
return (ted->find_case_sensitive ? 0 : PCRE2_CASELESS)
| (ted->find_regex ? 0 : PCRE2_LITERAL);
diff --git a/gl.c b/gl.c
index 6c66709..1063c96 100644
--- a/gl.c
+++ b/gl.c
@@ -1,6 +1,15 @@
#include "ted.h"
#include "lib/glcorearb.h"
+#if DEBUG
+unsigned char *stbi_load(const char *filename, int *x, int *y, int *comp, int req_comp);
+#else
+#define STB_IMAGE_STATIC
+no_warn_start
+#include "stb_image.c"
+no_warn_end
+#endif
+
// macro trickery to avoid having to write everything twice
#define gl_for_each_proc(do)\
do(DRAWARRAYS, DrawArrays)\
diff --git a/main.c b/main.c
index 26e6749..871d203 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,8 @@
/*
@TODO:
- rename v[234] to vec[234]
+- make ctrl+up/ctrl+down move to next/prev blank line
+- broken session fix: close buffers not in any used node
- handle multiple symbols with same name in go-to-definition menu
- better non-error window/showMessage(Request)
- document lsp.h and lsp.c.
@@ -73,18 +75,6 @@ no_warn_end
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "shell32.lib")
#endif
-#define PCRE2_STATIC
-#define PCRE2_CODE_UNIT_WIDTH 32
-#include <pcre2.h>
-
-#if DEBUG
-extern unsigned char *stbi_load(const char *filename, int *x, int *y, int *comp, int req_comp);
-#else
-#define STB_IMAGE_STATIC
-no_warn_start
-#include "stb_image.c"
-no_warn_end
-#endif
#include "util.c"
diff --git a/node.c b/node.c
index 413600f..587b253 100644
--- a/node.c
+++ b/node.c
@@ -1,4 +1,6 @@
-static void node_switch_to_tab(Ted *ted, Node *node, u16 new_tab_index) {
+#include "ted.h"
+
+void node_switch_to_tab(Ted *ted, Node *node, u16 new_tab_index) {
node->active_tab = new_tab_index;
if (node == ted->active_node) {
// switch active buffer
@@ -9,26 +11,25 @@ static void node_switch_to_tab(Ted *ted, Node *node, u16 new_tab_index) {
}
// move n tabs to the right
-static void node_tab_next(Ted *ted, Node *node, i64 n) {
+void node_tab_next(Ted *ted, Node *node, i64 n) {
assert(node->tabs);
u16 ntabs = (u16)arr_len(node->tabs);
u16 tab_idx = (u16)mod_i64(node->active_tab + n, ntabs);
node_switch_to_tab(ted, node, tab_idx);
}
-static void node_tab_prev(Ted *ted, Node *node, i64 n) {
+void node_tab_prev(Ted *ted, Node *node, i64 n) {
node_tab_next(ted, node, -n);
}
-static void node_tab_switch(Ted *ted, Node *node, i64 tab) {
+void node_tab_switch(Ted *ted, Node *node, i64 tab) {
assert(node->tabs);
if (tab < arr_len(node->tabs)) {
node_switch_to_tab(ted, node, (u16)tab);
}
}
-// swap the position of two tabs
-static void node_tabs_swap(Node *node, u16 tab1, u16 tab2) {
+void node_tabs_swap(Node *node, u16 tab1, u16 tab2) {
assert(tab1 < arr_len(node->tabs) && tab2 < arr_len(node->tabs));
if (node->active_tab == tab1) node->active_tab = tab2;
else if (node->active_tab == tab2) node->active_tab = tab1;
@@ -37,13 +38,12 @@ static void node_tabs_swap(Node *node, u16 tab1, u16 tab2) {
node->tabs[tab2] = tmp;
}
-static void node_free(Node *node) {
+void node_free(Node *node) {
arr_free(node->tabs);
memset(node, 0, sizeof *node);
}
-// returns index of parent in ted->nodes, or -1 if this is the root node.
-static i32 node_parent(Ted *ted, u16 node_idx) {
+i32 node_parent(Ted *ted, u16 node_idx) {
bool *nodes_used = ted->nodes_used;
assert(node_idx < TED_MAX_NODES && nodes_used[node_idx]);
for (u16 i = 0; i < TED_MAX_NODES; ++i) {
@@ -73,8 +73,7 @@ static u8 node_depth(Ted *ted, u16 node_idx) {
return depth;
}
-// join this node with its sibling
-static void node_join(Ted *ted, Node *node) {
+void node_join(Ted *ted, Node *node) {
i32 parent_idx = node_parent(ted, (u16)(node - ted->nodes));
if (parent_idx >= 0) {
Node *parent = &ted->nodes[parent_idx];
@@ -105,7 +104,7 @@ static void node_join(Ted *ted, Node *node) {
}
}
-static void node_close(Ted *ted, u16 node_idx) {
+void node_close(Ted *ted, u16 node_idx) {
ted->dragging_tab_node = NULL;
ted->resizing_split = NULL;
@@ -154,9 +153,7 @@ static void node_close(Ted *ted, u16 node_idx) {
}
-// close tab, WITHOUT checking for unsaved changes!
-// returns true if the node is still open
-static bool node_tab_close(Ted *ted, Node *node, u16 index) {
+bool node_tab_close(Ted *ted, Node *node, u16 index) {
ted->dragging_tab_node = NULL;
u16 ntabs = (u16)arr_len(node->tabs);
@@ -186,7 +183,7 @@ static bool node_tab_close(Ted *ted, Node *node, u16 index) {
}
}
-static void node_frame(Ted *ted, Node *node, Rect r) {
+void node_frame(Ted *ted, Node *node, Rect r) {
const Settings *settings = ted_active_settings(ted);
if (node->tabs) {
bool is_active = node == ted->active_node;
@@ -387,7 +384,7 @@ static void node_frame(Ted *ted, Node *node, Rect r) {
}
}
-static void node_split(Ted *ted, Node *node, bool vertical) {
+void node_split(Ted *ted, Node *node, bool vertical) {
if (node_depth(ted, (u16)(node - ted->nodes)) >= 4) return; // prevent splitting too deep
if (arr_len(node->tabs) > 1) { // need at least 2 tabs to split
@@ -417,7 +414,7 @@ static void node_split(Ted *ted, Node *node, bool vertical) {
}
}
-static void node_split_switch(Ted *ted) {
+void node_split_switch(Ted *ted) {
assert(ted->active_node);
u16 active_node_idx = (u16)(ted->active_node - ted->nodes);
i32 parent_idx = node_parent(ted, active_node_idx);
@@ -432,7 +429,7 @@ static void node_split_switch(Ted *ted) {
}
}
-static void node_split_swap(Ted *ted) {
+void node_split_swap(Ted *ted) {
assert(ted->active_node);
u16 active_node_idx = (u16)(ted->active_node - ted->nodes);
i32 parent_idx = node_parent(ted, active_node_idx);
diff --git a/ted.c b/ted.c
index 3aaec75..ef91745 100644
--- a/ted.c
+++ b/ted.c
@@ -1,3 +1,5 @@
+#include "ted.h"
+
// this is a macro so we get -Wformat warnings
#define ted_seterr(ted, ...) \
snprintf((ted)->error, sizeof (ted)->error - 1, __VA_ARGS__)
@@ -236,8 +238,6 @@ static void ted_load_fonts(Ted *ted) {
}
-// sets the active buffer to this buffer, and updates active_node, etc. accordingly
-// you can pass NULL to buffer to make it so no buffer is active.
void ted_switch_to_buffer(Ted *ted, TextBuffer *buffer) {
TextBuffer *search_buffer = find_search_buffer(ted);
ted->active_buffer = buffer;
@@ -340,8 +340,6 @@ static void ted_node_switch(Ted *ted, Node *node) {
ted_switch_to_buffer(ted, &ted->buffers[node->tabs[node->active_tab]]);
}
-static bool node_tab_close(Ted *ted, Node *node, u16 index);
-
// Open a new buffer. Fills out *tab to the index of the tab used, and *buffer_idx to the index of the buffer.
// Returns true on success.
static Status ted_open_buffer(Ted *ted, u16 *buffer_idx, u16 *tab) {
diff --git a/ted.h b/ted.h
index 6f7f979..8118a36 100644
--- a/ted.h
+++ b/ted.h
@@ -519,8 +519,8 @@ typedef struct Ted {
bool replace; // is the find+replace menu open?
bool find_regex, find_case_sensitive; // find options
u32 find_flags; // flags used last time search term was compiled
- pcre2_code *find_code;
- pcre2_match_data *find_match_data;
+ struct pcre2_real_code_32 *find_code;
+ struct pcre2_real_match_data_32 *find_match_data;
FindResult *find_results;
bool find_invalid_pattern; // invalid regex?
Command warn_unsaved; // if non-zero, the user is trying to execute this command, but there are unsaved changes
@@ -731,11 +731,13 @@ void buffer_toggle_comment_lines(TextBuffer *buffer, u32 first_line, u32 last_li
void buffer_toggle_comment_selection(TextBuffer *buffer);
// make sure to call gl_geometry_draw after this
void buffer_highlight_lsp_range(TextBuffer *buffer, LSPRange range);
+
// === colors.c ===
ColorSetting color_setting_from_str(const char *str);
const char *color_setting_to_str(ColorSetting s);
Status color_from_str(const char *str, u32 *color);
ColorSetting color_for_symbol_kind(SymbolKind kind);
+
// === gl.c ===
GlRcSAB *gl_rc_sab_new(GLuint shader, GLuint array, GLuint buffer);
void gl_rc_sab_incref(GlRcSAB *s);
@@ -755,6 +757,28 @@ void gl_geometry_rect(Rect r, u32 color_rgba);
void gl_geometry_rect_border(Rect r, float border_thickness, u32 color);
void gl_geometry_draw(void);
GLuint gl_load_texture_from_image(const char *path);
+
+// === node.c ===
+void node_switch_to_tab(Ted *ted, Node *node, u16 new_tab_index);
+void node_tab_next(Ted *ted, Node *node, i64 n);
+void node_tab_prev(Ted *ted, Node *node, i64 n);
+void node_tab_switch(Ted *ted, Node *node, i64 tab);
+// swap the position of two tabs
+void node_tabs_swap(Node *node, u16 tab1, u16 tab2);
+void node_free(Node *node);
+// returns index of parent in ted->nodes, or -1 if this is the root node.
+i32 node_parent(Ted *ted, u16 node_idx);
+// join this node with its sibling
+void node_join(Ted *ted, Node *node);
+void node_close(Ted *ted, u16 node_idx);
+// close tab, WITHOUT checking for unsaved changes!
+// returns true if the node is still open
+bool node_tab_close(Ted *ted, Node *node, u16 index);
+void node_frame(Ted *ted, Node *node, Rect r);
+void node_split(Ted *ted, Node *node, bool vertical);
+void node_split_switch(Ted *ted);
+void node_split_swap(Ted *ted);
+
// === syntax.c ===
Language language_from_str(const char *str);
const char *language_to_str(Language language);
@@ -765,6 +789,30 @@ char32_t syntax_matching_bracket(Language lang, char32_t c);
bool syntax_is_opening_bracket(Language lang, char32_t c);
void syntax_highlight(SyntaxState *state, Language lang, const char32_t *line, u32 line_len, SyntaxCharType *char_types);
+// === ted.c ===
+void ted_seterr_to_buferr(Ted *ted, TextBuffer *buffer);
+bool ted_haserr(Ted *ted);
+const char *ted_geterr(Ted *ted);
+void ted_clearerr(Ted *ted);
+char *ted_get_root_dir_of(Ted *ted, const char *path);
+char *ted_get_root_dir(Ted *ted);
+Settings *ted_active_settings(Ted *ted);
+Settings *ted_get_settings(Ted *ted, const char *path, Language language);
+LSP *ted_get_lsp_by_id(Ted *ted, LSPID id);
+LSP *ted_get_lsp(Ted *ted, const char *path, Language language);
+LSP *ted_active_lsp(Ted *ted);
+u32 ted_color(Ted *ted, ColorSetting color);
+// sets the active buffer to this buffer, and updates active_node, etc. accordingly
+// you can pass NULL to buffer to make it so no buffer is active.
+void ted_switch_to_buffer(Ted *ted, TextBuffer *buffer);
+void ted_load_configs(Ted *ted, bool reloading);
+void ted_press_key(Ted *ted, SDL_Scancode scancode, SDL_Keymod modifier);
+bool ted_get_mouse_buffer_pos(Ted *ted, TextBuffer **pbuffer, BufferPos *ppos);
+void ted_flash_error_cursor(Ted *ted);
+void ted_go_to_position(Ted *ted, const char *path, u32 line, u32 index, bool is_lsp);
+void ted_go_to_lsp_document_position(Ted *ted, LSP *lsp, LSPDocumentPosition position);
+void ted_cancel_lsp_request(Ted *ted, LSPID lsp, LSPRequestID request);
+
char *buffer_contents_utf8_alloc(TextBuffer *buffer);
Command command_from_str(const char *str);