Make Emacs column width configurable.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 12 May 2016 09:22:24 +0000 (10:22 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 12 May 2016 09:27:14 +0000 (10:27 +0100)
This change introduces a new metaconfiguration variable `emacs-width'
which defaults for 77 for the usual historical reasons.  It's used:

  * to set the default `loose' Emacs frame width, in `.Xdefaults', via
    some fiddly C preprocessor hacking;

  * to choose the initial Emacs frame size, in `.xinitrc';

  * to decide how to divvy up windows, refill text, highlight overlong
    lines, and all of that good stuff, in `.emacs' and `dot-emacs.el'.

Emacs itself now has two new variable, `mdw-column-width' which is the
`physical' column width, used to decide how big to make windows and
frames; and `mdw-text-width' which is a potentially buffer-local
variable holding the logical text width in the buffer, used for
refilling text and highlighting long lines.

This is probably not completely right yet, but it seems like a good
start for supporting environments where I'm expected to use a different
column width most of the time.

If `emacs-width' is unset, or left as its default, there should be no
change.

dot/Xdefaults
dot/emacs
dot/xinitrc
el/dot-emacs.el
setup

index 2b200c4..2787e0b 100644 (file)
@@ -71,7 +71,9 @@ XConsole*foreground:          #54ff9f
 XConsole*geometry:             485x455
 
 !! Emacs.
-emacs.geometry:                        77x33
+#define _GEOM(wd, ht) wd##x##ht
+#define GEOM(wd, ht) _GEOM(wd, ht)
+emacs.geometry:                        GEOM(EMACSWD,33)
 Emacs.pane.menubar.font:       NICEFONT
 Emacs.menu*.font:              NICEFONT
 Emacs.font:                    FIXED
index 9bb23b2..677338c 100644 (file)
--- a/dot/emacs
+++ b/dot/emacs
 (setq read-quoted-char-radix 16)       ;C-q HEX-STUFF [RET]
 (setq case-fold-file-names nil)                ;Don't translate file names (grr...)
 (setq scroll-step 5)                   ;Don't scroll too much at a time
-(setq-default fill-column 77)          ;I use rather narrow windows
+(setq-default fill-column mdw-text-width) ;I use rather narrow windows
 (setq-default comment-column 40)       ;Set a standard comment column
 (setq-default truncate-partial-width-windows nil
              truncate-lines t)
 (setq view-read-only t)
 (setq whitespace-style '(trailing empty indentation face lines-tail
                         space-before-tab space-after-tab)
-      whitespace-line-column 77)
+      whitespace-line-column mdw-text-width)
 (setq woman-use-own-frame nil          ;Keep man pages somewhere sensible
       woman-fill-column 72)            ;Right margin position.
 (setq diff-switches "-u"               ;I like reading unified diffs
 
 (setq frame-background-mode (if mdw-black-background 'dark 'light)
       default-frame-alist
-      `((width . ,(if (>= emacs-major-version 21) 77 78))
+      `((width . ,(+ mdw-column-width
+                    (if (>= emacs-major-version 21) 0 1)))
        (height . 33)
        (vertical-scroll-bars . right)
        (cursor-type . bar)
        (cursor-color . "red")
        (background-mode . ,frame-background-mode))
       initial-frame-alist
-      `((width . ,(if (>= emacs-major-version 21) 77 78))
+      `((width . ,(+ mdw-column-width
+                    (if (>= emacs-major-version 21) 0 1)))
        (menu-bar-lines . ,(if window-system 1 0)))
       window-system-default-frame-alist
       '((pm (font . "-os2-System VIO-medium-r-normal--*-40-*-*-m-*-cp850")
index a1f6e06..1710242 100755 (executable)
@@ -233,7 +233,9 @@ term=$(pick_program terminal pterm Eterm xterm)
 ## e_lineht = height of a character line in pixels
 ## e_vextra = number of additional vertical cruft pixels
 ##     So an N-line Emacs frame takes N*e_lineht + e_vextra pixels
-e_colwd=492 e_colchars=82 e_lineht=13
+e_colsz=$(mdw-conf emacs-width 77) e_charwd=6 e_colextra=30
+e_colwd=$(( e_colsz*e_charwd + e_colextra ))
+e_colchars=$(( e_colsz + 5 )) e_lineht=13
 case "$emacs" in
   emacs21 | emacs) e_hextra=34 e_cextra=-2 e_vextra=52 ;;
   emacs22 | emacs23) e_hextra=8 e_cextra=-6 e_vextra=46 ;;
index d883666..950f2db 100644 (file)
@@ -102,6 +102,15 @@ This may be at the expense of cool features.")
                    (concat "(" (buffer-string) ")")))))))
   (cdr (assq sym mdw-config)))
 
+;; Width configuration.
+
+(defvar mdw-column-width
+  (string-to-number (or (mdw-config 'emacs-width) "77"))
+  "Width of Emacs columns.")
+(defvar mdw-text-width mdw-column-width
+  "Expected width of text within columns.")
+(put 'mdw-text-width 'safe-local-variable 'integerp)
+
 ;; Local variables hacking.
 
 (defun run-local-vars-mode-hook ()
@@ -196,8 +205,8 @@ fringes is not taken out of the allowance for WIDTH, unlike
   (interactive "P")
   (setq width (cond (width (prefix-numeric-value width))
                    ((and window-system (mdw-emacs-version-p 22))
-                    77)
-                   (t 78)))
+                    mdw-column-width)
+                   (t (1+ mdw-column-width))))
   (let* ((win (selected-window))
         (sb-width (mdw-horizontal-window-overhead))
         (c (/ (+ (window-width) sb-width)
@@ -981,7 +990,7 @@ case."
   (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
   (setq comment-column 40)
   (auto-fill-mode 1)
-  (setq fill-column 77)
+  (setq fill-column mdw-text-width)
   (and (fboundp 'gtags-mode)
        (gtags-mode))
   (if (fboundp 'hs-minor-mode)
@@ -991,6 +1000,7 @@ case."
   (trap (turn-on-font-lock)))
 
 (defun mdw-post-local-vars-misc-mode-config ()
+  (setq whitespace-line-column mdw-text-width)
   (when (and mdw-do-misc-mode-hacking
             (not buffer-read-only))
     (setq show-trailing-whitespace t)
diff --git a/setup b/setup
index c4eb953..057a1ba 100755 (executable)
--- a/setup
+++ b/setup
@@ -185,6 +185,8 @@ cppfiles=""
 [ "$xstuff" ] && cppfiles="$cppfiles
   Xdefaults"
 echo "Hacking files with C preprocessor..."
+defs="-DHOME=$HOME -DPROFILE=$here"
+defs="$defs -DEMACSWD=$(mdw-conf emacs-width 77)"
 for c in $cppfiles; do
   target=.$c
   case $c in
@@ -193,7 +195,7 @@ for c in $cppfiles; do
   ft=$HOME$sub/$target
   dir=${ft%/*}
   mkdir -p $dir
-  cpp -P dot/$c -o $ft.new
+  cpp -P $defs dot/$c -o $ft.new
   mv $ft.new $ft
   echo "  $target"
 done