From 1ce37c45ba673715250002bb5324ca76e600619a Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 27 Oct 2022 13:58:05 -0700 Subject: try out starting an instance of flock(1) early in kill-emacs-hook --- .emacs.d/init.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index dbe06590..02185e93 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -2342,6 +2342,22 @@ Called by '~/src/dotfiles/bin/emacsclient --spw/update-environment'." (funcall orig-fun))) (advice-add 'comint-stop-subjob :around #'spw/comint-stop-subjob) +;; flock(1) starting daemons named the same as us so that instances of my +;; emacsclient(1) wrapper wait on us completing our exit before trying to +;; start us again. +(defun spw/daemon-lock-self () + (when (and (daemonp) (executable-find "flock") (executable-find "sleep")) + (let ((file + (file-name-concat + (or (getenv "XDG_RUNTIME_DIR") (format "/run/user/%d" (user-uid))) + "spw_emacsclient" + (cl-etypecase (daemonp) (string (daemonp)) (t "server"))))) + (set-process-query-on-exit-flag + (start-process "spw_emacsclient" nil + "flock" "-E" "0" "-n" file "sleep" "infinity") + nil)))) +(add-hook 'kill-emacs-hook #'spw/daemon-lock-self -99) + ;; open a frame on a new workspace with only the relevant dired buffer open, ;; eval this form: (global-set-key "\C-cG" #'spw/grading-advance) ;; and then use C-c G to open the first item (will need C-c f t after just -- cgit v1.2.3