#260 restore UTF-8 mode when leaving hex mode (with patch)

v3.8
closed-fixed
5
2014-11-12
2008-11-15
No

This patch makes joe restore UTF-8 mode after entering hex mode in a
UTF-8 buffer, and then leaving hex mode. A more general fix would restore the
proper old o->charmap.

Index: rc.c

--- rc.c (revision 25)
+++ rc.c (working copy)
@@ -243,6 +243,7 @@
/* Hex not allowed with UTF-8 */
if (o->hex && o->charmap->type) {
o->charmap = find_charmap(USTR "c");
+ o->hex = 2;
}
}

@@ -806,6 +807,7 @@
return simple_cmplt(bw,syntaxes);
}

+/* Return true iff there is a hex window with this bw */
int check_for_hex(BW *bw)
{
W *w;
@@ -835,8 +837,10 @@

if (map) {
bw->o.charmap = map;
- joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("%s encoding assumed for this file")), map->name);
- msgnw(bw->parent, msgbuf);
+ if (!xx) {
+ joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("%s encoding assumed for this file")), map->name);
+ msgnw(bw->parent, msgbuf);
+ }
} else
msgnw(bw->parent, joe_gettext(_("Character set not found")));

@@ -928,7 +932,7 @@

static int olddoopt(BW *bw, int y, int flg, int *notify)
{
- int *xx;
+ int *xx, *optp, oldval;
unsigned char buf[OPT_BUF_SIZE];

if (y >= 0) {
@@ -943,20 +947,22 @@
msgnw(bw->parent, *(int *)glopts[y].set ? joe_gettext(glopts[y].yes) : joe_gettext(glopts[y].no));
break;
case 4:
- if (!flg)
- *(int *) ((unsigned char *) &bw->o + glopts[y].ofst) = !*(int *) ((unsigned char *) &bw->o + glopts[y].ofst);
- else if (flg == 1)
- *(int *) ((unsigned char *) &bw->o + glopts[y].ofst) = 1;
- else
- *(int *) ((unsigned char *) &bw->o + glopts[y].ofst) = 0;
- msgnw(bw->parent, *(int *) ((unsigned char *) &bw->o + glopts[y].ofst) ? joe_gettext(glopts[y].yes) : joe_gettext(glopts[y].no));
+ optp = (int *) ((unsigned char *) &bw->o + glopts[y].ofst);
+ oldval = *optp;
+ *optp = !flg ? !*optp : (flg == 1);
+ msgnw(bw->parent, joe_gettext(*optp ? glopts[y].yes : glopts[y].no));
if (glopts[y].ofst == (unsigned char *) &fdefault.readonly - (unsigned char *) &fdefault)
bw->b->rdonly = bw->o.readonly;
/* Kill UTF-8 mode if we switch to hex display */
- if (glopts[y].ofst == (unsigned char *) &fdefault.hex - (unsigned char *) &fdefault &&
- bw->o.hex &&
- bw->b->o.charmap->type) {
- doencoding(bw, vsncpy(NULL, 0, sc("C")), NULL, NULL);
+ if (glopts[y].ofst == (unsigned char *) &fdefault.hex - (unsigned char *) &fdefault) {
+ if (bw->o.hex && bw->b->o.charmap->type) {
+ /* Quietly cancel UTF-8 mode if we switch to hex display */
+ bw ->o.hex = 2;
+ doencoding(bw, vsncpy(NULL, 0, sc("C")), 1+(int*)0, NULL);
+ } else if (oldval == 2 && !bw->o.hex && !bw->b->o.charmap->type) {
+ /* Quietly restore UTF-8 mode after leaving hex display */
+ doencoding(bw, vsncpy(NULL, 0, sc("UTF-8")), 1+(int*)0, NULL);
+ }
}
break;
case 6:

Discussion

  • John J. Jordan

    John J. Jordan - 2014-11-12

    Applied something like this patch in [e4d71f]. I did not include the bit to silence the encoding change notice -- this fix will be a bit different in the coroutine branch, where it will be easier to achieve that. It's broken already anyway when changing into hex mode.

     

    Related

    Commit: [e4d71f]

  • John J. Jordan

    John J. Jordan - 2014-11-12
    • status: open --> closed-fixed
    • assigned_to: John J. Jordan
    • Group: --> v3.8
     

Log in to post a comment.