0

I have the following code that changes mode-line colours. When using the :box property I want to use a variable. But I get an error using :color fglamp because I need to evaluate the colour variable. How may I solve this ?

(set-face-attribute 'mode-line nil
  :background bglamp
  :foreground fglamp
  :inverse-video nil
  :box '(:line-width 3 :color fglamp :style nil)) )
Dilna
  • 1
  • 3
  • 11

1 Answers1

1

When using the :box property I want to use a variable. ... I need to evaluate the colour variable.

Since you want to change the value (actually the face attribute) dynamically:

(progn
  (add-variable-watcher 'VARIABLE-NAME
                        (lambda (symbol newval operation where)
                          (set-face-attribute ...
                                              :box `( :color ,newval
                                                      ...))))
  (set-face-attribute ...
                      :box `( :color ,VARIABLE-NAME
                              ...)))

add-variable-watcher has limitations, please C-h f it.

shynur
  • 5,253
  • 1
  • 4
  • 25
  • The add-variable-watcher is an unnecessary complication: the OP only wanted to propagate whatever value fglamp has into the quoted expression. So only the backquote part is relevant to the question I believe. – NickD Jul 08 '23 at 14:25
  • @NickD: I am not sure -- I thought he wants to give the face attribute a variable instead of a value. E.g., (setq a b) then if (setq b xxx), the value of a will change to xxx as well. don't know whether I made this clear... – shynur Jul 08 '23 at 14:30
  • I think you are overcomplicating the question: and if so, the question is a frequent duplicate. See marked duplicate, although there are tens of othe instances. – NickD Jul 08 '23 at 14:36
  • @NickD: I guess this question is not about backquote, because OP uses backquote in his last question -- he knows how to use it. – shynur Jul 08 '23 at 14:47
  • 1
    We'll have to agree to disagree :-) – NickD Jul 08 '23 at 15:08
  • Just because he uses backquote (in a custom-set-faces moreover) does not mean that he knows how to use it: I suspect that if you look for custom-set-faces on Emacs SE you will always find it used with a backquote, so it is much more likely that he cut-and-pasted that construct without understanding it. – NickD Jul 08 '23 at 15:14