From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Rudolf Schlatte Newsgroups: gmane.emacs.bugs Subject: bug#68781: [PATCH] Don't fill yaml except comments and block scalars. Date: Sun, 28 Jan 2024 14:15:58 +0100 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16389"; mail-complaints-to="usenet@ciao.gmane.io" To: 68781@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 28 14:17:07 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rU522-00044i-RU for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 28 Jan 2024 14:17:07 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rU51w-0006e5-9h; Sun, 28 Jan 2024 08:17:00 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rU51r-0006ah-6G for bug-gnu-emacs@gnu.org; Sun, 28 Jan 2024 08:16:55 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rU51q-0000A6-U2 for bug-gnu-emacs@gnu.org; Sun, 28 Jan 2024 08:16:54 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rU51y-0004Ts-H0 for bug-gnu-emacs@gnu.org; Sun, 28 Jan 2024 08:17:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Rudolf Schlatte Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 28 Jan 2024 13:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 68781 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.170644778717175 (code B ref -1); Sun, 28 Jan 2024 13:17:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 Jan 2024 13:16:27 +0000 Original-Received: from localhost ([127.0.0.1]:56842 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rU51P-0004Sx-2g for submit@debbugs.gnu.org; Sun, 28 Jan 2024 08:16:27 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:44848) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rU51N-0004Sk-K9 for submit@debbugs.gnu.org; Sun, 28 Jan 2024 08:16:26 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rU518-0006Uo-Ob for bug-gnu-emacs@gnu.org; Sun, 28 Jan 2024 08:16:10 -0500 Original-Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rU513-0008UL-7s for bug-gnu-emacs@gnu.org; Sun, 28 Jan 2024 08:16:09 -0500 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.nyi.internal (Postfix) with ESMTP id 2404A5C0260 for ; Sun, 28 Jan 2024 08:16:03 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Sun, 28 Jan 2024 08:16:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1706447763; x=1706534163; bh=/GROhgdWe95xG5q3CrqnDNIVD0anWq+Cgx7 e6npP0Fo=; b=bS2xqy5lyFLUMRKxt4TXh+m3/hWBCY9EYtKGtTPY+iI4r0eD9DK zDQ2hWJ3qap51cDUPEILZKlI5Gq7f9ZFP6WfH0KHvLOZAclH6k8KX3nj0WN/XoXZ dGADXgUAZccb3KyPq2FE4rkxAklpBF1IKzzwWlLtii35NEYTSY7BwVj9GZX7w+t8 fuKzx4a2qK93YHg+uwLPYGAUVG1/551Z49fKEKB0Q1ZooR5XRLAHETZd+b2FVlNu 7yZcR1mbcSDBJc9vm0GNoO5q+EJ3JojV1W6aIXErnDjOsI8etnvbA/qlP5Syz1bb /M+ng9JBbzmdaJQ7KzupvU5rWveZh3AGu9A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedtvddggeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkgggtsehmtderredttd dtnecuhfhrohhmpeftuhguohhlfhcuufgthhhlrghtthgvuceorhhuughisegtohhnshht rghnthhlhidrrghtqeenucggtffrrghtthgvrhhnpeefkeekuefhheehtddtueekheffve elieeifeekveeihfelveetgfekgeehieffleenucevlhhushhtvghrufhiiigvpedtnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehruhguihestghonhhsthgrnhhtlhihrdgrth X-ME-Proxy: Feedback-ID: i5b4840b3:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sun, 28 Jan 2024 08:16:02 -0500 (EST) Received-SPF: none client-ip=66.111.4.29; envelope-from=rudi@constantly.at; helo=out5-smtp.messagingengine.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:279084 Archived-At: --=-=-= Content-Type: text/plain 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'. --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Don-t-fill-yaml-except-comments-and-block-scalars.patch >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 --=-=-=--