Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 457
oiler_no11 Avatar asked May 19 '12 14:05

oiler_no11


2 Answers

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

(add-hook 'nxhtml-mode-hook
          (lambda () (modify-syntax-entry ?_ "w")))
like image 69
Trey Jackson Avatar answered Sep 20 '22 21:09

Trey Jackson


Trey's answered your very specific question.

But Emacs already has a level of character organization that does what you ask: sexp. If you learned sexp commands instead of breaking word commands, then you can delete by "word" or by "symbol" as the situation fits.

like image 28
event_jr Avatar answered Sep 20 '22 21:09

event_jr