Emacs with pantheon desktop

Because of the issue described here https://elementaryos.stackexchange.com/questions/797/how-to-get-gnu-emacs-work-on-elementary-os, I can’t start emacs using the normal application launcher (it basically crashes on startup - I can start if from the command line if I set the environment variable as described in the above post, but not using the normal ‘click the icon’ way).

My question is, should this be considered a bug, and how should I deal with that? Should I open an issue on GitHub (nixpkgs?) or something like that?

If not considered a bug with nixpkgs (because it’s a known upstream issue), then the way to deal with this would be to modify the .desktop file associated with emacs. But I have no idea where this file is located, let alone how to change it. Any help with that would also be appreciated.

Thanks, and sorry for the noob question.

1 Like

This is a bug in Emacs that impacts anyone using the Pantheon desktop (NixOS or not).

You can override any .desktop file by copying it into ~/.local/share/applications and then making the relevant edits. Where that original desktop file is depends on how you installed Emacs, but you can probably find it in either /run/current-system/sw/share/applications or ~/.nix-profile/share/applications.

Assuming you installed it system-wide, I’d just do something like the following in your terminal:

mkdir -p ~/.local/share/applications
cat /run/current-system/sw/share/applications/emacs.desktop > ~/.local/share/applications/emacs.desktop
nano ~/.local/share/applications/emacs.desktop

Then, look for the line that starts Emacs and wrap it in env XLIB_SKIP_ARGB_VISUALS=1. I forget what the Emacs line looks like, but it will be something like Exec=emacs %F, in which case you’ll change it to Exec=env XLIB_SKIP_ARGB_VISUALS=1 emacs %F.

Once you make the change, it should work immediately, but if it doesn’t try logging out and then back in again.

1 Like

Thanks, this is awesome. It works like a charm.

I realize that this is an upstream bug not related to NixOS, but the reason I wanted to ask whether it can be fixed at the package level is that it makes for a very bad out-of-the-box experience when you try to install one of the most popular packages out there and it simply fails without warning (you get the warning if you try to run it from the command line, but that’s not the way most people will do it initially). I suppose it would be hard to build in logic to say “if running pantheon use this emacs.desktop, otherwise use another one” or something like that?

Anyways, thanks again for your help. The NixOS community is amazing.

1 Like

There’s occasionally overrides in other cases, so I think someone could always submit a patch.

From my (limited) reading, my understanding is that the problem isn’t Pantheon per se, but rather there’s a long-standing buggy interaction between Emacs and a class of GTK themes (which happens to include the Elementary GTK theme) that trigger this. So limiting the fix to Pantheon is really too narrow of a solution (there’s other themes that will also crash Emacs like this), and it’s not really clear how you’d create a more general work-around (my understanding is that you generally don’t want to set XLIB_SKIP_ARGB_VISUALS=1, as doing so can have a negative performance impact).

I think the intersection of Pantheon users and NixOS users and Emacs users and people willing to spend the time and/or have the skill to put together a pull request that works around this in a robust way is zero right now.

You could create a custom desktop file and put it in ‘.local/share/applications’

I think that, unfortunately, you are right. The problem lies at the intersection of different projects, and none of them wants to take responsibility for fixing it, so the issue goes unresolved (and as an unfortunate consequence, desktop linux will continue to have the reputation that things don’t work properly out of the box). Anyways, thanks so much for your help, it’s much appreciated.

@fctorial: That is exactly what I did, following the advice of @necopinus, and it worked.

I’ve found that if you use the emacs overlay with the emacsPgtk option, it will also work fine on pantheon.