Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hello_World is a word in Python, it is different in an other mode. How I change it?

Tags:

python

emacs

In python mode, when I forward-word. The cursor jumps from H to d (Hello_World). But in another mode(shell-mode or c-mode), the cursor jumps from H to _.

I want the result which i get in Python mode, even in the other mode. What should I do?

PS: I saw a similar question before, I have searched, but I could't find it.

like image 888
louxiu Avatar asked Jul 05 '13 12:07

louxiu


2 Answers

I think you're looking for this:

(modify-syntax-entry ?_ "w")

Underscores will be treated as part of a word. This command will change the syntax table of the mode you're currently in. AFAIK there's no way to change syntax globally. However, you could try modifying the standard syntax table. Most major modes inherit the standard-syntax-table.

(modify-syntax-entry  ?_ "w" standard-syntax-table)

If that doesn't work, I guess you have to add mode-hooks for all modes you're using and modify their syntax tables individually.

like image 170
djf Avatar answered Oct 02 '22 17:10

djf


Things got a little simpler since Emacs 24.4. There's now a M-x superword-mode that has the desired effect.

like image 44
shakurov Avatar answered Oct 02 '22 15:10

shakurov