Subject: bug#20592: the `display' property messes the `face' properties after `concat'

From: Eli Zaretskii <[email-masked]>
Date: Sun, 17 May 2015 17:39:12 +0300

> Date: Sun, 17 May 2015 01:58:29 +0200
> From: Alexander Shukaev <[email-masked]>
> 
> Consider another piece of code:
> 
> (setq-default minibuffer-line-format
> 	      `((:eval
> 		 (let ((string (concat
> 				(propertize (format-time-string "%Y.%m.%d")
> 					    'face
> 					    'minibuffer-line-date)
> 				" "
> 				(propertize (format-time-string "%A")
> 					    'face
> 					    'minibuffer-line-weekday)
> 				" "
> 				(propertize (format-time-string "%R")
> 					    'face
> 					    'minibuffer-line-time))))
> 		   (concat (propertize " "
> 				       'display
> 				       `((space :align-to
> 						(- right
> 						   right-fringe
> 						   ,(length string)))))
> 			   string)))))

> Alignment works as expected, but faces are messed up.  In fact, the default face is used everywhere (which comes from the `display' property), like if subsequent propertizings of date, weekday, and time have never been there.

(To complete the bug report, the 3 minibuffer-line-* faces need to be
defined, and the minibuffer-line package from ELPA loaded and then
minibuffer-line-mode turned on.)

The behavior you observe is because the ':eval' construct expects to
produce a single string with either the same common face spec on all
of its characters, or no faces at all.  You cannot use ':eval' to
produce a string that has more than one face spec on its different
characters; if you do, only the face spec of the first character of
the string will be honored.

'minibuffer-line-mode' is implemented via the function
'format-mode-line'.  While I can understand this design decision, the
downside is that you get to face some of the idiosyncrasies of
formatting the mode line.  (E.g., did you ask yourself why you get an
extra column of white space after the string?)

The upshot of this is that you need to generate each substring that
has a unique face with its own ':eval'.  For example, the following
abomination works as you expect:

  (setq-default minibuffer-line-format
		'((:eval
		   (propertize " "
			       'display
			       `((space :align-to
					(- right
					   right-fringe
					   ,(length
					     (concat
					      (format-time-string "%Y.%m.%d")
					      " "
					      (format-time-string "%A")
					      " "
					      (format-time-string "%R"))))))))
		  (:eval (propertize (format-time-string "%Y.%m.%d")
				     'face
				     'minibuffer-line-date))
		  " "
		  (:eval (propertize (format-time-string "%A")
				     'face
				     'minibuffer-line-weekday))
		  " "
		  (:eval (propertize (format-time-string "%R")
				     'face
				     'minibuffer-line-time))))