From 2ea6ee5cbfac5c5e9a1e27ddda2d88cdedc6a6eb Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Fri, 6 Jan 2023 19:56:20 +0200 Subject: [PATCH] (font-lock-regexp-face): New face * lisp/font-lock.el (font-lock-regexp-face): New face. * lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode--font-lock-settings): * lisp/progmodes/ruby-ts-mode.el (ruby-ts--font-lock-settings): * lisp/progmodes/js.el (js--treesit-font-lock-settings): Use it for regexps. * etc/NEWS: Mention the addition. --- etc/NEWS | 1 + lisp/font-lock.el | 6 ++++++ lisp/progmodes/js.el | 2 +- lisp/progmodes/ruby-ts-mode.el | 6 ++---- lisp/progmodes/typescript-ts-mode.el | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 059278b08a1..5901b2718e9 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -798,6 +798,7 @@ filter/sentinel error has been handled. These faces are primarily meant for use with tree-sitter. They are: 'font-lock-bracket-face', 'font-lock-delimiter-face', 'font-lock-escape-face', 'font-lock-number-face', +'font-lock-regexp-face', 'font-lock-misc-punctuation-face', 'font-lock-operator-face', 'font-lock-property-face', and 'font-lock-punctuation-face'. diff --git a/lisp/font-lock.el b/lisp/font-lock.el index 74881a14ccf..99df8fb9e06 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el @@ -2073,6 +2073,12 @@ as the constructs of Haddock, Javadoc and similar systems." "Font Lock mode face used to highlight preprocessor directives." :group 'font-lock-faces) +(defface font-lock-regexp-face + '((t :inherit font-lock-string-face)) + "Font Lock mode face used to highlight regexp literals." + :group 'font-lock-faces + :version "29.1") + (defface font-lock-regexp-grouping-backslash '((t :inherit bold)) "Font Lock mode face for backslashes in Lisp regexp grouping constructs." diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 90b9068fd5d..fe483f220da 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -3498,7 +3498,7 @@ This function is intended for use in `after-change-functions'." :language 'javascript :feature 'string - '((regex pattern: (regex_pattern)) @font-lock-string-face + '((regex pattern: (regex_pattern)) @font-lock-regexp-face (string) @font-lock-string-face) :language 'javascript diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el index bf09726b34f..5f5de500435 100644 --- a/lisp/progmodes/ruby-ts-mode.el +++ b/lisp/progmodes/ruby-ts-mode.el @@ -227,10 +227,8 @@ values of OVERRIDE" ;; Also before 'operator because % and / are operators :language language :feature 'regexp - ;; TODO: We probably need a separate face for regexps everywhere. - ;; Maybe another one for regexp delimiters as well. - '((regex "/" @font-lock-string-face) - (regex _ (string_content) @font-lock-string-face)) + '((regex "/" @font-lock-regexp-face) + (regex _ (string_content) @font-lock-regexp-face)) :language language :feature 'operator diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index 4042e2b1013..5a9a7eea959 100644 --- a/lisp/progmodes/typescript-ts-mode.el +++ b/lisp/progmodes/typescript-ts-mode.el @@ -151,7 +151,7 @@ Argument LANGUAGE is either `typescript' or `tsx'." :language language :override t :feature 'string - `((regex pattern: (regex_pattern)) @font-lock-string-face + `((regex pattern: (regex_pattern)) @font-lock-regexp-face (string) @font-lock-string-face (template_string) @js--fontify-template-string (template_substitution ["${" "}"] @font-lock-misc-punctuation-face)) -- 2.39.2