ken wrote:
I prefer this method because it's
straightforward and easy to understand, plus,
it leaves the mark where it was. However, in
instances in which the middle word is at the
end of the line, the result is unexpected:
With the point after the '3':
1 2 3 4
5 6 7 8
invoking M-a yields this:
1 2 5
4 3 6 7 8
You are right, here the other function is
better
(defun transpose-over-word-2 ()
(interactive)
(backward-char 1)
(push-mark)
(forward-word 3)
(backward-char 1)
(transpose-words 0)
(forward-word 1) )
(local-set-key (kbd "M-a") #'transpose-over-word-2) ; try it