This has the feel of a faq.  Forgive, I am a python newbie, and this
issue, as strange as it may seem to you, could stop me from studying
python further.

>From python-mode.el:

  ;; For historical reasons, underscore is word class instead of
  ;; symbol class.  GNU conventions say it should be symbol class, but
  ;; there's a natural conflict between what major mode authors want
  ;; and what users expect from `forward-word' and `backward-word'.
  ;; Guido and I have hashed this out and have decided to keep
  ;; underscore in word class.  If you're tempted to change it, try
  ;; binding M-f and M-b to py-forward-into-nomenclature and
  ;; py-backward-into-nomenclature instead.  This doesn't help in all
  ;; situations where you'd want the different behavior
  ;; (e.g. backward-kill-word).
  (modify-syntax-entry ?\_ "w"  py-mode-syntax-table)


When you talk about conflict, I am not sure on which side you imagine
the users to be.  _This_ longtime Emacs user definitely expects _ as a
symbol (i.e. M-f and M-b move into the middle of an identifier, if
there's an embedded underscore).  These are some of the most frequently
used Emacs commands of all, so the different behavior really is a big
deal.  It's just like the resentment you feel when you boot into single
user mode and get ash as the interactive shell instead of bash with its
readline features.  And it's impossible to "get used" to it, because
naturally I continue to edit a dozen other languages as well and all of
_their_ modes follow the convention.

So, rant over - what bad things will happen when I change it?  Does
the code internally depend on the syntax somehow?  The suspect parts
would be highlighting and indentation, of course - anywhere you do
something like 

(re-search-backward "\<while\>")

because with the changed syntax it will find "foo_while_bar" as well.
But Emacs has a mechanism to deal with this: you should do as follows,

(let internal-python-syntax-table (make-syntax-table))
        .
        .
        .
(modify-syntax-entry ?\_ "_" internal-python-syntax-table)
        .
        .
        .
(with-syntax-table internal-python-syntax-table
        (re-search-backward "\<while\>))

This is what I do in the major modes I write.
Thanks for your attention and understanding.

-- 
This line is completely ham.
_______________________________________________
Python-mode mailing list
Python-mode@python.org
http://mail.python.org/mailman/listinfo/python-mode

Reply via email to