reddit / emacs

Emacs 28 as favorite application in gnome

cathedral_mistreat · 2022-04-05 20:13
Hi, I have previously had emacs 27 as a favorite application in gnome, with the following behavior: If no instance of emacs is open, clicking it opens emacs If an instance of emacs is open, clicking it brings the current instance to the front. However, with emacs 28 I notice that there are two emacs shortcuts available, one called "Emacs" and one called "Emacs (client)". Neither of these replicate the previous behavior. The "emacs" application opens new instances of emacs each time. The behavior of "Emacs (client)" is more subtle. If I have opened "Emacs" it *sometimes* does the right thing and focuses the existing instance, but some times it does not do anything. If no instance of emacs is open, it does open emacs but does not load doom emacs as expected. Is there some compiler flag somewhere that I'm missing? I never meant to enable emacsclient. [edit] I see from the news file: New desktop integration for connecting to the server. If your operating system's desktop environment is freedesktop.org-compatible (which is true of most GNU/Linux and other recent Unix-like desktops), you may use the new "Emacs (Client)" desktop menu entry to open files in an existing Emacs instance rather than starting a new one. The daemon starts if it is not already running. So I guess this is the relevant change, though it doesn't seem to interact perfectly with my fedora 35 install.
Hastrack · 2022-04-05 23:17
Have you verified the difference between the .desktop files of emacs 28 and 27? That might give a hint. I don't use a DE neither have emacs 27 so I can't test that.
Michaelmrose · 2022-04-06 08:47
Running emacs and nothing else always starts a new instance. Running emacs --daemon starts the background service Running emacsclient -c creates a new frame on an existing daemon You can pass an argument to emacsclient to have it automatically start emacs if it's not already running but since emacs can take depending on your configuration several seconds to start I think it makes sense to run emacs --daemon as a user service at login and just call emacsclient -c Who knows what your distro has in it's desktop file unless you check.
cathedral_mistreat · 2022-04-06 13:24
Thanks. The desktop files are identical between 27 and 28. It seems like I can get my desired behavior by starting emacs first, and having "emacs (client)" as a favorite. I tried this yesterday but it seemed unreliable, trying it today seems reliable. Emacs starts in about a second which is fast enough for me.
cathedral_mistreat · 2022-04-06 13:24
The desktop files are the same.
Michaelmrose · 2022-04-06 14:27
The point I'm making is that there is zero inconsistency in how these commands work. They don't do some things some of the time and other times others. For example there is absolutely no logic in emacsclient to focus an existing instance that is something your bar/desktop environment provides the logic for. If you make and enable user service that runs emacs --daemon and ensure you are invoking emacsclient -c you will note the correct behavior as far as creating a client on the existing daemon. Looking at my desktop file for emacsclient exec will create a new instance of daemon if not running then a new frame. New window will create a new frame doing as above. New instance starts emacs from scratch not starting daemon unless explicitly invoked in your configuration. This last is unlikely to be what you want. Also note there is a long standing bug with the gtk UI and daemon mode where closing the last window can kill the daemon. It even warns you about this in output. I haven't seen this issue any longer but if you see emacs the daemon exiting after the last client frame you can check out emacs lucid.
andreyorst · 2022-04-06 16:10
I've written my own `emacs.desktop` file to achieve this behavior: https://raw.githubusercontent.com/andreyorst/dotfiles/master/.local/share/applications/emacs.desktop With this desktop file, I can launch emacs, and use the same desktop file to open files from file browser in the already running instance. It's still possible to launch separate instance by clicking with the mouse wheel (three finger click on touchpad). It does require a server to be started from Emacs: https://github.com/andreyorst/dotfiles/blob/f4caf204b44e616342efa416846bab9b40bcfef5/.config/emacs/init.el#L1144-L1148 (I don't use daemon mode, because I don't have emacs running all the time, and frequently restart or close it. Since startup time is a bit shorter than 1 second I don't care much)