diff options
| author | Yuan Fu | 2025-04-17 16:56:07 -0700 |
|---|---|---|
| committer | Yuan Fu | 2025-04-17 16:56:07 -0700 |
| commit | f728aa72c047ff8485bce08a6effb1c7790bce9f (patch) | |
| tree | bf2fe5cbaa018c9642bbb0881b84c12eed302400 | |
| parent | 4f80a116f53c2d8dc58301630f6dc7de6e0e346e (diff) | |
| download | emacs-f728aa72c047ff8485bce08a6effb1c7790bce9f.tar.gz emacs-f728aa72c047ff8485bce08a6effb1c7790bce9f.zip | |
Add guard in treesit-language-at-point-default (bug#77870)
* lisp/treesit.el (treesit-language-at-point-default): Return
nil if there's no parser in the buffer.
(treesit-parsers-at): Add docstring for parser order.
| -rw-r--r-- | lisp/treesit.el | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index 59718fd3d3d..c67d7bb996e 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el | |||
| @@ -190,9 +190,14 @@ the return value of that function instead." | |||
| 190 | 190 | ||
| 191 | (defun treesit-language-at-point-default (position) | 191 | (defun treesit-language-at-point-default (position) |
| 192 | "Default function for `treesit-language-at-point-function'. | 192 | "Default function for `treesit-language-at-point-function'. |
| 193 | Return the deepest parser by embed level." | 193 | |
| 194 | (treesit-parser-language | 194 | Returns the language at POSITION, or nil if there's no parser in the |
| 195 | (car (treesit-parsers-at position)))) | 195 | buffer. When there are multiple parsers that cover POSITION, use the |
| 196 | parser with the deepest embed level as it's the \"most relevant\" parser | ||
| 197 | at POSITION." | ||
| 198 | (let ((parser (car (treesit-parsers-at position)))) | ||
| 199 | (when parser | ||
| 200 | (treesit-parser-language parser)))) | ||
| 196 | 201 | ||
| 197 | ;;; Node API supplement | 202 | ;;; Node API supplement |
| 198 | 203 | ||
| @@ -855,7 +860,10 @@ by an overlay with non-nil `treesit-parser-local-p' property. | |||
| 855 | If ONLY contains the symbol `global', include non-local parsers | 860 | If ONLY contains the symbol `global', include non-local parsers |
| 856 | excluding the primary parser. | 861 | excluding the primary parser. |
| 857 | 862 | ||
| 858 | If ONLY contains the symbol `primary', include the primary parser." | 863 | If ONLY contains the symbol `primary', include the primary parser. |
| 864 | |||
| 865 | The returned parsers are sorted in descending order of embed level. | ||
| 866 | That is, the deepest embedded parser comes first." | ||
| 859 | (let ((res nil)) | 867 | (let ((res nil)) |
| 860 | ;; Refer to (ref:local-parser-overlay) for more explanation of local | 868 | ;; Refer to (ref:local-parser-overlay) for more explanation of local |
| 861 | ;; parser overlays. | 869 | ;; parser overlays. |