I want to change some attributes for the mode-line using elisp file calls. But I want to use exclusively the code that I write myself, without having emacs write to my init file.

Although I have been using both set-face-attribute and custom-set-faces, what would be preferred in my case ?

(set-face-attribute 'mode-line nil
  :background "#ff4500" 
  :foreground "#ffffff")


 `(mode-line ((t ( :background ,bglamp
                   :foreground ,fglamp)))))

1 Answer 1

  • If you want to change the appearance of face mode-line for your personal use, and for future Emacs sessions, then use Customize - in this case, customize-face.

  • If you want to change its appearance only for the current Emacs session, use either one.

  • If you want to change the appearance using Elisp, e.g., in a library, then use set-face-attribute.

There's nothing special about changing faces in this question, as posed. And nothing special about face mode-line. This is really just the question about when to use Customize versus Elisp.

There's also a question about whether to use Elisp in your init file or use Customize, putting the setting in your custom-file. Different people prefer the one or the other. Generally, IMO, you should leverage Customize - that's what it's for, whether you use its functions in Lisp code or you use the Customize UI. And it's a good idea to confine Customize to a custom-file, not let it write to your init file.

This is all covered in other Q&A on this site and elsewhere... Just search tags [customize] etc.

For example, this covers the general Lisp-vs-Customize question for user options. The same applies to faces.

  • I want to use elisp. I use the above code in elisp code already,
    – Dilna
    Jul 7, 2023 at 21:30
  • I do not want emacs to write to my init file at all. I only want the elisp code I actually write to be included in the emacs setup configuration.
    – Dilna
    Jul 7, 2023 at 21:33
  • Put all such info in the question. Put your code in a separate file from your init file, and require it from the init file. (Customize does that automatically, and it doesn't make mistakes like we do - you just have to set variable custom-file...)
    – Drew
    Jul 7, 2023 at 21:35
  • I shall settle with set-face-attribute as instructed.
    – Dilna
    Jul 7, 2023 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.