unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#70657: [PATCH] Add go-ts-mode font-locking for function var decls
@ 2024-04-29 23:22 Noah Peart
  2024-05-01  2:38 ` Randy Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: Noah Peart @ 2024-04-29 23:22 UTC (permalink / raw)
  To: 70657


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

Tags: patch


Adds font-locking for functions in go-ts-mode declared in var specs.

Currently, all the identifiers in var specs are given
font-lock-variable-name-face font-locking.

This patch adds a rule to give identifiers in var specs
font-lock-function-name-face when they are function types.

For example, the following test is included in the patch, showing where
font-lock-function-name is applied:

var x, y, z int
//    ^ font-lock-variable-name-face
//        ^ font-lock-variable-name-face
//                ^ font-lock-type-face
var foo, bar func(x int) int
//     ^ font-lock-function-name-face
//             ^ font-lock-function-name-face
//                         ^ font-lock-variable-name-face
//                             ^ font-lock-type-face
//                                   ^ font-lock-type-face


In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.33, cairo version 1.16.0) of 2024-04-29 built on noah-X580VD
Repository revision: 3000edc6179dfe0b5f24ae2e472826530809dfd1
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Ubuntu 22.04.4 LTS

Configured using:
 'configure --prefix=/usr/local --with-modules --with-tree-sitter
--with-threads --with-x-toolkit=gtk3 --with-xwidgets --with-gnutls
--with-json --with-mailutils --with-jpeg --with-png --with-rsvg
--with-tiff --with-xml2 --with-xpm --with-imagemagick CC=gcc-12
CXX=gcc-12'

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

[-- Attachment #2: 0001-Add-go-ts-mode-font-locking-for-function-var-decls.patch --]
[-- Type: text/x-patch, Size: 2977 bytes --]

From f5825cb56b847512103bf441fff05d05474a512c Mon Sep 17 00:00:00 2001
From: Noah Peart <noah.v.peart@gmail.com>
Date: Mon, 29 Apr 2024 16:14:43 -0700
Subject: [PATCH] Add go-ts-mode font-locking for function var decls

* lisp/progmodes/go-ts-mode.el (go-ts-mode--font-lock-settings):
Add font-locking rule for go-ts-mode functions declared in
var_specs.
* test/lisp/progmodes/go-ts-mode-resources/font-lock.go: New file
with font-locking tests for go-ts-mode.
* test/lisp/progmodes/go-ts-mode-tests.el: Add go-ts-mode
font-locking tests.
---
 lisp/progmodes/go-ts-mode.el                          |  3 +++
 test/lisp/progmodes/go-ts-mode-resources/font-lock.go | 11 +++++++++++
 test/lisp/progmodes/go-ts-mode-tests.el               |  6 ++++++
 3 files changed, 20 insertions(+)
 create mode 100644 test/lisp/progmodes/go-ts-mode-resources/font-lock.go

diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index aef224ab3fa..9c38985ff4e 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -179,6 +179,9 @@ go-ts-mode--font-lock-settings
       left: (expression_list
              (identifier) @font-lock-variable-name-face
              ("," (identifier) @font-lock-variable-name-face)*))
+     (var_spec name: (identifier) @font-lock-function-name-face
+               ("," name: (identifier) @font-lock-function-name-face)*
+               type: (function_type))
      (var_spec name: (identifier) @font-lock-variable-name-face
                ("," name: (identifier) @font-lock-variable-name-face)*))
 
diff --git a/test/lisp/progmodes/go-ts-mode-resources/font-lock.go b/test/lisp/progmodes/go-ts-mode-resources/font-lock.go
new file mode 100644
index 00000000000..8d8656f96e7
--- /dev/null
+++ b/test/lisp/progmodes/go-ts-mode-resources/font-lock.go
@@ -0,0 +1,11 @@
+package main
+var x, y, z int
+//  ^ font-lock-variable-name-face
+//     ^ font-lock-variable-name-face
+//           ^ font-lock-type-face
+var foo, bar func(x int) int
+//   ^ font-lock-function-name-face
+//        ^ font-lock-function-name-face
+//                ^ font-lock-variable-name-face
+//                    ^ font-lock-type-face
+//                        ^ font-lock-type-face
diff --git a/test/lisp/progmodes/go-ts-mode-tests.el b/test/lisp/progmodes/go-ts-mode-tests.el
index fd9b57e8691..761238e60a6 100644
--- a/test/lisp/progmodes/go-ts-mode-tests.el
+++ b/test/lisp/progmodes/go-ts-mode-tests.el
@@ -20,6 +20,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-font-lock)
 (require 'ert-x)
 (require 'treesit)
 
@@ -27,5 +28,10 @@ go-ts-mode-test-indentation
   (skip-unless (treesit-ready-p 'go))
   (ert-test-erts-file (ert-resource-file "indent.erts")))
 
+(ert-deftest go-ts-test-font-lock ()
+  (skip-unless (treesit-ready-p 'go))
+  (let ((treesit-font-lock-level 4))
+    (ert-font-lock-test-file (ert-resource-file "font-lock.go") 'go-ts-mode)))
+
 (provide 'go-ts-mode-tests)
 ;;; go-ts-mode-tests.el ends here
-- 
2.34.1


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

* bug#70657: [PATCH] Add go-ts-mode font-locking for function var decls
  2024-04-29 23:22 bug#70657: [PATCH] Add go-ts-mode font-locking for function var decls Noah Peart
@ 2024-05-01  2:38 ` Randy Taylor
  2024-05-02  4:31   ` Yuan Fu
  0 siblings, 1 reply; 5+ messages in thread
From: Randy Taylor @ 2024-05-01  2:38 UTC (permalink / raw)
  To: Noah Peart; +Cc: 70657

On Monday, April 29th, 2024 at 19:22, Noah Peart <noah.v.peart@gmail.com> wrote:
> Tags: patch
> 
> 
> Adds font-locking for functions in go-ts-mode declared in var specs.
> 
> Currently, all the identifiers in var specs are given
> font-lock-variable-name-face font-locking.
> 
> This patch adds a rule to give identifiers in var specs
> font-lock-function-name-face when they are function types.
> 
> For example, the following test is included in the patch, showing where
> font-lock-function-name is applied:
> 
> var x, y, z int
> // ^ font-lock-variable-name-face
> // ^ font-lock-variable-name-face
> // ^ font-lock-type-face
> var foo, bar func(x int) int
> // ^ font-lock-function-name-face
> // ^ font-lock-function-name-face
> // ^ font-lock-variable-name-face
> // ^ font-lock-type-face
> // ^ font-lock-type-face

Thanks for working on this.

I'm not sure we want to do this though, since they are still variables.





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

* bug#70657: [PATCH] Add go-ts-mode font-locking for function var decls
  2024-05-01  2:38 ` Randy Taylor
