GNU bug report logs - #39812
26.1; face-remapping-alist is sometimes set to an unexpected value

Previous Next

Package: emacs;

Reported by: Markus Triska <triska <at> metalevel.at>

Date: Thu, 27 Feb 2020 19:21:02 UTC

Severity: minor

Found in version 26.1

Fixed in version 27.1

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 39812 in the body.
You can then email your comments to 39812 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#39812; Package emacs. (Thu, 27 Feb 2020 19:21:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Markus Triska <triska <at> metalevel.at>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 27 Feb 2020 19:21:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Markus Triska <triska <at> metalevel.at>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.1; face-remapping-alist is sometimes set to an unexpected value
Date: Thu, 27 Feb 2020 20:10:22 +0100
To reproduce this issue, please start Emacs with "emacs -Q", then place
the following forms in the appearing *scratch* buffer:

    (defun a ()
      (set (make-local-variable 'face-remapping-alist)
           '((default bold))))

    (a)
    (face-remap-add-relative 'default 'italic)
    (a)

and then evaluate the buffer with M-x eval-buffer RET.

Then, inspect the value of face-remapping-alist with:

    C-h v face-remapping-alist RET

In my case, the value is: '((default italic bold)).

How can this be explained? The final form (a) is supposed to set
face-remapping-alist to '((default bold)), and hence I expect the
value of face-remapping-alist to be '((default bold)) instead.

When I comment out the first invocation of "(a)", i.e., when I write:

    (defun a ()
      (set (make-local-variable 'face-remapping-alist)
           '((default bold))))

    ;; (a) ; now this line is commented out
    (face-remap-add-relative 'default 'italic)
    (a)

and then evaluate the buffer, then face-remapping-alist is set to
'((default bold)), which is the expected value.

As guideline for the definition of the function `a', I used the snippet
from the variable description of face-remapping-alist, which states:

   "For instance, the mode my-mode could define a
    face ‘my-mode-default’, and then in the mode setup function, do:

      (set (make-local-variable 'face-remapping-alist)
           '((default my-mode-default))))."

Is this still a recommended way to set this variable, should the above
example work? Is there a reliable way to set face-remapping-alist to
'((default bold)) in the function `a' so that the first example works?

Thank you and all the best!
Markus


In GNU Emacs 26.1 (build 1, x86_64-apple-darwin15.3.0, X toolkit, Xaw scroll bars)
 of 2018-09-22 built on mt-mb
Windowing system distributor 'The X.Org Foundation', version 11.0.11502000

Configured using:
 'configure --prefix=/opt/local --without-ns --without-dbus
 --without-gconf --without-libotf --without-m17n-flt --without-gpm
 --with-gnutls --with-xml2 --with-modules --infodir
 /opt/local/share/info/emacs --with-x-toolkit=lucid --without-xaw3d
 --without-imagemagick --with-xpm --with-jpeg --with-tiff --with-gif
 --with-png --with-lcms2 --without-rsvg --with-xft 'CFLAGS=-pipe -Os
 -arch x86_64' CPPFLAGS=-I/opt/local/include 'LDFLAGS=-L/opt/local/lib
 -Wl,-headerpad_max_install_names -lfreetype -lfontconfig -Wl,-no_pie
 -arch x86_64''

Configured features:
XPM JPEG TIFF GIF PNG GSETTINGS NOTIFY ACL GNUTLS LIBXML2 FREETYPE XFT
ZLIB TOOLKIT_SCROLL_BARS LUCID X11 MODULES THREADS LCMS2

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#39812; Package emacs. (Thu, 27 Feb 2020 19:59:02 GMT) Full text and rfc822 format available.

Message #8 received at 39812 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Markus Triska <triska <at> metalevel.at>
Cc: 39812 <at> debbugs.gnu.org
Subject: Re: bug#39812: 26.1;
 face-remapping-alist is sometimes set to an unexpected value
Date: Thu, 27 Feb 2020 14:57:56 -0500
Markus Triska <triska <at> metalevel.at> writes:

> To reproduce this issue, please start Emacs with "emacs -Q", then place
> the following forms in the appearing *scratch* buffer:
>
>     (defun a ()
>       (set (make-local-variable 'face-remapping-alist)
>            '((default bold))))
>
>     (a)
>     (face-remap-add-relative 'default 'italic)
>     (a)

face-remap-add-relative destructively modifies the list value, so
setting face-remapping-alist to a quoted literal gives unexpected
results like this.  Similar to the example at the bottom of (info
"(elisp) Rearrangement")

> Is this still a recommended way to set this variable, should the above
> example work? Is there a reliable way to set face-remapping-alist to
> '((default bold)) in the function `a' so that the first example works?

   (defun a ()
      (set (make-local-variable 'face-remapping-alist)
           (copy-tree '((default bold)))))

Or

   (defun a ()
      (set (make-local-variable 'face-remapping-alist)
           (list (list 'default 'bold))))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#39812; Package emacs. (Fri, 28 Feb 2020 07:16:02 GMT) Full text and rfc822 format available.

Message #11 received at 39812 <at> debbugs.gnu.org (full text, mbox):

From: Markus Triska <triska <at> metalevel.at>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 39812 <at> debbugs.gnu.org
Subject: Re: bug#39812: 26.1;
 face-remapping-alist is sometimes set to an unexpected value
Date: Fri, 28 Feb 2020 08:15:03 +0100
Noam Postavsky <npostavs <at> gmail.com> writes:

> face-remap-add-relative destructively modifies the list value, so
> setting face-remapping-alist to a quoted literal gives unexpected
> results like this.

Thank you for looking into this! Using copy-tree makes it work.

However, I find it very unexpected that face remapping modifies a value
that appears as a literal constant in my own code. Is it possible to
make face remapping word without such destructive side-effects?

Alternatively, would you please consider documenting how to work around
this, for example at the place where the sample snippet is mentioned?

Thank you and all the best!
Markus






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#39812; Package emacs. (Thu, 05 Mar 2020 12:49:01 GMT) Full text and rfc822 format available.

Message #14 received at 39812 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Markus Triska <triska <at> metalevel.at>
Cc: 39812 <at> debbugs.gnu.org
Subject: Re: bug#39812: 26.1;
 face-remapping-alist is sometimes set to an unexpected value
Date: Thu, 05 Mar 2020 07:48:25 -0500
Markus Triska <triska <at> metalevel.at> writes:

>> face-remap-add-relative destructively modifies the list value, so
>> setting face-remapping-alist to a quoted literal gives unexpected
>> results like this.
>
> Thank you for looking into this! Using copy-tree makes it work.
>
> However, I find it very unexpected that face remapping modifies a value
> that appears as a literal constant in my own code. Is it possible to
> make face remapping word without such destructive side-effects?

I guess it should be easy enough to add a copy-tree call in
face-remap-add-relative, but it looks like a couple of other functions
also modify the value destructively.

> Alternatively, would you please consider documenting how to work around
> this, for example at the place where the sample snippet is mentioned?

So updating the docs might be easier than trying to catch all the
potential trouble spots.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#39812; Package emacs. (Mon, 30 Mar 2020 02:36:30 GMT) Full text and rfc822 format available.

Message #17 received at 39812 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Markus Triska <triska <at> metalevel.at>
Cc: 39812 <at> debbugs.gnu.org
Subject: Re: bug#39812: 26.1; face-remapping-alist is sometimes set to an
 unexpected value
Date: Sat, 28 Mar 2020 21:33:05 -0400
close 39812 27.1
quit

>> Alternatively, would you please consider documenting how to work around
>> this, for example at the place where the sample snippet is mentioned?

> So updating the docs might be easier than trying to catch all the
> potential trouble spots.

I've done that now on emacs-27.

[1: ee47e00f4e]: 2020-03-28 21:22:49 -0400
  Don't suggest setting face-remapping-alist to a literal (Bug#39812)
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=ee47e00f4e0a644a0948743ac43892710663b243>





bug marked as fixed in version 27.1, send any further explanations to 39812 <at> debbugs.gnu.org and Markus Triska <triska <at> metalevel.at> Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 30 Mar 2020 02:36:49 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 27 Apr 2020 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 58 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.