Subject: Re: bug#21468: 24.5; When next-line (visual) crosses overlay with before-string="\n" point goes to column 0

From: Noam Postavsky <[email-masked]>
Date: Mon, 14 Sep 2015 08:46:57 -0400

On Mon, Sep 14, 2015 at 2:17 AM, Eli Zaretskii <[email-masked]> wrote:
>
> Of course: that's a line of text.  Why is that a problem?  (I have no
> idea what role is that thin line serving in Magit.)

In this particular case, the overlays are delimiting a "magit region"
(consisting of whole logical lines touched by Emacs' region). This
means the thin line has to move with point, staying just ahead of it.

Here is a demo, eval this in a buffer, then do set-mark-command and
move around a bit:

(require 'cl-lib)

(defvar-local magit-region-overlays nil)

(defun 21468-update-hunk-region (start end window rol)
  (mapc #'delete-overlay magit-region-overlays)
  (let ((rbeg (save-excursion (goto-char (region-beginning))
                              (line-beginning-position)))
        (rend (save-excursion (goto-char (region-end))
                              (line-end-position))))
    (cl-flet ((ov (start end &rest args)
                  (let ((ov (make-overlay start end nil t)))
                    (overlay-put ov 'evaporate t)
                    (while args (overlay-put ov (pop args) (pop args)))
                    (push ov magit-region-overlays)
                    ov)))
      (ov rbeg (1+ rbeg) 'before-string
          (propertize (concat (propertize "\s" 'display '(space :height (1)))
                              (propertize "\n" 'line-height t))
                      'face 'highlight))
      (ov rend (1+ rend) 'after-string
          (propertize (concat (propertize "\s" 'display '(space :height (1)))
                              (propertize "\n" 'line-height t))
                      'face 'highlight)))))

(setq-local redisplay-highlight-region-function '21468-update-hunk-region)

(setq-local redisplay-unhighlight-region-function
            (lambda (rol) (mapc #'delete-overlay magit-region-overlays)))