From e48f1a6b5319224a92a8e7d60cbf5a4098d14ff5 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 27 Sep 2026 00:12:30 +0200 Subject: ^E at the end of a line in a string argument "swallows" the EOL character 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. --- src/parser.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') 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 -- cgit v1.2.3