aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2025-07-19 22:34:57 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2025-07-19 22:34:57 +0300
commitac180a94ff749f5df7705279d3d08258417b9b34 (patch)
tree43265de4d2630c9bf2d4920b7d6ad0e4c34c5d0e /src
parentafdb2acdecf4b563ed037f983b820ce82f6735ba (diff)
downloadsciteco-ac180a94ff749f5df7705279d3d08258417b9b34.tar.gz
special Q-registers `$` (working directory) and the clipboard registers now support the append operation (:Xq, :^Uq...)
Works via a default implementation in the "external" Q-register "class" by first querying the string, appending and re-setting it.
Diffstat (limited to 'src')
-rw-r--r--src/qreg.c40
1 files changed, 16 insertions, 24 deletions
diff --git a/src/qreg.c b/src/qreg.c
index c8c4614..332b5f6 100644
--- a/src/qreg.c
+++ b/src/qreg.c
@@ -487,6 +487,19 @@ teco_qreg_external_edit(teco_qreg_t *qreg, GError **error)
}
static gboolean
+teco_qreg_external_append_string(teco_qreg_t *qreg, const gchar *str, gsize len, GError **error)
+{
+ g_auto(teco_string_t) buf = {NULL, 0};
+ guint codepage;
+
+ if (!qreg->vtable->undo_set_string(qreg, error) ||
+ !qreg->vtable->get_string(qreg, &buf.data, &buf.len, &codepage, error))
+ return FALSE;
+ teco_string_append(&buf, str, len);
+ return qreg->vtable->set_string(qreg, buf.data, buf.len, codepage, error);
+}
+
+static gboolean
teco_qreg_external_exchange_string(teco_qreg_t *qreg, teco_doc_t *src, GError **error)
{
g_auto(teco_string_t) other_str, own_str = {NULL, 0};
@@ -604,6 +617,7 @@ teco_qreg_external_save(teco_qreg_t *qreg, const gchar *filename, GError **error
.exchange_string = teco_qreg_external_exchange_string, \
.undo_exchange_string = teco_qreg_external_undo_exchange_string, \
.edit = teco_qreg_external_edit, \
+ .append_string = teco_qreg_external_append_string, \
.get_character = teco_qreg_external_get_character, \
.get_length = teco_qreg_external_get_length, \
.load = teco_qreg_external_load, \
@@ -636,6 +650,8 @@ teco_qreg_bufferinfo_get_integer(teco_qreg_t *qreg, teco_int_t *ret, GError **er
/*
* FIXME: Something could be implemented here. There are 2 possibilities:
* Either it renames the current buffer, or opens a file (alternative to EB).
+ * Should we implement it, we can probably remove the append_string
+ * implementation below.
*/
static gboolean
teco_qreg_bufferinfo_set_string(teco_qreg_t *qreg, const gchar *str, gsize len,
@@ -741,17 +757,6 @@ teco_qreg_workingdir_undo_set_string(teco_qreg_t *qreg, GError **error)
return TRUE;
}
-/*
- * FIXME: Redundant with teco_qreg_bufferinfo_append_string()...
- * Best solution would be to simply implement them.
- */
-static gboolean
-teco_qreg_workingdir_append_string(teco_qreg_t *qreg, const gchar *str, gsize len, GError **error)
-{
- teco_error_qregopunsupported_set(error, qreg->head.name.data, qreg->head.name.len, FALSE);
- return FALSE;
-}
-
static gboolean
teco_qreg_workingdir_get_string(teco_qreg_t *qreg, gchar **str, gsize *len,
guint *codepage, GError **error)
@@ -785,7 +790,6 @@ teco_qreg_workingdir_new(void)
static teco_qreg_vtable_t vtable = TECO_INIT_QREG_EXTERNAL(
.set_string = teco_qreg_workingdir_set_string,
.undo_set_string = teco_qreg_workingdir_undo_set_string,
- .append_string = teco_qreg_workingdir_append_string,
.get_string = teco_qreg_workingdir_get_string
);
@@ -851,17 +855,6 @@ teco_qreg_clipboard_set_string(teco_qreg_t *qreg, const gchar *str, gsize len,
return TRUE;
}
-/*
- * FIXME: Redundant with teco_qreg_bufferinfo_append_string()...
- * Best solution would be to simply implement them.
- */
-static gboolean
-teco_qreg_clipboard_append_string(teco_qreg_t *qreg, const gchar *str, gsize len, GError **error)
-{
- teco_error_qregopunsupported_set(error, qreg->head.name.data, qreg->head.name.len, FALSE);
- return FALSE;
-}
-
static gboolean
teco_qreg_clipboard_undo_set_string(teco_qreg_t *qreg, GError **error)
{
@@ -953,7 +946,6 @@ teco_qreg_clipboard_new(const gchar *name)
static teco_qreg_vtable_t vtable = TECO_INIT_QREG_EXTERNAL(
.set_string = teco_qreg_clipboard_set_string,
.undo_set_string = teco_qreg_clipboard_undo_set_string,
- .append_string = teco_qreg_clipboard_append_string,
.get_string = teco_qreg_clipboard_get_string,
.load = teco_qreg_clipboard_load
);