ianyepan / vscode-dark-plus-emacs-theme

An accurate port of the default Visual Studio Code Dark+ theme for Emacs
GNU General Public License v3.0
174 stars 17 forks source link

Custom face for keyword #27

Open AdrienWehrle opened 2 years ago

AdrienWehrle commented 2 years ago

Hi!

Thank you a lot for this theme, exactly what I was looking for!

Coming initially from Spyder, I like to have the self for Python classes standing out. I've changed faces for custom themes I wrote (basically one line), but never managed to get the keyword to take the comment face when commented (let's say a self commented would still be in its default color while the rest of the line would be e.g. in grey).

Could you help on that?

Thank you a lot in advance!

ianyepan commented 2 years ago

I think I understand what you mean, but I tested on my theme and it's working fine. "self" has its keyword color when uncommented, and uses the comment-face when commented:

image

How did you change the face for "self"?

AdrienWehrle commented 2 years ago

Yes everything is fine in your theme!

I would like to modify the default dark+ theme because it has "self" and class attributes in the same color (a light blue, see screenshot) and I would like to customize self to another color.

Screenshot from 2022-02-23 17-49-00

So my question was more about how to customize single keyword using your theme as a basis, and still keep the comment-face when commented?

ianyepan commented 2 years ago

So my question was more about how to customize single keyword using your theme as a basis, and still keep the comment-face when commented?

I'm afraid I don't know how. However, I don't think it's true that my theme "has self and class attributes in the same color". Look at the following screenshots, the first one has the default syntax highlighting, and the second one has tree-sitter-hl-mode turned on (for richer syntax highlighting). In both screenshots, self is distinct from class attribute colors. Just for reference, I pasted VSCode's screenshot too.

Emacs without tree-sitter

image

Emacs with tree-sitter

image

Visual Studio Code

image

AdrienWehrle commented 2 years ago

Thank you for your answer!

I don't think it's true that my theme "has self and class attributes in the same color".

I assumed your theme was the exact same as VS code dark+, but based on your three screenshots it doesn't look like it is?

ianyepan commented 2 years ago

I assumed your theme was the exact same as VS code dark+, but based on your three screenshots it doesn't look like it is?

Due to how VSCode and Emacs parse keywords and apply syntax highlighting differently, it's impossible to have an exact port. For instance, def and return are both recognized as simply the "keyword" font-face in Emacs, so having two different colors as in VSCode is not possible. Between blue and magenta, we must choose one and sacrifice the other.

AdrienWehrle commented 2 years ago

But what is preventing you from setting a custom font-face for .e.g return as below?

(defvar lawlist-print (make-face 'lawlist-print))
(set-face-attribute 'lawlist-print nil
  :background "#19232d" :foreground "#fab16c")

(defvar lawlist-keywords-01
  (concat "\\b\\(?:"
    (regexp-opt (list "print" ))
  "\\)\\b"))

(font-lock-add-keywords 'python-mode (list

  (list (concat
    "\\("lawlist-keywords-01"\\)") 1 'lawlist-print t)

  ))
ianyepan commented 2 years ago

Nothing really -- it didn't occur to me -- I'm more than happy to accept pull requests regarding setting custom font-faces!

AdrienWehrle commented 2 years ago

I will see if I can implement it properly and will do a PR if so!

ianyepan commented 2 years ago

Related: https://github.com/emacs-tree-sitter/elisp-tree-sitter/issues/141