As the title says, how does one change the behaviour of emacs forward-word function? For example, suppose [] is the cursor. Then:
my $abs_target_path[]= abs_path($target);
<M-f>
my $abs_target_path = abs[_]path($target);
I know I could just use M-f M-b but as far as I'm concerned, that shouldn't be necessary and I'd like to change it. In particular, I want two things:
- When I press M-f, I want to go to the first character of the next word regardless of whether the point is within a word, within a group of spaces or somewhere else.
- Customize word-characters on a mode-by-mode basis. After all, moving around in CPerl mode is different than, say, TeX mode.
So, in the above example, item 1 would have the cursor would move to the 'a' (and the point to it's left) after hitting M-f. Item 2 would allow me to define underscores and sigils as word characters.
Try:
Then use
M-x forward-to-word
and see if it does what you want. You can then rebindM-f
, etc.To make the
_
not a word separator (i.e. make it a word constituent) for C & C++ mode, you would do this:For more information on syntax tables, read this wiki page. Syntax tables are generally named like
tex-mode-syntax-table
andcperl-mode-syntax-table
.I wanted to copy the behavior of my previous editor thus needed a bit more control, so here's my take on it:
See forward-same-syntax function also. probably this is you needed to base on.
I have a minor mode that changes word-based commands to operate on syntax changes (and also CamelCaseSubwords). It may be a bit too fine-grained for some tastes, but I find I basically ever use single character movement anymore.
https://bitbucket.org/jpkotta/syntax-subword