From: Jacob Faibussowitsch <jacob.fai@gmail.com>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: Yuan Fu <casouri@gmail.com>, 61655@debbugs.gnu.org
Subject: bug#61655: [Tree sitter] [Feature Request] font-lock function calls, definitions, separately
Date: Tue, 21 Feb 2023 10:31:17 -0500 [thread overview]
Message-ID: <56C0998E-3053-49F3-BAE3-46D6432B16F5@gmail.com> (raw)
In-Reply-To: <e33a4663-fb90-bbda-54ba-a2cc5b51dce4@yandex.ru>
> but it's a relatively small change,
Indeed, after playing around with the syntax queries a bit more, all that is needed to implement this change is the following patch.
Note for the new faces that I populated the `:foreground` fields to match the colors for the example I showed in my first email, but maybe a better default is to leave these faces totally blank and just purely `:inherit` from `font-lock-function-name-face`.
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 9e944fe188a..d170123c2ca 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -2026,6 +2026,16 @@ font-lock-function-name-face
"Font Lock mode face used to highlight function names."
:group 'font-lock-faces)
+(defface font-lock-function-call-face
+ '((t :inherit font-lock-function-name-face :foreground "royalblue1"))
+ "Font Lock mode face used to highlight function calls."
+ :group 'font-lock-faces)
+
+(defface font-lock-member-function-call-face
+ '((t :inherit font-lock-function-name-face :foreground "brightred"))
+ "Font Lock mode face used to highlight member function calls."
+ :group 'font-lock-faces)
+
(defface font-lock-variable-name-face
'((((class grayscale) (background light))
:foreground "Gray90" :weight bold :slant italic)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index b7a487687a8..51a65aa6545 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -529,8 +529,8 @@ c-ts-mode--font-lock-settings
:feature 'function
'((call_expression
function:
- [(identifier) @font-lock-function-name-face
- (field_expression field: (field_identifier) @font-lock-function-name-face)]))
+ [(identifier) @font-lock-function-call-face
+ (field_expression field: (field_identifier) @font-lock-member-function-call-face)]))
:language mode
:feature 'variable
Best regards,
Jacob Faibussowitsch
(Jacob Fai - booss - oh - vitch)
> On Feb 21, 2023, at 04:55, Dmitry Gutov <dgutov@yandex.ru> wrote:
>
> On 21/02/2023 10:28, Yuan Fu wrote:
>> Hmmm, yeah. The builtin tree-sitter maps syntax queries directly into
>> faces, where the third-party tree-sitter maps syntax queries to some
>> syntax types, then maps types to faces. So it would be a bit harder to
>> do fine-grained control like in the builtin tree-sitter, comparing to
>> the third-party one.
>> I’ve thought of this idea before but didn’t pursue it further: Right now
>> we allow capture names to be face names and functions, eg
>> (commment) @font-lock-comment-face
>> or
>> (comment) @xxx-moode-fortify-comment
>> Maybe we can add a third type, arbitrary symbols, like
>> (comment) @comment
>> and add a variables treesit-font-lock-mapping which maps symbols to
>> faces or functions:
>> ((comment . font-lock-comment-face))
>> or
>> ((comment . xxx-mode-fontify-comment))
>> Then we can easily support differentiating between function call and
>> function definition.
>
> Before we do any of that, don't we need actual different faces to use for e.g. function definitions and function calls?
>
> Same for variables.
>
> And if we have those, we might not need the indirection, at least not right away.
>
> I figured we'd add them in Emacs 30, but it's a relatively small change, if people are interested.
next prev parent reply other threads:[~2023-02-21 15:31 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-20 15:54 bug#61655: [Tree sitter] [Feature Request] font-lock function calls, definitions, separately Jacob Faibussowitsch
2023-02-20 17:03 ` Eli Zaretskii
2023-02-20 20:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-20 20:45 ` Jacob Faibussowitsch
2023-02-21 8:28 ` Yuan Fu
2023-02-21 9:55 ` Dmitry Gutov
2023-02-21 15:31 ` Jacob Faibussowitsch [this message]
2023-02-21 23:24 ` Dmitry Gutov
2023-02-22 18:07 ` Jacob Faibussowitsch
2023-02-22 21:39 ` Dmitry Gutov
2023-02-22 20:45 ` Yuan Fu
2023-02-22 21:38 ` Dmitry Gutov
2023-02-23 18:15 ` Eli Zaretskii
2023-02-24 2:31 ` Dmitry Gutov
2023-02-24 7:56 ` Eli Zaretskii
2023-02-24 11:31 ` Dmitry Gutov
2023-02-24 11:44 ` Eli Zaretskii
2023-02-24 14:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-25 1:06 ` Randy Taylor
2023-02-25 2:28 ` Dmitry Gutov
2023-02-25 3:59 ` Randy Taylor
2023-02-25 13:05 ` Dmitry Gutov
2023-02-28 2:09 ` Dmitry Gutov
2023-02-25 8:05 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56C0998E-3053-49F3-BAE3-46D6432B16F5@gmail.com \
--to=jacob.fai@gmail.com \
--cc=61655@debbugs.gnu.org \
--cc=casouri@gmail.com \
--cc=dgutov@yandex.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).