]> git.neil.brown.name Git - edlib.git/commitdiff
input: Report unrecognised key sequence
authorNeilBrown <neil@brown.name>
Fri, 29 Sep 2023 06:16:14 +0000 (16:16 +1000)
committerNeilBrown <neil@brown.name>
Fri, 29 Sep 2023 23:46:12 +0000 (09:46 +1000)
If keystroke is not recognised, report the fact.
This helps e.g. if keyboard in is some other-language mode.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
lib-input.c
lib-menubar.c
mode-emacs.c
tests.d/01-hex

index d6cd3080c5ef65e7c4848694d3d2bd81116a034d..8bd044682e9c1cdcff0c675917eabaab388e8dd8 100644 (file)
@@ -9,7 +9,7 @@ the file.
 
 ### Triage
 
-- [ ] unknown keysequence should be reported so e.g. if keyboard
+- [X] unknown keysequence should be reported so e.g. if keyboard
       is is Greek mode, then I will be told that Cx-b doesn't work
 - [ ] menubar doesn't redraw background when resized wider.
 - [X] open second x11 window, use selections.  Close it.  command
index f862370ca288176831b8eb3b62b6d49116c70a3a..017ec89edcbf276a7dd46bac673e4a77be5fa7ca 100644 (file)
@@ -225,8 +225,13 @@ DEF_CMD(keystroke)
        }
        time_ends(ci->home);
        if (ret <= Efail)
-               call("Message:default", ci->focus, 0, NULL,
-                    "** Command Failed **");
+               call("Message:default", p, 0, NULL,
+                    strconcat(ci->home, "** Command ", key, " Failed **"));
+       else if (ret == Efallthrough) {
+               key = strconcat(ci->home, "K", mode, ci->str);
+               call("Message:modal", p, 0, NULL,
+                    strconcat(ci->home, "** Command ", key, " not known **"));
+       }
        return Efallthrough;
 }
 
@@ -250,6 +255,8 @@ DEF_CMD(keystroke_sequence)
                        return Efail;
                c = e+1;
        }
+       if (!*c)
+               return 1;
        dash = "";
        if (*c != ':' || c[1] == '\0')
                dash = "-";
@@ -452,6 +459,14 @@ DEF_CMD(mouse_grab)
        return 1;
 }
 
+DEF_CMD(input_cancel)
+{
+       /* Other handlers fall-through.  We catch so that
+        * it doesn't appear to be ignored
+        */
+       return 1;
+}
+
 DEF_CMD(refocus)
 {
        struct input_mode *im = ci->home->data;
@@ -509,6 +524,9 @@ static void register_map(void)
        key_add(im_map, "Notify:Close", &close_focus);
        key_add(im_map, "input:log", &log_input);
        key_add(im_map, "Close", &input_close);
+
+       key_add(im_map, "Cancel", &input_cancel);
+       key_add(im_map, "Abort", &input_cancel);
 }
 
 DEF_LOOKUP_CMD(input_handle, im_map);
index b4a265505adccbc698908a9ab289f1c07b74322c..5ad0d456efe7565e0e07fb3c4b872fae1c872e2e 100644 (file)
@@ -287,7 +287,8 @@ DEF_CMD(menubar_done)
 
        if (mbi->child)
                pane_take_focus(mbi->child);
-       call("Keystroke-sequence", home, 0, NULL, ci->str);
+       if (ci->str && ci->str[0])
+               call("Keystroke-sequence", home, 0, NULL, ci->str);
        return 1;
 }
 
index 07e2647b728daf8caad2961e67615128409190b4..cd287e566376f0bf4bd6b787149e4e46ac78b5a6 100644 (file)
@@ -215,7 +215,7 @@ REDEF_CMD(emacs_move)
 
        ret = call(mv->type, ci->focus, mv->direction * RPT_NUM(ci), ci->mark,
                   NULL, mv->extra);
-       if (ret <= 0)
+       if (ret < 0)
                return ret;
 
        if (strcmp(mv->type, "Move-View") == 0)
@@ -226,13 +226,13 @@ REDEF_CMD(emacs_move)
        /* Discard a transient selection */
        clear_selection(ci->focus, NULL, mk, 2);
 
