all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Graham Marlow <graham@mgmarlow.com>
To: Randy Taylor <dev@rjt.dev>, Rudolf Schlatte <rudi@constantly.at>
Cc: 68781@debbugs.gnu.org
Subject: bug#68781: [PATCH] Don't fill yaml except comments and block scalars.
Date: Mon, 29 Jan 2024 17:20:04 -0800	[thread overview]
Message-ID: <216ddb7b-e02d-4e68-9dbb-68fa1202d198@mgmarlow.com> (raw)
In-Reply-To: <UFxoqqquuFYfSmHgpyM56SBaMfFSfMn58RTXYb8CDYOa7ceBctmpp5hR0uOVoc9Ovp0HbzJeNvKG-DxEYzxz1qsTRZbFsUY1uBR_hwP4-WE=@rjt.dev>

[-- Attachment #1: Type: text/plain, Size: 878 bytes --]

> 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.

[-- Attachment #2: 0001-Inhibit-fill-paragraph-outside-of-blocks-comments.patch --]
[-- Type: text/plain, Size: 1476 bytes --]

From 5cc568f6cc7b237337b973aa9f64f6c97ab7bca8 Mon Sep 17 00:00:00 2001
From: Graham Marlow <graham@mgmarlow.com>
Date: Mon, 29 Jan 2024 17:16:04 -0800
Subject: [PATCH] Inhibit fill-paragraph outside of blocks/comments

* lisp/textmodes/yaml-ts-mode.el (yaml-ts-mode--fill-paragraph): Avoid
  fill-paragraph when outside of block_scalar or comment nodes.
---
 lisp/textmodes/yaml-ts-mode.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/textmodes/yaml-ts-mode.el b/lisp/textmodes/yaml-ts-mode.el
index c0185457bc2..a8cb504ef03 100644
--- a/lisp/textmodes/yaml-ts-mode.el
+++ b/lisp/textmodes/yaml-ts-mode.el
@@ -128,7 +128,7 @@ boundaries.  JUSTIFY is passed to `fill-paragraph'."
   (save-restriction
     (widen)
     (let ((node (treesit-node-at (point))))
-      (when (string= "block_scalar" (treesit-node-type node))
+      (if (member (treesit-node-type node) '("block_scalar" "comment"))
         (let* ((start (treesit-node-start node))
                (end (treesit-node-end node))
                (start-marker (point-marker))
@@ -138,7 +138,8 @@ boundaries.  JUSTIFY is passed to `fill-paragraph'."
             (forward-line)
             (move-marker start-marker (point))
             (narrow-to-region (point) end))
-          (fill-region start-marker end justify))))))
+          (fill-region start-marker end justify))
+        t))))
 
 ;;;###autoload
 (define-derived-mode yaml-ts-mode text-mode "YAML"
-- 
2.42.0.windows.1


  reply	other threads:[~2024-01-30  1:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-28 13:15 bug#68781: [PATCH] Don't fill yaml except comments and block scalars Rudolf Schlatte
2024-01-28 14:52 ` Rudolf Schlatte
2024-01-29  3:47 ` Randy Taylor
2024-01-29  8:20   ` Rudolf Schlatte
2024-01-29 14:08     ` Randy Taylor
2024-01-30  1:20       ` Graham Marlow [this message]
2024-01-30 10:15         ` Rudolf Schlatte
2024-01-30 19:25         ` Randy Taylor
2024-02-01 10:31           ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=216ddb7b-e02d-4e68-9dbb-68fa1202d198@mgmarlow.com \
    --to=graham@mgmarlow.com \
    --cc=68781@debbugs.gnu.org \
    --cc=dev@rjt.dev \
    --cc=rudi@constantly.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.