(defun yaml-format-buffer () "Run prettier." (interactive) (run-command-on-buffer "prettier" "--stdin-filepath" buffer-file-name) ) (use-package yaml-ts-mode :mode ( ("\\.y[a]?ml\\'" . yaml-ts-mode) ("playbook\\.tmp\\'" . yaml-ts-mode) ("environments/[^/]*/group_vars/[^/]*\\'" . yaml-ts-mode) ("environments/[^/]*/host_vars/[^/]*\\'" . yaml-ts-mode) ) :commands (yaml-ts-mode) :hook ( (yaml-ts-mode . (lambda () (add-hook 'before-save-hook 'yaml-format-buffer nil 'local) )) ) :init (add-to-list 'major-mode-remap-alist '(yaml-mode . yaml-ts-mode)) (add-to-list 'treesit-language-source-alist '(yaml "https://github.com/ikatyang/tree-sitter-yaml")) (unless (treesit-ready-p 'yaml) (treesit-install-language-grammar 'yaml)) ) (provide 'lang-yaml)