Function: yaml-ts-mode
yaml-ts-mode is an autoloaded, interactive and byte-compiled function
defined in yaml-ts-mode.el.gz.
Signature
(yaml-ts-mode)
Documentation
Major mode for editing YAML, powered by tree-sitter.
In addition to any hooks its parent mode text-mode might have run,
this mode runs the hook yaml-ts-mode-hook, as the final or penultimate
step during initialization.
Probably introduced at or before Emacs version 29.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/yaml-ts-mode.el.gz
;;;###autoload
(define-derived-mode yaml-ts-mode text-mode "YAML"
"Major mode for editing YAML, powered by tree-sitter."
:group 'yaml
:syntax-table yaml-ts-mode--syntax-table
;; `treesit-ready-p' also checks for buffer size.
(when (and (treesit-ensure-installed 'yaml)
(treesit-ready-p 'yaml))
(setq treesit-primary-parser (treesit-parser-create 'yaml))
;; Comments.
(setq-local comment-start "# ")
(setq-local comment-end "")
(setq-local comment-start-skip "#+ *")
;; Indentation.
(setq-local indent-tabs-mode nil)
;; Font-lock.
(setq-local treesit-font-lock-settings yaml-ts-mode--font-lock-settings)
(setq-local treesit-font-lock-feature-list yaml-ts-mode--font-lock-feature-list)
(setq-local fill-paragraph-function #'yaml-ts-mode--fill-paragraph)
;; Navigation.
(setq-local treesit-defun-type-regexp "block_mapping_pair")
(setq-local treesit-defun-name-function #'yaml-ts-mode--defun-name)
(setq-local treesit-defun-tactic 'top-level)
(setq-local treesit-thing-settings
`((yaml
(list ,(rx (or "block_mapping_pair" "flow_sequence")))
(sentence ,"block_mapping_pair"))))
;; Imenu.
(setq-local treesit-simple-imenu-settings
'((nil "\\`block_mapping_pair\\'" nil nil)))
;; Outline minor mode.
(setq-local treesit-outline-predicate #'yaml-ts-mode--outline-predicate)
;; Flymake
(add-hook 'flymake-diagnostic-functions #'yaml-ts-mode-flymake nil 'local)
(treesit-major-mode-setup)
(setq-local hs-treesit-things "block_mapping_pair")
(setq-local hs-adjust-block-end-function (lambda (_) (line-end-position)))
;; 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.
(kill-local-variable 'forward-sexp-function)
(kill-local-variable 'show-paren-data-function)))