@ 2024-05-02  4:31   ` Yuan Fu
  2024-05-02 10:27     ` Noah Peart
  0 siblings, 1 reply; 5+ messages in thread
From: Yuan Fu @ 2024-05-02  4:31 UTC (permalink / raw)
  To: Randy Taylor; +Cc: Noah Peart, 70657



> On Apr 30, 2024, at 7:38 PM, Randy Taylor <dev@rjt.dev> wrote:
> 
> On Monday, April 29th, 2024 at 19:22, Noah Peart <noah.v.peart@gmail.com> wrote:
>> Tags: patch
>> 
>> 
>> Adds font-locking for functions in go-ts-mode declared in var specs.
>> 
>> Currently, all the identifiers in var specs are given
>> font-lock-variable-name-face font-locking.
>> 
>> This patch adds a rule to give identifiers in var specs
>> font-lock-function-name-face when they are function types.
>> 
>> For example, the following test is included in the patch, showing where
>> font-lock-function-name is applied:
>> 
>> var x, y, z int
>> // ^ font-lock-variable-name-face
>> // ^ font-lock-variable-name-face
>> // ^ font-lock-type-face
>> var foo, bar func(x int) int
>> // ^ font-lock-function-name-face
>> // ^ font-lock-function-name-face
>> // ^ font-lock-variable-name-face
>> // ^ font-lock-type-face
>> // ^ font-lock-type-face
> 
> Thanks for working on this.
> 
> I'm not sure we want to do this though, since they are still variables.
> 

Yes, thanks for working on this, Noah!

I don’t know Go enough to tell. Do we know how does other editors fontify this statement? Or maybe we can look at how does the official documentation highlight their code?

