0

I have this mnemonic keybinding which I placed in my config

;; Switching window backwards
(global-set-key (kbd "C-x O") (lambda ()
                                (interactive)
                                (other-window -1)))

Which works fine, but works in the opposite direction when my CAPS are on. I have tried

;; Switching window backwards
(global-set-key (kbd "C-x S-o") (lambda ()
                                (interactive)
                                (other-window -1)))

but this does not work at all, it just gives me the regular forward buffer

7
  • 2
    stackoverflow.com/a/38193690/324105 explains why S-o does not work. What doe Emacs receive when you type o with caps lock on? What does C-h k report? – phils Jul 16 '20 at 6:59
  • 3
    (If my caps lock key was used for caps lock, I'd test it.) – phils Jul 16 '20 at 7:07
  • Note that with shift held down throughout, you're actually sending C-S-x O which, by default, and if there's no direct binding, gets translated to C-x O. That mechanism works fine so far as I can see, but I point it out in case it's relevant. – phils Jul 16 '20 at 7:13
  • What does C-h k C-x O tell you when caps-lock is on (turn it on after you hit C-h k, so the k is lowercase)? (In my case it says "C-x o (translated from C-x O) runs the command other-window.") That should tell you why Emacs does what it does. It sounds like your keyboard/platform is maybe sending something unusual to Emacs. – Drew Jul 16 '20 at 15:38
  • Thanks for the replies, I tried out @Drew's suggestion, and I got "C-x O runs the command...", I did not get the '(translated from ...)' part, same for C-x S-o. Now I tried C-x S-o with caps on, and I got "C-x o runs the command...". This comes as no surprise though, as it is what I observed, the problem is that emacs does not seem to be able to differentiate whether S or <CAPS> is make a captial O. Could this be an OS specific issue? I use Ubuntu 20.04 – Tian Jul 17 '20 at 1:59
1

The comments clarified that the question was about the behaviour of holding down the Shift modifier key while Caps Lock was on.

It's common for the shift key to invert the state of caps lock, rather than to unconditionally enable caps. Hence:

  1. t => t
  2. SHIFT + t => T
  3. CAPS + t => T
  4. CAPS + SHIFT + t => t

In that latter case, Emacs sees only a lower-case t. It is not aware that the shift key and the caps lock key were both involved in producing it, so you cannot make case (4) behave differently to case (1).

To prevent this, I think you'll need to look for some kind of "do not allow shift to invert an active caps lock" option in your OS or window manager.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.