unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juanma Barranquero <lekktu@gmail.com>
To: Ethan <ethan.glasser.camp@gmail.com>
Cc: 6032@debbugs.gnu.org
Subject: bug#6032: untabify causes point to move
Date: Mon, 26 Apr 2010 01:16:58 +0200	[thread overview]
Message-ID: <h2jf7ccd24b1004251616sf517413dlcaa68681a4e75d99@mail.gmail.com> (raw)
In-Reply-To: <h2k9cd2f5ff1004241701xca9aed56o4b0c15b58439f78d@mail.gmail.com>

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	other threads:[~2010-04-25 23:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-25  0:01 bug#6032: untabify causes point to move Ethan
2010-04-25 23:16 ` Juanma Barranquero [this message]
2011-07-13 18:13   ` Lars Magne Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=h2jf7ccd24b1004251616sf517413dlcaa68681a4e75d99@mail.gmail.com \
    --to=lekktu@gmail.com \
    --cc=6032@debbugs.gnu.org \
    --cc=ethan.glasser.camp@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).