[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFE] python-mode: removing `file` keyword from syntax highlight
From: |
Konstantin Kharlamov |
Subject: |
Re: [RFE] python-mode: removing `file` keyword from syntax highlight |
Date: |
Sat, 25 Jan 2025 23:54:52 +0300 |
User-agent: |
Evolution 3.54.3 |
On Sun, 2025-01-26 at 00:08 +0900, kobarity wrote:
> Kévin Le Gouguec wrote:
> > Konstantin Kharlamov <Hi-Angel@yandex.ru> writes:
> >
> > > > However, I know that Python 2 has already been EOL for a long
> > > > time and
> > > > that very few people still use it. Furthermore, even if some
> > > > keywords are not highlighted, it does not mean that we cannot
> > > > edit
> > > > Python 2 code. So I am not strongly against removing the
> > > > Python 2
> > > > keywords if many people want to.
> > >
> > > I see. Okay, what do you think then about adding to the mode
> > > initialization a check that would check if the first line of the
> > > buffer
> > > has word `python2`, and would otherwise assume it is python3 and
> > > turn
> > > off the python2 keywords highlight?
> >
> > An idea that I've never acted on:
> >
> > * a defcustom (python-dialect?) to pick between 2, 3, 'guess,
> >
> > * python-mode initialization would amend font-lock-defaults
> > depending on
> > that option (not unlike e.g. sh-builtins which maps shells to
> > literals
> > to sh-font-lock-keywords, which eventually finds its way to
> > font-lock-defaults)
> >
> > * 'guess could, as you say, peek at the shebang to hopefully do
> > TRT,
> >
> > * (maybe an additional value ('six?) to ask for "maximum coverage",
> > for
> > codebases that purport to still support 2 & 3?)
> >
> > * users could explicitly set that variable per-project via
> > .dir-locals.el.
>
> I don't think "guessing" will work, since the shebang is not always
> available.
>
> Ship Mints wrote:
> > To me, it's not worth the trouble to have two modes, or extra
> > configuration settings, or complex dynamic detectors just
> > to deprecate a couple of now non-keywords.
> >
> > I'd rather have "file" no longer be a keyword than incorrectly
> > display it as a keyword in now more popular python3 code.
> >
> > -Stephane
>
> I think `defcustom' is one option, but as it requires to update some
> variables such as `python-font-lock-keywords-level-2',
> `python-font-lock-keywords-maximum-decoration', and
> `python-font-lock-keywords', I agree that it's not worth introducing
> now.
>
> Since no one else seems to want it to remain, it would be appropriate
> to remove it.
>
> Are you going to remove only "file"? Or are you going to delete all
> the Python 2 keywords?
If that's a question for me: I have no grudge against other keywords.
Looking at the list in the source code¹, I think the only other keyword
one can see as an identifier is `cmp` (it would be code where you chose
a comprision-function from a list, and it's fair to name the variable
just `cmp`). Other words (like `long`) you'd typically see as part of a
larger word; `buffer` I don't remember for anyone to write in full,
people are more likely to type just `buf`. Then there's `reduce`, which
is Python's `foldl` function, but given that `all` and `any` are
highlighted as keywords, that would be strange to remove `reduce`…
So ultimately, I personally don't have problems with other keywords
besides `file`. It's just that `file` really comes up a lot in a code.
1:
https://github.com/emacs-mirror/emacs/blob/35d39278599caf30eb4bfbd83118ffe15d2bc705/lisp/progmodes/python.el#L717-L720
- [RFE] python-mode: removing `file` keyword from syntax highlight, Konstantin Kharlamov, 2025/01/22
- Re: [RFE] python-mode: removing `file` keyword from syntax highlight, Konstantin Kharlamov, 2025/01/24
- Re: [RFE] python-mode: removing `file` keyword from syntax highlight, kobarity, 2025/01/24
- Re: [RFE] python-mode: removing `file` keyword from syntax highlight, Kévin Le Gouguec, 2025/01/25
- Re: [RFE] python-mode: removing `file` keyword from syntax highlight, Ship Mints, 2025/01/25
- Re: [RFE] python-mode: removing `file` keyword from syntax highlight, kobarity, 2025/01/25
- Re: [RFE] python-mode: removing `file` keyword from syntax highlight,
Konstantin Kharlamov <=
- Re: [RFE] python-mode: removing `file` keyword from syntax highlight, kobarity, 2025/01/27
- [PATCH] Remove Python2 "file" from the list of keywords, Konstantin Kharlamov, 2025/01/29
- Re: [PATCH] Remove Python2 "file" from the list of keywords, kobarity, 2025/01/29
- Re: [PATCH v2] Remove Python2 "file" from the list of keywords, Konstantin Kharlamov, 2025/01/29
- Re: [PATCH v2] Remove Python2 "file" from the list of keywords, Stefan Kangas, 2025/01/29
- Re: [PATCH v2] Remove Python2 "file" from the list of keywords, Konstantin Kharlamov, 2025/01/30
- Re: [PATCH v2] Remove Python2 "file" from the list of keywords, kobarity, 2025/01/30
- Re: [PATCH v3] Stop highlighting Python2 keywords., Konstantin Kharlamov, 2025/01/30
- Re: [PATCH v3] Stop highlighting Python2 keywords., Stefan Kangas, 2025/01/30
- Re: [PATCH v3] Stop highlighting Python2 keywords., kobarity, 2025/01/31