-       return ret;
+       return 1;
 }
 
 REDEF_CMD(emacs_delete)
 {
        struct move_command *mv = container_of(ci->comm, struct move_command, cmd);
-       int ret = 0;
+       int ret;
        struct mark *m, *mk;
 
        if (!ci->mark)
@@ -250,7 +250,7 @@ REDEF_CMD(emacs_delete)
 
        ret = call(mv->type, ci->focus, mv->direction * RPT_NUM(ci), m);
 
-       if (ret <= 0) {
+       if (ret < 0) {
                mark_free(m);
                return ret;
        }
@@ -261,14 +261,14 @@ REDEF_CMD(emacs_delete)
        mark_free(m);
        call("Mode:set-num2", ci->focus, N2_undo_delete);
 
-       return ret;
+       return 1;
 }
 
 REDEF_CMD(emacs_kill)
 {
        /* Like delete, but copy to copy-buffer */
        struct move_command *mv = container_of(ci->comm, struct move_command, cmd);
-       int ret = 0;
+       int ret;
        struct mark *m;
        char *str;
 
@@ -284,7 +284,7 @@ REDEF_CMD(emacs_kill)
        else
                ret = call(mv->type, ci->focus, mv->direction * RPT_NUM(ci), m);
 
-       if (ret <= 0) {
+       if (ret < 0) {
                mark_free(m);
                return ret;
        }
@@ -299,13 +299,13 @@ REDEF_CMD(emacs_kill)
        mark_free(m);
        call("Mode:set-num2", ci->focus, N2_undo_delete);
 
-       return ret;
+       return 1;
 }
 
 REDEF_CMD(emacs_case)
 {
        struct move_command *mv = container_of(ci->comm, struct move_command, cmd);
-       int ret = 0;
+       int ret;
        struct mark *start = NULL;
        int cnt = mv->direction * RPT_NUM(ci);
        int dir;
@@ -388,7 +388,7 @@ REDEF_CMD(emacs_case)
                mark_to_mark(ci->mark, start);
                mark_free(start);
        }
-       return ret;
+       return 1;
 }
 
 REDEF_CMD(emacs_swap)
@@ -399,7 +399,6 @@ REDEF_CMD(emacs_swap)
         * previous objects.  Object is determined by mv->type.
         */
        struct move_command *mv = container_of(ci->comm, struct move_command, cmd);
-       int ret = 0;
        struct mark *start = NULL;
        int cnt = mv->direction * RPT_NUM(ci);
        int dir;
@@ -469,7 +468,7 @@ REDEF_CMD(emacs_swap)
                mark_to_mark(ci->mark, start);
                mark_free(start);
        }
-       return ret;
+       return 1;
 }
 
 DEF_CMD(emacs_move_view_other)
@@ -645,7 +644,8 @@ DEF_CMD(emacs_exit)
                        return Efail;
                }
                attr_set_str(&p->attrs, "done-key", "emacs:deactivate");
-               return call("docs:show-modified", p);
+               call("docs:show-modified", p);
+               return 1;
        } else
                call("event:deactivate", ci->focus);
        return 1;
@@ -678,7 +678,7 @@ DEF_CMD(emacs_insert)
        ret = call(dc, ci->focus, ci->num, ci->mark, NULL, !first);
        call("Mode:set-num2", ci->focus, N2_undo_insert);
 
-       return ret;
+       return ret < 0 ? ret : 1;
 }
 
 DEF_CMD(emacs_quote_insert)
@@ -709,7 +709,7 @@ DEF_CMD(emacs_quote_insert)
        ret = call("Replace", ci->focus, 1, ci->mark, str, !first);
        call("Mode:set-num2", ci->focus, N2_undo_insert);
 
-       return ret;
+       return ret < 0 ? ret : 1;
 }
 
 static struct {
@@ -762,7 +762,7 @@ DEF_CMD(emacs_insert_other)
        }
        /* A newline starts a new undo */
        call("Mode:set-num2", ci->focus, (*ins == '\n') ? 0 : N2_undo_insert);
-       return ret;
+       return ret < 0 ? ret : 1;
 }
 
 DEF_CMD(emacs_interactive_insert)
@@ -785,7 +785,7 @@ DEF_CMD(emacs_interactive_insert)
                   !first);
        call("Mode:set-num2", ci->focus,
             strchr(ci->str, '\n') ? 0 : N2_undo_insert);
-       return ret;
+       return ret < 0 ? ret : 1;
 }
 
 DEF_CMD(emacs_interactive_delete)
@@ -801,7 +801,7 @@ DEF_CMD(emacs_interactive_delete)
                   N2(ci) == N2_undo_insert, ci->mark2);
        call("Mode:set-num2", ci->focus,
             strchr(ci->str, '\n') ? 0 : N2_undo_delete);
-       return ret;
+       return ret < 0 ? ret : 1;
 }
 
 DEF_CMD(emacs_undo)
@@ -916,7 +916,7 @@ DEF_CMD(find_done)
                return 1;
        }
        ret = call("popup:close", ci->focus, 0, NULL, norm ?: str);
-       return ret;
+       return ret < 0 ? ret : 1;
 }
 
 struct find_helper {
index b3204d86f8311ef0cd7d68c54c7a041bbe621833..d92dc8a1b966f84ff7d06bfbb93ecf76ca104928 100644 (file)
@@ -66,7 +66,7 @@ Display 80,30 59916409B88D2F03AEF88C44A55EBF77 11,3
 Key ":C-C"
 Display 80,30 97948AE8E3CDD3ACAF8E85B77EF95795 11,3
 Key ":C-C"
-Display 80,30 59916409B88D2F03AEF88C44A55EBF77 11,3
+Display 80,30 0EBDF165D3D4F22FDD70842E59F8099A 11,3
 Key ":C-D"
 Display 80,30 F233AC0805C7B68515D774340BACB87F 11,3
 Key ":C-D"
@@ -83,4 +83,4 @@ Key ":C-X"
 Display 80,30 03B92C6B72859C64F0A8D6830B7789BC 14,3
 Key ":C-C"
 Display 80,30 59916409B88D2F03AEF88C44A55EBF77 14,3
-Close 604
+Close 605