From: Andreas Schwab Date: Wed, 17 Dec 1997 13:54:03 +0000 (+0000) Subject: (transpose-subr): Rewrite to make faster with big move X-Git-Tag: emacs-20.3~2609 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d3f4ef3fda5033fc1fb3678182b3f3be1310a1b1;p=emacs.git (transpose-subr): Rewrite to make faster with big move counts. (transpose-lines): In the mover function handle arbitrary move counts. --- diff --git a/lisp/simple.el b/lisp/simple.el index db3340e956f..e0eb58cc08c 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -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))