dot-emacs: Fix divvy-window for Emacs 21.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 4 Apr 2008 20:15:55 +0000 (21:15 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 4 Apr 2008 20:15:55 +0000 (21:15 +0100)
In Emacs 22 (and since I last looked) fringe-columns has become a
defsubst (i.e., it's inline-expandable), and its expansion refers to
yet another function not available in Emacs 21.  Since I want to use the
byte-compiled result with Emacs 21 too, we engage in some chicanery to
hide the symbol names from the byte compiler.

Also make the interactive version accept a prefix argument controlling
the column width (on the grounds that the feature was already there
anyway, but not for some reason available).

dot-emacs.el

index 5d650cf..efb6eb7 100644 (file)
@@ -111,37 +111,41 @@ path.  The non-nil value is the filename we found for the library."
 
 ;; --- Splitting windows ---
 
-(or (and (fboundp 'scroll-bar-columns)
-        (fboundp 'fringe-columns))
-    (progn
-      (defun scroll-bar-columns (side)
-       (cond ((eq side 'left) 0)
-             (window-system 3)
-             (t 1)))
-      (defun fringe-columns (side)
-       (cond ((not window-system) 0)
-             ((eq side 'left) 1)
-             (t 2)))))
-
-(defun mdw-divvy-window (&optional w)
+(unless (fboundp 'scroll-bar-columns)
+  (defun scroll-bar-columns (side)
+    (cond ((eq side 'left) 0)
+         (window-system 3)
+         (t 1))))
+(unless (fboundp 'fringe-columns)
+  (defun fringe-columns (side)
+    (cond ((not window-system) 0)
+         ((eq side 'left) 1)
+         (t 2))))
+
+(defun mdw-divvy-window (&optional width)
   "Split a wide window into appropriate widths."
-  (interactive)
-  (or w (setq w (if (and window-system
-                        (>= emacs-major-version 22))
-                   77
-                 78)))
+  (interactive "P")
+  (setq width (cond (width (prefix-numeric-value width))
+                   ((and window-system
+                         (>= emacs-major-version 22))
+                    77)
+                   (t 78)))
   (let* ((win (selected-window))
         (sb-width (if (not window-system)
                       1
-                    (+ (scroll-bar-columns 'left)
-                       (scroll-bar-columns 'right)
-                       (fringe-columns 'left)
-                       (fringe-columns 'right))))
+                    (let ((tot 0))
+                      (dolist (what '(scroll-bar fringe))
+                        (dolist (side '(left right))
+                          (incf tot
+                                (funcall (intern (concat (symbol-name what)
+                                                         "-columns"))
+                                         side))))
+                      tot)))
         (c (/ (+ (window-width) sb-width)
-              (+ w sb-width))))
+              (+ width sb-width))))
     (while (> c 1)
       (setq c (1- c))
-      (split-window-horizontally (+ w sb-width))
+      (split-window-horizontally (+ width sb-width))
       (other-window 1))
     (select-window win)))