emacs-devel
[Top][All Lists]
Advanced

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

Re: [RFE] python-mode: removing `file` keyword from syntax highlight


From: kobarity
Subject: Re: [RFE] python-mode: removing `file` keyword from syntax highlight
Date: Mon, 27 Jan 2025 23:27:00 +0900
User-agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (Gojō) APEL-LB/10.8 EasyPG/1.0.0 Emacs/31.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)

Konstantin Kharlamov wrote:
> 
> 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

Thanks, understood.



reply via email to

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