]> git.eshelyaron.com Git - emacs.git/commitdiff
Add treesit-thing-settings to yaml-ts-mode and enable transpose-sexps
authorJuri Linkov <juri@linkov.net>
Sun, 12 Jan 2025 18:17:16 +0000 (20:17 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 13 Jan 2025 07:43:32 +0000 (08:43 +0100)
* lisp/treesit.el (treesit-major-mode-setup): Move setting of
'transpose-sexps-function' outside of 'treesit-thing-defined-p'
since 'treesit-transpose-sexps' doesn't depend on the 'sexp' thing.

* lisp/textmodes/yaml-ts-mode.el (yaml-ts-mode):
Add 'treesit-thing-settings' with the 'list' thing,
but use it only for list commands, not sexp commands (bug#73404).

(cherry picked from commit 2d2bc6f1bc678b21c46af26cf343e24acdb48b79)

lisp/textmodes/yaml-ts-mode.el
lisp/treesit.el

index 957102950b44c8630b9841737d30d311b9a2a8f6..defef096aa6395116addaf0eaf5f9e7d0878175e 100644 (file)
@@ -167,7 +167,22 @@ boundaries.  JUSTIFY is passed to `fill-paragraph'."
 
     (setq-local fill-paragraph-function #'yaml-ts-mode--fill-paragraph)
 
-    (treesit-major-mode-setup)))
+    ;; Navigation.
+    (setq-local treesit-thing-settings
+                `((yaml
+                   (list ,(regexp-opt '("block_mapping_pair"
+                                        "flow_sequence"))
+                         'symbols))))
+
+    (treesit-major-mode-setup)
+
+    ;; Use the `list' thing defined above to navigate only lists
+    ;; with `C-M-n', `C-M-p', `C-M-u', `C-M-d', but not sexps
+    ;; with `C-M-f', `C-M-b' neither adapt to 'show-paren-mode'
+    ;; that is problematic in languages without explicit
+    ;; opening/closing nodes.
+    (setq-local forward-sexp-function nil)
+    (setq-local show-paren-data-function 'show-paren--default)))
 
 (derived-mode-add-parents 'yaml-ts-mode '(yaml-mode))
 
index fa25b067ccadbf6203c833fb3987cb93b43e6653..6c0f119dc5d81236f23f41c7133e7116a3d02fff 100644 (file)
@@ -3586,9 +3586,10 @@ before calling this function."
     (setq-local add-log-current-defun-function
                 #'treesit-add-log-current-defun))
 
+  (setq-local transpose-sexps-function #'treesit-transpose-sexps)
+
   (when (treesit-thing-defined-p 'sexp nil)
-    (setq-local forward-sexp-function #'treesit-forward-sexp)
-    (setq-local transpose-sexps-function #'treesit-transpose-sexps))
+    (setq-local forward-sexp-function #'treesit-forward-sexp))
 
   (when (treesit-thing-defined-p 'list nil)
     (setq-local forward-sexp-function #'treesit-forward-sexp-list)