unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Noah Peart <noah.v.peart@gmail.com>
To: 70665@debbugs.gnu.org
Subject: bug#70665: [PATCH] Add font-locking for typed parameters in python-ts-mode
Date: Tue, 30 Apr 2024 03:09:07 -0700	[thread overview]
Message-ID: <CAPVBTSe1UDAG5JpWNmd=GaYgiKh83hTWHfsKnnrbU4DipthsBg@mail.gmail.com> (raw)


[-- 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


             reply	other threads:[~2024-04-30 10:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30 10:09 Noah Peart [this message]
2024-04-30 10:27 ` bug#70665: [PATCH] Add font-locking for typed parameters in python-ts-mode Noah Peart
2024-05-01 15:04   ` Yuan Fu
2024-05-02  4:28     ` Yuan Fu

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='CAPVBTSe1UDAG5JpWNmd=GaYgiKh83hTWHfsKnnrbU4DipthsBg@mail.gmail.com' \
    --to=noah.v.peart@gmail.com \
    --cc=70665@debbugs.gnu.org \
    /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).