Subject: bug#27433: 25.2; add-face-text-property with APPEND to t mess up with initialized list

From: [email-masked]
Date: Sat, 24 Jun 2017 11:50:56 -0400

retitle 27433 add-face-text-property with APPEND=t destructively modifies the original property list
severity 27433 minor
quit

Sebastien Chapuis <[email-masked]> writes:

> Hello, I have found a bug reproducible with emacs -Q (tested with
> emacs 25.2.2 and 25.2.1)
>
> I made a small use case that you can find here:
> - https://gist.github.com/sebastiencs/3b1f33a028d2b8d1ee41c44f5338f8e7
> or here:
> - http://paste.lisp.org/display/349159
>
> I provided explainations in the code.
> When I use edebug, the variable 'list-attributes' in the function
> 'my-icons-in-terminal' is directly set to (:family "icons-in-terminal
> (:background "red") (:background "red") ...), even if it is initialized
> with '(:family "icons-in-terminal).

> ;; If I initialize the variable list-attributes to (list :family "...") instead of '(:family) in my-icons-in-terminal,
> ;;   it doesn't appear.

I think we can fix it by using append instead of nonc, or perhaps we
should just document the side effect?

---   i/src/textprop.c
+++   w/src/textprop.c
@@ -421,7 +421,7 @@ add_properties (Lisp_Object plist, INTERVAL i, Lisp_Object object,
 		if (set_type == TEXT_PROPERTY_PREPEND)
 		  Fsetcar (this_cdr, Fcons (val1, Fcar (this_cdr)));
 		else
-		  nconc2 (Fcar (this_cdr), list1 (val1));
+                  Fsetcar (this_cdr, CALLN (Fappend, Fcar (this_cdr), list1 (val1)));
 	      else {
 		/* The previous value is a single value, so make it
 		   into a list. */