bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#62717: 29.0.60; c-ts-mode does not indent the first line in a functi


From: Dmitry Gutov
Subject: bug#62717: 29.0.60; c-ts-mode does not indent the first line in a function after RET
Date: Sun, 9 Apr 2023 19:30:43 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0

On 09/04/2023 14:05, Daniel Martín wrote:
Dmitry Gutov <dmitry@gutov.dev> writes:


I'm not sure, though, what is the big deal with adding the top-level
function's closing curly first thing before writing the body (after
that the parser starts working much better), so as far as I'm
concerned this patch is very optional. It does add some complexity,
after all.

I think this problem also affects languages without curly braces like
Ruby or Python.

Python -- no, because it doesn't have closers. And its indentation doesn't use tree-sitter anyway.

For example, if I insert this Ruby code in a buffer with ruby-ts-mode
enabled

def sample RET

The newline is not indented, but it is indented in ruby-mode.

Right. I mentioned that in the previous email: a fix for ruby-ts-mode will involve a similar (but slightly different) advice together with a new indentation rule. I'm not quite certain yet we want to go there, because a top-level function is more rare in Ruby than in C/C++. And, again, as soon as there is at least once 'end' below the current line in the buffer, things start working much better. The user can either type is manually, or use ruby-end-mode.

Adding Alan and Joao, who were interested in this scenario as well.

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 981c7766375..9aaa8b32c73 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el

Thanks for the patch.  It works correctly and the existing c-ts-mode
tests pass.  I suggest adding a test to prevent regressions:

diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts 
b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
index 5cdefe2122c..221b3d809af 100644
--- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -464,3 +464,17 @@ main (void)
    |
  }
  =-=-=
+
+Name: Empty Line (Block Start)
+
+=-=
+int
+main (void)
+{
+|
+=-=
+int
+main (void)
+{
+  |
+=-=-=

Good idea, thanks.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]