Subject: bug#15155: 24.3; wrap-prefix in adaptive-wrap-prefix-mode with variable-pitch has wrong face

From: Eli Zaretskii <[email-masked]>
Date: Fri, 23 Aug 2013 17:29:37 +0300

> Date: Fri, 23 Aug 2013 15:17:58 +0200
> From: Frank Fischer <[email-masked]>
> Cc: [email-masked], [email-masked]
> 
> Am Fri, 23 Aug 2013 09:41:01 +0300
> schrieb Eli Zaretskii <[email-masked]>:
> 
> > > Date: Thu, 22 Aug 2013 22:32:46 +0200
> > > From: Frank Fischer <[email-masked]>
> > > Cc: [email-masked], [email-masked]
> > > 
> > > Am Thu, 22 Aug 2013 19:56:05 +0300
> > > schrieb Eli Zaretskii <[email-masked]>:
> > > 
> > > > Can you build Emacs from the trunk?  I would like to ask you to
> > > > try a patch that might fix this in your use case.
> > > 
> > > Sure, I'd be happy to help ;)
> > 
> > Thank you.  Please try the patch below.  It should solve the problem
> > with the font; you will still need to make sure on the Lisp level that
> > the prefix has the right face, to get the color you want.
> 
> That patch seems to work, thank you.

Thanks, committed as trunk revision 113979.

> I have only one (very) minor issue left: depending on the mode the
> wrap-prefix may contain characters with different faces (e.g. in
> emacs-lisp mode !!!;;; would be a correct prefix, the first three
> characters with default face, the latter three with comment-face), hence
> there is not really "the one" correct face to assign 'wrap-prefix with
> `propertize`. That why I tried the variant
> 
> (setq adaptive-fill-function
>   (lambda ()
>     (and adaptive-fill-regexp
>          (looking-at adaptive-fill-regexp)
>          (match-string 0))))
> 
> hoping that (match-string 0) returns the whole prefix with the correct
> fontification. However, there are situations where this does not work:
> for example if one has a (very long) wrapped line without comment and
> then inserts a semicolon (only one) at the beginning of that line to
> comment it out, then the wrap-prefix does not get comment face (to be
> precise, it has the correct font, thus your patch works, but not the
> correct color). But if one inserts a second semicolon then the
> wrap-prefix gets the correct color. I assume this happens because the
> wrap-prefix is set before font-lock changed the face of inserted
> semicolon. 

I think your analysis is correct.  Perhaps invoking font-lock to
fontify the appropriate portion of the text, before taking the prefix
string, will solve that?

> Perhaps this is a more an issue of adaptive-wrap-mode, I
> don't know.

I think it is indeed an issue with adaptive-wrap-mode.