On Mon, 16 Aug 2010, H Xu wrote:

>  On 2010/8/16 13:36, Dominique Pellé wrote:
> > H Xu wrote:
> > >   On 2010/8/16 7:40, Zvezdan Petkovic wrote:
> > > > On Aug 14, 2010, at 7:16 AM, H Xu wrote:
> > > > > I recommend the python syntax file add highlighting
> > > > > for the word "self". Thank you.
> > > > Why?
> > > > 
> > > > There is nothing special about the word "self".
> > > > It is *not* a Python keyword.
> > > > 
> > > > You could call that parameter "this" if you wanted.
> > > > Use of "self" is just a common established practice, but it is not a
> > > > part
> > > > of the language syntax specification.
> > > > 
> > > > If you prefer to have it highlighted you can always make your own
> > > > customized file.
> > > > 
> > > >         Zvezdan
> > > > 
> > > Hello Zvezdan,
> > > 
> > > My opinion is that syntax highlighting is not only for keyword. You may
> > > notice that in C language "NULL" is not a keyword, it has been colored.
> > NULL is defined in C standard header files (stdlib.h and stddef.h).
> > 
> > 'self' on the other hand is merely a coding convention in Python
> > so I don't think it should be highlighted by default.
> > 
> > -- Dominique
> > 
> Hello,
> 
> Syntax highlighting is aimed at convenience, not for the form. If this 
> is a coding convention, then "self" should be highlighted.

I started replying to this thinking that 'self' shouldn't be 
highlighted, since it's not "special" in any way.  If anything, a 
"correct" fix would be to parse out the first parameter to a method call 
and highlight that.  But that's not worth the effort.

The point is that in Python both of the following mean exactly the same 
thing:

class foo:
   def whatever(self):
      self.x = y

class foo:
   def whatever(bar):
      bar.x = y

The problem with the "but it's not special" argument is that *everyone* 
uses 'self', to the point where other syntax-highlighting tools usually 
syntax-highlight it.

See: http://docs.python.org/tutorial/classes.html#random-remarks
And notice the syntax highlighting.


> Or maybe it is better to add an option to turn this on and off.

Long-term, that sounds like a reasonable compromise.  (Hell, C++ syntax 
has an option to highlight Java keywords.)  Something like:

let g:python_self_is_special = 1
to turn 'self'-highlighting on.

(or perhaps even):

let g:python_self_not_special = 1
to turn it off.


For now, though, one (easy) option is to add it yourself.  It's as 
simple as putting this line:

syn keyword Keyword self

In the file: ~/.vim/after/syntax/python.vim
or vimfiles\after\syntax\python.vim in your Windows home directory.

-- 
Best,
Ben

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to