summaryrefslogtreecommitdiff
path: root/bin/emacsclient
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-09-26 10:55:22 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-09-30 22:34:04 -0700
commitab1dbe94462d611ce482d3d52ddd4262bdd69228 (patch)
treefb4307f62870cb235ccea11e7efd7a08e491b099 /bin/emacsclient
parent124632f7aca4beaca62ab10c711be3b1c65b851d (diff)
downloaddotfiles-ab1dbe94462d611ce482d3d52ddd4262bdd69228.tar.gz
gdbmacs instance, s.t. can always run Emacs under gdb, and for Gnus
Diffstat (limited to 'bin/emacsclient')
-rwxr-xr-xbin/emacsclient35
1 files changed, 27 insertions, 8 deletions
diff --git a/bin/emacsclient b/bin/emacsclient
index 0e6ab7a6..c261d469 100755
--- a/bin/emacsclient
+++ b/bin/emacsclient
@@ -21,11 +21,25 @@
# daemons and choosing between installed and in-tree builds of Emacs.
min_arg=0
+command -v ss >/dev/null || exit 1
+socket_dir="/run/user/$(id -u)/emacs/"
+get_listener () {
+ local socket="$1"
+ local listener=$(ss -Hplx src "$socket" \
+ | perl -wne'/pid=(\d+)/ and print $1')
+ if [ -z "$listener" -a -e "$socket" ]; then
+ # Nothing is listening: remove dangling socket.
+ rm "$socket"
+ else
+ echo "$listener"
+ fi
+}
for arg do
shift
case "$arg" in
'--spw/installed') mode=--spw/installed ;;
+ '--spw/no-start') start=false ;;
'--spw/update-environment') update=true ;;
'-s'|'--socket-name') min_arg=2; daemon_name="$1" ;;&
'-s'?*) min_arg=1; daemon_name="${arg:2}" ;;&
@@ -34,14 +48,9 @@ for arg do
esac
done
-command -v ss >/dev/null || exit 1
-socket="/run/user/$(id -u)/emacs/${daemon_name:-server}"
-listener="$(ss -Hplx src $socket | perl -wne'/pid=(\d+)/ and print $1')"
-
-if [ -z "$listener" -a -e "$socket" ]; then
- # Nothing is listening: remove dangling socket.
- rm "$socket"
-elif [ -n "$listener" ]; then
+socket="$socket_dir${daemon_name:-server}"
+listener="$(get_listener $socket)"
+if [ -n "$listener" ]; then
case "$(ps h -o exe $listener | sed -e 's/ (deleted)$//')" in
"$HOME/src/emacs/src/emacs") devel_running=true ;;
"$(realpath $(command -v emacs))") installed_running=true ;;
@@ -51,10 +60,20 @@ fi
if [ "$devel_running" = true -a "$mode" = --spw/installed ]; then
kill "$listener"
+
+ # Detach gdb so that Emacs can handle the SIGTERM.
+ # We also have to quit gdb so that `gdb-inferior-status' is reset from
+ # "signal-received"; see `spw/gdbmacs-attach' command.
+ [ -n "$(get_listener ${socket_dir}gdbmacs)" ] \
+ && emacsclient -sgdbmacs --eval '(gud-basic-call "detach")' \
+ --eval '(gud-basic-call "quit")'
+
[ -e "$socket" ] && inotifywait -qqt 2 -e delete "$socket"
devel_running=false
fi
+[ "$start" = false -a -z "$listener" ] && exit 0
+
# We check whether there is something which looks like the installed Emacs
# running because we do not want the in-tree emacsclient to try to connect to
# that, and we check whether there is a build in progress and no running