homebrew-emacs-plus icon indicating copy to clipboard operation
homebrew-emacs-plus copied to clipboard

MacOS App should detect running emacs brew service and connect as a GUI emacsclient.

Open cwlbraa opened this issue 2 years ago • 17 comments

I love that this formula includes a brew service, and for the longest time I was running that service alongside the Emacs.App. I only recently realized that these 2 paths to invoking Emacs are unaware of each other, and the App will not attempt to connect to the daemon started by the brew service.

If this worked, it'd be amazing for startup times and keeping a single persistent Emacs daemon.

cwlbraa avatar Sep 27 '21 16:09 cwlbraa

Hey @cwlbraa

I think this kind of relates to https://github.com/d12frosted/homebrew-emacs-plus/issues/158. That issue stagnated though.

What do you think about the following solution?

In addition to Emacs.app, emacs-plus provides extra application Emacs Client.app that is a wrapper around emacsclient. This way we don't need to come up with fancy heuristics, but instead rely on emacsclient itself that knows how to work.

The only possible issue I see - there will be no way to configure socket and server, you'll have to use defaults.

d12frosted avatar Sep 29 '21 07:09 d12frosted

I'd use the simple solution if it existed, so yeah I think it's good. I'd probably hide the full Emacs.app from Alfred and end up with basically the same behavior as the fancy thing I previously described. I'd also be perfectly happy with defaults.

cwlbraa avatar Sep 29 '21 15:09 cwlbraa

Currently I use an "application" created via automator that runs emacsclient -c, its been working great for me so far

The solution you propose seems about the same, having it included with emacs-plus would be very nice

shaunsingh avatar Oct 02 '21 18:10 shaunsingh

It would be great to have the Emacs Client.app.

C1oud555 avatar Apr 17 '22 03:04 C1oud555

I'm having trouble finding Emacs Client.app, do you have to install with a specific flag? Thanks.

diocletiann avatar May 11 '22 02:05 diocletiann

@restfuladi you can't find it because it doesn't exist :) But there is emacsclient binary installed that you can use for your needs.

d12frosted avatar May 11 '22 08:05 d12frosted

@restfuladi you can't find it because it doesn't exist :) But there is emacsclient binary installed that you can use for your needs.

Makes sense, thanks. Any ideas on how to integrate that with Spotlight/Alfred?

diocletiann avatar May 12 '22 16:05 diocletiann

@restfuladi Spotlight/Alfred have issues with symlinks, however Raycast works really well!

gf3 avatar May 12 '22 16:05 gf3

@restfuladi you can't find it because it doesn't exist :) But there is emacsclient binary installed that you can use for your needs.

Makes sense, thanks. Any ideas on how to integrate that with Spotlight/Alfred?

If you create an Automator application for emacs client and put it in /Applications, that should work with Spotlight. I recommend full path: /opt/homebrew/bin/emacsclient -c -a emacs "$@" >/dev/null 2>&1

mjgiffin avatar May 25 '22 13:05 mjgiffin

Piggy-backing on this issue, happy to make another one - when I launch emacsclient from terminal or Alfred, it doesn't switch to the app - the window opens behind other windows, and then I have to manually switch to it. Has anyone a fix for that?

rross101 avatar Jul 12 '22 19:07 rross101

Hi, I think Emacsclient.app is a fantastic idea. Is this something that will become available in the homebrew installation? I am new to macos (coming from linux), and I have very little experience doing mac-y things. I also observed what @rross101 said. It's a minor inconvenience, but of course, if it can be addressed it's even better.

Software architecture of the mac is so, so inefficient. It's like homebrew is creating an OS within an OS, and obviously there are no standards like XDG or how permissions are managed etc. I can't even get my brew-installed hunspell to integrate with emacs-plus. Sorry for the rant, but macos is just such a user unfriendly environment to work in if you are trying to something even remotely technical.

ChauhanT avatar Dec 02 '22 22:12 ChauhanT

Hi, I think Emacsclient.app is a fantastic idea. Is this something that will become available in the homebrew installation?

The idea is to provide this as part of Emacs+ installation. But it's not high on my priority list. So if someone really wants it, contributions are welcome.

Software architecture of the mac is so, so inefficient. It's like homebrew is creating an OS within an OS, and obviously there are no standards like XDG or how permissions are managed etc.

Indeed, macOS is slightly (quite?) different in many regards and might be confusing if you come from newer Linux-es. macOS is based on older FreeBSD.

I can't even get my brew-installed hunspell to integrate with emacs-plus. Sorry for the rant, but macos is just such a user unfriendly environment to work in if you are trying to something even remotely technical.

Look, if you need some help, don't hesitate to open a discussion. The problem you describe is not really related to Emacs+, but it's somewhere on the border, so maybe it's fine :)

d12frosted avatar Dec 04 '22 07:12 d12frosted

@ChauhanT This is what I did:

  1. Start the emacs-plus service and register it to launch on login/boot:
    brew services start emacs-plus@29
    
  2. Create an "application" with Automator: Screenshot 2022-12-28 at 16 14 28
  3. If you want, change the app icon (Right click -> "Get info" or Cmd-i). I used the same I compile emacs-plus with, nobu417-big-sur-icon: Screenshot 2022-12-28 at 16 17 49

@rross101 You could use Apple Script for that: osascript -e 'tell application "Emacs" to activate' You can wrap that up in aliases or shell functions, e.g.

function ec() {
  emacsclient $@ && osascript -e 'tell application "Emacs" to activate'
}

citizen428 avatar Dec 28 '22 09:12 citizen428

I found I had to tweak @citizen428's answer a little bit to get the applescript to work reliably:

Screenshot 2023-04-10 at 20 33 57

johnhamelink avatar Apr 10 '23 19:04 johnhamelink

I found I had to tweak @citizen428's answer a little bit to get the applescript to work reliably:

Screenshot 2023-04-10 at 20 33 57

This works for me. Thank you!

rross101 avatar Apr 11 '23 08:04 rross101

I changed it to following to set Emacs Client as the default text editor:

image

GauravTalreja avatar May 05 '23 07:05 GauravTalreja

I just checked quickly and noticed that these Automator scripts do not launch emacs when the server is not running. Has anyone else encountered this?

michaelssingh avatar Sep 27 '23 18:09 michaelssingh