chiark / gitweb /
dot/emacs, el/dot-emacs.el: Fix `split-window-horizontally'.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 13 May 2010 13:45:18 +0000 (14:45 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 13 May 2010 13:45:44 +0000 (14:45 +0100)
The standard version takes the space used for fringes and scroll bars
out of the space you request for the left window.  (But, oddly, if you
give a negative width, for the right window, then you get what you asked
for.)  This is annoying, so fix it.

Actually fixing (or even advising) `split-window-horizontally' is too
risky to compatibility, so I've invented a new function
`mdw-split-window-horizontally' which does the job right, and rebound
C-x 3 to use the new version.

dot/emacs
el/dot-emacs.el

index 729c6f73a2af9435a3f5ce5dd3966299808568f9..3dc2377d3d3363c723d05a8e0ac06173d3e82bb0 100644 (file)
--- a/dot/emacs
+++ b/dot/emacs
   (global-set-key [?\C-x ?t ?s] 'timeclock-status-string)
   (global-set-key [?\C-x ?t ?p] 'nc-timesheet-prepare)
   (global-set-key [?\C-x ?t ?\C-m] 'nc-timesheet-submit)
+  (global-set-key [?\C-x ?3] 'mdw-split-window-horizontally)
   (global-set-key [?\M-#] 'calc-dispatch)
   (global-set-key [?\C-x ?/] 'auto-fill-mode)
   (global-set-key [?\C-x ?w ?d] 'mdw-divvy-window)
index dc4b041c73de5762c30fdcf8db974139f8c5324b..08cc3def997fa881c1871d9da1b825cbb76436b6 100644 (file)
@@ -137,6 +137,33 @@   (defun fringe-columns (side)
          ((eq side 'left) 1)
          (t 2))))
 
+(defun mdw-horizontal-window-overhead ()
+  "Computes the horizontal window overhead.
+This is the number of columns used by fringes, scroll bars and other such
+cruft."
+  (if (not window-system)
+      1
+    (let ((tot 0))
+      (dolist (what '(scroll-bar fringe))
+       (dolist (side '(left right))
+         (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
+                            side))))
+      tot)))
+
+(defun mdw-split-window-horizontally (&optional width)
+  "Split a window horizontally.
+Without a numeric argument, split the window approximately in
+half.  With a numeric argument WIDTH, allocate WIDTH columns to
+the left-hand window (if positive) or -WIDTH columns to the
+right-hand window (if negative).  Space for scroll bars and
+fringes is not taken out of the allowance for WIDTH, unlike
+\\[split-window-horizontally]."
+  (interactive "P")
+  (split-window-horizontally
+   (cond ((null width) nil)
+        ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
+        ((< width 0) width))))
+
 (defun mdw-divvy-window (&optional width)
   "Split a wide window into appropriate widths."
   (interactive "P")
@@ -146,16 +173,7 @@ (defun mdw-divvy-window (&optional width)
                     77)
                    (t 78)))
   (let* ((win (selected-window))
-        (sb-width (if (not window-system)
-                      1
-                    (let ((tot 0))
-                      (dolist (what '(scroll-bar fringe))
-                        (dolist (side '(left right))
-                          (incf tot
-                                (funcall (intern (concat (symbol-name what)
-                                                         "-columns"))
-                                         side))))
-                      tot)))
+        (sb-width (mdw-horizontal-window-overhead))
         (c (/ (+ (window-width) sb-width)
               (+ width sb-width))))
     (while (> c 1)