I find myself applying the same attributes to multiple faces quite often:

(set-face-attribute 'sml/line-number nil :background zenburn/bg-1 :foreground zenburn/fg :weight 'unspecified)
(set-face-attribute 'sml/numbers-separator nil :background zenburn/bg-1 :foreground zenburn/fg :weight 'unspecified)
(set-face-attribute 'sml/col-number nil :background zenburn/bg-1 :foreground zenburn/fg :weight 'unspecified)

How can regroup those face attributes and apply them to a list of faces ?

I've tried to define a group:

(defgroup me/sml-numbers '('sml/line-number 'sml/numbers-separator 'sml/col-number)
  "Faces for numbers within `smart-mode-line'.")

But set-face-attribute takes a face as parameter:

set-face-attribute: Invalid face: me/sml-numbers

1 Answer 1

  1. This has nothing to do with defgroup, which is about defcustom :group. See the Elisp manual, node Group Definitions.

  2. If you insist on grouping here then you need to iterate over the faces using a function that calls set-face-attribute on a face (variable) with those other argument values.

For example:

(dolist (face  '(sml/line-number sml/numbers-separator sml/col-number))
  (set-face-attribute face nil
                      :background zenburn/bg-1
                      :foreground zenburn/fg
                      :weight 'unspecified))

But what have you really gained by this iteration? Now if you had 500 such settings to make then maybe...

  • My point was to be able to change my smart-mode-line faces with a single line, rather than many. It wouldn't have accomplished much (I won't be changing things too frequently), it was more for educational purposes :), thanks. Commented Apr 8, 2015 at 18:44

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.