3

Can't get colors to show up in the mode-line.

(eval-after-load "projectile"
  '(setq projectile-mode-line
         '(:eval (concat " Pj["
                         (propertize (projectile-project-name)
                                     'foreground "#81a2be")
                         "]"))))

The value gets evaluated correctly, because I see it change in the mode-line when I change pojectile projects, unfortunately it seems that string properties are stripped somewhere down the line. Any ideas how to fix this? Thx

EDIT projectile is unlikely to be at fault here cause I tried this with no effect:

(eval-after-load "lisp-mode"
  '(defadvice emacs-lisp-mode
       (after rename-modeline activate)
     (setq mode-name
           (propertize "El" 'foreground "#81a2be"))))

SOLUTION appears that I have been using the wrong property. Thanks to @politza this now works:

(eval-after-load "projectile"
  '(setq projectile-mode-line
         '(:eval (list " [Pj:"
                       (propertize (projectile-project-name)
                                   'face '(:foreground "#81a2be"))
                       "]"))))

One caveat is that replacing (list ...) with (concat ...) to actually concatenate strings breaks things. If anyone knows why, I'd be glad to learn.

  • Here is a link to a helpful example of how to customize the mode-line-format (including, adding coloring): amitp.blogspot.com/2011/08/emacs-custom-mode-line.html Since the projectile-mode-line is essentially the value of the minor-mode :lighter, you would likely need to customize the mode-line-format to achieve the coloring you desire -- i.e., attempting to add color to the value of a :lighter is likely the problem in this case. – lawlist Feb 1 '15 at 17:52
4

You are using the wrong property.

,----[ (info "(elisp) Special Properties") ]
|     `face'
|          This property controls the appearance of the text (*note Faces::).
`----

Example:

(propertize "Foo" 'face '(:foreground "orange"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.