hilighting 'self' (was: Re: total idiot question: +=, .=, etc...)

Preston Landers mithy at my-deja.com
Wed Jul 7 13:29:19 EDT 1999


In article <14211.28251.23566.522880 at anthem.cnri.reston.va.us>,
  bwarsaw at cnri.reston.va.us (Barry A. Warsaw) wrote:

> You could probably add "self" to python-font-lock-keywords.  I'm not
> entirely sure this is a good idea since self is just a convention, but
> if a lot of people would like to see this, I might consider adding it.

Well, even though self is a convention, its use is 'strongly encouraged'
and I don't think anybody would be terribly confused by Emacs
highlighting it.  Maybe if this was added to python-mode it could be
optional.

My personal opinion is that "self" is much more 'like' a type than a
keyword (like if, elif, for, and so on.)  I decided to color it like a
class declaration.

I inserted these lines into my python-mode.el at the appropriate place:

     ;; also color "self" as a 'type'
     '("\\b\\(self\\)[ .,]?"
       1 font-lock-type-face)

Sjoerd Mullender <sjoerd.mullender at oratrix.com> suggests adding this to
your .emacs instead:

(add-to-list 'after-load-alist
	     (cons "python-mode"
		   '((add-to-list (quote python-font-lock-keywords)
				  (quote ("\\b\\(self\\)[ .,]?"
					  1 font-lock-type-face))))))

which is a slightly more clever way of doing it. I'm not a terribly
experienced Emacs hacker.

--
||  Preston Landers <mithy at my-deja.com>  ||
||        http://askpreston.com          ||


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list