The capture name could also be a function, in which case (NODE
OVERRIDE START END) is passed to the function for fontification. START
-and END is the start and end of the region to be fontified. The
+and END are the start and end of the region to be fontified. The
function should only fontify within that region. The function should
also allow more optional arguments with (&rest _), for future
extensibility. For OVERRIDE check out the docstring of
The manual explains how to read grammar files in the bottom of section
"Tree-sitter Language Definitions".
-** Debugging queires
+** Debugging queries
If your query has problems, use ‘treesit-query-validate’ to debug the
query. It will pop a buffer containing the query (in text format) and
When the indentation process starts, point is at the BOL of a line, we
want to know which column to indent this line to. Let NODE be the node
at point, we pass this node to the MATCHER of each rule, one of them
-will match the node (eg, "this node is a closing bracket!"). Then we pass
-the node to the ANCHOR, which returns a point, eg, the BOL of the
+will match the node (eg, "this node is a closing bracket!"). Then we
+pass the node to the ANCHOR, which returns a point, eg, the BOL of the
previous line. We find the column number of that point (eg, 4), add
OFFSET to it (eg, 0), and that is the column we want to indent the
current line to (4 + 0 = 4).
When writing indent rules, you can use ‘treesit-check-indent’ to
check if your indentation is correct. To debug what went wrong, set
-‘treesit--indent-verboase’ to non-nil. Then when you indent, Emacs
+‘treesit--indent-verbose’ to non-nil. Then when you indent, Emacs
tells you which rule is applied in the echo area.
#+begin_src elisp
Tree-sitter has default implementations for
‘beginning-of-defun-function’ and ‘end-of-defun-function’. So for
-ordinary languages, it is suffice to set ‘treesit-defun-type-regexp’
+ordinary languages, it is enough to set ‘treesit-defun-type-regexp’
to something that matches all the defun struct types in the language,
and call ‘treesit-major-mode-setup’. For example,
If you have an imenu implementation, set ‘which-func-functions’ to
nil, and which-func will automatically use imenu’s data.
-If you want independent implementation for which-func, you can find
-the current function by going up the tree and looking for the
+If you want an independent implementation for which-func, you can
+find the current function by going up the tree and looking for the
function_definition node. See the function below for an example.
Since Python allows nested function definitions, that function keeps
going until it reaches the root node, and records all the function
* More features?
Obviously this list is just a starting point, if there are features in
-the major mode that would benefit a parse tree, adding tree-sitter
+the major mode that would benefit from a parse tree, adding tree-sitter
support for that would be great. But in the minimal case, just adding
font-lock is awesome.
(defun treesit--merge-ranges (old-ranges new-ranges start end)
"Merge OLD-RANGES and NEW-RANGES, discarding ranges between START and END.
-OLD-RANGES and NEW-RANGES are lists of cons of the form (BEG . END). When
-merging the two ranges, if a range in OLD-RANGES intersects with
+OLD-RANGES and NEW-RANGES are lists of cons of the form (BEG . END).
+When merging the two ranges, if a range in OLD-RANGES intersects with
another range in NEW-RANGES, discard the one in OLD-RANGES and
keep the one in NEW-RANGES. Also discard any range in OLD-RANGES
that intersects the region marked by START and END.
`font-lock-maximum-decoration' controls which levels are
activated.
-Inside each sublist are feature symbols, which corresponds to the
+Inside each sublist are feature symbols, which correspond to the
:feature value of a query defined in `treesit-font-lock-rules'.
Removing a feature symbol from this list disables the
corresponding query during font-lock.
string-interpolation, comment, doc, string, operator, property,
preprocessor, escape-sequence, key (in key-value pairs). Major
modes are free to subdivide or extend on these common features.
-See the manual for more explanations on some of the feature.
+See the manual for more explanations on some of the features.
For changes to this variable to take effect, run
`treesit-font-lock-recompute-features'.")
:feature \\='script
\"(script_element) @font-lock-builtin-face\")
-For each QUERY, a :language keyword and a :feature keyword is
+For each QUERY, a :language keyword and a :feature keyword are
required. Each query's :feature is a symbol summarizing what the
query fontifies. It is used to allow users to enable/disable
certain features. See `treesit-font-lock-kind-list' for more.
(- (treesit-node-end node) (treesit-node-start node)))
(defvar-local treesit--font-lock-fast-mode nil
- "If this variable is t, change the way we query so its faster.
+ "If this variable is t, change the way we query so it's faster.
This is not a general optimization and should be RARELY needed!
See comments in `treesit-font-lock-fontify-region' for more
detail.")
;; applied by regexp-based font-lock. The clipped part will be
;; fontified fine when Emacs fontifies the region containing it.
;;
-(defun treesit-font-lock-fontify-region
- (start end &optional loudly)
+(defun treesit-font-lock-fontify-region (start end &optional loudly)
"Fontify the region between START and END.
If LOUDLY is non-nil, display some debugging information."
(when (or loudly treesit--font-lock-verbose)
;; is very fast anyway (even in large files of size ~10MB).
;; Plus, querying the result of `treesit-node-on' could still
;; miss patterns even if we use some heuristic to enlarge the
- ;; node (how much to enlarge? to which extent?), its much safer
+ ;; node (how much to enlarge? to which extent?), it's much safer
;; to just use the root node.
;;
- ;; Sometimes the source file has some errors that causes
+ ;; Sometimes the source file has some errors that cause
;; tree-sitter to parse it into a enormously tall tree (10k
;; levels tall). In that case querying the root node is very
;; slow. So we try to get top-level nodes and query them. This
`(jit-lock-bounds ,start . ,end))
(defun treesit--font-lock-notifier (ranges parser)
- "Ensures updated parts of the parse-tree is refontified.
+ "Ensures updated parts of the parse-tree are refontified.
RANGES is a list of (BEG . END) ranges, PARSER is the tree-sitter
parser notifying of the change."
(with-current-buffer (treesit-parser-buffer parser)
"A list of presets.
These presets that can be used as MATHER and ANCHOR in
`treesit-simple-indent-rules'. MACHTERs and ANCHORs are
-functions that takes 3 arguments: NODE, PARENT and BOL.
+functions that take 3 arguments: NODE, PARENT and BOL.
MATCHER:
\(match NODE-TYPE PARENT-TYPE NODE-FIELD NODE-INDEX-MIN NODE-INDEX-MAX)
NODE-TYPE checks for NODE's type, PARENT-TYPE checks for
- PARENT's type, NODE-FIELD checks for the filed name of NODE
- in PARENT, NODE-INDEX-MIN and NODE-INDEX-MAX checks for
+ PARENT's type, NODE-FIELD checks for the field name of NODE
+ in PARENT, NODE-INDEX-MIN and NODE-INDEX-MAX check for
NODE's index in PARENT. Therefore, to match the first child
where PARENT is \"argument_list\", use
prev-line
- Returns the first non-whitespace character on the previous line.
+ Returns the first non-whitespace character on the previous line.
point-min
"How many lines of indent value do we precompute.
In `treesit-indent-region' we indent in batches: precompute
indent for each line, apply them in one go, let parser reparse,
-and do it again. This way the parser don't need to unnecessarily
+and do it again. This way the parser doesn't need to unnecessarily
reparse after indenting every single line.")
(defun treesit-indent-region (beg end)
RULES should be a value suitable for
`treesit-simple-indent-rules'. Return the optimized version of
RULES."
- ;; Right now this function just compiles queries. it doesn't
+ ;; Right now this function just compiles queries. It doesn't
;; byte-compile matchers and anchors because it doesn't make much
;; difference.
(cl-loop for setting in rules
If tree-sitter is not ready, emit a warning and return nil. If
the user has chosen to activate tree-sitter for LANGUAGE and
tree-sitter is ready, return non-nil. If QUIET is t, don't emit
-warning in either case; if quiet is `message', display a message
-instead of emitting warning."
+a warning in either case; if quiet is `message', display a message
+instead of emitting a warning."
(let ((language-list (if (consp language)
language
(list language)))