jcinnamond / old-emacs

My emacs config
1 stars 0 forks source link

How to conditionally "fix" nord theme comments #2

Open mandarvaze opened 7 years ago

mandarvaze commented 7 years ago

I know this is a personal emacs config, as such someone else should NOT open an issue against it. But I have a query, and I thought this might be the best way to communicate with you.

I use spacemacs, and have list of dark/light spacemacs themes. Just recently, I discovered and added nord theme to the list. I "switch" to nord via SPC T n (cycle thru the themes) Off course, since I set nord I haven't gone back to spacemacs-dark , but I might.

So is there a way to set the set the "faces" for the comments and vertical bar only if the theme is set to nord ? (As you may have guessed, I am relatively new to emacs and lisp)

jcinnamond commented 7 years ago

Opening issues against my emacs config is totally fine.

It's an interesting question, and I don't immediately know the answer. As far as I can tell from asking emacs and google, there is no way to see which themes have been loaded. So I can't write something like if nord is loaded then apply these fixes. However I could guess at nord being loaded by checking the existing comment foreground color. If it's set to nord3 then there's a good chance that nord is loaded and that I want to change it.

I can get the comment color using the face-attribute function. (You can type C-h f face-attribute to get emacs' built in documentation for this.)

(face-attribute 'font-lock-comment-face :foreground)

This returns a string containing #81A1C1 as I've overridden it, but with unmodified nord loaded it would return #4C566A. From this we could add a method to check for nord by seeing if this is the comment color:

(defun nord-loaded-p ()
  "Check if the nord theme is loaded by looking at some of the colors"
  (string-equal (face-attribute 'font-lock-comment-face :foreground) "#434C5E"))

So the new block in the config would look something like:

(defun nord-loaded-p ()
  "Check if the nord theme is loaded by looking at some of the colors"
  (string-equal (face-attribute 'font-lock-comment-face :foreground) "#434C5E"))

(if (nord-loaded-p)
    (progn
      (set-face-attribute 'font-lock-comment-face nil
              :foreground "#81A1C1") ; nord9
      (set-face-attribute 'vertical-border nil
              :foreground "#EBCB8B"))) ; nord13

To check the background color as well you could use and in nord-loaded-p.

mandarvaze commented 7 years ago

@jcinnamond Thanks for detailed answer. Yes, this definitely helps

💯