aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/qreg.c
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-09-09 16:54:26 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-09-09 18:22:21 +0200
commit4f231871a0208ec9bcc2679fce25d3b9795d1597 (patch)
treebdc9055166fe236f009c6640acf53b6706310c27 /src/qreg.c
parent41ab5cf0289dab60ac1ddc97cf9680ee2468ea6c (diff)
downloadsciteco-4f231871a0208ec9bcc2679fce25d3b9795d1597.tar.gz
added raw ANSI mode to facilitate 8-bit clean editing (refs #5)
* When enabled with bit 2 in the ED flags (0,4ED), all registers and buffers will get the raw ANSI encoding (as if 0EE had been called on them). You can still manually change the encoding, eg. by calling 65001EE afterwards. * Also the ANSI mode sets up character representations for all bytes >= 0x80. This is currently done only depending on the ED flag, not when setting 0EE. * Since setting 16,4ED for 8-bit clean editing in a macro can be tricky - the default unnamed buffer will still be at UTF-8 and at least a bunch of environment registers as well - we added the command line option `--8bit` (short `-8`) which configures the ED flags very early on. As another advantage you can mung the profile in 8-bit mode as well when using SciTECO as a sort of interactive hex editor. * Disable UTF-8 checks in 8-bit clean mode (sample.teco_ini).
Diffstat (limited to 'src/qreg.c')
-rw-r--r--src/qreg.c51
1 files changed, 22 insertions, 29 deletions
diff --git a/src/qreg.c b/src/qreg.c
index 08bc8fc..fb559af 100644
--- a/src/qreg.c
+++ b/src/qreg.c
@@ -127,11 +127,11 @@ teco_qreg_set_eol_mode(teco_qreg_t *qreg, gint mode)
if (teco_qreg_current)
teco_doc_update(&teco_qreg_current->string, teco_qreg_view);
- teco_doc_edit(&qreg->string);
+ teco_doc_edit(&qreg->string, teco_default_codepage());
teco_view_ssm(teco_qreg_view, SCI_SETEOLMODE, mode, 0);
if (teco_qreg_current)
- teco_doc_edit(&teco_qreg_current->string);
+ teco_doc_edit(&teco_qreg_current->string, 0);
}
/** @memberof teco_qreg_t */
@@ -144,7 +144,7 @@ teco_qreg_load(teco_qreg_t *qreg, const gchar *filename, GError **error)
if (teco_qreg_current)
teco_doc_update(&teco_qreg_current->string, teco_qreg_view);
- teco_doc_edit(&qreg->string);
+ teco_doc_edit(&qreg->string, teco_default_codepage());
teco_doc_reset(&qreg->string);
/*
@@ -162,7 +162,7 @@ teco_qreg_load(teco_qreg_t *qreg, const gchar *filename, GError **error)
return FALSE;
if (teco_qreg_current)
- teco_doc_edit(&teco_qreg_current->string);
+ teco_doc_edit(&teco_qreg_current->string, 0);
return TRUE;
}
@@ -174,18 +174,14 @@ teco_qreg_save(teco_qreg_t *qreg, const gchar *filename, GError **error)
if (teco_qreg_current)
teco_doc_update(&teco_qreg_current->string, teco_qreg_view);
- teco_doc_edit(&qreg->string);
+ teco_doc_edit(&qreg->string, teco_default_codepage());
- if (!teco_view_save(teco_qreg_view, filename, error)) {
- if (teco_qreg_current)
- teco_doc_edit(&teco_qreg_current->string);
- return FALSE;
- }
+ gboolean ret = teco_view_save(teco_qreg_view, filename, error);
if (teco_qreg_current)
- teco_doc_edit(&teco_qreg_current->string);
+ teco_doc_edit(&teco_qreg_current->string, 0);
- return TRUE;
+ return ret;
}
static gboolean
@@ -239,14 +235,14 @@ teco_qreg_plain_append_string(teco_qreg_t *qreg, const gchar *str, gsize len, GE
if (teco_qreg_current)
teco_doc_update(&teco_qreg_current->string, teco_qreg_view);
- teco_doc_edit(&qreg->string);
+ teco_doc_edit(&qreg->string, teco_default_codepage());
teco_view_ssm(teco_qreg_view, SCI_BEGINUNDOACTION, 0, 0);
teco_view_ssm(teco_qreg_view, SCI_APPENDTEXT, len, (sptr_t)str);
teco_view_ssm(teco_qreg_view, SCI_ENDUNDOACTION, 0, 0);
if (teco_qreg_current)
- teco_doc_edit(&teco_qreg_current->string);
+ teco_doc_edit(&teco_qreg_current->string, 0);
return TRUE;
}
@@ -262,27 +258,24 @@ static gboolean
teco_qreg_plain_get_character(teco_qreg_t *qreg, teco_int_t position,
teco_int_t *chr, GError **error)
{
- gboolean ret = TRUE;
-
if (teco_qreg_current)
teco_doc_update(&teco_qreg_current->string, teco_qreg_view);
- teco_doc_edit(&qreg->string);
+ teco_doc_edit(&qreg->string, teco_default_codepage());
sptr_t len = teco_view_ssm(teco_qreg_view, SCI_GETLENGTH, 0, 0);
gssize off = teco_view_glyphs2bytes(teco_qreg_view, position);
- if (off < 0 || off == len) {
+ gboolean ret = off >= 0 && off != len;
+ if (!ret)
g_set_error(error, TECO_ERROR, TECO_ERROR_RANGE,
"Position %" TECO_INT_FORMAT " out of range", position);
- ret = FALSE;
/* make sure we still restore the current Q-Register */
- } else {
+ else
*chr = teco_view_get_character(teco_qreg_view, off, len);
- }
if (teco_qreg_current)
- teco_doc_edit(&teco_qreg_current->string);
+ teco_doc_edit(&teco_qreg_current->string, 0);
return ret;
}
@@ -293,13 +286,13 @@ teco_qreg_plain_get_length(teco_qreg_t *qreg, GError **error)
if (teco_qreg_current)
teco_doc_update(&teco_qreg_current->string, teco_qreg_view);
- teco_doc_edit(&qreg->string);
+ teco_doc_edit(&qreg->string, teco_default_codepage());
sptr_t len = teco_view_ssm(teco_qreg_view, SCI_GETLENGTH, 0, 0);
teco_int_t ret = teco_view_bytes2glyphs(teco_qreg_view, len);
if (teco_qreg_current)
- teco_doc_edit(&teco_qreg_current->string);
+ teco_doc_edit(&teco_qreg_current->string, 0);
return ret;
}
@@ -326,7 +319,7 @@ teco_qreg_plain_edit(teco_qreg_t *qreg, GError **error)
if (teco_qreg_current)
teco_doc_update(&teco_qreg_current->string, teco_qreg_view);
- teco_doc_edit(&qreg->string);
+ teco_doc_edit(&qreg->string, teco_default_codepage());
teco_interface_show_view(teco_qreg_view);
teco_interface_info_update(qreg);
@@ -549,7 +542,7 @@ teco_qreg_bufferinfo_get_string(teco_qreg_t *qreg, gchar **str, gsize *len,
*/
*len = teco_ring_current->filename ? strlen(teco_ring_current->filename) : 0;
if (codepage)
- *codepage = SC_CP_UTF8;
+ *codepage = teco_default_codepage();
return TRUE;
}
@@ -647,7 +640,7 @@ teco_qreg_workingdir_get_string(teco_qreg_t *qreg, gchar **str, gsize *len,
else
g_free(dir);
if (codepage)
- *codepage = SC_CP_UTF8;
+ *codepage = teco_default_codepage();
return TRUE;
}
@@ -798,7 +791,7 @@ teco_qreg_clipboard_get_string(teco_qreg_t *qreg, gchar **str, gsize *len,
teco_string_clear(&str_converted);
*len = str_converted.len;
if (codepage)
- *codepage = SC_CP_UTF8;
+ *codepage = teco_default_codepage();
return TRUE;
}
@@ -910,7 +903,7 @@ teco_qreg_table_set_environ(teco_qreg_table_t *table, GError **error)
}
if (!qreg->vtable->set_string(qreg, value, strlen(value),
- SC_CP_UTF8, error))
+ teco_default_codepage(), error))
return FALSE;
}