summaryrefslogtreecommitdiff
path: root/bin/emacsclient
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-10-29 11:08:03 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-10-29 21:53:28 -0700
commit5c0d0b53498397ea3e28a9eb65e9d4b57ab81594 (patch)
tree14c8b160c3c921dd1c764da9bc935d0388d348cc /bin/emacsclient
parent4f431bcd816b01455bff49d2a0c977851770ccbc (diff)
downloaddotfiles-5c0d0b53498397ea3e28a9eb65e9d4b57ab81594.tar.gz
emacsclient wrapper: ensure Emacs puts sockets under XDG_RUNTIME_DIR
Diffstat (limited to 'bin/emacsclient')
-rwxr-xr-xbin/emacsclient17
1 files changed, 12 insertions, 5 deletions
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}"