Subject: bug#68781: closed (Re: bug#68781: [PATCH] Don't fill yaml except comments and block scalars.)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 01 Feb 2024 10:32:02 +0000

Your bug report

#68781: [PATCH] Don't fill yaml except comments and block scalars.

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
68781: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68781
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#68781: [PATCH] Don't fill yaml except comments and block scalars.
From: Eli Zaretskii <[email-masked]>
To: Randy Taylor <[email-masked]>
Cc: [email-masked], [email-masked], [email-masked]
Date: Thu, 01 Feb 2024 12:31:30 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> Cc: Rudolf Schlatte <[email-masked]>, [email-masked]
> Date: Tue, 30 Jan 2024 19:25:07 +0000
> From: Randy Taylor <[email-masked]>
> 
> On Monday, January 29th, 2024 at 20:20, Graham Marlow <[email-masked]> wrote:
> > 
> > 
> > > Hello Randy, thanks for having a look! Could you tell me which
> > 
> > > tree-sitter grammar you are using? I'm asking because with the grammar
> > > from https://github.com/ikatyang/tree-sitter-yaml I don't see what you
> > > describe.
> > 
> > 
> > For the record I'm also using this grammar.
> > 
> > Looking at the patch, what do you think about retaining the existing
> > behavior (so block_scalars still fill correctly) while inhibiting
> > fill_paragraph for everything else as suggested? Originally I retained
> > the existing behavior of fill-paragraph just to limit the number of
> > things changed by the patch, not because it was working properly. I
> > think blocking the call to fill-paragraph for non-block/comment nodes
> > makes sense.
> > 
> > I attached a patch w/ my edits, but it just swaps the when to and if,
> > accepts the comment node type for filling, and returns t to avoid
> > calling fill-paragraph for other nodes.
> 
> Thanks Graham, the patch looks good to me.
> 
> Would someone please install it on master? Thanks in advance.

Thanks, done, and closing the bug.

Subject: [PATCH] Don't fill yaml except comments and block scalars.
From: Rudolf Schlatte <[email-masked]>
To: [email-masked]
Date: Sun, 28 Jan 2024 14:15:58 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

Hi,

Currently, yaml-ts-mode fills comments and block scalars (multi-line
text literals) as expected, but re-fills the whole file when point is
outside of either of these constructs.  Since yaml line breaks and
whitespace are significant, I'd say that this is never the correct
behavior.

This patch against current master inhibits M-q (fill-paragraph) outside
of comments and block scalars.  In my tests default fill-paragraph
worked as expected both with and without justify, correctly detecting
comment and block literal boundaries, so I did not preserve the previous
code in `yaml-ts-mode--fill-paragraph'.

>From 003e9f0dbd20059dbf49761a7537658947a98d55 Mon Sep 17 00:00:00 2001
From: Rudolf Schlatte <[email-masked]>
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