Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Emacs theme with mode

Tags:

emacs

I would like to switch from 'solarized-dark (with my theme by default) to 'solarized-light when typing LATEX or Markdown. I'm using Emacs 24 and solarized from https://github.com/sellout/emacs-color-theme-solarized.

In my custom.el, I wrote the following lines :

(add-to-list 'custom-theme-load-path (make-plugin-path "color-theme-solarized"))
(load-theme 'solarized 1)

(add-hook 'markdown-mode-hook
      (lambda (frame)
        (set-frame-parameter frame 'background-mode 'light))
      )

But it doesn't work properly, i.e. loading a .md file does not make Emacs switch from 'dark to 'light solarized theme.

like image 355
ldc Avatar asked Sep 06 '25 03:09

ldc


1 Answers

Try this:

(add-hook 'markdown-mode-hook
  (lambda ()
    (set-frame-parameter (window-frame) 'background-mode 'dark)
    (enable-theme 'solarized)))

The main changes are calling window-frame to get the current frame and then enable-theme to make it active.

like image 177
Win Avatar answered Sep 08 '25 00:09

Win