Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shifted key translation #153

Open
bernardjoseph opened this issue Feb 20, 2023 · 5 comments
Open

Shifted key translation #153

bernardjoseph opened this issue Feb 20, 2023 · 5 comments
Labels

Comments

@bernardjoseph
Copy link

Some key bindings, like C-N for next-line, have shift-select-mode activated when called with an uppercase letter, which activates the mark. This does not work in God mode, because the key sequence is tranlated to C-S-N, which has no binding. For example, when I prees C-N with uppercase N, next-line with a highlighted region (because I have transient-mark-mode set) is called. When I press uppercase N in God mode, I get an error "Unknown key binding for 'C-S-N'". For now, I have modified the :else branch in god-mode-lookup-command as follows, which seems to work for me:

(defun god-mode-lookup-command (key-string)
  "Execute extended keymaps in KEY-STRING, or call it if it is a command."
  (when key-string
    (let* ((key-vector (read-kbd-macro key-string t))
           (binding (key-binding key-vector)))
      (cond ((commandp binding)
             (setq last-command-event
                   (aref key-vector (- (length key-vector) 1)))
             binding)
            ((keymapp binding)
             (god-mode-lookup-key-sequence nil key-string))
            (:else
             (if (and (string-match "S-\\(.\\)\\'" key-string)
                      (string= (get-char-code-property
                                (aref (match-string 1 key-string) 0)
                                'general-category)
                               "Lu"))
                 (god-mode-lookup-command (replace-regexp-in-string
                                           "S-\\(.\\)\\'" "\\1" key-string))
               (error "God: Unknown key binding for `%s`" key-string)))))))

In my understanding, Emacs translates all bindings with uppercase letters without binding to their lowercase counterparts. I do not know if my solution is acceptable; it looks a bit rude to me, but it works.

@darth10 darth10 added the bug label Feb 20, 2023
@darth10
Copy link
Collaborator

darth10 commented Feb 20, 2023

Thanks for brining this up @bernardjoseph!

I think your solution is fine, but it could be in a better place.
The call to god-mode-lookup-command could be done in either:

  • The outer let* form, or
  • The god-key-string-after-consuming-key function (I think).

That would make it slightly cleaner.
If the tests are passing with your change in verbatim though, I'm happy to merge that in and refactor it later.

That being said, you shouldn't be using C-S-N (or C-S-n) in the spirit of modal editing 😄
Instead, you should call set-mark-command and next-line i.e. SPC n in God mode.
Note that SPC n doesn't use any modifier keys.

@darth10
Copy link
Collaborator

darth10 commented Feb 20, 2023

Actually, I'm curious about the behavior with your change and the Caps Lock key turned on.
Is the behavior correct in that case?

@bernardjoseph
Copy link
Author

I must confess I do not know what the correct behavior is. Without God mode, pressing Ctrl-anything with Caps Lock on seems to ignore Caps Lock. With God mode enabled, with Caps Lock on, all alphanumeric keys are shifted. For me the behavior is ok and I am more wondering about the behavior with God mode turned off. What do you think?

@bernardjoseph
Copy link
Author

Sorry, after playing a bit more I am now convinced that the Caps Lock behavior is not good.

@bernardjoseph
Copy link
Author

A checked the behavior in View mode, which has some capital letter bindings. With Caps Lock on, all capital letter bindings are in effect. That is a strange behavior for me, I was not aware of until now. Caps Lock is not really recognized by Emacs in those cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants