Skip to content

Instantly share code, notes, and snippets.

@railwaycat
Last active March 12, 2023 01:26
Show Gist options
  • Save railwaycat/4043945 to your computer and use it in GitHub Desktop.
Save railwaycat/4043945 to your computer and use it in GitHub Desktop.
Start Emacs.app from CLI
#!/usr/bin/perl
# Emacs starter for Emacs mac port
# Thanks to Aquamacs Project and David Reitter
my $args = "";
my $tmpfiles = "";
for my $f (@ARGV) {
$args .= '"'.$f.'" ';
$tmpfiles .= '"'.$f.'" ' if (! -e $f);
}
system("touch $args") if ($tmpfiles);
system("open -a /Applications/Emacs.app $args");
# delay deletion because AE drag&drop doesn't work with non-existing documents
system("(sleep 3; rm $tmpfiles) &") if ($tmpfiles);
exit;
@nasyxx
Copy link

nasyxx commented Jan 27, 2019

@Vvkmnn

  • emacsclient doesn't work with emacs-mac, which doesn't install a /Applications/Emacs.app/Contents/MacOS/bin/emacsclient, and is therefore not available with or without the (server-start) parameter.

Hello Vivek, I tried to change /Applications/Emacs.app/Contents/MacOS/bin/emacsclient to /usr/local/bin/emacsclient (emacs-mac). After that, this script would work well.

@SolidStill
Copy link

Hi, would anyone happen to know the current functioning approach for the brew cask install emacs-mac installation?

The default script installed by brew at /usr/local/bin/emacs (without args) doesn't open a background instance of emacs by default, as is my preferred behaviour. I know I could do $ alias emacs='emacs &', but I'm basically a novice in this whole game and:

  1. I don't know what negative consequences that might have, and,
  2. I'm keen to get my hands on a working current solution as a case-study, and see why the other methods weren't working (or where I'm going wrong) for the sake of education in the ways of the shell.

Maybe someone knows whether me using the Spacemacs distribution or the Zsh shell would break these approaches?
(RE Spacemacs, when I attempted to use @ChillingHsu's approach I tried placing the (server-start) line in init.el, as well as every possible section of my .spacemacs file without luck)

Thanks very much

@aidanscannell
Copy link

Maybe someone knows whether me using the Spacemacs distribution or the Zsh shell would break these approaches?
(RE Spacemacs, when I attempted to use @ChillingHsu's approach I tried placing the (server-start) line in init.el, as well as every possible section of my .spacemacs file without luck)

Hi SolidStill, as a fellow spacemacs user I also faced some issues getting this setup.

I've written a short blog post about my emacs/spacemacs installation and setup which hopefully might help you. I used a combination of the code snippets from here but had to change a few things. You will also need to disable all of the spacemacs server variables in your .spacemacs file. I detail this in the post though.

Best of luck.

@SolidStill
Copy link

Just scanned thorugh your blog post @aidanscannell; thanks v much for taking the time to reply - your post touches on a few key additional topics I've been trying to develop a decent understanding of: Latex authoring in emacs on macos, version-controlling emacs setups/configurations.

Funnily enough, I actually graduated from Bristol with a Maths BSci in 2010, never used that education in any meaningful way, and am now training myself up to get a job in data analysis. I'm looking to redevelop a technical mindset/mentality by getting into the guts of (and really understanding) all the tools/methods/theory I encounter along that journey. Your post really nails the kind of efficiently-verbose and well-reasoned exposition that is crucial in really developing understanding in a concept, as opposed to just becoming familiar with a concept.

In all honesty, the temptation to pester you with emacs-related technical support questions is probably going to be too strong to resist. I'm truly glad that I eventually noticed this post, "being less amateur with Github notifications" is def going on my learning-list. Thanks for the inspiration and kudos for helping deliver Skynet to mankind 😛

@willbchang
Copy link

I wrote an Alfred workflow which supports emacs: https://github.com/willbchang/alfred-open-in-editor

@duhd1993
Copy link

duhd1993 commented Dec 10, 2020

Hi @mwolson, thanks for the update. I believe your starter script works for Nextstep port (although I haven't verify that by myself), but it not works for Mac port. Because Emacs Mac port lacks multi-tty support, which means, emacsclient from mac port can only able to create tty frames but not GUI frames.

@railwaycat This seems outdated. I'm able to open GUI emacs from emacsclient now. Could you update instructions for this? However, the Emacs server in GUI app won't run in the background. C-x C-x the last window closes the app and also the server. This behavior is different from the official Emacs build. Their Emacs.app can run without any window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment