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

Getting Emacs to tile #86

Closed
karrot42 opened this issue Jul 2, 2019 · 42 comments
Closed

Getting Emacs to tile #86

karrot42 opened this issue Jul 2, 2019 · 42 comments
Labels
help wanted Community help appreciated question Request for information or help, not an issue

Comments

@karrot42
Copy link

karrot42 commented Jul 2, 2019

From a straight install Emacs won't tile with the rest of the windows, so I figured out that if I run

'yabai -m rule --add app=Emacs manage=on' after starting emacs it will tile with the other windows but I have 2 problems

  1. How do I make this change permanent and consistent even after I restart yabai so I don't have to run the command every time
  2. Although the Emacs window tiles, it when I navigate around the open windows (alt - h, alt - l) the Emacs window won't get selected, I must use the mouse to highlight it.
@dominiklohmann
Copy link
Collaborator

1. How do I make this change permanent and consistent even after I restart yabai so I don't have to run the command every time

Just put the rule in your yabairc—it's just an executable shell script after all.

2. Although the Emacs window tiles, it when I navigate around the open windows (alt - h, alt - l) the Emacs window won't get selected, I must use the mouse to highlight it.

Assuming you installed via brew, do you have anything possibly relevant in your log files when doing this? stderr gets redirected to /usr/local/var/log/yabai/yabai.err.log (and similarly replace err with out for stdout). You can monitor this file using tail -f /usr/local/var/log/yabai/yabai.err.log.

An alternative would be to run yabai --verbose instead of the brew service to get a more detailed output, which should print why your windows cannot be selected.

Emacs has always been an issue, sadly.

@goranmoomin
Copy link

Emacs has always been an issue, sadly.

Try using emacs-mac from the tap emacsmacport.

It has much more better GUI support than the original, and a few additional features you might appreciate.

All this is due to GNU Emacs's main role being an AXTextField instead of AXWindow mentioned https://github.com/koekeishiya/chunkwm/issues/105#issuecomment-312619814. :-(

Sent with GitHawk

@koekeishiya
Copy link
Owner

Does Emacs not provide a good CLI alternative to its GUI version?

@koekeishiya koekeishiya added help wanted Community help appreciated question Request for information or help, not an issue labels Jul 2, 2019
@karrot42
Copy link
Author

karrot42 commented Jul 2, 2019

Assuming you installed via brew, do you have anything possibly relevant in your log files when doing this? stderr gets redirected to /usr/local/var/log/yabai/yabai.err.log (and similarly replace err with out for stdout). You can monitor this file using tail -f /usr/local/var/log/yabai/yabai.err.log.

An alternative would be to run yabai --verbose instead of the brew service to get a more detailed output, which should print why your windows cannot be selected.

There was no log file in /usr/local/var/log/yabai/ and the --verbose didn't show anything unusual that I could notice

Try using emacs-mac from the tap emacsmacport.

It has much more better GUI support than the original, and a few additional features you might appreciate.

this will probably be my solution especially because there have always been some glitchiness with my emacs install with window resizing and what not, I'll give a try tomorrow.

Does Emacs not provide a good CLI alternative to its GUI version?

It has a CLI alternative but I think it lacks things like following links to open files and URLs in orgmode files, which I use pretty heavily. I could be wrong about that though because I've only used CLI on a headless server in a pinch.

@qhuyduong
Copy link

@karrot42 I'm using emacs-mac and still have the same problem. The simple fix is to add

(menu-bar-mode t)

to configuration file. Hope it help!

@koekeishiya
Copy link
Owner

Closing this then.

@dominiklohmann
Copy link
Collaborator

I added this information to the tips and tricks section of the wiki: https://github.com/koekeishiya/yabai/wiki/Tips-and-tricks#tiling-emacs

I have not tested whether this works as I don't use Emacs myself, but maybe this will help some real programmers (xkcd).

@mattsawyer77
Copy link

I'm using emacs-mac with menu-bar-mode on. Yabai mostly works, but if I try to do cmd+tab to switch to emacs from another space, it moves emacs into the current space instead of switching. I haven't seen any other app do this.

@webframp
Copy link

