[PATCH] Syntax: Added syntax for Python decorators.

matteo_luigi_raso <[email protected]>
Newsgroups gmane.editors.nano.devel
Message-ID <SOax1PeBun0kCfP9gghMTpUbR0K_V4MwqcV-6z0NIsknjBEW15rQrin24bad5NOuU4vWqjWXGqewHy8Rey96k5bEkr2WiKVBeEz6LdlfTwU=@protonmail.com>
Decorators are an important part of the Python language, so GNU nano should
give them a colour instead of ignoring them. For the syntax, I start the
colouring at "@" and end it at either a blank space or a newline. The
reason I stop the syntax after a blank space is because "@" doubles as an
operator in Numpy and downstream packages, so we have to take care to not
mess up the entire line if "@" is used that way. One slight problem is that
the syntax colouring will also apply to any arguments passed to the decorator
if a space isn't placed between the opening bracket and the decorator.

e.g. "@dec(a)" will be one colour, which might be slightly unaesthetic.

This isn't much of a problem though, since it can be easily fixed by going
"@dec (a)"

Sent with [Proton Mail](https://proton.me/) secure email.
0001-Signed-off-by-Matteo-Raso-matteo_luigi_raso-protonma.patch (text/x-patch, 1.6 KB)
From c3253c9cca3bbbcb3f9cbeea7b61980665439e06 Mon Sep 17 00:00:00 2001
From: Matteo Raso <[email protected]>
Date: Wed, 18 Jan 2023 01:25:04 -0500
Subject: [PATCH] Signed-off-by: Matteo Raso <[email protected]>

Added syntax for Python decorators

Decorators are an important part of the Python language, so GNU nano should
give them a colour instead of ignoring them. For the syntax, I start the
colouring at "@" and end it at either a blank space or a newline. The
reason I stop the syntax after a blank space is because "@" doubles as an
operator in Numpy and downstream packages, so we have to take care to not
mess up the entire line if "@" is used that way. One slight problem is that
the syntax colouring will also apply to any arguments passed to the decorator
if a space isn't placed between the opening bracket and the decorator.

e.g. "@dec(a)" will be one colour, which might be slightly unaesthetic.

This isn't much of a problem though, since it can be easily fixed by going

"@dec (a)"
---
 syntax/python.nanorc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/syntax/python.nanorc b/syntax/python.nanorc
index e8ba17e2..be047fcb 100644
--- a/syntax/python.nanorc
+++ b/syntax/python.nanorc
@@ -33,6 +33,9 @@ color brightred "(^|[[:blank:]])#.*"
 color brightgreen start="'''([^'),]|$)" end="(^|[^(\])'''"
 color brightgreen start=""""([^"),]|$)" end="(^|[^(\])""""
 
+#Decorators.
+color sky start="@" end="^|\ "
+
 # Backslash escapes.
 color lime "\\($|[\'"abfnrtv]|[0-3]?[0-7]?[0-7]|x[[:xdigit:]]{2})"
 color lime "\\(N\{[[:alpha:]]+\}|u[[:xdigit:]]{4}|U[[:xdigit:]]{8})"
-- 
2.38.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.