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
and M-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 the M-d
and M-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)
(defun forward-word-stop-eol (arg)
(interactive "p")
(let ((start (point)))
(save-restriction
(save-excursion
(move-end-of-line 1)
(narrow-to-region start (point)))
(forward-word arg))))
(defun kill-to-end-of-word-or-line (arg)
(interactive "p")
(kill-region (point) (progn (forward-word-stop-eol arg) (point))))
(global-set-key "ef" forward-word-stop-eol)
(global-set-key "ek" kill-to-end-of-word-or-line)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…