unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Randy Taylor <dev@rjt.dev>
To: Yuan Fu <casouri@gmail.com>
Cc: Juan Palacios <jpalaciosdev@gmail.com>, 66845@debbugs.gnu.org
Subject: bug#66845: 29.1; cmake-ts-mode indentation broken
Date: Tue, 07 Nov 2023 17:21:44 +0000	[thread overview]
Message-ID: <KtEjEz2JJBgL_BYUTDSUUENVTfbaPlsmIpdqDPEBihAVEa-my5QOQnys_AKCon1b6ZayHztDJ2lhEt8Da4bu-M-7h1828MX2r8TKzAzq2oo=@rjt.dev> (raw)
In-Reply-To: <F236B215-277A-4B7B-A232-D1124E51318B@gmail.com>

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

On Tuesday, November 7th, 2023 at 03:25, Yuan Fu <casouri@gmail.com> wrote:
> IMO it makes more sense to use prev-sibling:
> 
> ,@(ignore-errors
> (treesit-query-capture 'cmake '((body) @capture))
> `(((parent-is "body") prev-sibling 0)))
> 
> This would allow users to manually adjust the indentation of a line and have the rest of the body follow that.

This would be much more elegant but unfortunately that and my previous patch failed to account for the following:

1 if(TRUE) # Comment.
2 endif()

And place POINT at the end of line 1 and hit RET. It will indent to the start of the comment :(. However, you gave me an idea: use the grand-parent as the anchor (which in this case is the if - exactly what we want). I've attached a new patch which accounts for that.

Juan, thanks for testing the first patch. Please give this new one a whirl if you're able to.

> 
> As for why parent-bol returns the BOL of the comment line, that’s expected: The parent is body, and body starts at the comment, so of course the beginning of the parent line is the beginning of the comment line. In the image below, the highlighted portion marks the body node.
> 
> Some tree-sitter grammar would mark the beginning of body at the end of if(TRUE), but what tree-sitter-cmake does here is equally valid.

Thanks, I understand what's happening now. Whenever line_comment is NOT the first child, the beginning of body is at the end of if(TRUE). If line_comment is the first child, then the beginning of body is at the start of the comment. I was expecting them to behave the same - that's why I was so confused, and I don't really understand why it was done that way.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-cmake-ts-mode-indentation-Bug-66845.patch --]
[-- Type: text/x-patch; name=0001-Fix-cmake-ts-mode-indentation-Bug-66845.patch, Size: 2267 bytes --]

From ee400533655bcbe0c803dde9ba8ded95f9d6d1e5 Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Tue, 31 Oct 2023 22:08:25 -0400
Subject: [PATCH] Fix cmake-ts-mode indentation (Bug#66845)

* lisp/progmodes/cmake-ts-mode.el
(cmake-ts-mode--indent-rules): Support versions v0.3.0 and v0.4.0 of
the grammar.
(cmake-ts-mode--font-lock-compatibility-fe9b5e0): Fix docstring.
---
 lisp/progmodes/cmake-ts-mode.el | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/cmake-ts-mode.el b/lisp/progmodes/cmake-ts-mode.el
index 53d471c381a..8fcdcaddc7b 100644
--- a/lisp/progmodes/cmake-ts-mode.el
+++ b/lisp/progmodes/cmake-ts-mode.el
@@ -63,7 +63,15 @@ cmake-ts-mode--indent-rules
      ((parent-is "foreach_loop") parent-bol cmake-ts-mode-indent-offset)
      ((parent-is "function_def") parent-bol cmake-ts-mode-indent-offset)
      ((parent-is "if_condition") parent-bol cmake-ts-mode-indent-offset)
-     ((parent-is "normal_command") parent-bol cmake-ts-mode-indent-offset)))
+     ((parent-is "normal_command") parent-bol cmake-ts-mode-indent-offset)
+     ;;; Release v0.4.0 wraps arguments in an argument_list node.
+     ,@(ignore-errors
+         (treesit-query-capture 'cmake '((argument_list) @capture))
+         `(((parent-is "argument_list") grand-parent cmake-ts-mode-indent-offset)))
+     ;;; Release v0.3.0 wraps the body of commands into a body node.
+     ,@(ignore-errors
+         (treesit-query-capture 'cmake '((body) @capture))
+         `(((parent-is "body") grand-parent cmake-ts-mode-indent-offset)))))
   "Tree-sitter indent rules for `cmake-ts-mode'.")
 
 (defvar cmake-ts-mode--constants
@@ -89,8 +97,8 @@ cmake-ts-mode--if-conditions
   "CMake if conditions for tree-sitter font-locking.")
 
 (defun cmake-ts-mode--font-lock-compatibility-fe9b5e0 ()
-  "Indent rules helper, to handle different releases of tree-sitter-cmake.
-Check if a node type is available, then return the right indent rules."
+  "Font lock helper, to handle different releases of tree-sitter-cmake.
+Check if a node type is available, then return the right font lock rules."
   ;; handle commit fe9b5e0
   (condition-case nil
       (progn (treesit-query-capture 'cmake '((argument_list) @capture))
-- 
2.42.1


  reply	other threads:[~2023-11-07 17:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-31 11:35 bug#66845: 29.1; cmake-ts-mode indentation broken Juan Palacios
2023-10-31 15:50 ` Randy Taylor
2023-11-01  2:45 ` Randy Taylor
2023-11-05 14:32   ` Juan Palacios
2023-11-05 18:16     ` Fu Yuan
2023-11-07  8:25   ` Yuan Fu
2023-11-07 17:21     ` Randy Taylor [this message]
2023-11-07 20:11       ` Juan Palacios
2023-11-08  2:52       ` Yuan Fu
2023-11-08  3:42         ` Randy Taylor
2023-11-08 12:33           ` 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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='KtEjEz2JJBgL_BYUTDSUUENVTfbaPlsmIpdqDPEBihAVEa-my5QOQnys_AKCon1b6ZayHztDJ2lhEt8Da4bu-M-7h1828MX2r8TKzAzq2oo=@rjt.dev' \
    --to=dev@rjt.dev \
    --cc=66845@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --cc=jpalaciosdev@gmail.com \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).