From b4adeea21740d94cab6e0061aabf22c4ee151618 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 28 Oct 2022 23:22:22 -0700 Subject: replace emacs.git workstation integration commit Also attempt to improve readability & commenting in wrapper script. Archival copy of the workstation integration commit we're replacing: Date: Sat, 25 Dec 2021 18:05:21 -0700 Subject: Workstation integration of personal development builds branch --- admin/flagfile.melete | 0 lib-src/emacsclient.c | 7 +++++-- lisp/emacs-lisp/package.el | 1 + lisp/startup.el | 7 ++++++- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 admin/flagfile.melete diff --git a/admin/flagfile.melete b/admin/flagfile.melete new file mode 100644 index 00000000000..e69de29bb2d diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 425db8cface..62d71559d3c 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -1794,7 +1794,10 @@ start_daemon_and_retry_set_socket (void) } else { - char emacs[] = "emacs"; + const char *devel_build_rel = "/src/emacs/src/emacs"; + char *emacs = xmalloc (strlen (egetenv ("HOME")) + + strlen (devel_build_rel) + 1); + strcpy ( stpcpy (emacs, egetenv ("HOME")), devel_build_rel); char daemon_option[] = "--daemon"; char *d_argv[3]; d_argv[0] = emacs; @@ -1811,7 +1814,7 @@ start_daemon_and_retry_set_socket (void) d_argv[1] = daemon_arg; } # endif - execvp ("emacs", d_argv); + execvp (emacs, d_argv); message (true, "%s: error starting emacs daemon\n", progname); exit (EXIT_FAILURE); } diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index d619142d64c..d464e120193 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -312,6 +312,7 @@ package-directory-list (and (stringp f) (equal (file-name-nondirectory f) "site-lisp") (push (expand-file-name "elpa" f) result))) + (push "/usr/share/emacs-snapshot/site-lisp/elpa" result) (nreverse result)) "List of additional directories containing Emacs Lisp packages. Each directory name should be absolute. diff --git a/lisp/startup.el b/lisp/startup.el index 725984b815b..e10d854c368 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -1452,7 +1452,12 @@ command-line ;; be loaded from site-run-file and wants to test if -q was given ;; should check init-file-user instead, since that is already set. ;; See cus-edit.el for an example. - (if site-run-file + (when site-run-file + (let ((file "/etc/emacs/site-start.d/00debian.el")) + ;; When the Emacs build invokes Emacs, such as in the + ;; Makefile rule for ${unidir}/emoji-labels.el, 00debian.el + ;; might not exist. Should be fine to just skip the load. + (when (file-readable-p file) (load file))) ;; Sites should not disable the startup screen. ;; Only individuals should disable the startup screen. (let ((inhibit-startup-screen inhibit-startup-screen)) --- bin/emacsclient | 179 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 89 insertions(+), 90 deletions(-) (limited to 'bin/emacsclient') diff --git a/bin/emacsclient b/bin/emacsclient index b4a2238b..1ac1b993 100755 --- a/bin/emacsclient +++ b/bin/emacsclient @@ -28,8 +28,9 @@ want_eval=false want_version=false devel_running=false installed_running=false -pass_to_gdbmacs=false -status= +make= +branch= +gud_status= daemon_name= gdbmacs= args= @@ -64,10 +65,14 @@ spw_flock () { fi } -die_wedged () { - maybe_notify "in-tree Emacs appears to be wedged" - # Only exit non-zero if we were expected to start the daemon. - ! $may_start; exit +pass_to_gdbmacs () { + if $want_eval || $want_update; then + maybe_notify "in-tree Emacs appears to be wedged" + # Only exit non-zero if we were expected to start the daemon. + ! $may_start; exit + else + exec "$installed_emacsclient" -sgdbmacs "$@" 3>&- 4>&- + fi } egrep_negate () { @@ -115,7 +120,8 @@ if [ -n "$listener" ]; then esac fi -# ---- Special case for primary session that's always under gdb +# Make it possible, with primary session, to quickly replace in-tree Emacs +# with installed Emacs. See 'C-i E' Sway/i3 binding. if [ -z "$daemon_name" ] && $devel_running && $want_installed; then inotifywait -qq -e delete "$socket" & inotifywait=$! @@ -133,88 +139,90 @@ if [ -z "$daemon_name" ] && $devel_running && $want_installed; then (gud-basic-call "quit")))))' wait $inotifywait + listener= devel_running=false fi -# ---- End special case for primary session that's always under gdb [ -z "$listener" ] && ! $may_start && ! $want_version && 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. +# We start up an in-tree Emacs daemon only when a branch named after this host +# is checked out, packages compiled against my emacs-snapshot Debian packages +# are available, and there isn't a build still in progress -- avoids having to +# consider whether a build is in progress when hitting 'C-i e'. +# +# The purpose of a branch for localhost is to keep track of what upstream +# commit we want to be running on this host (e.g. emacs-29 vs. master), and +# for WIP commits. It doesn't usually need to be pushed anywhere. +# +# We also examine $installed_running here to avoid having the in-tree +# emacsclient(1) connect to the installed Emacs. + 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 2>/dev/null \ - | grep -q "$HOME/src/emacs" ); then + && [ -x "$HOME/src/emacs/lib-src/emacsclient" \ + -a -d "/usr/share/emacs-snapshot/site-lisp/elpa" ]; then + make="$(ps h -o pid -C make)" + branch="$(git -C $HOME/src/emacs rev-parse --abbrev-ref HEAD)" +fi + +if [ "$branch" = "$(hostname -s)" ] \ + && ! ( ! $devel_running && [ -n "$make" ] \ + && echo "$make" | xargs pwdx \ + | grep -q "$HOME/src/emacs" ); then emacs="$devel_emacs" emacsclient="$devel_emacsclient" - - # ---- Two special cases for primary session that's always under gdb if [ -z "$daemon_name" ] && ! $want_version; then spw_flock 4 gdbmacs - # If devel Emacs is stopped or gdbmacs can't start it, ask gdbmacs to - # handle the request: it's probs. C-i e or editing a file via EDITOR. - [ -n "${gdbmacs:=$(get_listener ${socket_dir}gdbmacs)}" ] \ - && status=$("$installed_emacsclient" \ - -sgdbmacs \ - --eval \ - '(and (boundp '"'"'gud-comint-buffer) - (get-buffer-process gud-comint-buffer) - (string= "signal-received" - gdb-inferior-status))') - - if [ "$status" = t ]; then - if $want_eval || $want_update; then - die_wedged - else - pass_to_gdbmacs=true - fi - elif [ -z "$listener" ]; then - # inotifywait(1) in Debian "bullseye" doesn't have --include. - inotifywait -qq -e create "${socket_dir}" \ - --exclude "$(egrep_negate ${socket_dir}server)" & - inotifywait=$! - - if "$installed_emacsclient" \ - -a '' -sgdbmacs \ - --eval '(spw/gdbmacs-attach)' 3>&- 4>&-; then - wait $inotifywait - listener=true - elif $want_eval || $want_update; then - kill $inotifywait - die_wedged - else - kill $inotifywait - pass_to_gdbmacs=true - fi - fi - - if $pass_to_gdbmacs; then - emacs="$installed_emacs" - emacsclient="$installed_emacsclient" - socket="${socket_dir}gdbmacs" - listener="$gdbmacs" - set -- "$@" -sgdbmacs - fi - exec 4>&- + && gud_status=$("$installed_emacsclient" \ + -sgdbmacs \ + --eval \ + '(and (boundp '"'"'gud-comint-buffer) + (get-buffer-process gud-comint-buffer) + (string= "signal-received" + gdb-inferior-status))') fi - # ---- End two special cases for primary session that's always under gdb else emacs="$installed_emacs" emacsclient="$installed_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 $want_update && [ -n "$listener" ]; then +# Except in the case above where ss(1) is not available, this wrapper script +# is responsible for starting up the daemon if it's not running. This is to +# ensure that only the in-tree emacsclient(1) talks to the in-tree Emacs, and +# only the installed emacsclient(1) talks to the installed Emacs. (We used to +# patch the in-tree emacsclient.c to only execute the in-tree Emacs, instead +# of handling it here.) + +if [ "$gud_status" = t ]; then + # Primary session is stopped. Ask gdbmacs to handle the request: it's + # 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 + # 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 + wait $inotifywait + else + kill $inotifywait + pass_to_gdbmacs "$@" + fi + else + "$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. + # 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. + # + # --spw/update-environment may be combined with a regular request or be + # the only thing asked of this script. for var in DISPLAY WAYLAND_DISPLAY \ XAUTHORITY WINDOWID \ XDG_SESSION_TYPE XDG_CURRENT_DESKTOP \ @@ -232,21 +240,12 @@ if $want_update && [ -n "$listener" ]; then --eval "(spw/update-environment$args))" fi -maybe_hold_lock () { - # Hold on to the lock until daemon has started up. - $want_version || [ -n "$listener" ] \ - || inotifywait -qq -e create "${socket_dir}" \ - --exclude "$(egrep_negate $socket)" & -} - -# emacsclient(1) requires an argument. As a special case, if there are no -# arguments except -s/--socket-name, 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 "$min_arg" -a -z "$listener" ]; then - maybe_hold_lock - exec "$emacs" --daemon"${daemon_name:+=$daemon_name}" 3>&- -elif ! ( [ "$#" -eq "$min_arg" ] && $want_update ); then - maybe_hold_lock - exec "$emacsclient" -a "" "$@" 3>&- -fi +# emacsclient(1) requires argument(s) beyond just -s/--socket-name. +# However, in the absence of any such arguments, if the daemon wasn't already +# running, or if --spw/update-environment, this wrapper starts the daemon if +# it wasn't already running, and exits zero. +# +# 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>&- -- cgit v1.2.3