Commit 8b56e02d authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(transpose-subr, transpose-subr-1): Rename variables

bound in one function and used in the other.
(transpose-subr-start1, transpose-subr-start2): Add defvars.
(transpose-subr-end1, transpose-subr-end2): Add defvars.
parent dc32c4fa
...@@ -2524,56 +2524,66 @@ With argument 0, interchanges line point is in with line mark is in." ...@@ -2524,56 +2524,66 @@ With argument 0, interchanges line point is in with line mark is in."
(forward-line arg)))) (forward-line arg))))
arg)) arg))
(defvar transpose-subr-start1)
(defvar transpose-subr-start2)
(defvar transpose-subr-end1)
(defvar transpose-subr-end2)
(defun transpose-subr (mover arg) (defun transpose-subr (mover arg)
(let (start1 end1 start2 end2) (let (transpose-subr-start1
transpose-subr-end1
transpose-subr-start2
transpose-subr-end2)
(if (= arg 0) (if (= arg 0)
(progn (progn
(save-excursion (save-excursion
(funcall mover 1) (funcall mover 1)
(setq end2 (point)) (setq transpose-subr-end2 (point))
(funcall mover -1) (funcall mover -1)
(setq start2 (point)) (setq transpose-subr-start2 (point))
(goto-char (mark)) (goto-char (mark))
(funcall mover 1) (funcall mover 1)
(setq end1 (point)) (setq transpose-subr-end1 (point))
(funcall mover -1) (funcall mover -1)
(setq start1 (point)) (setq transpose-subr-start1 (point))
(transpose-subr-1)) (transpose-subr-1))
(exchange-point-and-mark)) (exchange-point-and-mark))
(if (> arg 0) (if (> arg 0)
(progn (progn
(funcall mover -1) (funcall mover -1)
(setq start1 (point)) (setq transpose-subr-start1 (point))
(funcall mover 1) (funcall mover 1)
(setq end1 (point)) (setq transpose-subr-end1 (point))
(funcall mover arg) (funcall mover arg)
(setq end2 (point)) (setq transpose-subr-end2 (point))
(funcall mover (- arg)) (funcall mover (- arg))
(setq start2 (point)) (setq transpose-subr-start2 (point))
(transpose-subr-1) (transpose-subr-1)
(goto-char end2)) (goto-char transpose-subr-end2))
(funcall mover -1) (funcall mover -1)
(setq start2 (point)) (setq transpose-subr-start2 (point))
(funcall mover 1) (funcall mover 1)
(setq end2 (point)) (setq transpose-subr-end2 (point))
(funcall mover (1- arg)) (funcall mover (1- arg))
(setq start1 (point)) (setq transpose-subr-start1 (point))
(funcall mover (- arg)) (funcall mover (- arg))
(setq end1 (point)) (setq transpose-subr-end1 (point))
(transpose-subr-1))))) (transpose-subr-1)))))
(defun transpose-subr-1 () (defun transpose-subr-1 ()
(if (> (min end1 end2) (max start1 start2)) (if (> (min transpose-subr-end1 transpose-subr-end2)
(max transpose-subr-start1 transpose-subr-start2))
(error "Don't have two things to transpose")) (error "Don't have two things to transpose"))
(let* ((word1 (buffer-substring start1 end1)) (let* ((word1 (buffer-substring transpose-subr-start1 transpose-subr-end1))
(len1 (length word1)) (len1 (length word1))
(word2 (buffer-substring start2 end2)) (word2 (buffer-substring transpose-subr-start2 transpose-subr-end2))
(len2 (length word2))) (len2 (length word2)))
(delete-region start2 end2) (delete-region transpose-subr-start2 transpose-subr-end2)
(goto-char start2) (goto-char transpose-subr-start2)
(insert word1) (insert word1)
(goto-char (if (< start1 start2) start1 (goto-char (if (< transpose-subr-start1 transpose-subr-start2)
(+ start1 (- len1 len2)))) transpose-subr-start1
(+ transpose-subr-start1 (- len1 len2))))
(delete-region (point) (+ (point) len1)) (delete-region (point) (+ (point) len1))
(insert word2))) (insert word2)))
......
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