Subject: bug#42552: closed (Re: bug#42552: 28.0.50; Overlay 'face' property doesn't set the "underlying face" for 'after-string')

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 10 Aug 2020 22:29:02 +0000

Your bug report

#42552: 28.0.50; Overlay 'face' property doesn't set the "underlying face" for 'after-string'

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
42552: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=42552
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#42552: 28.0.50; Overlay 'face' property doesn't set the "underlying face" for 'after-string'
From: Dmitry Gutov <[email-masked]>
To: Eli Zaretskii <[email-masked]>
Cc: [email-masked]
Date: Tue, 11 Aug 2020 01:27:59 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

On 07.08.2020 08:42, Eli Zaretskii wrote:

>> 1. Eval:
>>
>> (with-silent-modifications
>>     (insert (propertize "abc"
>>                         'font-lock-face
>>                         '((:background "green" :extend t)
>>                           default
>>                           ( :inverse-video t
>>                             :foreground "yellow"
>>                             :extend t)))))
>>
>> 2. C-j
>>
>> The "extended" newline is yellow.
> 
> That's expected due to face-merging, no?

I would have expected it to be green, at least. But if you say it's 
working correctly, it probably is.

>> I'll try to implement this all as suggested, and will come back after.
> 
> Should we close this bug or keep it open?

I've pushed the changes based on this discussion, so the matter looks 
closed.

Thanks.

Subject: 28.0.50; Overlay 'face' property doesn't set the "underlying face" for 'after-string'
From: Dmitry Gutov <[email-masked]>
To: [email-masked]
Date: Sun, 26 Jul 2020 21:23:32 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

I have tried to find a workaround around bug#42521 to render a 
completion popup with images.

The attached patch almost works, except in Emacs 27+ it leads to a
repeat of bug#38563. Meaning, the rendered popup inherits certain
properties (most importantly, :extend) from the character under the end
of the overlay. Leading to similar visual effects, screenshots attached.

I would hope to solve it like we solved it in bug#38563, but the 'face'
overlay property doesn't seem to have any effect here.

The attached patch for company.el should apply cleanly on top of its
current code in ELPA.

The reproduction scenario is almost the same, only in this case the 
problem occurs when the *end* of the overlay falls on a position with
the non-nil 'extend' property (and the overlay is 10 lines long).
See the screenshots.

Please let me know if you need any further clarifications.

I do believe it's a regression, considering the same code works okay in
Emacs 26.3, in exact same situations (whitespace-mode 'tail' face or the
log-edit line under the end of the popup overlay).

In GNU Emacs 28.0.50 (build 25, x86_64-pc-linux-gnu, GTK+ Version 
3.24.20, cairo version 1.16.0)
  of 2020-07-20 built on potemkin
Repository revision: 4c08c2f45b9bb0265f6d7c3529011dee1b18e843
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12008000
System Description: Ubuntu 20.04.1 LTS
diff --git a/company.el b/company.el
index 592c6d1..d47e79f 100644
--- a/company.el
+++ b/company.el
@@ -2742,6 +2742,9 @@ If SHOW-VERSION is non-nil, show the version in the echo area."
     (let ((str (concat (when nl " \n")
                        (mapconcat 'identity (nreverse new) "\n")
                        "\n")))
+      ;; Use add-face-text-property in Emacs 24.4
+      ;; https://debbugs.gnu.org/38563
+      (font-lock-append-text-property 0 (length str) 'face 'default str)
       (when nl (put-text-property 0 1 'cursor t str))
       str)))
 
@@ -2950,14 +2953,13 @@ Returns a negative number if the tooltip should be displayed above point."
       (overlay-put ov 'priority 111)
       ;; No (extra) prefix for the first line.
       (overlay-put ov 'line-prefix "")
-      ;; `display' is better
-      ;; (http://debbugs.gnu.org/18285, http://debbugs.gnu.org/20847),
-      ;; but it doesn't work on 0-length overlays.
-      (if (< (overlay-start ov) (overlay-end ov))
-          (overlay-put ov 'display disp)
-        (overlay-put ov 'after-string disp)
-        (overlay-put ov 'invisible t))
-      (overlay-put ov 'face 'default)
+      (overlay-put ov 'after-string disp)
+      ;; `display' is better than `invisible':
+      ;; https://debbugs.gnu.org/18285
+      ;; https://debbugs.gnu.org/20847
+      ;; https://debbugs.gnu.org/42521
+      (overlay-put ov 'display "")
+      (overlay-put ov 'face 'default) ; Has no effect!
       (overlay-put ov 'window (selected-window)))))
 
 (defun company-pseudo-tooltip-guard ()