From 22e1b8c34780d0ada1387977f00a68b7befd8343 Mon Sep 17 00:00:00 2001 Message-Id: <22e1b8c34780d0ada1387977f00a68b7befd8343.1717767269.git.mdw@distorted.org.uk> From: Mark Wooding Date: Fri, 9 Mar 2018 00:14:49 +0000 Subject: [PATCH] el/dot-emacs.el: Abstract out the frame column-width logic. Organization: Straylight/Edgeware From: Mark Wooding Now shared between `mdw-divvy-window' and `mdw-set-frame-width'. --- el/dot-emacs.el | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/el/dot-emacs.el b/el/dot-emacs.el index d99134d..24d076d 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -200,13 +200,16 @@ (defun mdw-split-window-horizontally (&optional width) ((>= width 0) (+ width (mdw-horizontal-window-overhead))) ((< width 0) width)))) +(defun mdw-preferred-column-width () + "Return the preferred column width." + (if (and window-system (mdw-emacs-version-p 22)) mdw-column-width + (1+ mdw-column-width))) + (defun mdw-divvy-window (&optional width) "Split a wide window into appropriate widths." (interactive "P") - (setq width (cond (width (prefix-numeric-value width)) - ((and window-system (mdw-emacs-version-p 22)) - mdw-column-width) - (t (1+ mdw-column-width)))) + (setq width (if width (prefix-numeric-value width) + (mdw-preferred-column-width))) (let* ((win (selected-window)) (sb-width (mdw-horizontal-window-overhead)) (c (/ (+ (window-width) sb-width) @@ -220,10 +223,8 @@ (defun mdw-divvy-window (&optional width) (defun mdw-set-frame-width (columns &optional width) (interactive "nColumns: P") - (setq width (cond (width (prefix-numeric-value width)) - ((and window-system (mdw-emacs-version-p 22)) - mdw-column-width) - (t (1+ mdw-column-width)))) + (setq width (if width (prefix-numeric-value width) + (mdw-preferred-column-width))) (let ((sb-width (mdw-horizontal-window-overhead))) (set-frame-width (selected-frame) (- (* columns (+ width sb-width)) -- [mdw]