aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schwab1997-12-17 13:54:03 +0000
committerAndreas Schwab1997-12-17 13:54:03 +0000
commitd3f4ef3fda5033fc1fb3678182b3f3be1310a1b1 (patch)
treea1098f1354d91be4d7d887ef2c4c725f128cb31e
parentfd0a060bee18b603877a9eaba7bcffc69397f9fe (diff)
downloademacs-d3f4ef3fda5033fc1fb3678182b3f3be1310a1b1.tar.gz
emacs-d3f4ef3fda5033fc1fb3678182b3f3be1310a1b1.zip
(transpose-subr): Rewrite to make faster with big move
counts. (transpose-lines): In the mover function handle arbitrary move counts.
-rw-r--r--lisp/simple.el61
1 files changed, 30 insertions, 31 deletions
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."
2262 (interactive "*p") 2262 (interactive "*p")
2263 (transpose-subr (function 2263 (transpose-subr (function
2264 (lambda (arg) 2264 (lambda (arg)
2265 (if (= arg 1) 2265 (if (> arg 0)
2266 (progn 2266 (progn
2267 ;; Move forward over a line, 2267 ;; Move forward over ARG lines,
2268 ;; but create a newline if none exists yet. 2268 ;; but create newlines if necessary.
2269 (end-of-line) 2269 (setq arg (forward-line arg))
2270 (if (eobp) 2270 (if (/= (preceding-char) ?\n)
2271 (newline) 2271 (setq arg (1+ arg)))
2272 (forward-char 1))) 2272 (if (> arg 0)
2273 (newline arg)))
2273 (forward-line arg)))) 2274 (forward-line arg))))
2274 arg)) 2275 arg))
2275 2276
@@ -2288,30 +2289,28 @@ With argument 0, interchanges line point is in with line mark is in."
2288 (funcall mover -1) 2289 (funcall mover -1)
2289 (setq start1 (point)) 2290 (setq start1 (point))
2290 (transpose-subr-1)) 2291 (transpose-subr-1))
2291 (exchange-point-and-mark))) 2292 (exchange-point-and-mark))
2292 (while (> arg 0) 2293 (if (> arg 0)
2293 (funcall mover -1) 2294 (progn
2294 (setq start1 (point)) 2295 (funcall mover -1)
2295 (funcall mover 1) 2296 (setq start1 (point))
2296 (setq end1 (point)) 2297 (funcall mover 1)
2297 (funcall mover 1) 2298 (setq end1 (point))
2298 (setq end2 (point)) 2299 (funcall mover arg)
2299 (funcall mover -1) 2300 (setq end2 (point))
2300 (setq start2 (point)) 2301 (funcall mover (- arg))
2301 (transpose-subr-1) 2302 (setq start2 (point))
2302 (goto-char end2) 2303 (transpose-subr-1)
2303 (setq arg (1- arg))) 2304 (goto-char end2))
2304 (while (< arg 0) 2305 (funcall mover -1)
2305 (funcall mover -1) 2306 (setq start2 (point))
2306 (setq start2 (point)) 2307 (funcall mover 1)
2307 (funcall mover -1) 2308 (setq end2 (point))
2308 (setq start1 (point)) 2309 (funcall mover (1- arg))
2309 (funcall mover 1) 2310 (setq start1 (point))
2310 (setq end1 (point)) 2311 (funcall mover (- arg))
2311 (funcall mover 1) 2312 (setq end1 (point))
2312 (setq end2 (point)) 2313 (transpose-subr-1)))))
2313 (transpose-subr-1)
2314 (setq arg (1+ arg)))))
2315 2314
2316(defun transpose-subr-1 () 2315(defun transpose-subr-1 ()
2317 (if (> (min end1 end2) (max start1 start2)) 2316 (if (> (min end1 end2) (max start1 start2))