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." (sexp (not ,(rx (or "{" "}" "[" "]" "(" ")" ",")))) (list ,(regexp-opt '("preproc_params" + "preproc_if" + "preproc_ifdef" + "preproc_if_in_field_declaration_list" + "preproc_ifdef_in_field_declaration_list" + "preproc_if_in_enumerator_list" + "preproc_ifdef_in_enumerator_list" + "preproc_if_in_enumerator_list_no_comma" + "preproc_ifdef_in_enumerator_list_no_comma" "preproc_parenthesized_expression" "preproc_argument_list" "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'." (funcall default-function inc) (point)) (scan-error nil))) + (parent (treesit-thing-at (point) pred t)) (sibling (if (> arg 0) (treesit-thing-next (point) pred) - (treesit-thing-prev (point) pred))) - (current (when default-pos - (treesit-thing-at (point) pred t)))) + (treesit-thing-prev (point) pred)))) + (when (and parent sibling + (not (treesit-node-enclosed-p sibling parent))) + (setq sibling nil)) ;; Use the default function only if it doesn't go ;; over the sibling and doesn't go out of the current group. (or (when (and default-pos @@ -2501,10 +2503,10 @@ ARG is described in the docstring of `forward-list'." (if (> arg 0) (<= default-pos (treesit-node-start sibling)) (>= default-pos (treesit-node-end sibling)))) - (or (null current) + (or (null parent) (if (> arg 0) - (<= default-pos (treesit-node-end current)) - (>= default-pos (treesit-node-start current))))) + (< default-pos (treesit-node-end parent)) + (> default-pos (treesit-node-start parent))))) (goto-char default-pos)) (when sibling (goto-char (if (> arg 0) @@ -3078,9 +3080,7 @@ function is called recursively." (if (eq tactic 'restricted) (setq pos (funcall advance - (cond ((and (null next) (null prev) - (not (eq thing 'list))) - parent) + (cond ((and (null next) (null prev)) parent) ((> arg 0) next) (t prev)))) ;; For `nested', it's a bit more work: