emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111284: * simple.el (transpose-subr-


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111284: * simple.el (transpose-subr-1): Preserve marker positions
Date: Fri, 21 Dec 2012 13:42:59 +0800
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111284
fixes bug: http://debbugs.gnu.org/13122
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Fri 2012-12-21 13:42:59 +0800
message:
  * simple.el (transpose-subr-1): Preserve marker positions
  by changing the insertion sequence.
modified:
  lisp/ChangeLog
  lisp/simple.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-12-21 03:49:28 +0000
+++ b/lisp/ChangeLog    2012-12-21 05:42:59 +0000
@@ -1,3 +1,8 @@
+2012-12-21  Chong Yidong  <address@hidden>
+
+       * simple.el (transpose-subr-1): Preserve marker positions by
+       changing the insertion sequence (Bug#13122).
+
 2012-12-21  Kelly Dean  <address@hidden>  (tiny change)
 
        * simple.el (kill-region): Deactivate mark even for empty regions

=== modified file 'lisp/simple.el'
--- a/lisp/simple.el    2012-12-21 03:49:28 +0000
+++ b/lisp/simple.el    2012-12-21 05:42:59 +0000
@@ -5300,14 +5300,21 @@
       (setq pos1 pos2 pos2 swap)))
   (if (> (cdr pos1) (car pos2)) (error "Don't have two things to transpose"))
   (atomic-change-group
-   (let (word2)
-     ;; FIXME: We first delete the two pieces of text, so markers that
-     ;; used to point to after the text end up pointing to before it :-(
-     (setq word2 (delete-and-extract-region (car pos2) (cdr pos2)))
-     (goto-char (car pos2))
-     (insert (delete-and-extract-region (car pos1) (cdr pos1)))
-     (goto-char (car pos1))
-     (insert word2))))
+    ;; This sequence of insertions attempts to preserve marker
+    ;; positions at the start and end of the transposed objects.
+    (let* ((word (buffer-substring (car pos2) (cdr pos2)))
+          (len1 (- (cdr pos1) (car pos1)))
+          (len2 (length word))
+          (boundary (make-marker)))
+      (set-marker boundary (car pos2))
+      (goto-char (cdr pos1))
+      (insert-before-markers word)
+      (setq word (delete-and-extract-region (car pos1) (+ (car pos1) len1)))
+      (goto-char boundary)
+      (insert word)
+      (goto-char (+ boundary len1))
+      (delete-region (point) (+ (point) len2))
+      (set-marker boundary nil))))
 
 (defun backward-word (&optional arg)
   "Move backward until encountering the beginning of a word.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]