all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#71209: [PATCH] Add font-locking for variables in go-ts-mode range clauses
@ 2024-05-26 12:41 Noah Peart
  2024-05-28  2:46 ` Randy Taylor
  0 siblings, 1 reply; 20+ messages in thread
From: Noah Peart @ 2024-05-26 12:41 UTC (permalink / raw)
  To: 71209


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

Tags: patch

Adds font-locking rule in go-ts-mode to give variables in range clauses
font-lock-variable-name-face (in feature 'definition).

For example, the following font-locking is added:

for idx, val := range arr {}
//     ^ font-lock-variable-name-face
//           ^ font-lock-variable-name-face

The patch also adds a test case.


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-05-21 built on noah-X580VD
Repository revision: 63d914e377f7cc37056de2503bfbeea831875037
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: 1098 bytes --]

[-- Attachment #2: 0001-Add-font-locking-for-variables-in-go-ts-mode-range-c.patch --]
[-- Type: text/x-patch, Size: 2691 bytes --]

From 1b6b2a7001ff079d81af7d42c7ee98e8e7318390 Mon Sep 17 00:00:00 2001
From: Noah Peart <noah.v.peart@gmail.com>
Date: Sun, 26 May 2024 05:34:34 -0700
Subject: [PATCH] Add font-locking for variables in go-ts-mode range clauses

* lisp/progmodes/go-ts-mode.el (go-ts-mode--font-lock-settings):
Add font-locking rule for variable names in range clauses.
* test/lisp/progmodes/go-ts-mode-tests.el (go-ts-test-font-lock):
Add font-locking test for go-ts-mode.
* test/lisp/progmodes/go-ts-mode-resources/font-lock.go: New file
for go-ts-mode font-locking tests.
---
 lisp/progmodes/go-ts-mode.el                          | 5 ++++-
 test/lisp/progmodes/go-ts-mode-resources/font-lock.go | 5 +++++
 test/lisp/progmodes/go-ts-mode-tests.el               | 5 +++++
 3 files changed, 14 insertions(+), 1 deletion(-)
 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..43f7e042590 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -180,7 +180,10 @@ go-ts-mode--font-lock-settings
              (identifier) @font-lock-variable-name-face
              ("," (identifier) @font-lock-variable-name-face)*))
      (var_spec name: (identifier) @font-lock-variable-name-face
-               ("," name: (identifier) @font-lock-variable-name-face)*))
+               ("," name: (identifier) @font-lock-variable-name-face)*)
+     (range_clause
+      left: (expression_list
+             (identifier) @font-lock-variable-name-face)))
 
    :language 'go
    :feature 'function
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..4e7a8e1710b
--- /dev/null
+++ b/test/lisp/progmodes/go-ts-mode-resources/font-lock.go
@@ -0,0 +1,5 @@
+for idx, val := range arr {}
+//   ^ font-lock-variable-name-face
+//        ^ font-lock-variable-name-face
+for idx := 0; idx < n; idx++ {}
+//   ^ font-lock-variable-name-face
diff --git a/test/lisp/progmodes/go-ts-mode-tests.el b/test/lisp/progmodes/go-ts-mode-tests.el
index fd9b57e8691..f36dbde5103 100644
--- a/test/lisp/progmodes/go-ts-mode-tests.el
+++ b/test/lisp/progmodes/go-ts-mode-tests.el
@@ -27,5 +27,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] 20+ messages in thread

end of thread, other threads:[~2024-08-04  7:52 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-26 12:41 bug#71209: [PATCH] Add font-locking for variables in go-ts-mode range clauses Noah Peart
2024-05-28  2:46 ` Randy Taylor
2024-05-30 13:25   ` Noah Peart
2024-05-30 23:23     ` Dmitry Gutov
2024-06-01  1:09     ` Randy Taylor
2024-06-01  1:42       ` Noah Peart
2024-06-01  1:50         ` Noah Peart
2024-06-01 14:13           ` Dmitry Gutov
2024-06-01  1:51         ` Dmitry Gutov
2024-06-01  1:56           ` Noah Peart
2024-06-01  1:59             ` Dmitry Gutov
2024-06-01  2:04               ` Noah Peart
2024-06-01 14:13         ` Dmitry Gutov
2024-06-15  7:56           ` Eli Zaretskii
2024-06-27  7:38             ` Eli Zaretskii
2024-06-27  9:29               ` Noah Peart
2024-07-06  7:46                 ` Eli Zaretskii
2024-07-20  9:42                   ` Eli Zaretskii
2024-08-04  7:52                     ` Eli Zaretskii
2024-06-01  1:56       ` Dmitry Gutov

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.