Font size issues with Emacs in linum-mode
You can just define the linum size in your init config so it doesn't depend on default-face
:
(set-face-attribute 'linum nil :height 100)
If you are not using linum-mode
as a global default (ie such as a major-mode hook), evaluate the set-face-attribute
command on load or else you will get an invalid face: linum
error:
(eval-after-load "linum"
'(set-face-attribute 'linum nil :height 100))
If you use the relative mode, it is also worth adjusting the face for this mode.
(set-face-attribute 'linum-relative-current-face nil :height 100)
Here is a work-around which works well enough on my setup, but my emacs knowledge is rather limited, and I'm not sure how it will behave in someone else's setup, but here it is:
Because the line number column does not change width while the font size does change, the approach I've taken is to prevent the line-number's font size from becoming any wider than its column.
I haven't find a way (ie. a function) to determine the necessary height of the line-number column for a particular scale, so I've built a list based on empirical data from a rather standard emacs. The list is scaled relative to text-scale-mode-step
= 1.04
... Also, text-scale-mode-amount
needs to be initalized, because it seems to only be triggered by text-scale functions, but is needed as 0
for a firs-time calculation by the workaround function.
EDIT: Zoom-Out now scales properly, but I'm stil looking for a better way to assess/control the line-number column's font height, so if someone has any ideas about it, I'd appreciate hearing about it.
;; This script is set for a `text-scale-mode-step` of `1.04`
(setq text-scale-mode-step 1.04)
;;
;; List: `Sub-Zoom Font Heights per text-scale-mode-step`
;; eg. For a default font-height of 120 just remove the leading `160 150 140 130`
(defvar sub-zoom-ht (list 160 150 140 130 120 120 110 100 100 90 80 80 80 80 70 70 60 60 50 50 50 40 40 40 30 20 20 20 20 20 20 10 10 10 10 10 10 10 10 10 10 5 5 5 5 5 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1))
(defvar sub-zoom-len (safe-length sub-zoom-ht))
(defvar def-zoom-ht (car sub-zoom-ht))
(set-face-attribute 'default nil :height def-zoom-ht)
(defun text-scale-adjust-zAp ()
(interactive)
(text-scale-adjust 0)
(set-face-attribute 'linum nil :height def-zoom-ht)
)
(global-set-key [C-kp-multiply] 'text-scale-adjust-zAp)
(defun text-scale-decrease-zAp ()
(interactive)
(if (not (boundp 'text-scale-mode-amount)) ;; first-time init
(setq text-scale-mode-amount 0))
(setq text-scale (round (/ (* 1 text-scale-mode-amount)
text-scale-mode-step)))
(if (> text-scale (- 1 sub-zoom-len))
(progn
(text-scale-decrease text-scale-mode-step)
(if (<= 0 text-scale-mode-amount)
(set-face-attribute 'linum nil :height def-zoom-ht)
(if (> 0 text-scale-mode-amount)
(set-face-attribute 'linum nil :height
(elt sub-zoom-ht (- 0 text-scale)))))))
)
(global-set-key [C-kp-subtract] 'text-scale-decrease-zAp)
(defun text-scale-increase-zAp ()
(interactive)
(if (not (boundp 'text-scale-mode-amount)) ;; first-time init
(setq text-scale-mode-amount 0))
(setq text-scale (round (/ (* 1 text-scale-mode-amount)
text-scale-mode-step)))
(if (< text-scale 85)
(progn
(text-scale-increase text-scale-mode-step)
(if (< (- 0 text-scale-mode-step) text-scale-mode-amount)
(set-face-attribute 'linum nil :height def-zoom-ht)
(if (> 0 text-scale-mode-amount)
(set-face-attribute 'linum nil :height
(elt sub-zoom-ht (- 0 text-scale)))))))
)
(global-set-key [C-kp-add] 'text-scale-increase-zAp)
;; Zoom font via Numeric Keypad
(global-set-key [C-kp-multiply] 'text-scale-adjust-zAp)
(global-set-key [C-kp-subtract] 'text-scale-decrease-zAp)
(global-set-key [C-kp-add] 'text-scale-increase-zAp)
;; Zoomf font via Control Mouse Wheel
(global-set-key (kbd "<C-mouse-4>") 'text-scale-increase-zAp)
(global-set-key (kbd "<C-mouse-5>") 'text-scale-decrease-zAp)
I think I can fix that problem with the following code:
(require 'linum)
(defun linum-update-window-scale-fix (win)
"fix linum for scaled text"
(set-window-margins win
(ceiling (* (if (boundp 'text-scale-mode-step)
(expt text-scale-mode-step
text-scale-mode-amount) 1)
(if (car (window-margins))
(car (window-margins)) 1)
))))
(advice-add #'linum-update-window :after #'linum-update-window-scale-fix)
(EDIT: some small bugs fixed. 2015-10-19 01:47 CEST) It seems to work, at least with 24.5.