kkk-windowsize.el 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ;;; kkk-windowsize.el --- Window Size -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2023 Vinicius Teshima <vini.tes@pm.me>
  3. ;; Author: Vinicius Teshima <vini.tes@pm.me>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;; Window Size
  16. ;;; Code:
  17. (defgroup kkk-window nil
  18. "Group for the window group."
  19. :group 'info)
  20. (defcustom kkk-window-size
  21. 80
  22. "Size of window."
  23. :type 'natnum
  24. :group 'kkk-window)
  25. (defun kkk-window-resize (&optional ignored)
  26. "This function change the size of the current window to 80 char wide.
  27. IGNORED is there to be complient with the 'window-state-change-functions' docs."
  28. (interactive)
  29. (let ((win (selected-window)))
  30. (unless (or (frame-root-window-p win) (minibufferp (current-buffer)))
  31. (let* ((width (window-text-width))
  32. (delta (+ 6 (- kkk-window-size width))))
  33. (if (> delta 0)
  34. (enlarge-window-horizontally delta)
  35. (shrink-window-horizontally (* delta -1))
  36. )
  37. )
  38. )
  39. )
  40. )
  41. (add-to-list 'window-state-change-functions #'kkk-window-resize)
  42. (provide 'kkk-windowsize)
  43. ;;; kkk-windowsize.el ends here