aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-01-28 06:21:12 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-01-28 06:32:47 +0300
commitf2b070cb6ced1828c3328b02f0b437cf19a7cfd1 (patch)
treea144e64ff9a01bad699e226904d1d427bb912b25
parent56c68477267d28f86b46692754874ea93526f47d (diff)
downloadsciteco-f2b070cb6ced1828c3328b02f0b437cf19a7cfd1.tar.gz
cursor movement via fnkeys.tes now preserves the column as in most text editors
* Horizontal movements (left/right cursor keys) establish the current column and vertical movements (up/down) will try to keep on that column. * This has long been problematic in SciTECO as it requires state that gets reversed when the command line replacement takes place. * I experimented with encoding the current horizontal position into the braced movement operations as in (123C5U$), but I decided that this was clumsy and I generally did not want these expressions to become even larger. * Instead I decided to add some minimal support to the C core in the form of 4EJ which is like a number register only that it does NOT get reversed on rubout. This is exploited by the fnkeys.tes macros by storing the current position beyond replacements. * In theory, this should be a property of the document, but we cannot easily store custom parameters per document. So instead, there is just one global variable. When editing another buffer, it gets reset to .ESGETCOLUMN$$. sample.teco_ini has been updated. * The current X position only makes sense in the context of fnkeys.tes, as TECO commands like <C> are not necessarily "horizonal" movements. For the same reason, the core does not try to initialize 4EJ automatically when editing new buffers. It's entirely left to the TECO macros. * The commandline replacement is more robust now as it checks braced expressions at the end of the command line more thorougly. It will no longer swallow all preceding braced expressions. Only if they are at least 4 characters in length and end in `C)` or `R)`.
-rw-r--r--lib/fnkeys.tes75
-rw-r--r--sample.teco_ini1
-rw-r--r--src/core-commands.c19
3 files changed, 67 insertions, 28 deletions
diff --git a/lib/fnkeys.tes b/lib/fnkeys.tes
index f33af2b..036445b 100644
--- a/lib/fnkeys.tes
+++ b/lib/fnkeys.tes
@@ -1,43 +1,59 @@
-! Here we define some reasonable default function key macros.
- Their corresponding command-line editing macros begin with  !
+!*
+ * Here we define some reasonable default function key macros.
+ * Their corresponding command-line editing macros begin with .
+ *!
-! edit command line to move <n> chars, updating existing move ops !
+!*
+ * Edit command line to move <n> chars, updating existing move ops.
+ * The command line at the time of call looks like: (123C)(M[FOO
+ *!
@#c{{U.c
<-A-("=-D1;' -D>
- .">
- -A-)"= -S(\U.v .,Z-2D 0A-C"=2DQ.v|2D-Q.v'%.c | I(Q.c '
- | I(Q.c '
- "> Q.c\IC) | -Q.c\IR) '
+ .-4"< Oins ' -2A-C"N -2A-R"N Oins ' ' -A-)"N Oins '
+ <R -A-("=1;'>
+ \U.v .-1,Z-2D 0A-R"=-'Q.v%.c 2D
+ !ins!
+ I( Q.c"> Q.c\IC | -Q.c\IR ' I)
}}
-! Make DELETE an ESCAPE surrogate.
- Macro is enabled everywhere. !
+!*
+ * Make DELETE an ESCAPE surrogate.
+ * Macro is enabled everywhere.
+ *!
@[DC]{}
-! Make SHIFT+DELETE a rubout/re-insert key.
- This reverses the ^G modifier for BACKSPACE.
- The macro is enabled everywhere. !
+!*
+ * Make SHIFT+DELETE a rubout/re-insert key.
+ * This reverses the ^G modifier for BACKSPACE.
+ * The macro is enabled everywhere.
+ *!
@[SDC]{}
-! Command line editing macros.
- They are enabled only in the start state (i.e. they
- have no effect in string arguments, etc.). !
+!*
+ * Command line editing macros.
+ * They are enabled only in the start state (i.e. they
+ * have no effect in string arguments, etc.).
+ *!
@[HOME]{
.ESLINEFROMPOSITIONESPOSITIONFROMLINEU.p
Q.pU.l <Q.l-."U 1; ' Q.l-.AU.c Q.c- "N Q.c-9"N Q.lU.p 1; '' %.l>
+ Q.pESGETCOLUMN,4EJ
Q.p-.M#c
}
@[HOME]{(M[HOME]}
1U[HOME]
@[END]{
- .ESLINEFROMPOSITIONESGETLINEENDPOSITION-.M#c
+ .ESLINEFROMPOSITIONESGETLINEENDPOSITIONU.p
+ Q.pESGETCOLUMN,4EJ
+ Q.p-.M#c
}
@[END]{(M[END]}
1U[END]
@[NPAGE]{
+ 0,4EJ
.ESLINEFROMPOSITION+(ESLINESONSCREEN)
ESPOSITIONFROMLINEU.p
Q.p"< Z | Q.p '-.M#c
@@ -46,6 +62,7 @@
1U[NPAGE]
@[PPAGE]{
+ 0,4EJ
.ESLINEFROMPOSITION-(ESLINESONSCREEN)U.l
Q.l"< 0 | Q.lESPOSITIONFROMLINE '-.M#c
}
@@ -53,41 +70,45 @@
1U[PPAGE]
@[LEFT]{
- ."=0|-1'M#c
+ ."=0|.-1'U.p
+ Q.pESGETCOLUMN,4EJ
+ Q.p-.M#c
}
@[LEFT]{(M[LEFT]}
1U[LEFT]
@[SLEFT]{
- 0,0,.ESWORDSTARTPOSITIONESWORDSTARTPOSITION-.M#c
+ 0,0,.ESWORDSTARTPOSITIONESWORDSTARTPOSITIONU.p
+ Q.pESGETCOLUMN,4EJ
+ Q.p-.M#c
}
@[SLEFT]{(M[SLEFT]}
1U[SLEFT]
@[RIGHT]{
- .-Z"=0|1'M#c
+ .-Z"=.|.+1'U.p
+ Q.pESGETCOLUMN,4EJ
+ Q.p-.M#c
}
@[RIGHT]{(M[RIGHT]}
1U[RIGHT]
@[SRIGHT]{
- 0,0,.ESWORDENDPOSITIONESWORDENDPOSITION-.M#c
+ 0,0,.ESWORDENDPOSITIONESWORDENDPOSITIONU.p
+ Q.pESGETCOLUMN,4EJ
+ Q.p-.M#c
}
@[SRIGHT]{(M[SRIGHT]}
1U[SRIGHT]
@[UP]{
- .ESGETCOLUMN
- (.ESLINEFROMPOSITION-1)
- ESFINDCOLUMN-.M#c
+ 4EJ(.ESLINEFROMPOSITION-1)ESFINDCOLUMN-.M#c
}
@[UP]{(M[UP]}
1U[UP]
@[DOWN]{
- .ESGETCOLUMN
- (.ESLINEFROMPOSITION+1)
- ESFINDCOLUMN-.M#c
+ 4EJ(.ESLINEFROMPOSITION+1)ESFINDCOLUMN-.M#c
}
@[DOWN]{(M[DOWN]}
1U[DOWN]
@@ -104,5 +125,5 @@
@[F10]{(ESZOOMIN{-12D}}
1U[F10]
-! enable function key (macro) support !
+!* enable function key (macro) support *!
0,64ED
diff --git a/sample.teco_ini b/sample.teco_ini
index 95e56a6..d25b176 100644
--- a/sample.teco_ini
+++ b/sample.teco_ini
@@ -30,6 +30,7 @@ EMQ[$SCITECOPATH]/session.tes
!edit!
! Add code here to execute when a document is edited !
+ .ESGETCOLUMN,4EJ

!close!
diff --git a/src/core-commands.c b/src/core-commands.c
index 237416d..bfec8be 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -2098,6 +2098,12 @@ teco_state_ecommand_flags(teco_machine_main_t *ctx, GError **error)
* on exit the author is aware of is \fBxterm\fP(1) and
* the Linux console driver.
* You have been warned. Good luck.
+ * .IP 4
+ * The column after the last horizontal movement.
+ * This is only used by \fCfnkeys.tes\fP and is similar to the Scintilla-internal
+ * setting \fBSCI_CHOOSECARETX\fP.
+ * Unless most other settings, this is on purpose not restored on rubout,
+ * so it "survives" command line replacements.
*/
static void
teco_state_ecommand_properties(teco_machine_main_t *ctx, GError **error)
@@ -2106,9 +2112,12 @@ teco_state_ecommand_properties(teco_machine_main_t *ctx, GError **error)
EJ_USER_INTERFACE = 0,
EJ_BUFFERS,
EJ_MEMORY_LIMIT,
- EJ_INIT_COLOR
+ EJ_INIT_COLOR,
+ EJ_CARETX
};
+ static teco_int_t caret_x = 0;
+
teco_int_t property;
if (!teco_expressions_eval(FALSE, error) ||
!teco_expressions_pop_num_calc(&property, teco_num_sign, error))
@@ -2144,6 +2153,10 @@ teco_state_ecommand_properties(teco_machine_main_t *ctx, GError **error)
teco_interface_init_color((guint)value, (guint32)color);
break;
+ case EJ_CARETX:
+ caret_x = value;
+ break;
+
default:
g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED,
"Cannot set property %" TECO_INT_FORMAT " "
@@ -2180,6 +2193,10 @@ teco_state_ecommand_properties(teco_machine_main_t *ctx, GError **error)
teco_expressions_push(teco_memory_limit);
break;
+ case EJ_CARETX:
+ teco_expressions_push(caret_x);
+ break;
+
default:
g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED,
"Invalid property %" TECO_INT_FORMAT " "