nordtheme/emacs

Decorators highlighting in python

sivakov512 opened this issue Β· 8 comments

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

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

@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

@egnha Thanks for your explanation and examples, this looks like a really promising solution πŸš€
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 πŸ˜„ (and you can get a swaggy t-shirt πŸ‘• as recognition for free πŸ˜† )

egnha commented

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 :)

@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 πŸ˜„

egnha commented

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

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

@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.