Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Line Height

I am trying to set the line height of text in an Emacs buffer so there is space above and below the letters. From the documentation, I infer that the line-height text property may help me to accomplish this.

There is also a line-spacing variable which I can set like (setq-default line-spacing 0.25). This kind of works, except it does not produce space before text, only after it. I don’t like the way this looks when using modes like show-paren-mode, since it “dips” down:

Undesired current behavior (“hanging”)

Undesired current behavior

Desired behavior mockup (vertically-centered)

Desired behavior

I'd like to vertically-center the text.

I have discovered that I can temporarily get the effect I want with the following code:

(add-text-properties (point-min) (point-max)
                     '(line-spacing 0.25 line-height 1.25))

However, in some modes the properties go away in regions where I start typing. How do I make that top and bottom spacing the default? (Hooks won't work.)

like image 892
Jackson Avatar asked Oct 18 '14 06:10

Jackson


3 Answers

As the doc says, line-height is a text (or an overlay) property. It is not a variable.

Try (setq-default line-spacing 20).

line-spacing is a frame parameter or a buffer-local variable. Its value can be an integer number of pixels or a floating-point number specifying spacing relative to the frame's default line height. The doc says nothing about giving it a list value, such as (32 64).


And if you are using Emacs in terminal mode then none of this applies. As the doc says about that:

On text terminals, the line spacing cannot be altered.
like image 136
Drew Avatar answered Nov 13 '22 07:11

Drew


Update

TLDR: I've succumbed to the fact that you can't really reliably achieve this natively with Emacs. You need to patch the font itself to include extra spacing. So, I created this script to take care of that.


Old/Incomplete Answer

TLDR: Add this somewhere in init file:

;; Set the padding between lines
(defvar line-padding 3)
(defun add-line-padding ()
  "Add extra padding between lines"

  ; remove padding overlays if they already exist
  (let ((overlays (overlays-at (point-min))))
    (while overlays
      (let ((overlay (car overlays)))
        (if (overlay-get overlay 'is-padding-overlay)
            (delete-overlay overlay)))
      (setq overlays (cdr overlays))))

  ; add a new padding overlay
  (let ((padding-overlay (make-overlay (point-min) (point-max))))
    (overlay-put padding-overlay 'is-padding-overlay t)
    (overlay-put padding-overlay 'line-spacing (* .1 line-padding))
    (overlay-put padding-overlay 'line-height (+ 1 (* .1 line-padding))))
  (setq mark-active nil))


(add-hook 'buffer-list-update-hook 'add-line-padding)

Increase or decrease the line-padding value to your liking.

This answer pretty much just summarizes the information in the above question, answer, and comments, so I suggest reading those first.

I use an overlay instead of text properties because it behaves more nicely when adding new text to the buffer (especially via copy/paste).

The buffer-list-update-hook is used as a means of identifying when a new buffer has been created and thus would need to have the overlay applied.

For performance reasons, to not continuously add overlays, the existing padding overlay is deleted if it aleady existed.

like image 27
tam5 Avatar answered Nov 13 '22 07:11

tam5


Try "Help => More Manuals => Emacs Lisp Reference" and from there type i text properties RET. This will hopefully clarify the situation. As for your specific request, I don't think there's a simple way to get what you want right now. You might like to M-x report-emacs-bug about the display appearence of the paren-highlighting.

like image 28
Stefan Avatar answered Nov 13 '22 08:11

Stefan