I find it rather annoying that kill-word and forward-word treat newline character as whitespace and e.g. kill everything up to the end of the word in the next line. I would like it to stop at the end of the line instead.
I tried modifying the syntax table to include newline character into the word definition as follows:
(modify-syntax-entry ?\n "w")
This gives the desired effect, but needs to be specified separately for every syntax table.
Is there a way to achieve this effect globally?
Well, first off I would strongly recommend getting used to the idea of treating newlines as whitespace for the most part. Emacs generally does this consistently and trying to buck such a trend might be a never-ending battle.
Secondly I agree with the answer given by Stefan in that messing with the syntax table, or re-defining
forward-word
itself, will cause you nothing but trouble and grief.If you really want the behaviour you describe for
M-d
andM-f
then perhaps it would be best to define a new set of functions that have this desired behaviour, and to which you can bind theM-d
andM-f
keys to.Indeed this would be the traditional way to change the default behaviour of some core functionality in any emacs.
Maybe something like this? (barely tested)
I used
with-syntax-table
to temporarily (and globally) modify the syntax table.E.g., I used it with
syntax-subword
mode:Changing the syntax of the
?\n
character will get you quickly into trouble in all kinds of modes. Instead, you want to change the way things likeforward-word
behave when called interactively (note that changing the behavior of the functionforward-word
can also lead to trouble because it is often used in things like indentation code). You might like to take a look at howsubword-mode
works for an example of how this can be done.