reddit / emacs

tab key not recognized in emacs on macos

un_dude · 2022-12-05 22:44
Hello, I have just moved to a macbook and I am already enjoying emacs even more than under WSL. But unfortunately, now the tab key sometimes stops working for emacs GUI. It is not even registered as a keypress: 'C-h c <tab>' just ignores the <tab> keypress. C-i is recognized as a tab press, and in the terminal things seem to work normally. I am on Monterey 12.5, emacsplus@28, using a doom config. I tried to find help online but so far was unsuccessful. I have disabled mission control key bindings, including the use of tab to shift focus, but it still seems to happen. Did somebody solve a similar problem? Does it have to do with the shell from which the emacs GUI is started? It might also be something basic about macOs, with which I am completely inexperienced. Thank you for any ideas how to find out what is happening. &#x200B; &#x200B; https://preview.redd.it/4noo0sr2q54a1.png?width=1346&format=png&auto=webp&s=e3ab47d203bc1fc86a87e99833feb9cb62c4d694
scherbi · 2022-12-05 23:05
Have you tested it with emacs -Q ?
un_dude · 2022-12-05 23:27
To my surprise, emacs -Q seems to work normally. Does that mean that the problem should be somewhere either in my doom config or doom? I was surprised <tab> keypress wouldn't even be registered. Any ideas how to narrow it down further?
scherbi · 2022-12-05 23:30
Yes. Something in your config. Do a binary search: comment half of your config out and test. If you still have the issue, it's in the half you didn't comment out, of course. Then comment half of that out, and test again. Repeat until the offending statement is revealed. There is probably better ways, but this will work.
un_dude · 2022-12-06 00:12
the bisecting went faster than I thought, after focusing on the suspect lines.But I was surprised to find the issue with (toggle-frame-fullscreen). Once called, all <tab> presses are ignored (even after leaving fullscreen). Would have been nice to understand how that is happening, and whether this is a bug. Thank you for your help!
scherbi · 2022-12-06 00:46
You're very welcome. glad to help.
suliveevil · 2022-12-06 03:13
Emacs 30 doesn't have this issue: \`(keymap-global-set "C-s-f" #'toggle-frame-fullscreen) ;; macOS\`
graduale · 2022-12-06 12:14
I too am using emacs-plus 28 on macOS but don’t have that issue, so I suspect it’s something else. I don’t use doom, but call `toggle-frame-fullscreen` multiple times a day without an issue.
un_dude · 2022-12-06 12:17
Thank you that is good to know. I can reproduce the issue with emacs-Q and `(toggle-frame-fullscreen)`, so it might be somewhere outside of the emacs config.
graduale · 2022-12-06 13:55
It could be a macOS level thing. ~~Maybe tab is bound to a command to switch spaces or some such?~~ Sorry, I missed the bit in our post about having disabled mission control. What happens if you do \`C-h k\` followed by <tab> after calling \`toggle-frame-fullscreen\`? Also, have you checked other shortcuts in the Keyboard preference pane? And have you tried starting emacs not from the shell, but directly by opening Emacs.app? (Your package manager should be able to tell you where that's been saved, but emacs-plus comes with, but if your Mac is new enough it's probably in `/opt/homebrew/opt/emacs-plus@28` )
owmagow · 2022-12-06 15:08
It works on my mac os ventura / Emacs 28.
un_dude · 2022-12-06 21:04
>/opt/homebrew/opt/emacs-plus@28 thanks for that suggestion! In a session where fullscreen has been toggled at least once, any <tab> keypress is not recognized as anything - the \`C-h k\` just keeps waiting for input and responds to whatever is pressed next. \`C-i\` is still recognized as <tab>. I have tried any shortcut setting I could find and turned off rectangle and altTab. spotlight didn't find Emacs.app, but the path was the same for me, so thank you. I ran \`open /.../Emacs.app\` but that did not change anything. Is that is still "starting from the shell", or is there a different way? (again, absolutely new to MacOS) It would be nice to find out what intercepts the <tab> press; other frames seem to work fine. I also tried opening two frames. <tab> only stops working in the emacs frame that has been toggled full-screen, not all emacs frames of the same session.
graduale · 2022-12-06 21:09
You may want to give this little utility a try and see if it helps. https://www.irradiatedsoftware.com/labs/ (Sorry, there's a bunch there: "Shortcut Detective" is what I had in mind.) Short of that, what I'd do is create a new user account in my computer, install emacs-plus again, see if you can reproduce the behavior then. If not, I'd try to quit all other running apps from within your main user account and see if you get the same behavior. If you do, it's probably something at the OS level. I don't know how one goes about figuring out what intercepts a keystroke at the OS level...
un_dude · 2022-12-06 22:25
thank you, the shortcut detective didn't help unfortunately. the user account is a good call, but before that I'll try emacs 29
un_dude · 2022-12-06 22:30
Update:some fullscreen issues are mentioned in [https://www.emacswiki.org/emacs/EmacsForMacOS](https://www.emacswiki.org/emacs/EmacsForMacOS) Running the snippet: (setq ns-use-native-fullscreen nil) (setq ns-use-fullscreen-animation nil) (run-at-time "5sec" nil (lambda () (let ((fullscreen (frame-parameter (selected-frame) 'fullscreen))) ;; If emacs has in fullscreen status, maximized ;; window first, drag from Mac's single space. (when (memq fullscreen '(fullscreen fullboth)) (set-frame-parameter (selected-frame) 'fullscreen 'maximized)) ;; Manipulating a frame without waiting for the ;; fullscreen animation to complete can cause a ;; crash, or other unexpected behavior, on macOS ;; (bug #28496). (sleep-for 0.5) ;; Call `toggle-frame-fullscreen' to fullscreen emacs. (toggle-frame-fullscreen)))) Seemed to work - in case somebody finds this useful later on. There might be some interference with macos window animations. But for now, I have switched to emacs 29, currently without nativecomp, where the issue seemed to disappear. Thank you for helping!