[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Displaying an overlay image across the margins and body

From: Thomas F. K. Jorna
Subject: Displaying an overlay image across the margins and body
Date: Tue, 6 Jul 2021 09:36:58 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0


I want to create an overlay (or, to avoid X-Y problems, a multicolored, multilayered, visually distinct line at an arbitrary position that cannot be removed, like a page-break) that spans the entire "page", by which I mean the margins and buffer width, of zero width, and insertable anywhere.

I've created a sample function which does that (be sure to |(require 'svg)| if you want to test it)

|(defun insert-svg-overlay () (interactive) (let* ((margin-pixel-width (* (frame-char-width) (car (window-margins)))) (svg (svg-create margin-pixel-width 50)) (svg2 (svg-create (window-body-width nil t) 50)) (ov (make-overlay (point) (point)))) (svg-rectangle svg 0 0 margin-pixel-width 50 :fill-color "red") (svg-rectangle svg2 0 0 (window-body-width nil t) 50 :fill-color "yellow") (overlay-put ov 'before-string (concat (propertize "x" 'display (svg-image svg2)) (propertize "x" 'display (list (list 'margin 'right-margin) (svg-image svg))) (propertize "x" 'display (list (list 'margin 'left-margin) (svg-image svg))))))) |

which, if you have margins set, will insert an (ugly-looking) overlay like so red-yellow line inserted in the middle of some code <>.

This does exactly what I want at the start of an "actual" line. However, I would like it to do the same thing at the start of a /visual / line. However, doing so yields (inserting before |(svg-image svg)|) same line, now with the yellow line offset from the rest <>

How do I "prevent" some of the overlay from going places it shouldn't? I have tried so many different combinations of |before-string|, |after-string| and plain inserting images, to no avail. There are two things that do work, but are undesirable in their own right.

1. Make the middle rectangle 1 pixel shorter, by changing |svg2| to
   |(svg2 (svg-create (1- (window-body-width nil t) 50))| same line,
   now correct but with a 1 pixel gap between the middle yellow chunk
   and the right red chunk <>
   Undesirable for obvious reasons.
2. Make the overlay occupy non-zero space. This allows you to change
   the region occupied by the overlay to the image/whatever, which
   somehow /does/ work. Undesirable because this would remove the
   character(s) we want to have.

I feel like there is some combination of |before-string|s and |after-string|s and svg-order that will accomplish what I want, but I have had very little luck so far.

Somehow parts of the overlay get pushed to the next line, but why? I'm relatively sure it has something to do with visual-line-mode, is there some way to "prevent" it from word-wrapping specific strings?

I am using svg's/overlays because I want to be able to draw in them/display multiple lines.

This way of displaying in the margins comes from |put-image|.

Thank you very much for your help!

Thomas F. K. Jorna

PS. This is a copy of

reply via email to

[Prev in Thread] Current Thread [Next in Thread]