2

I'm using after-string overlays as in this question to put text on the right hand side of the buffer, like this:

(let ((overlay (make-overlay (point-max) (point-max) (current-buffer))))
  (overlay-put overlay 'intangible t)
  (overlay-put overlay 'before-string
               (concat
                (propertize " " 'display `(space :align-to (- right-fringe ,(1+ (length text)))))
                text))
  overlay))

This works well, but if I position the cursor at the end of the buffer at insert characters, I insert past the overlay.

I'm inserting past the overlay. Oh no!

In the image, the check mark is my overlay, and the x after it is something I inserted by typing an x after the word Type, which was previously the last word in the buffer.

How can I stop this from happening? I'd like the overlay to permanently sit past all the actual text in the buffer.

pavpanchekha
  • 123
  • 3

2 Answers2

2

The simplest way is probably to use:

(let ((overlay (make-overlay (point-max) (point-max) nil t t)))
  ...)

The additional t t arguments will mark the overlays's boundaries as being "insert-before" rather than "insert-after".

Stefan
  • 26,154
  • 3
  • 46
  • 84
  • This is almost perfect. One downside—I use a bar cursor, and even though insertions are insert-before, the cursor appears after the overlay. I tried the `cursor` property but that didn't work. Any ideas? – pavpanchekha Aug 27 '15 at 19:19
  • I think you need to try the `cursor` property again. It's a tricky property to use, and I've often had to play with it for a while until it worked. – Stefan Aug 28 '15 at 02:58
1

I have found that setting 'cursor t as an overlay property has no effect when used in conjunction with an 'after-string property. However, it works if the STRING is propertized; e.g., 'after-string (propertize STRING 'cursor t).

WORKS:

(save-excursion
  (end-of-line)
  (let ((eol-floating-column (+ (current-column) 10))
        (ov (make-overlay (point) (point) nil t t)))
    (overlay-put ov
                 'after-string
                 (concat
                   (propertize (char-to-string ?\uE001)
                                'display
                                `((space :align-to ,eol-floating-column)
                                  (space :width 0))
                                'cursor t)
                   (propertize (char-to-string ?\u00B6)
                              'face '(:background "gray50" :foreground "black"))))))

BROKEN:

(save-excursion
  (end-of-line)
  (let ((eol-floating-column (+ (current-column) 10))
        (ov (make-overlay (point) (point) nil t t)))
    (overlay-put ov
                 'after-string
                 (concat
                   (propertize (char-to-string ?\uE001)
                                'display
                                `((space :align-to ,eol-floating-column)
                                  (space :width 0)))
                   (propertize (char-to-string ?\u00B6)
                              'face '(:background "gray50" :foreground "black"))))
    (overlay-put ov 'cursor t)))
lawlist
  • 18,826
  • 5
  • 37
  • 118