Function: ruby-ts-mode
ruby-ts-mode is an autoloaded, interactive and byte-compiled function
defined in ruby-ts-mode.el.gz.
Signature
(ruby-ts-mode)
Documentation
Major mode for editing Ruby, powered by tree-sitter.
In addition to any hooks its parent mode ruby-base-mode might have
run, this mode runs the hook ruby-ts-mode-hook, as the final or
penultimate step during initialization.
C-M-q prog-indent-sexp
C-c ' ruby-toggle-string-quotes
C-c C-f ruby-find-library-file
C-c { ruby-toggle-block
M-q prog-fill-reindent-defun
Probably introduced at or before Emacs version 29.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/ruby-ts-mode.el.gz
;;;###autoload
(define-derived-mode ruby-ts-mode ruby-base-mode "Ruby"
"Major mode for editing Ruby, powered by tree-sitter."
:group 'ruby
:syntax-table ruby-mode-syntax-table
(unless (treesit-ready-p 'ruby)
(error "Tree-sitter for Ruby isn't available"))
(treesit-parser-create 'ruby)
(setq-local add-log-current-defun-function #'ruby-ts-add-log-current-function)
;; Navigation.
(setq-local treesit-defun-type-regexp ruby-ts--method-regex)
(setq-local treesit-thing-settings
`((ruby
(sexp ,(cons (rx
bol
(or
"class"
"singleton_class"
"module"
"method"
"singleton_method"
"array"
"hash"
"parenthesized_statements"
"method_parameters"
"array_pattern"
"hash_pattern"
"if"
"else"
"then"
"unless"
"case"
"case_match"
"when"
"while"
"until"
"for"
"block"
"do_block"
"begin"
"integer"
"identifier"
"self"
"super"
"constant"
"simple_symbol"
"hash_key_symbol"
"symbol_array"
"string"
"string_array"
"heredoc_body"
"regex"
"argument_list"
"interpolation"
"instance_variable"
"global_variable"
)
eol)
#'ruby-ts--sexp-p))
(text ,(lambda (node)
(or (member (treesit-node-type node)
'("comment" "string_content" "heredoc_content"))
;; for C-M-f in hash[:key] and hash['key']
(and (member (treesit-node-text node)
'("[" "]"))
(equal (treesit-node-type
(treesit-node-parent node))
"element_reference"))
;; for C-M-f in "abc #{ghi} def"
(and (member (treesit-node-text node)
'("#{" "}"))
(equal (treesit-node-type
(treesit-node-parent node))
"interpolation"))))))))
;; Imenu.
(setq-local imenu-create-index-function #'ruby-ts--imenu)
;; Outline minor mode.
(setq-local treesit-outline-predicate
(rx bos (or "singleton_method"
"method"
"alias"
"class"
"module")
eos))
;; Restore default values of outline variables
;; to use `treesit-outline-predicate'.
(kill-local-variable 'outline-regexp)
(kill-local-variable 'outline-level)
(setq-local treesit-simple-indent-rules (ruby-ts--indent-rules))
;; Font-lock.
(setq-local treesit-font-lock-settings (ruby-ts--font-lock-settings 'ruby))
;; Level 3 is the default.
(setq-local treesit-font-lock-feature-list
'(( comment method-definition parameter-definition)
( keyword regexp string type)
( builtin-variable builtin-constant builtin-function
delimiter escape-sequence
constant global instance
interpolation literal symbol assignment)
( bracket error function operator punctuation)))
(treesit-major-mode-setup)
(setq-local syntax-propertize-function #'ruby-ts--syntax-propertize))