I'd like to apply a line-height property to all text in all buffers to add space above each line (so line-spacing doesn't work, I think).

I've added a function to 'buffer-list-update-hook to create and propertize an overlay that spans the entire buffer (also set to grow with text on either end). This works, but feels like a big hack for something this simple. Is there no better way of doing this?

(defvar fov-line-height-overlay nil
  "Overlay used to manage line-height across the buffer")
(make-variable-buffer-local 'fov-line-height-overlay)

(defun fov-update-line-height-overlays ()
  "Run through the list of buffers and ensure they have an overlay for line-height."
  (dolist (buf (buffer-list))
    (with-current-buffer buf
      (unless fov-line-height-overlay
        (setq fov-line-height-overlay (make-overlay (point-min) (point-max) nil nil t))
        (overlay-put fov-line-height-overlay 'line-height 1.2)))))

(add-hook 'buffer-list-update-hook 'fov-update-line-height-overlays)

PS: The reason I'm doing this is I've set the hl-line face to have a box with :line-width -1 (to avoid jitter while moving) but now I need more space for the text.

1 Answer 1


Add a function to buffer-access-fontify-functions that calls put-text-properties on the required substring. This is called by buffer-substring to lazily set up the text properties, so this will ensure that everything has the property as soon as it is needed, without mucking about with overlays. See section 31.19.7 Lazy Computation of Text Properties of the Emacs manual for the details.

Either way it is a bit of a hack, simply because Emacs doesn't have a very sophisticated or complete rendering model. This feels like less of a hack, though.

If you want something that's even nicer, I recommend diving into the rendering code and changing it so that line-spacing can be a list of two numbers, one for space below and one for space above the line. Then push that change out to the mailing list and see what they think of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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