diff options
| author | Juri Linkov | 2025-01-11 20:28:43 +0200 |
|---|---|---|
| committer | Juri Linkov | 2025-01-11 20:28:43 +0200 |
| commit | db4bf410f2bae6c77f2a0e660dcc680d73a18cd1 (patch) | |
| tree | 0188dd2409b9c096b24abc15315f2ca3768b3d93 | |
| parent | fafcc8458e805e5c7d7785aa7e943bacfadcf79d (diff) | |
| download | emacs-db4bf410f2bae6c77f2a0e660dcc680d73a18cd1.tar.gz emacs-db4bf410f2bae6c77f2a0e660dcc680d73a18cd1.zip | |
Improve treesit list navigation support for #if/#endif (bug#73404)
* lisp/treesit.el (treesit--forward-list-with-default): Improve to
better support the case when point is inside an opening/closing node
with a name longer than 1 character such as "#if" and "#endif".
(treesit-navigate-thing): No need to check for thing 'list'
since list commands now use other functions.
* lisp/progmodes/c-ts-mode.el (c-ts-mode--thing-settings): Add
more preproc nodes such as #if/#endif and #ifdef/#endif and their
variants to the 'list' thing.
| -rw-r--r-- | lisp/progmodes/c-ts-mode.el | 8 | ||||
| -rw-r--r-- | lisp/treesit.el | 18 |
2 files changed, 17 insertions, 9 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 80e635fe76d..dd08731edb4 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el | |||
| @@ -1153,6 +1153,14 @@ if `c-ts-mode-emacs-sources-support' is non-nil." | |||
| 1153 | (sexp (not ,(rx (or "{" "}" "[" "]" "(" ")" ",")))) | 1153 | (sexp (not ,(rx (or "{" "}" "[" "]" "(" ")" ",")))) |
| 1154 | (list | 1154 | (list |
| 1155 | ,(regexp-opt '("preproc_params" | 1155 | ,(regexp-opt '("preproc_params" |
| 1156 | "preproc_if" | ||
| 1157 | "preproc_ifdef" | ||
| 1158 | "preproc_if_in_field_declaration_list" | ||
| 1159 | "preproc_ifdef_in_field_declaration_list" | ||
| 1160 | "preproc_if_in_enumerator_list" | ||
| 1161 | "preproc_ifdef_in_enumerator_list" | ||
| 1162 | "preproc_if_in_enumerator_list_no_comma" | ||
| 1163 | "preproc_ifdef_in_enumerator_list_no_comma" | ||
| 1156 | "preproc_parenthesized_expression" | 1164 | "preproc_parenthesized_expression" |
| 1157 | "preproc_argument_list" | 1165 | "preproc_argument_list" |
| 1158 | "attribute_declaration" | 1166 | "attribute_declaration" |
diff --git a/lisp/treesit.el b/lisp/treesit.el index 6107ae10ad5..995d89332ad 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el | |||
| @@ -2489,11 +2489,13 @@ ARG is described in the docstring of `forward-list'." | |||
| 2489 | (funcall default-function inc) | 2489 | (funcall default-function inc) |
| 2490 | (point)) | 2490 | (point)) |
| 2491 | (scan-error nil))) | 2491 | (scan-error nil))) |
| 2492 | (parent (treesit-thing-at (point) pred t)) | ||
| 2492 | (sibling (if (> arg 0) | 2493 | (sibling (if (> arg 0) |
| 2493 | (treesit-thing-next (point) pred) | 2494 | (treesit-thing-next (point) pred) |
| 2494 | (treesit-thing-prev (point) pred))) | 2495 | (treesit-thing-prev (point) pred)))) |
| 2495 | (current (when default-pos | 2496 | (when (and parent sibling |
| 2496 | (treesit-thing-at (point) pred t)))) | 2497 | (not (treesit-node-enclosed-p sibling parent))) |
| 2498 | (setq sibling nil)) | ||
| 2497 | ;; Use the default function only if it doesn't go | 2499 | ;; Use the default function only if it doesn't go |
| 2498 | ;; over the sibling and doesn't go out of the current group. | 2500 | ;; over the sibling and doesn't go out of the current group. |
| 2499 | (or (when (and default-pos | 2501 | (or (when (and default-pos |
| @@ -2501,10 +2503,10 @@ ARG is described in the docstring of `forward-list'." | |||
| 2501 | (if (> arg 0) | 2503 | (if (> arg 0) |
| 2502 | (<= default-pos (treesit-node-start sibling)) | 2504 | (<= default-pos (treesit-node-start sibling)) |
| 2503 | (>= default-pos (treesit-node-end sibling)))) | 2505 | (>= default-pos (treesit-node-end sibling)))) |
| 2504 | (or (null current) | 2506 | (or (null parent) |
| 2505 | (if (> arg 0) | 2507 | (if (> arg 0) |
| 2506 | (<= default-pos (treesit-node-end current)) | 2508 | (< default-pos (treesit-node-end parent)) |
| 2507 | (>= default-pos (treesit-node-start current))))) | 2509 | (> default-pos (treesit-node-start parent))))) |
| 2508 | (goto-char default-pos)) | 2510 | (goto-char default-pos)) |
| 2509 | (when sibling | 2511 | (when sibling |
| 2510 | (goto-char (if (> arg 0) | 2512 | (goto-char (if (> arg 0) |
| @@ -3078,9 +3080,7 @@ function is called recursively." | |||
| 3078 | (if (eq tactic 'restricted) | 3080 | (if (eq tactic 'restricted) |
| 3079 | (setq pos (funcall | 3081 | (setq pos (funcall |
| 3080 | advance | 3082 | advance |
| 3081 | (cond ((and (null next) (null prev) | 3083 | (cond ((and (null next) (null prev)) parent) |
| 3082 | (not (eq thing 'list))) | ||
| 3083 | parent) | ||
| 3084 | ((> arg 0) next) | 3084 | ((> arg 0) next) |
| 3085 | (t prev)))) | 3085 | (t prev)))) |
| 3086 | ;; For `nested', it's a bit more work: | 3086 | ;; For `nested', it's a bit more work: |