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:
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:
(require 'misc)
Then use M-x forward-to-word
and see if it does what you want. You can then rebind M-f
, etc.
To make the _
not a word separator (i.e. make it a word constituent) for C & C++ mode, you would do this:
(modify-syntax-entry ?_ "w" c-mode-syntax-table)
(modify-syntax-entry ?_ "w" c++-mode-syntax-table)
For more information on syntax tables, read this wiki page. Syntax tables are generally named like tex-mode-syntax-table
and cperl-mode-syntax-table
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With