3

I would like to do the following: load some theme when working on a particular kind of source file (say, Haskell), but elsewhere use a different "default" theme.

I naively imagine that this is achievable by loading the the default theme when exiting haskell-mode, but I don't know how to do things on exiting modes. Is this possible, or is there some better way to achieve what I want?

  • You certainly can do things when exiting a mode (change-major-mode-hook for major modes, and for minor modes just using its own mode hook), but from my reading that's not remotely what you want. Emacs maintains an arbitrary number of buffers, each of which can have different modes to any others, and switching buffers does not "exit" any of the modes which are active in the buffer you started in -- so reacting to mode changes doesn't help you with your problem. – phils Jul 18 '18 at 11:39
  • 1
    I suggest rephrasing your question in more general terms, to avoid this confusion. It sounds as if you would like your haskell-mode buffers (possibly along with certain other particular modes) to look different to other buffers. Try elaborating on that requirement, and what you would like to change specifically. – phils Jul 18 '18 at 11:40
  • ...by which I meant rewrite the question text (not just the title). Never mind. AFAIK you can't do this with the 'theme' system. I'm pretty sure themes are global. You can have buffer-local face remapping however, and that could take place in a mode hook, so I think there's a solution for you -- but this is why I asked you to be specific about what you want to change, so someone might be able to show you how to do those specific things. – phils Jul 18 '18 at 21:40
  • This is similar to this question: emacs.stackexchange.com/questions/41772. – Damien Cassou Jul 19 '18 at 9:12
  • @phils: Please consider posting your comment (about not being able to do this) as an answer. – Drew Sep 23 '18 at 0:04
2

AFAIK you can't do this with the 'theme' system. I'm pretty sure themes are global.

You can have buffer-local face remapping however, and that could take place in a mode hook, so I think there's a solution for you.

e.g.:

(defun my-haskell-faces ()
  "Buffer-local face remapping for `haskell-mode-hook'."
  (face-remap-add-relative 'default
                           :background "darkgreen"
                           :foreground "lightblue"))

(add-hook 'haskell-mode-hook #'my-haskell-faces)
  • thanks dude, i almost switched to vs code over this thing – Asalle Jun 16 at 19:43

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.