benjaminor / kkp

Emacs support for the Kitty Keyboard Protocol
GNU General Public License v3.0
39 stars 6 forks source link

keys start with `C+q` does not work #11

Closed yangyingchao closed 9 months ago

yangyingchao commented 10 months ago

Thanks for providing this package; it's really helpful: now I can remove tricky CSI configurations in kitty & foot.

However, I've encountered an issue with the keys that start with C-q. For example, in both kitty & foot terminal:

Can you please provide some suggestions on this?

benjaminor commented 9 months ago

Hi, thanks for reporting this.

C-q calls quoted-insert in Emacs, which is used to insert an input character. This uses internally read-char to read the character input event, without any translation by the input translation maps which kkp uses. This is why you get the 'pure' event sent by the terminal.

An alternative would be to use a custom quoted-insert function which relies on read-key and not on read-char. This way, we can still translate the input event:

(defun my-quoted-insert-with-read-key (arg)
  "Insert the next character using read-key, not read-char."
  (interactive "*p")
  (let ((char (read-key)))
    ;; Ensure char is treated as a character code for insertion
    (unless (characterp char)
      (user-error "%s is not a valid character"
                  (key-description (vector char))))
    (when (numberp char)
      (while (> arg 0)
        (insert-and-inherit char)
        (setq arg (1- arg))))))

Then, bind C-q to my-quoted-insert-with-read-key and you should be good to go.

yangyingchao commented 9 months ago

thanks :)