diff options
| author | Chong Yidong | 2012-12-21 13:42:59 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-12-21 13:42:59 +0800 |
| commit | aa26f345096166bd8c135876dbab9b671ae232e3 (patch) | |
| tree | b511ad3694a4ad3fa02cc49e25441ac60f55cf8b | |
| parent | 05c22d878f065c583c9f0672c3b2719742f07b1b (diff) | |
| download | emacs-aa26f345096166bd8c135876dbab9b671ae232e3.tar.gz emacs-aa26f345096166bd8c135876dbab9b671ae232e3.zip | |
* simple.el (transpose-subr-1): Preserve marker positions
by changing the insertion sequence.
Fixes: debbugs:13122
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/simple.el | 23 |
2 files changed, 20 insertions, 8 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e89602c8e45..a26fc63fa49 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2012-12-21 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * simple.el (transpose-subr-1): Preserve marker positions by | ||
| 4 | changing the insertion sequence (Bug#13122). | ||
| 5 | |||
| 1 | 2012-12-21 Kelly Dean <kellydeanch@yahoo.com> (tiny change) | 6 | 2012-12-21 Kelly Dean <kellydeanch@yahoo.com> (tiny change) |
| 2 | 7 | ||
| 3 | * simple.el (kill-region): Deactivate mark even for empty regions | 8 | * simple.el (kill-region): Deactivate mark even for empty regions |
diff --git a/lisp/simple.el b/lisp/simple.el index 8c7e88d04bc..c0ba5477b56 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -5300,14 +5300,21 @@ current object." | |||
| 5300 | (setq pos1 pos2 pos2 swap))) | 5300 | (setq pos1 pos2 pos2 swap))) |
| 5301 | (if (> (cdr pos1) (car pos2)) (error "Don't have two things to transpose")) | 5301 | (if (> (cdr pos1) (car pos2)) (error "Don't have two things to transpose")) |
| 5302 | (atomic-change-group | 5302 | (atomic-change-group |
| 5303 | (let (word2) | 5303 | ;; This sequence of insertions attempts to preserve marker |
| 5304 | ;; FIXME: We first delete the two pieces of text, so markers that | 5304 | ;; positions at the start and end of the transposed objects. |
| 5305 | ;; used to point to after the text end up pointing to before it :-( | 5305 | (let* ((word (buffer-substring (car pos2) (cdr pos2))) |
| 5306 | (setq word2 (delete-and-extract-region (car pos2) (cdr pos2))) | 5306 | (len1 (- (cdr pos1) (car pos1))) |
| 5307 | (goto-char (car pos2)) | 5307 | (len2 (length word)) |
| 5308 | (insert (delete-and-extract-region (car pos1) (cdr pos1))) | 5308 | (boundary (make-marker))) |
| 5309 | (goto-char (car pos1)) | 5309 | (set-marker boundary (car pos2)) |
| 5310 | (insert word2)))) | 5310 | (goto-char (cdr pos1)) |
| 5311 | (insert-before-markers word) | ||
| 5312 | (setq word (delete-and-extract-region (car pos1) (+ (car pos1) len1))) | ||
| 5313 | (goto-char boundary) | ||
| 5314 | (insert word) | ||
| 5315 | (goto-char (+ boundary len1)) | ||
| 5316 | (delete-region (point) (+ (point) len2)) | ||
| 5317 | (set-marker boundary nil)))) | ||
| 5311 | 5318 | ||
| 5312 | (defun backward-word (&optional arg) | 5319 | (defun backward-word (&optional arg) |
| 5313 | "Move backward until encountering the beginning of a word. | 5320 | "Move backward until encountering the beginning of a word. |