diff options
| author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-11-24 04:38:16 +0300 |
|---|---|---|
| committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-11-24 04:51:34 +0300 |
| commit | 23c90e37ff48707c4aabdb8b1460df382a600d7a (patch) | |
| tree | 08547d899cc281ba2be0d96c785e64e7a4d04313 /src/qreg.c | |
| parent | 26e54b9248ca8be07530fb19422082827ee1fead (diff) | |
added special Q-Register ":" for accessing dot
* We cannot call it "." since that introduces a local register
and we don't want to add an unnecessary syntactic exception.
* Allows the idiom [: ... ]: to temporarily move around.
Also, you can now write ^E\: without having to store dot in a register first.
* In the future we might add an ^E register as well for byte offsets.
However, there are much fewer useful applications.
* Of course, you can now also write nU: instead of nJ, Q: instead of "." and
n%: instead of "nC.". However it's all not really useful.
Diffstat (limited to 'src/qreg.c')
| -rw-r--r-- | src/qreg.c | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -398,6 +398,56 @@ teco_qreg_plain_new(const gchar *name, gsize len) return teco_qreg_new(&vtable, name, len); } +/* see also teco_state_start_jump() */ +static gboolean +teco_qreg_dot_set_integer(teco_qreg_t *qreg, teco_int_t value, GError **error) +{ + gssize pos = teco_interface_glyphs2bytes(value); + if (pos < 0) { + g_set_error_literal(error, TECO_ERROR, TECO_ERROR_MOVE, + "Attempt to move pointer off page when setting Q-Register \":\""); + return FALSE; + } + + teco_interface_ssm(SCI_GOTOPOS, pos, 0); + return TRUE; +} + +static gboolean +teco_qreg_dot_undo_set_integer(teco_qreg_t *qreg, GError **error) +{ + if (teco_current_doc_must_undo()) + undo__teco_interface_ssm(SCI_GOTOPOS, + teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0), 0); + return TRUE; +} + +/* see also teco_state_start_dot() */ +static gboolean +teco_qreg_dot_get_integer(teco_qreg_t *qreg, teco_int_t *ret, GError **error) +{ + sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + *ret = teco_interface_bytes2glyphs(pos); + return TRUE; +} + +/** @static @memberof teco_qreg_t */ +teco_qreg_t * +teco_qreg_dot_new(void) +{ + static teco_qreg_vtable_t vtable = TECO_INIT_QREG( + .set_integer = teco_qreg_dot_set_integer, + .undo_set_integer = teco_qreg_dot_undo_set_integer, + .get_integer = teco_qreg_dot_get_integer + ); + + /* + * If we wanted to use ".", we'd have to either make this a local register + * or add ".." as special syntax equivalent to [.]. + */ + return teco_qreg_new(&vtable, ":", 1); +} + static gboolean teco_qreg_radix_set_integer(teco_qreg_t *qreg, teco_int_t value, GError **error) { |
