summaryrefslogtreecommitdiff
path: root/bin/emacsclient
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-10-21 09:43:41 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-10-29 21:47:37 -0700
commit544f3e9fd18894f0f3b9628011591f272c3ec271 (patch)
tree2af8c92c041e12a2988684627351f670f7b590f8 /bin/emacsclient
parent9d68e5109bfb0a6fa9ebe0be86b9ff36747717dc (diff)
downloaddotfiles-544f3e9fd18894f0f3b9628011591f272c3ec271.tar.gz
emacsclient wrapper: use cleaner booleans
Diffstat (limited to 'bin/emacsclient')
-rwxr-xr-xbin/emacsclient32
1 files changed, 19 insertions, 13 deletions
diff --git a/bin/emacsclient b/bin/emacsclient
index 02755f28..770ef66a 100755
--- a/bin/emacsclient
+++ b/bin/emacsclient
@@ -21,7 +21,13 @@
# daemons and choosing between installed and in-tree builds of Emacs.
min_arg=0
+may_start=true
+want_update=false
+want_installed=false
+devel_running=false
+installed_running=false
socket_dir="/run/user/$(id -u)/emacs/"
+
get_listener () {
local socket="$1"
local listener=$(ss -Hplx src "$socket" \
@@ -37,9 +43,9 @@ get_listener () {
for arg do
shift
case "$arg" in
- '--spw/installed') mode=--spw/installed ;;
- '--spw/no-start') start=false ;;
- '--spw/update-environment') update=true ;;
+ '--spw/installed') want_installed=true ;;
+ '--spw/no-start') may_start=false ;;
+ '--spw/update-environment') want_update=true ;;
'-s'|'--socket-name') min_arg=2; daemon_name="$1" ;;&
'-s'?*) min_arg=1; daemon_name="${arg:2}" ;;&
'--socket-name='?*) min_arg=1; daemon_name="${arg:14}" ;;&
@@ -67,7 +73,7 @@ if [ -n "$listener" ]; then
esac
fi
-if [ "$devel_running" = true -a "$mode" = --spw/installed ]; then
+if [ -z "$daemon_name" ] && $devel_running && $want_installed; then
kill "$listener"
# Detach gdb so that Emacs can handle the SIGTERM.
@@ -81,19 +87,19 @@ if [ "$devel_running" = true -a "$mode" = --spw/installed ]; then
devel_running=false
fi
-[ "$start" = false -a -z "$listener" ] && exit 0
+[ -z "$listener" ] && ! $may_start && 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
# daemon, as we don't want to start a new daemon until the build is finished.
# The idea is that I can always hit C-i e without worrying about builds.
-if [ "$mode" != --spw/installed -a "$installed_running" != true \
- -a -e "$HOME/src/emacs/admin/flagfile.melete" \
- -a -x "$HOME/src/emacs/lib-src/emacsclient" \
- -a -d "/usr/share/emacs-snapshot/site-lisp/elpa" ] \
- && ! ( [ "$devel_running" != true ] && ps h -o pid -C make \
- | xargs pwdx | grep -q "$HOME/src/emacs" ); then
+if ! $want_installed && ! $installed_running \
+ && [ -e "$HOME/src/emacs/admin/flagfile.melete" \
+ -a -x "$HOME/src/emacs/lib-src/emacsclient" \
+ -a -d "/usr/share/emacs-snapshot/site-lisp/elpa" ] \
+ && ! ( ! $devel_running && ps h -o pid -C make \
+ | xargs pwdx | grep -q "$HOME/src/emacs" ); then
emacs="$devel_emacs"
emacsclient="$devel_emacsclient"
else
@@ -105,7 +111,7 @@ fi
# allows us to have the Emacs daemon survive restarts of the graphical desktop
# environment, and to update Emacs on a remote host when there is a new
# forwarded SSH agent socket. See 'upenv' in .bash_defns.
-if [ "$update" = true -a -n "$listener" ]; then
+if $want_update && [ -n "$listener" ]; then
for var in DISPLAY WAYLAND_DISPLAY \
XAUTHORITY WINDOWID \
XDG_SESSION_TYPE XDG_CURRENT_DESKTOP \
@@ -129,6 +135,6 @@ fi
# vars, exit peacefully.
if [ "$#" -eq "$min_arg" -a -z "$listener" ]; then
exec "$emacs" --daemon"${daemon_name:+=$daemon_name}"
-elif ! [ "$#" -eq "$min_arg" -a "$update" = true ]; then
+elif ! ( [ "$#" -eq "$min_arg" ] && $want_update ); then
exec "$emacsclient" -a "" "$@"
fi