The problem here is that there’s no face to control the appearance of
the margins. You can display text in the margin using overlays (that’s
linum-mode does) but, like any text in Emacs, it’s constrained
to the limits of the buffer. So you can’t have any control over the
margin display beyond the last line of the buffer.
What you can do, is fix those faulty lines in-between.
What to put there
This variable controls what you want to display on those visual lines
“between” two logical lines. The important part is the
which ensures these lines will follow the appearance of
"-----" part is demonstrative, you can change it to spaces or
whatever you wish.
`((margin left-margin) ,(propertize "-----" 'face 'linum))
"String used on the margin.")
How to do it
The following code goes through the buffer and places overlays
(similar to the ones
linum-mode uses) on each line which isn’t
(defvar-local endless/margin-overlays nil
"List of overlays in current buffer.")
(defun endless/setup-margin-overlays ()
"Put overlays on each line which is visually wrapped."
(let ((ww (- (window-width)
(if (= 0 (or (cdr fringe-mode) 1)) 1 0)))
(mapc #'delete-overlay endless/margin-overlays)
(while (null (eobp))
;; On each logical line
;; Check if it has multiple visual lines.
(while (>= (current-column) ww)
(forward-char (- ww))))))))
(defun endles/make-overlay-at (p)
"Create a margin overlay at position P."
(push (make-overlay p (1+ p)) endless/margin-overlays)
(car endless/margin-overlays) 'before-string
(propertize " " 'display endless/margin-display)))
And we want to it run whenever
linum-mode updates the line numbers.
(add-hook 'linum-before-numbering-hook #'endless/setup-margin-overlays)