chiark / gitweb /
el/dot-emacs.el: Abstract out the frame column-width logic.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 9 Mar 2018 00:14:49 +0000 (00:14 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 9 Mar 2018 00:16:54 +0000 (00:16 +0000)
Now shared between `mdw-divvy-window' and `mdw-set-frame-width'.

el/dot-emacs.el

index d99134d7a9868e03128706d83c9af1a485c7f423..24d076d2e05477c4c1fb5ccd08e9eaf33fa20a6e 100644 (file)
@@ -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))