¿Cómo cambio partes de un tema personalizado?


21

Estoy usando uno de los temas personalizados predefinidos que vienen incluidos con Spacemacs (zenburn).

¿Cómo puedo modificar partes específicas del tema, por ejemplo, simplemente cambiar el color de fuente utilizado para los comentarios?


2
¿Estás seguro de que te refieres al tema de color y no al tema personalizado ? Si no está utilizando un tercero, color-theme.elprobablemente se refiera a un tema personalizado. En ese caso, edite su pregunta en consecuencia. Ver Color y Temas personalizados .
Dibujó

Respuestas:


13

Estoy a favor de usar custom-theme-set-facespara redefinir cómo el tema muestra una cara en particular, por ejemplo,

(custom-theme-set-faces
 'zenburn
 '(font-lock-comment-face ((t (:foreground "#DFAF8F"))))
 '(font-lock-comment-delimiter-face ((t (:foreground "#DFAF8F")))))

Para el caso específico de zenburn, el tema en sí define varios colores y una macro en la que están vinculados a nombres de variables, por lo que puede escribir lo anterior como:

(zenburn-with-color-variables
  (custom-theme-set-faces
   'zenburn
   `(font-lock-comment-face ((t (:foreground ,zenburn-orange))))
   `(font-lock-comment-delimiter-face ((t (:foreground ,zenburn-orange))))))

¿Dónde se supone que escribirás este código? en .spacemacs?
ChiseledAbs

1
Ni idea, lo siento; No uso Spacemacs. Sin embargo, en principio, todo lo que necesita hacer es evaluar el código en algún momento después de que zenburnse haya cargado el tema.
Aaron Harris

8

En spacemacs, instale la capa theming, consulte https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Bthemes/theming

Por ejemplo, tengo lo siguiente recortado en dotspacemacs/user-initmi .spacemacspara ajustar el fondo y el color del lino del gruvbox y el tema de la luz solarizada:

  (setq theming-modifications '(
    ;; requires the theming layer
    (gruvbox
       (default :background "#1D2021" :foreground "#fdf4c1")
       (linum :background "#000000" :foreground "#878787")
       (fringe  :background "#000000")
       (linum-relative-current-face :inherit (shadow default) :background "#3C3836" :foreground "#ff0000")
       (font-lock-comment-face :slant italic)
    )
    (solarized-light
     (linum :background "#DBCDA7" :foreground "#40371F")
       (fringe :background "#DBCDA7")
       (font-lock-comment-face :slant italic)
       )
))

4

Agregué consejos a la función load-theme para anular ciertas caras, de esa manera puede continuar usando load-theme de forma normal para seleccionar un tema y aplicará las anulaciones automáticamente.

(defadvice load-theme (after theme-set-overrides activate)
  "Set override faces for different custom themes."
  (dolist (theme-settings theme-overrides)
    (let ((theme (car theme-settings))
          (faces (cadr theme-settings)))
      (if (member theme custom-enabled-themes)
          (dolist (face faces)
            (custom-theme-set-faces theme face))))))

(defcustom theme-overrides nil
  "Association list of override faces to set for different custom themes.")

(defun alist-set (alist-symbol key value)
  "Set VALUE of a KEY in ALIST-SYMBOL."
  (set alist-symbol
        (cons (list key value) (assq-delete-all key (eval alist-symbol)))))

; override some settings of the ample-flat theme
(alist-set 'theme-overrides 'ample-flat '(
                                          (default ((t (:background "gray12" :foreground "#bdbdb3"))))
                                          (mode-line ((t (:background "cornsilk4" :foreground "#222" :inherit 'variable-pitch))))
                                          (outline-2 ((t (:inherit font-lock-keyword-face)))) ; blueish
                                          (outline-3 ((t (:inherit font-lock-comment-face)))) ; brownish
                                          (outline-4 ((t (:inherit font-lock-string-face)))) ; orangeish
                                          (org-table ((t (:inherit fixed-pitch :height 0.7 :foreground "#887"))))
                                          (org-formula ((t (:inherit org-table :foreground nil))))
                                          ))

Funciona, y sería bueno tenerlo como parte de la interfaz, pero probablemente sea más simple hacer una función para cada tema que use y llamar a custom-theme-set-faces después de cargarlo.

(defun ample-flat ()
  (interactive)
  (mapc #'disable-theme custom-enabled-themes) ; clear any existing themes
  (load-theme 'ample-flat t)
  (custom-theme-set-faces 'ample-flat 
                          '(default ((t (:background "gray12" :foreground "#bdbdb3"))))
                          '(mode-line ((t (:background "cornsilk4" :foreground "#222" :inherit 'variable-pitch))))
                          '(outline-2 ((t (:inherit font-lock-keyword-face)))) ; blueish
                          '(outline-3 ((t (:inherit font-lock-comment-face)))) ; brownish
                          '(outline-4 ((t (:inherit font-lock-string-face)))) ; orangeish
                          '(org-table ((t (:inherit fixed-pitch :height 0.7 :foreground "#887"))))
                          '(org-formula ((t (:inherit org-table :foreground nil))))
                          ))

(ample-flat)

0

Ejemplo de lo que hice para editar spacemacs-dark, eliminando un par de negritas que no me gustan:

  ;; on dotspacemacs/user-config:

  ;; configure spacemacs-dark theme, specifically removing bolds
  (let
      ((func "#d75fd7")
       (keyword "#4f97d7")
       (type "#ce537a"))

    (custom-theme-set-faces
     'spacemacs-dark
     `(font-lock-function-name-face ((t (:foreground ,func :inherit normal))))
     `(font-lock-keyword-face ((t (:foreground ,keyword :inherit normal))))
     `(font-lock-type-face ((t (:foreground ,type :inherit normal))))
     )
    )

0

Puede ser más fácil para usted simplemente usar SPC SPC custom-theme-visit-theme, buscar gruvbox, hacer sus ediciones allí y luego colocarlas (load-file "~/.emacs.d/gruvbox-theme.el")en su dotspacemacs/user-configfunción.

Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.