From a78c835e88316f94544cfaca19fe341b5e7fdb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 16 Oct 2021 21:12:58 +0200 Subject: Emacs: Fix buffer layout bugs --- .emacs.d/init.el | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 15c8a03..26ef5ff 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -147,6 +147,7 @@ ([?\M-f] . [C-right]) ([?\M-b] . [C-left]))) (setq exwm-input-global-keys '(("" . exwm-input-send-next-key))) +(setf (car exwm-input-prefix-keys) ?\C-ยง) (setq exwm-manage-force-tiling t) (exwm-enable) @@ -187,14 +188,18 @@ ;;; Layouts (defvar *buffer-layouts* (list) "Buffer-layout associations") +(defvar *protect-buffer-layouts* nil "Temporarily protect buffer layouts") (defun restore-buffer-layout () "Restore the layout associated with the current buffer." (interactive) (let ((conf (alist-get (current-buffer) *buffer-layouts*))) - (when (not conf) - (error "No layout associated with buffer.")) - (set-window-configuration conf) - (message "Restored buffer layout."))) + (if conf + (progn + (set-window-configuration conf) + (message "Restored buffer layout.")) + (setf (alist-get (current-buffer) *buffer-layouts*) + (current-window-configuration)) + (message "Set buffer layout.")))) (defun switch-to-buffer-with-layout () "Switch to the window layout associated with a buffer. At the same time, associate the original buffer with the original @@ -203,18 +208,25 @@ layout. If the new buffer has no associated layout, it is displayed as the only window in the frame." (interactive) - (dolist (window (window-list)) - (setf (alist-get (window-buffer window) *buffer-layouts*) - (current-window-configuration))) - (call-interactively #'helm-multi-files) - (delete-other-windows) - (let* ((buf (current-buffer)) - (conf (alist-get buf *buffer-layouts*))) - (when conf - (set-window-configuration conf) - (select-window (get-buffer-window buf))))) + (let ((*protect-buffer-layouts* t)) + (dolist (window (window-list)) + (setf (alist-get (window-buffer window) *buffer-layouts*) + (current-window-configuration))) + (call-interactively #'helm-multi-files) + (delete-other-windows) + (let* ((buf (current-buffer)) + (conf (alist-get buf *buffer-layouts*))) + (when conf + (set-window-configuration conf) + (select-window (get-buffer-window buf)))))) +(defun delete-layouts-before-delete-other-windows (&optional window) + (when (not *protect-buffer-layouts*) + (dolist (window (window-list)) + (setf (alist-get (window-buffer window) *buffer-layouts*) nil)))) (defun delete-layout-before-delete-window (window) - (setf (alist-get (window-buffer window) *buffer-layouts*) nil)) + (when (not *protect-buffer-layouts*) + (setf (alist-get (window-buffer window) *buffer-layouts*) nil))) +(advice-add #'delete-other-windows :before #'delete-layouts-before-delete-other-windows) (advice-add #'delete-window :before #'delete-layout-before-delete-window) (advice-add #'quit-window :before #'delete-layout-before-delete-window) (set-keys "C-c b" switch-to-buffer-with-layout -- cgit v1.2.3