Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Emacs 23. linum-mode works well if using with default settings.

But if I increase the font size, the numbers cannot be displayed. It seems the the frame to display the line numbers is not increased as the font size of the line number increases.

Anyone know how this can be fixed?

share|improve this question

marked as duplicate by G-Man, garethTheRed, Sparhawk, Archemar, Eric Renouf Oct 25 '15 at 11:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

7  
Annoying, isn't it... I posted a similar question a while back... Emacs text-scale-adjust causes line numbers column to incrementally shrink and disappear ... There has been no resolution yet, though Gilles thinks it is a bug in the implementation ... Maybe someone can pick up on it here.... – Peter.O Jan 24 '12 at 2:44
up vote 6 down vote accepted

You can just define the linum size in your init config so it doesnt 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))
share|improve this answer
    
Best solution. Works flawlessly. – Jesse Aug 14 '14 at 13:51
1  
This is an excellent solution, except for a minor issue when zooming out. Basically, the line spacing is limited on the lower bound to the height of 100. If, for example, I want to see the entire document when there are a lot of lines, I cannot view the entire document within the buffer because I reach a lower limit where the lines are spaces apart by 100 pt, no matter how small the font may be. (it is just a minor quip, but worth noting) – Lucas May 18 '15 at 7:04

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)
share|improve this answer

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.