changeset 20465:de641c2459a6

(transpose-subr): Rewrite to make faster with big move counts. (transpose-lines): In the mover function handle arbitrary move counts.
author Andreas Schwab <schwab@suse.de>
date Wed, 17 Dec 1997 13:54:03 +0000
parents 9c811b2d0836
children 38cee46393d4
files lisp/simple.el
diffstat 1 files changed, 30 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/simple.el	Wed Dec 17 13:16:22 1997 +0000
+++ b/lisp/simple.el	Wed Dec 17 13:54:03 1997 +0000
@@ -2262,14 +2262,15 @@
   (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 @@
 	    (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))