GNU bug report logs - #6032
untabify causes point to move

Previous Next

Package: emacs;

Reported by: Ethan <ethan.glasser.camp <at> gmail.com>

Date: Sun, 25 Apr 2010 00:33:02 UTC

Severity: minor

Tags: fixed, patch

Fixed in version 24.1

Done: Lars Magne Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 6032 in the body.
You can then email your comments to 6032 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#6032; Package emacs. (Sun, 25 Apr 2010 00:33:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ethan <ethan.glasser.camp <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 25 Apr 2010 00:33:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ethan <ethan.glasser.camp <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: untabify causes point to move
Date: Sat, 24 Apr 2010 20:01:35 -0400
[Message part 1 (text/plain, inline)]
`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.



In GNU Emacs 23.1.1 (i486-pc-linux-gnu, GTK+ Version 2.18.3)
 of 2010-03-26 on palmer, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.10604000
configured using `configure  '--build=i486-linux-gnu'
'--host=i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib'
'--libexecdir=/usr/lib' '--localstatedir=/var/lib'
'--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes'
'--enable-locallisppath=/etc/emacs23:/etc/emacs:/usr/local/share/emacs/23.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.1/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/23.1/leim'
'--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars'
'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g
-O2' 'LDFLAGS=-g' 'CPPFLAGS=''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default-enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  yas/global-mode: t
  yas/minor-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  global-auto-composition-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
M-x r e p o r t - e <tab> <return>

Recent messages:
Ido mode enabled
Failed to load jxp mode: (file-error Cannot open load file jxp-mode)
/usr/bin/mail is not an executable.  Setting mail-interactive to t.
For information about GNU Emacs and the GNU system, type C-h C-a.
Saving all Org-mode buffers...
(No files need saving)
Saving all Org-mode buffers... done
Saving all Org-mode buffers...
(No files need saving)
Saving all Org-mode buffers... done
[Message part 2 (text/html, inline)]

Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#6032; Package emacs. (Sun, 25 Apr 2010 23:18:02 GMT) Full text and rfc822 format available.

Message #8 received at 6032 <at> debbugs.gnu.org (full text, mbox):

From: Juanma Barranquero <lekktu <at> gmail.com>
To: Ethan <ethan.glasser.camp <at> gmail.com>
Cc: 6032 <at> debbugs.gnu.org
Subject: Re: 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 <at> 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.




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#6032; Package emacs. (Wed, 13 Jul 2011 18:14:01 GMT) Full text and rfc822 format available.

Message #11 received at 6032 <at> debbugs.gnu.org (full text, mbox):

From: Lars Magne Ingebrigtsen <larsi <at> gnus.org>
To: Juanma Barranquero <lekktu <at> gmail.com>
Cc: 6032 <at> debbugs.gnu.org, Ethan <ethan.glasser.camp <at> gmail.com>
Subject: Re: bug#6032: untabify causes point to move
Date: Wed, 13 Jul 2011 20:13:18 +0200
Juanma Barranquero <lekktu <at> gmail.com> writes:

> 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.

I think that's the easiest way to preserve point.  I've now applied the
patch to Emacs 24.

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/




Added tag(s) fixed. Request was from Lars Magne Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 13 Jul 2011 18:14:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 24.1, send any further explanations to 6032 <at> debbugs.gnu.org and Ethan <ethan.glasser.camp <at> gmail.com> Request was from Lars Magne Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 13 Jul 2011 18:14:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 11 Aug 2011 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 269 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.