]> code.delx.au - gnu-emacs/commitdiff
Preserve point when doing untabify
authorJuanma Barranquero <lekktu@gmail.com>
Wed, 13 Jul 2011 18:12:05 +0000 (20:12 +0200)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Wed, 13 Jul 2011 18:12:05 +0000 (20:12 +0200)
* tabify.el (untabify): Preserve the current column so that point
doesn't move.

Fixes: debbugs:6032
lisp/ChangeLog
lisp/tabify.el

index 1a0c445f965e3ef79cc8d3527a827368d8095f24..47f6b6c9aa6b06ce5bcd55188b06eb076c87f7a9 100644 (file)
@@ -1,3 +1,8 @@
+2011-07-13  Juanma Barranquero  <lekktu@gmail.com>
+
+       * tabify.el (untabify): Preserve the current column so that point
+       doesn't move (bug#6032).
+
 2011-07-13  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
        * progmodes/cperl-mode.el (cperl-syntaxify-by-font-lock): Rewrite
index da1038a21647afaca3b107f42d32687058a5038d..0b2411d03161af2bc793beeea33289ac38593bf8 100644 (file)
@@ -34,19 +34,21 @@ Called non-interactively, the region is specified by arguments
 START and END, rather than by the position of point and mark.
 The variable `tab-width' controls the spacing of tab stops."
   (interactive "r")
-  (save-excursion
-    (save-restriction
-      (narrow-to-region (point-min) end)
-      (goto-char start)
-      (while (search-forward "\t" nil t)       ; faster than re-search
-       (forward-char -1)
-       (let ((tab-beg (point))
-             (indent-tabs-mode nil)
-             column)
-         (skip-chars-forward "\t")
-         (setq column (current-column))
-         (delete-region tab-beg (point))
-         (indent-to column))))))
+  (let ((c (current-column)))
+    (save-excursion
+      (save-restriction
+        (narrow-to-region (point-min) end)
+        (goto-char start)
+        (while (search-forward "\t" nil t)      ; faster than re-search
+          (forward-char -1)
+          (let ((tab-beg (point))
+                (indent-tabs-mode nil)
+                column)
+            (skip-chars-forward "\t")
+            (setq column (current-column))
+            (delete-region tab-beg (point))
+            (indent-to column)))))
+    (move-to-column c)))
 
 (defvar tabify-regexp " [ \t]+"
   "Regexp matching whitespace that tabify should consider.