normalbold I tried (propertize ...">

How to embed various "right" ones?

I want to execute the elisp equivalent

<font color="red">normal<b>bold</b></font> 

I tried

  (propertize (concat "normal" (propertize "bold" 'font-lock-face '(:weight bold))) 'font-lock-face '(:foreground "red")) 

However, the "red" property overwrites the "bold" property, and I end up with

 #("normalbold" 0 6 (font-lock-face (:foreground "red")) 6 10 (font-lock-face (:foreground "red"))) 

Is this doable?

Thanks!

+4
source share
1 answer

I do not think that nesting can be done using elisp functions. Documents suggest defining each part of a line independently and then concatenating them:

"To put different properties in different parts of a string, you can build each part with a property and then combine them with concat:

  (concat (propertize "foo" 'face 'italic 'mouse-face 'bold-italic) " and " (propertize "bar" 'face 'italic 'mouse-face 'bold-italic)) ⇒ #("foo and bar" 0 3 (face italic mouse-face bold-italic) 3 8 nil 8 11 (face italic mouse-face bold-italic)) 

"

Which in your case will look something like this:

 (concat (propertize "normal" 'font-lock-face '(:foreground "red" )) (propertize "bold" 'font-lock-face '(:foreground "red" :weight bold))) 

Without knowing more about your use case, I cannot be sure that this will work for you. If this is not the case, you can try using add-text-properties (also described in the documents), which you can use to change the properties of the text in text form.

+2
source

Source: https://habr.com/ru/post/1496367/


All Articles