0

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")

or

(custom-set-faces
 `(mode-line ((t ( :background ,bglamp
                   :foreground ,fglamp)))))
shynur
  • 4,065
  • 1
  • 3
  • 23
Dilna
  • 1,173
  • 3
  • 10

1 Answers1

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.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • I want to use elisp. I use the above code in elisp code already, – Dilna Jul 07 '23 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 07 '23 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 07 '23 at 21:35
  • I shall settle with `set-face-attribute` as instructed. – Dilna Jul 07 '23 at 21:47