Search code examples
emacselisppython-mode

python-mode-hook not working as I'd expect


I'm trying to tweak my emacs configuration to treat _ as a word character.

I've added (add-hook 'python-mode-hook #'(lambda () (modify-syntax-entry ?_ "w"))) to my .emacs file, but it doesn't seem to work.

If I execute (modify-syntax-entry ?_ "w") directly in the mini-buffer, then it starts working.

I'm guessing that one of my minor modes may be changing the syntax table back.

I'm relatively new to emacs. How do I go about tracking down the source of the problem?


Solution

  • I had the mode hook in my ~/.emacs.d/el-get-init-files/init-python-mode.el. I put a call to (message "FOO BAR") in the file and noticed it wasn't being loaded on startup.

    Looks like el-get only loads files from the el-get-init-files directory for packages it has installed. Since python mode comes with emacs, and wasn't installed via el-get, my python init files wasn't being loaded.

    I moved the mode hook into my .emacs files and it started working right away!