Does Emacs or any packages provide a transpose-page command?

I know the C-x [ and C-x ] and forward or backward page, but many times I just want to transpose two adjacent pages, especially when in some Major Modes where pages are defined to be some group of special things.

  • 1
    You could write a command to do that. I don't think there is one that already exists for it. Or you could: (1) select the first page as the region and kill it: C-SPC C-x ] C-w, (2) move to the end of the second page and yank the first page there: C-x ] C-y. You can put that in a keyboard macro and repeat it any number of times, etc.
    – Drew
    Apr 1, 2017 at 17:03
  • There is a standard mark-page command and binding, so you can simplify that macro to C-x C-p C-w C-x ] C-y
    – phils
    Apr 1, 2017 at 23:01

1 Answer 1


The "transpose" functionality is beautifully abstracted such that to implement a new variant you need only give it a single function which knows how to move backward and forward over the thing in question.

Emacs doesn't provide transpose-pages by default, but it does provide the forward-page function we need, and so it is trivial to write the new command.

Here I've copied and pasted transpose-paragraphs and substituted "page" appropriately.

(defun transpose-pages (arg)
  "Interchange the current page with the next one.
With prefix argument ARG a non-zero integer, moves the current
page past ARG pages, leaving point after the current page.
If ARG is positive, moves the current page forwards, if
ARG is negative moves it backwards.  If ARG is zero, exchanges
the current page with the one containing the mark."
  (interactive "*p")
  (transpose-subr 'forward-page arg))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.