diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-09-27 00:12:30 +0200 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-09-27 00:12:30 +0200 |
| commit | e48f1a6b5319224a92a8e7d60cbf5a4098d14ff5 (patch) | |
| tree | 466ba5783925972a079fd5921237e9f29878d35a | |
| parent | e371b5fc710c597e175e6b7d7645b3a224a731a1 (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.
| -rw-r--r-- | doc/sciteco.7.template | 5 | ||||
| -rw-r--r-- | src/parser.c | 14 | ||||
| -rw-r--r-- | tests/testsuite.at | 2 |
3 files changed, 21 insertions, 0 deletions
diff --git a/doc/sciteco.7.template b/doc/sciteco.7.template index 14aee77..86ca68f 100644 --- a/doc/sciteco.7.template +++ b/doc/sciteco.7.template @@ -1878,6 +1878,11 @@ Analogous to \fB^V\fP, but upper-cases characters. Since \fB^W\fP is an immediate editing command, this can practically be typed only with upcarets in interactive mode. .TP +.SCITECO_TOPIC ^E^J ^E^M^J ^E^M +.BI ^E eol +\fB^E\fP followed by an end of line character (LF, CRLF or CR) is ignored, +so you can split a long string argument over several lines. +.TP .SCITECO_TOPIC ^E\[rs] ^E\[rs]q .BI ^E\(rs q Expands to the formatted number stored in the 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 diff --git a/tests/testsuite.at b/tests/testsuite.at index 5d4ec43..4378ca0 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -138,6 +138,8 @@ TE_CHECK([[@I/X/ H@FR{X}/12345/ Z-5"N(0/0)']], 0, ignore, ignore) TE_CHECK([[@Ia^EQa(0/0)a]], 0, ignore, ignore) # Video-TECO-like syntax - might change in the future TE_CHECK([[@I/^E<65>^E<0x41>^E<0101>/ <-A:; -A-^^A"N(0/0)' R>]], 0, ignore, ignore) +TE_CHECK([[@I/01^E +23/ .-4"N(0/0)']], 0, ignore, ignore) # TODO: More string building constructs AT_CLEANUP |
