all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#70665: [PATCH] Add font-locking for typed parameters in python-ts-mode
@ 2024-04-30 10:09 Noah Peart
  2024-04-30 10:27 ` Noah Peart
  0 siblings, 1 reply; 4+ messages in thread
From: Noah Peart @ 2024-04-30 10:09 UTC (permalink / raw)
  To: 70665


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

Tags: patch

This patch adds a rule to python--treesit-settings to apply
font-lock-variable-name-face to typed parameters in python-ts-mode.
Currently, function parameters with type annotations are missing
font-lock-variable-name-face.

For example, this patch adds font-locking in the following case:

    def foo(val: str) -> str
    #        ^ font-lock-variable-name-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: 1132 bytes --]

[-- Attachment #2: 0001-Add-font-locking-for-typed-parameters-in-python-ts-m.patch --]
[-- Type: text/x-patch, Size: 2064 bytes --]

From 77dd550a17426bf59de880a8808df0b1aa2c0bba Mon Sep 17 00:00:00 2001
From: Noah Peart <noah.v.peart@gmail.com>
Date: Tue, 30 Apr 2024 02:55:18 -0700
Subject: [PATCH] Add font-locking for typed parameters in python-ts-mode

* lisp/progmodes/python.el (python--treesit-settings): Add
tree-sitter font-locking rule for typed parameters.
* test/lisp/progmodes/python-tests.el
(python-ts-mode-types-face-1): Test for
font-lock-variable-name-face in typed parameter.
---
 .last-build-hash                    | 1 +
 lisp/progmodes/python.el            | 1 +
 test/lisp/progmodes/python-tests.el | 3 +++
 3 files changed, 5 insertions(+)
 create mode 100644 .last-build-hash

diff --git a/.last-build-hash b/.last-build-hash
new file mode 100644
index 00000000000..f64a905ac96
--- /dev/null
+++ b/.last-build-hash
@@ -0,0 +1 @@
+3000edc6179dfe0b5f24ae2e472826530809dfd1
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index d6c29e5ffc6..4ff5e9d4878 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1202,6 +1202,7 @@ python--treesit-settings
      (class_definition
       name: (identifier) @font-lock-type-face)
      (parameters (identifier) @font-lock-variable-name-face)
+     (parameters (typed_parameter (identifier) @font-lock-variable-name-face))
      (parameters (default_parameter name: (identifier) @font-lock-variable-name-face)))
 
    :feature 'builtin
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index e11440cdb5b..878f60f1614 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -7545,6 +7545,9 @@ python-ts-mode-union-types-face-2
 (ert-deftest python-ts-mode-types-face-1 ()
   (python-ts-tests-with-temp-buffer
    "def f(val: Callable[[Type0], (Type1, Type2)]):"
+   (search-forward "val")
+   (goto-char (match-beginning 0))
+   (should (eq (face-at-point) font-lock-variable-name-face))
    (dolist (test '("Callable" "Type0" "Type1" "Type2"))
      (search-forward test)
      (goto-char (match-beginning 0))
-- 
2.34.1


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

* bug#70665: [PATCH] Add font-locking for typed parameters in python-ts-mode
  2024-04-30 10:09 bug#70665: [PATCH] Add font-locking for typed parameters in python-ts-mode Noah Peart
@ 2024-04-30 10:27 ` Noah Peart
  2024-05-01 15:04   ` Yuan Fu
  0 siblings, 1 reply; 4+ messages in thread
From: Noah Peart @ 2024-04-30 10:27 UTC (permalink / raw)
  To: 70665


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

Sorry, previous patch added an extra file by accident.

Fixed patch attached.


On Tue, Apr 30, 2024 at 3:09 AM Noah Peart <noah.v.peart@gmail.com> wrote:

> Tags: patch
>
> This patch adds a rule to python--treesit-settings to apply
> font-lock-variable-name-face to typed parameters in python-ts-mode.
> Currently, function parameters with type annotations are missing
> font-lock-variable-name-face.
>
> For example, this patch adds font-locking in the following case:
>
>     def foo(val: str) -> str
>     #        ^ font-lock-variable-name-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: 1621 bytes --]

[-- Attachment #2: 0001-Add-font-locking-for-typed-parameters-in-python-ts-m.patch --]
[-- Type: text/x-patch, Size: 1790 bytes --]

From db9f32c31ff1bec49f2db727c51823bd98422f36 Mon Sep 17 00:00:00 2001
From: Noah Peart <noah.v.peart@gmail.com>
Date: Tue, 30 Apr 2024 02:55:18 -0700
Subject: [PATCH] Add font-locking for typed parameters in python-ts-mode

* lisp/progmodes/python.el (python--treesit-settings): Add
tree-sitter font-locking rule for typed parameters.
* test/lisp/progmodes/python-tests.el
(python-ts-mode-types-face-1): Test for
font-lock-variable-name-face in typed parameter.
---
 lisp/progmodes/python.el            | 1 +
 test/lisp/progmodes/python-tests.el | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index d6c29e5ffc6..4ff5e9d4878 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1202,6 +1202,7 @@ python--treesit-settings
      (class_definition
       name: (identifier) @font-lock-type-face)
      (parameters (identifier) @font-lock-variable-name-face)
+     (parameters (typed_parameter (identifier) @font-lock-variable-name-face))
      (parameters (default_parameter name: (identifier) @font-lock-variable-name-face)))
 
    :feature 'builtin
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index e11440cdb5b..878f60f1614 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -7545,6 +7545,9 @@ python-ts-mode-union-types-face-2
 (ert-deftest python-ts-mode-types-face-1 ()
   (python-ts-tests-with-temp-buffer
    "def f(val: Callable[[Type0], (Type1, Type2)]):"
+   (search-forward "val")
+   (goto-char (match-beginning 0))
+   (should (eq (face-at-point) font-lock-variable-name-face))
    (dolist (test '("Callable" "Type0" "Type1" "Type2"))
      (search-forward test)
      (goto-char (match-beginning 0))
-- 
2.34.1


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

* bug#70665: [PATCH] Add font-locking for typed parameters in python-ts-mode
  2024-04-30 10:27 ` Noah Peart
