japanoise / emsys

ersatz-emacs text editor
MIT License
3 stars 2 forks source link

Suggestion: Rethink Handling of Unknown Commands #20

Open nicholascarroll opened 2 months ago

nicholascarroll commented 2 months ago

When encountering unknown commands, the current implementation returns specific values:

My code change was to comment out the "return CTRL('x');" in CX_UNKNOWN, and ESC_UNKNOWN and discard the rest of the escape sequence:

    ESC_UNKNOWN:;
        char seqR[32];
        seqR[0] = 0;
        char buf[8];
        for (int i = 0; seq[i]; i++) {
            if (seq[i] < ' ') {
                sprintf(buf, "C-%c ", seq[i]+'`');
            } else {
                sprintf(buf, "%c ", seq[i]);
            }
            strcat(seqR, buf);
        }
        editorSetStatusMessage("Unknown command M-%s", seqR);
        // Discard the rest of the escape sequence
        char discard[32];
        read(STDIN_FILENO, discard, sizeof(discard)); // Read and discard remaining characters
        //return 033;
japanoise commented 1 month ago

The main thing I'm worried about here is that it might sit there discarding everything if whatever condition it wants isn't met. I haven't had the chance to test this yet though so it may be fine.

nicholascarroll commented 1 month ago

I just accidentally discovered that if you press C-x C-k C-k, you will get a Segmentation fault (core dumped). I tested this on current version and also on version 7652c69 .

japanoise commented 1 month ago

I just accidentally discovered that if you press C-x C-k C-k, you will get a Segmentation fault (core dumped). I tested this on current version and also on version 7652c69 .

Looks like ^K isn't checking for an empty buffer. You don't need to C-x C-k - just C-k on an empty buffer.

nicholascarroll commented 1 month ago

ref #34