From 7700d2d3e8c840f78f9fc5010cf778e764a912d2 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 29 Oct 2022 14:53:11 -0700 Subject: emacsclient wrapper: pass nicer zeroth arg to installed programs In-tree Emacs gets confused if we do something similar for that. --- bin/emacsclient | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'bin/emacsclient') diff --git a/bin/emacsclient b/bin/emacsclient index 2c1dcc41..d7a0d9b2 100755 --- a/bin/emacsclient +++ b/bin/emacsclient @@ -67,7 +67,7 @@ pass_to_gdbmacs () { # Only exit non-zero if we were expected to start the daemon. ! $may_start; exit else - exec "$installed_emacsclient" -sgdbmacs "$@" 3>&- 4>&- + exec -a emacsclient "$installed_emacsclient" -sgdbmacs "$@" 3>&- 4>&- fi } @@ -105,7 +105,8 @@ installed_emacsclient=$(PATH=$(echo "$PATH" \ | sed -e "s#$HOME/src/dotfiles/bin:##") \ command -v emacsclient) -command -v ss >/dev/null || exec "$installed_emacsclient" -a "" "$@" +command -v ss >/dev/null \ + || exec -a emacsclient "$installed_emacsclient" -a "" "$@" # We set and export XDG_RUNTIME_DIR such that Emacs doesn't choose # "/tmp/emacs$(id -u)" as the socket dir. @@ -140,13 +141,13 @@ if [ -z "$daemon_name" ] && $devel_running && $want_installed; then # Detach gdb so that Emacs can handle the SIGTERM. We also have to quit # gdb so that `spw/gdbmacs-attach' doesn't look at `gdb-inferior-status'. [ -n "${gdbmacs:=$(get_listener ${socket_dir}gdbmacs)}" ] \ - && "$installed_emacsclient" -sgdbmacs \ - --eval '(gdb-wait-for-pending - (lambda () - (gud-basic-call "detach") - (gdb-wait-for-pending - (lambda () - (gud-basic-call "quit")))))' + && ( exec -a emacsclient "$installed_emacsclient" -sgdbmacs \ + --eval '(gdb-wait-for-pending + (lambda () + (gud-basic-call "detach") + (gdb-wait-for-pending + (lambda () + (gud-basic-call "quit")))))' ) wait $inotifywait listener= @@ -178,22 +179,22 @@ if [ "$branch" = "$(hostname -s)" ] \ && ! ( ! $devel_running && [ -n "$make" ] \ && echo "$make" | xargs pwdx \ | grep -q "$HOME/src/emacs" ); then - emacs="$devel_emacs" - emacsclient="$devel_emacsclient" + emacs=("$devel_emacs") + emacsclient=("$devel_emacsclient") if [ -z "$daemon_name" ] && ! $want_version; then spw_flock 4 gdbmacs [ -n "${gdbmacs:=$(get_listener ${socket_dir}gdbmacs)}" ] \ - && gud_status=$("$installed_emacsclient" \ - -sgdbmacs \ - --eval \ - '(and (boundp '"'"'gud-comint-buffer) - (get-buffer-process gud-comint-buffer) - (string= "signal-received" - gdb-inferior-status))') + && gud_status=$(exec -a emacsclient "$installed_emacsclient" \ + -sgdbmacs \ + --eval \ + '(and (boundp '"'"'gud-comint-buffer) + (get-buffer-process gud-comint-buffer) + (string= "signal-received" + gdb-inferior-status))') fi else - emacs="$installed_emacs" - emacsclient="$installed_emacsclient" + emacs=(-a emacs "$installed_emacs") + emacsclient=(-a emacsclient "$installed_emacsclient") fi # Except in the case above where ss(1) is not available, this wrapper script @@ -208,22 +209,22 @@ if [ "$gud_status" = t ]; then # probably C-i e or editing a file via EDITOR. pass_to_gdbmacs "$@" elif [ -z "$listener" ] && ! $want_version; then - if [ -z "$daemon_name" -a "$emacs" = "$devel_emacs" ]; then + if [ -z "$daemon_name" -a "${emacs[0]}" = "$devel_emacs" ]; then # inotifywait(1) in Debian "bullseye" doesn't have --include. inotifywait -qq -e create "${socket_dir}" \ --exclude "$(egrep_negate ${socket_dir}server)" & inotifywait=$! # If gdbmacs fails to start main session, have gdbmacs handle the # request; again, probably C-i e or editing via EDITOR. - if "$installed_emacsclient" \ - -a '' -sgdbmacs --eval '(spw/gdbmacs-attach)' 3>&- 4>&-; then + if ( exec -a emacsclient "$installed_emacsclient" -a '' -sgdbmacs \ + --eval '(spw/gdbmacs-attach)' 3>&- 4>&- ); then wait $inotifywait else kill $inotifywait pass_to_gdbmacs "$@" fi else - "$emacs" --daemon"${daemon_name:+=$daemon_name}" 3>&- + ( exec "${emacs[@]}" --daemon"${daemon_name:+=$daemon_name}" 3>&- ) fi elif $want_update && ! $want_version; then # Facility to update a (running) daemon's env for a new login session. @@ -246,8 +247,8 @@ elif $want_update && ! $want_version; then fi done [ -n "$args" ] \ - && "$emacsclient" -s"${daemon_name:-server}" \ - --eval "(spw/update-environment$args))" + && ( exec "${emacsclient[@]}" -s"${daemon_name:-server}" \ + --eval "(spw/update-environment$args))" ) fi # emacsclient(1) requires argument(s) beyond just -s/--socket-name. @@ -258,4 +259,4 @@ fi # Note that if the daemon *was* already running and the only argument was # -s/--socket-name, we do exec emacsclient(1) and it'll immediately exit. [ "$#" -eq "$min_arg" ] && ( $want_update || [ -z "$listener" ] ) \ - || exec "$emacsclient" "$@" 3>&- 4>&- + || exec "${emacsclient[@]}" "$@" 3>&- 4>&- -- cgit v1.2.3