@ 2024-05-01 15:04   ` Yuan Fu
  2024-05-02  4:28     ` Yuan Fu
  0 siblings, 1 reply; 4+ messages in thread
From: Yuan Fu @ 2024-05-01 15:04 UTC (permalink / raw)
  To: Noah Peart; +Cc: 70665



> On Apr 30, 2024, at 3:27 AM, Noah Peart <noah.v.peart@gmail.com> wrote:
> 
> Sorry, previous patch added an extra file by accident.
> 
> Fixed patch attached.
> 
> 
> On Tue, Apr 30, 2024 at 3:09 AM Noah Peart <noah.v.peart@gmail.com> wrote:
> Tags: patch
> 
> This patch adds a rule to python--treesit-settings to apply
> font-lock-variable-name-face to typed parameters in python-ts-mode.
> Currently, function parameters with type annotations are missing
> font-lock-variable-name-face.
> 
> For example, this patch adds font-locking in the following case:
> 
>     def foo(val: str) -> str
>     #        ^ font-lock-variable-name-face

Thank you!! Had some issue with my Emacs build last night. I’ll try to get it merged tonight.

Yuan




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

* bug#70665: [PATCH] Add font-locking for typed parameters in python-ts-mode
  2024-05-01 15:04   ` Yuan Fu
@ 2024-05-02  4:28     ` Yuan Fu
  0 siblings, 0 replies; 4+ messages in thread
From: Yuan Fu @ 2024-05-02  4:28 UTC (permalink / raw)
  To: Noah Peart; +Cc: 70665-done



> On May 1, 2024, at 8:04 AM, Yuan Fu <casouri@gmail.com> wrote:
> 
> 
> 
>> On Apr 30, 2024, at 3:27 AM, Noah Peart <noah.v.peart@gmail.com> wrote:
>> 
>> Sorry, previous patch added an extra file by accident.
>> 
>> Fixed patch attached.
>> 
>> 
>> On Tue, Apr 30, 2024 at 3:09 AM Noah Peart <noah.v.peart@gmail.com> wrote:
>> Tags: patch
>> 
>> This patch adds a rule to python--treesit-settings to apply
>> font-lock-variable-name-face to typed parameters in python-ts-mode.
>> Currently, function parameters with type annotations are missing
>> font-lock-variable-name-face.
>> 
>> For example, this patch adds font-locking in the following case:
>> 
>>    def foo(val: str) -> str
>>    #        ^ font-lock-variable-name-face
> 
> Thank you!! Had some issue with my Emacs build last night. I’ll try to get it merged tonight.
> 
> Yuan

Merged, thanks again!

Yuan






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

end of thread, other threads:[~2024-05-02  4:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-30 10:09 bug#70665: [PATCH] Add font-locking for typed parameters in python-ts-mode Noah Peart
2024-04-30 10:27 ` Noah Peart
2024-05-01 15:04   ` Yuan Fu
2024-05-02  4:28     ` Yuan Fu

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.