]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix treesit-forward-sexp/list navigation in the middle of a node.
authorJuri Linkov <juri@linkov.net>
Thu, 10 Apr 2025 16:20:35 +0000 (19:20 +0300)
committerEshel Yaron <me@eshelyaron.com>
Fri, 11 Apr 2025 11:36:31 +0000 (13:36 +0200)
* lisp/treesit.el (treesit--forward-list-with-default):
Check the thing 'sexp-default' (bug#76791).

* lisp/progmodes/elixir-ts-mode.el (elixir-ts-mode):
* lisp/progmodes/go-ts-mode.el (go-ts-mode):
* lisp/progmodes/ruby-ts-mode.el (ruby-ts-mode):
* lisp/progmodes/sh-script.el (bash-ts-mode):
Add the thing 'sexp-default' to 'treesit-thing-settings'.

(cherry picked from commit ec62674cb959278240a56246cb6a958217dd17c0)

lisp/progmodes/elixir-ts-mode.el
lisp/progmodes/go-ts-mode.el
lisp/progmodes/ruby-ts-mode.el
lisp/progmodes/sh-script.el
lisp/treesit.el

index 9d938e10fde4a73965e5c960ca0adb93eabf0ad6..43cb6d12cc3d71f036d724b004a34c4a5d3d84ee 100644 (file)
@@ -720,6 +720,11 @@ Return nil if NODE is not a defun node or doesn't have a name."
                                      "do_block"
                                      "anonymous_function")
                              eos)))
+                   (sexp-default
+                    ;; For `C-M-f' in "&|(a)"
+                    ("(" . ,(lambda (node)
+                              (equal (treesit-node-type (treesit-node-parent node))
+                                     "unary_operator"))))
                    (sentence
                     ,(rx bos (or "call") eos))
                    (text
index 130e3829ae4bd49eb4ff5aab2ed673bdcae834e3..82bcf5ef7c1063f497da19a1401b8bbfac107c55 100644 (file)
                                  "argument_list"
                                  "literal_value")
                          eos))
+                   (sexp-default
+                    ;; For `C-M-f' in "switch a |{ }"
+                    (lambda (node)
+                      (equal (treesit-node-type (treesit-node-parent node))
+                             "expression_switch_statement")))
                    (sentence
                     (or "declaration" "statement")))))
 
index f646e5e9385fb2d1177a91b72a691af2e372bc1f..6b53dc8ef603c77d024a864891fef68779398a43 100644 (file)
@@ -1219,6 +1219,12 @@ leading double colon is not added."
                                 "hash")
                                eos)
                               #'ruby-ts--list-p))
+                 (sexp-default
+                  ;; For `C-M-f' in "#|{a}"
+                  ("#{" . ,(lambda (node)
+                             (and (eq (char-after (point)) ?{)
+                                  (equal (treesit-node-type (treesit-node-parent node))
+                                         "interpolation")))))
                  (sentence ,(rx bos (or "return"
                                         "body_statement"
                                         "call"
@@ -1226,19 +1232,8 @@ leading double colon is not added."
                                 eos))
                  (text ,(lambda (node)
                           (or (member (treesit-node-type node)
-                                      '("comment" "string_content" "heredoc_content"))
-                              ;; for C-M-f in hash[:key] and hash['key']
-                              (and (member (treesit-node-text node)
-                                           '("[" "]"))
-                                   (equal (treesit-node-type
-                                           (treesit-node-parent node))
-                                          "element_reference"))
-                              ;; for C-M-f in "abc #{ghi} def"
-                              (and (member (treesit-node-text node)
-                                           '("#{" "}"))
-                                   (equal (treesit-node-type
-                                           (treesit-node-parent node))
-                                          "interpolation"))))))))
+                                      '("comment" "string_content"
+                                        "heredoc_content"))))))))
 
   ;; Imenu.
   (setq-local imenu-create-index-function #'ruby-ts--imenu)
index 38306ed26e634053fa44caef81418e79b21471aa..795e79ef2f79d92066c4a9db64f40985c9323d79 100644 (file)
@@ -1662,6 +1662,12 @@ not written in Bash or sh."
                                  "command_substitution"
                                  "process_substitution")
                          eos))
+                   (sexp-default
+                    ;; For `C-M-f' in "$|(a)"
+                    ("$(" .
+                     ,(lambda (node)
+                        (equal (treesit-node-type (treesit-node-parent node))
+                               "command_substitution"))))
                    (sentence
                     ,(rx bos (or "redirected_statement"
                                  "declaration_command"
index 1270c197111fd9b387b5463cfb7d32c1186fdb05..8c0fdd64253b767a1d213257cebbebeffcf7d0a6 100644 (file)
@@ -3041,6 +3041,14 @@ ARG is described in the docstring of `forward-list'."
         ;; 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
+                       ;; Fallback to the default sexp function when
+                       ;; matching the thing 'sexp-default' at point.
+                       (treesit-node-match-p
+                        (treesit-node-at (if (> arg 0) (point)
+                                           (max (1- (point)) (point-min))))
+                        'sexp-default t))
+              (goto-char default-pos))
+            (when (and default-pos
                        (or (null sibling)
                            (if (> arg 0)
                                (<= default-pos (treesit-node-start sibling))