diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2022-04-15 18:08:51 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-04-15 18:12:39 -0700 |
commit | b45434316738d02ad7b660b0609420cde19aa2a6 (patch) | |
tree | fde01dfa690eb7c74441054a81ba84f159a3ef7a | |
parent | 9dd6d67f0fc6ddf766ab6ac783b10f9cc52eeb87 (diff) | |
download | dotfiles-b45434316738d02ad7b660b0609420cde19aa2a6.tar.gz |
combine s/d/emacsclient & update-emacs-daemon-environment
-rw-r--r-- | .bashrc | 2 | ||||
-rw-r--r-- | .config/i3/config | 20 | ||||
-rw-r--r-- | .config/sway/config | 20 | ||||
-rw-r--r-- | .emacs.d/init.el | 15 | ||||
-rw-r--r-- | .mrconfig.in | 2 | ||||
-rwxr-xr-x | archive/bin/i3-startup-once | 2 | ||||
-rwxr-xr-x | bin/doccheckin | 3 | ||||
-rwxr-xr-x | bin/emacsclient | 94 | ||||
-rwxr-xr-x | bin/update-emacs-daemon-environment | 35 | ||||
-rwxr-xr-x | scripts/desktop/emacsclient | 43 |
10 files changed, 123 insertions, 113 deletions
@@ -75,7 +75,7 @@ upenv () { eval "export $var" done fi - update-emacs-daemon-environment + emacsclient --spw/update-environment } # --- host-specific aliases/functions diff --git a/.config/i3/config b/.config/i3/config index aab9bbac..53c12f57 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -48,21 +48,19 @@ mode "C-i-" { # make a fresh Emacs frame -- typically this gets invoked only on # empty workspaces, as otherwise I use commands under `C-x 5` to get # more Emacs frames - bindsym e exec ~/src/dotfiles/scripts/desktop/emacsclient, mode "default" + bindsym e exec emacsclient -nc, mode "default" # override the script's usual logic to start a fresh, non-debug daemon - bindsym Shift+e \ - exec ~/src/dotfiles/scripts/desktop/emacsclient --installed, \ - mode "default" + bindsym Shift+e exec emacsclient -nc --spw/installed, mode "default" # Fresh Emacs frame and get a shell in HOME. Without this it's # C-i e C-c e h which is too many keys esp. compared to C-i DEL - bindsym Return exec ~/src/dotfiles/scripts/desktop/emacsclient -- -nce \ - "(let ((default-directory (expand-file-name "'"'~/'"'")) \ - (display-buffer-overriding-action \ - '(display-buffer-same-window \ - . ((inhibit-same-window . nil))))) \ - (transient-cycles-cmd-spw/eshell-jump-from-here))", \ + bindsym Return exec emacsclient -- -nce \ + "(let ((default-directory (expand-file-name "'"'~/'"'")) \ + (display-buffer-overriding-action \ + '(display-buffer-same-window \ + . ((inhibit-same-window . nil))))) \ + (transient-cycles-cmd-spw/eshell-jump-from-here))", \ mode "default" # start a terminal emulator @@ -338,7 +336,7 @@ bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume @DEFAULT bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ -10% bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute @DEFAULT_SINK@ toggle -exec --no-startup-id update-emacs-daemon-environment +exec --no-startup-id emacsclient --spw/update-environment exec --no-startup-id xss-lock --transfer-sleep-lock -- \ i3lock --nofork --ignore-empty-password --color=FFFFF6 diff --git a/.config/sway/config b/.config/sway/config index 0c0e29ed..9a0cfd29 100644 --- a/.config/sway/config +++ b/.config/sway/config @@ -33,21 +33,19 @@ mode "C-i-" { # make a fresh Emacs frame -- typically this gets invoked only on # empty workspaces, as otherwise I use commands under `C-x 5` to get # more Emacs frames - bindsym e exec ~/src/dotfiles/scripts/desktop/emacsclient, mode "default" + bindsym e exec emacsclient -nc, mode "default" # override the script's usual logic to start a fresh, non-debug daemon - bindsym Shift+e \ - exec ~/src/dotfiles/scripts/desktop/emacsclient --installed, \ - mode "default" + bindsym Shift+e exec emacsclient -nc --spw/installed, mode "default" # Fresh Emacs frame and get a shell in HOME. Without this it's # C-i e C-c e h which is too many keys esp. compared to C-i DEL - bindsym Return exec ~/src/dotfiles/scripts/desktop/emacsclient -- -nce \ - "(let ((default-directory (expand-file-name "'"'~/'"'")) \ - (display-buffer-overriding-action \ - '(display-buffer-same-window \ - . ((inhibit-same-window . nil))))) \ - (transient-cycles-cmd-spw/eshell-jump-from-here))", \ + bindsym Return exec emacsclient -nce \ + "(let ((default-directory (expand-file-name "'"'~/'"'")) \ + (display-buffer-overriding-action \ + '(display-buffer-same-window \ + . ((inhibit-same-window . nil))))) \ + (transient-cycles-cmd-spw/eshell-jump-from-here))", \ mode "default" # start a terminal emulator @@ -364,7 +362,7 @@ input type:keyboard repeat_delay 380 seat * hide_cursor 5000 exec mako -exec update-emacs-daemon-environment +exec emacsclient --spw/update-environment exec_always fcitx5 -d --replace diff --git a/.emacs.d/init.el b/.emacs.d/init.el index d02145c8..87c72a3e 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -463,10 +463,10 @@ Lisp Interaction C-j in `lisp-interaction-mode' and similar." (let ((mouse-autoselect-window nil)) (apply orig-fun args))) -;; update-emacs-daemon-environment supplies us with I3SOCK, so if we see that -;; variable we know there is at least one frame under i3 or swaywm, and so we -;; want to set `mouse-autoselect-window' and `focus-follows-mouse' to t. As -;; we can't do that frame-locally, once they're set they're set. +;; 'emacsclient --spw/update-environment' supplies us with I3SOCK, so if we +;; see that variable we know there is at least one frame under i3 or swaywm, +;; and so we want to set `mouse-autoselect-window' and `focus-follows-mouse' +;; to t. As we can't do that frame-locally, once they're set they're set. ;; ;; On the other hand, ideally functions like `spw/save-buffer-for-later' ;; decide whether to open a new frame or a new tab frame-locally, so we used @@ -2155,10 +2155,9 @@ Single prefix argument to clear." ;; unimplemented: update values in any Lisp image we may have (defun spw/propagate-new-environment () - "After ~/src/dotfiles/bin/update-emacs-daemon-environment has -updated our environment variables, propagate to subenvironments. - -Called by that script using emacsclient(1)." + "After '~/src/dotfiles/bin/emacsclient --spw/update-environment' +has updated our env vars, propagate to subenvironments. Called +by that script, which see." (dolist (var '("DISPLAY" "WAYLAND_DISPLAY" "SSH_ASKPASS" "SSH_AUTH_SOCK" "SSH_AGENT_PID" "SSH_CONNECTION" diff --git a/.mrconfig.in b/.mrconfig.in index 50cef7bf..7730a9ad 100644 --- a/.mrconfig.in +++ b/.mrconfig.in @@ -477,7 +477,7 @@ skip = lazy # Backported from athena/unstable. Automatically updated by # rebuild-for-athena when updating athena/unstable as described above. # -# See also scripts/desktop/emacsclient in dotfiles.git. +# See also bin/emacsclient wrapper script in dotfiles.git. [src/emacs] checkout = git clone https://git.savannah.gnu.org/git/emacs.git emacs post_clean = ./autogen.sh autoconf diff --git a/archive/bin/i3-startup-once b/archive/bin/i3-startup-once index ce0a3075..8e09ccd0 100755 --- a/archive/bin/i3-startup-once +++ b/archive/bin/i3-startup-once @@ -31,4 +31,4 @@ fi # ---- Emacs daemon -update-emacs-daemon-environment +emacsclient --spw/update-environment diff --git a/bin/doccheckin b/bin/doccheckin index d3cc3880..d492ccef 100755 --- a/bin/doccheckin +++ b/bin/doccheckin @@ -8,8 +8,7 @@ cd ~/doc/ # If emacs is running, try to save all ~/doc/ buffers. [ -n "$LOGNAME" ] && pgrep -u "$LOGNAME" emacs >/dev/null \ - && ~/src/dotfiles/scripts/desktop/emacsclient \ - -- --eval '(spw/save-my-doc-buffers)' + && emacsclient --eval '(spw/save-my-doc-buffers)' # 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 new file mode 100755 index 00000000..91cef0aa --- /dev/null +++ b/bin/emacsclient @@ -0,0 +1,94 @@ +#!/bin/sh + +# Copyright (C) 2022 Sean Whitton +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + + +# emacsclient(1) wrapper to handle updating the environment of existing +# daemons and choosing between installed and in-tree builds of Emacs. + +for arg do + shift + case "$arg" in + '--spw/installed') mode=--spw/installed ;; + '--spw/update-environment') update=true ;; + *) set -- "$@" "$arg" ;; + esac +done + +processes=$(ps -o exe -u "$LOGNAME" -U "$LOGNAME") +echo "$processes" | grep -q "$HOME/src/emacs/src/emacs" && devel_running=true +echo "$processes" | grep -q $(command -v emacs) && installed_running=true + +if [ "$devel_running" = true -a "$mode" = --spw/installed ]; then + pgrep --full "$HOME/src/emacs/src/emacs" | while read pid; do + kill $pid + done + socket="/run/user/$(id -u)/emacs/server" + [ -e $socket ] && inotifywait -qqt 2 -e delete $socket + devel_running=false +fi + +# 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 + emacs="$HOME/src/emacs/src/emacs" + emacsclient="$HOME/src/emacs/lib-src/emacsclient" +else + emacs=$(command -v emacs) + emacsclient=$(PATH=$(echo "$PATH" | sed -e "s#$HOME/src/dotfiles/bin:##") \ + command -v emacsclient) +fi + +# Update Emacs daemon environment vars for a new interactive session. This +# 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 \( "$devel_running" = true \ + -o "$installed_running" = true \) ]; then + for var in DISPLAY WAYLAND_DISPLAY \ + XAUTHORITY WINDOWID \ + XDG_SESSION_TYPE XDG_CURRENT_DESKTOP \ + SWAYSOCK I3SOCK \ + SSH_ASKPASS SSH_CONNECTION \ + SSH_AUTH_SOCK SSH_AGENT_PID; do + eval isset=\${$var+x} + if [ "$isset" = "x" ]; then + eval val=\$$var + args="$args"' (setenv "'$var'" "'$val'")' + fi + done + "$emacsclient" --eval "(progn$args (spw/propagate-new-environment))" +fi + +# emacsclient(1) requires an argument. As a special case, if there are no +# arguments and no daemon is running, just start one. And if there were no +# arguments but we were requested just to update env vars, exit peacefully. +if [ "$#" -eq 0 \ + -a "$devel_running" != true -a "$installed_running" != true ]; then + exec "$emacs" --daemon +elif ! [ "$#" -eq 0 -a "$update" = true ]; then + exec "$emacsclient" -a "" "$@" +fi diff --git a/bin/update-emacs-daemon-environment b/bin/update-emacs-daemon-environment deleted file mode 100755 index 1198fd80..00000000 --- a/bin/update-emacs-daemon-environment +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -# Update Emacs daemon environment vars for a new interactive session. This -# 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. -# -# Note that this will start the Emacs daemon if it not up already. - -which emacsclient >/dev/null || exit 0 - -for var in DISPLAY \ - WAYLAND_DISPLAY \ - SSH_ASKPASS \ - SSH_AUTH_SOCK \ - SSH_AGENT_PID \ - SSH_CONNECTION \ - WINDOWID \ - XAUTHORITY \ - XDG_SESSION_TYPE \ - XDG_CURRENT_DESKTOP \ - SWAYSOCK \ - I3SOCK; do - eval isset=\${$var+x} - if [ "$isset" = "x" ]; then - eval value=\$$var - ~/src/dotfiles/scripts/desktop/emacsclient \ - -- --eval '(setenv "'$var'" "'$value'")' - fi -done - -# finally, also call a function which now updates the values in Eshells and -# our (Common) Lisp image(s) from Emacs' values -~/src/dotfiles/scripts/desktop/emacsclient \ - -- --eval '(spw/propagate-new-environment)' diff --git a/scripts/desktop/emacsclient b/scripts/desktop/emacsclient deleted file mode 100755 index 8360b0e1..00000000 --- a/scripts/desktop/emacsclient +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh - -# We also check whether there is something which looks like the installed -# Emacs running, as we do not want the in-tree emacsclient to try to connect -# to that, and 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. - -getopt=$(getopt -o "" -l installed -n scripts/desktop/emacsclient -- "$@") -eval "set - $getopt" -while true; do - case "$1" in - '--installed') mode="--installed"; shift; continue ;; - '--') shift; break ;; - esac -done -[ "$#" -eq 0 ] && set -- -nc - -processes=$(ps -o exe -u "$LOGNAME" -U "$LOGNAME") -echo "$processes" | grep -q "$HOME/src/emacs/src/emacs" && devel_running=true - -if [ "$devel_running" = true -a "$mode" = --installed ]; then - pgrep --full "$HOME/src/emacs/src/emacs" | while read pid; do - kill $pid - done - socket="/run/user/$(id -u)/emacs/server" - [ -e $socket ] && inotifywait -qqt 2 -e delete $socket -fi - -if [ "$mode" != --installed \ - -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" ] \ - && ! echo "$processes" | grep -q $(command -v emacs) \ - && ! ( [ "$devel_running" != true ] && ps h -o pid -C make \ - | xargs pwdx | grep -q "$HOME/src/emacs" ); then - EMACSCLIENT="$HOME/src/emacs/lib-src/emacsclient" -else - EMACSCLIENT=$(command -v emacsclient) -fi - -exec "$EMACSCLIENT" -a "" "$@" |