0

I have set TAB to flip between two windows using:-

(global-set-key (kbd "TAB") 'other-window)

This works sometimes, but not always. How should I define it?

Drew
  • 77,472
  • 10
  • 114
  • 243
balanga
  • 135
  • 6

2 Answers2

2

It could possibly be caused due to sometimes the key being understood as <tab> and other times as TAB.

Switch to fundamental-mode. Try,

  1. C-h k C-i: This should get you TAB.
  2. C-h k tabkey: This may get you TAB (translated from <tab>).

One way then is to,

(global-set-key (kbd "<tab>") #'other-window)
(global-set-key (kbd "TAB") #'other-window)

For the difference between TAB and <tab> read more here.

scribe
  • 1,035
  • 5
  • 16
1

(global-set-key (kbd "TAB") 'other-window)

As @scribe said, with bindings containing Tab, Backspace, Escape, etc. you may get the syntax wrong so you can read more about the use of angle brackets, and the differences in general.

This works sometimes, but not always. How should I define it?

It's hard to guess if you don't provide more details but one reason why other-window may behave "work sometimes" (i.e. changing window usually but sometimes, even if another window is present, not changing to it) is because of the no-other-window window parameter: windows such as temporary side windows (e.g. output of some command) work this way - cycling through windows will ignore them. Using ignore-window-parameters can alter this behavior.

Furthermore, bindings for functions like other-window (bindings with which you cycle through buffers/windows) may at some point "stop working" because you ended up in a buffer which overrides your keybinding.

By the way, you may consider leaving TAB alone (so you can use its default behavior), and instead using a prefix like:

(keymap-global-set "M-<tab>" 'other-window)

This uses the new key binding syntax (Emacs 29) as an example but should work exactly like global-set-key

Alex
  • 363
  • 2
  • 11