Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to define multiple emacs faces?
    primarykey
    data
    text
    <p>I'm trying to define some emacs font faces to do some custom highlighting. This seems to work when I define them individually:</p> <pre><code>(defface my-r-face `((t (:foreground "red"))) "Red highlight") (defvar m-r-face 'my-r-face "Red.") (defface my-g-face `((t (:foreground "green"))) "Green highlight") (defvar m-g-face 'my-g-face "Green.") (defface my-b-face `((t (:foreground "#0088ff"))) "Blue highlight") (defvar m-b-face 'my-b-face "Blue.") ....etc </code></pre> <p>However I have a few dozen of these and I want to define them all in one go from some kind of colour table:</p> <pre><code>(setq ctable '(("red" "r") ("orange" "o") ("yellow" "y") ("#88ff00" "gy") ("green" "g") ("#00ff88" "gc") ("cyan" "c") ("#0088ff" "bc") ("blue" "b") ("purple" "bm") ("magenta" "m") ("#ff0088" "rm") ("grey" "lg") ("white" "w") )) </code></pre> <p>My difficulty is with assembling the symbol names for each face, ie concatenating "my-" and "-face" onto either side of an entry from the table. I have discovered (intern) that can make a new symbol from a string, however this symbol is then not acceptable to (defface), as it seems what I am doing is equivalent to (defface 'my-r-face ..., and defface doesn't like the quoted symbol, and expects (defface my-r-face .. instead. My attempt is as follows:</p> <pre><code>(dolist (tpl ctable) (defvar (intern (concat "my-" (nth 1 tpl) "-face")) (quote (intern (concat "my-" (nth 1 tpl) "-face"))) "colour") (defface (intern (concat "my-" (nth 1 tpl) "-face")) `((t (:foreground ,(car tpl)))) "Highlight" :group 'fortran) ) </code></pre> <p>Running this results in </p> <pre><code>Lisp error: (wrong-type-argument symbolp (intern (concat "fegs-" (nth 1 tpl) "-face"))) (defvar (intern (concat "fegs-" ... "-face")) (quote (intern ...)) "colour") </code></pre> <p>Can anyone shed some light on what I'm doing wrong, or if I'm barking up the wrong tree entirely and there is a better way of doing this?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload