Subject: bug#25777: 25.1; [PATCH] `rectangle--pos-cols' should not move point

From: Drew Adams <[email-masked]>
Date: Fri, 17 Feb 2017 09:51:01 -0800 (PST)

The code defining `rectangle--pos-cols' mistakenly moves point.  All of
the calls to `goto-char' in this function need to be wrapped in
`save-excursion'.  Below is a patch that does this.

(This bug causes a regression from the correct behavior in Emacs 24.5,
BTW.)

I think that most, if not all, of the other uses of `goto-char' in
rect.el also need to be wrapped with `save-excursion'.  But as I am not
sure of this, I leave it to someone else to take a close look and DTRT.

-------------------------

diff -u rect.el rect-2017-02-17-patched.el
--- rect.el	2017-02-17 09:37:56.938748300 -0800
+++ rect-2017-02-17-patched.el	2017-02-17 09:43:13.884439700 -0800
@@ -85,26 +85,26 @@
                     (cdr rectangle--mark-crutches)
                   (if rectangle--mark-crutches
                       (setq rectangle--mark-crutches nil))
-                  (goto-char end) (current-column))))
+                  (save-excursion (goto-char end) (current-column)))))
         (if (eq start end) (cons (min sc ec) (max sc ec)) (cons sc ec))))
      ((eq end (car cw))
       (if (eq start (car rectangle--mark-crutches))
           (cons (cdr rectangle--mark-crutches) (cdr cw))
         (if rectangle--mark-crutches (setq rectangle--mark-crutches nil))
-        (cons (progn (goto-char start) (current-column)) (cdr cw))))
+        (cons (save-excursion (goto-char start) (current-column)) (cdr cw))))
      ((progn
         (if cw (setf (window-parameter nil 'rectangle--point-crutches) nil))
         (eq start (car rectangle--mark-crutches)))
       (let ((sc (cdr rectangle--mark-crutches))
-            (ec (progn (goto-char end) (current-column))))
+            (ec (save-excursion (goto-char end) (current-column))))
         (if (eq start end) (cons (min sc ec) (max sc ec)) (cons sc ec))))
      ((eq end (car rectangle--mark-crutches))
-      (cons (progn (goto-char start) (current-column))
+      (cons (save-excursion (goto-char start) (current-column))
             (cdr rectangle--mark-crutches)))
      (t
       (if rectangle--mark-crutches (setq rectangle--mark-crutches nil))
-      (cons (progn (goto-char start) (current-column))
-            (progn (goto-char end) (current-column)))))))
+      (cons (save-excursion (goto-char start) (current-column))
+            (save-excursion (goto-char end) (current-column)))))))
 
 (defun rectangle--col-pos (col kind)
   (let ((c (move-to-column col)))

---------------------

In GNU Emacs 25.1.1 (x86_64-w64-mingw32)
 of 2016-11-15
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --without-dbus --without-compress-install 'CFLAGS=-O2
 -static -g3''