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

Re: emacs question: removing "self" keyword in python-mode

On Wed, Apr 08, 2009 at 10:09:09PM -0700, Evan Klitzke wrote:
> I know, this is an emacs question and not a fedora question per se. But
> I've asked my question on the emacs help news group without a response,
> and I know there are some emacs users lurking around these parts, so I
> thought I'd try here :-)
> My question is stated previously at:
> http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/785fb0e6542eda80/1ad000e4fa700e1e
> Basically, emacs uses a big complex regular expression to figure out
 regx? Where?
> what words to highlight in different modes. There seems to be a command
> font-lock-remove-keyword that can be used to safely edit the regular
> expression and remove a keyword from it; but the documentation is pretty
> vague, and the source code for the function is way over my head.
> Thanks for any help!

Caution "self" is a convention of some importance....

See http://www.python.org/doc/2.5.2/tut/node11.html

"""Often, the first argument of a method is called self. This is nothing
more than a convention: the name self has absolutely no special meaning
to Python. (Note, however, that by not following the convention your
code may be less readable to other Python programmers, and it is also
conceivable that a class browser program might be written that relies
upon such a convention.) """

Is this in the class of things not unlike the Emacs programmer that redefines Meta-X?

$ locate py | grep py$ | xargs grep self | wc -l
In ./lisp/progmodes/python.el.gz I see:

             ;; Not real keywords, but close enough to be fontified as such
             "self" "True" "False")

So you could take the hint and go with the flow or edit the .el file to read something like
this for the three not real key words.  The bytecompile it or add it to your own .emacs:

(defvar python-font-lock-keywords
  `(,(rx symbol-start
         ;; From v 2.5 reference, <A7> keywords.
         ;; def and class dealt with separately below
         (or "and" "as" "assert" "break" "continue" "del" "elif" "else"
             "except" "exec" "finally" "for" "from" "global" "if"
             "import" "in" "is" "lambda" "not" "or" "pass" "print"
             "raise" "return" "try" "while" "with" "yield"
             ;; Not real keywords, but close enough to be fontified as such
             "RubarbInTheSpringself" "RubarbInTheSpringTrue" "RubarbInTheSpringFalse")

	T o m  M i t c h e l l 
	Found me a new hat, now what?

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