I recommend the python syntax file add highlighting
for the word "self". Thank you.
Regards,
Hong Xu
2010/8/14
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
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.
Regards,
Hong Xu
2010/8/16
Do you mean I have to "#define NULL" to something myself if I want to
use it for a pointer that points nowhere in C? I would never have
guessed that.
Best regards,
Tony.
--
First Corollary of Taber's Second Law:
Machines that piss people off get murdered.
-- Pat Taber
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
Syntax highlighting is aimed at convenience, not for the form. If this
is a coding convention,
then "self" should be highlighted. Or maybe it is better to add an
option to turn this on and off.
Regards,
Hong Xu
2010/8/16
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
I have to agree, self is effectively universal, I've never seen a python
example using anything other than self. At the same time, it's used very
often so it makes a lot of sense to highlight it, so that when you look
through code you will focus on variable names and if you misspell self
it's easy to spot.
-ak
--
Python plugins for vim: outliner, todo list, project manager, calendar,
expenses tracker, sortable table, and more |
http://lightbird.net/pysuite/
> 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.
This is definitely the best solution! It's precisely what the
.vim/after/ directory is for...
or, to be finicky, maybe use one of the highlight groups starting with
python defined in the syntax/python.vim script, maybe
:syn keyword pythonBuiltin self
(pretending that "self", like "False" "True" and "None", is a reserved
word?)
Best regards,
Tony.
--
INSPECTOR END OF FILM: Move along. There's nothing to see! Keep moving!
[Suddenly he notices the cameras.]
INSPECTOR END OF FILM: (to Camera) All right, put that away sonny.
[He walks over to it and puts his hand over the lens.]
"Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD