From: Juanma Barranquero Date: Wed, 13 Jul 2011 18:12:05 +0000 (+0200) Subject: Preserve point when doing untabify X-Git-Tag: emacs-pretest-24.0.90~104^2~310 X-Git-Url: https://code.delx.au/gnu-emacs/commitdiff_plain/bead9a43c1c13b812b4c4f10219a79897e18617d Preserve point when doing untabify * tabify.el (untabify): Preserve the current column so that point doesn't move. Fixes: debbugs:6032 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1a0c445f96..47f6b6c9aa 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2011-07-13 Juanma Barranquero + + * tabify.el (untabify): Preserve the current column so that point + doesn't move (bug#6032). + 2011-07-13 Lars Magne Ingebrigtsen * progmodes/cperl-mode.el (cperl-syntaxify-by-font-lock): Rewrite diff --git a/lisp/tabify.el b/lisp/tabify.el index da1038a216..0b2411d031 100644 --- a/lisp/tabify.el +++ b/lisp/tabify.el @@ -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.