;;; window-utils.el --- Utility functions and config for window management -*- lexical-binding: t -*- ;; This file is not part of GNU Emacs ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; commentary ;;; Code: (setq switch-to-buffer-obey-display-actions t) (defun delete-other-main-windows () "Kill all windows except for side windows." (interactive) (dolist (win (window-list)) (when (and (not (equal (selected-window) win)) (not (window-parameter win 'window-side))) (delete-window win)))) (define-key global-map (kbd "C-x 1") #'delete-other-main-windows) (define-key global-map (kbd "C-S-x 1") #'delete-other-windows) ;; left, top, right, bottom (setq window-sides-slots (if (equal system-type 'android) '(1 1 0 1) '(5 1 5 2))) (add-to-list 'display-buffer-alist `("\\*Help" (display-buffer-in-side-window) (side . ,(if (equal system-type 'android) 'bottom 'right)) (slot . ,(if (equal system-type 'android) 0 4)) (window-height . 0.2))) (add-to-list 'display-buffer-alist `("\\*grep\\*" (display-buffer-in-side-window) (side . bottom) (slot . 1))) (add-to-list 'display-buffer-alist `("\\*Buffer List\\*" (display-buffer-in-side-window) (side . bottom) (slot . 1))) (defun mark-side-window-as-no-other (orig-fun &rest args) "Set `no-other-window' to t for any window being displayed as a side window." (let ((window (apply orig-fun args))) (when (window-live-p window) (set-window-parameter window 'no-other-window t)) window)) (advice-add 'display-buffer-in-side-window :around #'mark-side-window-as-no-other) (setq windmove-allow-all-windows t) (provide 'window-utils) ;;; window-utils.el ends here