mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-05 03:39:38 +00:00
ruby-ts-mode: Support the option ruby-block-indent
* lisp/progmodes/ruby-ts-mode.el (ruby-ts--block-indent-anchor): New function. (ruby-ts--indent-rules): Use it. * test/lisp/progmodes/ruby-ts-mode-tests.el: Run indent test for ruby-block-indent.rb.
This commit is contained in:
parent
44c9cb8653
commit
352e41016b
2 changed files with 27 additions and 6 deletions
|
@ -780,12 +780,20 @@ i.e. expr of def foo(args) = expr is returned."
|
||||||
;; but with node set to the statement and parent set to
|
;; but with node set to the statement and parent set to
|
||||||
;; body_statement for all others. ... Fine. Be that way.
|
;; body_statement for all others. ... Fine. Be that way.
|
||||||
;; Ditto for "block" and "block_body"
|
;; Ditto for "block" and "block_body"
|
||||||
((node-is "body_statement") parent-bol ruby-indent-level)
|
((node-is "body_statement")
|
||||||
((parent-is "body_statement") (ruby-ts--bol ruby-ts--grand-parent-node) ruby-indent-level)
|
(ruby-ts--block-indent-anchor ruby-ts--parent-node)
|
||||||
((match "end" "do_block") parent-bol 0)
|
ruby-indent-level)
|
||||||
((n-p-gp "block_body" "block" nil) parent-bol ruby-indent-level)
|
((parent-is "body_statement")
|
||||||
((n-p-gp nil "block_body" "block") (ruby-ts--bol ruby-ts--grand-parent-node) ruby-indent-level)
|
(ruby-ts--block-indent-anchor ruby-ts--grand-parent-node)
|
||||||
((match "}" "block") parent-bol 0)
|
ruby-indent-level)
|
||||||
|
((match "end" "do_block") (ruby-ts--block-indent-anchor ruby-ts--parent-node) 0)
|
||||||
|
((n-p-gp "block_body" "block" nil)
|
||||||
|
(ruby-ts--block-indent-anchor ruby-ts--parent-node)
|
||||||
|
ruby-indent-level)
|
||||||
|
((n-p-gp nil "block_body" "block")
|
||||||
|
(ruby-ts--block-indent-anchor ruby-ts--grand-parent-node)
|
||||||
|
ruby-indent-level)
|
||||||
|
((match "}" "block") (ruby-ts--block-indent-anchor ruby-ts--parent-node) 0)
|
||||||
|
|
||||||
;; Chained strings
|
;; Chained strings
|
||||||
((match "string" "chained_string") first-sibling 0)
|
((match "string" "chained_string") first-sibling 0)
|
||||||
|
@ -794,6 +802,18 @@ i.e. expr of def foo(args) = expr is returned."
|
||||||
(catch-all parent-bol ruby-indent-level))))
|
(catch-all parent-bol ruby-indent-level))))
|
||||||
`((ruby . ,common))))
|
`((ruby . ,common))))
|
||||||
|
|
||||||
|
(defun ruby-ts--block-indent-anchor (block-node-getter)
|
||||||
|
(lambda (node parent _bol &rest _rest)
|
||||||
|
(let ((block-node (funcall block-node-getter node parent)))
|
||||||
|
(save-excursion
|
||||||
|
(goto-char
|
||||||
|
(treesit-node-start
|
||||||
|
(if ruby-block-indent
|
||||||
|
(ruby-ts--statement-ancestor block-node)
|
||||||
|
block-node)))
|
||||||
|
(back-to-indentation)
|
||||||
|
(point)))))
|
||||||
|
|
||||||
(defun ruby-ts--class-or-module-p (node)
|
(defun ruby-ts--class-or-module-p (node)
|
||||||
"Predicate if NODE is a class or module."
|
"Predicate if NODE is a class or module."
|
||||||
(string-match-p ruby-ts--class-or-module-regex (treesit-node-type node)))
|
(string-match-p ruby-ts--class-or-module-regex (treesit-node-type node)))
|
||||||
|
|
|
@ -251,6 +251,7 @@ The whitespace before and including \"|\" on each line is removed."
|
||||||
(kill-buffer buf)))))
|
(kill-buffer buf)))))
|
||||||
|
|
||||||
(ruby-ts-deftest-indent "ruby-method-params-indent.rb")
|
(ruby-ts-deftest-indent "ruby-method-params-indent.rb")
|
||||||
|
(ruby-ts-deftest-indent "ruby-block-indent.rb")
|
||||||
|
|
||||||
(provide 'ruby-ts-mode-tests)
|
(provide 'ruby-ts-mode-tests)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue