87 lines
3.3 KiB
EmacsLisp
87 lines
3.3 KiB
EmacsLisp
;;; gpolonkai/windows.el --- Window manipulation
|
|
;;;
|
|
;;; SPDX-License-Identifier: GPL-3.0-or-later
|
|
;;; Copyright © 2025 Gergely Polonkai
|
|
;;; This library is free software; you can redistribute it and/or
|
|
;;; modify it under the terms of the GNU Lesser General Public
|
|
;;; License as published by the Free Software Foundation; either
|
|
;;; version 3 of the License, or (at your option) any later version.
|
|
;;;
|
|
;;; This library 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
|
|
;;; Lesser General Public License for more details.
|
|
;;;
|
|
;;; You should have received a copy of the GNU Lesser General Public
|
|
;;; License along with this library; if not, write to the
|
|
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
;;; Boston, MA 02111-1307, USA.
|
|
;;;
|
|
;;; Commentary:
|
|
;;;
|
|
;;; Utility functions stolen from the Internet or written by me
|
|
;;;
|
|
;;; Code:
|
|
|
|
(defun gpolonkai/bury-window (window)
|
|
"Quit WINDOW without killing it (effectively burying it under other windows)."
|
|
(interactive)
|
|
(quit-window nil window))
|
|
|
|
(defun gpolonkai/scroll-window-up (window)
|
|
"Scroll WINDOW up as `scroll-up-command' would."
|
|
(interactive)
|
|
(save-selected-window
|
|
(select-window window)
|
|
(scroll-up)))
|
|
|
|
(defun gpolonkai/scroll-window-down (window)
|
|
"Scroll WINDOW down as `scroll-down-command' would."
|
|
(interactive)
|
|
(save-selected-window
|
|
(select-window window)
|
|
(scroll-down)))
|
|
|
|
(defun gpolonkai/transpose-windows (arg)
|
|
"Transpose the buffers shown in two windows."
|
|
(interactive "p")
|
|
(let ((selector (if (>= arg 0) 'next-window 'previous-window)))
|
|
(while (/= arg 0)
|
|
(let ((this-win (window-buffer))
|
|
(next-win (window-buffer (funcall selector))))
|
|
(set-window-buffer (selected-window) next-win)
|
|
(set-window-buffer (funcall selector) this-win)
|
|
(select-window (funcall selector)))
|
|
(setq arg (if (plusp arg) (1- arg) (1+ arg))))))
|
|
|
|
(defun gpolonkai/toggle-window-split ()
|
|
"Toggle window split between horizontal and vertical."
|
|
(interactive)
|
|
(if (= (count-windows) 2)
|
|
(let* ((this-win-buffer (window-buffer))
|
|
(next-win-buffer (window-buffer (next-window)))
|
|
(this-win-edges (window-edges (selected-window)))
|
|
(next-win-edges (window-edges (next-window)))
|
|
(this-win-2nd (not (and (<= (car this-win-edges)
|
|
(car next-win-edges))
|
|
(<= (cadr this-win-edges)
|
|
(cadr next-win-edges)))))
|
|
(splitter
|
|
(if (= (car this-win-edges)
|
|
(car (window-edges (next-window))))
|
|
'split-window-horizontally
|
|
'split-window-vertically)))
|
|
(delete-other-windows)
|
|
(let ((first-win (selected-window)))
|
|
(funcall splitter)
|
|
(if this-win-2nd (other-window 1))
|
|
(set-window-buffer (selected-window) this-win-buffer)
|
|
(set-window-buffer (next-window) next-win-buffer)
|
|
(select-window first-win)
|
|
(if this-win-2nd (other-window 1))))
|
|
(error "This works only for two windows!")))
|
|
|
|
(provide 'gpolonkai/windows)
|
|
|
|
;;; windows.el ends here
|