0

For example I have this text in a buffer:

aaa
bbb
ccc

and I want it displayed with some spacing above the bbb line:

aaa

bbb
ccc

Is there a face or something which I could add to the bbb line, so it has some margin above it (without modyfing the buffer contents, so not with a newline like here, which I added only for demonstration purposes).

8
  • Not an ideal solution, but the first thing that comes to mind is using an overlay or text property with an :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, 2020 at 17:18
  • Thanks, overline may work, though in my emacs the docs only says that I can set the color. Is the thickness an emacs 27 feature?
    – Tom
    Jan 15, 2020 at 17:29
  • Hmmm ... I am having trouble getting :overline to behave like :underline in terms of setting color and thickness and style. If I am able to come up with a working example, I'll post a follow-up comment.
    – lawlist
    Jan 15, 2020 at 18:12
  • Well, underline can work too, I guess, if it works for the line above. The point is to have some spacing between the two lines, so it doesn't really matter if it's a top margin or a bottom margin for the upper row.
    – Tom
    Jan 15, 2020 at 18:42
  • Sorry ... according to the accepted answer in the following thread, Emacs does not permit underline thickness adjustment: emacs.stackexchange.com/questions/37813/…
    – lawlist
    Jan 15, 2020 at 19:04

1 Answer 1

1

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))
4
  • 1
    I think you'd be better off putting the line-spacing or line-height property on the newline for the relevant lines.
    – rpluim
    Jan 16, 2020 at 10:52
  • Good idea, that works too.
    – Tom
    Jan 16, 2020 at 12:17
  • 1
    The newline method does not work well in practice, because I use the margin to make some files with long lines more readable (one physical line spans multiple visual lines), and if you put the line-height setting to the newline then the margin appears above the last virtual screen line of the physical line which is not good. If I put the height on the first space in the line then the first visual line always has the margin, even if the line spans multiple visual lines.
    – Tom
    Jan 16, 2020 at 15:53
  • What if there is no space on the line? Maybe you can use a before-string property? Feb 5, 2022 at 7:38

Your Answer

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

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