all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Aaron Jensen <aaronjensen@gmail.com>, 61017@debbugs.gnu.org
Subject: bug#61017: 29.0.60; ruby-ts-mode indents class between two lines incorrectly
Date: Mon, 23 Jan 2023 23:28:41 +0200	[thread overview]
Message-ID: <1a2436ef-ff4d-827c-f22f-33b0737d9b1f@yandex.ru> (raw)
In-Reply-To: <m2o7qpswdc.fsf@gmail.com>

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

Hi!

On 23/01/2023 06:33, Aaron Jensen wrote:
> 
> Start with a buffer in ruby-ts-mode like:
> 
> a
> 
> b
> 
> Between the two lines, type "class Foo", then press enter
> 
> You should get this:
> 
> a
> 
>    class Foo
> 
> b
> 
> But this is expected:
> 
> a
> 
> class Foo
> 
> b
> 
> Note that reindenting after adding the "end" will indent correctly, so
> it's only an issue with electric indent

Thanks for the report, the problem here is that such examples parse into 
a malformed syntax tree:

   (program (identifier)
    (ERROR class (constant) (identifier)))

Another example would be:

   class C
     def foo

which parses as

   (ERROR class (constant) def (identifier))

We can try to anticipate such cases and infer the implied structure 
somehow, or just disable indentation for specific cases. See the 
attached patch for the latter.

Is it enough of an improvement?

[-- Attachment #2: ruby-ts-error-indent.diff --]
[-- Type: text/x-patch, Size: 696 bytes --]

diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el
index f0337775d51..c3c77d68e9a 100644
--- a/lisp/progmodes/ruby-ts-mode.el
+++ b/lisp/progmodes/ruby-ts-mode.el
@@ -546,6 +546,12 @@ ruby-ts--indent-rules
            ((n-p-gp nil nil "regex") no-indent 0)
            ((parent-is "regex") no-indent 0)
 
+           ;; Incomplete buffer state, better not reindent.
+           ((and (parent-is "ERROR")
+                 (or (node-is ,ruby-ts--class-or-module-regex)
+                     (node-is "\\`def\\'")))
+            no-indent 0)
+
            ;; if then else elseif notes:
            ;;
            ;;   1. The "then" starts at the end of the line that ends

  reply	other threads:[~2023-01-23 21:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-23  4:33 bug#61017: 29.0.60; ruby-ts-mode indents class between two lines incorrectly Aaron Jensen
2023-01-23 21:28 ` Dmitry Gutov [this message]
2023-01-24 14:17   ` Aaron Jensen
2023-01-24 18:53     ` Dmitry Gutov
2023-01-25  0:45       ` Aaron Jensen
2023-01-25  4:00         ` Dmitry Gutov
2023-01-25 14:22           ` Aaron Jensen
2023-01-25 15:23             ` Dmitry Gutov

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=1a2436ef-ff4d-827c-f22f-33b0737d9b1f@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=61017@debbugs.gnu.org \
    --cc=aaronjensen@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 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.