1

I am using the ov library to display overlays.

If I try to insert an overlay into an empty line, it truncates the line. See the pictures below to understand the problem, and use the code to reproduce it.

(ov.el is just a wrapper using emacs' overlays, so this should not be a library specific problem.)

enter image description here enter image description here

(require 'ov)
(defun untitled--display-char-at-point (char point)
  (progn (ov-set (ov point (+ 1 point))
                 'display char)))

(point)
(untitled--display-char-at-point "t" 192)

;; This line moves!

The below is another example of the same happening. If you evaluate this:

(defun untitled--display-char-at-point (char point)
  (progn (ov-set (ov point (+ 1 point))
                 'display char)))

(point)
(untitled--display-char-at-point "t" 184)
;; hi

;; This line moves!

you end up with this:

(defun untitled--display-char-at-point (char point)
  (progn (ov-set (ov point (+ 1 point))
                 'display char)))

(point)
(untitled--display-char-at-point "t" 184)
;; hi
t;; This line moves!

GNU Emacs 24.5.1 (x86_64-apple-darwin14.3.0, Carbon Version 157 AppKit 1347.57)

Ps. could we get an ov tag? That library is the rural jurors bees' knees.

2

The question has nothing to do with spacemacs, so the reference to that library/configuration should be removed from the question so as not to confuse other forum participants.

The original poster should use a test to determine whether point -- where the overlay will be placed -- is at the end of the line, and use either of the following if that is the case:

  • The 'display property with the string plus a new-line \n -- e.g., "t\n"

  • The 'after-string property with just the string -- e.g., "t"

A sample test is as follows: (= (point) (point-at-eol))

When point is not at the end of the line, just the string and the 'display property will suffice.

Here are two examples of overlay placement when point is at the end of the line:

(overlay-put (make-overlay (point) (1+ (point)) 'display "t\n")

(overlay-put (make-overlay (point) (point)) 'after-string "t")
  • Will try this out. I realise now that I did not make the question general enough for posterity; an overlay might be more than one point, this will surely complicate the workaround? E.g. overlay from 10-20 while eol is at 15... – 24HrRevengeTherapist Oct 27 '15 at 9:58
  • 1
    @24HrRevengeTherapist: you have to decide whether you want the overlay to replace or add to the existing text, the existing text may or may not contain newlines, but there is nothing special about newlines per se. – npostavs Oct 27 '15 at 14:49
  • 1
    @24HrRevengeTherapist -- if you have text spanning multiple lines, then you may need to create multiple overlays in order to handle an eol situation. An alternative might be to use a 'face property and then just colorize the region desired. – lawlist Oct 27 '15 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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