I found a solution which is bit hackish, but not too much. I find the first space in the line and set it to a larger height. The line in my case always have a space somewhere (and it's generally true usually), the bigger height space forces the line height to be bigger which is effectively a top margin:
(let ((pos (1- (save-excursion (beginning-of-line) (search-forward " ")))))
(put-text-property pos (1+ pos) 'display '(height 1.5)))
In the comments @rpluim suggested an even simpler alternative: putting the text property on the newline, but note that this method does not work well if the line is long and spans multiple visual lines.
(put-text-property (line-end-position) (1+ (line-end-position)) 'display '(height 1.5))
:overline
property and set the thickness to your desire and make the color be the same as the background so that it is basically invisible to the naked eye. If there is a project more specific that you wish to accomplish, then forum participants may have a more comprehensive solution to suggest if you provide some additional details .... – lawlist Jan 15 '20 at 17:18(add-text-properties (line-beginning-position) (line-end-position) (list 'face '(:box (:line-width 10 :color "yellow")))
The color can be changed to match the background face of thedefault
face so that it can be invisible. Instead of text-properties, an overlay can probably be used instead if so desired. – lawlist Jan 15 '20 at 19:12(overlay-put (make-overlay (line-beginning-position) (line-end-position) nil t t) 'face (list 'face '(:box (:line-width 10 :color "yellow"))))
Another idea would be to insert a thin character and adjust the height of it to force the line height to increase; e.g., there is an ascii character that is zero-width but Emacs treats it as being 1 pixel wide. – lawlist Jan 15 '20 at 19:20