Less Redundancy Removal

I want to define a bunch of faces for different characters, as shown below:

(defface char-face-a '((((type tty) (class color)) (:background "yellow" :foreground "black")) (((type tty) (class mono)) (:inverse-video t)) (((class color) (background dark)) (:background "yellow" :foreground "black")) (((class color) (background light)) (:background "yellow" :foreground "black")) (t (:background "gray"))) "Face for marking up A's" :group 'char-faces) (defface char-face-b '((((type tty) (class color)) (:background "red" :foreground "black")) (((type tty) (class mono)) (:inverse-video t)) (((class color) (background dark)) (:background "red" :foreground "black")) (((class color) (background light)) (:background "red" :foreground "black")) (t (:background "gray"))) "Face for marking up B's" :group 'char-faces) ... ... 

In any case, to avoid explicitly writing all defface definitions and making the code less redundant? (I know make-face , but it seems deprecated and cannot set attributes according to different types of terminals, as defface does.)

+4
source share
2 answers

What about a macro and a loop that works with the display of ↔ colors suffixes:

 (defmacro brian-def-char-face (letter backgrnd foregrnd) `(defface ,(intern (concat "brian-char-face-" letter)) '((((type tty) (class color)) (:background ,backgrnd :foreground ,foregrnd)) (((type tty) (class color)) (:inverse-video t)) (((class color) (background dark)) (:foreground ,foregrnd :background ,backgrnd)) (((class color) (background light)) (:foreground ,foregrnd :background ,backgrnd)) (t (:background "gray"))) ,(concat "Face for marking up " (upcase letter) "'s"))) (let ((letcol-alist '((s . (white black)) (t . (black yellow)) (u . (green pink))))) (loop for elem in letcol-alist for l = (format "%s" (car elem)) for back = (format "%s" (cadr elem)) for fore = (format "%s" (caddr elem)) do (eval (macroexpand `(brian-def-char-face ,l ,back ,fore))))) 

Gives you new facets:

brian-char-face-s , brian-char-face-t and brian-char-face-u

Now you just need to save the list of letters ↔ color matching and, possibly, expand the macro to support other facial properties (if desired).

+2
source
  • make-face is not outdated at all, AFAICT.

  • defface can use inheritance - see the face :inherit . I don't know if this helps in your particular context.

+4
source

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


All Articles