2

As a theme I am using Dracula.

For example I have this example code piece coloring:

enter image description here

When cursor is on terminate() and I typed M-x customize-face it is linked to (default ‘all faces’). I am not sure which variable's color should I change.


This is example coloring in the SublimeText where functions such as: terminate, is_internet_on, error, session_start_msg has a different color rather than white. I was wondering is it possible to achive this in emacs as well?

enter image description here

1 Answer 1

2
+50

I know one interesting solution, emacs-tree-sitter which is the Emacs implementation of the general parser tree-sitter used in Atom.

It's quite easy to use and work out of the box, this is how it look the function with the modus-vivendi theme: enter image description here

As tree-sitter inherit from the font-lock default variables (define by the Dracula theme) for Emacs basic, stuff like the function name (in this case tools), is enough to call customize-face and then font-lock-function-name-face. BUT if you want to change more specific face colour (method,function call) those are define by tree-sitter, there is two main ways to achieve this, with the built in Emacs font customization, or setting the variables manually The first way:

  • Get the function at point (where the cursor is) with face-at-point - Call customize-face with the face name (keep in mind that it may scape some characters like the dot), and change the colours clicking in Show all attributes.

  • Same as the first one - Use the function face-spec-set for every face you want to change, in this case, the method call face: (face-spec-set 'tree-sitter-hl-face:method\.call '((t (:inherit tree-sitter-hl-face:function\.call :foreground "red"))))

In this case, I put the face in red color.

For more information, emacs-tree-sitter documentation

5
  • What should I do to change the color of functions using tree-sitter ?
    – alper
    Commented Nov 8, 2020 at 12:16
  • Also currently I am using Dracula theme; can these change overwrite into the default theme ?
    – alper
    Commented Nov 8, 2020 at 12:21
  • As tree-sitter inherit from the font-lock default variables (define by the Dracula theme) for Emacs basic, stuff like the function name (in this case tools), is enough to call customize-face and then font-lock-function-name-face. BUT if you want to change more specific face color (method,function call) those are define by tree-sitter, there is two main ways to achieve this, with the built in emacs font customization, or setting the variables manually,cont
    – Fermin MF
    Commented Nov 9, 2020 at 7:56
  • The first way: - Get the function at point (where the cursor is) with face-at-point - Call customize-face with the face name (keep in mind that it may scape some characters like the dot), and change the colors clicking in Show all attributes The second way: - Same as the first one - Use the function face-spec-set for every face you want to change, in this case, the mehtod call face: (face-spec-set 'tree-sitter-hl-face:method\.call '((t (:inherit tree-sitter-hl-face:function\.call :foreground "red")))) In this case, I put the face in red color.
    – Fermin MF
    Commented Nov 9, 2020 at 7:57
  • 1
    You should add these comments as an edit to your answer. Comments can disappear.
    – NickD
    Commented Nov 16, 2020 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.