# HG changeset patch # User Karl Heuer # Date 866853311 0 # Node ID dca9b4a8155e747854006f750e95240aa110c151 # Parent b5cee57a4a0fd4fc5a2dbdcf67a39212eafb5ea4 (untabify): Handle consecutive tabs all at once. (tabify-regexp): New var. (tabify): Use it. diff -r b5cee57a4a0f -r dca9b4a8155e lisp/tabify.el --- a/lisp/tabify.el Fri Jun 20 21:43:44 1997 +0000 +++ b/lisp/tabify.el Sat Jun 21 00:35:11 1997 +0000 @@ -40,13 +40,20 @@ (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)) - (column (current-column)) - (indent-tabs-mode nil)) - (skip-chars-backward "\t" start) + (indent-tabs-mode nil) + column) + (skip-chars-forward "\t") + (setq column (current-column)) (delete-region tab-beg (point)) (indent-to column)))))) +(defvar tabify-regexp "[ \t][ \t]+" + "Regexp matching whitespace that tabify should consider. +Usually this will be \"[ \\t][ \\t]+\" to match two or more spaces or tabs. +\"^[ \\t]+\" is also useful, for tabifying only initial whitespace.") + ;;;###autoload (defun tabify (start end) "Convert multiple spaces in region to tabs when possible. @@ -64,7 +71,7 @@ (beginning-of-line) (narrow-to-region (point) end) (goto-char start) - (while (re-search-forward "[ \t][ \t][ \t]*" nil t) + (while (re-search-forward tabify-regexp nil t) (let ((column (current-column)) (indent-tabs-mode t)) (delete-region (match-beginning 0) (point))