From: Mark Wooding Date: Thu, 13 May 2010 13:45:18 +0000 (+0100) Subject: dot/emacs, el/dot-emacs.el: Fix `split-window-horizontally'. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/3ba0b7778354b6be6c7889b48a86874c48ae9ac9?ds=inline;hp=--cc dot/emacs, el/dot-emacs.el: Fix `split-window-horizontally'. 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. --- 3ba0b7778354b6be6c7889b48a86874c48ae9ac9 diff --git a/dot/emacs b/dot/emacs index 729c6f7..3dc2377 100644 --- a/dot/emacs +++ b/dot/emacs @@ -443,6 +443,7 @@ (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) diff --git a/el/dot-emacs.el b/el/dot-emacs.el index dc4b041..08cc3de 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -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)