;; Single Window Mode: I don't know the original author of this. It was ;; better than the standard toggle-single-window-mode when I found it, ;; and I've made a few improvements. ;; my changes: ;; 1) keep a list of windows that got iconified when you went to ;; single window mode, and only restore those when leaving ;; single-window-mode. ;; 2) really only allow one window -- when a new non-ignored window shows up, ;; iconify the existing one and add it to the list of windows we're managing. ;; TODO: ;; 1) work properly on multiple workspaces (maintain separate list of ;; iconified windows). Not a high priority, since if you are using ;; single window mode, you are probably not also using workspaces, ;; since they solve basically the same problem. ;; 2) single-window-iconified needs to be made into a stack or something ;; so that single-window-mode-handle-close works right. (defvar single-window-mode-enabled nil) (defvar single-window-iconified nil) (defun single-window-mode-apply (w) "Iconify all normal windows, except for the selected one." (interactive "%W") (delete w single-window-iconified) (map-other-window-groups (lambda (x) (when (and (windows-share-workspace-p w x) (not (window-get x 'ignored)) (not (window-get x 'iconified))) (progn (if (not (member x single-window-iconified)) (setq single-window-iconified (append single-window-iconified (list x)))) (iconify-window x)))) w) ) (defun single-window-mode-maybe-apply (w) "Maybe iconify all normal windows, except for the selected one. Won't do anything if the selected window is a transient." (interactive "%W") (if (not (window-transient-p w)) (single-window-mode-apply w))) (defun single-window-mode-handle-close (w) "If you close a window, that leaves no window on your screen. This uniconifies the next window. Hopefully this will work logically, but at first I doubt it." (interactive "%W") (delete w single-window-iconified) (if (last single-window-iconified) (progn (uniconify-window (last single-window-iconified)) (delete (last single-window-iconified) single-window-iconified)))) (defun single-window-mode-revert (w) "Deiconify all windows, keeping the selected window focused." (interactive "%W") (raise-window-depth w) (map-other-window-groups (lambda (x) (when (and (windows-share-workspace-p w x) (not (window-get x 'ignored))) (if (member x single-window-iconified) (progn (uniconify-window x) (delete x single-window-iconified) )))) w) (lower-window-depth w) (set-input-focus w)) (defun single-window-mode-toggle (w) "Toggle single window mode, keeping the selected window group displayed." (interactive "%W") (if single-window-mode-enabled (progn (remove-hook 'uniconify-window-hook single-window-mode-apply) (remove-hook 'add-window-hook single-window-mode-maybe-apply) (remove-hook 'destroy-notify-hook single-window-mode-handle-close) (single-window-mode-revert w) (setq single-window-mode-enabled nil)) (single-window-mode-apply w) (add-hook 'uniconify-window-hook single-window-mode-apply) (add-hook 'add-window-hook single-window-mode-maybe-apply t) (add-hook 'destroy-notify-hook single-window-mode-handle-close t) (setq single-window-mode-enabled t)))