From 003e9f0dbd20059dbf49761a7537658947a98d55 Mon Sep 17 00:00:00 2001 From: Rudolf Schlatte Date: Sun, 28 Jan 2024 13:54:35 +0100 Subject: [PATCH] Don't fill yaml except comments and block scalars. Indentation and line breaks are significant syntax, so only fill reflowable nodes. * lisp/textmodes/yaml-ts-mode.el (yaml-ts-mode--fill-paragraph): Check if point is inside a comment or block scalar, do not fill otherwise. --- lisp/textmodes/yaml-ts-mode.el | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/lisp/textmodes/yaml-ts-mode.el b/lisp/textmodes/yaml-ts-mode.el index c0185457bc2..301d7ba03a9 100644 --- a/lisp/textmodes/yaml-ts-mode.el +++ b/lisp/textmodes/yaml-ts-mode.el @@ -120,25 +120,17 @@ yaml-ts-mode--font-lock-settings '((ERROR) @font-lock-warning-face)) "Tree-sitter font-lock settings for `yaml-ts-mode'.") -(defun yaml-ts-mode--fill-paragraph (&optional justify) +(defun yaml-ts-mode--fill-paragraph (&optional _justify) "Fill paragraph. -Behaves like `fill-paragraph', but respects block node -boundaries. JUSTIFY is passed to `fill-paragraph'." - (interactive "*P") - (save-restriction - (widen) - (let ((node (treesit-node-at (point)))) - (when (string= "block_scalar" (treesit-node-type node)) - (let* ((start (treesit-node-start node)) - (end (treesit-node-end node)) - (start-marker (point-marker)) - (fill-paragraph-function nil)) - (save-excursion - (goto-char start) - (forward-line) - (move-marker start-marker (point)) - (narrow-to-region (point) end)) - (fill-region start-marker end justify)))))) +Hand over to `fill-paragraph' if point is inside a comment or +block scalar; do nothing otherwise." + (let ((node (treesit-node-at (point))) + (fillable-types '("block_scalar" "comment"))) + (if (member (treesit-node-type node) fillable-types) + ;; Explicitly return these two specific values; see + ;; `fill-paragraph-function' documentation. + nil + t))) ;;;###autoload (define-derived-mode yaml-ts-mode text-mode "YAML" -- 2.43.0