Commit d3f4ef3f authored by Andreas Schwab's avatar Andreas Schwab
Browse files

(transpose-subr): Rewrite to make faster with big move

counts.
(transpose-lines): In the mover function handle arbitrary move
counts.
parent fd0a060b
......@@ -2262,14 +2262,15 @@ With argument 0, interchanges line point is in with line mark is in."
(interactive "*p")
(transpose-subr (function
(lambda (arg)
(if (= arg 1)
(if (> arg 0)
(progn
;; Move forward over a line,
;; but create a newline if none exists yet.
(end-of-line)
(if (eobp)
(newline)
(forward-char 1)))
;; Move forward over ARG lines,
;; but create newlines if necessary.
(setq arg (forward-line arg))
(if (/= (preceding-char) ?\n)
(setq arg (1+ arg)))
(if (> arg 0)
(newline arg)))
(forward-line arg))))
arg))
......@@ -2288,30 +2289,28 @@ With argument 0, interchanges line point is in with line mark is in."
(funcall mover -1)
(setq start1 (point))
(transpose-subr-1))
(exchange-point-and-mark)))
(while (> arg 0)
(funcall mover -1)
(setq start1 (point))
(funcall mover 1)
(setq end1 (point))
(funcall mover 1)
(setq end2 (point))
(funcall mover -1)
(setq start2 (point))
(transpose-subr-1)
(goto-char end2)
(setq arg (1- arg)))
(while (< arg 0)
(funcall mover -1)
(setq start2 (point))
(funcall mover -1)
(setq start1 (point))
(funcall mover 1)
(setq end1 (point))
(funcall mover 1)
(setq end2 (point))
(transpose-subr-1)
(setq arg (1+ arg)))))
(exchange-point-and-mark))
(if (> arg 0)
(progn
(funcall mover -1)
(setq start1 (point))
(funcall mover 1)
(setq end1 (point))
(funcall mover arg)
(setq end2 (point))
(funcall mover (- arg))
(setq start2 (point))
(transpose-subr-1)
(goto-char end2))
(funcall mover -1)
(setq start2 (point))
(funcall mover 1)
(setq end2 (point))
(funcall mover (1- arg))
(setq start1 (point))
(funcall mover (- arg))
(setq end1 (point))
(transpose-subr-1)))))
(defun transpose-subr-1 ()
(if (> (min end1 end2) (max start1 start2))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment