help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Transposing words over middle words


From: Arnaldo Mandel
Subject: Re: Transposing words over middle words
Date: Wed, 22 Nov 2017 16:18:25 -0200

Here is my take on this function.  It is slightly different from what came
before in that the cursor should be in the middle word, and it stays there.

(defun transpose-over-word ()
  "Transposes the two words adjacent to the one containing point."
  (interactive)
  (let ((p (point)))
    (forward-word 1)
    (setq p (- (point) p))
    (backward-word 1)
    (transpose-words  2)
    (backward-word 2)
    (transpose-words 1)
    (backward-char p)))


On Tue, Nov 21, 2017 at 3:21 PM, Tomas Nordin <tomasn@posteo.net> wrote:

>
> > Than again, maybe M-t should work like `C-0 M-t` whenever the region
> > is active so you don't even need the C-u at all.
>
> Here is an advice to make that happen, respecting possible prefixes.
>
> (defun tn-transpose-dwim-advice (transpose-subr &rest args)
>   (if (and (use-region-p) (= (cadr args) 1))
>       ;;                      MOVER  dwim  SPECIAL
>       (apply transpose-subr (car args) 0 (cddr args))
>     (apply transpose-subr args)))
>
> (advice-add 'transpose-subr :around #'tn-transpose-dwim-advice)
>
> ;;; remove the hack with this:
> ;; (advice-remove 'transpose-subr #'tn-transpose-dwim-advice)
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]