nordtheme / emacs

An arctic, north-bluish clean and elegant Emacs theme.
https://www.nordtheme.com/ports/emacs
MIT License
492 stars 64 forks source link

Decorators highlighting in python #52

Open sivakov512 opened 7 years ago

sivakov512 commented 7 years ago

What about the highlighting of Python decorators with color different from classes and methods? For example screenshots from Emacs (first) and Visual Studio Code (second)

image image

arcticicestudio commented 7 years ago

I've tried to add the py-decorator-face face, but it seems to have no effect because the decorator inherits from the font-lock-type-face.

egnha commented 6 years ago

@sivakov512: You can "fontify" decorators by adding a regular expression for them to the keyword list for font locking. (This has nothing to do with Nord theme, specifically, cf. docs on font locking.)

For example, try adding the following to your Emacs config:

(add-hook 'python-mode-hook
      (lambda ()
        (font-lock-add-keywords
         nil
         '(("\\(^@[^(]*\\)" 1 'font-lock-preprocessor-face)))))

With an optional customization of the preprocessor face

(set-face-attribute 'font-lock-preprocessor-face nil
  :weight 'normal
  :foreground "#B48EAD")

you should get something like this (aside from further custom coloring of constant and keyword faces):

screen shot 2018-10-01 at 12 26 18

arcticicestudio commented 6 years ago

@egnha Thanks for your explanation and examples, this looks like a really promising solution :rocket: Would you like to submit a PR for this? Nord uses nord12 for annotations/decorators if you'd like to go for it.

Also Hacktoberfest started to today, I'd really appreciate some contributions to get some things done during this month :smile: (and you can get a swaggy t-shirt :shirt: as recognition for free :laughing: )

egnha commented 6 years ago

I’d be glad to submit a PR (though I won’t be able to get around to that until the weekend). Thanks for the 👕 offer :)

arcticicestudio commented 6 years ago

@egnha Take your time, there's no time pressure. You can register on their site by simply logging in with your GitHub account (via OAuth) and as soon as you submited 5 PRs in october to any open source project on GitHub they'll send you a T-Shirt and some other swag like a certificate of participation :smile:

egnha commented 6 years ago

In the meantime, a more robust regex to identify decorators:

(add-hook 'python-mode-hook
      (lambda ()
        (font-lock-add-keywords
         nil
         '(("^[[:space:]]*\\(@[^(#[:space:]\n]*\\)" 1 'font-lock-preprocessor-face)))))
egnha commented 5 years ago

@arcticicestudio, unfortunately, I won't have time to submit a PR. Sorry.

arcticicestudio commented 5 years ago

@egnha No problem, I'm also busy with other urgent tasks and projects, but I'll try to test and put your code into a PR as soon as there is some time.