]> git.neil.brown.name Git - edlib.git/commitdiff
emacs: all inserts and deletes should deactivate the transient region.
authorNeilBrown <neil@brown.name>
Tue, 21 Sep 2021 04:23:43 +0000 (14:23 +1000)
committerNeilBrown <neil@brown.name>
Tue, 21 Sep 2021 04:23:43 +0000 (14:23 +1000)
Some edits, such as "K:Enter" and "K:Backspace" weren't deactivating a
transient region.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
mode-emacs.c

index 3a742f1613c7bbc5bcab9f70e124c80080d0ba4f..713cd1381bd5757cb5f809014b5f25435757acbc 100644 (file)
@@ -49,7 +49,7 @@ Bugs to be fixed
 - [X] base64 saved-file of content ending 
       IHdpZHRoPScxJyBoZWlnaHQ9JzEnID48L3NwYW4+IDwvYm9keT48L2h0bWw+DQo= 
       adds 0x40 0xff to the end.
-- [ ] this highlighted added by xterm-keyboard-paste is disabled when chars
+- [X] this highlighted added by xterm-keyboard-paste is disabled when chars
       are typed, but not on 'enter'
 - [ ] URL highlighting of email is sometimes bizzare - possibly when
       orig content is b64
index 9f477c0257bd80cf467c551e041c86f394ba8c20..198cca72a81c646028f87b3a4f34347561c156cb 100644 (file)
@@ -235,8 +235,11 @@ REDEF_CMD(emacs_delete)
 
        mk = call_ret(mark2, "doc:point", ci->focus);
        /* If selection is replacable, clear it and use mk */
-       if (!clear_selection(ci->focus, NULL, mk, 3))
+       if (!clear_selection(ci->focus, NULL, mk, 3)) {
+               /* else clear any transient selection */
+               clear_selection(ci->focus, NULL, mk, 2);
                mk = NULL;
+       }
 
        m = mark_dup(ci->mark);
 
@@ -683,10 +686,17 @@ DEF_CMD(emacs_quote_insert)
        int ret;
        char buf[2] = ".";
        const char *str;
+       bool first = N2(ci) != N2_undo_insert;
 
        if (!ci->mark)
                return Enoarg;
 
+       if (clear_selection(ci->focus, NULL, ci->mark, 3)) {
+               call("Replace", ci->focus, 1, ci->mark, NULL, !first);
+               first = False;
+       } else
+               clear_selection(ci->focus, NULL, ci->mark, 2);
+
        str = ksuffix(ci, "K:CQ-");
        if (!str[0]) {
                str = ksuffix(ci, "K:CQ:C-");
@@ -696,8 +706,7 @@ DEF_CMD(emacs_quote_insert)
                } else
                        str = "??";
        }
-       ret = call("Replace", ci->focus, 1, ci->mark, str,
-                  N2(ci) == N2_undo_insert);
+       ret = call("Replace", ci->focus, 1, ci->mark, str, !first);
        call("Mode:set-num2", ci->focus, N2_undo_insert);
 
        return ret;
@@ -720,6 +729,7 @@ DEF_CMD(emacs_insert_other)
        int i;
        struct mark *m = NULL;
        struct mark *mk = call_ret(mark2, "doc:point", ci->focus);
+       bool first = N2(ci) != N2_undo_insert;
        char *ins;
 
        if (!ci->mark)
@@ -732,8 +742,11 @@ DEF_CMD(emacs_insert_other)
        if (ins == NULL)
                return Efallthrough;
 
-       if (clear_selection(ci->focus, NULL, mk, 3))
-               call("Replace", ci->focus, 1, mk);
+       if (clear_selection(ci->focus, NULL, mk, 3)) {
+               call("Replace", ci->focus, 1, mk, NULL, !first);
+               first = False;
+       } else
+               clear_selection(ci->focus, NULL, mk, 2);
 
        if (!*ins) {
                ins++;
@@ -742,8 +755,7 @@ DEF_CMD(emacs_insert_other)
                mark_step(m, 0);
        }
 
-       ret = call("Replace", ci->focus, 1, m, ins,
-                  N2(ci) == N2_undo_insert, ci->mark);
+       ret = call("Replace", ci->focus, 1, m, ins, !first, ci->mark);
        if (m) {
                mark_to_mark(ci->mark, m);
                mark_free(m);
@@ -759,11 +771,18 @@ DEF_CMD(emacs_interactive_insert)
         * it calls this, and we set up for proper undo
         */
        int ret;
+       bool first = N2(ci) != N2_undo_insert;
 
        if (!ci->str)
                return Enoarg;
+
+       if (clear_selection(ci->focus, NULL, ci->mark, 3)) {
+               call("Replace", ci->focus, 1, ci->mark, NULL, !first);
+               first = False;
+       } else
+               clear_selection(ci->focus, NULL, ci->mark, 2);
        ret = call("Replace", ci->focus, 1, ci->mark, ci->str,
-                  N2(ci) == N2_undo_insert);
+                  !first);
        call("Mode:set-num2", ci->focus,
             strchr(ci->str, '\n') ? 0 : N2_undo_insert);
        return ret;