0

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?

lawlist
  • 13,099
  • 3
  • 49
  • 158
erikcw
  • 10,787
  • 15
  • 58
  • 75
  • Try removing `#'` and report back please. – lawlist Mar 19 '14 at 19:57
  • @lawlist Removing `#'` and just `#` didn't make any difference. – erikcw Mar 19 '14 at 20:15
  • Step 2: How about pulling up the variables (i.e., `M-x describe-variable`):   `python-mode-syntax-table` and `python-dotty-syntax-table` and `python-shell-output-syntax-table`. See which ones you want to change and set them using `setq`. Go ahead and open up the source code for `.../lisp/progmodes/python.el` so that you can see the same thing that I'm looking. – lawlist Mar 19 '14 at 20:43
  • @lawlist Ok, when I `describe-variable` on those 3, I just get these massive buffers with some sort of low level tree structure. I see the definition of `python-dotty-syntax-table` in `python.el`. I'm guessing these are getting over-written at some point by something else. – erikcw Mar 19 '14 at 21:13
  • My best guess would be that your `python-mode-hook` (without `#'`) is being overwritten by one or more of those three variables (that are being called subsequent to your `python-mode-hook`), and that is why I suggested modifying those variables directly. But, you are correct, there may be other settings that are trumping your mode-hook. Are you using any particular starter kit, or related library, that other forum participants should be aware of so that they can provide further assistance? Dig right in and open up `.../lisp/progmodes/python.el` -- don't be shy! – lawlist Mar 19 '14 at 21:31
  • Your code looks correct, so either there's a bug in python-mode, or you have some other problem elsewhere which causes your add-hook to be ineffective. – Stefan Mar 20 '14 at 01:10
  • Is that hook mentioned in output of M-x describe-variable RET python-mode-hook ? – Andreas Röhler Mar 20 '14 at 08:02

1 Answers1

1

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!

erikcw
  • 10,787
  • 15
  • 58
  • 75
  • You stated explicitly in the question that the code was in your `.emacs` file, which wasn't very helpful for the folks who spent time trying to help you. Trying to "simplify" a problem like that isn't a good idea, if you haven't actually *tested* your simplification. – phils Jun 22 '14 at 00:25