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

3

15

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?

Dingy answered 9/10, 2009 at 20:18 Comment(0)
V
15

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...

Vicissitude answered 9/10, 2009 at 20:36 Comment(1)
That did it. (modify-syntax-entry ?_ "w" csharp-mode-syntax-table) Thank you.Dingy
E
8

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).

Edith answered 9/10, 2009 at 21:36 Comment(0)
A
6
(modify-syntax-entry ?_ "w")
Acromion answered 9/10, 2009 at 20:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.