Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 880 lines (809 sloc) 31.9 KB
;;; switch-window.el --- A *visual* way to switch window -*- lexical-binding: t -*-
;; Copyright (C) 2010-2017 Dimitri Fontaine
;; 2016-2017 Feng Shu
;; Author: Dimitri Fontaine <>
;; Feng Shu <>
;; URL:
;; Git-URL:
;; Version: 1.5.0
;; Created: 2010-04-30
;; Keywords: convenience
;; Licence: WTFPL, grab your copy here:
;; Package-Requires: ((emacs "24"))
;; This file is NOT part of GNU Emacs.
;;; Commentary:
;; * What is switch-window :README:
;; switch-window is an Emacs window switch tool, which offer a
;; *visual* way to choose a window to switch to, delete, split
;; or other operations.
;; [[./snapshots/switch-window.png]]
;; ** Installation
;; 1. Config melpa source, please read:
;; 2. M-x package-install RET switch-window RET
;; Note: User can install switch-window with [[][El-Get]] too.
;; ** Configure and Usage
;; (require 'switch-window)
;; (global-set-key (kbd "C-x o") 'switch-window)
;; (global-set-key (kbd "C-x 1") 'switch-window-then-maximize)
;; (global-set-key (kbd "C-x 2") 'switch-window-then-split-below)
;; (global-set-key (kbd "C-x 3") 'switch-window-then-split-right)
;; (global-set-key (kbd "C-x 0") 'switch-window-then-delete)
;; (global-set-key (kbd "C-x 4 d") 'switch-window-then-dired)
;; (global-set-key (kbd "C-x 4 f") 'switch-window-then-find-file)
;; (global-set-key (kbd "C-x 4 m") 'switch-window-then-compose-mail)
;; (global-set-key (kbd "C-x 4 r") 'switch-window-then-find-file-read-only)
;; (global-set-key (kbd "C-x 4 C-f") 'switch-window-then-find-file)
;; (global-set-key (kbd "C-x 4 C-o") 'switch-window-then-display-buffer)
;; (global-set-key (kbd "C-x 4 0") 'switch-window-then-kill-buffer)
;; When switch-window is enabled, user can use the below five keys:
;; | key | command description |
;; |-----+-----------------------|
;; | "i" | Move the border up |
;; | "k" | Move the border down |
;; | "j" | Move the border left |
;; | "k" | Move the border right |
;; | "b" | Balance windows |
;; |"SPC"| Resume auto-resize |
;; If you want to customize this feature, please see variable:
;; `switch-window-extra-map'.
;; Note: if you use auto-resize window feature, you *must* know
;; that when you execute above window operate commands, auto-resize
;; feature will be disabled temporarily, you should use above "SPC"
;; key to resume.
;; ** Tips
;; *** I want to select a window with "a-z" instead of "1-9".
;; (setq switch-window-shortcut-style 'qwerty)
;; (setq switch-window-qwerty-shortcuts
;; '("a" "s" "d" "f" "j" "k" "l" ";" "w" "e" "i" "o"))
;; *** I want to let window to show bigger label.
;; (setq switch-window-increase 6) ;Increase or decrease this number.
;; *** I want to *hide* window label when window's number < 3
;; (setq switch-window-threshold 2)
;; *** I want to select minibuffer with label "z".
;; (setq switch-window-minibuffer-shortcut ?z)
;; *** I want to auto resize a window when switch to it
;; (setq switch-window-auto-resize-window t)
;; (setq switch-window-default-window-size 0.8) ;80% of frame size
;; (switch-window-mouse-mode) ;auto resize when switch window with mouse
;; Advanced usage:
;; (setq switch-window-auto-resize-window
;; (lambda ()
;; (equal (buffer-name) "*scratch*"))) ;when return t, run auto switch
;; (setq switch-window-default-window-size '(0.8 . 0.6)) ;80% width and 60% height of frame
;; By the way, you can use package [[][golden-ratio]] also.
;; *** Switch-window seem to conflict with Exwm, how to do?
;; By default, switch-window get user's input with the help
;; of function `read-event', this approach does not work well
;; with [[][Exwm]] (Emacs X window manager),
;; user should set the below variable and use minibuffer
;; to get input instead:
;; (setq switch-window-input-style 'minibuffer)
;; Note: if you use minibuffer to get input, the feature about
;; `switch-window-minibuffer-shortcut' will not work well.
;; *** I use text terminal, but I want *bigger* label.
;; The only choice is using asciiart, which *draw* a bigger label
;; with *small* ascii char.
;; (setq switch-window-shortcut-appearance 'asciiart)
;; [[./snapshots/switch-window-3.png]]
;; *** I want to use image or icon as label.
;; 1. Prepare your label images, rename them to:
;; 1.png ... 9.png, a.png ... z.png.
;; You can use other image types supported by
;; Emacs, please see: `image-types'.
;; 2. Put all above images to directory:
;; `switch-window-image-directory'.
;; 3. Set variable: `switch-window-shortcut-appearance'
;; (setq switch-window-shortcut-appearance 'image)
;; [[./snapshots/switch-window-2.png]]
;; *** `switch-window-shortcut-appearance' can't satisfy my need. how to do?
;; All you should do is hacking you own label buffer function,
;; for example: my-switch-window-label-buffer-function, and set
;; the below variable:
;; (setq switch-window-label-buffer-function
;; 'my-switch-window-label-buffer-function)
;; *** Have any other similar package exist?
;; - [[][ace-window]]
;; ** Changelog
;; *** 1.5.0 - 2017-04-29
;; - Implement commands:
;; 1. switch-window-then-maximize
;; 2. switch-window-then-delete
;; 3. switch-window-then-split-below
;; 4. switch-window-then-split-right
;; 5. switch-window-then-split-horizontally
;; 6. switch-window-then-split-vertically
;; 7. switch-window-then-swap-buffer
;; - Let switch-window work well with Exwm (Emacs X window manager).
;; - User can customize switch-window label's appearance.
;; *** 1.0.0 - 2015-01-14
;; - Please fixme.
;; *** 0.11 - 2013-09-14
;; - restore point to end-of-buffer for windows where it was the case after
;; switching, fixing an anoying bug.
;; *** 0.10 - 2011-06-19
;; - implement M-x delete-other-window (thanks developernotes on github)
;; *** 0.9 - 2010-11-11 - emacs22 called, it wants some support
;; - implement a propertize based hack to support emacs22
;; *** 0.8 - 2010-09-13 - 999
;; - Suport more than 9 windows (with a single key to type)
;; - Use quail-keyboard-layout to choose single key labels for windows
;; *** 0.7 - 2010-08-23 - window-dedicated-p
;; - temporarily unset the window dedicated flag for displaying the
;; numbers, patch from René Kyllingstad <>
;; - fix timeout and RET handling wrt to not changing window selection
;; *** 0.6 - 2010-08-12 - *Minibuf-1*
;; - add support for selecting the minibuffer when it's active
;; - some try at a better horizontal centering
;; - assorted cleanup
;; *** 0.5 - 2010-08-08 - Polishing
;; - dim:switch-window-increase is now a maximum value
;;; Code:
;; * Switch-window's code
(require 'cl-lib)
(require 'quail)
(require 'switch-window-asciiart)
(require 'switch-window-mvborder)
(defgroup switch-window nil
"switch-window customization group"
:group 'convenience)
(defcustom switch-window-increase 12
"How much to increase text size in the window numbering, maximum."
:type 'integer
:group 'switch-window)
(defcustom switch-window-timeout 5
"After this many seconds, cancel the window switching."
:type 'integer
:group 'switch-window)
(defcustom switch-window-threshold 2
"Only active ‘switch-window’ after this many windows open."
:type 'integer
:group 'switch-window)
(defcustom switch-window-relative nil
"Control the ordering of windows, when true this depends on current-window."
:type 'boolean
:group 'switch-window)
(defcustom switch-window-shortcut-style 'quail
"Use either keyboard layout or alphabet shortcut style."
:type '(choice (const :tag "Alphabet" 'alphabet)
(const :tag "Keyboard Layout" 'quail)
(const :tag "Qwerty Homekeys Layout" 'qwerty))
:group 'switch-window)
(defcustom switch-window-qwerty-shortcuts
'("a" "s" "d" "f" "j" "k" "l" ";" "w" "e" "i" "o" "g" "h" "r" "q" "u" "v" "n")
"The list of characters used when ‘switch-window-shortcut-style’ is 'qwerty'."
:type 'list
:group 'switch-window)
(defcustom switch-window-shortcut-appearance 'text
"Switch-window shortcut's appearance."
:type '(choice (const :tag "Show shortcut with text" 'text)
(const :tag "Show shortcut with Ascii art." 'asciiart)
(const :tag "Show shortcut with image." 'image))
:group 'switch-window)
(defcustom switch-window-image-directory (locate-user-emacs-file "switch-window/image")
"Switch-window image directory.
If `switch-window-shortcut-appearance' set to 'image, image file
will be found in this directory."
:type 'directory
:group 'switch-window)
(defcustom switch-window-label-buffer-function
"Switch-window's label buffer function.
This function is used to prepare a temp buffer to diplay
a window's label string, three arguments are required:
1. buffer Label string will be inserted into this buffer.
2. label The window's shortcut string.
3. scale Use to increase or decrease label's size."
:type 'function
:group 'switch-window)
(defcustom switch-window-input-style 'default
"Use `read-event' or `read-from-minibuffer' to get user's input."
:type '(choice (const :tag "Get input by read-event" 'default)
(const :tag "Get input from minibuffer" 'minibuffer))
:group 'switch-window)
(defcustom switch-window-minibuffer-shortcut nil
"Whether to customize the minibuffer shortcut.
Default to no customisation (nil), which will make the minibuffer
take whatever the last short is. If a character is specified
it will always use that key for the minibuffer shortcut.
Note: this feature only works when the value
of `switch-window-input-style' is 'default ."
:type '(choice (const :tag "Off" nil)
(character "m"))
:group 'switch-window)
(defcustom switch-window-auto-resize-window nil
"Auto resize window's size when switch to a window.
1. If its value is t, auto resize the selected window.
2. If its value is a function without arguments,
when the returned value it non-nil, auto resize
the selected window."
:group 'switch-window)
(defcustom switch-window-default-window-size 0.7
"The default auto resize window's size.
1. If its value is nil, disable auto resize feature.
2. If its value is a number (0<x<1), resize selected window to % of frame size.
3. If its value is a number (0<x<1) cons, resize selected window to
car% of frame width and cdr% of frame height."
:group 'switch-window)
(defcustom switch-window-finish-hook nil
"A hook, run when `switch-window--then' is finishd.
Its hook function have no arguments."
:group 'switch-window
:type 'hook)
(defcustom switch-window-preferred 'default
"Prefer default commands or helm/ivy style commands."
:type '(choice (const :tag "Emacs default" 'default)
(const :tag "Helm" 'helm)
(const :tag "Ivy or Counsel" 'ivy))
:group 'switch-window)
(defvar switch-window-preferred-alist
(find-file . helm-find-files)
(switch-to-buffer . helm-mini))
(find-file . counsel-find-files)
(switch-to-buffer . ivy-switch-buffer)))
"The settings of `switch-window-preferred'.")
(defvar switch-window-extra-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "i") 'switch-window-mvborder-up)
(define-key map (kbd "k") 'switch-window-mvborder-down)
(define-key map (kbd "j") 'switch-window-mvborder-left)
(define-key map (kbd "l") 'switch-window-mvborder-right)
(define-key map (kbd "b") 'balance-windows)
(define-key map (kbd "SPC") 'switch-window-resume-auto-resize-window)
"Extra keymap for ‘switch-window’ input.
Note: at the moment, it cannot bind commands, which will
increase or decrease window's number, for example:
`split-window-below' `split-window-right' `maximize'.")
(defcustom switch-window-configuration-change-hook-inhibit nil
"Whether inhibit `window-configuration-change-hook' during ‘switch-window’."
:type 'boolean
:group 'switch-window)
(defvar switch-window--temp-disable-auto-resize nil
"Disable auto resize window feature temporarily.")
;; Fix warn when compile switch-window with emacs-no-x
(defvar image-types)
(defun switch-window--list-keyboard-keys ()
"Return a list of current keyboard layout keys."
(cl-loop with layout = (split-string quail-keyboard-layout "")
for row from 1 to 4
nconc (cl-loop for col from 1 to 10
collect (nth (+ 1 (* 2 col) (* 30 row)) layout))))
(defun switch-window--list-keys ()
"Return a list of keys to use depending on `switch-window-shortcut-style'."
#'(lambda (key)
(or (and switch-window-minibuffer-shortcut
(equal key (char-to-string switch-window-minibuffer-shortcut)))
(lookup-key switch-window-extra-map key)))
(cond ((eq switch-window-shortcut-style 'qwerty)
((eq switch-window-shortcut-style 'alphabet)
(cl-loop for i from 0 to 25
collect (byte-to-string (+ (string-to-char "a") i))))
(t (switch-window--list-keyboard-keys)))))
(defun switch-window--enumerate ()
"Return a list of one-letter strings to label current windows."
(cl-loop for w in (switch-window--list)
for x in (switch-window--list-keys)
collect (if (and switch-window-minibuffer-shortcut
(minibuffer-window-active-p w))
(char-to-string switch-window-minibuffer-shortcut)
(defun switch-window--label (num)
"Return the label to use for a given window NUM."
(nth (- num 1) (switch-window--enumerate)))
(defun switch-window--list (&optional from-current-window)
"List windows for current frame.
It will start at top left unless FROM-CURRENT-WINDOW is not nil"
(if (or from-current-window switch-window-relative)
(window-list nil nil)
(window-list nil nil (frame-first-window))))
(defun switch-window--display-number (win num)
"Prepare a temp buffer to diplay NUM in the window WIN while choosing."
(let* ((label (switch-window--label num))
(buffer (get-buffer-create
(format " *%s: %s*"
label (buffer-name (window-buffer win))))))
(funcall switch-window-label-buffer-function
buffer label switch-window-increase)
(set-window-buffer win buffer)
(defun switch-window--create-label-buffer (buffer label scale)
"The default LABEL BUFFER create funcion."
(with-current-buffer buffer
((eq switch-window-shortcut-appearance 'asciiart)
(setq line-spacing nil)
"^\n" ""
(nth (cl-position
(remove "" (split-string "123456789abcdefjhijklmnopqrstuvwxyz" ""))
:test #'equal)
((eq switch-window-shortcut-appearance 'text)
(if (fboundp 'text-scale-increase)
(progn (text-scale-increase scale)
(insert label))
(insert (propertize
label 'face (list :height (* 1.0 scale))))))
((eq switch-window-shortcut-appearance 'image)
(let ((types (cl-copy-seq image-types))
(while types
(let* ((type (pop types))
(file1 (format "%s%s.%S"
(file-name-as-directory switch-window-image-directory)
label type)))
(when (file-exists-p file1)
(setq file file1)
(setq types nil))))
(if (and file (display-images-p))
(insert-image-file (expand-file-name file))
(if (fboundp 'text-scale-increase)
(progn (text-scale-increase scale)
(insert label))
(insert label))))))
(goto-char (point-min))
(defun switch-window--jump-to-window (index)
"Jump to the window depend on INDEX."
(cl-loop for c from 1
for win in (switch-window--list)
until (= c index)
finally (select-window win)))
(defun switch-window--list-eobp ()
"Return a list of all the windows where `eobp' is currently true.
so that we can restore that important property (think
auto scrolling) after switching."
(cl-loop for win in (switch-window--list)
when (with-current-buffer (window-buffer win) (eobp))
collect win))
(defun switch-window--restore-eobp (eobp-window-list)
"For each window in EOBP-WINDOW-LIST move the point to end of buffer."
(cl-loop for win in eobp-window-list
do (let ((buffer (window-buffer win)))
(when buffer
(with-current-buffer buffer
(goto-char (point-max)))))))
(defun switch-window-then-delete ()
"Display an overlay in each window showing a unique key.
In the mean time, user will be asked to choose the window deleted."
"Delete window: "
#'delete-window t))
(defalias 'delete-other-window 'switch-window-then-delete)
(make-obsolete 'delete-other-window 'switch-window-then-delete
"switch-window version 0.2")
(defun switch-window-then-maximize ()
"Display an overlay in each window showing a unique key.
In the mean time, ask user which window to maximize"
"Maximize window: "
#'delete-other-windows t))
(defun switch-window ()
"Display an overlay in each window showing a unique key.
In the mean time, ask user for the window where move to"
"Move to window: "
#'(lambda () (other-window 1))))
(defun switch-window-then-split-horizontally (arg)
"Select a window then split it horizontally.
Argument ARG ."
(interactive "P")
"Horiz-split window: "
#'split-window-horizontally arg 1))
(defun switch-window-then-split-vertically (arg)
"Select a window then split it vertically.
Argument ARG ."
(interactive "P")
"Verti-split window: "
#'split-window-vertically arg 1))
(defun switch-window-then-split-below (arg)
"Select a window then split it with split-window-below's mode.
TODO: Argument ARG."
(interactive "P")
"Below-split window: "
#'split-window-below arg 1))
(defun switch-window-then-split-right (arg)
"Select a window then split it with split-window-right's mode.
TODO: Argument ARG ."
(interactive "P")
"Right-split window: "
#'split-window-right arg 1))
(defun switch-window-then-swap-buffer (arg)
"Select a window then swap it buffer with current window's buffer.
TODO: Argument ARG."
(interactive "P")
(let ((buffer1 (window-buffer))
(window1 (get-buffer-window))
buffer2 window2)
(setq buffer2 (current-buffer))
(setq window2 (get-buffer-window))
(set-window-buffer window2 buffer1)
(set-window-buffer window1 buffer2)
(if arg
(select-window window1)
(select-window window2))))
(defun switch-window-then-find-file ()
"Select a window, then find a file in it.
Designed to replace `find-file-other-window'."
"Find file in window: "
(defun switch-window-then-find-file-read-only ()
"Select a window, then find a file in it, read-only.
Designed to replace `find-file-read-only-other-window'."
"Find file read-only in window: "
(defun switch-window-then-display-buffer ()
"Select a window, display a buffer in it, then return.
Designed to replace `display-buffer'."
(let ((original-window (selected-window)))
"Show buffer in window: "
(select-window original-window)))
(defun switch-window-then-kill-buffer ()
"Select a window, then kill its buffer, then close it.
Designed to replace `kill-buffer-and-window'."
"Window to kill: "
(defun switch-window-then-dired ()
"Select a window, then dired in it.
Designed to replace `dired-other-window'."
"Dired in window: "
(defun switch-window-then-compose-mail ()
"Select a window, then start composing mail in it.
Designed to replace `compose-mail-other-window'."
"Compose mail in window: "
(defun switch-window--get-preferred-function (function)
"Get the preferred FUNCTION based on `switch-window-preferred'."
(or (cdr (assq function
(cdr (assq switch-window-preferred
(defun switch-window--then-other-window (prompt function)
"PROMPT a question and let use select or create a window to run FUNCTION."
(let ((f (switch-window--get-preferred-function function)))
(lambda ()
(if (one-window-p)
(call-interactively f))
(lambda () (call-interactively f))
(defun switch-window--then (prompt function1 &optional function2
return-original-window threshold)
"Prompt a PROMPT, let user switch to a window to do something.
If the number of opened window is less than THRESHOLD,
call FUNCTION1 in current window, otherwise, switch to
the window assocated with the typed key, then call FUNCTION2.
1. FUNCTION1 and FUNCTION2 are functions with no arguments.
2. When RETURN-ORIGINAL-WINDOW is t, switch to original window
after FUNCTION2 is called.
3. When THRESHOLD is not a number, use the value of
‘switch-window-threshold’ instead."
(if (<= (length (window-list))
(if (numberp threshold)
(when (functionp function1)
(funcall function1))
(let ((orig-window (selected-window))
(index (switch-window--prompt prompt))
(eobps (switch-window--list-eobp)))
(switch-window--jump-to-window index)
(when (functionp function2)
(funcall function2))
(when (and return-original-window
(window-live-p orig-window))
(select-window orig-window))
(switch-window--restore-eobp eobps)))
(run-hooks 'switch-window-finish-hook))
(defun switch-window--get-input (prompt-message minibuffer-num eobps)
"Get user's input with the help of `read-event'.
(let (key)
(while (not key)
(let ((input (event-basic-type
(if minibuffer-num
(format "Move to window [minibuffer is %s]: "
(if switch-window-minibuffer-shortcut
(char-to-string switch-window-minibuffer-shortcut)
(switch-window--label minibuffer-num)))
nil switch-window-timeout))))
(if (or (null input) (eq input 'return))
(switch-window--restore-eobp eobps)
(keyboard-quit)) ; timeout or RET
(unless (symbolp input)
(let* ((wchars (mapcar 'string-to-char
(pos (cl-position input wchars))
(lookup-key switch-window-extra-map
(char-to-string input))))
(call-interactively extra-function)
;; Commands in `switch-window-extra-map' mainly are window-resize commands.
;; If we use these commands, theirs effects should not be override by
;; auto-resize feature.
(unless (eq extra-function 'switch-window-resume-auto-resize-window)
(setq switch-window--temp-disable-auto-resize t)))
(pos (setq key (1+ pos)))
(t (switch-window--restore-eobp eobps)
(defun switch-window--get-minibuffer-input (prompt-message minibuffer-num eobps)
"Get user's input with the help of `read-from-minibuffer'.
(let (key)
(while (not key)
(let ((input (read-from-minibuffer
(if minibuffer-num
(format "Move to window [minibuffer is %s]: "
(if switch-window-minibuffer-shortcut
(char-to-string switch-window-minibuffer-shortcut)
(switch-window--label minibuffer-num)))
(let ((map (copy-keymap minibuffer-local-map))
(i ?\ ))
(while (< i 127)
(define-key map (char-to-string i)
(lambda ()
(self-insert-command 1)
(setq i (1+ i)))
(if (< (length input) 1)
(switch-window--restore-eobp eobps)
(let ((pos (cl-position input (switch-window--enumerate)
:test #'equal))
(lookup-key switch-window-extra-map input)))
(call-interactively extra-function)
;; Commands in `switch-window-extra-map' mainly are window resize commands.
;; If we use these commands, theirs effects should not be override by
;; auto-resize feature.
(unless (eq extra-function 'switch-window-resume-auto-resize-window)
(setq switch-window--temp-disable-auto-resize t)))
(pos (setq key (1+ pos)))
(t (switch-window--restore-eobp eobps)))))))
(defun switch-window--prompt (prompt-message)
"Display an overlay in each window showing a unique key.
In the mean time, prompt PROMPT-MESSAGE and let user select
a window"
(let ((window-configuration-change-hook
(unless switch-window-configuration-change-hook-inhibit
(original-cursor (default-value 'cursor-type))
(eobps (switch-window--list-eobp))
(minibuffer-num nil)
(num 1)
key label-buffers
window-buffers window-points dedicated-windows)
;; arrange so that C-g will get back to previous window configuration
;; hide cursor during window selection process
(setq-default cursor-type nil)
;; save window's buffer, point and dedicate state.
;; then display label buffers in all window.
(dolist (win (switch-window--list))
(push (cons win (window-buffer win)) window-buffers)
(push (cons win (window-point win)) window-points)
(when (window-dedicated-p win)
(push (cons win (window-dedicated-p win)) dedicated-windows)
(set-window-dedicated-p win nil))
(if (minibuffer-window-active-p win)
(setq minibuffer-num num)
(push (switch-window--display-number win num) label-buffers))
(setq num (1+ num)))
;; get user's input
(cond ((eq switch-window-input-style 'default)
(setq key (switch-window--get-input
prompt-message minibuffer-num eobps)))
((eq switch-window-input-style 'minibuffer)
(setq key (switch-window--get-minibuffer-input
prompt-message minibuffer-num eobps)))))
;; clean input-method-previous-message
(setq input-method-previous-message nil)
;; restore original cursor
(setq-default cursor-type original-cursor)
;; remove all label-buffers, useless now.
(mapc 'kill-buffer label-buffers)
;; Restore window's buffer, point and dedicate state.
(dolist (w window-buffers)
(set-window-buffer (car w) (cdr w)))
(dolist (w window-points)
(set-window-point (car w) (cdr w)))
(dolist (w dedicated-windows)
(set-window-dedicated-p (car w) (cdr w))))
(define-minor-mode switch-window-mouse-mode
"Enable auto resize window when switch window with mouse."
:global t
:require 'switch-window
(if switch-window-mouse-mode
(add-hook 'mouse-leave-buffer-hook
(remove-hook 'mouse-leave-buffer-hook
(defun switch-window--mouse-auto-resize-window ()
"Auto resize window when switch window with mouse."
(run-at-time 0.1 nil #'switch-window--auto-resize-window))
(defun switch-window-resume-auto-resize-window ()
"Resume auto resize window feature.
It is temporarily disabled by commands in
(setq switch-window--temp-disable-auto-resize nil))
(defun switch-window--auto-resize-window ()
"Auto resize window's size when switch to window."
(when (and (not switch-window--temp-disable-auto-resize)
(if (functionp switch-window-auto-resize-window)
(funcall switch-window-auto-resize-window)
(not (window-minibuffer-p))
(not (one-window-p)))
(let ((arg switch-window-default-window-size)
n1 n2)
(cond ((and (numberp arg) (< 0 arg 1))
(setq n1 arg)
(setq n2 arg))
((and (consp arg)
(numberp (car arg))
(numberp (cdr arg))
(< 0 (car arg) 1)
(< 0 (cdr arg) 1))
(setq n1 (car arg))
(setq n2 (cdr arg)))
(t (setq n1 nil)
(setq n2 nil)
(message "The value of `switch-window-default-window-size' is invalid.")))
(when (and n1 n2)
(with-selected-window (selected-window)
(let ((ncol (floor (- (* (frame-width) n1)
(nrow (floor (- (* (frame-height) n2)
(when (window-resizable-p (selected-window) nrow)
(enlarge-window nrow))
(when (window-resizable-p (selected-window) ncol t)
(enlarge-window ncol t)))))))
(when (and switch-window-auto-resize-window
"Switch-window: resume auto-resize with `\\[switch-window-resume-auto-resize-window]'"))
(message "")))
(provide 'switch-window)
;;; switch-window.el ends here