Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make forward-word, backward-word, treat underscore as part of a word?

Tags:

c#

emacs

In my C# mode, M-b and M-f are bound to {backward,forward}-word.

But these things stop at underscores, which I use sometimes as a prefix on member variables.

How do I get emacs to treat the underscore as a word character?

like image 922
Cheeso Avatar asked Oct 09 '09 20:10

Cheeso


3 Answers

As huaiyuan mentioned, you ned to modify your syntax table. That said, what he posted modifies the current table...

Each language has a syntax table, e.g. For c++, you could do

(modify-syntax-entry ?_ "w" c++-mode-syntax-table)

I don't know what "your c# mode" uses, but a quick M-x apropos with a look up of syntax-table should help you find out...

like image 189
Bahbar Avatar answered Nov 20 '22 02:11

Bahbar


You don't necessarily have to modify your syntax table. _ belongs to the syntax class symbol in csharp-mode, so you may use forward-symbol instead of forward-word. forward-symbol is in thingatpt, which comes with emacs (at least 23).

You can btw quickly look at the syntax table of a mode with C-h s (describe-syntax).

like image 39
andre-r Avatar answered Nov 20 '22 00:11

andre-r


(modify-syntax-entry ?_ "w")
like image 6
huaiyuan Avatar answered Nov 20 '22 00:11

huaiyuan