[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 94b9cbf96f 3/4: (ruby-ts--parent-call-or-bol): Handle more case
From: |
Dmitry Gutov |
Subject: |
emacs-29 94b9cbf96f 3/4: (ruby-ts--parent-call-or-bol): Handle more cases with nested literals |
Date: |
Wed, 18 Jan 2023 22:28:08 -0500 (EST) |
branch: emacs-29
commit 94b9cbf96fbb61b53242d205ff559deee36279c6
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>
(ruby-ts--parent-call-or-bol): Handle more cases with nested literals
* lisp/progmodes/ruby-ts-mode.el (ruby-ts--parent-call-or-bol):
Handle more cases with nested literals.
* test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb: Add examples.
---
lisp/progmodes/ruby-ts-mode.el | 29 ++++++++++++++--------
test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb | 17 +++++++++++++
2 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el
index 5df7e397f0..a2b2721dc1 100644
--- a/lisp/progmodes/ruby-ts-mode.el
+++ b/lisp/progmodes/ruby-ts-mode.el
@@ -796,18 +796,21 @@ a statement container is a node that matches
(treesit-parent-until
parent
(lambda (node)
- (or (<= (treesit-node-start node) parent-bol)
- (and
- ;; Parenless call.
- (equal (treesit-node-type node) "argument_list")
- (not (equal (treesit-node-type
- (treesit-node-child node 0))
- "(")))))
- t)))
+ (or (< (treesit-node-start node) parent-bol)
+ (string-match-p "\\`array\\|hash\\'" (treesit-node-type node))
+ ;; Method call on same line.
+ (equal (treesit-node-type node) "argument_list"))))))
(cond
- ;; No parenless call found on the current line.
- ((<= (treesit-node-start found) parent-bol)
+ ((null found)
parent-bol)
+ ;; No paren/curly/brace found on the same line.
+ ((< (treesit-node-start found) parent-bol)
+ parent-bol)
+ ;; Hash or array opener on the same line.
+ ((string-match-p "\\`array\\|hash\\'" (treesit-node-type found))
+ (save-excursion
+ (goto-char (treesit-node-start (treesit-node-child found 1)))
+ (point)))
;; Parenless call found: indent to stmt with offset.
((not ruby-parenless-call-arguments-indent)
(save-excursion
@@ -815,6 +818,12 @@ a statement container is a node that matches
(ruby-ts--statement-ancestor found)))
;; (**) Same.
(+ (point) ruby-indent-level)))
+ ;; Call with parens -- ident to first arg.
+ ((equal (treesit-node-type (treesit-node-child found 0))
+ "(")
+ (save-excursion
+ (goto-char (treesit-node-start (treesit-node-child found 1)))
+ (point)))
;; Indent to the parenless call args beginning.
(t
(save-excursion
diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb
b/test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb
index 1f7caf64c3..fa16107c56 100644
--- a/test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb
+++ b/test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb
@@ -62,6 +62,23 @@ without_paren = a + b *
c * d +
12
+{'a' => {
+ 'b' => 'c',
+ 'd' => %w(e f)
+ }
+}
+
+[1, 2, {
+ 'b' => 'c',
+ 'd' => %w(e f)
+ }
+]
+
+foo(a, {
+ a: b,
+ c: d
+ })
+
# Local Variables:
# mode: ruby-ts
# ruby-after-operator-indent: t