diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2022-09-26 10:55:22 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-09-30 22:34:04 -0700 |
commit | ab1dbe94462d611ce482d3d52ddd4262bdd69228 (patch) | |
tree | fb4307f62870cb235ccea11e7efd7a08e491b099 /bin | |
parent | 124632f7aca4beaca62ab10c711be3b1c65b851d (diff) | |
download | dotfiles-ab1dbe94462d611ce482d3d52ddd4262bdd69228.tar.gz |
gdbmacs instance, s.t. can always run Emacs under gdb, and for Gnus
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/doccheckin | 6 | ||||
-rwxr-xr-x | bin/emacsclient | 35 |
2 files changed, 31 insertions, 10 deletions
diff --git a/bin/doccheckin b/bin/doccheckin index 92afe12b..b7a1eb35 100755 --- a/bin/doccheckin +++ b/bin/doccheckin @@ -7,8 +7,10 @@ cd ~/doc/ # also want to use it as the myrepos autoci action for ~/doc/. # If emacs is running, try to save all ~/doc/ buffers. -[ -n "$LOGNAME" ] && pgrep -u "$LOGNAME" emacs >/dev/null \ - && emacsclient --eval '(spw/save-my-doc-buffers)' +if [ -n "$LOGNAME" ] && pgrep -u "$LOGNAME" emacs >/dev/null; then + emacsclient --eval '(spw/save-my-doc-buffers)' + emacsclient -sgdbmacs --spw/no-start --eval '(spw/save-my-doc-buffers)' +fi # don't do anything if waiting on a manual merge; don't want just # blanket commit that merge 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 |