In my .emacs I have the following line of code:

(modify-syntax-entry ?_ "." python-mode-syntax-table)

This is so that commands like forward-word and backward-kill-word stop at any underscores that are in a word. This is different behavior than the default, and it is the behavior I want. The problem is that then auto-complete-mode also respects underscores as word boundaries in an undesirable way. For example, if I have a variable called foo_var, and I type fo and then try to complete, it will only complete to foo not foo_var.

In text-mode and c-mode the behavior is exactly what I want i.e. motion obeys underscores, but auto-complete-mode will complete across them. What do I need to change in my auto-complete-mode configuration to fix this in Python?


I managed to get my problem solved. I did a diff on the syntax tables loaded for both python-mode and c-mode (using C-h s). I noticed that in c-mode, the underscore was a symbol character ("_") and in python-mode the underscore was a punctuation character ("."). So, I simply changed the aforementioned line of code to

(modify-syntax-entry ?_ "_" python-mode-syntax-table)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.