all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
@ 2022-11-01  1:21 Randy Taylor
  2022-11-01  2:14 ` Yuan Fu
  2022-11-01 22:54 ` Dmitry Gutov
  0 siblings, 2 replies; 22+ messages in thread
From: Randy Taylor @ 2022-11-01  1:21 UTC (permalink / raw)
  To: 58940


[-- Attachment #1.1: Type: text/plain, Size: 490 bytes --]

The attached patch adds the following faces:

- font-lock-escape-face
- font-lock-number-face
- font-lock-operator-face
- font-lock-property-face
- font-lock-punctuation-face

font-lock-property-face inherits font-lock-variable-name-face which matches the behaviour of cc-mode and python-mode.

font-lock-escape-face inherits nothing. In python-mode, it inherits font-lock-constant-face, but not in cc-mode. Do we want it to inherit anything?

Hopefully I put everything in the right place.

[-- Attachment #1.2: Type: text/html, Size: 1251 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-more-font-lock-faces.patch --]
[-- Type: text/x-patch; name=0001-Add-more-font-lock-faces.patch, Size: 5197 bytes --]

From 8f05a744744143ce05a0eee0ab8ac9926bc5f3eb Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Fri, 28 Oct 2022 22:39:50 -0400
Subject: [PATCH] Add more font-lock faces

* lisp/font-lock.el (font-lock-escape-face, font-lock-number-face,
font-lock-operator-face, font-lock-property-face,
font-lock-punctuation-face): Define new faces.
* lisp/cus-theme.el (custom-theme--listed-faces): Add them to the list.
* doc/lispref/modes.texi (Faces for Font Lock): Document them.
* etc/NEWS: Mention them.
---
 doc/lispref/modes.texi | 21 ++++++++++++++++++++
 etc/NEWS               |  5 +++++
 lisp/cus-theme.el      |  7 +++++--
 lisp/font-lock.el      | 45 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index f587252422..0095d62026 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -3653,6 +3653,27 @@ Faces for Font Lock
 @item font-lock-negation-char-face
 @vindex font-lock-negation-char-face
 for easily-overlooked negation characters.
+
+@item font-lock-escape-face
+@vindex font-lock-escape-face
+for escape sequences in strings.
+
+@item font-lock-number-face
+@vindex font-lock-number-face
+for numbers.
+
+@item font-lock-operator-face
+@vindex font-lock-operator-face
+for operators.
+
+@item font-lock-property-face
+@vindex font-lock-property-face
+for properties, such as fields of a struct or class.
+This face inherits, by default, from @code{font-lock-variable-name-face}.
+
+@item font-lock-punctuation-face
+@vindex font-lock-punctuation-face
+for punctuation.
 @end table
 
 @node Syntactic Font Lock
diff --git a/etc/NEWS b/etc/NEWS
index c5a142b500..b1e342eff6 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -732,6 +732,11 @@ If the current buffer is visiting a file that is executable, the
 This determines how long to pause Emacs after a process
 filter/sentinel error has been handled.
 
++++
+** New faces for font-lock.
+'font-lock-escape-face', 'font-lock-number-face', 'font-lock-operator-face',
+'font-lock-property-face', 'font-lock-punctuation-face'.
+
 +++
 ** New face 'variable-pitch-text'.
 This face is like 'variable-pitch' (from which it inherits), but is
diff --git a/lisp/cus-theme.el b/lisp/cus-theme.el
index 90680ff68f..a977d6834c 100644
--- a/lisp/cus-theme.el
+++ b/lisp/cus-theme.el
@@ -68,9 +68,12 @@ custom-theme--listed-faces
   shadow secondary-selection trailing-whitespace
   font-lock-builtin-face font-lock-comment-delimiter-face
   font-lock-comment-face font-lock-constant-face
-  font-lock-doc-face font-lock-doc-markup-face font-lock-function-name-face
+  font-lock-doc-face font-lock-doc-markup-face
+  font-lock-escape-face font-lock-function-name-face
   font-lock-keyword-face font-lock-negation-char-face
-  font-lock-preprocessor-face font-lock-regexp-grouping-backslash
+  font-lock-number-face font-lock-operator-face
+  font-lock-preprocessor-face font-lock-property-face
+  font-lock-punctuation-face font-lock-regexp-grouping-backslash
   font-lock-regexp-grouping-construct font-lock-string-face
   font-lock-type-face font-lock-variable-name-face
   font-lock-warning-face button link link-visited fringe
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index b6f4150964..51c0b156ee 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -359,6 +359,21 @@ font-lock-negation-char-face
 (defvar font-lock-preprocessor-face	'font-lock-preprocessor-face
   "Face name to use for preprocessor directives.")
 
+(defvar font-lock-escape-face		'font-lock-escape-face
+  "Face name to use for escape sequences in strings.")
+
+(defvar font-lock-number-face		'font-lock-number-face
+  "Face name to use for numbers.")
+
+(defvar font-lock-operator-face	'font-lock-operator-face
+  "Face name to use for operators.")
+
+(defvar font-lock-property-face	'font-lock-property-face
+  "Face name to use for properties.")
+
+(defvar font-lock-punctuation-face	'font-lock-punctuation-face
+  "Face name to use for punctuation.")
+
 ;; Fontification variables:
 
 (defvar font-lock-keywords nil
@@ -2073,6 +2088,36 @@ font-lock-preprocessor-face
   "Font Lock mode face used to highlight preprocessor directives."
   :group 'font-lock-faces)
 
+(defface font-lock-escape-face
+  '((t nil))
+  "Font Lock mode face used to highlight escape sequences in strings."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-number-face
+  '((t nil))
+  "Font Lock mode face used to highlight numbers."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-operator-face
+  '((t nil))
+  "Font Lock mode face used to highlight operators."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-property-face
+  '((t :inherit font-lock-variable-name-face))
+  "Font Lock mode face used to highlight properties."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-punctuation-face
+  '((t nil))
+  "Font Lock mode face used to highlight punctuation."
+  :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."
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-01  1:21 bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces Randy Taylor
@ 2022-11-01  2:14 ` Yuan Fu
  2022-11-02  2:04   ` Randy Taylor
  2022-11-01 22:54 ` Dmitry Gutov
  1 sibling, 1 reply; 22+ messages in thread
From: Yuan Fu @ 2022-11-01  2:14 UTC (permalink / raw)
  To: Randy Taylor; +Cc: 58940



> On Oct 31, 2022, at 6:21 PM, Randy Taylor <dev@rjt.dev> wrote:
> 
> The attached patch adds the following faces:
> 	• font-lock-escape-face
> 	• font-lock-number-face
> 	• font-lock-operator-face
> 	• font-lock-property-face
> 	• font-lock-punctuation-face
> 
> font-lock-property-face inherits font-lock-variable-name-face which matches the behaviour of cc-mode and python-mode.
> 
> font-lock-escape-face inherits nothing. In python-mode, it inherits font-lock-constant-face, but not in cc-mode. Do we want it to inherit anything?
> 
> Hopefully I put everything in the right place.
> 
> <0001-Add-more-font-lock-faces.patch>

Looks good! I would add a bit more explanation/example for font-lock-property-face and font-lock-punctuation-face. Eg, it’s not immediately clear to me what does preperty represent (property of an object as in obj.prop?). And it would be nice to say that punctuation-face are for commas and parenthesises.

Yuan




^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-01  1:21 bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces Randy Taylor
  2022-11-01  2:14 ` Yuan Fu
@ 2022-11-01 22:54 ` Dmitry Gutov
  2022-11-02  2:30   ` Randy Taylor
  1 sibling, 1 reply; 22+ messages in thread
From: Dmitry Gutov @ 2022-11-01 22:54 UTC (permalink / raw)
  To: Randy Taylor, 58940

On 01.11.2022 03:21, Randy Taylor wrote:
> font-lock-escape-face inherits nothing. In python-mode, it inherits 
> font-lock-constant-face, but not in cc-mode. Do we want it to inherit 
> anything?

It might be a good idea to inherit from font-lock-regexp-grouping-backslash.

Or vice versa.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-01  2:14 ` Yuan Fu
@ 2022-11-02  2:04   ` Randy Taylor
  2022-11-02 12:27     ` Eli Zaretskii
  0 siblings, 1 reply; 22+ messages in thread
From: Randy Taylor @ 2022-11-02  2:04 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 58940

[-- Attachment #1: Type: text/plain, Size: 1063 bytes --]

On Monday, October 31st, 2022 at 22:14, Yuan Fu <casouri@gmail.com> wrote:

> Looks good! I would add a bit more explanation/example for font-lock-property-face and font-lock-punctuation-face. Eg, it’s not immediately clear to me what does preperty represent (property of an object as in obj.prop?). And it would be nice to say that punctuation-face are for commas and parenthesises.

I added explanations (and an example for property) to the
documentation.

I'm wondering if we want to separate out the punctuation as follows:
- font-lock-punctuation-delimiter-face
- font-lock-punctuation-bracket-face
- font-lock-punctuation-special-face for any punctuation that doesn't
  fit in the aforementioned categories.

These would all inherit from font-lock-punctuation-face.

I think it would be more useful than just having
font-lock-punctuation-face, since I think most people would style a
particular type of punctuation, as opposed to all of it. And in the
definition of the highlight queries, they will usually be grouped like
above anyway.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-more-font-lock-faces.patch --]
[-- Type: text/x-patch; name=0001-Add-more-font-lock-faces.patch, Size: 5531 bytes --]

From 8ab8545af0dc13d6e90d62063777f90c53bea911 Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Fri, 28 Oct 2022 22:39:50 -0400
Subject: [PATCH] Add more font-lock faces

* lisp/font-lock.el (font-lock-escape-face, font-lock-number-face,
font-lock-operator-face, font-lock-property-face,
font-lock-punctuation-face): Define new faces.
* lisp/cus-theme.el (custom-theme--listed-faces): Add them to the list.
* doc/lispref/modes.texi (Faces for Font Lock): Document them.
* etc/NEWS: Mention them.
---
 doc/lispref/modes.texi | 40 +++++++++++++++++++++++++++++++++++++
 etc/NEWS               |  5 +++++
 lisp/cus-theme.el      |  7 +++++--
 lisp/font-lock.el      | 45 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+), 2 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index d778636d6d..d996446189 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -3653,6 +3653,46 @@ Faces for Font Lock
 @item font-lock-negation-char-face
 @vindex font-lock-negation-char-face
 for easily-overlooked negation characters.
+
+@item font-lock-escape-face
+@vindex font-lock-escape-face
+for escape sequences in strings.
+
+@item font-lock-number-face
+@vindex font-lock-number-face
+for numbers.
+
+@item font-lock-operator-face
+@vindex font-lock-operator-face
+for operators.
+
+@item font-lock-property-face
+@vindex font-lock-property-face
+for properties of an object, such as the declaration and use of fields
+in a struct.
+This face inherits, by default, from @code{font-lock-variable-name-face}.
+
+For example,
+
+@smallexample
+typedef struct
+@{
+  int prop;
+//    ^ property
+@} obj;
+
+int main()
+@{
+  obj o;
+  o.prop = 3;
+//  ^ property
+@}
+@end smallexample
+
+@item font-lock-punctuation-face
+@vindex font-lock-punctuation-face
+for punctuation such as delimiters (e.g. @code{;}, @code{:}, @code{,})
+and brackets (e.g. @code{()}, @code{[]}, @code{@{@}}).
 @end table
 
 @node Syntactic Font Lock
diff --git a/etc/NEWS b/etc/NEWS
index c5a142b500..b1e342eff6 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -732,6 +732,11 @@ If the current buffer is visiting a file that is executable, the
 This determines how long to pause Emacs after a process
 filter/sentinel error has been handled.
 
++++
+** New faces for font-lock.
+'font-lock-escape-face', 'font-lock-number-face', 'font-lock-operator-face',
+'font-lock-property-face', 'font-lock-punctuation-face'.
+
 +++
 ** New face 'variable-pitch-text'.
 This face is like 'variable-pitch' (from which it inherits), but is
diff --git a/lisp/cus-theme.el b/lisp/cus-theme.el
index 90680ff68f..a977d6834c 100644
--- a/lisp/cus-theme.el
+++ b/lisp/cus-theme.el
@@ -68,9 +68,12 @@ custom-theme--listed-faces
   shadow secondary-selection trailing-whitespace
   font-lock-builtin-face font-lock-comment-delimiter-face
   font-lock-comment-face font-lock-constant-face
-  font-lock-doc-face font-lock-doc-markup-face font-lock-function-name-face
+  font-lock-doc-face font-lock-doc-markup-face
+  font-lock-escape-face font-lock-function-name-face
   font-lock-keyword-face font-lock-negation-char-face
-  font-lock-preprocessor-face font-lock-regexp-grouping-backslash
+  font-lock-number-face font-lock-operator-face
+  font-lock-preprocessor-face font-lock-property-face
+  font-lock-punctuation-face font-lock-regexp-grouping-backslash
   font-lock-regexp-grouping-construct font-lock-string-face
   font-lock-type-face font-lock-variable-name-face
   font-lock-warning-face button link link-visited fringe
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index e88dc1d3b7..3870a512bc 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -359,6 +359,21 @@ font-lock-negation-char-face
 (defvar font-lock-preprocessor-face	'font-lock-preprocessor-face
   "Face name to use for preprocessor directives.")
 
+(defvar font-lock-escape-face		'font-lock-escape-face
+  "Face name to use for escape sequences in strings.")
+
+(defvar font-lock-number-face		'font-lock-number-face
+  "Face name to use for numbers.")
+
+(defvar font-lock-operator-face	'font-lock-operator-face
+  "Face name to use for operators.")
+
+(defvar font-lock-property-face	'font-lock-property-face
+  "Face name to use for properties.")
+
+(defvar font-lock-punctuation-face	'font-lock-punctuation-face
+  "Face name to use for punctuation.")
+
 ;; Fontification variables:
 
 (defvar font-lock-keywords nil
@@ -2085,6 +2100,36 @@ font-lock-preprocessor-face
   "Font Lock mode face used to highlight preprocessor directives."
   :group 'font-lock-faces)
 
+(defface font-lock-escape-face
+  '((t nil))
+  "Font Lock mode face used to highlight escape sequences in strings."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-number-face
+  '((t nil))
+  "Font Lock mode face used to highlight numbers."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-operator-face
+  '((t nil))
+  "Font Lock mode face used to highlight operators."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-property-face
+  '((t :inherit font-lock-variable-name-face))
+  "Font Lock mode face used to highlight properties."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-punctuation-face
+  '((t nil))
+  "Font Lock mode face used to highlight punctuation."
+  :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."
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-01 22:54 ` Dmitry Gutov
@ 2022-11-02  2:30   ` Randy Taylor
  2022-11-02 13:41     ` Dmitry Gutov
  0 siblings, 1 reply; 22+ messages in thread
From: Randy Taylor @ 2022-11-02  2:30 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 58940

On Tuesday, November 1st, 2022 at 18:54, Dmitry Gutov <dgutov@yandex.ru> wrote:

> It might be a good idea to inherit from font-lock-regexp-grouping-backslash.
> 
> Or vice versa.

Thanks for the suggestion. It seems like a lot of modes don't do anything special for escape sequences, so to keep with status quo maybe it shouldn't inherit anything.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-02  2:04   ` Randy Taylor
@ 2022-11-02 12:27     ` Eli Zaretskii
  2022-11-05  2:46       ` Randy Taylor
  0 siblings, 1 reply; 22+ messages in thread
From: Eli Zaretskii @ 2022-11-02 12:27 UTC (permalink / raw)
  To: Randy Taylor; +Cc: casouri, 58940

> Cc: 58940@debbugs.gnu.org
> Date: Wed, 02 Nov 2022 02:04:12 +0000
> From: Randy Taylor <dev@rjt.dev>
> 
> I'm wondering if we want to separate out the punctuation as follows:
> - font-lock-punctuation-delimiter-face
> - font-lock-punctuation-bracket-face
> - font-lock-punctuation-special-face for any punctuation that doesn't
>   fit in the aforementioned categories.

The names are too wordy, IMO.  If we want the above, I suggest

  font-lock-delimiter-face
  font-lock-bracket-face
  font-lock-misc-punctuation-face





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-02  2:30   ` Randy Taylor
@ 2022-11-02 13:41     ` Dmitry Gutov
  2022-11-03  2:30       ` Randy Taylor
  0 siblings, 1 reply; 22+ messages in thread
From: Dmitry Gutov @ 2022-11-02 13:41 UTC (permalink / raw)
  To: Randy Taylor; +Cc: 58940

On 02.11.2022 04:30, Randy Taylor wrote:
> On Tuesday, November 1st, 2022 at 18:54, Dmitry Gutov<dgutov@yandex.ru>  wrote:
> 
>> It might be a good idea to inherit from font-lock-regexp-grouping-backslash.
>>
>> Or vice versa.
> Thanks for the suggestion. It seems like a lot of modes don't do anything special for escape sequences, so to keep with status quo maybe it shouldn't inherit anything.

This face has customizations in the default and other themes, so it can 
be useful to do something with it.

It's also inherited from in highlight-escape-sequences (ELPA package).

As for modes which don't do anything with escape sequences, the upside 
is that they won't be affected: no chance to break anything.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-02 13:41     ` Dmitry Gutov
@ 2022-11-03  2:30       ` Randy Taylor
  0 siblings, 0 replies; 22+ messages in thread
From: Randy Taylor @ 2022-11-03  2:30 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 58940

On Wednesday, November 2nd, 2022 at 09:41, Dmitry Gutov <dgutov@yandex.ru> wrote:
> This face has customizations in the default and other themes, so it can
> be useful to do something with it.
> 
> It's also inherited from in highlight-escape-sequences (ELPA package).
> 
> As for modes which don't do anything with escape sequences, the upside
> is that they won't be affected: no chance to break anything.
> 

Sure, I think it makes sense to inherit it. Modes that don't currently do anything with escape sequences will be affected when using tree-sitter however, although it's just bold in this case, so not really a big deal. And they could just remove escape sequence highlighting in that case too, if they want.

I'll post an updated patch (with Eli's feedback) sometime tomorrow.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-02 12:27     ` Eli Zaretskii
@ 2022-11-05  2:46       ` Randy Taylor
  2022-11-05  9:24         ` Eli Zaretskii
  0 siblings, 1 reply; 22+ messages in thread
From: Randy Taylor @ 2022-11-05  2:46 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: casouri, 58940

[-- Attachment #1: Type: text/plain, Size: 821 bytes --]

On Wednesday, November 2nd, 2022 at 08:27, Eli Zaretskii <eliz@gnu.org> wrote:
> 
> The names are too wordy, IMO. If we want the above, I suggest
> 
> font-lock-delimiter-face
> font-lock-bracket-face
> font-lock-misc-punctuation-face

Sorry for the delay, furniture building took longer than anticipated
and desired.

New changes:
- Finally remembered to add Bug# to commit message.
- Made font-lock-escape-face inherit from
  font-lock-regexp-grouping-backslash per Dmitry's suggestion.
- Added font-lock-{bracket,delimiter,misc-punctuation}-faces
  inheriting from font-lock-punctuation-face.

With the use of tree-sitter features for syntax highlighting
(i.e. specifying specific highlight capabilities), how do we see
punctuation being used? Just a 'punctuation feature that includes
everything?

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-more-font-lock-faces-Bug-58940.patch --]
[-- Type: text/x-patch; name=0001-Add-more-font-lock-faces-Bug-58940.patch, Size: 7680 bytes --]

From e8237990037625b0c937b1fa5486c811c64d3d16 Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Fri, 28 Oct 2022 22:39:50 -0400
Subject: [PATCH] Add more font-lock faces (Bug#58940)

* lisp/font-lock.el (font-lock-bracket-face, font-lock-delimiter-face,
font-lock-escape-face, font-lock-number-face,
font-lock-misc-punctuation-face, font-lock-operator-face,
font-lock-property-face, font-lock-punctuation-face): Define new
faces.
* lisp/cus-theme.el (custom-theme--listed-faces): Add them to the
list.
* doc/lispref/modes.texi (Faces for Font Lock): Document them.
* etc/NEWS: Mention them.
---
 doc/lispref/modes.texi | 54 +++++++++++++++++++++++++++++++
 etc/NEWS               |  7 ++++
 lisp/cus-theme.el      | 16 ++++++----
 lisp/font-lock.el      | 72 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 143 insertions(+), 6 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index c1b092247b..290bd5075e 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -3653,6 +3653,60 @@ Faces for Font Lock
 @item font-lock-negation-char-face
 @vindex font-lock-negation-char-face
 for easily-overlooked negation characters.
+
+@item font-lock-bracket-face
+@vindex font-lock-bracket-face
+for brackets (e.g. @code{()}, @code{[]}, @code{@{@}}).
+This face inherits, by default, from @code{font-lock-punctuation-face}.
+
+@item font-lock-delimiter-face
+@vindex font-lock-delimiter-face
+for delimiters (e.g. @code{;}, @code{:}, @code{,}).
+This face inherits, by default, from @code{font-lock-punctuation-face}.
+
+@item font-lock-escape-face
+@vindex font-lock-escape-face
+for escape sequences in strings.
+This face inherits, by default, from @code{font-lock-regexp-grouping-backslash}.
+
+@item font-lock-number-face
+@vindex font-lock-number-face
+for numbers.
+
+@item font-lock-misc-punctuation-face
+@vindex font-lock-misc-punctuation-face
+for punctuation that is not a bracket or delimiter.
+
+@item font-lock-operator-face
+@vindex font-lock-operator-face
+for operators.
+
+@item font-lock-property-face
+@vindex font-lock-property-face
+for properties of an object, such as the declaration and use of fields
+in a struct.
+This face inherits, by default, from @code{font-lock-variable-name-face}.
+
+For example,
+
+@smallexample
+typedef struct
+@{
+  int prop;
+//    ^ property
+@} obj;
+
+int main()
+@{
+  obj o;
+  o.prop = 3;
+//  ^ property
+@}
+@end smallexample
+
+@item font-lock-punctuation-face
+@vindex font-lock-punctuation-face
+for punctuation such as brackets and delimiters.
 @end table
 
 @node Syntactic Font Lock
diff --git a/etc/NEWS b/etc/NEWS
index c5a142b500..6cf92bdcca 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -732,6 +732,13 @@ If the current buffer is visiting a file that is executable, the
 This determines how long to pause Emacs after a process
 filter/sentinel error has been handled.
 
++++
+** New faces for font-lock.
+'font-lock-bracket-face', 'font-lock-delimiter-face',
+'font-lock-escape-face', 'font-lock-number-face',
+'font-lock-misc-punctuation-face', 'font-lock-operator-face',
+'font-lock-property-face', 'font-lock-punctuation-face'.
+
 +++
 ** New face 'variable-pitch-text'.
 This face is like 'variable-pitch' (from which it inherits), but is
diff --git a/lisp/cus-theme.el b/lisp/cus-theme.el
index 90680ff68f..1df2ab8db7 100644
--- a/lisp/cus-theme.el
+++ b/lisp/cus-theme.el
@@ -66,13 +66,17 @@ custom-theme--listed-faces
   variable-pitch escape-glyph homoglyph
   minibuffer-prompt highlight region
   shadow secondary-selection trailing-whitespace
-  font-lock-builtin-face font-lock-comment-delimiter-face
-  font-lock-comment-face font-lock-constant-face
-  font-lock-doc-face font-lock-doc-markup-face font-lock-function-name-face
+  font-lock-bracket-face font-lock-builtin-face
+  font-lock-comment-delimiter-face font-lock-comment-face
+  font-lock-constant-face font-lock-delimiter-face
+  font-lock-doc-face font-lock-doc-markup-face
+  font-lock-escape-face font-lock-function-name-face
   font-lock-keyword-face font-lock-negation-char-face
-  font-lock-preprocessor-face font-lock-regexp-grouping-backslash
-  font-lock-regexp-grouping-construct font-lock-string-face
-  font-lock-type-face font-lock-variable-name-face
+  font-lock-number-face font-lock-misc-punctuation-face
+  font-lock-operator-face font-lock-preprocessor-face
+  font-lock-property-face font-lock-punctuation-face
+  font-lock-regexp-grouping-backslash font-lock-regexp-grouping-construct
+  font-lock-string-face font-lock-type-face font-lock-variable-name-face
   font-lock-warning-face button link link-visited fringe
   header-line tooltip mode-line mode-line-buffer-id
   mode-line-emphasis mode-line-highlight mode-line-inactive
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index e88dc1d3b7..b79d578848 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -359,6 +359,30 @@ font-lock-negation-char-face
 (defvar font-lock-preprocessor-face	'font-lock-preprocessor-face
   "Face name to use for preprocessor directives.")
 
+(defvar font-lock-bracket-face		'font-lock-bracket-face
+  "Face name to use for brackets.")
+
+(defvar font-lock-delimiter-face	'font-lock-delimiter-face
+  "Face name to use for delimiters.")
+
+(defvar font-lock-escape-face		'font-lock-escape-face
+  "Face name to use for escape sequences in strings.")
+
+(defvar font-lock-number-face		'font-lock-number-face
+  "Face name to use for numbers.")
+
+(defvar font-lock-misc-punctuation-face 'font-lock-misc-punctuation-face
+  "Face name to use for miscellaneous punctuation.")
+
+(defvar font-lock-operator-face	'font-lock-operator-face
+  "Face name to use for operators.")
+
+(defvar font-lock-property-face	'font-lock-property-face
+  "Face name to use for properties.")
+
+(defvar font-lock-punctuation-face	'font-lock-punctuation-face
+  "Face name to use for punctuation.")
+
 ;; Fontification variables:
 
 (defvar font-lock-keywords nil
@@ -2085,6 +2109,54 @@ font-lock-preprocessor-face
   "Font Lock mode face used to highlight preprocessor directives."
   :group 'font-lock-faces)
 
+(defface font-lock-bracket-face
+  '((t :inherit font-lock-punctuation-face))
+  "Font Lock mode face used to highlight brackets."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-delimiter-face
+  '((t :inherit font-lock-punctuation-face))
+  "Font Lock mode face used to highlight delimiters."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-escape-face
+  '((t :inherit font-lock-regexp-grouping-backslash))
+  "Font Lock mode face used to highlight escape sequences in strings."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-number-face
+  '((t nil))
+  "Font Lock mode face used to highlight numbers."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-misc-punctuation-face
+  '((t :inherit font-lock-punctuation-face))
+  "Font Lock mode face used to highlight miscellaneous punctuation."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-operator-face
+  '((t nil))
+  "Font Lock mode face used to highlight operators."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-property-face
+  '((t :inherit font-lock-variable-name-face))
+  "Font Lock mode face used to highlight properties."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-punctuation-face
+  '((t nil))
+  "Font Lock mode face used to highlight punctuation."
+  :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."
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-05  2:46       ` Randy Taylor
@ 2022-11-05  9:24         ` Eli Zaretskii
  2022-11-06  1:00           ` Randy Taylor
  0 siblings, 1 reply; 22+ messages in thread
From: Eli Zaretskii @ 2022-11-05  9:24 UTC (permalink / raw)
  To: Randy Taylor; +Cc: casouri, 58940

> Date: Sat, 05 Nov 2022 02:46:30 +0000
> From: Randy Taylor <dev@rjt.dev>
> Cc: casouri@gmail.com, 58940@debbugs.gnu.org
> 
> Sorry for the delay, furniture building took longer than anticipated
> and desired.

We all have our lives, no need to apologize.

> +@item font-lock-delimiter-face
> +@vindex font-lock-delimiter-face
> +for delimiters (e.g. @code{;}, @code{:}, @code{,}).

You need a comma or a @: after "e.g.", to avoid its being interpreted
as the end of a sentence.

> +@item font-lock-escape-face
> +@vindex font-lock-escape-face
> +for escape sequences in strings.

I suggest an example of an escape sequence here, ideally from 2 or
more programming languages.

> +@smallexample
> +typedef struct
> +@{
> +  int prop;
> +//    ^ property
> +@} obj;
> +
> +int main()
> +@{
> +  obj o;
> +  o.prop = 3;
> +//  ^ property
> +@}
> +@end smallexample

Please use @group..@end group here, since the two parts of this can be
typeset on separate pages, but we don't want each one of thgem to be
broken between pages.

> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -732,6 +732,13 @@ If the current buffer is visiting a file that is executable, the
>  This determines how long to pause Emacs after a process
>  filter/sentinel error has been handled.
>  
> ++++
> +** New faces for font-lock.
> +'font-lock-bracket-face', 'font-lock-delimiter-face',
> +'font-lock-escape-face', 'font-lock-number-face',
> +'font-lock-misc-punctuation-face', 'font-lock-operator-face',
> +'font-lock-property-face', 'font-lock-punctuation-face'.

Should this say that they are primarily meant for use with
tree-sitter?

> +(defvar font-lock-property-face	'font-lock-property-face
> +  "Face name to use for properties.")

This doc string is too concise to be useful.  Please add some
information from the detailed descriptions above.

> +(defface font-lock-bracket-face
> +  '((t :inherit font-lock-punctuation-face))

It is better to have the parent face font-lock-punctuation-face
defined before it is used.

Thanks.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-05  9:24         ` Eli Zaretskii
@ 2022-11-06  1:00           ` Randy Taylor
  2022-11-06  6:14             ` Eli Zaretskii
  2022-11-06  8:22             ` Eli Zaretskii
  0 siblings, 2 replies; 22+ messages in thread
From: Randy Taylor @ 2022-11-06  1:00 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: casouri, 58940

[-- Attachment #1: Type: text/plain, Size: 551 bytes --]

On Saturday, November 5th, 2022 at 05:24, Eli Zaretskii <eliz@gnu.org> wrote:

> I suggest an example of an escape sequence here, ideally from 2 or
> more programming languages.

Example added, but not sure about a second programming language. Isn't it basically the same for most programming languages?

> It is better to have the parent face font-lock-punctuation-face
> defined before it is used.

Done. BTW I see that font-lock-regexp-grouping-{backslash,construct}
do not have related variables like the rest of the faces. Why is that?

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-more-font-lock-faces-Bug-58940.patch --]
[-- Type: text/x-patch; name=0001-Add-more-font-lock-faces-Bug-58940.patch, Size: 8004 bytes --]

From a48b49413891e9e2be389ed6992a45d204093cad Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Fri, 28 Oct 2022 22:39:50 -0400
Subject: [PATCH] Add more font-lock faces (Bug#58940)

* lisp/font-lock.el (font-lock-bracket-face, font-lock-delimiter-face,
font-lock-escape-face, font-lock-number-face,
font-lock-misc-punctuation-face, font-lock-operator-face,
font-lock-property-face, font-lock-punctuation-face): Define new
faces.
* lisp/cus-theme.el (custom-theme--listed-faces): Add them to the
list.
* doc/lispref/modes.texi (Faces for Font Lock): Document them.
* etc/NEWS: Mention them.
---
 doc/lispref/modes.texi | 65 +++++++++++++++++++++++++++++++++++++
 etc/NEWS               |  8 +++++
 lisp/cus-theme.el      | 16 +++++----
 lisp/font-lock.el      | 73 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 156 insertions(+), 6 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index c1b092247b..3f3e7037cf 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -3653,6 +3653,71 @@ Faces for Font Lock
 @item font-lock-negation-char-face
 @vindex font-lock-negation-char-face
 for easily-overlooked negation characters.
+
+@item font-lock-escape-face
+@vindex font-lock-escape-face
+for escape sequences in strings.
+This face inherits, by default, from @code{font-lock-regexp-grouping-backslash}.
+
+Here is an example in Python, where the escape sequence @code{\n} is used:
+
+@smallexample
+@group
+print('Hello world!\n')
+@end group
+@end smallexample
+
+@item font-lock-number-face
+@vindex font-lock-number-face
+for numbers.
+
+@item font-lock-operator-face
+@vindex font-lock-operator-face
+for operators.
+
+@item font-lock-property-face
+@vindex font-lock-property-face
+for properties of an object, such as the declaration and use of fields
+in a struct.
+This face inherits, by default, from @code{font-lock-variable-name-face}.
+
+For example,
+
+@smallexample
+@group
+typedef struct
+@{
+  int prop;
+//    ^ property
+@} obj;
+
+int main()
+@{
+  obj o;
+  o.prop = 3;
+//  ^ property
+@}
+@end group
+@end smallexample
+
+@item font-lock-punctuation-face
+@vindex font-lock-punctuation-face
+for punctuation such as brackets and delimiters.
+
+@item font-lock-bracket-face
+@vindex font-lock-bracket-face
+for brackets (e.g., @code{()}, @code{[]}, @code{@{@}}).
+This face inherits, by default, from @code{font-lock-punctuation-face}.
+
+@item font-lock-delimiter-face
+@vindex font-lock-delimiter-face
+for delimiters (e.g., @code{;}, @code{:}, @code{,}).
+This face inherits, by default, from @code{font-lock-punctuation-face}.
+
+@item font-lock-misc-punctuation-face
+@vindex font-lock-misc-punctuation-face
+for punctuation that is not a bracket or delimiter.
+This face inherits, by default, from @code{font-lock-punctuation-face}.
 @end table
 
 @node Syntactic Font Lock
diff --git a/etc/NEWS b/etc/NEWS
index c5a142b500..74f1948569 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -732,6 +732,14 @@ If the current buffer is visiting a file that is executable, the
 This determines how long to pause Emacs after a process
 filter/sentinel error has been handled.
 
++++
+** New faces for font-lock.
+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-misc-punctuation-face', 'font-lock-operator-face',
+'font-lock-property-face', 'font-lock-punctuation-face'.
+
 +++
 ** New face 'variable-pitch-text'.
 This face is like 'variable-pitch' (from which it inherits), but is
diff --git a/lisp/cus-theme.el b/lisp/cus-theme.el
index 90680ff68f..1df2ab8db7 100644
--- a/lisp/cus-theme.el
+++ b/lisp/cus-theme.el
@@ -66,13 +66,17 @@ custom-theme--listed-faces
   variable-pitch escape-glyph homoglyph
   minibuffer-prompt highlight region
   shadow secondary-selection trailing-whitespace
-  font-lock-builtin-face font-lock-comment-delimiter-face
-  font-lock-comment-face font-lock-constant-face
-  font-lock-doc-face font-lock-doc-markup-face font-lock-function-name-face
+  font-lock-bracket-face font-lock-builtin-face
+  font-lock-comment-delimiter-face font-lock-comment-face
+  font-lock-constant-face font-lock-delimiter-face
+  font-lock-doc-face font-lock-doc-markup-face
+  font-lock-escape-face font-lock-function-name-face
   font-lock-keyword-face font-lock-negation-char-face
-  font-lock-preprocessor-face font-lock-regexp-grouping-backslash
-  font-lock-regexp-grouping-construct font-lock-string-face
-  font-lock-type-face font-lock-variable-name-face
+  font-lock-number-face font-lock-misc-punctuation-face
+  font-lock-operator-face font-lock-preprocessor-face
+  font-lock-property-face font-lock-punctuation-face
+  font-lock-regexp-grouping-backslash font-lock-regexp-grouping-construct
+  font-lock-string-face font-lock-type-face font-lock-variable-name-face
   font-lock-warning-face button link link-visited fringe
   header-line tooltip mode-line mode-line-buffer-id
   mode-line-emphasis mode-line-highlight mode-line-inactive
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index e88dc1d3b7..6e284dd3e5 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -359,6 +359,30 @@ font-lock-negation-char-face
 (defvar font-lock-preprocessor-face	'font-lock-preprocessor-face
   "Face name to use for preprocessor directives.")
 
+(defvar font-lock-escape-face		'font-lock-escape-face
+  "Face name to use for escape sequences in strings.")
+
+(defvar font-lock-number-face		'font-lock-number-face
+  "Face name to use for numbers.")
+
+(defvar font-lock-operator-face	'font-lock-operator-face
+  "Face name to use for operators.")
+
+(defvar font-lock-property-face	'font-lock-property-face
+  "Face name to use for properties.")
+
+(defvar font-lock-punctuation-face	'font-lock-punctuation-face
+  "Face name to use for punctuation.")
+
+(defvar font-lock-bracket-face		'font-lock-bracket-face
+  "Face name to use for brackets.")
+
+(defvar font-lock-delimiter-face	'font-lock-delimiter-face
+  "Face name to use for delimiters.")
+
+(defvar font-lock-misc-punctuation-face 'font-lock-misc-punctuation-face
+  "Face name to use for miscellaneous punctuation.")
+
 ;; Fontification variables:
 
 (defvar font-lock-keywords nil
@@ -2095,6 +2119,55 @@ font-lock-regexp-grouping-construct
   "Font Lock mode face used to highlight grouping constructs in Lisp regexps."
   :group 'font-lock-faces)
 
+(defface font-lock-escape-face
+  '((t :inherit font-lock-regexp-grouping-backslash))
+  "Font Lock mode face used to highlight escape sequences in strings."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-number-face
+  '((t nil))
+  "Font Lock mode face used to highlight numbers."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-operator-face
+  '((t nil))
+  "Font Lock mode face used to highlight operators."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-property-face
+  '((t :inherit font-lock-variable-name-face))
+  "Font Lock mode face used to highlight properties of an object, such
+as the declaration and use of fields in a struct."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-punctuation-face
+  '((t nil))
+  "Font Lock mode face used to highlight punctuation."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-bracket-face
+  '((t :inherit font-lock-punctuation-face))
+  "Font Lock mode face used to highlight brackets."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-delimiter-face
+  '((t :inherit font-lock-punctuation-face))
+  "Font Lock mode face used to highlight delimiters."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-misc-punctuation-face
+  '((t :inherit font-lock-punctuation-face))
+  "Font Lock mode face used to highlight miscellaneous punctuation."
+  :group 'font-lock-faces
+  :version "29.1")
+
 ;; End of Color etc. support.
 \f
 ;;; Menu support.
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-06  1:00           ` Randy Taylor
@ 2022-11-06  6:14             ` Eli Zaretskii
  2022-11-06 14:05               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-11-06  8:22             ` Eli Zaretskii
  1 sibling, 1 reply; 22+ messages in thread
From: Eli Zaretskii @ 2022-11-06  6:14 UTC (permalink / raw)
  To: Randy Taylor, Stefan Monnier; +Cc: casouri, 58940

> Date: Sun, 06 Nov 2022 01:00:38 +0000
> From: Randy Taylor <dev@rjt.dev>
> Cc: casouri@gmail.com, 58940@debbugs.gnu.org
> 
> BTW I see that font-lock-regexp-grouping-{backslash,construct}
> do not have related variables like the rest of the faces. Why is that?

No idea.  I didn't even know we had those faces until I've read your
patch.

Stefan, any idea why those faces don't have variables?





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-06  1:00           ` Randy Taylor
  2022-11-06  6:14             ` Eli Zaretskii
@ 2022-11-06  8:22             ` Eli Zaretskii
  2022-11-06 17:02               ` Randy Taylor
  1 sibling, 1 reply; 22+ messages in thread
From: Eli Zaretskii @ 2022-11-06  8:22 UTC (permalink / raw)
  To: Randy Taylor; +Cc: casouri, 58940

> Date: Sun, 06 Nov 2022 01:00:38 +0000
> From: Randy Taylor <dev@rjt.dev>
> Cc: casouri@gmail.com, 58940@debbugs.gnu.org
> 
> On Saturday, November 5th, 2022 at 05:24, Eli Zaretskii <eliz@gnu.org> wrote:
> 
> > I suggest an example of an escape sequence here, ideally from 2 or
> > more programming languages.
> 
> Example added, but not sure about a second programming language. Isn't it basically the same for most programming languages?

Maybe one example is enough, thanks.

> +(defface font-lock-property-face
> +  '((t :inherit font-lock-variable-name-face))
> +  "Font Lock mode face used to highlight properties of an object, such
> +as the declaration and use of fields in a struct."

The first line of a doc string should be a single complete sentence.

I suggest to have the detailed description be separate sentences
after the first one.

Otherwise, LGTM, thanks.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-06  6:14             ` Eli Zaretskii
@ 2022-11-06 14:05               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-11-06 16:43                 ` Randy Taylor
  2022-11-06 19:24                 ` Stefan Kangas
  0 siblings, 2 replies; 22+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-06 14:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Randy Taylor, casouri, 58940

>> BTW I see that font-lock-regexp-grouping-{backslash,construct}
>> do not have related variables like the rest of the faces. Why is that?
>
> No idea.  I didn't even know we had those faces until I've read your
> patch.
>
> Stefan, any idea why those faces don't have variables?

Not really, no.  But AFAIK the "variable associated with a face" is an
old idiosyncrasy of `font-lock.el` that's never been explained
nor justified.  It was used at some point for customization purposes (to
tweak the face buffer-locally) but we introduced the face-remapping
facility as a better replacement for that hack, so faces should not need
accompanying vars since Emacs-23.

I suspect that's part of the reason.  Ideally, we'd phase out those old
`font-lock-*-face` variables rather than introduce new ones.
I think the only thing they bring nowadays is confusion.


        Stefan






^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-06 14:05               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-11-06 16:43                 ` Randy Taylor
  2022-11-06 19:24                 ` Stefan Kangas
  1 sibling, 0 replies; 22+ messages in thread
From: Randy Taylor @ 2022-11-06 16:43 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Eli Zaretskii, casouri, 58940

On Sunday, November 6th, 2022 at 09:05, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> 
> >> BTW I see that font-lock-regexp-grouping-{backslash,construct}
> 
> > > do not have related variables like the rest of the faces. Why is that?
> > 
> > No idea. I didn't even know we had those faces until I've read your
> > patch.
> > 
> > Stefan, any idea why those faces don't have variables?
> 
> 
> Not really, no. But AFAIK the "variable associated with a face" is an
> old idiosyncrasy of `font-lock.el` that's never been explained
> nor justified. It was used at some point for customization purposes (to
> tweak the face buffer-locally) but we introduced the face-remapping
> facility as a better replacement for that hack, so faces should not need
> accompanying vars since Emacs-23.
> 
> I suspect that's part of the reason. Ideally, we'd phase out those old
> `font-lock-*-face` variables rather than introduce new ones.
> I think the only thing they bring nowadays is confusion.
>

Thanks, I'll remove them in the next patch.

I was following 1bfbb2b706db6a7ca9420b27d22a737deccdd5b0 for inspiration, hence why I included them.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-06  8:22             ` Eli Zaretskii
@ 2022-11-06 17:02               ` Randy Taylor
  2022-11-10  2:47                 ` Randy Taylor
  0 siblings, 1 reply; 22+ messages in thread
From: Randy Taylor @ 2022-11-06 17:02 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: casouri, 58940

[-- Attachment #1: Type: text/plain, Size: 794 bytes --]

On Sunday, November 6th, 2022 at 03:22, Eli Zaretskii <eliz@gnu.org> wrote:

> 
> > +(defface font-lock-property-face
> > + '((t :inherit font-lock-variable-name-face))
> > + "Font Lock mode face used to highlight properties of an object, such
> > +as the declaration and use of fields in a struct."
> 
> 
> The first line of a doc string should be a single complete sentence.
> 
> I suggest to have the detailed description be separate sentences
> after the first one.
> 

I wonder if that detailed description is really necessary anymore? Before the doc string read "...highlight properties". Now it reads "...highlight properties of an object." - perhaps that's enough? Regardless, I separated the detailed description out to its own sentence.

I also removed the variables.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-more-font-lock-faces-Bug-58940.patch --]
[-- Type: text/x-patch; name=0001-Add-more-font-lock-faces-Bug-58940.patch, Size: 6937 bytes --]

From d697b284cb17872b20dec02d6929b0480791f7c1 Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Fri, 28 Oct 2022 22:39:50 -0400
Subject: [PATCH] Add more font-lock faces (Bug#58940)

* lisp/font-lock.el (font-lock-bracket-face, font-lock-delimiter-face,
font-lock-escape-face, font-lock-number-face,
font-lock-misc-punctuation-face, font-lock-operator-face,
font-lock-property-face, font-lock-punctuation-face): Define new
faces.
* lisp/cus-theme.el (custom-theme--listed-faces): Add them to the
list.
* doc/lispref/modes.texi (Faces for Font Lock): Document them.
* etc/NEWS: Mention them.
---
 doc/lispref/modes.texi | 65 ++++++++++++++++++++++++++++++++++++++++++
 etc/NEWS               |  8 ++++++
 lisp/cus-theme.el      | 16 +++++++----
 lisp/font-lock.el      | 49 +++++++++++++++++++++++++++++++
 4 files changed, 132 insertions(+), 6 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index c1b092247b..3f3e7037cf 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -3653,6 +3653,71 @@ Faces for Font Lock
 @item font-lock-negation-char-face
 @vindex font-lock-negation-char-face
 for easily-overlooked negation characters.
+
+@item font-lock-escape-face
+@vindex font-lock-escape-face
+for escape sequences in strings.
+This face inherits, by default, from @code{font-lock-regexp-grouping-backslash}.
+
+Here is an example in Python, where the escape sequence @code{\n} is used:
+
+@smallexample
+@group
+print('Hello world!\n')
+@end group
+@end smallexample
+
+@item font-lock-number-face
+@vindex font-lock-number-face
+for numbers.
+
+@item font-lock-operator-face
+@vindex font-lock-operator-face
+for operators.
+
+@item font-lock-property-face
+@vindex font-lock-property-face
+for properties of an object, such as the declaration and use of fields
+in a struct.
+This face inherits, by default, from @code{font-lock-variable-name-face}.
+
+For example,
+
+@smallexample
+@group
+typedef struct
+@{
+  int prop;
+//    ^ property
+@} obj;
+
+int main()
+@{
+  obj o;
+  o.prop = 3;
+//  ^ property
+@}
+@end group
+@end smallexample
+
+@item font-lock-punctuation-face
+@vindex font-lock-punctuation-face
+for punctuation such as brackets and delimiters.
+
+@item font-lock-bracket-face
+@vindex font-lock-bracket-face
+for brackets (e.g., @code{()}, @code{[]}, @code{@{@}}).
+This face inherits, by default, from @code{font-lock-punctuation-face}.
+
+@item font-lock-delimiter-face
+@vindex font-lock-delimiter-face
+for delimiters (e.g., @code{;}, @code{:}, @code{,}).
+This face inherits, by default, from @code{font-lock-punctuation-face}.
+
+@item font-lock-misc-punctuation-face
+@vindex font-lock-misc-punctuation-face
+for punctuation that is not a bracket or delimiter.
+This face inherits, by default, from @code{font-lock-punctuation-face}.
 @end table
 
 @node Syntactic Font Lock
diff --git a/etc/NEWS b/etc/NEWS
index c5a142b500..74f1948569 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -732,6 +732,14 @@ If the current buffer is visiting a file that is executable, the
 This determines how long to pause Emacs after a process
 filter/sentinel error has been handled.
 
++++
+** New faces for font-lock.
+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-misc-punctuation-face', 'font-lock-operator-face',
+'font-lock-property-face', 'font-lock-punctuation-face'.
+
 +++
 ** New face 'variable-pitch-text'.
 This face is like 'variable-pitch' (from which it inherits), but is
diff --git a/lisp/cus-theme.el b/lisp/cus-theme.el
index 90680ff68f..1df2ab8db7 100644
--- a/lisp/cus-theme.el
+++ b/lisp/cus-theme.el
@@ -66,13 +66,17 @@ custom-theme--listed-faces
   variable-pitch escape-glyph homoglyph
   minibuffer-prompt highlight region
   shadow secondary-selection trailing-whitespace
-  font-lock-builtin-face font-lock-comment-delimiter-face
-  font-lock-comment-face font-lock-constant-face
-  font-lock-doc-face font-lock-doc-markup-face font-lock-function-name-face
+  font-lock-bracket-face font-lock-builtin-face
+  font-lock-comment-delimiter-face font-lock-comment-face
+  font-lock-constant-face font-lock-delimiter-face
+  font-lock-doc-face font-lock-doc-markup-face
+  font-lock-escape-face font-lock-function-name-face
   font-lock-keyword-face font-lock-negation-char-face
-  font-lock-preprocessor-face font-lock-regexp-grouping-backslash
-  font-lock-regexp-grouping-construct font-lock-string-face
-  font-lock-type-face font-lock-variable-name-face
+  font-lock-number-face font-lock-misc-punctuation-face
+  font-lock-operator-face font-lock-preprocessor-face
+  font-lock-property-face font-lock-punctuation-face
+  font-lock-regexp-grouping-backslash font-lock-regexp-grouping-construct
+  font-lock-string-face font-lock-type-face font-lock-variable-name-face
   font-lock-warning-face button link link-visited fringe
   header-line tooltip mode-line mode-line-buffer-id
   mode-line-emphasis mode-line-highlight mode-line-inactive
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index e88dc1d3b7..baeafecf16 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -2095,6 +2095,55 @@ font-lock-regexp-grouping-construct
   "Font Lock mode face used to highlight grouping constructs in Lisp regexps."
   :group 'font-lock-faces)
 
+(defface font-lock-escape-face
+  '((t :inherit font-lock-regexp-grouping-backslash))
+  "Font Lock mode face used to highlight escape sequences in strings."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-number-face
+  '((t nil))
+  "Font Lock mode face used to highlight numbers."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-operator-face
+  '((t nil))
+  "Font Lock mode face used to highlight operators."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-property-face
+  '((t :inherit font-lock-variable-name-face))
+  "Font Lock mode face used to highlight properties of an object.
+For example, the declaration and use of fields in a struct."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-punctuation-face
+  '((t nil))
+  "Font Lock mode face used to highlight punctuation."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-bracket-face
+  '((t :inherit font-lock-punctuation-face))
+  "Font Lock mode face used to highlight brackets."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-delimiter-face
+  '((t :inherit font-lock-punctuation-face))
+  "Font Lock mode face used to highlight delimiters."
+  :group 'font-lock-faces
+  :version "29.1")
+
+(defface font-lock-misc-punctuation-face
+  '((t :inherit font-lock-punctuation-face))
+  "Font Lock mode face used to highlight miscellaneous punctuation."
+  :group 'font-lock-faces
+  :version "29.1")
+
 ;; End of Color etc. support.
 \f
 ;;; Menu support.
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-06 14:05               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-11-06 16:43                 ` Randy Taylor
@ 2022-11-06 19:24                 ` Stefan Kangas
  2022-11-07  1:33                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 22+ messages in thread
From: Stefan Kangas @ 2022-11-06 19:24 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Randy Taylor, Eli Zaretskii, casouri, 58940

> I suspect that's part of the reason.  Ideally, we'd phase out those old
> `font-lock-*-face` variables rather than introduce new ones.
> I think the only thing they bring nowadays is confusion.

Would it be worth it to make them obsolete?





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-06 19:24                 ` Stefan Kangas
@ 2022-11-07  1:33                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-11-07  3:31                     ` Eli Zaretskii
  0 siblings, 1 reply; 22+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-11-07  1:33 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Randy Taylor, Eli Zaretskii, casouri, 58940

>> I suspect that's part of the reason.  Ideally, we'd phase out those old
>> `font-lock-*-face` variables rather than introduce new ones.
>> I think the only thing they bring nowadays is confusion.
> Would it be worth it to make them obsolete?

I'd be in favor, yes.

Note that most uses are within the `<foo>-font-lock-keywords` variables
where they're invisible to the byte-compiler, so users/maintainers won't
get to see very many warnings.  Maybe we could tweak
`font-lock-compile-keywords` to emit further warnings, but that will
trigger at run-time rather than compile-time :-(


        Stefan






^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-07  1:33                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-11-07  3:31                     ` Eli Zaretskii
  0 siblings, 0 replies; 22+ messages in thread
From: Eli Zaretskii @ 2022-11-07  3:31 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: dev, casouri, stefankangas, 58940

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: Eli Zaretskii <eliz@gnu.org>,  Randy Taylor <dev@rjt.dev>,
>   casouri@gmail.com,  58940@debbugs.gnu.org
> Date: Sun, 06 Nov 2022 20:33:18 -0500
> 
> >> I suspect that's part of the reason.  Ideally, we'd phase out those old
> >> `font-lock-*-face` variables rather than introduce new ones.
> >> I think the only thing they bring nowadays is confusion.
> > Would it be worth it to make them obsolete?
> 
> I'd be in favor, yes.

I wouldn't.  There's gobs of code out there which will suddenly get
warnings.  For what purpose?  Those variables cause no harm
whatsoever.

We shouldn't be too eager to obsolete things that cause us no harm.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-06 17:02               ` Randy Taylor
@ 2022-11-10  2:47                 ` Randy Taylor
  2022-11-10  3:59                   ` Yuan Fu
  0 siblings, 1 reply; 22+ messages in thread
From: Randy Taylor @ 2022-11-10  2:47 UTC (permalink / raw)
  To: casouri; +Cc: Eli Zaretskii, 58940

On Sunday, November 6th, 2022 at 12:02, Randy Taylor <dev@rjt.dev> wrote:
> 
> I wonder if that detailed description is really necessary anymore? Before the doc string read "...highlight properties". Now it reads "...highlight properties of an object." - perhaps that's enough? Regardless, I separated the detailed description out to its own sentence.
> 
> I also removed the variables.

Yuan, any further comments? If not, would you or someone else be able to push the patch?

Thanks.





^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-10  2:47                 ` Randy Taylor
@ 2022-11-10  3:59                   ` Yuan Fu
  2022-11-10 11:06                     ` Eli Zaretskii
  0 siblings, 1 reply; 22+ messages in thread
From: Yuan Fu @ 2022-11-10  3:59 UTC (permalink / raw)
  To: Randy Taylor; +Cc: Eli Zaretskii, 58940



> On Nov 9, 2022, at 6:47 PM, Randy Taylor <dev@rjt.dev> wrote:
> 
> On Sunday, November 6th, 2022 at 12:02, Randy Taylor <dev@rjt.dev> wrote:
>> 
>> I wonder if that detailed description is really necessary anymore? Before the doc string read "...highlight properties". Now it reads "...highlight properties of an object." - perhaps that's enough? Regardless, I separated the detailed description out to its own sentence.
>> 
>> I also removed the variables.
> 
> Yuan, any further comments? If not, would you or someone else be able to push the patch?
> 
> Thanks.

I don’t have much to say, since this is not really about tree-sitter. I’ll wait for other folks to decide & push ;-)

Yuan




^ permalink raw reply	[flat|nested] 22+ messages in thread

* bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces
  2022-11-10  3:59                   ` Yuan Fu
@ 2022-11-10 11:06                     ` Eli Zaretskii
  0 siblings, 0 replies; 22+ messages in thread
From: Eli Zaretskii @ 2022-11-10 11:06 UTC (permalink / raw)
  To: Yuan Fu; +Cc: dev, 58940-done

> From: Yuan Fu <casouri@gmail.com>
> Date: Wed, 9 Nov 2022 19:59:30 -0800
> Cc: Eli Zaretskii <eliz@gnu.org>,
>  58940@debbugs.gnu.org
> 
> > Yuan, any further comments? If not, would you or someone else be able to push the patch?
> > 
> > Thanks.
> 
> I don’t have much to say, since this is not really about tree-sitter. I’ll wait for other folks to decide & push ;-)

I installed it, thanks.





^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2022-11-10 11:06 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-01  1:21 bug#58940: [PATCH] feature/tree-sitter: Add more font lock faces Randy Taylor
2022-11-01  2:14 ` Yuan Fu
2022-11-02  2:04   ` Randy Taylor
2022-11-02 12:27     ` Eli Zaretskii
2022-11-05  2:46       ` Randy Taylor
2022-11-05  9:24         ` Eli Zaretskii
2022-11-06  1:00           ` Randy Taylor
2022-11-06  6:14             ` Eli Zaretskii
2022-11-06 14:05               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-06 16:43                 ` Randy Taylor
2022-11-06 19:24                 ` Stefan Kangas
2022-11-07  1:33                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-07  3:31                     ` Eli Zaretskii
2022-11-06  8:22             ` Eli Zaretskii
2022-11-06 17:02               ` Randy Taylor
2022-11-10  2:47                 ` Randy Taylor
2022-11-10  3:59                   ` Yuan Fu
2022-11-10 11:06                     ` Eli Zaretskii
2022-11-01 22:54 ` Dmitry Gutov
2022-11-02  2:30   ` Randy Taylor
2022-11-02 13:41     ` Dmitry Gutov
2022-11-03  2:30       ` Randy Taylor

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.