From 5c0d0b53498397ea3e28a9eb65e9d4b57ab81594 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 29 Oct 2022 11:08:03 -0700 Subject: emacsclient wrapper: ensure Emacs puts sockets under XDG_RUNTIME_DIR --- bin/emacsclient | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'bin/emacsclient') diff --git a/bin/emacsclient b/bin/emacsclient index 752102f9..f14c6c63 100755 --- a/bin/emacsclient +++ b/bin/emacsclient @@ -34,9 +34,6 @@ gud_status= daemon_name= gdbmacs= args= -xdg="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" -socket_dir="$xdg/emacs/" -locks_dir="$xdg/spw_emacsclient/" get_listener () { local socket="$1" @@ -52,8 +49,7 @@ get_listener () { maybe_notify () { echo >&2 "$1" - [ -n "$XDG_RUNTIME_DIR" ] \ - && notify-send --urgency=low --expire-time=10000 "$1" + $was_set && notify-send --urgency=low --expire-time=10000 "$1" } spw_flock () { @@ -111,6 +107,17 @@ installed_emacsclient=$(PATH=$(echo "$PATH" \ command -v ss >/dev/null || exec "$installed_emacsclient" -a "" "$@" +# We set and export XDG_RUNTIME_DIR such that Emacs doesn't choose +# "/tmp/emacs$(id -u)" as the socket dir. +if [ -n "$XDG_RUNTIME_DIR" ]; then + was_set=true +else + was_set=false + export XDG_RUNTIME_DIR=/run/user/$(id -u) +fi +socket_dir="$XDG_RUNTIME_DIR/emacs/" +locks_dir="$XDG_RUNTIME_DIR/spw_emacsclient/" + $want_version || spw_flock 3 "${daemon_name:-server}" socket="$socket_dir${daemon_name:-server}" -- cgit v1.2.3