Download
(defvar toggle-one-window-window-configuration nil
"The window configuration use for `toggle-one-window'.")
(defun delete-buffer-and-window (buffer-name)
"Delete buffer and window that special.
Argument BUFFER-NAME the buffer name that will delete."
(interactive)
(if (bufferp (get-buffer buffer-name))
(progn
(delete-buffer-window buffer-name)
(kill-buffer (get-buffer buffer-name)))
(message "Buffer %s is not exist." buffer-name)))
(defun delete-current-buffer-and-window ()
"Delete current buffer and window."
(interactive)
(delete-buffer-and-window (buffer-name)))
(defun delete-buffer-window (buffer-name)
"Delete the window of special buffer.
Argument BUFFER-NAME the buffer name that will delete."
(interactive)
(if (bufferp (get-buffer buffer-name))
(delete-window (get-buffer-window (get-buffer buffer-name)))
(message "Buffer %s is not exist." buffer-name)))
(defun delete-current-buffer-window ()
"Delete the window of current buffer."
(interactive)
(delete-buffer-window (current-buffer)))
(defun select-next-window ()
"Select next window."
(interactive)
(other-window +1))
(defun select-prev-window ()
"Select next window."
(interactive)
(other-window -1))
(defun toggle-one-window ()
"Toggle between window layout and one window."
(interactive)
(if (one-window-p t)
(if toggle-one-window-window-configuration
(progn
(set-window-configuration toggle-one-window-window-configuration)
(setq toggle-one-window-window-configuration nil))
(message "No other windows exist."))
(setq toggle-one-window-window-configuration (current-window-configuration))
(delete-other-windows)))
(defun sticky-window-keep-window-visible ()
"Insure the buffer associated with the current window stays visible.
This is handy for ERC buffers where you would like to see the
conversation while you work in other windows within the frame.
This is intended to be used with `sticky-window-delete-window'."
(interactive)
(set-window-dedicated-p (selected-window) t))
(defun sticky-window-delete-window ()
"This is intended to be a replacement for `delete-window', but
that avoids deleting windows that have been marked as dedicated
with `sticky-window-keep-window-visible'."
(interactive)
(let ((window (selected-window)))
(if (and (not current-prefix-arg) (window-dedicated-p window))
(error "This is a dedicated window. Use C-u prefix on this keybinding to really delete it.")
(set-window-dedicated-p (selected-window) nil)
(delete-window window))))
(defun sticky-window-delete-other-windows ()
"Delete all other windows that are not marked to be visible with `sticky-window-keep-window-visible'."
(interactive)
(mapcar (lambda (window)
(if (not (window-dedicated-p window))
(delete-window window)))
(cdr (window-list))))
(defun delete-other-windows-vertically+ ()
"Delete all windows above or below the current window."
(interactive)
(let ((win (selected-window)))
(save-excursion
(while (condition-case nil (windmove-up) (error nil))
(delete-window)
(select-window win))
(while (condition-case nil (windmove-down) (error nil))
(delete-window)
(select-window win)))))
(defun delete-other-windows-horizontally+ ()
"Delete all windows left or right of the current window."
(interactive)
(let ((win (selected-window)))
(save-excursion
(while (condition-case nil (windmove-left) (error nil))
(delete-window)
(select-window win))
(while (condition-case nil (windmove-right) (error nil))
(delete-window)
(select-window win)))))
(defun another-window ()
"Select the next window or split the current one."
(interactive)
(cond ((one-window-p)
(split-window-vertically)
(other-window 1)
(switch-to-buffer nil))
(t (other-window 1))))
(provide 'window-extension)