emacsemacs23nxhtml

Underscore as part of word for forward-word not working


I am trying to make underscores get treated as part of the word for the forward/backward-word function as described here and here. I am specifically trying to get this to work for nxhtml mode, but would really like it to work like this for all modes.

I have modified my site-start.el file a number of different ways but to no avail. But if I manually execute the command M-x modify-syntax-table in the buffer, it works just fine. I just can't get this to be the default behavior.

Here is what I tried putting in my site-start.el file:

;; 1
;; thought  this would apply it to all modes - no error, but did not work
(modify-syntax-entry ?_ "w") 

;; 2
;; thought this would automatically set it on a mode change - no error, but did not work
(defun change-major-mode-hook ()
(modify-syntax-entry ?_ "w"))


;; 3
;; thought  this would apply it to all modes - no error, but did not work
(modify-syntax-entry ?_ "w")

;; 4
;; this produced a symbol's value as variable is void error
(modify-syntax-entry ?_ "w" nxhtml-mode-syntax-table)

What am I missing?


Solution

  • Have you tried modifying the nxhtml-mode-hook directly? Like so:

    (add-hook 'nxhtml-mode-hook
              (lambda () (modify-syntax-entry ?_ "w")))