On macOS I use an emacs config based on doom emacs with emacs-plus installed with these options:
brew install emacs-plus --with-no-titlebar --with-modern-icon --without-spacemacs-icon and this has (menu-bar-mode t) set

I use this rule to contain emacs windows: yabai -m rule --add app=Emacs manage=on space=2

With this setup emacs tiles just fine using yabai and seems well behaved.

@oguzserbetci
Copy link

@webframp your comment helped me tile emacs but I still can't get it to focus by using commands. I get could not locate a southward managed window. although I set

yabai -m rule --add app=Emacs manage=on

@brorbw
Copy link

brorbw commented Oct 9, 2019

Hi, I have been a user of chunkwm and Emacs tiled just as all other programs. Today I installed yabai because a macOS update bricked my chunkwm installation. And everything works as before except Emacs.
Now i have installed a version of emacs called emacs-plus, which has a --with-no-titlebar option that removes the window decoration. The option (menu-bar-mode t) is stil set in emacs which means that what worked for everybody else have not worked for me.
I have also added a tiling rule for Emacs in .yabairc with no effect.
I digged a little bit and it seems like Emacs will tile when it is launched. It even reacts on resizing regardless which application is in focus. I can swap and move commands but only when Emacs is in focus, not when another application is in focus. The same applies for moving focus. I can use commands to move focus away from Emacs, but not to Emacs.

Below is my Emacs installation

brew tap d12frosted/emacs-plus
brew install emacs-plus --with-no-titlebar

@goranmoomin
Copy link

@brorbw
Quoting the wiki... (emphasis mine)

Emacs is not a well-behaved citizen of macOS. Try using → emacs-mac from the Homebrew tap → emacsmacport.

If Emacs is still not recognized by yabai, try enabling menu-bar-mode.

If you're using emacs-plus, you should set up a custom rule for it (which actually creates lots of problems relating to tooltips).

Please see this, this, this, this for more info.

@webframp
Copy link

@brorbw can you provide any more info on your emacs config? I use emacs-plus as I mentioned and have no tiling issues with it. It may be worth trying emacs-mac just to eliminate the cause of the issue

@brorbw
Copy link

brorbw commented Oct 10, 2019

I realise that my poor english skills might have come across as unfamiliarity with chunkwm. For that i apologise.

@pcr910303 I appreciate your answer but all of the above mentioned methods does not work for me. I like having the --with-no-titlebar option and i have been using it for age with chunkwm and i have had no problem.

If Emacs is still not recognized by yabai, try enabling menu-bar-mode.
The (menu-bar-mode t) options is set and makes no difference.

I will add that the official Homebrew install of emacs and emacs-plus does not work either.

If you're using emacs-plus, you should set up a custom rule for it (which actually creates lots of problems relating to tooltips).
I had a custom rule for emacs before and i remember having a workaround for tooltips

@webframp My emacs config is almost the dev branch of spacemacs with some minor changes.

@goranmoomin
Copy link

@pcr910303 I appreciate your answer but all of the above mentioned methods does not work for me. I like having the --with-no-titlebar option and i have been using it for age with chunkwm and i have had no problem.
I had a custom rule for emacs before and i remember having a workaround for tooltips

Well, then I don't understand the question, why would you not add a custom rule for Emacs in your yabai init file?

I will add that the official Homebrew install of emacs and emacs-plus does not work either.

Yes, as said, the official emacs and emacs-plus don't work without custom rules.

Try something like this (this doesn't consider tooltips): have checked working on macOS 10.15 Catalina with Emacs built on master.

yabai -m rule --add label=emacs app=Emacs manage=on

@d12frosted
Copy link

Since emacs-plus is mentioned here several times, let me share a special option that should fix the window role:

$ brew install emacs-plus --with-window-role-fix

It's in 'experimental' state. And if it works reliably, I will make it on by default. Using it for several days (with yabai) and can confirm that doesn't require any special rules.

@brorbw
Copy link

brorbw commented Dec 31, 2019

Does it also work with the --no-title-bar option?

@d12frosted
Copy link

Yes, it works with --with-no-titlebar (please make sure that you use the right option 😸 ).

@brorbw
Copy link

brorbw commented Dec 31, 2019

Yeah, I just wrote what was on the top of my head. Of course it's --woth-no-titlebar.
Happy new year 🎉

@brorbw
Copy link

brorbw commented Jan 3, 2020

@pcr910303

Well, then I don't understand the question, why would you not add a custom rule for Emacs in your yabai init file?

For completeness I will answer your question. I tried adding a custom rule for emacs-plus but it simply wouldn't work hence why I kept asking.

@d12frosted
Copy link

That option was merged and is not required anymore. Have fun :)

