diff options
| author | Dmitry Gutov | 2023-01-19 05:10:05 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2023-01-19 05:27:43 +0200 |
| commit | 94b9cbf96fbb61b53242d205ff559deee36279c6 (patch) | |
| tree | aa2ac07b43540f344fda3ce268bcbf7a5909fada | |
| parent | ba33b83ce4b27b353441a174faaba024d59e4614 (diff) | |
| download | emacs-94b9cbf96fbb61b53242d205ff559deee36279c6.tar.gz emacs-94b9cbf96fbb61b53242d205ff559deee36279c6.zip | |
(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.
| -rw-r--r-- | lisp/progmodes/ruby-ts-mode.el | 29 | ||||
| -rw-r--r-- | 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 5df7e397f03..a2b2721dc1b 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 | |||
| 796 | (treesit-parent-until | 796 | (treesit-parent-until |
| 797 | parent | 797 | parent |
| 798 | (lambda (node) | 798 | (lambda (node) |
| 799 | (or (<= (treesit-node-start node) parent-bol) | 799 | (or (< (treesit-node-start node) parent-bol) |
| 800 | (and | 800 | (string-match-p "\\`array\\|hash\\'" (treesit-node-type node)) |
| 801 | ;; Parenless call. | 801 | ;; Method call on same line. |
| 802 | (equal (treesit-node-type node) "argument_list") | 802 | (equal (treesit-node-type node) "argument_list")))))) |
| 803 | (not (equal (treesit-node-type | ||
| 804 | (treesit-node-child node 0)) | ||
| 805 | "("))))) | ||
| 806 | t))) | ||
| 807 | (cond | 803 | (cond |
| 808 | ;; No parenless call found on the current line. | 804 | ((null found) |
| 809 | ((<= (treesit-node-start found) parent-bol) | ||
| 810 | parent-bol) | 805 | parent-bol) |
| 806 | ;; No paren/curly/brace found on the same line. | ||
| 807 | ((< (treesit-node-start found) parent-bol) | ||
| 808 | parent-bol) | ||
| 809 | ;; Hash or array opener on the same line. | ||
| 810 | ((string-match-p "\\`array\\|hash\\'" (treesit-node-type found)) | ||
| 811 | (save-excursion | ||
| 812 | (goto-char (treesit-node-start (treesit-node-child found 1))) | ||
| 813 | (point))) | ||
| 811 | ;; Parenless call found: indent to stmt with offset. | 814 | ;; Parenless call found: indent to stmt with offset. |
| 812 | ((not ruby-parenless-call-arguments-indent) | 815 | ((not ruby-parenless-call-arguments-indent) |
| 813 | (save-excursion | 816 | (save-excursion |
| @@ -815,6 +818,12 @@ a statement container is a node that matches | |||
| 815 | (ruby-ts--statement-ancestor found))) | 818 | (ruby-ts--statement-ancestor found))) |
| 816 | ;; (**) Same. | 819 | ;; (**) Same. |
| 817 | (+ (point) ruby-indent-level))) | 820 | (+ (point) ruby-indent-level))) |
| 821 | ;; Call with parens -- ident to first arg. | ||
| 822 | ((equal (treesit-node-type (treesit-node-child found 0)) | ||
| 823 | "(") | ||
| 824 | (save-excursion | ||
| 825 | (goto-char (treesit-node-start (treesit-node-child found 1))) | ||
| 826 | (point))) | ||
| 818 | ;; Indent to the parenless call args beginning. | 827 | ;; Indent to the parenless call args beginning. |
| 819 | (t | 828 | (t |
| 820 | (save-excursion | 829 | (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 1f7caf64c34..fa16107c56e 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 * | |||
| 62 | c * d + | 62 | c * d + |
| 63 | 12 | 63 | 12 |
| 64 | 64 | ||
| 65 | {'a' => { | ||
| 66 | 'b' => 'c', | ||
| 67 | 'd' => %w(e f) | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | [1, 2, { | ||
| 72 | 'b' => 'c', | ||
| 73 | 'd' => %w(e f) | ||
| 74 | } | ||
| 75 | ] | ||
| 76 | |||
| 77 | foo(a, { | ||
| 78 | a: b, | ||
| 79 | c: d | ||
| 80 | }) | ||
| 81 | |||
| 65 | # Local Variables: | 82 | # Local Variables: |
| 66 | # mode: ruby-ts | 83 | # mode: ruby-ts |
| 67 | # ruby-after-operator-indent: t | 84 | # ruby-after-operator-indent: t |