aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parser.c
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2026-09-27 00:12:30 +0200
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2026-09-27 00:12:30 +0200
commite48f1a6b5319224a92a8e7d60cbf5a4098d14ff5 (patch)
tree466ba5783925972a079fd5921237e9f29878d35a /src/parser.c
parente371b5fc710c597e175e6b7d7645b3a224a731a1 (diff)
^E at the end of a line in a string argument "swallows" the EOL characterHEADmaster-fmsbw-cimaster
This is similar to `\` at the line end in many languages like C and allows you to split a very long string argument over several lines without adding the EOL characters themselves. The TECO equivalent to `\` would be ^Q, but it would be a semantic exception since ^Q (escaping) is supposed to _preserve_ the value of the following character. Therefore I decided to use ^E instead. This works with DOS and Mac line breaks as well.
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/parser.c b/src/parser.c
index 8b02764..45e1e3c 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -487,6 +487,7 @@ static teco_state_t teco_state_stringbuilding_lower;
static teco_state_t teco_state_stringbuilding_upper;
static teco_state_t teco_state_stringbuilding_ctle;
+static teco_state_t teco_state_stringbuilding_ctle_cr;
static teco_state_t teco_state_stringbuilding_ctle_num;
static teco_state_t teco_state_stringbuilding_ctle_u;
static teco_state_t teco_state_stringbuilding_ctle_code;
@@ -714,6 +715,8 @@ teco_state_stringbuilding_ctle_input(teco_machine_stringbuilding_t *ctx, gunicha
teco_state_t *next;
switch (teco_ascii_toupper(chr)) {
+ case '\r': return &teco_state_stringbuilding_ctle_cr;
+ case '\n': return &teco_state_stringbuilding_start;
case '\\': next = &teco_state_stringbuilding_ctle_num; break;
case 'U': next = &teco_state_stringbuilding_ctle_u; break;
case '<': next = &teco_state_stringbuilding_ctle_code; break;
@@ -747,6 +750,17 @@ static TECO_DEFINE_STATE_CASEINSENSITIVE(teco_state_stringbuilding_ctle,
gboolean teco_state_stringbuilding_qreg_process_edit_cmd(teco_machine_stringbuilding_t *ctx, teco_machine_t *parent_ctx,
gunichar chr, GError **error);
+static teco_state_t *
+teco_state_stringbuilding_ctle_cr_input(teco_machine_stringbuilding_t *ctx, gunichar chr, GError **error)
+{
+ return chr == '\n' ? &teco_state_stringbuilding_start /* DOS linebreak */
+ : teco_state_stringbuilding_start_input(ctx, chr, error); /* Mac linebreak */
+}
+
+static TECO_DEFINE_STATE(teco_state_stringbuilding_ctle_cr,
+ .input_cb = (teco_state_input_cb_t)teco_state_stringbuilding_ctle_cr_input
+);
+
/**
* @interface TECO_DEFINE_STATE_STRINGBUILDING_QREG
* @implements TECO_DEFINE_STATE