Yuan




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

* bug#70657: [PATCH] Add go-ts-mode font-locking for function var decls
  2024-05-02  4:31   ` Yuan Fu
@ 2024-05-02 10:27     ` Noah Peart
  2024-05-09  0:30       ` Randy Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: Noah Peart @ 2024-05-02 10:27 UTC (permalink / raw)
  To: Yuan Fu; +Cc: Randy Taylor, 70657

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

> Do we know how does other editors fontify this statement? Or maybe we can
look
> at how does the official documentation highlight their code?

From what I can tell, both neovim and vscode give them variable
font-locking (basic vim doesnt
give them any font).  The syntax highlighting is very basic in the official
docs I looked at (just the repl in Tour of Go), not
giving variables any highlight.

They are variables with function values like Randy said, and looking now at
other languages
it seems like they all give variable font-locking to named closures (eg.
rust-ts-mode, lambdas in ruby-ts-mode).

> I'm not sure we want to do this though, since they are still variables.

Sounds good, thanks for taking a look.


On Wed, May 1, 2024 at 9:31 PM Yuan Fu <casouri@gmail.com> wrote:

>
>
> > On Apr 30, 2024, at 7:38 PM, Randy Taylor <dev@rjt.dev> wrote:
> >
> > On Monday, April 29th, 2024 at 19:22, Noah Peart <noah.v.peart@gmail.com>
> wrote:
> >> Tags: patch
> >>
> >>
> >> Adds font-locking for functions in go-ts-mode declared in var specs.
> >>
> >> Currently, all the identifiers in var specs are given
> >> font-lock-variable-name-face font-locking.
> >>
> >> This patch adds a rule to give identifiers in var specs
> >> font-lock-function-name-face when they are function types.
> >>
> >> For example, the following test is included in the patch, showing where
> >> font-lock-function-name is applied:
> >>
> >> var x, y, z int
> >> // ^ font-lock-variable-name-face
> >> // ^ font-lock-variable-name-face
> >> // ^ font-lock-type-face
> >> var foo, bar func(x int) int
> >> // ^ font-lock-function-name-face
> >> // ^ font-lock-function-name-face
> >> // ^ font-lock-variable-name-face
> >> // ^ font-lock-type-face
> >> // ^ font-lock-type-face
> >
> > Thanks for working on this.
> >
> > I'm not sure we want to do this though, since they are still variables.
> >
>
> Yes, thanks for working on this, Noah!
>
> I don’t know Go enough to tell. Do we know how does other editors fontify
> this statement? Or maybe we can look at how does the official documentation
> highlight their code?
>
> Yuan

[-- Attachment #2: Type: text/html, Size: 3015 bytes --]

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

* bug#70657: [PATCH] Add go-ts-mode font-locking for function var decls
  2024-05-02 10:27     ` Noah Peart
@ 2024-05-09  0:30       ` Randy Taylor
  0 siblings, 0 replies; 5+ messages in thread
From: Randy Taylor @ 2024-05-09  0:30 UTC (permalink / raw)
  To: Noah Peart; +Cc: Yuan Fu, 70657-done@debbugs.gnu.org

On Thursday, May 2nd, 2024 at 06:27, Noah Peart <noah.v.peart@gmail.com> wrote:
> > Do we know how does other editors fontify this statement? Or maybe we can look
> > at how does the official documentation highlight their code?
> 
> From what I can tell, both neovim and vscode give them variable font-locking (basic vim doesnt
> give them any font). The syntax highlighting is very basic in the official docs I looked at (just the repl in Tour of Go), not
> giving variables any highlight.
> 
> They are variables with function values like Randy said, and looking now at other languages
> it seems like they all give variable font-locking to named closures (eg. rust-ts-mode, lambdas in ruby-ts-mode).
> 
> > I'm not sure we want to do this though, since they are still variables.
> 
> Sounds good, thanks for taking a look.

Closing.





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

end of thread, other threads:[~2024-05-09  0:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-29 23:22 bug#70657: [PATCH] Add go-ts-mode font-locking for function var decls Noah Peart
2024-05-01  2:38 ` Randy Taylor
2024-05-02  4:31   ` Yuan Fu
2024-05-02 10:27     ` Noah Peart
2024-05-09  0:30       ` Randy Taylor

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).