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

emacs-30: provide Emacs Client.app #783

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

d12frosted
Copy link
Owner

this is mostly for testing
if it goes well, I will provide Emacs Client.app for other versions of Emacs.

@d12frosted
Copy link
Owner Author

It works, but I can't figure out how to capture file path when you open a file from Finder. If someone knows - please let me know :)

@d12frosted
Copy link
Owner Author

Ok, shell scripts is not the right approach as it seems. Turns out macos sends filename via system events, not via arguments. Will explore two directions - a simple cocoa application or a simple apple script application.

@danielboston38
Copy link

if you create a AppleScript or automator app it works fine. I am using it this way.

@danielboston38
Copy link

unfortunately brew services does not run the daemon. I guess it's just keeping emacs alive? which six of one half dozen of the other I guess. I guess emacs is looking for the daemon to run in client mode? so maybe it doesn't know what's going on with this service that's just keeping emacs running?

@mbhutton
Copy link

mbhutton commented Feb 26, 2025

I'm curious about what this is for?

If the idea is to support opening files via finder interactions or via open -an Emacs, the existing Emacs.app already handles this well (once the app is already running).

If it's to support opening via org-capture, isn't that better done in the existing Emacs.app, ie issue #285 .

Or is it to have an app to call that can ensure the main Emacs is alive and route file args to it?

In my current workflow, restarting Emacs looks like
brew services restart emacs-plus@30 ; sleep 4; emacsclient -c -n ; sleep 2; open -a Emacs.

Once that's up, I can treat the Emacs.app like most other apps using activation/open/drag files etc. It'd be nice to have stop/start/restart/daemon handling less of a thing I need to worry about, as depending on the timing I can end up with extra processes, or a foreground daemon app instead.

I think ideally the one Emacs.app would act as the app to:

Is there benefit to handling these cases in different applications, or is it more about what's feasible?

@mbhutton
Copy link

mbhutton commented Feb 27, 2025

unfortunately brew services does not run the daemon

@danielboston38 I'm running emacs-plus via brew services restart emacs-plus@30 which runs Emacs as a daemon:

$ ps aux  | grep emacs
[...] /opt/homebrew/Cellar/emacs-plus@30/30.1/Emacs.app/Contents/MacOS/Emacs --fg-daemon

@d12frosted
Copy link
Owner Author

unfortunately brew services does not run the daemon.

Any proof? I just did it and it works. Keep in mind that TCP is not supported (not sure why).

if you create a AppleScript or automator app it works fine. I am using it this way.

Yes, but every user needs to create it. Wouldn't it be nice if we had it OOTB?

I'm curious about what this is for?

To have ability to open files from Finder in Emacs Client. And I just realised that you are correct for cases when Emacs is already open, because Finder doesn't create a new instance of Emacs. But if you start Emacs server via brew, then things break. When I try to open a file in Emacs via Finder when the service is running, Emacs is opened, but the window is not created 🤷 So I actually have to use CLI to open a new window. And maybe this is what needs to be fixed actually.

@mbhutton thanks a lot for your insights! 🙏

@mbhutton
Copy link

mbhutton commented Feb 27, 2025

True! Activation and file opening via Finder work well when the service is running and at least one frame is active. But when there's no active frame then usually something surprising happens like an extra process, or no window opening, and I need to figure out what went wrong and fix it.

It would be amazing to have an app, Emacs.app itself or a companion app, "do what I mean", for activation, finder files, and org-protocol.

My dream would be for it to:

  • ensure the brew Emacs service is running, waiting until ready to...
  • create a frame if necessary, waiting until ready to...
  • Do The Thing (open file or org-protocol link then activate)

A tool that was able to do all that would also be just as useful from the command line.

emacsclient-dwim and Emacs Client DWIM.app for "do what I mean"?

@mbhutton
Copy link

mbhutton commented Feb 27, 2025

Maybe there are some extractable, composable commands in there that could be useful as their own command.

Eg:

  • emacsclient-dwim ensure-daemon-ready
  • emacsclient-dwim ensure-frame
  • emacsclient-dwim focus-frame
  • emacsclient-dwim open-files
  • emacsclient-dwim open-org-protocol-link

Btw I know this is crazy out of scope for this PR (!), just trying to capture what the scope of the problem is. Kinda sounds like a project in itself to cover all the above.

@mbhutton
Copy link

Oh and (to add to the list of wishes!) ideally the app would also act as a share target to invoke the command org-protocol convention of url, title, and text.

If all of that aligns with what most users want, I could definitely contribute, or possibly write it directly in a different project, as it could potentially be useful across all the macOS Emacs flavours.

I think that solving all those problems probably does require one tool that's able to coordinate all those aspects, otherwise it's easy to end up with a patchwork of apps/tools that only work in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants