When I turn on
nlinum-modeand increase the font size via
C-x C-+ it does not increase the size of the "margin" where the line number is displayed, so only part of the line number is visible. Is there a way to configure either of these modes so that the entire line number is always visible regardless of font size? Tested using emacs 24.5 on OS X and emacs 24.3.1 on ubuntu 14.04
When I turn on
This is what I put in my
init.el file to fix the problem. It's a hack, at some sizes the left margin is a bit off but so far this is the best solution I've found to this problem.
(defun adjust-left-margin-hook () (let ((new-margin (+ 1 text-scale-mode-amount))) (setq left-margin-width (if (< new-margin 0) 0 new-margin)) (set-window-buffer nil (current-buffer)))) (add-hook 'linum-before-numbering-hook 'adjust-left-margin-hook) (add-hook 'text-scale-mode-hook 'adjust-left-margin-hook)
adjust-left-margin-hook performs the following commands:
new-marginto 1 more than the current
new-margin(or 0 if it's below the minimum). You can play around with this variable to adjust based on your preferences but take note, that
left-margin-widthmust be a positive integer
- redisplays the buffer so the margin width changes are applied
Then the two hooks are there for the function to be called whenever the left margin needs to be adjusted. That is, before the linum or nlinum packages start numbering the lines or whenever you change the scale of the text manually.
My Emacs version is 27.0.50, but it should work on earlier versions starting from 23 as well.