You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/emacs-tree-sitter.org
+14-17Lines changed: 14 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,7 +191,7 @@ If, for some reason, you cannot update, the older binaries can be downloaded fro
191
191
:EXPORT_TITLE: Syntax Highlighting
192
192
:END:
193
193
194
-
Syntax highlighting is provided by the minor mode ~tree-sitter-hl-mode~. It overrides the regex-based highlighting provided by ~font-lock-mode~, using the syntax tree provided by ~tree-sitter-mode~. It is based on *tree queries*, a system for pattern-matching on Tree-sitter's syntax trees.
194
+
Syntax highlighting is provided by the minor mode ~tree-sitter-hl-mode~. It overrides the regex-based highlighting provided by ~font-lock-mode~, using the syntax tree provided by ~tree-sitter-mode~. It is based on [[* Queries][*tree queries*]], a system for pattern-matching on Tree-sitter's syntax trees.
195
195
196
196
It can be toggled in a buffer by the command ~tree-sitter-hl-mode~, or enabled through major mode hooks:
197
197
#+begin_src emacs-lisp
@@ -203,25 +203,22 @@ To enable it whenever possible (assuming the language major modes were already i
The package ~tree-sitter-langs~ provides syntax highlighting [[https://github.com/emacs-tree-sitter/tree-sitter-langs/tree/master/queries][queries]] for some languages:
208
-
- C
209
-
- C++
210
-
- *CSS*
211
-
- Go
212
-
- HTML
213
-
- Java
214
-
- *JavaScript*
215
-
- PHP
216
-
- *Python*
217
-
- Ruby
218
-
- *Rust*
219
-
- *TypeScript*
206
+
*** tree-sitter-langs
207
+
The package ~tree-sitter-langs~ provides syntax highlighting [[https://github.com/emacs-tree-sitter/tree-sitter-langs/tree/master/queries][queries]] for some languages.
208
+
209
+
Most of them are *intentionally different* from those from upstream repositories, which are more geared towards /GitHub's use cases/. We try to be more consistent with /Emacs's existing conventions/. The general principles are:
210
+
- Definitions and uses should be differentiated:
211
+
+ ~@function~ vs. ~@function.call~.
212
+
+ ~@method~ vs. ~@method.call~.
213
+
+ ~@type.parameter~ vs. ~@type.argument~.
214
+
- ~@variable~ and ~@variable.parameter~ should be applied only to declarations/definitions/bindings/mutations (/writes/), not usage (/reads/).
215
+
- Special faces should have high priority (placed earlier in the pattern list): ~@function.macro~, ~@type.builtin~, ~@variable.special~.
216
+
- Patterns whose internals may be highlighted should have low priority (placed towards the end). Example: strings with interpolation.
220
217
221
218
{{% notice info %}}
222
-
Most of the [[https://github.com/emacs-tree-sitter/tree-sitter-langs/tree/master/queries][highlighting queries]] in the bundle are very basic, as they are copies of those included in the [[https://github.com/tree-sitter][grammar repositories]]. Queries for languages written in bold have received additional work to leverage more of the querying system's expressiveness.
219
+
For some languages, the highlighting patterns are similar to those from upstream [[https://github.com/tree-sitter][grammar repositories]], instead of extensively following the above principles. They should be considered WIP.
223
220
224
-
Contributions to highlighting queries are welcome.
0 commit comments