Emacs Mode color change based on native mode

I like to see if there is a way to change the base color area of ​​the mode and background in the main mode,

I thought to add logic to

(add-hook 'after-change-major-mode-hook 

But I have no experience with emacs lisp to make such a change. Here is the logic:

 switch major-mode: case "emacs-lisp-mode": (set-face-foreground 'mode-line "ivory") (set-face-background 'mode-line "DarkOrange2") case "ruby-mode": (set-face-foreground 'mode-line "white") (set-face-background 'mode-line "red") ... default: (set-face-foreground 'mode-line "black") (set-face-background 'mode-line "white") end switch 

Thank you very much in advance!

+6
source share
2 answers

You probably want something like:

 (add-hook 'emacs-lisp-mode-hook (lambda () (face-remap-add-relative 'mode-line '((:foreground "ivory" :background "DarkOrange2") mode-line)))) 

You might want to use face-remap for a mode-line-inactive face.

+9
source

The "logic" you are talking about is something like this:

 (add-hook 'after-change-major-mode-hook 'my-set-mode-line-colors) (defvar my-mode-line-colors '((emacs-lisp-mode :foreground "ivory" :background "DarkOrange2") (ruby-mode :foreground "white" :background "red"))) (defun my-set-mode-line-colors () (face-remap-add-relative 'mode-line (list (or (cdr (assq major-mode my-mode-line-colors)) '(:foreground "black" :background "white")) 'mode-line))) 

Alternatively, you can do this from mode-dependent hooks, as Stefan suggests.

+3
source

All Articles