rougier / nano-emacs

GNU Emacs / N Λ N O - Emacs made simple
GNU General Public License v3.0
2.52k stars 195 forks source link

Proposal: Allow dark/light theme switching #26

Closed r-zip closed 1 year ago

r-zip commented 3 years ago

Unless I'm missing something, right now you have to specify either the -dark or -light command flag at startup to choose a theme. It would be more convenient (and more emacsy) to instead provide themes that can be activated using the load-theme command. What road blocks are there to adding this feature? I'd like to help.

mrzor commented 3 years ago

Because Emacs themes can run arbitrary code, I see no major obstacles to wrapping the existing nano theme in a file with (deftheme).

A concern would be to preserve the ability to have the theme code split between several files, as opposed to a single big one. I took a quick glance at the Custom Themes manual section, I have a feeling custom-load-path and the usual load-path have some un(?)documented intertwining.

Right now, faces are defined programmatically in nano-faces.el and derived from a set of base colors nano-base-colors.el. The nano "faces" are then applies to a whole range of other faces, in nano-theme.el.

I proposed #18 to move the face derivation code into custom get/set functions, but I wasn't able to formulate convincing arguments to answer Nicolas' reticence. I don't think it's actually blocking the introduction of a (deftheme).

Now, if your goal is simply to change the base colors, feel free to load any theme before you load nano.el, and nano should pick them up.

tefkah commented 3 years ago

I solved this like this

(defvar nano-theme-light-var t)
(defun nano-change-theme-dark ()
  (interactive)
  (nano-theme-set-dark)
  (nano-faces)
  (nano-theme))

(defun nano-change-theme-light ()
  (interactive)
  (nano-theme-set-light)
  (nano-faces)
  (nano-theme))

(defun nano-change-theme ()
  (interactive)
  (if nano-theme-light-var (nano-change-theme-dark) (nano-change-theme-light))
  (setq nano-theme-light-var (not nano-theme-light-var)))
rougier commented 3 years ago

Actually, you could even rename your nano-change-theme into nano-toggle-theme. Could you make a PR?