bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#6032: untabify causes point to move


From: Juanma Barranquero
Subject: bug#6032: untabify causes point to move
Date: Mon, 26 Apr 2010 01:16:58 +0200

On Sun, Apr 25, 2010 at 02:01, Ethan <ethan.glasser.camp@gmail.com> wrote:
> `untabify' sometimes causes the cursor to jump. If you have a buffer
> like this, with (-!-) representing point:
>
> ^I(-!-)^ISome text some text some text
>
> And (for example) have a before-save-hook that calls untabify on the
> whole buffer, the cursor will jump to the beginning of line. This is a
> bit surprising.

It can also happen in interactive use. In your example, if you select
the first tab, with point just at the second one, and do M-x untabify,
the cursor jumps to the beginning of the line.

All in all, it is a bit surprising. If you put the cursor at the first
t (in text), for example, the cursor does not jump. Why not?
`save-excursion' saves the point, but the point was 8 and it is now
22...

The problem can be trivially fixed by wrapping the tabify code in

  (let ((c (current-column)))
     ;;; tabify
     (move-to-column c))

as in the following patch, but perhaps there are cleaner ways.

(You can do that in an around advice, as a workaround.)

    Juanma


=== modified file 'lisp/tabify.el'
--- lisp/tabify.el      2010-01-13 08:35:10 +0000
+++ lisp/tabify.el      2010-04-25 22:53:06 +0000
@@ -34,19 +34,21 @@
 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.






reply via email to

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