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 /.emacs.d | |
parent | 124632f7aca4beaca62ab10c711be3b1c65b851d (diff) | |
download | dotfiles-ab1dbe94462d611ce482d3d52ddd4262bdd69228.tar.gz |
gdbmacs instance, s.t. can always run Emacs under gdb, and for Gnus
Diffstat (limited to '.emacs.d')
-rw-r--r-- | .emacs.d/eshell/profile | 6 | ||||
-rw-r--r-- | .emacs.d/init.el | 58 |
2 files changed, 53 insertions, 11 deletions
diff --git a/.emacs.d/eshell/profile b/.emacs.d/eshell/profile index 59099604..42eb0e8a 100644 --- a/.emacs.d/eshell/profile +++ b/.emacs.d/eshell/profile @@ -1,7 +1,7 @@ # for processes spawned by Eshell, drop the -c/-t set in ~/.shenv, so that the -# Emacs frame containing Eshell gets reused -export EDITOR=emacsclient -export VISUAL=emacsclient +# Emacs frame containing Eshell gets reused, and pass -s if necessary +export EDITOR="emacsclient$(if (stringp (daemonp)) (concat \" -s\" (daemonp)) \"\")" +export VISUAL="$EDITOR" # debconf will fall back to this frontend but emit a warning; set it ourselves # to avoid that warning diff --git a/.emacs.d/init.el b/.emacs.d/init.el index c85c779e..559ed09f 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -77,7 +77,10 @@ ;; we're probably a shortlived instance of Emacs just to test something. ;; Set a different background colour to more easily distinguish frames ;; belonging to shortlived instances from those belonging to main instance. - `(,ws . ((background-color . ,(if (daemonp) "#FFFFF6" "alice blue")))))) + `(,ws + . ((background-color + . ,(pcase (daemonp) + ('nil "alice blue") ("gdbmacs" "honeydew") (_ "#FFFFF6"))))))) (defun spw/maybe-scale-basic-faces (frame) "Entry for `window-size-change-functions' to increase font sizes @@ -2233,6 +2236,43 @@ Called by '~/src/dotfiles/bin/emacsclient --spw/update-environment'." (let ((slime-dispatching-connection connection)) (slime-eval cl-form)))))) +(defvar-local spw/gdbmacs-target-emacs nil) + +(defun spw/gdbmacs-attach (pid) + (interactive "nEmacs PID: ") + (when-let ((proc (and (boundp 'gud-comint-buffer) + (get-buffer-process gud-comint-buffer)))) + (if (string= gdb-inferior-status "signal-received") + ;; Avoid wiping out useful info. + (error "Possibly Emacs just crashed; not attaching for now") + (set-process-query-on-exit-flag proc nil) + (kill-buffer gud-comint-buffer))) + (require 'gdb-mi) + (let ((default-directory (expand-file-name "~/src/emacs/"))) + (gdb-reset) + (gdb (format "gdb -i=mi --pid=%d src/emacs" pid)) + (setq spw/gdbmacs-target-emacs pid) + (gud-basic-call "continue"))) + +(defun spw/remote-gdbmacs-attach () + (interactive) + (call-process "emacsclient" nil "*gdbmacs-emacsclient*" nil + "--socket-name=gdbmacs" "--spw/installed" + "-e" (prin1-to-string `(spw/gdbmacs-attach ,(emacs-pid))))) + +(defun spw/maybe-remote-gdbmacs-attach () + (when (and (eq (daemonp) t) + (file-in-directory-p invocation-directory "~/src/emacs/")) + (spw/remote-gdbmacs-attach))) +(add-hook 'after-init-hook #'spw/maybe-remote-gdbmacs-attach) + +;; C-c C-z to attempt to return control to the debugger. +(defun spw/comint-stop-subjob (orig-fun) + (if spw/gdbmacs-target-emacs + (signal-process spw/gdbmacs-target-emacs 'SIGTSTP) + (funcall orig-fun))) +(advice-add 'comint-stop-subjob :around #'spw/comint-stop-subjob) + ;; 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 @@ -2678,13 +2718,15 @@ mutt's review view, after exiting EDITOR." (defvar gnus-always-read-dribble-file) (defun spw/gnus-startup-wrapper (orig-fun &rest args) - (if (and (daemonp) (file-directory-p "~/.fmail/") - (not (file-exists-p "~/.newsrc.eld"))) - (user-error "Must use dedicated Emacs for Gnus first run") - (let ((gc-cons-percentage 0.6) - (gc-cons-threshold 402653184) - (gnus-always-read-dribble-file (file-exists-p "~/.newsrc.eld"))) - (apply orig-fun args)))) + (when-let ((daemon (and (file-directory-p "~/.fmail/") (daemonp)))) + (unless (file-exists-p "~/.newsrc.eld") + (user-error "Must use dedicated Emacs for Gnus first run")) + (unless (string= "gdbmacs" daemon) + (user-error "This is not the Gnusmacs you're looking for"))) + (let ((gc-cons-percentage 0.6) + (gc-cons-threshold 402653184) + (gnus-always-read-dribble-file (file-exists-p "~/.newsrc.eld"))) + (apply orig-fun args))) (advice-add 'gnus :around #'spw/gnus-startup-wrapper) (advice-add 'gnus-no-server :around #'spw/gnus-startup-wrapper) |