File: ruby-ts-mode.el.html
This file defines ruby-ts-mode which is a major mode for editing Ruby files that uses Tree Sitter to parse the language. More information about Tree Sitter can be found in the Elisp Info pages as well as this website: https://tree-sitter.github.io/tree-sitter/
For this major mode to work, Emacs has to be compiled with
tree-sitter support, and the Ruby grammar has to be compiled and
put somewhere Emacs can find it. See the docstring of
treesit-extra-load-path.
This mode doesn't associate itself with .rb files automatically. To use this mode by default, assuming you have the tree-sitter grammar available, do one of the following:
- Add the following to your init file:
(add-to-list 'major-mode-remap-alist '(ruby-mode . ruby-ts-mode))
- Customize 'auto-mode-alist' to turn ruby-ts-mode automatically.
For example:
(add-to-list 'auto-mode-alist
(cons (concat "\\\\(?:\\\\.\\\\(?:"
"rbw?\\\\|ru\\\\|rake\\\\|thor\\\\|axlsx"
"\\\\|jbuilder\\\\|rabl\\\\|gemspec\\\\|podspec"
"\\\\)"
"\\\\|/"
"\\\\(?:Gem\\\\|Rake\\\\|Cap\\\\|Thor"
"\\\\|Puppet\\\\|Berks\\\\|Brew\\\\|Fast"
"\\\\|Vagrant\\\\|Guard\\\\|Pod\\\\)file"
"\\\\)\\\\'")
'ruby-ts-mode))
will turn on the ruby-ts-mode for Ruby source files.
- If you have the Ruby grammar installed, customize
'treesit-enabled-modes' and add 'ruby-ts-mode' to it.
You can also turn on this mode manually in a buffer.
Tree Sitter brings a lot of power and versitility which can be broken into these features.
* Font Lock
The ability to color the source code is not new but what is new is the versatility to enable and disable particular font lock rules. I suggest reviewing variable treesit-font-lock-level and function treesit-font-lock-recompute-features to get a better understanding of the following.
Currently tree treesit-font-lock-feature-list is set with the
following levels:
1: comment method-definition parameter-definition
2: keyword regexp string type
3: builtin-variable builtin-constant builtin-function
delimiter escape-sequence
constant global instance
interpolation literal symbol assignment
4: bracket error function operator punctuation
Thus if treesit-font-lock-level is set to level 3 which is its default, all the features listed in levels 1 through 3 above will be enabled. i.e. those features will font lock or colorize the code accordingly. Individual features can be added and removed via treesit-font-lock-recompute-features.
describe-face can be used to view how a face looks.
* Indent
ruby-ts-mode tries to adhere to the indentation related user options from ruby-mode, such as ruby-indent-level, ruby-indent-tabs-mode, and so on.
Type 'M-x customize-group RET ruby RET' to see the options.
* IMenu
* Navigation
* Which-func
Defined variables (12)
ruby-ts--builtin-methods | Ruby built-in methods. |
ruby-ts--class-or-module-regex | Regular expression that matches a class or module’s node type. |
ruby-ts--delimiters | Ruby’s punctuation characters. |
ruby-ts--keywords | Ruby keywords for tree-sitter font-locking. |
ruby-ts--method-regex | Regular expression matching methods and singleton methods. |
ruby-ts--operators | Ruby operators for tree-sitter font-locking. |
ruby-ts--predefined-constants | Ruby predefined global constants. |
ruby-ts--predefined-variables | Ruby predefined global variables. |
ruby-ts--statement-container-regexp | Regular expression of the nodes that can contain statements. |
ruby-ts-mode-abbrev-table | Abbrev table for ‘ruby-ts-mode’. |
ruby-ts-mode-hook | Hook run after entering ‘ruby-ts-mode’. |
ruby-ts-mode-map | Keymap used in Ruby mode |