From 28d20af3e9ec4ef095d3215e23aa54932a6555c7 Mon Sep 17 00:00:00 2001 From: Izzy Gomez Date: Mon, 9 Mar 2026 09:53:34 -0400 Subject: [PATCH] [WIP] `emacs`: have all emacs invocations call running daemon --- zsh/fragments/zshrc_emacs | 40 ++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/zsh/fragments/zshrc_emacs b/zsh/fragments/zshrc_emacs index 9fe6121..f7669c8 100644 --- a/zsh/fragments/zshrc_emacs +++ b/zsh/fragments/zshrc_emacs @@ -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.'" @@ -25,21 +26,30 @@ connect_to_emacs() { # `e ` to open 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='' "$@" }