X-Git-Url: https://git.distorted.org.uk/~mdw/profile/blobdiff_plain/6ada84f4e0acb4149b95b02ab35ec7a3f73ac1c8..183e55e2d8a6203d14cefbe6b55ee4bc66628525:/el/dot-emacs.el diff --git a/el/dot-emacs.el b/el/dot-emacs.el index bc512b4..8b4f8f8 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -287,6 +287,59 @@ This is sadly necessary because Emacs 26 is broken in this regard." (set-frame-parameter frame 'background-color (car colour)) (set-frame-parameter frame 'foreground-color (cdr colour))) +;; Window configuration switching. + +(defvar mdw-current-window-configuration nil + "The current window configuration register name, or `nil'.") + +(defun mdw-switch-window-configuration (register &optional no-save) + "Switch make REGISTER be the new current window configuration. +If a current window configuration register is established, and +NO-SAVE is nil, then save the current window configuration to +that register first. + +Signal an error if the new register contains something other than +a window configuration. If the register is unset then save the +current window configuration to it immediately. + +With one or three C-u, or an odd numeric prefix argument, set +NO-SAVE, so the previous window configuration register is left +unchanged. + +With two or three C-u, or a prefix argument which is an odd +multiple of 2, just clear the record of the current window +configuration register, so that the next switch doesn't save the +prevailing configuration." + (interactive + (let ((arg current-prefix-arg)) + (list (if (or (and (consp arg) (= (car arg) 16) (= (car arg) 64)) + (and (integerp arg) (not (zerop (logand arg 2))))) + nil + (register-read-with-preview "Switch to window configuration: ")) + (or (and (consp arg) (= (car arg) 4) (= (car arg) 64)) + (and (integerp arg) (not (zerop (logand arg 1)))))))) + + (let ((current-windows (list (current-window-configuration) + (point-marker))) + (register-value (and register (get-register register)))) + (when (and mdw-current-window-configuration (not no-save)) + (set-register mdw-current-window-configuration current-windows)) + (cond ((null register) + (setq mdw-current-window-configuration nil)) + ((not (or (null register-value) + (and (consp register-value) + (window-configuration-p (car register-value)) + (integer-or-marker-p (cadr register-value)) + (null (caddr register-value))))) + (error "Register `%c' is not a window configuration" register)) + (t + (cond ((null register-value) + (set-register register current-windows)) + (t + (set-window-configuration (car register-value)) + (goto-char (cadr register-value)))) + (setq mdw-current-window-configuration register))))) + ;; Don't raise windows unless I say so. (defcustom mdw-inhibit-raise-frame nil