Domanda

Sto cercando di definire alcuni facce dei font Emacs per fare qualche evidenziazione personalizzata.Questo sembra funzionare quando li definisco individualmente:

(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
.

Comunque ne ho alcune dozzine di questi e voglio definirli tutti in una volta da qualche tipo di tavolo colorato:

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

La mia difficoltà è con il montaggio dei nomi dei simboli per ogni viso, cioè concatenare "my-" e "-faccia" su entrambi i lati di una voce dalla tabella.Ho scoperto (tirocere) che può creare un nuovo simbolo da una stringa, tuttavia questo simbolo non è quindi accettabile per (sblocco), come sembra quello che sto facendo è equivalente a (defface 'my-r-faccia ...,e sgombra non piace il simbolo citato e si aspetta (sblocco my-r-faccia .. invece. Il mio tentativo è il seguente:

(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)
)
.

Esecuzione di questo risultato in

Lisp error: (wrong-type-argument symbolp (intern (concat "fegs-" (nth 1 tpl) "-face")))
  (defvar (intern (concat "fegs-" ... "-face")) (quote (intern ...)) "colour")
.

Qualcuno può far luce su ciò che sto facendo male, o se sto abbaiando per l'albero sbagliato interamente e c'è un modo migliore di fare questo?

Grazie.

È stato utile?

Soluzione

Defvar è un modulo speciale, DefFace è una macro (quindi gli argomenti sono passati non sempre preside).Hai provato a usare qualcosa nella linea di

(eval `(defface ,(intern "foo") '((t (:foreground "red"))) "Highlight" :group 'fortran))

(eval `(defvar ,(intern "bar")))
.

Altri suggerimenti

È possibile evitare eval:

(defconst my-ctable '(...))

(defmacro my-init-cfaces ()
  `(progn
    ,@(mapcar (lambda (tpl)
               `(defface ,(intern (format "my-%s-face" (nth 1 tpl)))
                  '((t :foreground ,(car tpl)))
                  ,(format "Face for color %s." (car tpl))
                  :group 'fortran))
              my-ctable)))

(my-init-cfaces)
.

Il codice completo che ha funzionato alla fine è il seguente:

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

(dolist (tpl ctable)
  (let ((fname (concat "fegs-" (nth 1 tpl) "-face")))
    (eval `(defface ,(intern fname) '((t (:foreground ,(car tpl)))) "Highlight" :group 'fortran))
    (eval `(defvar ,(intern fname) ',(intern fname)))
  )
)
.

La mia linea Defvar è leggermente diversa in quanto consente di raccogliere il viso dal codice di evidenziazione altrove come variabile globale.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top