1

I'm trying to setup line numbering in Emacs.
Linum works well, but when I open two buffers, numbering for empty lines disappears. I use Manjaro Linux. Emacs works in the terminal.

Here's screenshot.

Code from .emacs file:

(add-hook 'find-file-hook (lambda () (linum-mode 1)))

(unless window-system
  (add-hook 'linum-before-numbering-hook
    (lambda ()
      (setq-local linum-format-fmt
          (let ((w (length (number-to-string
                (count-lines (point-min) (point-max))))))
            (concat "%"(number-to-string w) "d"))))))

(defun linum-format-func (line)
  (concat
   (propertize (format linum-format-fmt line) 'face 'linum)
   (propertize " " 'face 'mode-line)))

(unless window-system
  (setq linum-format 'linum-format-func))

How can I fix it?

Drew
  • 29,895
  • 7
  • 74
  • 104
  • See: http://stackoverflow.com/a/25082664/2112489 and http://emacs.stackexchange.com/a/4179/2287 Perhaps one of them applies. – lawlist Jul 21 '16 at 18:40

1 Answers1

5
  1. You might be able to fix this by replacing all of the above code with just

    (global-linum-mode 1)
    
  2. linum-mode should already do the variable-size-format thing for you. Don't know why you're reinventing the wheel.

  3. Maybe your problem is that you're trying to string concat two propertize-d objects. You can avoid this by making your formatting like "%3d " instead of "%3d" and concatting " " later:

    (add-hook 'find-file-hook (lambda () (linum-mode 1)))
    
    (unless window-system
      (add-hook 'linum-before-numbering-hook
        (lambda ()
          (setq-local linum-format-fmt
              (let ((w (length (number-to-string
                    (count-lines (point-min) (point-max))))))
                (concat "%" (number-to-string w) "d "))))))
    
    (defun linum-format-func (line)
      (propertize (format linum-format-fmt line) 'face 'linum))
    
    (unless window-system
      (setq linum-format 'linum-format-func))
    
Brian Malehorn
  • 2,627
  • 14
  • 15