dbordak / telephone-line

A new implementation of Powerline for Emacs
GNU General Public License v3.0
550 stars 51 forks source link

Cannot use custom face #55

Closed shackra closed 6 years ago

shackra commented 6 years ago

For some reason I cannot use a custom face for my segment, I'm getting this error when I make something that sets a value in the variable venv-current-name:

Error during redisplay: (eval (telephone-line-add-subseparators (quote ((lambda (face) (telephone-line-raw venv-current-name)))) telephone-line-cubed-hollow-right (quote orange))) signaled (wrong-type-argument listp shackra-orange)
Error during redisplay: (eval (telephone-line-separator-render telephone-line-cubed-right (telephone-line-face-map (quote accent)) (telephone-line-face-map (quote orange)))) signaled (wrong-type-argument listp shackra-orange)
Error during redisplay: (eval (telephone-line-separator-render telephone-line-cubed-right (telephone-line-face-map (quote orange)) (telephone-line-face-map (quote nil)))) signaled (wrong-type-argument listp shackra-orange)

Here is my configuration:

(use-package telephone-line
  :preface (defun shackra/vc-state ()
             (if vc-mode
                 (vc-state (buffer-file-name (current-buffer)))
               nil))
  :init
  ;; define una nueva cara
  (defface shackra-orange '((t (:foreground "white" :background "orange"))) "")
  ;; Informa a telephine-line sobre la existencia de la nueva cara, llamada `orange'
  ;; Cambia el estilo de los separadores
  (setq telephone-line-primary-left-separator 'telephone-line-cubed-left
        telephone-line-secondary-left-separator 'telephone-line-cubed-hollow-left
        telephone-line-primary-right-separator 'telephone-line-cubed-right
        telephone-line-secondary-right-separator 'telephone-line-cubed-hollow-right)
  (setf telephone-line-height 40)
  (custom-set-faces
   '(mode-line ((t (:box nil))))
   '(mode-line-inactive ((t (:box nil))))
   '(mode-line-highlight ((t (:box nil)))))
  :config
  (add-to-list 'telephone-line-faces '(orange . shackra-orange))
  (telephone-line-defsegment* shackra-buffer-vc-modified-segment ()
    (list (cond ((buffer-modified-p)
                 (propertize (format " %s" (all-the-icons-faicon "pencil")) 'face `(:height 1.3 :family ,(all-the-icons-faicon-family))
                             'display '(raise -0.1) 'help-echo "Buffer modificado."))
                ((eq (shackra/vc-state) 'edited)
                 (propertize (format " %s?" (all-the-icons-faicon "cloud-upload")) 'face `(:height 1.3 :family ,(all-the-icons-faicon-family))
                             'display '(raise -0.1) 'help-echo "Cambios sin registrar.")))
          (cond ((eq (shackra/vc-state) 'missing)
                 (propertize (format " %s " (all-the-icons-faicon "trash")) 'face `(:height 1.3 :family ,(all-the-icons-faicon-family))
                             'display '(raise -0.1) 'help-echo "Archivo sólo existe en VCS, no en el disco duro."))
                ((eq (shackra/vc-state) 'ignored)
                 (propertize (format " %s " (all-the-icons-faicon "ban")) 'face `(:height 1.3 :family ,(all-the-icons-faicon-family))
                             'display '(raise -0.1) 'help-echo "Archivo ignorado"))
                ((eq (shackra/vc-state) 'added)
                 (propertize (format " %s " (all-the-icons-faicon "plus")) 'face `(:height 1.3 :family ,(all-the-icons-faicon-family))
                             'display '(raise -0.1) 'help-echo "Archivo será registrado en VCS en el siguiente commit."))
                ((eq (shackra/vc-state) 'unregistered)
                 (propertize (format " %s " (all-the-icons-faicon "question")) 'face `(:height 1.3 :family ,(all-the-icons-faicon-family))
                             'display '(raise -0.1) 'help-echo "Archivo sin registrar al VCS.")))))

  (telephone-line-defsegment shackra-virtualenv-name () venv-current-name)

  (telephone-line-defsegment shackra-line-buffer-segment ()
    (telephone-line-raw mode-line-buffer-identification t))

  (telephone-line-defsegment* shackra-vc-info ()
    (when vc-mode
      (cond ((string-match "Git[:-]" vc-mode)
             (let ((branch (mapconcat 'concat (cdr (split-string vc-mode "[:-]")) "-")))
               (concat
                (propertize (format " %s" (all-the-icons-faicon "git-square" :v-adjust -0.1)) 'face `(:foreground "orange" :height 1.3 :family ,(all-the-icons-octicon-family)))
                (propertize (format "%s" branch) 'face `(:foreground "orange")))))
            (t (format "%s" vc-mode)))))
  (telephone-line-defsegment* shackra-flycheck-status ()
    (let* ((text (pcase flycheck-last-status-change
                   (`finished (if flycheck-current-errors
                                  (let ((count (let-alist (flycheck-count-errors flycheck-current-errors)
                                                 (+ (or .warning 0) (or .error 0)))))
                                    (propertize (format " ✖ %s problema%s" count (if (> count 1) "s" "")) 'face `(:foreground "orange")))
                                (propertize " ✔ Sin problemas" 'face `(:foreground "dark grey"))))
                   (`running     (propertize " ⟲ En ejecución" 'face `(:foreground "deep sky blue")))
                   (`no-checker  (propertize " ⚠ No existe revisor" 'face `(:foreground "dim grey")))
                   (`not-checked (propertize " ✖ Sin revisar" 'face `(:foreground "dim grey")))
                   (`errored     (propertize " ⚠ Error" 'face `(:foreground "tomato")))
                   (`interrupted (propertize " ⛔ Interrumpido" 'face `(:foreground "tomato")))
                   (`suspicious  ""))))
      (propertize text
                  'help-echo "Muestra errores detectados por Flycheck"
                  'local-map (make-mode-line-mouse-map
                              'mouse-1 (lambda () (interactive) (flycheck-list-errors))))))

  (setf telephone-line-lhs
        '((accent . (shackra-line-buffer-segment shackra-buffer-vc-modified-segment))
          (nil .  (shackra-vc-info shackra-flycheck-status))))

  (setf telephone-line-rhs '((nil . (telephone-line-misc-info-segment telephone-line-major-mode-segment))
                             (orange . (shackra-virtualenv-name))
                             (accent . (telephone-line-position-segment))))
  (telephone-line-mode 1))
dbordak commented 6 years ago

Items in the face map have to be of the form (symbol . (active-face . inactive-face)), you only have the one face... I think that's the problem here?

shackra commented 6 years ago

Are you referring to (add-to-list 'telephone-line-faces '(orange . shackra-orange)) right? I was using your rainbow example as reference and maybe I didn't understood something about the said example

dbordak commented 6 years ago

Yeah. Instead of shackra-orange, you need a pair of two faces (e.g. (shackra-orange . shackra-orange) would work). The first is the face used on the active window, the second is used on any inactive ones.

shackra commented 6 years ago

Doing (add-to-list 'telephone-line-faces '(my-orange . (shackra-orange . shackra-orange)) fixed my issue!