чување 78f61b1fcec401d29aba3fb75912f9b6f637dfe6
родитељ c012a668f5bbaa53c25a5ed9367067d7831d9d85
Аутор: Страхиња Радић <sr@strahinja.org>
Датум: Sat, 2 Nov 2024 10:34:49 +0100
Update patches
Diffstat:
измењених датотека: 4, додавања: 872(+), брисања: 162(-)
diff --git a/patch/bw-theme.patch b/patch/bw-theme.patch
@@ -1,6 +1,6 @@
-From 744a42da5c6578c1febcfe3f260ed63b9cbcba94 Mon Sep 17 00:00:00 2001
+From 364246b5b0e7c37a3b2c0550d67605c632d72a59 Mon Sep 17 00:00:00 2001
From: Страхиња Радић <sr@strahinja.org>
-Date: Sat Sep 7 10:00:11 2024 UTC
+Date: Sat Nov 2 08:45:40 2024 UTC
Subject: [PATCH] Set black and white theme
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
@@ -11,7 +11,7 @@ Content-Transfer-Encoding: 8bit
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/config.def.h b/config.def.h
-index 504bf7d20..744a42da5 100644
+index c012a668f..364246b5b 100644
--- a/config.def.h
+++ b/config.def.h
@@ -6,25 +6,22 @@
diff --git a/patch/dark-theme.patch b/patch/dark-theme.patch
@@ -1,6 +1,6 @@
-From 0ce620d838cec52583c50fa808af0e9dab38760c Mon Sep 17 00:00:00 2001
+From 5c3865687fa0debec6192bd58a69d01f969254fb Mon Sep 17 00:00:00 2001
From: Страхиња Радић <sr@strahinja.org>
-Date: Sat Sep 7 10:09:58 2024 UTC
+Date: Sat Nov 2 08:45:04 2024 UTC
Subject: [PATCH] Set dark theme
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
@@ -12,7 +12,7 @@ Content-Transfer-Encoding: 8bit
2 files changed, 18 insertions(+), 23 deletions(-)
diff --git a/config.def.h b/config.def.h
-index 504bf7d20..0ce620d83 100644
+index c012a668f..5c3865687 100644
--- a/config.def.h
+++ b/config.def.h
@@ -4,29 +4,23 @@
@@ -63,15 +63,15 @@ index 504bf7d20..0ce620d83 100644
/* clang-format on */
diff --git a/sled.c b/sled.c
-index 504bf7d20..0ce620d83 100644
+index c012a668f..5c3865687 100644
--- a/sled.c
+++ b/sled.c
-@@ -3210,6 +3210,7 @@ main_skip_backups:
-
+@@ -3122,6 +3122,7 @@ main_skip_backups:
init_termbox:
- tb_init();
+ if (tb_init())
+ goto main_done;
+ tb_set_output_mode(TB_OUTPUT_256);
- *error = 0;
+ errno = 0;
state.maxx = 0;
state.recalculate_size = 1;
--
diff --git a/patch/light-theme.patch b/patch/light-theme.patch
@@ -1,6 +1,6 @@
-From be1314e35d0efb2ae94f012693f749eb6c69cbc3 Mon Sep 17 00:00:00 2001
+From f564d4fb92d6daee7cbafed3fd19776ac1c5a764 Mon Sep 17 00:00:00 2001
From: Страхиња Радић <sr@strahinja.org>
-Date: Sat Sep 7 10:05:55 2024 UTC
+Date: Sat Nov 2 08:44:22 2024 UTC
Subject: [PATCH] Set light theme
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
@@ -12,7 +12,7 @@ Content-Transfer-Encoding: 8bit
2 files changed, 18 insertions(+), 23 deletions(-)
diff --git a/config.def.h b/config.def.h
-index 504bf7d20..be1314e35 100644
+index c012a668f..f564d4fb9 100644
--- a/config.def.h
+++ b/config.def.h
@@ -4,29 +4,23 @@
@@ -63,15 +63,15 @@ index 504bf7d20..be1314e35 100644
/* clang-format on */
diff --git a/sled.c b/sled.c
-index 504bf7d20..be1314e35 100644
+index c012a668f..f564d4fb9 100644
--- a/sled.c
+++ b/sled.c
-@@ -3210,6 +3210,7 @@ main_skip_backups:
-
+@@ -3122,6 +3122,7 @@ main_skip_backups:
init_termbox:
- tb_init();
+ if (tb_init())
+ goto main_done;
+ tb_set_output_mode(TB_OUTPUT_256);
- *error = 0;
+ errno = 0;
state.maxx = 0;
state.recalculate_size = 1;
--
diff --git a/patch/syntax.patch b/patch/syntax.patch
@@ -1,23 +1,27 @@
-From 4673c3e20138dd0ded6c3edf95c47cedd6987b7f Mon Sep 17 00:00:00 2001
+From 374ad070073bb248cbfba37053a6527b0150d5b9 Mon Sep 17 00:00:00 2001
From: Страхиња Радић <sr@strahinja.org>
-Date: Sat Sep 7 10:20:17 2024 UTC
+Date: Sat Nov 2 09:29:39 2024 UTC
Subject: [PATCH] Add syntax highlighting
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
- config.def.h | 7+ 0-
- draw.c | 663+ 30-
- draw.h | 77+ 6-
- sled.c | 82+ 16-
- 4 files changed, 829 insertions(+), 52 deletions(-)
+ config.def.h | 7+ 0-
+ draw.c | 616+ 31-
+ draw.h | 76+ 6-
+ patch/bw-theme.patch | 3+ 3-
+ patch/dark-theme.patch | 8+ 8-
+ patch/light-theme.patch | 8+ 8-
+ patch/syntax.patch | 121+ 85-
+ sled.c | 82+ 15-
+ 8 files changed, 921 insertions(+), 156 deletions(-)
diff --git a/config.def.h b/config.def.h
-index 504bf7d20..4673c3e20 100644
+index fcae0e64e..374ad0700 100644
--- a/config.def.h
+++ b/config.def.h
-@@ -232,6 +232,13 @@ static const struct Key command_keys[] = {
+@@ -234,6 +234,13 @@ static const struct Key command_keys[] = {
#endif /* SLED_C_GLOBALS */
/* clang-format off */
@@ -32,7 +36,7 @@ index 504bf7d20..4673c3e20 100644
{.format = "%s%s",
.callback = format_filename,
diff --git a/draw.c b/draw.c
-index 504bf7d20..4673c3e20 100644
+index fcae0e64e..374ad0700 100644
--- a/draw.c
+++ b/draw.c
@@ -3,6 +3,7 @@
@@ -69,7 +73,7 @@ index 504bf7d20..4673c3e20 100644
enum {
UNKNOWN_MODE,
COMMAND_MODE,
-@@ -88,6 +108,95 @@ static const struct {
+@@ -86,6 +106,95 @@ static const struct {
{ .boundary = 99, .width = 3 },
{ .boundary = 9, .width = 2 }
};
@@ -165,7 +169,7 @@ index 504bf7d20..4673c3e20 100644
const char* go_to_dialog_title = "Go to line";
const char* prompt_dirty = "File changed, save [y/n/ESC]?";
const char* prompt_overwrite = "Not empty, overwrite? [y/n/ESC]?";
-@@ -96,6 +205,46 @@ const char* replace_dialog_title = "Replace with";
+@@ -94,6 +203,46 @@ const char* replace_dialog_title = "Replace with";
const char* search_dialog_title = "Search text";
/* clang-format on */
@@ -212,7 +216,7 @@ index 504bf7d20..4673c3e20 100644
void get_selection(int* ssr, int* ssc, int* ser, int* sec,
const struct DrawState* state);
-@@ -269,14 +418,14 @@ draw_help(const struct DrawState* state)
+@@ -267,14 +416,14 @@ draw_help(const struct DrawState* state)
draw_box(startx, endx, starty, endy, colors[C_DLG].fg, colors[C_DLG].bg);
if (draw_string(startx, starty, colors[C_TITLE].fg, colors[C_TITLE].bg,
@@ -231,7 +235,7 @@ index 504bf7d20..4673c3e20 100644
return 1;
row++;
}
-@@ -312,16 +461,16 @@ draw_input_dialog(const struct DrawState* state)
+@@ -310,16 +459,16 @@ draw_input_dialog(const struct DrawState* state)
colors[C_INPUT_EDIT].fg, colors[C_INPUT_EDIT].bg);
if (state->input_title)
if (draw_string(startx, starty, colors[C_TITLE].fg,
@@ -252,7 +256,7 @@ index 504bf7d20..4673c3e20 100644
tb_set_cursor(startx + 2 + state->input_display_column
- state->input_first_shown_column,
starty + 1);
-@@ -343,7 +492,7 @@ draw_line_number(const struct DrawState* state, const
+@@ -341,7 +490,7 @@ draw_line_number(const struct DrawState* state, const
? numbuf_end - state->line_numbers_width
: numbuf;
draw_string(0, cy, colors[C_LINENO].fg, colors[C_LINENO].bg,
@@ -261,7 +265,7 @@ index 504bf7d20..4673c3e20 100644
state->line_numbers_width, 0, 0, RIGHT, 0, 1, NULL, 0,
0, 0, 0, 0, 0);
}
-@@ -424,8 +573,9 @@ draw_screen(const struct DrawState* state)
+@@ -422,8 +571,9 @@ draw_screen(const struct DrawState* state)
? state->line_numbers_width + 2
: 0,
cy, colors[C_TEXT].fg, colors[C_TEXT].bg,
@@ -273,7 +277,7 @@ index 504bf7d20..4673c3e20 100644
colors[C_SEARCH].bg, ssi, sei, colors[C_SEL].fg,
colors[C_SEL].bg);
i++;
-@@ -457,7 +607,7 @@ draw_status(const struct DrawState* state)
+@@ -455,7 +605,7 @@ draw_status(const struct DrawState* state)
if (IN(state->mode, M_PROMPT) && *state->prompt)
{
if (draw_string(0, state->maxy - 1, colors[C_PROMPT].fg,
@@ -282,25 +286,26 @@ index 504bf7d20..4673c3e20 100644
strlen(state->prompt) + 2, maxx, 1, 1, CENTER, 0, 1,
NULL, 0, 0, 0, 0, 0, 0))
return 1;
-@@ -465,7 +615,7 @@ draw_status(const struct DrawState* state)
- else if (state->action && *state->action)
+@@ -463,15 +613,15 @@ draw_status(const struct DrawState* state)
+ else if (state->action)
{
if (draw_string(0, state->maxy - 1, colors[C_ACTION].fg,
-- colors[C_ACTION].bg, state->action,
-+ colors[C_ACTION].bg, state->action, NULL, 0,
- strlen(state->action) + 2, maxx, 1, 1, CENTER, 0, 1,
- NULL, 0, 0, 0, 0, 0, 0))
+- colors[C_ACTION].bg, actions[state->action],
+- strlen(actions[state->action]) + 2, maxx, 1, 1,
++ colors[C_ACTION].bg, actions[state->action], NULL,
++ 0, strlen(actions[state->action]) + 2, maxx, 1, 1,
+ CENTER, 0, 1, NULL, 0, 0, 0, 0, 0, 0))
return 1;
-@@ -473,7 +623,7 @@ draw_status(const struct DrawState* state)
- else if (state->error && *state->error)
+ }
+ else if (state->error)
{
if (draw_string(0, state->maxy - 1, colors[C_ERROR].fg,
-- colors[C_ERROR].bg, state->error,
-+ colors[C_ERROR].bg, state->error, NULL, 0,
- strlen(state->error) + 2, maxx, 1, 1, CENTER, 0, 1,
- NULL, 0, 0, 0, 0, 0, 0))
+- colors[C_ERROR].bg, errors[state->error],
++ colors[C_ERROR].bg, errors[state->error], NULL, 0,
+ strlen(errors[state->error]) + 2, maxx, 1, 1,
+ CENTER, 0, 1, NULL, 0, 0, 0, 0, 0, 0))
return 1;
-@@ -499,7 +649,7 @@ draw_status(const struct DrawState* state)
+@@ -497,7 +647,7 @@ draw_status(const struct DrawState* state)
seg_size = maxx - 1 - current_start;
if (draw_string(current_start, state->maxy - 1,
colors[pseg->color_index].fg,
@@ -309,7 +314,7 @@ index 504bf7d20..4673c3e20 100644
MIN(seg_size, (ssize_t)(strlen(buf) + 2)),
last ? seg_size + 1 : seg_size, 1, 1,
pseg->alignment, 0, 1, NULL, 0, 0, 0, 0, 0,
-@@ -534,8 +684,9 @@ draw_status(const struct DrawState* state)
+@@ -532,8 +682,9 @@ draw_status(const struct DrawState* state)
* */
int
draw_string(const int x, const int y, const uint16_t fg, const uint16_t bg,
@@ -321,7 +326,7 @@ index 504bf7d20..4673c3e20 100644
const uint32_t* srch, const uint16_t sfg, const uint16_t sbg,
const int ssi, const int sei, const uint16_t slfg, const uint16_t slbg)
{
-@@ -545,8 +696,8 @@ draw_string(const int x, const int y, const uint16_t f
+@@ -543,8 +694,8 @@ draw_string(const int x, const int y, const uint16_t f
if (!us)
return 1;
u8_string_to_unicode(us, s, mc);
@@ -332,7 +337,7 @@ index 504bf7d20..4673c3e20 100644
free(us);
return 0;
}
-@@ -651,14 +802,41 @@ free_bufferline(struct BufferLine* bl)
+@@ -650,13 +801,19 @@ free_bufferline(struct BufferLine* bl)
bl->length = 0;
bl->fg = 0;
bl->bg = 0;
@@ -341,8 +346,7 @@ index 504bf7d20..4673c3e20 100644
}
void
- free_drawstate(struct DrawState* state, const int skip_paste_free,
- const int skip_filename_free)
+ free_drawstate(struct DrawState* state)
{
+ struct Keyword32* kw;
+ struct Comment32* cm;
@@ -350,31 +354,10 @@ index 504bf7d20..4673c3e20 100644
ssize_t row = 0;
assert(state != NULL);
+
-+ if (state->ukeywords)
-+ {
-+ for (kw = state->ukeywords; kw->text != NULL; kw++)
-+ free(kw->text);
-+ free(state->ukeywords);
-+ }
-+ if (state->ucomments)
-+ {
-+ for (cm = state->ucomments; cm->start_text != NULL; cm++)
-+ {
-+ free(cm->start_text);
-+ free(cm->end_text);
-+ }
-+ free(state->ucomments);
-+ }
-+ if (state->uoperators)
-+ {
-+ for (op = state->uoperators; op->text != NULL; op++)
-+ free(op->text);
-+ free(state->uoperators);
-+ }
for (row = 0; row < state->buffer_size; row++)
free_bufferline(state->buffer + row);
free(state->buffer);
-@@ -684,11 +862,13 @@ init_bufferline(struct BufferLine* bl)
+@@ -669,11 +826,13 @@ init_bufferline(struct BufferLine* bl)
{
if (!bl)
return;
@@ -393,7 +376,7 @@ index 504bf7d20..4673c3e20 100644
}
void
-@@ -714,6 +894,14 @@ init_drawstate(struct DrawState* state, char* error, c
+@@ -698,6 +857,14 @@ init_drawstate(struct DrawState* state, char* filename
state->orig_real_filename = NULL;
state->backup_filename = NULL;
state->rfn_len = 0;
@@ -408,7 +391,7 @@ index 504bf7d20..4673c3e20 100644
}
state->input = NULL;
state->search = NULL;
-@@ -772,7 +960,429 @@ recalculate_size(struct DrawState* state)
+@@ -756,7 +923,402 @@ recalculate_size(struct DrawState* state)
recalculate_line_numbers(state);
}
@@ -460,7 +443,6 @@ index 504bf7d20..4673c3e20 100644
+ struct Comment32* comment;
+ struct Operator32* operator;
+ uint32_t* temp32;
-+ char* temp;
+ ssize_t i, li, ti, comment_start, quote_start, literal_start;
+ uint32_t quote;
+ int comment_index, seen_end_comment;
@@ -485,8 +467,6 @@ index 504bf7d20..4673c3e20 100644
+ = calloc(keyword_count + 1, sizeof(struct Keyword32));
+ if (!state->ukeywords)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -499,8 +479,6 @@ index 504bf7d20..4673c3e20 100644
+ pklist->text = calloc(kw->size, sizeof(*ukw));
+ if (!pklist->text)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -527,8 +505,6 @@ index 504bf7d20..4673c3e20 100644
+ = calloc(comment_count + 1, sizeof(struct Comment32));
+ if (!state->ucomments)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -543,8 +519,6 @@ index 504bf7d20..4673c3e20 100644
+ = calloc(cm->start_size, sizeof(*ucm));
+ if (!pclist->start_text)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -562,8 +536,6 @@ index 504bf7d20..4673c3e20 100644
+ pclist->end_text = calloc(cm->end_size, sizeof(*ucm));
+ if (!pclist->end_text)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -591,8 +563,6 @@ index 504bf7d20..4673c3e20 100644
+ = calloc(operator_count + 1, sizeof(struct Operator32));
+ if (!state->uoperators)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -605,8 +575,6 @@ index 504bf7d20..4673c3e20 100644
+ polist->text = calloc(op->size, sizeof(*uop));
+ if (!polist->text)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -663,8 +631,6 @@ index 504bf7d20..4673c3e20 100644
+ ti - comment_start)
+ < 0)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -694,8 +660,6 @@ index 504bf7d20..4673c3e20 100644
+ curline->length - ti)
+ < 0)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -730,8 +694,6 @@ index 504bf7d20..4673c3e20 100644
+ ti - quote_start)
+ < 0)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -761,8 +723,6 @@ index 504bf7d20..4673c3e20 100644
+ ti - literal_start)
+ < 0)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -788,8 +748,6 @@ index 504bf7d20..4673c3e20 100644
+ keyword->size - 1)
+ < 0)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -816,8 +774,6 @@ index 504bf7d20..4673c3e20 100644
+ ti, operator->size - 1)
+ < 0)
+ {
-+ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
-+ LINE_DEFAULT, temp);
+ state->running = 0;
+ return;
+ }
@@ -838,7 +794,7 @@ index 504bf7d20..4673c3e20 100644
redraw_status(struct DrawState* state)
{
assert(state != NULL);
-@@ -803,7 +1413,8 @@ redraw_status(struct DrawState* state)
+@@ -787,7 +1349,8 @@ redraw_status(struct DrawState* state)
* */
void
u32_draw_string(const int x, const int y, const uint16_t fg, const uint16_t bg,
@@ -848,7 +804,7 @@ index 504bf7d20..4673c3e20 100644
const int p_r, const Alignment align, const int ds, const int fill,
const uint32_t* srch, const uint16_t sfg, const uint16_t sbg,
const int ssi, const int sei, const uint16_t slfg, const uint16_t slbg)
-@@ -841,6 +1452,8 @@ u32_draw_string(const int x, const int y, const uint16
+@@ -825,6 +1388,8 @@ u32_draw_string(const int x, const int y, const uint16
int w = 0; /* actual on-screen rune width */
@@ -857,7 +813,7 @@ index 504bf7d20..4673c3e20 100644
const int ts = TAB_SIZE;
const uint32_t* ps = s; /* pointer to current character in
-@@ -849,11 +1462,23 @@ u32_draw_string(const int x, const int y, const uint16
+@@ -833,11 +1398,23 @@ u32_draw_string(const int x, const int y, const uint16
uint16_t cfg = fg; /* current fg */
uint16_t cbg = bg; /* current bg */
@@ -881,7 +837,7 @@ index 504bf7d20..4673c3e20 100644
c = mc - p_l - p_r;
if (align == LEFT)
-@@ -885,7 +1510,12 @@ u32_draw_string(const int x, const int y, const uint16
+@@ -869,7 +1446,12 @@ u32_draw_string(const int x, const int y, const uint16
*/
while (*ps && sc < c)
{
@@ -895,7 +851,7 @@ index 504bf7d20..4673c3e20 100644
{
cfg = slfg;
cbg = slbg;
-@@ -902,6 +1532,9 @@ u32_draw_string(const int x, const int y, const uint16
+@@ -886,6 +1468,9 @@ u32_draw_string(const int x, const int y, const uint16
}
}
@@ -905,7 +861,7 @@ index 504bf7d20..4673c3e20 100644
if (*ps == '\t')
{
if (ssc < ds)
-@@ -1017,11 +1650,11 @@ u32_draw_string(const int x, const int y, const uint16
+@@ -1001,11 +1586,11 @@ u32_draw_string(const int x, const int y, const uint16
}
ssc += w;
}
@@ -922,18 +878,10 @@ index 504bf7d20..4673c3e20 100644
}
diff --git a/draw.h b/draw.h
-index 504bf7d20..4673c3e20 100644
+index fcae0e64e..374ad0700 100644
--- a/draw.h
+++ b/draw.h
-@@ -1,6 +1,7 @@
- /* This program is licensed under the terms of GNU GPL v3 or (at your option)
- * any later version. Copyright (C) 2022-2024 Страхиња Радић.
- * See the file LICENSE for exact copyright and license details. */
-+
- #include <stddef.h>
- #include <sys/types.h>
- #include <termios.h>
-@@ -62,17 +63,69 @@ struct Color {
+@@ -63,17 +63,69 @@ struct Color {
uint16_t bg;
};
@@ -1003,7 +951,7 @@ index 504bf7d20..4673c3e20 100644
};
struct DrawState {
-@@ -112,12 +165,20 @@ struct DrawState {
+@@ -113,12 +165,20 @@ struct DrawState {
int dirty;
int new_file;
int recalculate_size;
@@ -1024,7 +972,7 @@ index 504bf7d20..4673c3e20 100644
};
struct Key {
-@@ -133,6 +194,13 @@ struct StatusSegment {
+@@ -134,6 +194,13 @@ struct StatusSegment {
Alignment alignment;
};
@@ -1038,7 +986,7 @@ index 504bf7d20..4673c3e20 100644
void assign_coord(struct Coord* dest, const struct Coord src);
ssize_t buffer_length(uint32_t* buffer, const ssize_t max_index);
int calculate_help_width(const struct DrawState* state);
-@@ -149,7 +217,8 @@ void draw_rect(const int startx, const int endx, const
+@@ -150,7 +217,8 @@ void draw_rect(const int startx, const int endx, const
int draw_screen(const struct DrawState* state);
int draw_status(const struct DrawState* state);
int draw_string(const int x, const int y, const uint16_t fg, const uint16_t bg,
@@ -1048,8 +996,8 @@ index 504bf7d20..4673c3e20 100644
const int padding_left, const int padding_right, const Alignment align,
const int ds, const int fill, const uint32_t* srch, const uint16_t sfg,
const uint16_t sbg, const int ssi, const int sei, const uint16_t slfg,
-@@ -172,10 +241,12 @@ void init_drawstate(struct DrawState* state, char* err
- const int skip_filenames_init);
+@@ -171,10 +239,12 @@ void init_drawstate(struct DrawState* state, char* fil
+ const int skip_paste_and_mode_init, const int skip_filenames_init);
void recalculate_line_numbers(struct DrawState* state);
void recalculate_size(struct DrawState* state);
+void recalculate_syntax(struct DrawState* state);
@@ -1066,11 +1014,774 @@ index 504bf7d20..4673c3e20 100644
+ const int ds, const int fill, const uint32_t* srch, const uint16_t sfg,
+ const uint16_t sbg, const int ssi, const int sei, const uint16_t slfg,
+ const uint16_t slbg);
+diff --git a/patch/bw-theme.patch b/patch/bw-theme.patch
+index fcae0e64e..374ad0700 100644
+--- a/patch/bw-theme.patch
++++ b/patch/bw-theme.patch
+@@ -1,6 +1,6 @@
+-From 364246b5b0e7c37a3b2c0550d67605c632d72a59 Mon Sep 17 00:00:00 2001
++From 744a42da5c6578c1febcfe3f260ed63b9cbcba94 Mon Sep 17 00:00:00 2001
+ From: Страхиња Радић <sr@strahinja.org>
+-Date: Sat Nov 2 08:45:40 2024 UTC
++Date: Sat Sep 7 10:00:11 2024 UTC
+ Subject: [PATCH] Set black and white theme
+ MIME-Version: 1.0
+ Content-Type: text/plain; charset=UTF-8
+@@ -11,7 +11,7 @@ Content-Transfer-Encoding: 8bit
+ 1 file changed, 12 insertions(+), 15 deletions(-)
+
+ diff --git a/config.def.h b/config.def.h
+-index c012a668f..364246b5b 100644
++index 504bf7d20..744a42da5 100644
+ --- a/config.def.h
+ +++ b/config.def.h
+ @@ -6,25 +6,22 @@
+diff --git a/patch/dark-theme.patch b/patch/dark-theme.patch
+index fcae0e64e..374ad0700 100644
+--- a/patch/dark-theme.patch
++++ b/patch/dark-theme.patch
+@@ -1,6 +1,6 @@
+-From 5c3865687fa0debec6192bd58a69d01f969254fb Mon Sep 17 00:00:00 2001
++From 0ce620d838cec52583c50fa808af0e9dab38760c Mon Sep 17 00:00:00 2001
+ From: Страхиња Радић <sr@strahinja.org>
+-Date: Sat Nov 2 08:45:04 2024 UTC
++Date: Sat Sep 7 10:09:58 2024 UTC
+ Subject: [PATCH] Set dark theme
+ MIME-Version: 1.0
+ Content-Type: text/plain; charset=UTF-8
+@@ -12,7 +12,7 @@ Content-Transfer-Encoding: 8bit
+ 2 files changed, 18 insertions(+), 23 deletions(-)
+
+ diff --git a/config.def.h b/config.def.h
+-index c012a668f..5c3865687 100644
++index 504bf7d20..0ce620d83 100644
+ --- a/config.def.h
+ +++ b/config.def.h
+ @@ -4,29 +4,23 @@
+@@ -63,15 +63,15 @@ index c012a668f..5c3865687 100644
+ /* clang-format on */
+
+ diff --git a/sled.c b/sled.c
+-index c012a668f..5c3865687 100644
++index 504bf7d20..0ce620d83 100644
+ --- a/sled.c
+ +++ b/sled.c
+-@@ -3122,6 +3122,7 @@ main_skip_backups:
++@@ -3210,6 +3210,7 @@ main_skip_backups:
++
+ init_termbox:
+- if (tb_init())
+- goto main_done;
++ tb_init();
+ + tb_set_output_mode(TB_OUTPUT_256);
+- errno = 0;
++ *error = 0;
+ state.maxx = 0;
+ state.recalculate_size = 1;
+ --
+diff --git a/patch/light-theme.patch b/patch/light-theme.patch
+index fcae0e64e..374ad0700 100644
+--- a/patch/light-theme.patch
++++ b/patch/light-theme.patch
+@@ -1,6 +1,6 @@
+-From f564d4fb92d6daee7cbafed3fd19776ac1c5a764 Mon Sep 17 00:00:00 2001
++From be1314e35d0efb2ae94f012693f749eb6c69cbc3 Mon Sep 17 00:00:00 2001
+ From: Страхиња Радић <sr@strahinja.org>
+-Date: Sat Nov 2 08:44:22 2024 UTC
++Date: Sat Sep 7 10:05:55 2024 UTC
+ Subject: [PATCH] Set light theme
+ MIME-Version: 1.0
+ Content-Type: text/plain; charset=UTF-8
+@@ -12,7 +12,7 @@ Content-Transfer-Encoding: 8bit
+ 2 files changed, 18 insertions(+), 23 deletions(-)
+
+ diff --git a/config.def.h b/config.def.h
+-index c012a668f..f564d4fb9 100644
++index 504bf7d20..be1314e35 100644
+ --- a/config.def.h
+ +++ b/config.def.h
+ @@ -4,29 +4,23 @@
+@@ -63,15 +63,15 @@ index c012a668f..f564d4fb9 100644
+ /* clang-format on */
+
+ diff --git a/sled.c b/sled.c
+-index c012a668f..f564d4fb9 100644
++index 504bf7d20..be1314e35 100644
+ --- a/sled.c
+ +++ b/sled.c
+-@@ -3122,6 +3122,7 @@ main_skip_backups:
++@@ -3210,6 +3210,7 @@ main_skip_backups:
++
+ init_termbox:
+- if (tb_init())
+- goto main_done;
++ tb_init();
+ + tb_set_output_mode(TB_OUTPUT_256);
+- errno = 0;
++ *error = 0;
+ state.maxx = 0;
+ state.recalculate_size = 1;
+ --
+diff --git a/patch/syntax.patch b/patch/syntax.patch
+index fcae0e64e..374ad0700 100644
+--- a/patch/syntax.patch
++++ b/patch/syntax.patch
+@@ -1,6 +1,6 @@
+-From 11d154f8f00681fdea534d624749b08167786590 Mon Sep 17 00:00:00 2001
++From 4673c3e20138dd0ded6c3edf95c47cedd6987b7f Mon Sep 17 00:00:00 2001
+ From: Страхиња Радић <sr@strahinja.org>
+-Date: Sat Nov 2 08:38:49 2024 UTC
++Date: Sat Sep 7 10:20:17 2024 UTC
+ Subject: [PATCH] Add syntax highlighting
+ MIME-Version: 1.0
+ Content-Type: text/plain; charset=UTF-8
+@@ -8,16 +8,16 @@ Content-Transfer-Encoding: 8bit
+
+ ---
+ config.def.h | 7+ 0-
+- draw.c | 637+ 31-
+- draw.h | 76+ 6-
+- sled.c | 82+ 15-
+- 4 files changed, 802 insertions(+), 52 deletions(-)
++ draw.c | 663+ 30-
++ draw.h | 77+ 6-
++ sled.c | 82+ 16-
++ 4 files changed, 829 insertions(+), 52 deletions(-)
+
+ diff --git a/config.def.h b/config.def.h
+-index c012a668f..11d154f8f 100644
++index 504bf7d20..4673c3e20 100644
+ --- a/config.def.h
+ +++ b/config.def.h
+-@@ -234,6 +234,13 @@ static const struct Key command_keys[] = {
++@@ -232,6 +232,13 @@ static const struct Key command_keys[] = {
+ #endif /* SLED_C_GLOBALS */
+
+ /* clang-format off */
+@@ -32,7 +32,7 @@ index c012a668f..11d154f8f 100644
+ {.format = "%s%s",
+ .callback = format_filename,
+ diff --git a/draw.c b/draw.c
+-index c012a668f..11d154f8f 100644
++index 504bf7d20..4673c3e20 100644
+ --- a/draw.c
+ +++ b/draw.c
+ @@ -3,6 +3,7 @@
+@@ -69,7 +69,7 @@ index c012a668f..11d154f8f 100644
+ enum {
+ UNKNOWN_MODE,
+ COMMAND_MODE,
+-@@ -86,6 +106,95 @@ static const struct {
++@@ -88,6 +108,95 @@ static const struct {
+ { .boundary = 99, .width = 3 },
+ { .boundary = 9, .width = 2 }
+ };
+@@ -165,7 +165,7 @@ index c012a668f..11d154f8f 100644
+ const char* go_to_dialog_title = "Go to line";
+ const char* prompt_dirty = "File changed, save [y/n/ESC]?";
+ const char* prompt_overwrite = "Not empty, overwrite? [y/n/ESC]?";
+-@@ -94,6 +203,46 @@ const char* replace_dialog_title = "Replace with";
++@@ -96,6 +205,46 @@ const char* replace_dialog_title = "Replace with";
+ const char* search_dialog_title = "Search text";
+ /* clang-format on */
+
+@@ -212,7 +212,7 @@ index c012a668f..11d154f8f 100644
+ void get_selection(int* ssr, int* ssc, int* ser, int* sec,
+ const struct DrawState* state);
+
+-@@ -267,14 +416,14 @@ draw_help(const struct DrawState* state)
++@@ -269,14 +418,14 @@ draw_help(const struct DrawState* state)
+
+ draw_box(startx, endx, starty, endy, colors[C_DLG].fg, colors[C_DLG].bg);
+ if (draw_string(startx, starty, colors[C_TITLE].fg, colors[C_TITLE].bg,
+@@ -231,7 +231,7 @@ index c012a668f..11d154f8f 100644
+ return 1;
+ row++;
+ }
+-@@ -310,16 +459,16 @@ draw_input_dialog(const struct DrawState* state)
++@@ -312,16 +461,16 @@ draw_input_dialog(const struct DrawState* state)
+ colors[C_INPUT_EDIT].fg, colors[C_INPUT_EDIT].bg);
+ if (state->input_title)
+ if (draw_string(startx, starty, colors[C_TITLE].fg,
+@@ -252,7 +252,7 @@ index c012a668f..11d154f8f 100644
+ tb_set_cursor(startx + 2 + state->input_display_column
+ - state->input_first_shown_column,
+ starty + 1);
+-@@ -341,7 +490,7 @@ draw_line_number(const struct DrawState* state, const
++@@ -343,7 +492,7 @@ draw_line_number(const struct DrawState* state, const
+ ? numbuf_end - state->line_numbers_width
+ : numbuf;
+ draw_string(0, cy, colors[C_LINENO].fg, colors[C_LINENO].bg,
+@@ -261,7 +261,7 @@ index c012a668f..11d154f8f 100644
+ state->line_numbers_width, 0, 0, RIGHT, 0, 1, NULL, 0,
+ 0, 0, 0, 0, 0);
+ }
+-@@ -422,8 +571,9 @@ draw_screen(const struct DrawState* state)
++@@ -424,8 +573,9 @@ draw_screen(const struct DrawState* state)
+ ? state->line_numbers_width + 2
+ : 0,
+ cy, colors[C_TEXT].fg, colors[C_TEXT].bg,
+@@ -273,7 +273,7 @@ index c012a668f..11d154f8f 100644
+ colors[C_SEARCH].bg, ssi, sei, colors[C_SEL].fg,
+ colors[C_SEL].bg);
+ i++;
+-@@ -455,7 +605,7 @@ draw_status(const struct DrawState* state)
++@@ -457,7 +607,7 @@ draw_status(const struct DrawState* state)
+ if (IN(state->mode, M_PROMPT) && *state->prompt)
+ {
+ if (draw_string(0, state->maxy - 1, colors[C_PROMPT].fg,
+@@ -282,26 +282,25 @@ index c012a668f..11d154f8f 100644
+ strlen(state->prompt) + 2, maxx, 1, 1, CENTER, 0, 1,
+ NULL, 0, 0, 0, 0, 0, 0))
+ return 1;
+-@@ -463,15 +613,15 @@ draw_status(const struct DrawState* state)
+- else if (state->action)
++@@ -465,7 +615,7 @@ draw_status(const struct DrawState* state)
++ else if (state->action && *state->action)
+ {
+ if (draw_string(0, state->maxy - 1, colors[C_ACTION].fg,
+-- colors[C_ACTION].bg, actions[state->action],
+-- strlen(actions[state->action]) + 2, maxx, 1, 1,
+-+ colors[C_ACTION].bg, actions[state->action], NULL,
+-+ 0, strlen(actions[state->action]) + 2, maxx, 1, 1,
+- CENTER, 0, 1, NULL, 0, 0, 0, 0, 0, 0))
++- colors[C_ACTION].bg, state->action,
+++ colors[C_ACTION].bg, state->action, NULL, 0,
++ strlen(state->action) + 2, maxx, 1, 1, CENTER, 0, 1,
++ NULL, 0, 0, 0, 0, 0, 0))
+ return 1;
+- }
+- else if (state->error)
++@@ -473,7 +623,7 @@ draw_status(const struct DrawState* state)
++ else if (state->error && *state->error)
+ {
+ if (draw_string(0, state->maxy - 1, colors[C_ERROR].fg,
+-- colors[C_ERROR].bg, errors[state->error],
+-+ colors[C_ERROR].bg, errors[state->error], NULL, 0,
+- strlen(errors[state->error]) + 2, maxx, 1, 1,
+- CENTER, 0, 1, NULL, 0, 0, 0, 0, 0, 0))
++- colors[C_ERROR].bg, state->error,
+++ colors[C_ERROR].bg, state->error, NULL, 0,
++ strlen(state->error) + 2, maxx, 1, 1, CENTER, 0, 1,
++ NULL, 0, 0, 0, 0, 0, 0))
+ return 1;
+-@@ -497,7 +647,7 @@ draw_status(const struct DrawState* state)
++@@ -499,7 +649,7 @@ draw_status(const struct DrawState* state)
+ seg_size = maxx - 1 - current_start;
+ if (draw_string(current_start, state->maxy - 1,
+ colors[pseg->color_index].fg,
+@@ -310,7 +309,7 @@ index c012a668f..11d154f8f 100644
+ MIN(seg_size, (ssize_t)(strlen(buf) + 2)),
+ last ? seg_size + 1 : seg_size, 1, 1,
+ pseg->alignment, 0, 1, NULL, 0, 0, 0, 0, 0,
+-@@ -532,8 +682,9 @@ draw_status(const struct DrawState* state)
++@@ -534,8 +684,9 @@ draw_status(const struct DrawState* state)
+ * */
+ int
+ draw_string(const int x, const int y, const uint16_t fg, const uint16_t bg,
+@@ -322,7 +321,7 @@ index c012a668f..11d154f8f 100644
+ const uint32_t* srch, const uint16_t sfg, const uint16_t sbg,
+ const int ssi, const int sei, const uint16_t slfg, const uint16_t slbg)
+ {
+-@@ -543,8 +694,8 @@ draw_string(const int x, const int y, const uint16_t f
++@@ -545,8 +696,8 @@ draw_string(const int x, const int y, const uint16_t f
+ if (!us)
+ return 1;
+ u8_string_to_unicode(us, s, mc);
+@@ -333,7 +332,7 @@ index c012a668f..11d154f8f 100644
+ free(us);
+ return 0;
+ }
+-@@ -650,13 +801,40 @@ free_bufferline(struct BufferLine* bl)
++@@ -651,14 +802,41 @@ free_bufferline(struct BufferLine* bl)
+ bl->length = 0;
+ bl->fg = 0;
+ bl->bg = 0;
+@@ -342,7 +341,8 @@ index c012a668f..11d154f8f 100644
+ }
+
+ void
+- free_drawstate(struct DrawState* state)
++ free_drawstate(struct DrawState* state, const int skip_paste_free,
++ const int skip_filename_free)
+ {
+ + struct Keyword32* kw;
+ + struct Comment32* cm;
+@@ -374,7 +374,7 @@ index c012a668f..11d154f8f 100644
+ for (row = 0; row < state->buffer_size; row++)
+ free_bufferline(state->buffer + row);
+ free(state->buffer);
+-@@ -669,11 +847,13 @@ init_bufferline(struct BufferLine* bl)
++@@ -684,11 +862,13 @@ init_bufferline(struct BufferLine* bl)
+ {
+ if (!bl)
+ return;
+@@ -393,7 +393,7 @@ index c012a668f..11d154f8f 100644
+ }
+
+ void
+-@@ -698,6 +878,14 @@ init_drawstate(struct DrawState* state, char* filename
++@@ -714,6 +894,14 @@ init_drawstate(struct DrawState* state, char* error, c
+ state->orig_real_filename = NULL;
+ state->backup_filename = NULL;
+ state->rfn_len = 0;
+@@ -408,7 +408,7 @@ index c012a668f..11d154f8f 100644
+ }
+ state->input = NULL;
+ state->search = NULL;
+-@@ -756,7 +944,402 @@ recalculate_size(struct DrawState* state)
++@@ -772,7 +960,429 @@ recalculate_size(struct DrawState* state)
+ recalculate_line_numbers(state);
+ }
+
+@@ -460,6 +460,7 @@ index c012a668f..11d154f8f 100644
+ + struct Comment32* comment;
+ + struct Operator32* operator;
+ + uint32_t* temp32;
+++ char* temp;
+ + ssize_t i, li, ti, comment_start, quote_start, literal_start;
+ + uint32_t quote;
+ + int comment_index, seen_end_comment;
+@@ -484,6 +485,8 @@ index c012a668f..11d154f8f 100644
+ + = calloc(keyword_count + 1, sizeof(struct Keyword32));
+ + if (!state->ukeywords)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -496,6 +499,8 @@ index c012a668f..11d154f8f 100644
+ + pklist->text = calloc(kw->size, sizeof(*ukw));
+ + if (!pklist->text)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -522,6 +527,8 @@ index c012a668f..11d154f8f 100644
+ + = calloc(comment_count + 1, sizeof(struct Comment32));
+ + if (!state->ucomments)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -536,6 +543,8 @@ index c012a668f..11d154f8f 100644
+ + = calloc(cm->start_size, sizeof(*ucm));
+ + if (!pclist->start_text)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -553,6 +562,8 @@ index c012a668f..11d154f8f 100644
+ + pclist->end_text = calloc(cm->end_size, sizeof(*ucm));
+ + if (!pclist->end_text)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -580,6 +591,8 @@ index c012a668f..11d154f8f 100644
+ + = calloc(operator_count + 1, sizeof(struct Operator32));
+ + if (!state->uoperators)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -592,6 +605,8 @@ index c012a668f..11d154f8f 100644
+ + polist->text = calloc(op->size, sizeof(*uop));
+ + if (!polist->text)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -648,6 +663,8 @@ index c012a668f..11d154f8f 100644
+ + ti - comment_start)
+ + < 0)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -677,6 +694,8 @@ index c012a668f..11d154f8f 100644
+ + curline->length - ti)
+ + < 0)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -711,6 +730,8 @@ index c012a668f..11d154f8f 100644
+ + ti - quote_start)
+ + < 0)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -740,6 +761,8 @@ index c012a668f..11d154f8f 100644
+ + ti - literal_start)
+ + < 0)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -765,6 +788,8 @@ index c012a668f..11d154f8f 100644
+ + keyword->size - 1)
+ + < 0)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -791,6 +816,8 @@ index c012a668f..11d154f8f 100644
+ + ti, operator->size - 1)
+ + < 0)
+ + {
+++ MEMCCPY(state->error, errors[ERR_CANT_ALLOC],
+++ LINE_DEFAULT, temp);
+ + state->running = 0;
+ + return;
+ + }
+@@ -811,7 +838,7 @@ index c012a668f..11d154f8f 100644
+ redraw_status(struct DrawState* state)
+ {
+ assert(state != NULL);
+-@@ -787,7 +1370,8 @@ redraw_status(struct DrawState* state)
++@@ -803,7 +1413,8 @@ redraw_status(struct DrawState* state)
+ * */
+ void
+ u32_draw_string(const int x, const int y, const uint16_t fg, const uint16_t bg,
+@@ -821,7 +848,7 @@ index c012a668f..11d154f8f 100644
+ const int p_r, const Alignment align, const int ds, const int fill,
+ const uint32_t* srch, const uint16_t sfg, const uint16_t sbg,
+ const int ssi, const int sei, const uint16_t slfg, const uint16_t slbg)
+-@@ -825,6 +1409,8 @@ u32_draw_string(const int x, const int y, const uint16
++@@ -841,6 +1452,8 @@ u32_draw_string(const int x, const int y, const uint16
+
+ int w = 0; /* actual on-screen rune width */
+
+@@ -830,7 +857,7 @@ index c012a668f..11d154f8f 100644
+ const int ts = TAB_SIZE;
+
+ const uint32_t* ps = s; /* pointer to current character in
+-@@ -833,11 +1419,23 @@ u32_draw_string(const int x, const int y, const uint16
++@@ -849,11 +1462,23 @@ u32_draw_string(const int x, const int y, const uint16
+ uint16_t cfg = fg; /* current fg */
+ uint16_t cbg = bg; /* current bg */
+
+@@ -854,7 +881,7 @@ index c012a668f..11d154f8f 100644
+ c = mc - p_l - p_r;
+
+ if (align == LEFT)
+-@@ -869,7 +1467,12 @@ u32_draw_string(const int x, const int y, const uint16
++@@ -885,7 +1510,12 @@ u32_draw_string(const int x, const int y, const uint16
+ */
+ while (*ps && sc < c)
+ {
+@@ -868,7 +895,7 @@ index c012a668f..11d154f8f 100644
+ {
+ cfg = slfg;
+ cbg = slbg;
+-@@ -886,6 +1489,9 @@ u32_draw_string(const int x, const int y, const uint16
++@@ -902,6 +1532,9 @@ u32_draw_string(const int x, const int y, const uint16
+ }
+ }
+
+@@ -878,7 +905,7 @@ index c012a668f..11d154f8f 100644
+ if (*ps == '\t')
+ {
+ if (ssc < ds)
+-@@ -1001,11 +1607,11 @@ u32_draw_string(const int x, const int y, const uint16
++@@ -1017,11 +1650,11 @@ u32_draw_string(const int x, const int y, const uint16
+ }
+ ssc += w;
+ }
+@@ -895,10 +922,18 @@ index c012a668f..11d154f8f 100644
+ }
+
+ diff --git a/draw.h b/draw.h
+-index c012a668f..11d154f8f 100644
++index 504bf7d20..4673c3e20 100644
+ --- a/draw.h
+ +++ b/draw.h
+-@@ -63,17 +63,69 @@ struct Color {
++@@ -1,6 +1,7 @@
++ /* This program is licensed under the terms of GNU GPL v3 or (at your option)
++ * any later version. Copyright (C) 2022-2024 Страхиња Радић.
++ * See the file LICENSE for exact copyright and license details. */
+++
++ #include <stddef.h>
++ #include <sys/types.h>
++ #include <termios.h>
++@@ -62,17 +63,69 @@ struct Color {
+ uint16_t bg;
+ };
+
+@@ -968,7 +1003,7 @@ index c012a668f..11d154f8f 100644
+ };
+
+ struct DrawState {
+-@@ -113,12 +165,20 @@ struct DrawState {
++@@ -112,12 +165,20 @@ struct DrawState {
+ int dirty;
+ int new_file;
+ int recalculate_size;
+@@ -989,7 +1024,7 @@ index c012a668f..11d154f8f 100644
+ };
+
+ struct Key {
+-@@ -134,6 +194,13 @@ struct StatusSegment {
++@@ -133,6 +194,13 @@ struct StatusSegment {
+ Alignment alignment;
+ };
+
+@@ -1003,7 +1038,7 @@ index c012a668f..11d154f8f 100644
+ void assign_coord(struct Coord* dest, const struct Coord src);
+ ssize_t buffer_length(uint32_t* buffer, const ssize_t max_index);
+ int calculate_help_width(const struct DrawState* state);
+-@@ -150,7 +217,8 @@ void draw_rect(const int startx, const int endx, const
++@@ -149,7 +217,8 @@ void draw_rect(const int startx, const int endx, const
+ int draw_screen(const struct DrawState* state);
+ int draw_status(const struct DrawState* state);
+ int draw_string(const int x, const int y, const uint16_t fg, const uint16_t bg,
+@@ -1013,8 +1048,8 @@ index c012a668f..11d154f8f 100644
+ const int padding_left, const int padding_right, const Alignment align,
+ const int ds, const int fill, const uint32_t* srch, const uint16_t sfg,
+ const uint16_t sbg, const int ssi, const int sei, const uint16_t slfg,
+-@@ -171,10 +239,12 @@ void init_drawstate(struct DrawState* state, char* fil
+- const int skip_paste_and_mode_init, const int skip_filenames_init);
++@@ -172,10 +241,12 @@ void init_drawstate(struct DrawState* state, char* err
++ const int skip_filenames_init);
+ void recalculate_line_numbers(struct DrawState* state);
+ void recalculate_size(struct DrawState* state);
+ +void recalculate_syntax(struct DrawState* state);
+@@ -1032,10 +1067,10 @@ index c012a668f..11d154f8f 100644
+ + const uint16_t sbg, const int ssi, const int sei, const uint16_t slfg,
+ + const uint16_t slbg);
+ diff --git a/sled.c b/sled.c
+-index c012a668f..11d154f8f 100644
++index 504bf7d20..4673c3e20 100644
+ --- a/sled.c
+ +++ b/sled.c
+-@@ -50,6 +50,18 @@ extern const char* prompt_reread_dirty;
++@@ -67,6 +67,18 @@ extern const char* prompt_reread_dirty;
+ extern const char* replace_dialog_title;
+ extern const char* search_dialog_title;
+
+@@ -1054,19 +1089,20 @@ index c012a668f..11d154f8f 100644
+ static int
+ cancel_close(struct DrawState* state)
+ {
+-@@ -175,8 +187,9 @@ create_file(struct DrawState* state)
++@@ -193,9 +205,9 @@ create_file(struct DrawState* state)
+ state->buffer_size = ALLOC_DELTA;
+ state->rows_count = 1;
+ recalculate_line_numbers(state);
+ - state->coord.row = 0;
+ - state->dirty = 1;
++-
+ + state->coord.row = 0;
+ + state->dirty = 1;
+ + state->recalculate_syntax = 1;
+-
+- return 0;
++ return LOAD_ERR_NONE;
+ }
+-@@ -307,6 +320,7 @@ do_search_replace(struct DrawState* state)
++
++@@ -325,6 +337,7 @@ do_search_replace(struct DrawState* state)
+ state->buffer[row].length = buflen;
+ }
+ free(buf);
+@@ -1074,7 +1110,7 @@ index c012a668f..11d154f8f 100644
+ return 0;
+
+ do_search_replace_alloc_error:
+-@@ -357,7 +371,8 @@ erase_backwards(struct DrawState* state)
++@@ -377,7 +390,8 @@ erase_backwards(struct DrawState* state)
+ buffer_line->text[i - 1] = 0;
+ buffer_line->length--;
+ position_to(state, state->coord.row, state->coord.col - 1);
+@@ -1084,7 +1120,7 @@ index c012a668f..11d154f8f 100644
+ }
+ else if (state->coord.row > 0)
+ {
+-@@ -394,7 +409,8 @@ erase_forward(struct DrawState* state)
++@@ -414,7 +428,8 @@ erase_forward(struct DrawState* state)
+ }
+ buffer_line->text[i] = 0;
+ buffer_line->length--;
+@@ -1094,7 +1130,7 @@ index c012a668f..11d154f8f 100644
+ }
+ else if ((state->coord.row + 1) < state->rows_count)
+ simple_join_lines(state);
+-@@ -428,7 +444,8 @@ erase_line(struct DrawState* state)
++@@ -449,7 +464,8 @@ erase_line(struct DrawState* state)
+ state->coord.row--;
+ position_to(state, state->coord.row, 0);
+ state->rows_count--;
+@@ -1104,7 +1140,7 @@ index c012a668f..11d154f8f 100644
+ recalculate_line_numbers(state);
+ return 0;
+
+-@@ -467,6 +484,7 @@ erase_prev_word(struct DrawState* state)
++@@ -489,6 +505,7 @@ erase_prev_word(struct DrawState* state)
+ state->coord.col = i;
+ state->display_column = display_length(current->text, state->coord.col);
+ state->dirty = 1;
+@@ -1112,7 +1148,7 @@ index c012a668f..11d154f8f 100644
+ return 0;
+ }
+
+-@@ -522,7 +540,8 @@ erase_selection(struct DrawState* state)
++@@ -544,7 +561,8 @@ erase_selection(struct DrawState* state)
+ recalculate_line_numbers(state);
+ }
+ free(buf);
+@@ -1122,7 +1158,7 @@ index c012a668f..11d154f8f 100644
+ }
+ return 0;
+ }
+-@@ -547,7 +566,8 @@ erase_to_end(struct DrawState* state)
++@@ -569,7 +587,8 @@ erase_to_end(struct DrawState* state)
+ buffer_line->text[state->coord.col] = 0;
+ buffer_line->length = state->coord.col;
+ move_end(state);
+@@ -1132,7 +1168,7 @@ index c012a668f..11d154f8f 100644
+ return 0;
+ }
+
+-@@ -581,7 +601,8 @@ erase_to_start(struct DrawState* state)
++@@ -603,7 +622,8 @@ erase_to_start(struct DrawState* state)
+ buffer_line->text[len - state->coord.col] = 0;
+ buffer_line->length = len - state->coord.col;
+ move_start(state);
+@@ -1142,7 +1178,7 @@ index c012a668f..11d154f8f 100644
+ return 0;
+ }
+
+-@@ -1130,8 +1151,8 @@ insert_char(struct DrawState* state, uint32_t ch)
++@@ -1159,8 +1179,8 @@ insert_char(struct DrawState* state, uint32_t ch)
+ }
+
+ insert_skip_wrap:
+@@ -1153,7 +1189,7 @@ index c012a668f..11d154f8f 100644
+ return 0;
+
+ insert_char_error:
+-@@ -1182,7 +1203,8 @@ insert_skip_wrap:
++@@ -1212,7 +1232,8 @@ insert_skip_wrap:
+ simple_insert_line(state);
+ state->saved_column = -1;
+ position_to(state, state->coord.row + 1, 0);
+@@ -1163,7 +1199,7 @@ index c012a668f..11d154f8f 100644
+ return 0;
+ }
+
+-@@ -1704,7 +1726,8 @@ paste_from_paste(struct DrawState* state)
++@@ -1747,7 +1768,8 @@ paste_from_paste(struct DrawState* state)
+ }
+
+ position_to(state, newpos.row, newpos.col);
+@@ -1173,15 +1209,15 @@ index c012a668f..11d154f8f 100644
+
+ paste_from_paste_cleanup:
+ free(rest);
+-@@ -1970,6 +1993,7 @@ reread_file(struct DrawState* state)
++@@ -2025,6 +2047,7 @@ reread_file(struct DrawState* state)
++ break;
++ default:
++ recalculate_line_numbers(state);
+++ state->recalculate_syntax = 1;
+ }
+-
+- recalculate_line_numbers(state);
+-+ state->recalculate_syntax = 1;
+- return 0;
++ return result;
+ }
+-
+-@@ -2357,6 +2381,7 @@ simple_join_lines(struct DrawState* state)
++@@ -2438,6 +2461,7 @@ simple_join_lines(struct DrawState* state)
+ state->rows_count--;
+ state->dirty = 1;
+ recalculate_line_numbers(state);
+@@ -1189,19 +1225,19 @@ index c012a668f..11d154f8f 100644
+ return;
+
+ simple_join_lines_error:
+-@@ -2831,6 +2856,8 @@ main(int argc, char** argv)
++@@ -2905,6 +2929,8 @@ main(int argc, char** argv)
++ int result = 0;
+ int dir_access;
+ int dir_access_errno;
+- int saved_errno;
+ + int found_ending = 0;
+ + int i;
+
+- *prompt = 0;
++ *error = 0;
++ *action = 0;
++@@ -2988,6 +3014,40 @@ main(int argc, char** argv)
+
+-@@ -2913,6 +2940,40 @@ main(int argc, char** argv)
++ init_drawstate(&state, error, action, filename, prompt, 0, 0);
+
+- init_drawstate(&state, filename, prompt, 0, 0);
+-
+ + for (i = 0; (size_t)i < LEN(syntax_endings); i++)
+ + {
+ + int filename_len = strlen(state.filename);
+@@ -1239,21 +1275,21 @@ index c012a668f..11d154f8f 100644
+ #ifdef __OpenBSD__
+ if (unveil(state.filename, "rwc") < 0)
+ {
+-@@ -3122,9 +3183,10 @@ main_skip_backups:
++@@ -3210,9 +3270,10 @@ main_skip_backups:
++
+ init_termbox:
+- if (tb_init())
+- goto main_done;
+-- errno = 0;
++ tb_init();
++- *error = 0;
+ - state.maxx = 0;
+ - state.recalculate_size = 1;
+-+ errno = 0;
+++ *error = 0;
+ + state.maxx = 0;
+ + state.recalculate_size = 1;
+ + state.recalculate_syntax = 1;
+
+ while (state.running)
+ {
+-@@ -3136,6 +3198,11 @@ init_termbox:
++@@ -3224,6 +3285,11 @@ init_termbox:
+ recalculate_size(&state);
+ state.recalculate_size = 0;
+ }
diff --git a/sled.c b/sled.c
-index 504bf7d20..4673c3e20 100644
+index fcae0e64e..374ad0700 100644
--- a/sled.c
+++ b/sled.c
-@@ -67,6 +67,18 @@ extern const char* prompt_reread_dirty;
+@@ -50,6 +50,18 @@ extern const char* prompt_reread_dirty;
extern const char* replace_dialog_title;
extern const char* search_dialog_title;
@@ -1089,20 +1800,19 @@ index 504bf7d20..4673c3e20 100644
static int
cancel_close(struct DrawState* state)
{
-@@ -193,9 +205,9 @@ create_file(struct DrawState* state)
+@@ -175,8 +187,9 @@ create_file(struct DrawState* state)
state->buffer_size = ALLOC_DELTA;
state->rows_count = 1;
recalculate_line_numbers(state);
- state->coord.row = 0;
- state->dirty = 1;
--
+ state->coord.row = 0;
+ state->dirty = 1;
+ state->recalculate_syntax = 1;
- return LOAD_ERR_NONE;
- }
-@@ -325,6 +337,7 @@ do_search_replace(struct DrawState* state)
+ return 0;
+ }
+@@ -307,6 +320,7 @@ do_search_replace(struct DrawState* state)
state->buffer[row].length = buflen;
}
free(buf);
@@ -1110,7 +1820,7 @@ index 504bf7d20..4673c3e20 100644
return 0;
do_search_replace_alloc_error:
-@@ -377,7 +390,8 @@ erase_backwards(struct DrawState* state)
+@@ -357,7 +371,8 @@ erase_backwards(struct DrawState* state)
buffer_line->text[i - 1] = 0;
buffer_line->length--;
position_to(state, state->coord.row, state->coord.col - 1);
@@ -1120,7 +1830,7 @@ index 504bf7d20..4673c3e20 100644
}
else if (state->coord.row > 0)
{
-@@ -414,7 +428,8 @@ erase_forward(struct DrawState* state)
+@@ -394,7 +409,8 @@ erase_forward(struct DrawState* state)
}
buffer_line->text[i] = 0;
buffer_line->length--;
@@ -1130,7 +1840,7 @@ index 504bf7d20..4673c3e20 100644
}
else if ((state->coord.row + 1) < state->rows_count)
simple_join_lines(state);
-@@ -449,7 +464,8 @@ erase_line(struct DrawState* state)
+@@ -428,7 +444,8 @@ erase_line(struct DrawState* state)
state->coord.row--;
position_to(state, state->coord.row, 0);
state->rows_count--;
@@ -1140,7 +1850,7 @@ index 504bf7d20..4673c3e20 100644
recalculate_line_numbers(state);
return 0;
-@@ -489,6 +505,7 @@ erase_prev_word(struct DrawState* state)
+@@ -467,6 +484,7 @@ erase_prev_word(struct DrawState* state)
state->coord.col = i;
state->display_column = display_length(current->text, state->coord.col);
state->dirty = 1;
@@ -1148,7 +1858,7 @@ index 504bf7d20..4673c3e20 100644
return 0;
}
-@@ -544,7 +561,8 @@ erase_selection(struct DrawState* state)
+@@ -522,7 +540,8 @@ erase_selection(struct DrawState* state)
recalculate_line_numbers(state);
}
free(buf);
@@ -1158,7 +1868,7 @@ index 504bf7d20..4673c3e20 100644
}
return 0;
}
-@@ -569,7 +587,8 @@ erase_to_end(struct DrawState* state)
+@@ -547,7 +566,8 @@ erase_to_end(struct DrawState* state)
buffer_line->text[state->coord.col] = 0;
buffer_line->length = state->coord.col;
move_end(state);
@@ -1168,7 +1878,7 @@ index 504bf7d20..4673c3e20 100644
return 0;
}
-@@ -603,7 +622,8 @@ erase_to_start(struct DrawState* state)
+@@ -581,7 +601,8 @@ erase_to_start(struct DrawState* state)
buffer_line->text[len - state->coord.col] = 0;
buffer_line->length = len - state->coord.col;
move_start(state);
@@ -1178,7 +1888,7 @@ index 504bf7d20..4673c3e20 100644
return 0;
}
-@@ -1159,8 +1179,8 @@ insert_char(struct DrawState* state, uint32_t ch)
+@@ -1130,8 +1151,8 @@ insert_char(struct DrawState* state, uint32_t ch)
}
insert_skip_wrap:
@@ -1189,7 +1899,7 @@ index 504bf7d20..4673c3e20 100644
return 0;
insert_char_error:
-@@ -1212,7 +1232,8 @@ insert_skip_wrap:
+@@ -1182,7 +1203,8 @@ insert_skip_wrap:
simple_insert_line(state);
state->saved_column = -1;
position_to(state, state->coord.row + 1, 0);
@@ -1199,7 +1909,7 @@ index 504bf7d20..4673c3e20 100644
return 0;
}
-@@ -1747,7 +1768,8 @@ paste_from_paste(struct DrawState* state)
+@@ -1704,7 +1726,8 @@ paste_from_paste(struct DrawState* state)
}
position_to(state, newpos.row, newpos.col);
@@ -1209,15 +1919,15 @@ index 504bf7d20..4673c3e20 100644
paste_from_paste_cleanup:
free(rest);
-@@ -2025,6 +2047,7 @@ reread_file(struct DrawState* state)
- break;
- default:
- recalculate_line_numbers(state);
-+ state->recalculate_syntax = 1;
+@@ -1970,6 +1993,7 @@ reread_file(struct DrawState* state)
}
- return result;
+
+ recalculate_line_numbers(state);
++ state->recalculate_syntax = 1;
+ return 0;
}
-@@ -2438,6 +2461,7 @@ simple_join_lines(struct DrawState* state)
+
+@@ -2357,6 +2381,7 @@ simple_join_lines(struct DrawState* state)
state->rows_count--;
state->dirty = 1;
recalculate_line_numbers(state);
@@ -1225,18 +1935,18 @@ index 504bf7d20..4673c3e20 100644
return;
simple_join_lines_error:
-@@ -2905,6 +2929,8 @@ main(int argc, char** argv)
- int result = 0;
+@@ -2831,6 +2856,8 @@ main(int argc, char** argv)
int dir_access;
int dir_access_errno;
+ int saved_errno;
+ int found_ending = 0;
+ int i;
- *error = 0;
- *action = 0;
-@@ -2988,6 +3014,40 @@ main(int argc, char** argv)
+ *prompt = 0;
+
+@@ -2913,6 +2940,40 @@ main(int argc, char** argv)
- init_drawstate(&state, error, action, filename, prompt, 0, 0);
+ init_drawstate(&state, filename, prompt, 0, 0);
+ for (i = 0; (size_t)i < LEN(syntax_endings); i++)
+ {
@@ -1275,21 +1985,21 @@ index 504bf7d20..4673c3e20 100644
#ifdef __OpenBSD__
if (unveil(state.filename, "rwc") < 0)
{
-@@ -3210,9 +3270,10 @@ main_skip_backups:
-
+@@ -3122,9 +3183,10 @@ main_skip_backups:
init_termbox:
- tb_init();
-- *error = 0;
+ if (tb_init())
+ goto main_done;
+- errno = 0;
- state.maxx = 0;
- state.recalculate_size = 1;
-+ *error = 0;
++ errno = 0;
+ state.maxx = 0;
+ state.recalculate_size = 1;
+ state.recalculate_syntax = 1;
while (state.running)
{
-@@ -3224,6 +3285,11 @@ init_termbox:
+@@ -3136,6 +3198,11 @@ init_termbox:
recalculate_size(&state);
state.recalculate_size = 0;
}