nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Syntax: Added syntax for Python decorators.


From: Benno Schulenberg
Subject: Re: [PATCH] Syntax: Added syntax for Python decorators.
Date: Thu, 19 Jan 2023 13:01:21 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2


Op 18-01-2023 om 08:02 schreef matteo_luigi_raso:
Decorators are an important part of the Python language,

I think that is overstating the importance of "decorators".  But yes,
it would be good if nano colored them specially.

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.

This commit message is too verbose -- too much banter.  Instead it would
be good to include a URL to a webpage that documents these "decorators".
For example: https://peps.python.org/pep-0318/.  But maybe you have a
better one?

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 is very unesthetic and thus unacceptable.  Vim and Emacs don't do this
either.  But your coloring rule can be easily simplified to achieve this.

+#Decorators.
+color sky start="@" end="^|\ "

One should use start="" and end="" only when wanting to colorize something
that occupies multiple lines.  Decorators don't do that, if I understand
correctly.  So the coloring rule can be a simple, single regex.  Looking at
https://wiki.python.org/moin/Decorators, the names of decorators contain
only letters and maybe underscores, digits, and periods.  So this would do:

  color sea "@[[:alnum:]_.]+"

Probably a decorator name must start with a letter or underscore, so
probably this is more accurate:

  color sea "@[[:alpha:]_][[:alnum:]_.]*"

I've chosen 'sea' as color, because for me 'sky' has too low a contrast
with the lightblue of function names.  Does this color and regex work for
you?

For signing off a patch, you can use the -s option with 'commit', say:

  git commit --amend -s.


Benno

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]