#!/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; | |
This comment has been minimized.
This comment has been minimized.
Thanks @ptb :) |
This comment has been minimized.
This comment has been minimized.
Sorry to ask guys, how can I install this? |
This comment has been minimized.
This comment has been minimized.
@lmartins Paste into a file named |
This comment has been minimized.
This comment has been minimized.
It'd be better to use |
This comment has been minimized.
This comment has been minimized.
The command system("open -a Emacs $args"); |
This comment has been minimized.
This comment has been minimized.
Here's a variation that ensures Emacs.app is launched, waits for it to be ready, and then uses #!/bin/sh
CLIENT=/Applications/Emacs.app/Contents/MacOS/bin/emacsclient
$(/usr/bin/osascript <<-END
tell application ((path to applications folder as text) & "Emacs.app")
activate
end tell
END
)
while ! "$CLIENT" -e '"pass"' 2>&1 | grep '"pass"' > /dev/null; do
sleep 0.3
done
if test "$#" -gt 0; then
exec "$CLIENT" -c $@
fi |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
@ptb Just curious, why do you use a sub-shell to initialize Edit: After some digging, I see I was misinterpreting the parentheses and mistaking an array assignment for a sub-shell. |
This comment has been minimized.
This comment has been minimized.
Do I need to start server in emacs config before running this? because emacsclient gives me the following error
|
This comment has been minimized.
This comment has been minimized.
I made some small modifications to the script @ptb provided. This variation is callable with or without file args, and will make emacs visible even if it was previously hidden. The #!/bin/sh
emacs_app=/usr/local/opt/emacs-mac/Emacs.app
if [ ! -x $emacs_app ]; then
echo "Emacs.app not found" >&2
exit 1
fi
/usr/bin/osascript -e "tell application \"$emacs_app\" to activate" &
if [ $# -gt 0 ]; then
tempfiles=()
while IFS= read -r filename; do
if [ ! -f "$filename" ]; then
tempfiles+=("$filename")
/usr/bin/touch "$filename"
fi
file=$(echo $(cd $(dirname "$filename") && pwd -P)/$(basename "$filename"))
/usr/bin/osascript -e "tell application \"$emacs_app\" to open POSIX file \"$file\""
done <<< "$(printf '%s\n' "$@")"
for tempfile in "${tempfiles[@]}"; do
[ ! -s "$tempfile" ] && /bin/rm "$tempfile"
done
fi & |
This comment has been minimized.
This comment has been minimized.
This will create buffers of any number of existing or non-existing files with or without spaces in their names in a new instance of Emacs.app.
If you have an emacs server running, then typing |
This comment has been minimized.
This comment has been minimized.
Anyone know if it's possible to use emacsclient with emacs-mac in a way that opens a new cocoa frame with the Interestingly it looks like some people seem to have a
If it's useful to anyone here's the plist I'm using to start the emacs daemon automatically on login:
Then I have a couple utility functions for restarting it or stopping it as needed:
Would love to know if anyone has figured out the emacsclient thing though. That's the only thing I seem to be able to do with the default homebrew emacs setup that I haven't figured out with emacs-mac. |
This comment has been minimized.
This comment has been minimized.
@worace If you start the server in a running GUI Emacs instance, |
This comment has been minimized.
This comment has been minimized.
@tonylotts do you know if it's possible to have the GUI emacs client connect to an already existing emacs daemon instance? |
This comment has been minimized.
This comment has been minimized.
@worace @johnhamelink #!/bin/bash
BG_RED=`tput setaf 1`
BG_GREEN=`tput setaf 2`
BOLD=`tput bold`
RESET=`tput sgr0`
EMACS='/Applications/Emacs.app'
EMACS_CLIENT='/Applications/Emacs.app/Contents/MacOS/bin/emacsclient'
DEFAULT_EVAL='(switch-to-buffer "*scratch*")'
DEFAULT_ARGS="-e"
NO_WAIT='-n'
function run_client(){
if [ $# -ne 0 ]
then
${EMACS_CLIENT} ${NO_WAIT} $@
else
${EMACS_CLIENT} ${NO_WAIT} ${DEFAULT_ARGS} "${DEFAULT_EVAL}" &> /dev/null
fi
}
echo -e "Checking Emacs server status...\c"
if pgrep Emacs &> /dev/null
then
echo "${BOLD}${BG_GREEN}Active${RESET}"
echo -e "Connecting...\c"
run_client $*
echo "${BOLD}${BG_GREEN}DONE${RESET}"
else
echo "${BOLD}${BG_RED}Inactive${RESET}"
echo -e "Emacs server is starting...\c"
open -a ${EMACS}
echo "${BOLD}${BG_GREEN}DONE${RESET}"
echo -e "Trying connecting...\c"
until run_client $* &> /dev/null;[ $? -eq 0 ]
do
sleep 1
done
echo "${BOLD}${BG_GREEN}DONE${RESET}"
fi |
This comment has been minimized.
This comment has been minimized.
Tested out @ChillingHsu's method from above across a few different builds on macOS High Sierra 10.13 with Emacs 26, and found the following:
I like |
This comment has been minimized.
This comment has been minimized.
How to place a hook for when one opens a file via the terminal? (Using plain Emacs.app - no client/server) Update: I can confirm either of these works: (add-hook 'find-file-hook 'xxx)
(advice-add 'pop-to-buffer-same-window :after 'xxx) |
This comment has been minimized.
This comment has been minimized.
Hello Vivek, I tried to change |
This comment has been minimized.
This comment has been minimized.
Hi, would anyone happen to know the current functioning approach for the 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
Maybe someone knows whether me using the Spacemacs distribution or the Zsh shell would break these approaches? Thanks very much |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
I wrote an Alfred workflow which supports emacs: https://github.com/willbchang/alfred-open-in-editor |
This comment has been minimized.
This comment has been minimized.
@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. |
This comment has been minimized.
I rewrote this as a shell script and added the capability to accommodate filenames with spaces:
Since I switched from vi, I can't help but to type
vi filename
every time, so I saved this script as/usr/local/bin/vi
. In the off chance I haven't yet installed Emacs.app, it uses the built in systemvim
instead.