@picaschaf
Copy link

That option was merged and is not required anymore. Have fun :)

Was it recently merged? Yesterday I still had to add it for brew install.

@d12frosted
Copy link

@picaschaf it was merged just minutes before I posted about it here. Here is relevant commit: d12frosted/homebrew-emacs-plus@0017af1

@TomFaulkner
Copy link

I know this is closed, but I still have this issue. I installed the Emacs plus from @d12frosted above, and have the rule, yabai -m rule --add label=emacs app=Emacs manage=on. However, I yabai -m window --focus [direction] skips over Emacs as if it wasn't there. Thankfully, it is tiling, however.

@brorbw
Copy link

brorbw commented May 27, 2020

I do not have lable=emacs in my rule and it works fine. Could it be the flavour of emacs? I have installed emacs-plus

@TomFaulkner
Copy link

That is the same Emacs I am using.

I installed the Emacs plus from @d12frosted above

@d12frosted
Copy link

@TomFaulkner I also use emacs-plus and I don't have any special rules for Emacs. And still it works well with --focus commands. AFAIR, it works regardless of Emacs version, but just for the sake of completeness, I am using Emacs 28. This is how I got my version:

$ brew install emacs-plus --without-spacemacs-icon --with-jansson --HEAD

@TomFaulkner
Copy link

TomFaulkner commented May 29, 2020

I was on 26.3, then tried 28 with the --HEAD option, but it couldn't read the Spacemacs (up-to-date develop branch) init.el file for some reason. 27 works and Yabai treats it like other windows now. Thanks for the help.

@larionov
Copy link

I installed emacs-plus --with-no-titlebar, 27, 28, 29 versions, but it still didn't want to tile.
What I found is that when I remove some package's initialization from the .emacs it tiles, but not every time.
And what worked every time is when I restart the yabai service after starting Emacs. This way it always tiles.

@choco
Copy link

choco commented Dec 23, 2021

I've also started using emacs recently, and even with proper accessibility attributes on the window tiling sometimes fails. From a brief investigation this is what happens:

  1. emacs starts, Yabai gets notification, notices that app has not finished launching, listens for application finished launching notification
  2. once Yabai gets that notification it tries to register for the common notifications, but sometimes we get back kAXErrorCannotComplete
  3. app is not registered, not tiles :(

This is mainly caused by the fact the Emacs actually takes a while to properly startup and properly responding to ax requests.
The fix in my case is changing the value here

AXUIElementSetMessagingTimeout(wm->system_element, 1.0);

@koekeishiya I think it would be worth to make that value a little higher or at least configurable, I've seen the same failure described above for other apps like Safari, especially when the system is under load.

@behaghel
Copy link

@choco nice catch. Most likely what's happening with me. It explains also why emacs -Q (skip config, starts in a flash) always get tiled.

@koekeishiya
Copy link
Owner

@choco Just a regression in the changes that were made on the-future branch. Should be back to working as before on the master branch now.

@noctuid
Copy link

noctuid commented Jun 30, 2023

A lot of the suggestions here will cause problems. For anyone confused, you should not use rules. All you need is to use emacs-plus or apply its fix-window-role patch.

Here is a more detailed summary of what currently works to get Emacs tiled correctly without messing up e.g. completion popups:

  • I'm using Emacs installed with emacs-plus's fix-window-role and undecorated-round patches. The fix-window-role patch is all you need to get it working (default if you're using emacs-plus; I'm installing through nix and using the patch). You don't need to use a title bar or manage rule.
  • If you want to use the daemon and emacsclient, run open -a Emacs --args --daemon first or the windows created with emacsclient won't be managed/tiled
  • Do not use any manage=on rules related to Emacs; Emacs.app will already be managed correctly by default, and if you add a manage rule, it will tile child frames (e.g. completion popups); maybe you can use title exclusions to get things working correctly in all cases, but this is unnecessarily complicated (it's not as simple as ignoring empty titles as suggested in Emacs Window Strange Behaviour #587)
  • Do not set yabai -m config window_topmost on; leave it as the default (off) (or completion popups can appear behind Emacs - Bug where menus are created below the active window #1657)

@saucoide
Copy link

@noctuid can I ask, to which emacs version in nixpkgs are you applying the patches to?

I've tried applying the same patches from emacs-plus to get this to work with emacs29 emacs29-pgtk (fails to build) and emacs29-gtk3 but they dont tile correctly, or only tile when the titlebar is enabled, while the version from emacs-plus works without just fine :/

@brorbw
Copy link

brorbw commented Nov 19, 2023

@saucoide I'm using emacs@29 installed with

brew install emacs-plus@29 --with-no-titlebar --with-native-comp

Removing all rules for emacs. That works great. Sometimes when I reboot and emacs opens before yabai loads it wont tile. In that case I have to toggle tiling for the emacs window and then it works.

@noctuid
Copy link

noctuid commented Nov 20, 2023

@saucoide I'm using emacs-git from emacs-overlay. See here.

Why are you trying to use pgtk or gtk on mac? I would not try to use pgtk unless on Wayland or WSL with Wayland.

@saucoide
Copy link

saucoide commented Nov 20, 2023

@noctuid thanks! I wasnt planing on using pgtk, but since the standard one was not working I wanted to try if different ones would behave differently, but thanks will try with that one :)

@brorbw thanks, yes the brew version also works for me, but i've switched everything to nix and emacs is the last straggler that's why i asked noctiud since he mentioned he uses nix as well

update: I'm giving up on getting emacs/yabai to work via nix, will just use the emacs-plus versions which works fine for me, nix + patches i can only get it to tile if i launch it with open -a Emacs + showing the title bar, the moment i modify the 'default-frame-alist to make it undecorated, it doesn't tile anymore, plus M-x is switched between the option & command keys vs the homebrew version with the same emacs config. Anyway thanks everyone for the help at least i learned something

@noctuid
Copy link

noctuid commented Nov 21, 2023

Yeah, I found undecorated-round to be too buggy with yabai (for other reasons I think, but I can't remember) and ended up removing the setting from my early-init. You don't have any issues with it in emacs-plus?

The other issue is probably solvable by just explicitly setting mac-command-modifier and mac-option-modifier.

@saucoide
Copy link

yes, with emacs-plus i dont have any issues, everything works mostly, sometimes if i run emacsclient -c -a '' from keybinding it won't tile, but it's rare and most times it does tile correctly, so i don't worry about it. Could be that it's a race between removing the decoration and naming the frame or something, but for now i'm ok with leaving emacs on homebrew

@noctuid
Copy link

noctuid commented Nov 21, 2023

I take back what I said about undecorated-round. I've been using it for months without issue. Not sure what your setup is, but I don't have any issues with skhd.

@g-simmons
Copy link

I recently switched from "regular" brew emacs to https://github.com/railwaycat/homebrew-emacsmacport.

Using spacemacs, tiling would not work until I changed the following line in .spacemacs:

   ;; dotspacemacs-maximized-at-startup t
   dotspacemacs-maximized-at-startup nil

To check whether spacemacs is the problem, you can break your .spacemacs with a syntax error (or maybe rename it? didn't try).

Broken .spacemacs will open in recovery mode which looks like:

image

Try tiling this window. For me it worked, which pointed to spacemacs as the issue.

ElleNajt added a commit to ElleNajt/emacs that referenced this issue Feb 26, 2024
Per yabai documentation, this makes emacs better behaved with yabi:
koekeishiya/yabai#86
@tshu-w
Copy link

tshu-w commented Jan 7, 2025

Has anyone encountered the issue where M-x restart-emacs fails to get tiled? A fresh Emacs launch works normally.

Steps to reproduce:

  1. emacs -Q
  2. M-x restart-emacs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Community help appreciated question Request for information or help, not an issue
Projects
None yet
Development

No branches or pull requests