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 | |
parent | 26e54b9248ca8be07530fb19422082827ee1fead (diff) | |
download | sciteco-23c90e37ff48707c4aabdb8b1460df382a600d7a.tar.gz |
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.
-rw-r--r-- | TODO | 8 | ||||
-rw-r--r-- | doc/sciteco.7.template | 13 | ||||
-rw-r--r-- | lib/getopt.tes | 8 | ||||
-rw-r--r-- | lib/lexers/git.tes | 6 | ||||
-rw-r--r-- | src/core-commands.c | 2 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/qreg.c | 50 | ||||
-rw-r--r-- | src/qreg.h | 1 | ||||
-rw-r--r-- | tests/testsuite.at | 1 |
9 files changed, 76 insertions, 15 deletions
@@ -356,12 +356,8 @@ Features: cmdline.c can then directly operate on the Scintilla document. * A Scintilla view will allow syntax highlighting * command line could highlight dead branches (e.g. gray them out) - * Add special Q-Register for dot: - Would simplify inserting dot with string building and saving/restoring - dot on the QReg stack. - Since [. is currently not valid and [[.] is cumbersome, there should be - a special syntactic workaround to allow [.. or perhaps we'll simply call - it :, so you can write [: + * Perhaps add a ^E register analogous to ":", but working with + byte offsets. This would mainly be useful in ^E\^E. * EL command could also be used to convert all EOLs in the current buffer. * nEL should perhaps dirtify the buffer, at least when automatic diff --git a/doc/sciteco.7.template b/doc/sciteco.7.template index 8ded77c..99a9178 100644 --- a/doc/sciteco.7.template +++ b/doc/sciteco.7.template @@ -1431,6 +1431,19 @@ Replacement string register. Its integer part is currently unused. It is initialized automatically on startup. .TP +.B : " (colon)" +The current document's position (dot). +This changes dot when set as with the +.B J +and other movement commands. +This allows you to change dot temporarily with the following idiom: +.SCITECO_TT +.EX +[: ! ...change dot... ! ]: +.SCITECO_TT_END +.EE +The string part of this register is currently unused. +.TP .SCITECO_TOPIC filename .BR * " (asterisk)" File name (string part) and id (numeric part) of current diff --git a/lib/getopt.tes b/lib/getopt.tes index a2bcb31..46c813f 100644 --- a/lib/getopt.tes +++ b/lib/getopt.tes @@ -18,15 +18,14 @@ * there was a parsing error. *! [optstring] -@[getopt]{ - .U.d +@[getopt]{ [: < .-Z"= 1; ' 0A-^^-"N :L; F< ' 1A-^^-"= K 1; ' 0U.i < - :Q[optstring]-Q.i"= Q.dJ 0 ' + :Q[optstring]-Q.i"= ]: 0 ' Q.iQ[optstring]U.c 0U.#ar < @@ -48,5 +47,4 @@ ' > > - Q.dJ --1} +]: -1} diff --git a/lib/lexers/git.tes b/lib/lexers/git.tes index 3162f78..567859b 100644 --- a/lib/lexers/git.tes +++ b/lib/lexers/git.tes @@ -7,12 +7,10 @@ :EN*/git-rebase-todoQ* } -@[lexer.set.git]{ +@[lexer.set.git]{[: :M[color.comment],1M[color.set] - .U.p J< .-Z"= 1; ' 0A-#"= ESSTARTSTYLING 1,(Q.lESLINELENGTH)ESSETSTYLING ' :L; %.l> - Q.pJ -} +]:} diff --git a/src/core-commands.c b/src/core-commands.c index c3ec3dd..60e7bcc 100644 --- a/src/core-commands.c +++ b/src/core-commands.c @@ -123,6 +123,8 @@ teco_state_start_comma(teco_machine_main_t *ctx, GError **error) * \(lq.\(rq pushes onto the stack, the current * position (also called <dot>) of the currently * selected buffer or Q-Register. + * + * <dot> is also available in Q-Register \(lq:\(rq. */ static void teco_state_start_dot(teco_machine_main_t *ctx, GError **error) @@ -399,6 +399,8 @@ main(int argc, char **argv) teco_qreg_table_insert(&teco_qreg_table_globals, teco_qreg_plain_new("_", 1)); /* replacement string register */ teco_qreg_table_insert(&teco_qreg_table_globals, teco_qreg_plain_new("-", 1)); + /* current document's dot (":") */ + teco_qreg_table_insert(&teco_qreg_table_globals, teco_qreg_dot_new()); /* current buffer name and number ("*") */ teco_qreg_table_insert(&teco_qreg_table_globals, teco_qreg_bufferinfo_new()); /* current working directory ("$") */ @@ -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) { @@ -112,6 +112,7 @@ struct teco_qreg_t { }; teco_qreg_t *teco_qreg_plain_new(const gchar *name, gsize len); +teco_qreg_t *teco_qreg_dot_new(void); teco_qreg_t *teco_qreg_bufferinfo_new(void); teco_qreg_t *teco_qreg_workingdir_new(void); teco_qreg_t *teco_qreg_clipboard_new(const gchar *name); diff --git a/tests/testsuite.at b/tests/testsuite.at index 31ce257..59b1041 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -94,6 +94,7 @@ AT_SETUP([Q-Register stack]) AT_CHECK([$SCITECO -e "[[a 23Ub ]]b Qb\"N(0/0)'"], 0, ignore, ignore) # FG will temporarily change the working directory to tests/testsuite.dir. AT_CHECK([$SCITECO -e "[[\$ @FG'..' ]]\$ :Q\$-1Q\$-^^r\"=(0/0)'"], 0, ignore, ignore) +AT_CHECK([$SCITECO -e "[[: @I/XXX/ ]]: .\"N(0/0)'"], 0, ignore, ignore) AT_CLEANUP AT_SETUP([Searches]) |