aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parser.h
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-09-12 13:55:40 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-09-12 16:44:13 +0200
commitabb5d23eba21a2aafda0346c0c5dd845561b2aa2 (patch)
tree9e42c1e72e0d61c322c0af8d54a9d740a7e2e45c /src/parser.h
parent73d574b71a10d4661ada20275cafde75aff6c1ba (diff)
downloadsciteco-abb5d23eba21a2aafda0346c0c5dd845561b2aa2.tar.gz
function key macros have been reworked into a more generic key macro feature
* ALL keypresses (the UTF-8 sequences resulting from key presses) can now be remapped. * This is especially useful with Unicode support, as you might want to alias international characters to their corresponding latin form in the start state, so you don't have to change keyboard layouts so often. This is done automatically in Gtk, where we have hardware key press information, but has to be done with key macros in Curses. There is a new key mask 4 (bit 3) for that purpose now. * Also, you might want to define non-ANSI letters to perform special functions in the start state where it won't be accepted by the parser anyway. Suppose you have a macro M→, you could define @^U[^K→]{m→} 1^_U[^K→] This effectively "extends" the parser and allow you to call macro "→" by a single key press. See also #5. * The register prefix has been changed from ^F (for function) to ^K (for key). This is the only thing you have to change in order to migrate existing function key macros. * Key macros are enabled by default. There is no longer any way to disable function key handling in curses, as I never found any reason or need to disable it. Theoretically, the default ESCDELAY could turn out to be too small and function keys don't get through. I doubt that's possible unless on extremely slow serial lines. Even then, you'd have to increase ESCDELAY and instead of disabling function keys simply define an escape surrogate. * The ED flag has been removed and its place is reserved for a future mouse support flag (which does make sense to disable in curses sometimes). fnkeys.tes is consequently also enabled by default in sample.teco_ini. * Key macros are handled as an unit. If one character results in an error, the entire string is rubbed out. This fixes the "CLOSE" key on Gtk. It also makes sure that the original error message is preserved and not overwritten by some subsequent syntax error. It was never useful that we kept inserting characters after the first error.
Diffstat (limited to 'src/parser.h')
-rw-r--r--src/parser.h30
1 files changed, 11 insertions, 19 deletions
diff --git a/src/parser.h b/src/parser.h
index fe7f559..0303bae 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -108,10 +108,11 @@ typedef gboolean (*teco_state_process_edit_cmd_cb_t)(teco_machine_t *ctx, teco_m
gunichar key, GError **error);
typedef enum {
- TECO_FNMACRO_MASK_START = (1 << 0),
- TECO_FNMACRO_MASK_STRING = (1 << 1),
- TECO_FNMACRO_MASK_DEFAULT = ~((1 << 2)-1)
-} teco_fnmacro_mask_t;
+ TECO_KEYMACRO_MASK_START = (1 << 0),
+ TECO_KEYMACRO_MASK_STRING = (1 << 1),
+ TECO_KEYMACRO_MASK_CASEINSENSITIVE = (1 << 2),
+ TECO_KEYMACRO_MASK_DEFAULT = ~((1 << 3)-1)
+} teco_keymacro_mask_t;
/**
* A teco_machine_t state.
@@ -184,28 +185,19 @@ struct teco_state_t {
/**
* Whether this state is a start state (ie. not within any
* escape sequence etc.).
- * This is separate of TECO_FNMACRO_MASK_START which is set
+ * This is separate of TECO_KEYMACRO_MASK_START which is set
* only in the main machine's start states.
*/
bool is_start : 1;
/**
- * Whether this state accepts case insensitive characters,
- * ie. is part of a command name, that can be case folded.
- * This is also used to determine which state accepts only
- * ANSI characters.
- * @fixme But it should be callback to detect all
- * string building constructs nested in Q-Reg specs.
- */
- bool is_case_insensitive : 1;
- /**
- * Function key macro mask.
+ * Key macro mask.
* This is not a bitmask since it is compared with values set
* from TECO, so the bitorder needs to be defined.
*
* @fixme If we intend to "forward" masks from other state machines like
* teco_machine_stringbuilding_t, this should probably be a callback.
*/
- teco_fnmacro_mask_t fnmacro_mask : 8;
+ teco_keymacro_mask_t keymacro_mask : 8;
/**
* Additional state-dependent callbacks and settings.
@@ -245,7 +237,7 @@ gboolean teco_state_process_edit_cmd(teco_machine_t *ctx, teco_machine_t *parent
.end_of_macro_cb = teco_state_end_of_macro, \
.process_edit_cmd_cb = teco_state_process_edit_cmd, \
.is_start = FALSE, \
- .fnmacro_mask = TECO_FNMACRO_MASK_DEFAULT, \
+ .keymacro_mask = TECO_KEYMACRO_MASK_DEFAULT, \
##__VA_ARGS__ \
}
@@ -268,7 +260,7 @@ gboolean teco_state_caseinsensitive_process_edit_cmd(teco_machine_t *ctx, teco_m
*/
#define TECO_DEFINE_STATE_CASEINSENSITIVE(NAME, ...) \
TECO_DEFINE_STATE(NAME, \
- .is_case_insensitive = TRUE, \
+ .keymacro_mask = TECO_KEYMACRO_MASK_CASEINSENSITIVE, \
.process_edit_cmd_cb = teco_state_caseinsensitive_process_edit_cmd, \
##__VA_ARGS__ \
)
@@ -552,7 +544,7 @@ gboolean teco_state_expectstring_process_edit_cmd(teco_machine_main_t *ctx, teco
.refresh_cb = (teco_state_refresh_cb_t)teco_state_expectstring_refresh, \
.process_edit_cmd_cb = (teco_state_process_edit_cmd_cb_t) \
teco_state_expectstring_process_edit_cmd, \
- .fnmacro_mask = TECO_FNMACRO_MASK_STRING, \
+ .keymacro_mask = TECO_KEYMACRO_MASK_STRING, \
.expectstring.string_building = TRUE, \
.expectstring.last = TRUE, \
.expectstring.process_cb = NULL, /* do nothing */ \