diff options
author | Dmitry Gutov <dgutov@yandex.ru> | 2023-01-20 03:56:44 +0200 |
---|---|---|
committer | Dmitry Gutov <dgutov@yandex.ru> | 2023-01-20 03:58:03 +0200 |
commit | d66ac5285f72e0343d1cc6aae2db70a00b35feed (patch) | |
tree | 7c8b6e57b5de85be9b786faa478a92da14f81874 /lisp/progmodes/ruby-ts-mode.el | |
parent | 370b1ac99ec4328981ce8502ecb03353dbea5041 (diff) | |
download | emacs-d66ac5285f72e0343d1cc6aae2db70a00b35feed.tar.gz emacs-d66ac5285f72e0343d1cc6aae2db70a00b35feed.tar.bz2 emacs-d66ac5285f72e0343d1cc6aae2db70a00b35feed.zip |
ruby-ts-mode: Highlight builtin methods
* lisp/progmodes/ruby-mode.el (ruby-builtin-methods-with-reqs)
(ruby-builtin-methods-no-reqs): New constants, extracted.
(ruby-font-lock-keywords): Replace values with references.
* lisp/progmodes/ruby-ts-mode.el (ruby-ts--builtin-methods): New
variable. Construct regexp from aforementioned constants' values.
* lisp/progmodes/ruby-ts-mode.el (ruby-ts--font-lock-settings):
Use it.
* lisp/progmodes/ruby-ts-mode.el (ruby-ts-mode):
Add new font-lock feature: builtin-functions.
* lisp/progmodes/ruby-ts-mode.el (ruby-ts--predefined-constants)
(ruby-ts--predefined-variables): Unrelated to the rest of the
patch, add string-start and string-end anchors.
Diffstat (limited to 'lisp/progmodes/ruby-ts-mode.el')
-rw-r--r-- | lisp/progmodes/ruby-ts-mode.el | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el index da2d00ce168..f365ca7f8c2 100644 --- a/lisp/progmodes/ruby-ts-mode.el +++ b/lisp/progmodes/ruby-ts-mode.el @@ -116,21 +116,30 @@ "Ruby's punctuation characters.") (defvar ruby-ts--predefined-constants - (rx (or "ARGF" "ARGV" "DATA" "ENV" "RUBY_COPYRIGHT" + (rx string-start + (or "ARGF" "ARGV" "DATA" "ENV" "RUBY_COPYRIGHT" "RUBY_DESCRIPTION" "RUBY_ENGINE" "RUBY_ENGINE_VERSION" "RUBY_PATCHLEVEL" "RUBY_PLATFORM" "RUBY_RELEASE_DATE" "RUBY_REVISION" "RUBY_VERSION" "STDERR" "STDIN" "STDOUT" - "TOPLEVEL_BINDING")) + "TOPLEVEL_BINDING") + string-end) "Ruby predefined global constants.") (defvar ruby-ts--predefined-variables - (rx (or "$!" "$@" "$~" "$&" "$‘" "$‘" "$+" "$=" "$/" "$\\" "$," "$;" + (rx string-start + (or "$!" "$@" "$~" "$&" "$‘" "$‘" "$+" "$=" "$/" "$\\" "$," "$;" "$." "$<" "$>" "$_" "$*" "$$" "$?" "$:" "$LOAD_PATH" "$LOADED_FEATURES" "$DEBUG" "$FILENAME" "$stderr" "$stdin" "$stdout" "$VERBOSE" "$-a" "$-i" "$-l" "$-p" - (seq "$" (+ digit)))) + (seq "$" (+ digit))) + string-end) "Ruby predefined global variables.") +(defvar ruby-ts--builtin-methods + (format "\\`%s\\'" (regexp-opt (append ruby-builtin-methods-no-reqs + ruby-builtin-methods-with-reqs))) + "Ruby built-in methods.") + (defconst ruby-ts--class-or-module-regex (rx string-start (or "class" "module" "singleton_class") @@ -324,6 +333,12 @@ values of OVERRIDE" (in_clause pattern: (identifier) @font-lock-variable-name-face)) + :language language + :feature 'builtin-functions + `((((identifier) @font-lock-builtin-face) + (:match ,ruby-ts--builtin-methods + @font-lock-builtin-face))) + ;; Yuan recommends also putting method definitions into the ;; 'function' category (thus keeping it in both). I've opted to ;; just use separate categories for them -- dgutov. @@ -1022,9 +1037,9 @@ leading double colon is not added." (setq-local treesit-font-lock-feature-list '(( comment method-definition parameter-definition) ( keyword regexp string type) - ( builtin-variable builtin-constant constant + ( builtin-variable builtin-constant builtin-functions delimiter escape-sequence - global instance + constant global instance interpolation literal symbol assignment) ( bracket error function operator punctuation))) |