Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions zsh/fragments/zshrc_emacs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Sourced by ~/.zshrc. Not intended to be run standalone; may rely on
# variables & functions defined earlier in the sourcing chain.

export EDITOR=emacs # set as default editor
# Set emacs as default editor. TODO more docstring
export EDITOR="emacsclient --socket-name default --alternate-editor=''"

# Shortcuts to manually start/kill emacs daemon and use emacsclient.
alias emacsd="emacs --daemon && echo 'Started emacs daemon.'"
Expand All @@ -25,21 +26,30 @@ connect_to_emacs() {
# `e <file>` to open <file> in daemon.
e() {
# If emacs daemon is already running, connect to it.
if pgrep -x "emacs" | xargs ps -p | grep -q "\--daemon"; then
# if pgrep -x "emacs" | xargs ps -p | grep -q "\--daemon"; then
# echo "Emacs daemon already running. Connecting..."
# connect_to_emacs "$@"
# else
# echo "Emacs daemon not already running. Starting..."
# emacs --daemon

# # Wait until the daemon is ready
# while ! emacsclient --eval \
# "(progn (require 'server) (server-running-p))" \
# >/dev/null 2>&1; do
# sleep 1
# done

# echo "Emacs daemon started. Connecting..."
# connect_to_emacs "$@" # Connect to new daemon with same arguments
# fi

#### LOOK AT CLAUDE CHAT ####
#### NEW CODE ####
if pgrep -x emacs | xargs ps -p 2>/dev/null | grep -q -- --daemon; then
echo "Emacs daemon already running. Connecting..."
connect_to_emacs "$@"
else
echo "Emacs daemon not already running. Starting..."
emacs --daemon

# Wait until the daemon is ready
while ! emacsclient --eval \
"(progn (require 'server) (server-running-p))" \
>/dev/null 2>&1; do
sleep 1
done

echo "Emacs daemon started. Connecting..."
connect_to_emacs "$@" # Connect to new daemon with same arguments
echo "Emacs daemon not running. Starting..."
fi
emacsclient -c --alternate-editor='' "$@"
}