* bug#6032: untabify causes point to move
@ 2010-04-25 0:01 Ethan
2010-04-25 23:16 ` Juanma Barranquero
0 siblings, 1 reply; 3+ messages in thread
From: Ethan @ 2010-04-25 0:01 UTC (permalink / raw)
To: 6032
[-- Attachment #1: Type: text/plain, Size: 2365 bytes --]
`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
[-- Attachment #2: Type: text/html, Size: 2744 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#6032: untabify causes point to move
2010-04-25 0:01 bug#6032: untabify causes point to move Ethan
@ 2010-04-25 23:16 ` Juanma Barranquero
2011-07-13 18:13 ` Lars Magne Ingebrigtsen
0 siblings, 1 reply; 3+ messages in thread
From: Juanma Barranquero @ 2010-04-25 23:16 UTC (permalink / raw)
To: Ethan; +Cc: 6032
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#6032: untabify causes point to move
2010-04-25 23:16 ` Juanma Barranquero
@ 2011-07-13 18:13 ` Lars Magne Ingebrigtsen
0 siblings, 0 replies; 3+ messages in thread
From: Lars Magne Ingebrigtsen @ 2011-07-13 18:13 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: 6032, Ethan
Juanma Barranquero <lekktu@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/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-07-13 18:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-25 0:01 bug#6032: untabify causes point to move Ethan
2010-04-25 23:16 ` Juanma Barranquero
2011-07-13 18:13 ` Lars Magne Ingebrigtsen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.